我正在使用自定义键盘。在那里我使用CustomTextInput代替TextInput。一切运作良好,但我想将输入字段集中在功能上。
<CustomTextInput customKeyboardType="hello"
onFocus={() => this.onFocus('fieldname')}
selectTextOnFocus={ true }
ref="TextInput"
underlineColorAndroid = 'transparent'
onChangeText={(value) => this.setState({fieldname:this.onChange(value)})}
/>
在功能如下: -
function () {
Keyboard.dismiss();
this.refs.TextInput.focus();
}
但我收到一个错误: - this.refs.TextInput.focus不是一个函数。基本上我的focus()函数不起作用。
请帮忙!
我尝试了this.refs['TextInput'].focus()
,它对我有用。你可以为Textinput
的onFocus
编写一个函数,在这个函数dimiss默认键盘中,午餐你的自定义键盘并再次关注你的TextInput
。我希望它会有所帮助。
这是我的代码:
<TextInput
style={{ height: 40, width: 200 }}
ref="TextInput"
/>
<TouchableOpacity
onPress={() => { (this.refs['TextInput'] as any).focus() }}>
<Text>Press to focus</Text>
</TouchableOpacity>