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

Don't render twice when goBack and re navigate on same screen #2331

Closed
thomasarbona opened this issue Aug 7, 2017 · 16 comments
Closed

Don't render twice when goBack and re navigate on same screen #2331

thomasarbona opened this issue Aug 7, 2017 · 16 comments

Comments

@thomasarbona
Copy link

I use StackNavigator for a small application with some screens.

Current Behavior

When I am on screen B, goBack on screen A (B was unmount) and re navigate on B, B is re-mount.

Expected Behavior

I expect that the StackNavigator keep screen B mount so when I re navigate on B it don't render it twice.
How to do that ? Should I navigate without goBack ? (I use fade transition)

Your Environment

software version
react-navigation 1.0.0-beta.11
react-native 0.43.4
node 6.10.3
npm or yarn 3.10.10
@spencercarli
Copy link
Member

Here's a snack to go along with this.

I'm not sure why you would want the behavior you described as going back would imply you're not longer interested in that screen.

I also imagine it would add a host of issues with tracking navigation state (what happens when you go from screen 1 to screen 2, back to screen 1, then to screen 3 - does screen 2 get unmounted?)

@sseyha
Copy link

sseyha commented Aug 8, 2017

@spencercarli
I'm not sure about @thomasarbona purpose.
But in my thought, he might not want to reload the content data again and again.
And that is what i want either, because i don't want user stuck on reload the content of screen page as always when they navigate from screen to screen.
Hope it will have the solution. Regards, :)

@spencercarli
Copy link
Member

spencercarli commented Aug 8, 2017

@sseyha ah that makes complete sense! Hadn't thought about that - thanks for clarifying.

I'm typically using Redux so in cases like this I would have saved the data to the store after the first screen mount and then any subsequent screen mounts would use the old data and refresh in the background.

@sseyha
Copy link

sseyha commented Aug 8, 2017

@spencercarli
Wow, you have a great idea. You blow my mind now.
It's a bit hard for me, because i'm new with React and Redux as well.
If you don't mind, could you please share us small project about this?
It will be honor and save my day of spending on React Navigation.
Please... :)

@spencercarli
Copy link
Member

spencercarli commented Aug 8, 2017

I don't have any small examples directly related to this but you can see this strategy in action in this repo.

That repo is broken down into a bunch of branches (it's for a course) but the final app can be found on the module-7-lesson-4-upload branch.

@sseyha
Copy link

sseyha commented Aug 8, 2017

@spencercarli I will learn more about redux. However, Thank so much for your guide. Appreciate!

@thomasarbona
Copy link
Author

thomasarbona commented Aug 8, 2017

Thanks for your answers. Like @sseyha said, I don't want to reload the component again and again, but my problem with the reloading isn't about reloading any data (effectively stored in redux) but is to reload a few GLView components that take time to render.
I can't avoid this because react-navigation creates a new instance of screen B when I return on it.

@spencercarli
Copy link
Member

Ah, I see. I'm not sure of a solution to this issue. I suppose I've seen a similar issue when pushing a screen with a map onto the stack. I'll do some thinking and if I can think of anything useful I'll try to add it to this thread.

@sseyha
Copy link

sseyha commented Aug 10, 2017

@spencercarli You how to refresh or reload the current active page of drawer?

@farzd
Copy link

farzd commented Aug 11, 2017

related i guess : #2365

@nhuthan
Copy link

nhuthan commented Oct 13, 2017

+1

@callmejm
Copy link

callmejm commented Nov 17, 2017

+1 , don't want to reload the component again and again when re-enter the screen. Hope there have a solution for this. Because I also finding solution Close screen / unmount screen

@kelset kelset removed the bug label Dec 3, 2017
@kelset
Copy link

kelset commented Dec 3, 2017

Pinging OP @thomasarbona since this issue has not been active for a while, and it's related to an old version of the lib.

Please let me know if you want this to remain open; if I get no answer in the next 7 days I will close it.

Moreover:

When I am on screen B, goBack on screen A (B was unmount) and re navigate on B, B is re-mount.

This is literally the way a stack is supposed to work.

If there are data you need to manage/show in the second screen, you need to use a state manager like Redux. Or you could use a tab navigator without showing the tabbar.

@kelset
Copy link

kelset commented Dec 10, 2017

Hi there @thomasarbona ,

In an effort to cleanup this project and prioritize a bit, since this issue had no follow up since my last comment I'm going to close it.

If you are still having the issue with the latest version (especially if it's a bug report) please check the current open issues, and if you can't find a duplicate, open a new one that uses the new Issue Template to provide some more details to help us solve it.

@ShamarYarde
Copy link

ShamarYarde commented May 13, 2018

To the above posters that want to reload the content data, you can create a function which resets the data to their original state. An example is as follows:

onPress(){ this.setState({ value1: 'value1', value2: 'value2' } }

@emilemoureau
Copy link

Hello! Someone found a solution?

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

No branches or pull requests

10 participants