首页 文章

如何点击视图中的提交按钮而不必先解除键盘?

提问于
浏览
0

我正在使用react native来实现社区提要 . 在Feed中的每个帖子中,我都可以发表评论,如下所示 .

enter image description here

但是,问题是在我输入评论并想按下右侧的提交图标后,键盘将先解除,然后我才能点击图标提交文本 .

问题:如何在按下提交图标后立即提交我的文本而不点击两次(一次关闭键盘,第二次提交)

这是我的实现的片段://评论代码部分/框

<View style={styles.commentSectionContainer}>
    <View style={[textInputStyle.dark, textInputStyle.compact]}>
      <LocalizedTextInput
        multiline={false}
        autoCorrect={true}
        onChangeText={onCommentTextChange}
        placeholder="placeholder/writeComment"
        style={[textInputStyle.default, {fontSize: 13}]}
        underlineColorAndroid="transparent"
        value={textComment}
        onSubmitEditing={() => {
          if (textComment) {
            onSubmitComment();
          }
        }}
        returnKeyType="send"
     />
     <View style={styles.iconSubmitContainer}>
      <IconButton style={styles.commentSubmit} iconName="send" isDisabled={textComment === ''} onPress={onSubmitComment} hitSlop={hitSlop} />
    </View>
  </View>
</View>

本地化文本输入使用以下textinput

<View style={{flex: 1}}>
  <TextInput
    multiline={multiline}
    style={[defaultStyle, {flex: 1}]}
    underlineColorAndroid="transparent"
    autoCorrect={true}
    {...otherProps}
  />
</View>

这些帖子都包含在scrollView中 .

我尝试使用“keyboardShouldPersistTaps”和keyboardDismissMode =“Drag-on”,但它不会产生预期的体验 . 用户应该能够通过点击textinput框外的任何地方而不需要滚动来关闭键盘 .

2 回答

  • 0

    如果你的父组件是 ScrollView 组件,那么传递prop keyboardShouldPersistTaps="always" 应该可以解决问题 . 请参阅官方文档here .

  • 0

    由于Ankit建议需要将prop传递给滚动视图,但如果没有给出所需的结果,TextInput有一个blur()方法,您可以使用该TextInput的ref调用该方法 . 也许这会有所帮助 .

相关问题