繁体   English   中英

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

[英]React native touchable not working with keyboard

我正在使用裸 react-native CLI。

我的模式里面有一个文本输入字段。 在模态中,当我打开键盘时,文本输入旁边的按钮不起作用。 他们在点击而不是工作时关闭键盘。

我尝试使用本机模态模块(使用 KeyboardAvoidingView)并使用react-native-modal

图片

   // 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>

解决此问题的一种方法是将组件包装在 ScrollView 中并使用keyboardShouldPersistTaps道具。

当键盘启动时,“从不”在聚焦文本输入的外部点击会关闭键盘。 发生这种情况时,孩子们将无法获得水龙头。

'always',键盘不会自动关闭,滚动视图不会捕获点击,但滚动视图的子视图可以捕获点击。

'handled',当点击由滚动视图的子级处理(或由祖先捕获)时,键盘不会自动关闭。

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

暂无
暂无

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

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