expo / ex-navigator

Route-centric navigation built on top of React Native's Navigator
MIT License
522 stars 68 forks source link

Hook up navigation bar methods to the scene state and props #134

Closed varungupta85 closed 8 years ago

varungupta85 commented 8 years ago

I know that the repo suggests using ex-navigation instead of this and that there isn't much active development going into this repo but I have been using this repo for some time and not in a state to move to the newer repo right now.

I wanted to know if there is a way to hook up navigation bar methods (right button, left button) to the state and props of the scene that is currently rendered in the navigator. For e.g. I have some input boxes in the scene and I want to provide a Done right button in the navigation bar which when clicked, collects the user inputs (state and props for the screen) and do something with it. I am unable to find a way to achieve it using this library and wanted to check if I am missing anything or if there is an accepted pattern to achieve it.

Thanks!

cc @brentvatne @ide

ide commented 8 years ago

The recommended pattern is to share an EventEmitter (or another message-passing mechanism of your choice) between the components in your navigation bar (ex: Done button) and your scene component.

varungupta85 commented 8 years ago

@ide, Thanks a lot for the tip. EventEmitter would be perfect for this use case.