Search code examples
react-nativeautosuggest

I want to navigate from one scene to another in react native


I have a one autocomplete textinput in react native.This autocomplete textinput shows suggestion below the area of textinput and once the user tap on that value ,that value gets set in textinput.Now i want to navigate to next page once the user selects the suggestion value and it set to textinput.Its like when you search search on google it give you suggestions and when you select any one suggestion,here i want to navigate to next scene once user selects suggestion and set those values to textinput


Solution

  • As I understood, you want to push next component on navigation stack with selected props. You need to provide navigation for your components, take a look at navigator component: https://facebook.github.io/react-native/docs/navigator.html

    When navigation is set, you can navigate and pass props with method:

    this.props.navigator.push({
        name: 'name_of_your_component',
        passProps: {
            title: 'Components title',
            data: someObject
        }
    });
    

    If you have a listview providing suggestions, than you can wrap every row to TouchableHighligt. That way you are providing function that fires when row is tapped.

    renderRow(data) {
        return (
                <TouchableHighlight
                    onPress={this.rowTapped.bind(this, data)}>
                    <View>
                        <Text>This is a row.</Text>
                    </View>
                </TouchableHighlight>
            );
    }