本文介绍了在外部点击时模糊 TextInput的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 TextInput 时遇到问题,预期行为是当我点击它时,它会聚焦并显示键盘,当我点击它时(除了输入之外的任何地方),TextInput应该模糊,键盘会消失.目前这不会发生,无论我点击哪里,文本输入都会保持专注.这是预期的行为吗?如果是,通常如何处理?

I'm experiencing issue using TextInput expected behaviour is that when I tap on it, it is focused and keyboard is shown, and when I tap around it (anywhere besides the input), the TextInput should blur and keyboard will go away. At present this doesn't happen, text input stays focused no matter where I click. Is this expected behaviour, if so how is it usually handled?

<Image source={require('../assets/background.jpg')} style={{width: undefined; height: undefined; flex: 1;}}>
  <View>
    <TextInput placeholder="Email" style={{ width: 200; height: 40; }} />
  </View>
</Image>

推荐答案

不幸的是,这是预期的行为.

Unfortunately that is expected behaviour.

您应该将 TextInput 包裹在 ScrollView(并在需要时禁用滚动),然后使用属性 keyboardShouldPersistTaps="never".

You should wrap TextInput inside ScrollView (and disable scrolling if needed) and then with property keyboardShouldPersistTaps="never".

这篇关于在外部点击时模糊 TextInput的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 14:19