-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Issues with Android's hardware back button with Tabs #3184
Comments
Could you try with most recent version and let me know if is still broken? |
@daviscabral, will test tomorrow |
Please update your React and React Native versions and also try to use |
I had attempted to do with previously with React |
Those versions aren't compatible like I told you in the other ticket. About the hardware back button - that also happens with React Navigation when the POP action is called. That seems like a good enhancement to me. I don't have time now to work on that, but if someone else decide to take stab ;-) |
@daviscabral Thanks for helping me work through this. We're slowing making progress. I'm now using While I am still having the original problem of the software back button still skipping views, I've also noticed that tapping through the tabbar, and pressing back, will take you to the first tab. Not the previously selected ones.
Going from |
That's because of the navigator reference that is used. The default back action is dispatched from there, what causes the nested navigators to be ignored. To fix that you will need to override the back handler from your |
Interesting. @daviscabral, you'd suggest keeping my own stack of views and then just going back to the previous one? Does the |
This does not seem to get triggered 😨 export default class App extends React.Component {
render() {
return (
<Router
scenes={Routes}
onStateChange={() => console.warn('changed')}
/>
);
}
} |
@daviscabral yeah, haha. Good stuff! I think this thread can be closed now 🎉 Thanks again. I'll come up with a nice example for the back button and update the docs. |
class App extends React.Component {
constructor() {
super();
this.state = {};
this.state.routes = [Actions.currentScene.replace('_', '')];
this.state.logged_in = false;
}
async onStateChange() {
const route = Actions.currentScene.replace('_', '');
const routes = this.state.routes;
if (route !== routes[routes.length - 1]) {
routes.push(route);
console.warn('pushed', routes);
await this.setState({ routes });
}
}
async hardwareBackPress() {
const { routes, logged_in } = this.state;
if (!!routes.length) {
const last_route = routes[routes.length - 2];
if (logged_in && last_route === 'Login') {
return true;
}
routes.pop();
await this.setState({ routes });
Actions[last_route]();
}
return true;
}
componentDidMount() {
Auth.isAuthenticated().then(logged_in => this.setState({ logged_in }));
BackAndroid.addEventListener('hardwareBackPress', () => this.hardwareBackPress());
}
componentWillMount() {
BackAndroid.removeEventListener('hardwareBackPress', () => this.hardwareBackPress());
}
render() {
return (
<Router scenes={Routes} onStateChange={() => this.onStateChange()}/>
);
}
} @daviscabral Here's what I am doing to make the back button work as expected 😸 |
I will keep this opened to track the PR that I might work in the weekend to make it easier. |
I believe a custom reducer also can make it work without needing to change the lib. I am inclined to close this issue since the lib is flexible enough to allow a proper fix. What do you think? |
Version
Tell us which versions you are using:
4.0.0-beta.27
(v3 is not supported)0.54.0
Expected behaviour
When navigating to a
Scene
outside ofTabs
from within tabs and then pressing the hardware back button, you should then be navigated back to the previous scene within tabs.Actual behaviour
When navigating to a scene outside of tabs from within tabs and then pressing the hardware back button it navigates you to the last visited page outside of tabs. Ignoring the scene within tabs which was previously visited.
Steps to reproduce
For non-obvious bugs, please fork this component, modify Example project to reproduce your issue and include link here.
page_2
page_3
page_1
Minimal example router:
Edit: Now seeing the same issues on react-native-router-flux
4.0.2
The text was updated successfully, but these errors were encountered: