In React-Native, how can I call popToTop() for each NavigatorIOS tab within TabBarIOS?

221 views Asked by At

The app I am building has a root client object that affects all of the subsequent views of the app. I want the user to be able to change clients and have all of the tabs reset, i.e. popToTop() and update the client appropriately.

I have a TabBarIOS component with 4 tabs, each tab is a NavigatorIOS component that manages the subsequent ListView components. How can I force all the NavigatorIOS components to popToTop() and re-render based on a client change?

Thanks in advance.

1

There are 1 answers

3
ide On BEST ANSWER

One simple approach would be to use an event emitter. Create an event emitter and pass it down to the component that owns the NavigatorIOS components. The owner can use the ref prop of each NavigatorIOS component to get a reference to each navigator.

The owner then can add a listener to the event emitter, and call popToTop() on each navigator when the listener is invoked. Then, it's just a matter of emitting the event when appropriate.