【发布时间】:2021-01-17 00:03:57
【问题描述】:
对我来说,键盘应该在不点击的情况下自动打开,我使用了 react-navigation,所以从一个屏幕到另一个屏幕时自动对焦不起作用
我试过了:
import React, {Component} from 'react';
import {
View,
StyleSheet,
TextInput,
TouchableOpacity,
Keyboard,
} from 'react-native';
export default class App extends Component {
constructor(props) {
super(props);
this.buildNameTextInput = React.createRef();
}
render() {
return (
<View style={styles.container}>
<View
style={{
backgroundColor: 'white',
alignItems: 'center',
flexDirection: 'row',
width: '90%',
paddingHorizontal: 10,
}}>
<TouchableOpacity />
<TextInput
autoFocus={!!this.buildNameTextInput}
ref={this.buildNameTextInput}
style={{backgroundColor: 'white', width: '80%'}}
/>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#8ee3ab',
},
});
但是如果我使用它在进入下一个屏幕后它不起作用, 如果有人有任何解决方案请发布, 提前谢谢....
【问题讨论】:
标签: android keyboard react-native-android autofocus