React-native-router-flux: Actions.sceneKey({type: ActionsConst.REPLACE}) isn't working

Created on 20 Jul 2017  路  9Comments  路  Source: aksonov/react-native-router-flux

On v3, to redirect our users from a splash screen to our home screen, we're using something like:

Actions.loggedIn({type: ActionConst.REPLACE})

Expected Behavior

The user would be redirect to the home screen and wouldn't be able to pop to the splash screen.

Current Behavior

Currently, the action type seems to be ignored and the scene isn't replaced, but pushed (I've tested on the example project).

Versions

Update

For this basic scenario, I could easily get to the desired effect through:

Actions.replace('loggedIn');

But with this approach, I noticed that we might have another problem. The replace action isn't part of the react-navigation API, so it's normally a RESET(which wipes the whole navigation state) passing all the past states but the current as the new navigation stack state.

Taking a look on RNRF replace function, it seems (but I can be wrong) that only the new route is added to the new stack which, in the end, is just a reset.

Am I missing something or we can't replace just the current scene? 馃槉

Most helpful comment

Actions.replace('routeName') works. Thanks for your help @aksonov

All 9 comments

Did you try Actions.loggedIn({type: 'replace'})?

@diegocouto Please check latest master

@igorarkhipenko yes, I did! At the time, no luck, but it got fixed already. Thanks for your help! 馃槃

@aksonov, thanks for your work! Adding a {type: ActionConst.REPLACE} now won't perform a push anymore. Unfortunately, the issue with the whole navigation stack being cleaned up on replace remains.

This issue can actually be seen on the example project. Try:
launch -> register page -> register2 page -> replace -> back.

The replace screen should have replaced only the register2 page and, on a back action, should have lead to the register page. What actually happens is that we're redirected to launch, acting as a reset.

I know that this issue isn't well represented by the original title, should I open another one?

Yes, please create new one. Also it would be great if you will try to show me how to solve it with pure ReactNavigation (or just submit PR) - it is how I've fixed issue with 'reset' #2066

As you can see from ReactNavigation docs there is no 'replace' action yet:
https://github.com/react-community/react-navigation/issues/802
Feel free to submit PR, probably we should do it by ourselves (i.e. don't use reactnavigation router) like I did for 'popTo'.

Sure! I don't know if you have a better idea, but I was thinking about rebuilding the stack using the current one (without the current scene, of course) with the new scene on top of it. This would allow us to keep the expected flow.

Yes, something like this

Actions.replace('routeName') works. Thanks for your help @aksonov

Use setTimeout

this.sceneTimeout = setTimeout(() => {
Actions.reset(sceneName); // Also use replace, push anything.
}, 1000);

Was this page helpful?
0 / 5 - 0 ratings