[英]after typing focus to next text input
假設我有3個帶有TextInput
視圖。
<View style={styles.row}>
<TextInput
ref={'cell_'+i}
maxLength={1}
spellCheck={false}
style={styles.chewy}
onKeyPress={this._onInputFilled} />
</View>
<View style={styles.row}>
<TextInput
ref={'cell_'+i}
maxLength={1}
spellCheck={false}
style={styles.chewy}
onKeyPress={this._onInputFilled} />
</View>
<View style={styles.row}>
<TextInput
ref={'cell_'+i}
maxLength={1}
spellCheck={false}
style={styles.chewy}
onKeyPress={this._onInputFilled} />
</View>
注意ref={'cell_'+i}
,其中i
等於0.2。 現在,當我在cell_0
內鍵入一個char時,如何聚焦(移動光標)到下一個TextInput上。 cell_1
嗎?
試試這個代碼:
<View style={styles.row}>
<TextInput
ref={'cell_'+i}
maxLength={1}
spellCheck={false}
style={styles.chewy}
onKeyPress={this._onInputFilled}
onSubmitEditing={() => this.focusNextField('cell_' + (i+1))}
/>
</View>
<View style={styles.row}>
<TextInput
ref={'cell_'+i}
maxLength={1}
spellCheck={false}
style={styles.chewy}
onKeyPress={this._onInputFilled}
onSubmitEditing={() => this.focusNextField('cell_' + (i+1))}
/>
</View>
<View style={styles.row}>
<TextInput
ref={'cell_'+i}
maxLength={1}
spellCheck={false}
style={styles.chewy}
onKeyPress={this._onInputFilled}
/>
</View>
onSubmitEditing:
focusNextField = nextField => {
this.refs[nextField].focus();
};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.