以下是代码:
<TextInput multiline={true} style={{height:160}} onChangeText={(text) => this._changeBody(text)} value={this.state.body} blurOnSubmit={false} placeholder={ARTICLE_BODY_TIPS}/>
当我按下返回键时,它没有插入换行符,os是android,RN版本是0.43.3
答案 0 :(得分:0)
试试吧!它也在线的中间工作!
<TextInput
value={this.state.query}
onChangeText={text => this.setState({ query: text, allowEditing: true })}
selection = {this.state.selection}
onSelectionChange={(event) => this.setState({ cursorPosition: event.nativeEvent.selection, selection: event.nativeEvent.selection, allowEditing: true })}
onSubmitEditing={() => {
const { query, cursorPosition } = this.state;
let newText = query;
const ar = newText.split('');
ar.splice(cursorPosition.start, 0, '\n');
newText = ar.join('');
if (cursorPosition.start === query.length && query.endsWith('\n')) {
this.setState({ query: newText });
} else if (this.state.allowEditing) {
this.setState({
query: newText,
selection: {
start: cursorPosition.start + 1,
end: cursorPosition.end + 1
},
allowEditing: !this.state.allowEditing
});
}
}}
multiline = {true}
numberOfLines = {10}
blurOnSubmit={false}
editable={true}
/>
this.state = {
query: '',
cursorPosition: [0,0],
selection: null,
allowEditing: true
}