我尝试使用焦点和自动对焦。使用React Native 0.43 示例简单方案
<ListItem
title="Username"
textInput={true}
textInputValue={this.state.userName}
textInputSecureTextEntry={false}
textInputOnChangeText={this
.bindData
.bind(this, 'userName')}
textInputAutoFocus={this.state.userNameAutoFocus}
textInputFocus={this.state.userNameFocus}
textInputKeyboardType="default"
textInputPlaceHolder="Type your Username Here"
textInputContainerStyle={styles.inputFormStyle}
textInputOnSubmitEditing={this
.nextFormComponent
.bind(this, 'userPassword')}
textInputReturnKeyType="next" />
答案 0 :(得分:0)
constructor(props) {
super(props);
this.state = {
textInputFocus:true
};
}
render() {
<View>
<TextInput autoFocus={this.state.textInputFocus} />
</View>
}
试试这段代码。
答案 1 :(得分:0)
你可以尝试:
class App extends React.Component{
componentDidMount(){
this.nameInput.focus();
}
render() {
return(
<View>
<input defaultValue="Won't focus"/>
<input ref={(input) => { this.nameInput = input; }} defaultValue="will focus" />
</View>
);
}
}