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
/
Copy pathComposer.js
97 lines (97 loc) · 3.45 KB
/
Composer.js
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
import PropTypes from 'prop-types';
import React from 'react';
import { Platform, StyleSheet, TextInput } from 'react-native';
import { MIN_COMPOSER_HEIGHT, DEFAULT_PLACEHOLDER } from './Constant';
import Color from './Color';
const styles = StyleSheet.create({
textInput: {
flex: 1,
marginLeft: 10,
fontSize: 14,
lineHeight: 16,
...Platform.select({
web: {
paddingTop: 6,
paddingLeft: 4,
},
}),
marginTop: Platform.select({
ios: 6,
android: 0,
web: 6,
}),
marginBottom: Platform.select({
ios: 5,
android: 3,
web: 4,
}),
},
});
export default class Composer extends React.Component {
constructor() {
super(...arguments);
this.contentSize = undefined;
this.onContentSizeChange = (e) => {
const { contentSize } = e.nativeEvent;
// Support earlier versions of React Native on Android.
if (!contentSize) {
return;
}
if (!this.contentSize ||
(this.contentSize &&
(this.contentSize.width !== contentSize.width ||
this.contentSize.height !== contentSize.height))) {
this.contentSize = contentSize;
this.props.onInputSizeChanged(this.contentSize);
}
};
this.onChangeText = (text) => {
this.props.onTextChanged(text);
};
}
render() {
return (<TextInput testID={this.props.placeholder} accessible accessibilityLabel={this.props.placeholder} placeholder={this.props.placeholder} placeholderTextColor={this.props.placeholderTextColor} multiline={this.props.multiline} editable={!(this.props.disableComposer)} onChange={this.onContentSizeChange} onContentSizeChange={this.onContentSizeChange} onChangeText={this.onChangeText} style={[
styles.textInput,
this.props.textInputStyle,
{
height: this.props.composerHeight,
...Platform.select({
web: {
outlineWidth: 0,
outlineColor: 'transparent',
outlineOffset: 0,
},
}),
},
]} autoFocus={this.props.textInputAutoFocus} value={this.props.text} enablesReturnKeyAutomatically underlineColorAndroid='transparent' keyboardAppearance={this.props.keyboardAppearance} {...this.props.textInputProps}/>);
}
}
Composer.defaultProps = {
composerHeight: MIN_COMPOSER_HEIGHT,
text: '',
placeholderTextColor: Color.defaultColor,
placeholder: DEFAULT_PLACEHOLDER,
textInputProps: null,
multiline: true,
disableComposer: false,
textInputStyle: {},
textInputAutoFocus: false,
keyboardAppearance: 'default',
onTextChanged: () => { },
onInputSizeChanged: () => { },
};
Composer.propTypes = {
composerHeight: PropTypes.number,
text: PropTypes.string,
placeholder: PropTypes.string,
placeholderTextColor: PropTypes.string,
textInputProps: PropTypes.object,
onTextChanged: PropTypes.func,
onInputSizeChanged: PropTypes.func,
multiline: PropTypes.bool,
disableComposer: PropTypes.bool,
textInputStyle: PropTypes.any,
textInputAutoFocus: PropTypes.bool,
keyboardAppearance: PropTypes.string,
};
//# sourceMappingURL=Composer.js.map