【发布时间】:2018-12-22 18:45:44
【问题描述】:
我正在尝试使用 react native 元素和 react native 实现多行扩展文本输入,但我似乎无法使其正常运行。该行为显示在以下屏幕截图中:
这里可以看到,text has 明显不止一行,但是 text input 并没有展开。
每当我再输入几个字符时,它会稍微扩展一点,但会向下扩展至键盘。
添加另一行不会扩展键盘:
直到我添加更多字符,直到最新的行是文本输入宽度的一半,输入才会扩展
这是我用于文本输入的代码:
<View style={{flexDirection:'row', backgroundColor: 'transparent', height: Math.max(45, this.state.viewHeight)}}>
<Input
containerStyle={{marginVertical: 0, width:300, marginLeft: 10}}
inputStyle={[styles.textInput, {height: Math.max(35, this.state.height)}]}
multiline
enablesReturnKeyAutomatically={true}
keyboardAppearance="dark"
placeholder=""
onContentSizeChange={(event) => {
if (this.state.height <= (35*6)){
this.setState({
height: event.nativeEvent.contentSize.height,
viewHeight: event.nativeEvent.contentSize.height })
}
}}
onChangeText={(message) => { this.setState({message})
}}
这是我的文本输入样式的代码:
textInput: {
paddingHorizontal: 12,
width: 100,
backgroundColor: '#F0F0F0',
borderStyle: 'solid',
marginLeft: -4,
overflow: 'hidden',
marginTop: 5,
borderWidth: 1,
borderColor: 'lightgrey',
borderRadius: 25,
},
似乎内容大小更改事件在错误的时间触发,有什么方法可以将其设置为仅在新行具有特定长度并向上扩展而不是向下扩展到键盘时触发?
【问题讨论】:
标签: javascript react-native react-native-ios textinput