Wel*_*ton 9 android textinput react-native
我TextInput的本机应用程序中有一个。当我设置值prop且该值比的长度长时TextInput,它显示的是从结尾开始而不是开头的文本。在iOS中可以正常使用,这似乎是Android问题。有没有一种方法可以使文字从的开头显示,TextInput还是首选?
这是我看到的:
这就是我要的:
这是我的代码
<TextInput
defaultValue={address}
ref="searchInput"
autoCorrect={false}
style={searchStyles.searchInputField}
placeholderTextColor={'#ddd'}
placeholder="Location"
onChangeText={query => this.search(query)}
/>
Run Code Online (Sandbox Code Playgroud)
我遇到了同样的问题,我的解决方案是默认将选择道具添加到开始。这是有效的,因此当输入聚焦时,它会进入开始。然后我添加了autoFocus道具并将其设置为 true 以使其在加载组件时进入开始状态。
<TextInput value={address} autoFocus={true} selection={{start:0, end:0}} />
Run Code Online (Sandbox Code Playgroud)
可能有更好的方法来做到这一点,但这是我提出的希望它可以帮助其他人。
试试这个它对我有用
constructor(props) {
super(props);
this.state = {
selection: Platform.OS === 'android' ? { start: 0 } : null
}
}
onFocus =()=>{
if(Platform.OS==='android'){
this.setState({ selection:null });
}
}
onBlur =()=>{
if(Platform.OS==='android'){
this.setState({ selection:{ start: 0, end: 0 } });
}
}
<TextInput
onFocus={()=>this.onFocus()}
onBlur={()=>this.onBlur()}
selection={this.state.selection}
/>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1589 次 |
| 最近记录: |