Skip to content

Error "_reactNative.Backhander.removeEventListener is not a function"#5826

Description

@MohammadKanaan

Hi! 馃憢

Firstly, thanks for your work on this project! 馃檪

Today I used patch-package to patch native-base@3.4.28 for the project I'm working on.

I got the error "_reactNative.Backhander.removeEventListener is not a function"

Here is the diff that solved my problem:

diff --git a/node_modules/native-base/src/hooks/useKeyboardDismissable.ts b/node_modules/native-base/src/hooks/useKeyboardDismissable.ts
index f3cfa44..af443fa 100644
--- a/node_modules/native-base/src/hooks/useKeyboardDismissable.ts
+++ b/node_modules/native-base/src/hooks/useKeyboardDismissable.ts
@@ -48,12 +48,17 @@ export function useBackHandler({ enabled, callback }: IParams) {
       callback();
       return true;
     };
+    let subscription: any;
     if (enabled) {
-      BackHandler.addEventListener('hardwareBackPress', backHandler);
-    } else {
-      BackHandler.removeEventListener('hardwareBackPress', backHandler);
+      subscription = BackHandler.addEventListener(
+        'hardwareBackPress',
+        backHandler
+      );
     }
-    return () =>
-      BackHandler.removeEventListener('hardwareBackPress', backHandler);
+    return () => {
+      if (subscription && typeof subscription.remove === 'function') {
+        subscription.remove();
+      }
+    };
   }, [enabled, callback]);
 }

This issue body was partially generated by patch-package.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions