简体   繁体   English

反应本机可触摸不适用于键盘

[英]React native touchable not working with keyboard

I am using bare react-native CLI.我正在使用裸 react-native CLI。

My modal has a text input field inside.我的模式里面有一个文本输入字段。 In the modal, when I open the keyboard, the buttons next to the text input are not working.在模态中,当我打开键盘时,文本输入旁边的按钮不起作用。 They close the keyboard when tapped instead of working.他们在点击而不是工作时关闭键盘。

I tried it using the native modal module (with KeyboardAvoidingView) and using the react-native-modal我尝试使用本机模态模块(使用 KeyboardAvoidingView)并使用react-native-modal

Image图片

   // with react-native-modal
  <View style={styles.PostCommentArea}>
        <View style={styles.PostBody}>
          <Image
            source={{ uri: UserDetails.profile_image }}
            style={styles.UserImg}
          />
          <InputField
            ref={InputRef}
            style={styles.InputField}
            length={0.65}
            hv={0.055}
            placeholder="Add Comment..."
            onSubmitEditing={postComment}
          />
          <TouchableHighlight style={styles.PostBtn} onPress={postComment}>
            {PostingComment ? (
              <>
                <Indicator size="small" color={Colors.WHITE} />
              </>
            ) : (
              <IconOutline
                name="arrow-up"
                size={height * 0.027}
                color={Colors.WHITE}
              />
            )}
          </TouchableHighlight>
        </View>
      </View>

One way of fixing this is wrapping the component in a ScrollView and using the keyboardShouldPersistTaps prop.解决此问题的一种方法是将组件包装在 ScrollView 中并使用keyboardShouldPersistTaps道具。

'never' tapping outside of the focused text input when the keyboard is up dismisses the keyboard.当键盘启动时,“从不”在聚焦文本输入的外部点击会关闭键盘。 When this happens, children won't receive the tap.发生这种情况时,孩子们将无法获得水龙头。

'always', the keyboard will not dismiss automatically, and the scroll view will not catch taps, but children of the scroll view can catch taps. 'always',键盘不会自动关闭,滚动视图不会捕获点击,但滚动视图的子视图可以捕获点击。

'handled', the keyboard will not dismiss automatically when the tap was handled by children of the scroll view (or captured by an ancestor). 'handled',当点击由滚动视图的子级处理(或由祖先捕获)时,键盘不会自动关闭。

  <ScrollView keyboardShouldPersistTaps={'handled'}>
  ...
  </ScrollView>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM