UNPKG

3.57 kBJavaScriptView Raw
1import PropTypes from 'prop-types';
2import React from 'react';
3import { Platform, StyleSheet, TextInput } from 'react-native';
4import { MIN_COMPOSER_HEIGHT, DEFAULT_PLACEHOLDER } from './Constant';
5import Color from './Color';
6import { StylePropType } from './utils';
7const styles = StyleSheet.create({
8 textInput: {
9 flex: 1,
10 marginLeft: 10,
11 fontSize: 16,
12 lineHeight: 16,
13 ...Platform.select({
14 web: {
15 paddingTop: 6,
16 paddingLeft: 4,
17 },
18 }),
19 marginTop: Platform.select({
20 ios: 6,
21 android: 0,
22 web: 6,
23 }),
24 marginBottom: Platform.select({
25 ios: 5,
26 android: 3,
27 web: 4,
28 }),
29 },
30});
31export default class Composer extends React.Component {
32 constructor() {
33 super(...arguments);
34 this.contentSize = undefined;
35 this.onContentSizeChange = (e) => {
36 const { contentSize } = e.nativeEvent;
37 // Support earlier versions of React Native on Android.
38 if (!contentSize) {
39 return;
40 }
41 if (!this.contentSize ||
42 (this.contentSize &&
43 (this.contentSize.width !== contentSize.width ||
44 this.contentSize.height !== contentSize.height))) {
45 this.contentSize = contentSize;
46 this.props.onInputSizeChanged(this.contentSize);
47 }
48 };
49 this.onChangeText = (text) => {
50 this.props.onTextChanged(text);
51 };
52 }
53 render() {
54 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={[
55 styles.textInput,
56 this.props.textInputStyle,
57 {
58 height: this.props.composerHeight,
59 ...Platform.select({
60 web: {
61 outlineWidth: 0,
62 outlineColor: 'transparent',
63 outlineOffset: 0,
64 },
65 }),
66 },
67 ]} autoFocus={this.props.textInputAutoFocus} value={this.props.text} enablesReturnKeyAutomatically underlineColorAndroid='transparent' keyboardAppearance={this.props.keyboardAppearance} {...this.props.textInputProps}/>);
68 }
69}
70Composer.defaultProps = {
71 composerHeight: MIN_COMPOSER_HEIGHT,
72 text: '',
73 placeholderTextColor: Color.defaultColor,
74 placeholder: DEFAULT_PLACEHOLDER,
75 textInputProps: null,
76 multiline: true,
77 disableComposer: false,
78 textInputStyle: {},
79 textInputAutoFocus: false,
80 keyboardAppearance: 'default',
81 onTextChanged: () => { },
82 onInputSizeChanged: () => { },
83};
84Composer.propTypes = {
85 composerHeight: PropTypes.number,
86 text: PropTypes.string,
87 placeholder: PropTypes.string,
88 placeholderTextColor: PropTypes.string,
89 textInputProps: PropTypes.object,
90 onTextChanged: PropTypes.func,
91 onInputSizeChanged: PropTypes.func,
92 multiline: PropTypes.bool,
93 disableComposer: PropTypes.bool,
94 textInputStyle: StylePropType,
95 textInputAutoFocus: PropTypes.bool,
96 keyboardAppearance: PropTypes.string,
97};
98//# sourceMappingURL=Composer.js.map
\No newline at end of file