Last active
August 1, 2017 20:54
-
-
Save JodusNodus/1f0c246f6933b69cae195e20f0ef84a5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BackController extends Component { | |
static propTypes = { | |
onBack: PropTypes.func.isRequired | |
} | |
componentDidMount = () => | |
BackHandler.addEventListener('hardwareBackPress', this.handleBack) | |
componentWillUnmount = () => | |
BackHandler.removeEventListener('hardwareBackPress', this.handleBack) | |
handleBack = () => this.props.onBack() | |
render = () => null | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SomeView extends Component { | |
handleBack = () => {} // ? Do some navigation logic ? | |
render = () => ( | |
<View> | |
<BackController onBack={this.handleBack} /> | |
<NavController show /> | |
<Text>Some text</Text> | |
</View> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment