This repository was archived by the owner on Aug 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathInputToolbar.js
More file actions
125 lines (125 loc) · 3.68 KB
/
InputToolbar.js
File metadata and controls
125 lines (125 loc) · 3.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import PropTypes from 'prop-types';
import React from 'react';
import { StyleSheet, View, Keyboard, ViewPropTypes, } from 'react-native';
import Composer from './Composer';
import Send from './Send';
import Actions from './Actions';
import Color from './Color';
const styles = StyleSheet.create({
container: {
borderTopWidth: StyleSheet.hairlineWidth,
borderTopColor: Color.defaultColor,
backgroundColor: Color.white,
bottom: 0,
left: 0,
right: 0,
},
primary: {
flexDirection: 'row',
alignItems: 'flex-end',
},
accessory: {
height: 44,
},
});
export default class InputToolbar extends React.Component {
constructor() {
super(...arguments);
this.state = {
position: 'absolute',
};
this.keyboardWillShowListener = undefined;
this.keyboardWillHideListener = undefined;
this.keyboardWillShow = () => {
if (this.state.position !== 'relative') {
this.setState({
position: 'relative',
});
}
};
this.keyboardWillHide = () => {
if (this.state.position !== 'absolute') {
this.setState({
position: 'absolute',
});
}
};
}
componentDidMount() {
this.keyboardWillShowListener = Keyboard.addListener('keyboardWillShow', this.keyboardWillShow);
this.keyboardWillHideListener = Keyboard.addListener('keyboardWillHide', this.keyboardWillHide);
}
componentWillUnmount() {
if (this.keyboardWillShowListener) {
this.keyboardWillShowListener.remove();
}
if (this.keyboardWillHideListener) {
this.keyboardWillHideListener.remove();
}
}
renderActions() {
const { containerStyle, ...props } = this.props;
if (this.props.renderActions) {
return this.props.renderActions(props);
}
else if (this.props.onPressActionButton) {
return <Actions {...props}/>;
}
return null;
}
renderSend() {
if (this.props.renderSend) {
return this.props.renderSend(this.props);
}
return <Send {...this.props}/>;
}
renderComposer() {
if (this.props.renderComposer) {
return this.props.renderComposer(this.props);
}
return <Composer {...this.props}/>;
}
renderAccessory() {
if (this.props.renderAccessory) {
return (<View style={[styles.accessory, this.props.accessoryStyle]}>
{this.props.renderAccessory(this.props)}
</View>);
}
return null;
}
render() {
return (<View style={[
styles.container,
this.props.containerStyle,
{ position: this.state.position },
]}>
<View style={[styles.primary, this.props.primaryStyle]}>
{this.renderActions()}
{this.renderComposer()}
{this.renderSend()}
</View>
{this.renderAccessory()}
</View>);
}
}
InputToolbar.defaultProps = {
renderAccessory: null,
renderActions: null,
renderSend: null,
renderComposer: null,
containerStyle: {},
primaryStyle: {},
accessoryStyle: {},
onPressActionButton: () => { },
};
InputToolbar.propTypes = {
renderAccessory: PropTypes.func,
renderActions: PropTypes.func,
renderSend: PropTypes.func,
renderComposer: PropTypes.func,
onPressActionButton: PropTypes.func,
containerStyle: ViewPropTypes.style,
primaryStyle: ViewPropTypes.style,
accessoryStyle: ViewPropTypes.style,
};
//# sourceMappingURL=InputToolbar.js.map