[英]after typing focus to next text input
let say I have 3 views with TextInput
inside it. 假设我有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>
notice ref={'cell_'+i}
where i
equal to 0..2. 注意ref={'cell_'+i}
,其中i
等于0.2。 now when I type in a char inside cell_0
how to focus (move the cursor) to the next TextInput ie. 现在,当我在cell_0
内键入一个char时,如何聚焦(移动光标)到下一个TextInput上。 cell_1
? cell_1
吗?
Try this code : 试试这个代码:
<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: onSubmitEditing:
focusNextField = nextField => {
this.refs[nextField].focus();
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.