I can not update a status with the current page when Navigator executes its pop method

1

I can not update the status of my App.js with the current page when Navigator executes its pop method in React-Native (0.26).

I update the status with the function goto.

  _goto(currentPage, scene) {
    this.setState({currentPage});
    this._navigator.push({
      id: currentPage,
    });
  }

This is the function that renders scenes in the Navigator.

  _renderScene(route, nav) {
    curPage = route.id;
    switch (route.id) {
       ...
   }

Teng ona function that runs when I press the back button on Android.

  _patras(){
    if(curPage != 'MainPage' && curPage != 'SplashPage'){
      this._navigator.pop();
      return true;
    }
  }

And this is the render method of my App.js where I have the TabBar.

var currentPage = this.state.currentPage;
if (currentPage != 'SplashPage'){
  if (this.isAndroid){
    TBar = (<TabBar goto={(page) => this._goto(page)} currentPage={currentPage}/>);
  } else {
    TBar = (<TabBarIOS goto={(page) => this._goto(page)} currentPage={currentPage}/>);
  }
}

I use the current page to change the style and disable the TabBar button that corresponds to it. With this code it works well for me if I move forward but when I turn back it does not update me since I can only take it through the goto. If I put a this.setState in the renderScene method the application is blocked.

What would be the best way to do it?

    
asked by Carlos Quiroga 24.05.2016 в 12:13
source

1 answer

0

What must happen is that tabbar creates a new navigator, which means that the previous route does not exist in that new browser, so it can not return to a route that does not exist inside the browser.

My recommendation is to use react-native-router-flux that allows you to use the clone attribute that copies the route in the browser allowing you to return from any view.

    
answered by 25.03.2017 в 19:37