Tell us which versions you are using:
If opening the screen with the key 'main', currentScene should show the main screens key
If the screen opens with the key 'main' it should show this key in currentScene, but it shows the previous screens key which main was mounted from
@SourceCipher Could you reproduce this issue with Example project? The main difference between current RNRF version and older is that currentScene is set AFTER component is mounted/rendered (because React Navigation does that). So for custom navbars you have to read currentScene from actual navigation.state (because it is passed before rendering), not Actions.currentScene
You may also check ReduxExample, how it renders 'current scene' (as name prop): https://github.com/aksonov/react-native-router-flux/blob/7d4d2880a11d5125ee698a044b31ae1fc4b1aee6/ReduxExample/src/home.js#L11
@aksonov I am using mobx but I dont think adding with observables is a good idea. I will try using navigation.state even tho not really sure how to implement it :/ But using Actions.currentScene on componentDidMount is still showing the wrong scene tho
For mobx it is even easier (we are using it) - just create simple mobx store navStore and with one observable scene and setScene action, then pass onStateChange param to Router:
<Router onStateChange={() => navStore.setScene(Actions.currentScene)}>...</Router>
and then you can observe navStore from your components and use navStore.scene
@aksonov oh I see.. I think I can do that with the mobx the same way as well
Updated: Your solution worked after I used this with Mobx. Well done
Thank you @SourceCipher for letting us know that the solution provided worked. Closing this one.
If you implement onEnter event in the scene, the currentScene updates correctly.
Most helpful comment
For mobx it is even easier (we are using it) - just create simple mobx store
navStoreand with one observablesceneandsetSceneaction, then passonStateChangeparam to Router:<Router onStateChange={() => navStore.setScene(Actions.currentScene)}>...</Router>and then you can observe
navStorefrom your components and usenavStore.scene