Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to link 'from outside' into Navigator (for example from a global footer)

With React Navigation, is there a way to link from outside to a specific path/screen inside a Navigator?

For example to implement a global footer, like this:

<Provider store={store}>
  <View>
     <AppNavigator />
     <MyFooter /> // Link from here to a path/screen inside AppNavigator
  </View>
</Provider>
like image 610
cseelus Avatar asked Sep 13 '25 03:09

cseelus


1 Answers

I think refs might work here. If you want to use Navigator from the same level you declare it you can use react's refs and pass props to MyFooter. Look at example in official documentation.

const AppNavigator = StackNavigator(SomeAppRouteConfigs);

class App extends React.Component {
  someFunction = () => {
    // call navigate for AppNavigator here:
    this.navigator && this.navigator.dispatch({ type: 'Navigate', routeName, params });
  }
  render() {
    return (
      <View>
        <AppNavigator ref={nav => { this.navigator = nav; }} />
        <MyFooter someFunction={this.someFunction} />
      </View>
    );
  }
}
like image 74
mradziwon Avatar answered Sep 14 '25 17:09

mradziwon