我在这个模态中有一个Modal
和一个TextInput
,我希望键盘打开,当模态出现时,但是,键盘只出现在IOS
中。
是焦点,但是,键盘仅在用户点击文本输入时显示。
这是我的代码:
export default class MyModal extends React.Component {
componentDidMount() {
this.ref.focus();
}
render() {
return (
<View style={styles.container}>
<Modal
animationType="slide"
transparent
visible={true}
onRequestClose={() => {}}>
<View style={styles.modalViewStyle}>
<View style={styles.modalContainer}>
<TextInput
ref={ref => this.ref = ref}
autoFocus={true}
value={this.props.reflection}
onChange={ e => this.props.onChange('reflection', e) }
/>
</View>
</View>
</View>
</Modal>
</View>)
}
}
您的模态是否从屏幕底部出现?如果是这样,那么键盘可能确实出现了,但它隐藏在模态后面。如果是这种情况,那么根据键盘的事件函数keyboardDidShow, keyboardDidHide
(https://facebook.github.io/react-native/docs/keyboard#docsNav(向上推你的模态(边距底部:键盘高度(。希望这有帮助。