1

If I have a navigator with two views:

  _renderScene(route, navigator) {
    if (route.id === 1) {
      return <PageOne navigator={navigator}
                         setIndex={this.setIndex} />
    } else if (route.id === 2) {
      return <PageTwo navigator={navigator}
                      index={this.state.index} />
    }
  }

And when I'm on PageOne, I want to begin to preload PageTwo. Is there an easy way to handle this asynchronous loading so the page is ready when the user clicks to navigate?

Imagine page one is a scrollview, and page two is a list of images, so you want to start loading the list of images for view2 as soon as you scroll to a tab. That way when you select the tab it will begin loading the associated view.

The real confusion for me is how to begin loading a page in the background?

1 Answer 1

1

I would initially create both PageOne and PageTwo in the constructor of this component, then pass the relevant one in the render.

Something like:

_initComponent() { //to call on constructor, or right after component mounted, or when props changed. make sure this does only run once in the component lifetime.
    this.page1 = <PageOne navigator={navigator}
                         setIndex={this.setIndex} />
    this.page2 = <PageTwo navigator={navigator}
                      index={this.state.index} />
}

_renderScene(route, navigator) {
    if (route.id === 1) {
      return this.page1
    } else if (route.id === 2) {
      return this.page2
    }
  }
Sign up to request clarification or add additional context in comments.

1 Comment

so you would only have it load the two pages when the app is opened?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.