Skip to content

Commit

Permalink
feat: Reintroducing correct onBackButtonPress behaviour (#519)
Browse files Browse the repository at this point in the history
Fix back button Android #260
  • Loading branch information
junioroga committed Feb 20, 2021
1 parent 3e3b61f commit 80abcab
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/modal.tsx
Expand Up @@ -7,6 +7,7 @@ import {
KeyboardAvoidingView,
Modal,
PanResponder,
BackHandler,
PanResponderGestureState,
PanResponderInstance,
Platform,
Expand Down Expand Up @@ -261,9 +262,11 @@ export class ReactNativeModal extends React.Component<ModalProps, State> {
if (this.state.isVisible) {
this.open();
}
BackHandler.addEventListener('hardwareBackPress', this.onBackButtonPress);
}

componentWillUnmount() {
BackHandler.removeEventListener('hardwareBackPress', this.onBackButtonPress);
DeviceEventEmitter.removeListener(
'didUpdateDimensions',
this.handleDimensionsUpdate,
Expand Down Expand Up @@ -303,6 +306,13 @@ export class ReactNativeModal extends React.Component<ModalProps, State> {
}
getDeviceHeight = () => this.props.deviceHeight || this.state.deviceHeight;
getDeviceWidth = () => this.props.deviceWidth || this.state.deviceWidth;
onBackButtonPress = () => {
if (this.props.onBackButtonPress && this.props.isVisible) {
this.props.onBackButtonPress()
return true
}
return false
}
buildPanResponder = () => {
let animEvt: OrNull<AnimationEvent> = null;

Expand Down

0 comments on commit 80abcab

Please sign in to comment.