@javascriptcommon/react-native-webview 13.17.0 → 13.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -3,6 +3,8 @@ package com.reactnativecommunity.webview;
|
|
|
3
3
|
import android.annotation.SuppressLint;
|
|
4
4
|
import android.graphics.Rect;
|
|
5
5
|
import android.net.Uri;
|
|
6
|
+
import android.os.Handler;
|
|
7
|
+
import android.os.Looper;
|
|
6
8
|
import android.text.TextUtils;
|
|
7
9
|
import android.view.ActionMode;
|
|
8
10
|
import android.view.Menu;
|
|
@@ -87,6 +89,11 @@ public class RNCWebView extends WebView implements LifecycleEventListener {
|
|
|
87
89
|
|
|
88
90
|
public void setContentBlockerEnabled(boolean enabled) {
|
|
89
91
|
this.contentBlockerEnabled = enabled;
|
|
92
|
+
// The embed (WebView/YouTube) player is the only WebView that enables the
|
|
93
|
+
// content blocker on Android, so this uniquely identifies it. Track it as the
|
|
94
|
+
// target for background script delivery (see enqueueBgScript) without needing
|
|
95
|
+
// reactTag resolution.
|
|
96
|
+
if (enabled) EMBED_INSTANCE = this;
|
|
90
97
|
}
|
|
91
98
|
|
|
92
99
|
public boolean getContentBlockerEnabled() {
|
|
@@ -107,6 +114,43 @@ public class RNCWebView extends WebView implements LifecycleEventListener {
|
|
|
107
114
|
* Activity Context is required for creation of dialogs internally by WebView
|
|
108
115
|
* Reactive Native needed for access to ReactNative internal system functionality
|
|
109
116
|
*/
|
|
117
|
+
// Background-capable RN→WebView injection channel for the embed player.
|
|
118
|
+
//
|
|
119
|
+
// RN's injectJavaScript() is dispatched via the UIManager view-command queue, flushed
|
|
120
|
+
// on the next UI frame — a backgrounded / screen-off app produces no frames, so those
|
|
121
|
+
// commands never reach the WebView. A native evaluateJavascript() posted on the main
|
|
122
|
+
// Handler is NOT frame-gated and IS delivered in background. So RN enqueues background-
|
|
123
|
+
// critical scripts here (via EmbedInjectModule → enqueueBgScript) and this Handler
|
|
124
|
+
// drains them straight into the renderer, immediately (FIFO order preserved, so a
|
|
125
|
+
// navigate→play sequence always runs in order). EMBED_INSTANCE is the embed WebView
|
|
126
|
+
// (the only one with the content blocker on), so no reactTag resolution is needed.
|
|
127
|
+
private final Handler bgInjectHandler = new Handler(Looper.getMainLooper());
|
|
128
|
+
public static volatile RNCWebView EMBED_INSTANCE;
|
|
129
|
+
private final java.util.concurrent.ConcurrentLinkedQueue<String> pendingBgScripts =
|
|
130
|
+
new java.util.concurrent.ConcurrentLinkedQueue<>();
|
|
131
|
+
|
|
132
|
+
public static void enqueueBgScript(String script) {
|
|
133
|
+
RNCWebView v = EMBED_INSTANCE;
|
|
134
|
+
if (v != null && script != null) {
|
|
135
|
+
v.pendingBgScripts.add(script);
|
|
136
|
+
v.bgInjectHandler.post(v.drainRunnable); // immediate drain (FIFO)
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Drains all queued scripts into the renderer via native evaluateJavascript, in FIFO
|
|
141
|
+
// order. Runs on the main looper (posted by enqueueBgScript).
|
|
142
|
+
private void drainPendingScripts() {
|
|
143
|
+
String script;
|
|
144
|
+
while ((script = pendingBgScripts.poll()) != null) {
|
|
145
|
+
try { evaluateJavascript(script, null); } catch (Throwable ignored) { }
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
private final Runnable drainRunnable = new Runnable() {
|
|
150
|
+
@Override
|
|
151
|
+
public void run() { drainPendingScripts(); }
|
|
152
|
+
};
|
|
153
|
+
|
|
110
154
|
public RNCWebView(ThemedReactContext reactContext) {
|
|
111
155
|
super(reactContext);
|
|
112
156
|
ReactApplicationContext appContext = reactContext.getReactApplicationContext();
|
|
@@ -443,6 +487,9 @@ public class RNCWebView extends WebView implements LifecycleEventListener {
|
|
|
443
487
|
}
|
|
444
488
|
|
|
445
489
|
protected void cleanupCallbacksAndDestroy() {
|
|
490
|
+
bgInjectHandler.removeCallbacks(drainRunnable);
|
|
491
|
+
if (EMBED_INSTANCE == this) EMBED_INSTANCE = null;
|
|
492
|
+
pendingBgScripts.clear();
|
|
446
493
|
setWebViewClient(null);
|
|
447
494
|
destroy();
|
|
448
495
|
}
|
package/package.json
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"Thibault Malbranche <malbranche.thibault@gmail.com>"
|
|
11
11
|
],
|
|
12
12
|
"license": "MIT",
|
|
13
|
-
"version": "13.
|
|
13
|
+
"version": "13.18.0",
|
|
14
14
|
"homepage": "https://github.com/react-native-webview/react-native-webview#readme",
|
|
15
15
|
"scripts": {
|
|
16
16
|
"android": "react-native run-android",
|