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

当我集中在一个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 } }); 

原来,当input字段在一个ScrollView中时,它们的行为如上所述(你不能只从一个字段到另一个字段)。 我试图在视图中包装TextInputs来解决这个问题,但它没有奏效。

你需要添加keyboardShouldPersistTaps={true}给你ScrollView 。

keyboardShouldPersistTaps bool:

如果input错误,则在键盘启动时轻敲焦点文本input以外的部分将取消键盘。 如果为true,则滚动视图不会捕捉水龙头,并且键盘不会自动closures。 默认值是false。

您可以使用TextInput委托方法使用辞职第一个响应者