react-native-inappbrowser icon indicating copy to clipboard operation
react-native-inappbrowser copied to clipboard

RN 0.70 crashes

Open georgeilas-tem opened this issue 3 years ago • 8 comments

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 avatar Sep 20 '22 08:09 georgeilas-tem

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;
   }
 }

georgeilas-tem avatar Sep 20 '22 08:09 georgeilas-tem

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.

hstorz avatar Oct 10 '22 10:10 hstorz

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

mstiggle avatar Nov 16 '22 00:11 mstiggle

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...

LitileXueZha avatar Nov 28 '22 08:11 LitileXueZha

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"

melisa-at-levelpath avatar Mar 16 '23 13:03 melisa-at-levelpath

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

jdnichollsc avatar Mar 16 '23 16:03 jdnichollsc

any news guys?

timorss avatar Mar 22 '23 13:03 timorss

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?

LonelyCpp avatar Mar 30 '23 20:03 LonelyCpp