Skip to content

Commit

Permalink
fix: Removal of BackHandler.removeEventListener in react-native (#339)
Browse files Browse the repository at this point in the history
  • Loading branch information
dprevost-LMI authored Feb 21, 2025
1 parent 1ce802b commit b7e050c
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/ActionSheet/CustomActionSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
BackHandler,
Easing,
Modal,
NativeEventSubscription,
Platform,
StyleSheet,
TouchableWithoutFeedback,
Expand Down Expand Up @@ -38,6 +39,7 @@ const ESCAPE_KEY = 'Escape';
// Has same API as https://facebook.github.io/react-native/docs/actionsheetios.html
export default class CustomActionSheet extends React.Component<Props, State> {
_actionSheetHeight = 360;
_backHandlerListener: NativeEventSubscription | undefined;

state: State = {
isVisible: false,
Expand Down Expand Up @@ -227,8 +229,12 @@ export default class CustomActionSheet extends React.Component<Props, State> {
this._deferAfterAnimation = undefined;
}
});
// @ts-ignore: Argument of type '"actionSheetHardwareBackPress"' is not assignable to parameter of type '"hardwareBackPress"'
BackHandler.addEventListener('actionSheetHardwareBackPress', this._selectCancelButton);

this._backHandlerListener = BackHandler.addEventListener(
// @ts-ignore: Argument of type '"actionSheetHardwareBackPress"' is not assignable to parameter of type '"hardwareBackPress"'
'actionSheetHardwareBackPress',
this._selectCancelButton
);
};

_selectCancelButton = () => {
Expand Down Expand Up @@ -269,8 +275,9 @@ export default class CustomActionSheet extends React.Component<Props, State> {
return false;
}

// @ts-ignore: Argument of type '"actionSheetHardwareBackPress"' is not assignable to parameter of type '"hardwareBackPress"'
BackHandler.removeEventListener('actionSheetHardwareBackPress', this._selectCancelButton);
if (this._backHandlerListener) {
this._backHandlerListener.remove();
}
this.setState({
isAnimating: true,
});
Expand Down

0 comments on commit b7e050c

Please sign in to comment.