Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

currentScene is not showing the currently mounted screens key #3165

Closed
SourceCipher opened this issue Aug 10, 2018 · 7 comments
Closed

currentScene is not showing the currently mounted screens key #3165

SourceCipher opened this issue Aug 10, 2018 · 7 comments
Labels

Comments

@SourceCipher
Copy link

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

@aksonov
Copy link
Owner

aksonov commented Aug 10, 2018

@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
Copy link
Owner

aksonov commented Aug 10, 2018

You may also check ReduxExample, how it renders 'current scene' (as name prop):

<Text style={styles.text}>Current scene: "{this.props.name}"</Text>

@SourceCipher
Copy link
Author

@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

@aksonov
Copy link
Owner

aksonov commented Aug 10, 2018

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

@SourceCipher
Copy link
Author

SourceCipher commented Aug 10, 2018

@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

@daviscabral
Copy link
Collaborator

Thank you @SourceCipher for letting us know that the solution provided worked. Closing this one.

@MasoudShah
Copy link

If you implement onEnter event in the scene, the currentScene updates correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants