gpt4 book ai didi

android - React-Native TextInput showSoftInputOnFocus 效果不佳

转载 作者:行者123 更新时间:2023-11-29 22:48:28 27 4
gpt4 key购买 nike

我的代码中有两个 TextInput。其中之一我将其 showSoftInputOnFocus 设置为 true,我想在它聚焦时显示键盘。另一个我将它的 showSoftInputOnFocus 设置为 false,我不想在它聚焦时显示键盘。

<View>
<Text style={_label}>Field1</Text>
<TextInput
value={value1}
showSoftInputOnFocus={false}
keyboardType="numeric"
/>
</View>
<View>
<Text style={_label}>Field2</Text>
<TextInput
value={value2}
autoFocus={true}
showSoftInputOnFocus={true}
/>
</View>

当第二个 TextInput 获得焦点时,键盘显示。然后我按下第一个 TextInput,它聚焦了,但键盘仍然在屏幕上,它没有关闭。

我尝试将 onBlur={Keyboard.dismiss} 添加到第二个 TextInput。当我将光标从第二个 TextInput 切换到第一个时,键盘确实被隐藏了,但第一个 TextInput 没有获得焦点。我必须再次按下第一个 TextInput 以使其聚焦。

如何让第一个 TextInput 在我按下时立即获得焦点?

最佳答案

ScrollView 有一个名为 keyboardShouldPersistTaps 的属性,它会在显示键盘时更改触摸行为。尝试在主视图中添加 ScrollView:

<View>
<ScrollView keyboardShouldPersistTaps='always'>
...
</ScrollView>
</View>

关于android - React-Native TextInput showSoftInputOnFocus 效果不佳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58145749/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com