question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Navigator] renderScene onBack not working?

See original GitHub issue

Hey, so mistake me if I’m wrong but I’m trying to use the onBack function from the example and it doesn’t do anything. I am trying to have a callback that when I swipe back from my video view to my videos view something happens (like navigator.popToTop()).

Can anyone help me understand how I can create a callback properly when the user swipes back to the scene?

Thanks!

renderScene: function(route, navigator){
  switch (route.id){
    case 'login':
    if(Parse.User.current()){
      return <Feed/>
    }else{
      return <Login/>
    }

    case 'signup':
    return <Signup/>;

    case 'feed':
    return <Feed/>;

    case 'video':
    return <Video name={route.name} url={route.url} onBack={() => {
      console.log('you swiped back!');
    }} />;

    default:
      return <Login/>;
  }
},
render: function(){
  return (
    <Navigator style={{backgroundColor: 'black'}} ref="navigator"
      initialRoute={{id: 'login'}}
      renderScene={this.renderScene}
     />
  )
}

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

3reactions
ericvicenticommented, Jun 21, 2015

Hey! We’re working on making this easier. In the next release (and in master), there is a new way to monitor navigation changes:

this.currentRoute = this.props.navigator.navigationContext.currentRoute;
this.props.navigator.navigationContext.addListener('willfocus', (event) => {
  // this.currentRoute will go away
  // event.data.route will be focused
  this.nextRoute = event.data.route;
});
this.props.navigator.navigationContext.addListener('didfocus', (event) => {
  // this.currentRoute has gone away
  // event.data.route has been focused
  this.currentRoute = event.data.route;
  this.nextRoute = null;
});

In the current release, you can get similar events by adding handlers to the navigator component: (keep in mind this will be deprecated)

<Navigator
  ...
  onWillFocus={(route) => {
    // will switch to `route`
  }}
  onDidFocus={(route) => {
    // did switch to `route`
  }}
/>
0reactions
jtrembackcommented, Jun 24, 2015

👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Navigation back() and goBack() not working
The key property for goBack() is a dynamically created string, created by react-navigation whenever it navigates to a new route.
Read more >
Call a function when focused screen changes
In this guide we will call a function or render something on screen focusing. ... This could cause issues depending on the type...
Read more >
Navigate to a new screen and back
Navigate to a new screen and back · 1. Create two routes. First, create two routes to work with. · 2. Navigate to...
Read more >
Custom Handling the Android Back Button with ... - Code Daily
Not only that you may want to control the back navigation based upon the state of ... onBack); } render() { return this.props.children;...
Read more >
React Navigation re-render / reset previous page's state on ...
Various stackoverflow and medium articles, but not the thing I was looking for. Problem statement: In a react native mobile app, when a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found