ex-navigation icon indicating copy to clipboard operation
ex-navigation copied to clipboard

Accessing navigator at the root component where StackNavigation is first rendered?

Open sidutta opened this issue 7 years ago • 0 comments

My root index.js looks like the following:

class RelayApp extends Component {
  componentDidMount() {
    OneSignal.addEventListener('received', this.onReceived);
    OneSignal.addEventListener('opened', this.onOpened);
  }

  componentWillUnmount() {
    OneSignal.removeEventListener('received', this.onReceived);
    OneSignal.removeEventListener('opened', this.onOpened);
  }

  render() {
		return (
			<View style={{flex : 1}}>
				<StatusBar
					backgroundColor={'#005054'}
					barStyle='light-content'
				/>
				<NavigationProvider router={Router}>
					<StackNavigation
						id='master'
						initialRoute={Router.getRoute('home', {
														origin : 'index'
													})}
					/>
				</NavigationProvider>
				<ShareModal/>
			</View>
		);
  }
}

export default RelayApp = codePush(withNavigation(RelayApp));

For OneSignal listeners to work when the app is closed, I need to declare the listeners at root. However, to redirect to appropriate screen when notification is opened, I need props.navigator there. How can I achieve the same? I tried the withNavigation decorator and the above, but it doesn't seem to work. I use Relay. Is it necessary to integrate Redux so that I can achieve the above by calling actions on my own store? Isn't there a way to directly call actions on whatever store exnav uses so that I can avoid integrating my own store just for navigation?

sidutta avatar Apr 23 '17 05:04 sidutta