【发布时间】:2020-04-19 21:46:20
【问题描述】:
我想在按下输入字段时显示我的自定义键盘组件。我想防止系统默认键盘被触发。
我尝试在 onFocus 上关闭键盘,但这会触发键盘,然后关闭键盘。
<TextInput
placeholder="type here"
onFocus={Keyboard.dismiss}
/>
我已经厌倦了将 TextInput 包装在 TouchableWithoutFeedback 中,但这个解决方案不起作用。
<TouchableWithoutFeedback
onPress={() => Keyboard.dismiss()}
accessible={false}
>
<View>
<TextInput placeholder="type here" />
</View>
</TouchableWithoutFeedback>
有什么想法可以达到预期的效果吗?
【问题讨论】:
-
您不必为此使用
TextInput。您可以在TouchableWithoutFeedback中放置一个Text来触发键盘,将您的自定义键盘输入保存为某种状态或其他内容,然后将值传递给Text -
我想到了这个想法,但
Text组件的行为与TextInput不同。
标签: react-native keyboard textinput