Skip to content

Commit

Permalink
Add backHandler only when modal is toggle, do not add action when `al…
Browse files Browse the repository at this point in the history
…waysOpen` props is passed
  • Loading branch information
jeremybarbet committed Jun 21, 2019
1 parent 1cf56d1 commit 2591a8e
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/Modalize.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,11 @@ export default class Modalize extends React.Component<IProps, IState> {
this.onAnimateOpen(this.props.alwaysOpen);
}

BackHandler.addEventListener('hardwareBackPress', this.onBackPress);
Keyboard.addListener('keyboardWillShow', this.onKeyboardShow);
Keyboard.addListener('keyboardWillHide', this.onKeyboardHide);
}

componentWillUnmount() {
BackHandler.removeEventListener('hardwareBackPress', this.onBackPress);
Keyboard.removeListener('keyboardWillShow', this.onKeyboardShow);
Keyboard.removeListener('keyboardWillHide', this.onKeyboardHide);
}
Expand Down Expand Up @@ -220,6 +218,8 @@ export default class Modalize extends React.Component<IProps, IState> {
const { overlay, modalHeight } = this.state;
const toValue = alwaysOpen ? modalHeight - alwaysOpen : height ? modalHeight - height : 0;

BackHandler.addEventListener('hardwareBackPress', this.onBackPress);

this.setState({
isVisible: true,
showContent: true,
Expand Down Expand Up @@ -250,6 +250,8 @@ export default class Modalize extends React.Component<IProps, IState> {
const { overlay } = this.state;
const lastSnap = height ? this.snaps[1] : 0;

BackHandler.removeEventListener('hardwareBackPress', this.onBackPress);

this.beginScrollYValue = 0;
this.beginScrollY.setValue(0);

Expand Down Expand Up @@ -415,7 +417,11 @@ export default class Modalize extends React.Component<IProps, IState> {
}

private onBackPress = async (): Promise<boolean> => {
const { onBackButtonPress } = this.props;
const { onBackButtonPress, alwaysOpen } = this.props;

if (alwaysOpen) {
return false;
}

if (onBackButtonPress) {
onBackButtonPress();
Expand Down

0 comments on commit 2591a8e

Please sign in to comment.