Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
102 views
in Technique[技术] by (71.8m points)

javascript - Next Input in React Native using functional component and component Input

i try implemented the next input where user click in enter to react native, but i dont know what i can do

I created a component Input in my components files:

class Input extends React.Component {
constructor() {
    super();

    this.state = {
        hidePassword: true
    }
}

setPasswordVisibility = () => {
    this.setState({ hidePassword: !this.state.hidePassword })
}

render() {
    return (
        <>
            <TextInput
                placeholder={this.props.placeholder ? this.props.placeholder : ''}
                selectionColor='#BA90B7'
                keyboardType={this.props.keyboard ? this.props.keyboard : 'default'}
                maxLength={this.props.maxLen ? this.props.maxLen : 100}
                style={[styles.input,
                {
                    width: this.props.width ? this.props.width : 244,
                    marginLeft: this.props.marginL ? this.props.marginL : 0,
                    marginTop: this.props.marginT ? this.props.marginT : 0,
                    textAlign: this.props.alignText ? this.props.alignText : 'left',
                    fontSize: this.props.fontSize ? this.props.fontSize : 15,
                }]}
                autoFocus={this.props.focus ? this.props.focus : false}
                secureTextEntry={this.props.type == 'security' ? this.state.hidePassword : false}
            />
            <Feather style={[styles.eye,
            {
                marginTop: this.props.marginT ? this.props.marginT : 0,
            }]}
                name={(this.state.hidePassword) ? 'eye' : 'eye-off'}
                size={this.props.eye ? 24 : 0}
                color="#BA90B7"
                onPress={this.setPasswordVisibility}
            />
        </>
    );
}}

and in my file, i call this component third times:

export default function RegisterStep1({ navigation }) {

return (
    <View style={styles.container}>

        <Back navi={() => navigation.navigate('Login')} />

        <Text style={styles.txtNome}>
            Seu nome:
        </Text>

        <Input
            placeholder="nome"
            width={141}
            focus={true}
            maxLen={50}
        />
        <Input
            placeholder="Sobrenome"
            width={141} marginL={164}
            maxLen={50}
        />

        <Text style={styles.txtChoiceUser}>
            Escolha seu
        </Text>
        <Text style={styles.txtUser}>
            usuário:
        </Text>

        <Input
            placeholder="Usuário"
            width={312}
            marginT={200}
            maxLen={30}
        />

        <Button text="Próximo" marginT={250} navi={() => navigation.navigate('RegisterStep2')} />

        <Text style={styles.infoUser}>
            N?o mostraremos seu usuário dentro do aplicativo, ele séra usado somente para logar na plataforma.
        </Text>

    </View>

But i dont can call the "onSubmitEditing" in component Input, and not thought some way to resolve this in my component.

Exist some form this?

question from:https://stackoverflow.com/questions/65919577/next-input-in-react-native-using-functional-component-and-component-input

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I resolved this problem using this in my component:

<Input
            placeholder="nome"
            inputName="nome"
            width={141}
            focus={true}
            onSubmitEditing={(event) => {
                this.sobrenomeInput.focus()
            }}
            maxLen={50}
        />
        <Input
            placeholder="Sobrenome"
            inputName="sobrenome"
            width={141} marginL={164}
            maxLen={50}
            inputRef={(input) => {
                this.sobrenomeInput = input
            }}
            onSubmitEditing={(event) => {
                this.sobrenomeInput.focus()
            }}
        />

and this in my logical componenet:

 {...this.props}
 ref={(input) => this.props.inputRef && this.props.inputRef(input)}

now here it works in two first inputs, but in my third input it does not work, i'm still trying to solve this


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...