Skip to content

Commit

Permalink
refactor: use remove() to unsubscribe dimension listeners (#157)
Browse files Browse the repository at this point in the history
* Fix removeEventListener warning in rn0.65

 removeEventListener is deprecated in React-native >= 0.65 and will throw warnings

* typo & error fixed

I have not read all the code , but I think maybe in some places removeListeners is called before  attachListeners,  an error will occur: backPressListner is undefined

* fix typo

Co-authored-by: Óscar Carretero <[email protected]>

Co-authored-by: Vojtech Novak <[email protected]>
Co-authored-by: Óscar Carretero <[email protected]>
  • Loading branch information
3 people committed Jun 12, 2022
1 parent 37e995b commit 9607600
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/overflowMenu/vendor/Menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,15 +240,15 @@ export class Menu extends React.Component<Props, State> {
};

attachListeners = () => {
BackHandler.addEventListener('hardwareBackPress', this.handleDismiss);
Dimensions.addEventListener('change', this.handleDismiss);
this.backPressListener = BackHandler.addEventListener('hardwareBackPress', this.handleDismiss);
this.dimensionChangeListener = Dimensions.addEventListener('change', this.handleDismiss);

this.isBrowser() && document.addEventListener('keyup', this.handleKeypress);
};

removeListeners = () => {
BackHandler.removeEventListener('hardwareBackPress', this.handleDismiss);
Dimensions.removeEventListener('change', this.handleDismiss);
this?.backPressListener?.remove();
this?.dimensionChangeListener?.remove();

this.isBrowser() && document.removeEventListener('keyup', this.handleKeypress);
};
Expand Down

0 comments on commit 9607600

Please sign in to comment.