Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TextInput field lost focus for each character input #3177

Closed
keneseu opened this issue Aug 14, 2018 · 2 comments
Closed

TextInput field lost focus for each character input #3177

keneseu opened this issue Aug 14, 2018 · 2 comments

Comments

@keneseu
Copy link

keneseu commented Aug 14, 2018

Version

Tell us which versions you are using:

  • react-native-router-flux v4.0.0 (I think is recently renamed from 4.0.1 back to 4.0.0)
  • react-native v0.56.0

Expected behaviour

The TextInput field to accept the input text, and to be eventually passed as a prop to another scene.

State and helper function defined ...

state = {
task: ''
}
updateTask = (task) => {
this.setState({task: task});
}

          <Scene
            key="tasks"
            component={Tasks}
            title="Task"
            hideNavBar
            initial
            task = {this.state.task}
            updateTask = {this.updateTask}
            />

...

            <Input
              placeholder="Please enter task ..."
              label="Task :"
              value={this.props.task}
              onChangeText={this.props.updateTask}
            />

Actual behaviour

The TextInput field lost focus at each character input. The same code works well for earlier versions e.g. version 4 betas.

Steps to reproduce

For non-obvious bugs, please fork this component, modify Example project to reproduce your issue and include link here.
1.
2.
3.

@mwskwong
Copy link

mwskwong commented Aug 18, 2018

Try to do the following:

In your Scene 1:

updateTask = (value) => {
    this.setState({
        task: value
    });    
};

// ...

<Input
    placeholder="Please enter task ..."
    label="Task :"
     value={this.state.task}
    onChangeText={this.updateTask}
/>

When you want to pass the value to another scene, let say you want to navigate to Scene 2 on button press,

onPress = () => {
    Actions.push("scene2", {incomingTask: this.state.task}); // passing state.task of Scene 1 to props.incomingTask of Scene 2
}

@daviscabral
Copy link
Collaborator

Thank you @matthewkwong2.

I believe the way you are working with controlled/uncontrolled components here might be causing it. If the suggestion from @matthewkwong2 does not work for you or you are still having issue, please provide an example with the code from Example folder that I'll take a look.

I found this article really interesting and helpful to do a better use of controlled/uncontrolled components, it might help you like helped me:
https://goshakkk.name/controlled-vs-uncontrolled-inputs-react/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants