ericvicenti / navigation-rfc

Better Navigation in React Native
440 stars 45 forks source link

What would be the right way for scene know it's in focus? #82

Open jnak opened 8 years ago

jnak commented 8 years ago

My use case is that a scene A needs to know it's in focus when the user navigates back from scene B. I would like to decouple the back button from Scene B action from my scene A. Which means I'm looking for a way that animatedView to notifiy that Scene B is back in focus.

Hope it makes sense! Thanks your work btw :)

ericvicenti commented 8 years ago

In componentWillUpdate or componentDidUpdate of the view containing the NavigationAnimatedView, you can detect the case that you are going back from B to A. Then you can adjust the state so that scene A can see the change

hedgerwang commented 8 years ago

@jnak: Please keep in mind that that NavigationAnimatedView is deprecated.

For focus change, there are to ways to detect focus change.

  1. The navigation states is owned and managed by you, so you should be able to detect the focused index changes via your data flow process.
  2. Alternatively, you could rely on the component to tell you what the focus may change.
<NavigationTransitioner
  onTranstionEnd={(currentScenes, prevScenes) => {
    // compute the focus change here.
  }}
/>
jnak commented 8 years ago

Thanks guys for the answers. The onTranstionEnd callback makes the most sense to me. Any interest to add this as a built-in props passed to scenes?