简体   繁体   English

react-native android:TextInput会短暂忽略值prop

[英]react-native android: TextInput briefly ignores value prop

This is on android with react-native v0.55.4. 这在带有react-native v0.55.4的android上。

<TextInput
  value="should always be this value"
/>

When I am typing inside this TextInput, the text will briefly update with whatever new text I enter, before going back to showing "should always be this value". 当我在此TextInput中键入内容时,该文本将使用输入的任何新文本进行短暂更新,然后返回显示“应始终为该值”。

For example, if I type 'X', the text will briefly update to "should always be this valueX", before returning back to "should always be this value", creating a jitter inside the TextInput. 例如,如果我键入“ X”,则文本将短暂更新为“应始终为该值X”,然后返回“应始终为该值”,从而在TextInput内部产生抖动。

edit: the docs addressed this issue: https://facebook.github.io/react-native/docs/textinput#value 编辑:文档解决了这个问题: https : //facebook.github.io/react-native/docs/textinput#value

Based on just that short codesnippet, you need to set value to a state property. 仅基于该短代码片段,您需要将值设置为state属性。

constructor(props) {
 super(props);
 this.state = {
   textInput: 'Should always be this value'
 }
}

And your text input 和你的文字输入

<TextInput
 value={this.state.textInput}
 onChangeText={text => this.setState({ textInput: text }) }
/>

Here is some docs 这是一些文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM