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

Is there a way to "hide" a scene but not "pop" a scene? #2906

Closed
Shu-Ji opened this issue Feb 27, 2018 · 3 comments
Closed

Is there a way to "hide" a scene but not "pop" a scene? #2906

Shu-Ji opened this issue Feb 27, 2018 · 3 comments

Comments

@Shu-Ji
Copy link

Shu-Ji commented Feb 27, 2018

Version

Tell us which versions you are using:

  • react-native-router-flux v4.0.0-beta.28
  • react-native v0.53.0

Expected behaviour

Keep components in memory.

Actual behaviour

Actions.pop() will destroy the current scene.

Steps to reproduce

There are 2 tabs in my app:

Router(backAndroidHandler={() => {
  Actions.pop();
  return true;
}})
  Stack
    Scene(key=main initial={is_user_authed})
        Tabs(key=tabs)
          Scene(key=home)
          Scene(key=settings)
    Scene(key=profile)
    Scene(key=login initial={!is_user_authed})

We know tabs will keep tab-component-scene in memory.
See if I visit tab-home, do scroll for a while, then visit tab-settings, do somthing.
If I click tab-home icon, the scrollbar keeps well. This is the default and expected behavor.

In the tab-settings-scene, I have a button.

  < Button onPress={() => {
        Actions.push('profile');
  }}>Go to profile</Button>

When I click this button, the profile screen shows, then I tap the Android Back Button, the profile-scene unmounted. I want make the profile mounted in forever.

In my Router, I write a backAndroidHandler, call Actions.pop().

Is there a way to not pop the profile-scene, as profile is a tab like tab-home, so that I can keep the tab-profile state(such as the scrollbar position) if user visit again?

Maby a Actions.hide().

Or:

Is there a "virtual tab" that is a tab-scene, but invisible in tabbar?

Router
  Stack
    Scene(key=main initial={is_user_authed})
        Tabs(key=tabs)
          Scene(key=home)
          Scene(key=settings)
          Scene(key=profile lazy={true} virtual={true})  {/* see the virtual props */}
    Scene(key=login initial={!is_user_authed})

So that user will see two tabs(home and settings) in the tabar, but in real, I have three tabs(home, settings and profile).

Sorry for my poor English.

What I want to do is something like this:

In jQuery/Bootstrap,
I have a <div class="modal">...</div>,
then I can use $(".modal").show() / $(".modal").hide(),
But not $(".modal").create() / $(".modal").destory()

I tried the Modal and Lightbox component, it will also unmount.

The same question in react navigation:
react-navigation/react-navigation#2331
react-navigation/react-navigation#2365
I created a expo repo snack:
image
Everytime I enter the detail page, it will remount(the number changes), which I don't want.

@aksonov
Copy link
Owner

aksonov commented Aug 8, 2018

You may try to use tabs with hideTabBar so all your scenes will not be destroyed

@aksonov aksonov closed this as completed Aug 8, 2018
@qiruiqq3
Copy link

how to fix this issue? tks

@Riant
Copy link

Riant commented Jun 19, 2019

I think the drawerNavigator is a better solution, but not the best solution.

https://react-navigation.canny.io/feature-requests/p/is-there-a-way-to-keep-some-screen-alive-after-goback-similar-as-the-drawer-navi

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

No branches or pull requests

4 participants