proyecto26 / react-native-inappbrowser

📱InAppBrowser for React Native (Android & iOS) 🤘
https://www.npmjs.com/package/react-native-inappbrowser-reborn
MIT License
1.29k stars 220 forks source link

RN 0.70 crashes #381

Open georgeilas-tem opened 1 year ago

georgeilas-tem commented 1 year ago

RN 0.70 deprecated:

AppState.removeEventListener: https://reactnative.dev/docs/appstate#removeeventlistener Linking.removeEventListener: https://reactnative.dev/docs/linking#removeeventlistener

Both are used in utils.js and cause crashes on Android.

georgeilas-tem commented 1 year ago

Patched it quickly this way:

diff --git a/node_modules/react-native-inappbrowser-reborn/utils.js b/node_modules/react-native-inappbrowser-reborn/utils.js
index 9fe6085..c7ca6e8 100644
--- a/node_modules/react-native-inappbrowser-reborn/utils.js
+++ b/node_modules/react-native-inappbrowser-reborn/utils.js
@@ -5,22 +5,24 @@

 import invariant from 'invariant';
 import {
-  processColor,
+  AppState,
   Linking,
+  NativeModules,
   Platform,
-  AppState,
-  NativeModules
+  processColor
 } from 'react-native';
+
 import type {
+  AuthSessionResult,
   BrowserResult,
+  InAppBrowserOptions,
   RedirectEvent,
-  RedirectResult,
-  AuthSessionResult,
-  InAppBrowserOptions
+  RedirectResult
 } from './types';

 export const RNInAppBrowser = NativeModules.RNInAppBrowser;

+let _redirectListener = null
 let _redirectHandler: ?(event: RedirectEvent) => void;

 type AppStateStatus = typeof AppState.currentState
@@ -33,7 +35,7 @@ function waitForRedirectAsync(returnUrl: string): Promise<RedirectResult> {
       }
     };

-    Linking.addEventListener('url', _redirectHandler);
+    _redirectListener = Linking.addEventListener('url', _redirectHandler);
   });
 }

@@ -42,17 +44,19 @@ function waitForRedirectAsync(returnUrl: string): Promise<RedirectResult> {
  */
 function handleAppStateActiveOnce(): Promise<void> {
   return new Promise(function (resolve) {
+    let listener=null 
+    
     // Browser can be closed before handling AppState change
     if (AppState.currentState === 'active') {
       return resolve();
     }
     function handleAppStateChange(nextAppState: AppStateStatus) {
       if (nextAppState === 'active') {
-        AppState.removeEventListener('change', handleAppStateChange);
+        listener.remove()
         resolve();
       }
     }
-    AppState.addEventListener('change', handleAppStateChange);
+    listener = AppState.addEventListener('change', handleAppStateChange);
   });
 }

@@ -137,7 +141,9 @@ export async function openAuthSessionPolyfillAsync(

 export function closeAuthSessionPolyfillAsync(): void {
   if (_redirectHandler) {
-    Linking.removeEventListener('url', _redirectHandler);
+    _redirectListener.remove()
+
+    _redirectListener = null
     _redirectHandler = null;
   }
 }
hstorz commented 1 year ago

Can confirm, I got the same error on 0.70.2. Could fix the crash with your patch on version 3.6.3, thanks for that!. Would be nice if this could be merged in a new release soon.

mstiggle commented 1 year ago

Ran into this problem as well, would love to have this merged in to avoid applying a patch.

LitileXueZha commented 1 year ago

Also crashed, here is my logcat:

11-28 16:42:56.014 10270 10313 E AndroidRuntime: ob.e: Subscriber class d8.c and its super classes have no public methods with the @Subscribe annotation
11-28 16:42:56.014 10270 10313 E AndroidRuntime:        at ob.p.a(Unknown Source:58)
11-28 16:42:56.014 10270 10313 E AndroidRuntime:        at ob.c.p(Unknown Source:6)
11-28 16:42:56.014 10270 10313 E AndroidRuntime:        at d8.c.l(Unknown Source:14)
11-28 16:42:56.014 10270 10313 E AndroidRuntime:        at d8.c.k(Unknown Source:352)
11-28 16:42:56.014 10270 10313 E AndroidRuntime:        at com.proyecto26.inappbrowser.RNInAppBrowserModule.open(Unknown Source:10)
11-28 16:42:56.014 10270 10313 E AndroidRuntime:        at java.lang.reflect.Method.invoke(Native Method)
11-28 16:42:56.014 10270 10313 E AndroidRuntime:        at com.facebook.react.bridge.JavaMethodWrapper.invoke(Unknown Source:148)
11-28 16:42:56.014 10270 10313 E AndroidRuntime:        at com.facebook.react.bridge.JavaModuleWrapper.invoke(Unknown Source:147)
11-28 16:42:56.014 10270 10313 E AndroidRuntime:        at com.facebook.jni.NativeRunnable.run(Native Method)
11-28 16:42:56.014 10270 10313 E AndroidRuntime:        at android.os.Handler.handleCallback(Handler.java:808)
11-28 16:42:56.014 10270 10313 E AndroidRuntime:        at android.os.Handler.dispatchMessage(Handler.java:101)
11-28 16:42:56.014 10270 10313 E AndroidRuntime:        at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(Unknown Source:0)
11-28 16:42:56.014 10270 10313 E AndroidRuntime:        at android.os.Looper.loop(Looper.java:166)
11-28 16:42:56.014 10270 10313 E AndroidRuntime:        at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(Unknown Source:37)
11-28 16:42:56.014 10270 10313 E AndroidRuntime:        at java.lang.Thread.run(Thread.java:784)

UPDATE: I reallized that my problem may caused by ProGuard, and fixed it through modify proguard-rules.pro 😂🙄 Also found a trick of Android Optimizations from README, however onStart() not worked in RNN...

melisa-at-levelpath commented 1 year ago

Running in the same issue on android. Any plans on fixing this? 🤔

Same error in logs:

k7.e: Subscriber class o5.c and its super classes have no public methods with the @Subscribe annotation
at k7.p.a(Unknown Source:58)
at k7.c.p(Unknown Source:6)
at o5.c.l(Unknown Source:14)
at o5.c.k(Unknown Source:352)
at com.proyecto26.inappbrowser.RNInAppBrowserModule.open(Unknown Source:10)
at java.lang.reflect.Method.invoke(Native Method)
at com.facebook.react.bridge.JavaMethodWrapper.invoke(Unknown Source:148)
at com.facebook.react.bridge.JavaModuleWrapper.invoke(Unknown Source:147)
at com.facebook.jni.NativeRunnable.run(Native Method)
at android.os.Handler.handleCallback(Handler.java:958)
at android.os.Handler.dispatchMessage(Handler.java:99)
at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(Unknown Source:0)
at android.os.Looper.loopOnce(Looper.java:205)
at android.os.Looper.loop(Looper.java:294)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(Unknown Source:37)
at java.lang.Thread.run(Thread.java:1012)

"react-native": "0.71.2" "react-native-inappbrowser-reborn": "^3.7.0"

jdnichollsc commented 1 year ago

Hey folks, thanks for reporting this issue! Let me try ASAP! <3

timorss commented 1 year ago

any news guys?

LonelyCpp commented 1 year ago

this has been fixed in this PR if I'm not wrong : https://github.com/proyecto26/react-native-inappbrowser/pull/297/

It handles both appstate and linking compatibility. What am I missing?