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

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

Open jnak opened this issue 8 years ago • 3 comments

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 :)

jnak avatar Jun 10 '16 19:06 jnak

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

ericvicenti avatar Jun 10 '16 19:06 ericvicenti

@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.
  }}
/>

hedgerwang avatar Jun 10 '16 20:06 hedgerwang

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?

jnak avatar Jun 14 '16 02:06 jnak