无法从一个 TextInput 点按到另一个

ffx*_*sam 3 ios react-native

当我专注于一个领域时TextInput,点击另一个TextInput领域并没有达到我所期望的(将焦点转移到那个领域TextInput)。

相反,它只是模糊了当前TextInput,需要第二次点击才能聚焦下一个TextInput

有没有办法做到这一点,或者这是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
  }
});
Run Code Online (Sandbox Code Playgroud)

事实证明,当输入字段在 ScrollView 中时,它们的行为与我上面描述的一样(您不能只是从一个字段点击到另一个字段)。我尝试将 TextInputs 包装在 View 中以解决此问题,但没有奏效。

Mat*_*olo 5

您需要添加keyboardShouldPersistTaps={true}到您的ScrollView

keyboardShouldPersistTaps 布尔值:

如果为 false,则在键盘向上时在焦点文本输入之外点击会关闭键盘。当为 true 时,滚动视图不会捕捉点击,并且键盘不会自动关闭。默认值为假。