Skip to content

Commit

Permalink
Move modal hide and key-listener cleanup to new fn
Browse files Browse the repository at this point in the history
  • Loading branch information
Beamanator committed Mar 15, 2021
1 parent 7743763 commit f5e7b9f
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/components/Modal/BaseModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,22 @@ class BaseModal extends PureComponent {
constructor(props) {
super(props);

this.hideModalAndRemoveEventListeners = this.hideModalAndRemoveEventListeners.bind(this);
this.subscribeToKeyEvents = this.subscribeToKeyEvents.bind(this);
this.unsubscribeFromKeyEvents = this.unsubscribeFromKeyEvents.bind(this);
}

componentWillUnmount() {
this.hideModalAndRemoveEventListeners();
}

/**
* Hides modal and unsubscribes from key event listeners
*/
hideModalAndRemoveEventListeners() {
this.unsubscribeFromKeyEvents();
setModalVisibility(false);
this.props.onModalHide();
}

/**
Expand Down Expand Up @@ -66,11 +75,7 @@ class BaseModal extends PureComponent {
this.subscribeToKeyEvents();
setModalVisibility(true);
}}
onModalHide={() => {
this.unsubscribeFromKeyEvents();
setModalVisibility(false);
this.props.onModalHide();
}}
onModalHide={this.hideModalAndRemoveEventListeners}
onSwipeComplete={this.props.onClose}
swipeDirection={swipeDirection}
isVisible={this.props.isVisible}
Expand Down

0 comments on commit f5e7b9f

Please sign in to comment.