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

Adding to the stack without navigating to the page #2848

Closed
BGrayDevelopment opened this issue Feb 1, 2018 · 2 comments
Closed

Adding to the stack without navigating to the page #2848

BGrayDevelopment opened this issue Feb 1, 2018 · 2 comments

Comments

@BGrayDevelopment
Copy link

First off, love rnrf it's great. Routes are still a fairly new concept to me so it could be something wrong in my implementation of solving the problem.
What I'm trying to achieve is from the Login Page have some logic to determine what the User's first page is after login. For instance the user can set a favourite device and from Login navigate straight to this page, if the user doesn't have a favourite set, it should go to the default Home Page.
After this though, from the Users Favourite Device Page they should be able to pop to the default home page.

Login Page -> User's Favourite Device Screen (if exists) OR -> Home Page (no favourites set)

Then from:
Users Favourite Device Screen -> Pop() -> Home Page

So effectively I'm trying to add the Home Page to the stack (or Route?) and then add the Device Screen as well, so I can pop back.

Version

  • react-native-router-flux v4.0.0-beta.22
  • react-native v0.49.1,

Expected behaviour

To add to the stack (Or Route) without actually navigating to the page

Actual behaviour

The only way I can think of doing it is to load the first page initially then quickly load the next. The screen flickers and isn't a very elegant solution.

@Blapi
Copy link
Collaborator

Blapi commented Feb 1, 2018

Do something like :

For Android BackButton :

    this.usersFavouriteDeviceBackPressHandler = BackHandler.addEventListener('usersFavouriteDeviceBackPress', () => {
      if (Actions.currentScene === 'usersFavouriteDevice') {
        Actions.home({ type: 'replace' })
        return true
      }
      return false
    })

(don't forget to remove the listener in WillUnmount)

And then, if you're using a back button on your screen, override your code and implement something like the Android code, meaning that instead of pop your scene, you replace it with your home scene

@BGrayDevelopment
Copy link
Author

Thanks for your ideas, I ended up creating a flag that is set if the homePage is loaded to the stack or not. Then created a backhandler like:

if (this.props.homePageLoaded) {
        //else we can pop to it
        Actions.pop();
    }
    else {
        //if home page is not loaded in the stack we need to navigate to it
        Actions.Home();
    }
    return true;
}

Then on the ComponentWillMount on the Home page I set the homePageLoaded to true. Otherwise it's default is false.

@Blapi Blapi closed this as completed Aug 1, 2018
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

2 participants