How would I get the current scene I am on, maybe the key of the scene?
I can't find any apparent way in the documentation.
Thanks.
Take a look at the detailed example, specifically the reducerCreate and it's usage. By creating your own reducer, you can keep track of what scenes are active.
Edit: Link to example
Where would you keep track of the current scene then, if I may ask?
We have been trying to use a redux reducer reacting to FOCUS to save the currently focused scene, but on jump between tabs, although the JUMP goes to the right tab, the scene FOCUSed will be the parent scene (tabs).
Surely there has to be a somewhat easy way to know which scene you are currently on?? Since non of the scenes are unmounted, it is essential to have a way of finding out if a scene is currently focused or not.
Also related to https://github.com/aksonov/react-native-router-flux/issues/925
@cridenour I think RNRF should enable us to track current focused view without need of redux,
I agree this seems like a high barrier of entry for this specific task - but this library was made to be used with a flux implementation (I personally use Alt) and to ignore that aspect means we would end up writing a lot of code into the library that would duplicate code that's already in a most apps, or muddle the right way to integrate this library into your app.
Not saying that one way is right or wrong, but this isn't a simple case of missing functionality. More of a case of the community using this library for basic routing (since there is an absence of a easily configurable one in React itself) vs the intended use when it was built (to integrate the navigation into your flux implementation of choice).
@cridenour can you explain how you would keep track of which scene is displayed on screen through the reducer? for instance, in the example you linked to, the "error" modal would not dispatch a FOCUS action, only a PUSH. i understand how to track the focused scene, but that doesn't necessarily indicate which scene is actually dispalyed. What am I missing here?
If using modals and drawers it's very difficult to find the current scene. I can't follow the logic of why sometimes the redux state (I used the example reducer) will contain no scene children at all or perhaps many scene children. Sometimes the children will contain sibling scenes. I can't find any way to accurately determine what scene the user is actually on.
Just tried this for hours.
This is impossible using this library. Once you think you're getting the hang of it some different behavior while navigating for a few more seconds breaks your logic.
Argh...
@cridenour please update the link to example, it's currently giving me 404
@y2k-shubham He means this one: https://github.com/aksonov/react-native-router-flux/blob/master/docs/v3/DETAILED_EXAMPLE.md
For anyone who missed the one line where it says how to get the current scene under v4 changes... and ends up here
Actions.currentScene is what you are looking for.
onBackPress(){
if (Actions.currentScene == "Home") {
Alert.alert(
'Tho谩t 峄﹏g d峄g',
'B岷 c贸 mu峄憂 tho谩t kh么ng?', [{
text: 'Cancel',
onPress: () => console.log('Cancel Pressed'),
style: 'cancel'
}, {
text: 'OK',
onPress: () => BackHandler.exitApp()
}, ], {
cancelable: false
}
)
return true;
}
}
I need a snippet version for v3 without redux :(
Most helpful comment
For anyone who missed the one line where it says how to get the current scene under v4 changes... and ends up here
Actions.currentScene is what you are looking for.