React-native-router-flux: currentScene is not showing the currently mounted screens key

Created on 10 Aug 2018  路  7Comments  路  Source: aksonov/react-native-router-flux

Version

Tell us which versions you are using:

  • react-native-router-flux 4.0.0-beta.40
  • react-native 0.55.4

Expected behaviour

If opening the screen with the key 'main', currentScene should show the main screens key

Actual behaviour

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

question

Most helpful comment

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

All 7 comments

@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

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

YouYII picture YouYII  路  3Comments

sarovin picture sarovin  路  3Comments

llgoer picture llgoer  路  3Comments

booboothefool picture booboothefool  路  3Comments

xnog picture xnog  路  3Comments