From befffe160266178af21ae9b3d4fef97469d41a6a Mon Sep 17 00:00:00 2001 From: Nguyen Bao Duy <29066552+bdtren@users.noreply.github.com> Date: Thu, 22 Sep 2022 10:11:05 +0700 Subject: [PATCH] fix: support RN 0.70+ --- android/gradle.properties | 2 +- src/index.tsx | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/android/gradle.properties b/android/gradle.properties index 152717b..6203ae8 100644 --- a/android/gradle.properties +++ b/android/gradle.properties @@ -1,3 +1,3 @@ -WebBrowser_kotlinVersion=1.3.50 +WebBrowser_kotlinVersion=1.6.0 WebBrowser_compileSdkVersion=29 WebBrowser_targetSdkVersion=29 diff --git a/src/index.tsx b/src/index.tsx index 570a145..0a0780f 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,4 +1,4 @@ -import { AppState, AppStateStatus, Linking, Platform } from 'react-native'; +import { AppState, AppStateStatus, Linking, Platform, EmitterSubscription } from 'react-native'; import NativeWebBrowser from './NativeWebBrowser'; import { RedirectEvent, @@ -356,6 +356,9 @@ function _onAppStateChangeAndroid(state: AppStateStatus) { } } +// Event Emitter of react native `Linking` +let _linkingSubscription: EmitterSubscription; + async function _openBrowserAndWaitAndroidAsync( startUrl: string, browserParams: WebBrowserOpenOptions = {} @@ -436,7 +439,7 @@ function _stopWaitingForRedirect() { ); } - Linking.removeEventListener('url', _redirectHandler); + _linkingSubscription?.remove?.(); _redirectHandler = null; } @@ -450,6 +453,6 @@ function _waitForRedirectAsync( } }; - Linking.addEventListener('url', _redirectHandler); + _linkingSubscription = Linking.addEventListener('url', _redirectHandler); }); -} +} \ No newline at end of file