2017-04-09 3 views
-1

私はフォーカスを使用して試してみてもautofocus.Usingているネイティブ0.43 例単純なシナリオrefを使用せずにテキスト入力にピントを合わせるにはどうすればよいですか?

<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" /> 

Source Code Source Code NPM

+0

あなたの質問を編集してください、あなたは問題を抱えているコードセクションを追加します。問題の内容を正確に特定せずに300コード行のリンクを追加すると、誰も助けてくれません。 –

+0

は、この問題を理解するためのより簡単なコードを追加しました。 –

答えて

0
constructor(props) { 
    super(props); 
    this.state = { 
    textInputFocus:true 
    }; 
} 

render() { 
<View> 
    <TextInput autoFocus={this.state.textInputFocus} /> 
</View> 
} 

は、このコードを試してみ反応します。

+0

私の元のコードは上記と同じものを使用していて動作しません。 '<リストアイテム textInputAutoFocus = {this.state.userNameAutoFocus} textInputFocus = {this.state.userNameFocus} textInputReturnKeyType = "次">' –

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> 
    ); 
    } 
} 
+0

Iが変更NPMソースファイルにないことを好みます。問題は、refをソースnpmに置くとエラーが発生します。ステートレス関数はrefs.Aboveを使用してはいけません。上記のようなnpmソースファイルを書き直してください。 –

関連する問題