【问题标题】:RN TextInput not lose it's focus and hide it's keyboad when clicked outside of the input在输入之外单击时,RN TextInput 不会失去焦点并隐藏它的键盘
【发布时间】:2022-01-09 22:52:06
【问题描述】:
<SafeAreaView style={[styles.mainContainer, Props.style]}>
  <View style={[styles.titleContainer, Props.titleContainerStyle]}>
    <Text style={[styles.title, Props.titleStyle]}>{Props.title}</Text>
  </View>
  <ScrollView keyboardShouldPersistTaps="never">
    {Props.column === (1 || undefined) ? (
      <TouchableWithoutFeedback
        onPress={Keyboard.dismiss}
        accessible={false}>
        <View style={styles.contentContainer}>
          <TextInput
            placeholder="Hello"
            onChangeText={setInputField}
            value={inputField}
            style={[styles.textInput, Props.textInputStyle]}
          />
        </View>
      </TouchableWithoutFeedback>
    ) : Props.column === 2 ? (
      <View>
        <Text>Input2</Text>
      </View>
    ) : Props.column === 3 ? (
      <View>
        <Text>Input3</Text>
      </View>
    ) : (
      <View>
        <Text>Select Values between and 1 and 3 </Text>
      </View>
    )}
  </ScrollView>
</SafeAreaView>

我已经搜索了解决方案并找到了thisthis one,但即使尝试了这些链接中提到的内容,它仍然不会失去焦点并隐藏键盘。 (我只在android模拟器中检查过)

【问题讨论】:

    标签: android react-native react-native-textinput


    【解决方案1】:

    删除keyboardShouldPersistTaps

    并使用可触摸的删除来删除keyboard.dismiss函数。

    在没有任何额外内容的情况下单击外部功能时,滚动视图会关闭焦点。

    【讨论】:

    • 不,它仍然没有失去焦点
    猜你喜欢
    • 2022-11-15
    • 1970-01-01
    • 1970-01-01
    • 2017-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多