Skip to content

Commit db3ae53

Browse files
jacargentinasodik82
authored andcommitted
Fix #289: RN 0.77 compatibility: BackHandler.removeEventListener is not a function
1 parent ca2e308 commit db3ae53

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/MenuProvider.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export default class MenuProvider extends Component {
2929
super(props);
3030
this._menuRegistry = makeMenuRegistry();
3131
this._isMenuClosing = false;
32-
this._isBackHandlerRegistered = false;
32+
this._backHandlerSubscription = null;
3333
const menuActions = {
3434
openMenu: name => this.openMenu(name),
3535
closeMenu: () => this.closeMenu(),
@@ -76,8 +76,9 @@ export default class MenuProvider extends Component {
7676

7777
componentWillUnmount() {
7878
debug('unmounting menu provider')
79-
if (this._isBackHandlerRegistered) {
80-
BackHandler.removeEventListener('hardwareBackPress', this._handleBackButton);
79+
if (this._backHandlerSubscription != null) {
80+
this._backHandlerSubscription.remove();
81+
this._backHandlerSubscription = null;
8182
}
8283
const { skipInstanceCheck } = this.props;
8384
if (!skipInstanceCheck) {
@@ -96,11 +97,10 @@ export default class MenuProvider extends Component {
9697
return Promise.resolve();
9798
}
9899
debug('open menu', name);
99-
if (!this._isBackHandlerRegistered) {
100+
if (this._backHandlerSubscription == null) {
100101
// delay menu registration until the menu is really opened (and thus this back handler will be called "sooner")
101102
// too soon registration can cause another back handlers (e.g. react navigation) to be called instead of our back handler
102-
BackHandler.addEventListener('hardwareBackPress', this._handleBackButton);
103-
this._isBackHandlerRegistered = true;
103+
this._backHandlerSubscription = BackHandler.addEventListener('hardwareBackPress', this._handleBackButton);
104104
}
105105
menu.instance._setOpened(true);
106106
return this._notify();

0 commit comments

Comments
 (0)