From 2460dc7c74f8eb22fd2f629f6eefb90d21df478e Mon Sep 17 00:00:00 2001 From: David Prevost Date: Sun, 16 Feb 2025 12:51:48 -0500 Subject: [PATCH 1/2] Fix removal of `BackHandler.removeEventListener` in react-native --- src/ActionSheet/CustomActionSheet.tsx | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/ActionSheet/CustomActionSheet.tsx b/src/ActionSheet/CustomActionSheet.tsx index e88906c..a4b8ba9 100644 --- a/src/ActionSheet/CustomActionSheet.tsx +++ b/src/ActionSheet/CustomActionSheet.tsx @@ -4,6 +4,7 @@ import { BackHandler, Easing, Modal, + NativeEventSubscription, Platform, StyleSheet, TouchableWithoutFeedback, @@ -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 { _actionSheetHeight = 360; + _backHandlerListener: NativeEventSubscription | undefined; state: State = { isVisible: false, @@ -228,7 +230,10 @@ export default class CustomActionSheet extends React.Component { } }); // @ts-ignore: Argument of type '"actionSheetHardwareBackPress"' is not assignable to parameter of type '"hardwareBackPress"' - BackHandler.addEventListener('actionSheetHardwareBackPress', this._selectCancelButton); + this._backHandlerListener = BackHandler.addEventListener( + 'actionSheetHardwareBackPress', + this._selectCancelButton + ); }; _selectCancelButton = () => { @@ -269,8 +274,9 @@ export default class CustomActionSheet extends React.Component { 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, }); From 430367e7bf0c8f99a0e9954d4d994d820c0ee091 Mon Sep 17 00:00:00 2001 From: David Prevost Date: Sun, 16 Feb 2025 12:58:25 -0500 Subject: [PATCH 2/2] move ts-ignore since it was reformatted --- src/ActionSheet/CustomActionSheet.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ActionSheet/CustomActionSheet.tsx b/src/ActionSheet/CustomActionSheet.tsx index a4b8ba9..e821158 100644 --- a/src/ActionSheet/CustomActionSheet.tsx +++ b/src/ActionSheet/CustomActionSheet.tsx @@ -229,8 +229,9 @@ export default class CustomActionSheet extends React.Component { this._deferAfterAnimation = undefined; } }); - // @ts-ignore: Argument of type '"actionSheetHardwareBackPress"' is not assignable to parameter of type '"hardwareBackPress"' + this._backHandlerListener = BackHandler.addEventListener( + // @ts-ignore: Argument of type '"actionSheetHardwareBackPress"' is not assignable to parameter of type '"hardwareBackPress"' 'actionSheetHardwareBackPress', this._selectCancelButton );