ptomasroos / react-native-tab-navigator

A tab bar that switches between scenes, written in JS for cross-platform support
MIT License
2.4k stars 415 forks source link

Scene transition notification #15

Closed mrlaessig closed 8 years ago

mrlaessig commented 8 years ago

I'm trying to figure out how to get some kind notification if the user switches between scenes. I need the notification to stop/pause a video in one if my scenes. Otherwise it continues playing in the background. I didn't find anything in the code or in the doc. Is there some workaround for this or did I miss something.

Thanks

ide commented 8 years ago

The way TabNavigator switches tabs is that you decide which TabItem has the prop selected={true}, which is determined by your code. So when you change which tab is selected, that's when you'd know that the user is switching between scenes.

mrlaessig commented 8 years ago

Yes, thats true. I figured out that the video doesn't stop because only the selected scene is going to be rerendered. This causes the player to continue playing in the background after the scene transition.

ide commented 8 years ago

We keep the scenes around because they might contain UI state (e.g. scroll position, how far you've watched a video). Sounds like you have enough to work with to come up with a solution.

mrlaessig commented 8 years ago

Just in case someone comes by, my solution to the problem: Since only the selected scene is getting updated ("rendered") you can't update other scenes by passing down props. So I used a EventEmitter to emit a transition event, when the user is switching between scenes.