2017-06-14 45 views
0

在React-Native> 0.44.0中切換到下一個TextInput的正確方法是什麼?在React-Native中切換TextInputs

我試過它和.focus(),但這沒有奏效。我發現的所有答案都過時了。

+1

你使用對焦() – digit

+0

,它沒有定義,而不是一個功能 –

+0

你嘗試喜歡指派裁判時,你得到了什麼錯誤:' this.refs = el} />' – Raymond

回答

3

您應該指定ref到下一個文本輸入。試試這個

<TextInput 
    placeholder="first" 
    placeholderTextColor="rgba(0,0,0,0.5)" 
    returnKeyType="next" 
    onSubmitEditing={() => this.second.focus()} 
    /> 

    <TextInput 
    placeholder="second" 
    placeholderTextColor="rgba(0,0,0,0.5)" 
    returnKeyType="done" 
    ref={input => (this.second = input)} // This line is important 
    /> 
+1

這個應該肯定有效,試試看。 – Andreyco

+0

我的問題是,我嵌套的元素,並試圖通過'ref'通過我的組件的孩子,但'ref'屬性永遠不會通過React –