react-native-onback
1.0.1 • Public • Published react-native-onback
Handle complex back button flows on android
Version 1.0.0 (breaking.feature.fix)
Usage:
const React = require('react');
const onBack = require('react-native-onback');
class App extends React.Component {
componentDidMount() {
onBack.hook();
}
componentWillUnmount() {
onBack.unhook();
}
render() {
return (
...
);
}
}
- Inside a component with a
Navigator
const React = require('react');
const onBack = require('react-native-onback');
class SomeScreen extends React.Component {
componentDidMount() {
onBack(() => {
BackHandler.exitApp();
}, this);
onBack((ev) => {
if (this.refs.navigator.getCurrentRoutes().length > 1) {
requestAnimationFrame(() => this.refs.navigator.pop());
ev.stopPropagation()
}
}, this);
}
componentWillUnmount() {
onBack.unmount(this);
}
render() {
return (
...
);
}
}
- Inside any other random Component loaded via
navigator
class SomeOtherComponent extends React.Component {
onSomeUserActionRegisterOnBackListener() {
onBack((ev) => {
if (this.state.someCondition) {
this.doSomethingOnBack();
ev.stopPropagation();
}
}, this);
}
componentWillUnmount() {
onBack.unmount(this);
}
render() {
return (
...
);
}
}
Readme
Keywords
nonePackage Sidebar
Install
npm i react-native-onback
Weekly Downloads