当用户按下键盘上的下一个按钮时,我试图聚焦下一个字段。但我一直在努力undefined is not an object (_this2.passwordInput.focus).
我有CustomInputText,这就是我实现它的方式。
labelText="Email or Phone Number"
returnKeyType = "next"
onSubmitEditing={ () => this.passwordInput.focus() }
onChangeText={text => this.setState({ username: text })}
blurOnSubmit={false}
/>
ref={(ref) => { this.passwordInput = ref; }}
labelText="Password"
secureText={true}
onChangeText={text => this.setState({ password: text })}
/>
CustomEditText.jsconst CustomEditText = props => {
return (
{props.labelText}
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 ? (
fontFamily="semi-bold"
color={props.darkText? Colors.TEXT_PRIMARY_COLOR : "#fff"}
style={styles.secondaryLabelStyle}
>
{props.secondaryLabelText}
) : null}
);
};
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;