gpt4 book ai didi

android - 未定义不是 TextInput onSubmitEditing Focus 的对象

转载 作者:行者123 更新时间:2023-11-28 23:28:35 25 4
gpt4 key购买 nike

当用户按下键盘上的下一个按钮时,我尝试聚焦下一个字段。但我一直收到undefined is not an object (_this2.passwordInput.focus)。

我指的是this实现它的问题。但它没有用。

我有 CustomInputText,这就是我实现它的方式。

<CustomEditText
labelText="Email or Phone Number"
returnKeyType = "next"
onSubmitEditing={ () => this.passwordInput.focus() }
onChangeText={text => this.setState({ username: text })}
blurOnSubmit={false}
/>

<CustomEditText
ref={(ref) => { this.passwordInput = ref; }}
labelText="Password"
secureText={true}
onChangeText={text => this.setState({ password: text })}
/>

CustomEditText.js

const CustomEditText = props => {
return (
<View style={styles.container}>
<SmallText fontFamily="semi-bold" color={props.darkText? Colors.TEXT_PRIMARY_COLOR : "#fff"}>
{props.labelText}
</SmallText>

<TextInput
ref = {props.ref}
blurOnSubmit= {props.blurOnSubmit}
onSubmitEditing = {props.onSubmitEditing}
returnKeyType = {props.returnKeyType}
onFocus = {props.onFocus}
autoCapitalize="none"
editable={props.editable}
onChangeText={props.onChangeText}
keyboardType={props.keyboardType}
{...props}
value={props.value}
/>
{props.secondaryLabelText ? (
<ExtraSmallText
fontFamily="semi-bold"
color={props.darkText? Colors.TEXT_PRIMARY_COLOR : "#fff"}
style={styles.secondaryLabelStyle}
>
{props.secondaryLabelText}
</ExtraSmallText>
) : null}
</View>
);
};

const styles = StyleSheet.create({
container: {
margin: 5
},
textInputStyle: {
backgroundColor: "#fff",
height: 45,
borderRadius: 5,
borderWidth: 1,
padding: 5,
marginTop: 5,
color:"#000"
},
secondaryLabelStyle: {
marginTop: 5
}
});

CustomEditText.propTypes = {
labelText: propTypes.string.isRequired,
secondaryLabelText: propTypes.string,
keyboardType: propTypes.string,
secureText: propTypes.bool,
placeholderText: propTypes.string,
placeholderTextColor: propTypes.bool,
onChangeText: propTypes.func,
darkText: propTypes.bool,
editable: propTypes.bool,
onFocus: propTypes.func,
pointerEvents: propTypes.string,
returnKeyType : propTypes.string,
onSubmitEditing: propTypes.func,
ref: propTypes.func,
blurOnSubmit: propTypes.bool

};

export default CustomEditText;

最佳答案

使用以下代码更新您的 CustomTextInput.js 文件

<TextInput
ref={input => props.inputRef && props.inputRef(input)}
blurOnSubmit= {props.blurOnSubmit}
onSubmitEditing = {props.onSubmitEditing}
returnKeyType = {props.returnKeyType}
onFocus = {props.onFocus}
autoCapitalize="none"
editable={props.editable}
onChangeText={props.onChangeText}
keyboardType={props.keyboardType}
{...props}
value={props.value}
/>

然后像这样使用它

<CustomEditText
inputRef={(ref) => this.passwordInput = ref}
labelText="Password"
secureText={true}
// onChangeText={text => this.setState({ password: text })}
/>

关于android - 未定义不是 TextInput onSubmitEditing Focus 的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57671879/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com