无法从一个TextInput轻按到另一个 [英] Can't tap from one TextInput to another

查看:94
本文介绍了无法从一个TextInput轻按到另一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我专注于一个TextInput时,点击另一个TextInput字段并不能达到我的期望(将 focus 更改为该TextInput).

When I'm focused in one TextInput, tapping in another TextInput field doesn't do what I'd expect (change focus to that TextInput).

相反,它只是模糊当前的TextInput,需要第二次点击来聚焦下一个TextInput.

Instead, it simply blurs the current TextInput, requiring a second tap to focus the next TextInput.

有什么方法可以做到吗,或者这是 React Native 的当前缺点吗?

Is there some way to do this, or is this a current shortcoming of React Native?

示例代码:

class MyTest extends Component {
  render() {
    return (
      <ScrollView style={styles.container}>
        <View>
          <TextInput style={styles.textInput} />
          <TextInput style={styles.textInput} />
        </View>
      </ScrollView>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#ddd',
    paddingTop: 64
  },
  textInput: {
    backgroundColor: '#fff',
    borderColor: '#000',
    borderWidth: 1,
    height: 46,
    paddingLeft: 10
  }
});

结果是,当输入字段位于ScrollView内时,它们的行为如上所述(您不能仅从一个字段点击到另一个字段).我尝试将TextInputs包装在View中以解决此问题,但这没有用.

Turns out, when the input fields are within a ScrollView, they behave as I described above (you can't just tap from one field to the other). I tried wrapping the TextInputs in a View to remedy this, but it didn't work.

推荐答案

您需要向您添加keyboardShouldPersistTaps={true}

键盘应该持久击打布尔值:

如果为false,则在键盘向上按下时在聚焦文本输入的外部轻击可关闭键盘.设置为true时,滚动视图将 不能抓住水龙头,键盘也不会自动关闭.这 默认值为false.

When false, tapping outside of the focused text input when the keyboard is up dismisses the keyboard. When true, the scroll view will not catch taps, and the keyboard will not dismiss automatically. The default value is false.

这篇关于无法从一个TextInput轻按到另一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆