Browse Source

Add (and document) injectedJavaScriptBeforeContentLoadedForMainFrameOnly and injectedJavaScriptForMainFrameOnly stub props for parity with iOS and macOS.

Jamie Birch 4 years ago
parent
commit
cd14c2e87f

+ 26
- 0
android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java View File

397
     ((RNCWebView) view).setInjectedJavaScriptBeforeContentLoaded(injectedJavaScriptBeforeContentLoaded);
397
     ((RNCWebView) view).setInjectedJavaScriptBeforeContentLoaded(injectedJavaScriptBeforeContentLoaded);
398
   }
398
   }
399
 
399
 
400
+  @ReactProp(name = "injectedJavaScriptForMainFrameOnly")
401
+  public void setInjectedJavaScriptForMainFrameOnly(WebView view, boolean enabled) {
402
+    ((RNCWebView) view).setInjectedJavaScriptForMainFrameOnly(enabled);
403
+  }
404
+
405
+  @ReactProp(name = "injectedJavaScriptBeforeContentLoadedForMainFrameOnly")
406
+  public void setInjectedJavaScriptBeforeContentLoadedForMainFrameOnly(WebView view, boolean enabled) {
407
+    ((RNCWebView) view).setInjectedJavaScriptBeforeContentLoadedForMainFrameOnly(enabled);
408
+  }
409
+
400
   @ReactProp(name = "messagingEnabled")
410
   @ReactProp(name = "messagingEnabled")
401
   public void setMessagingEnabled(WebView view, boolean enabled) {
411
   public void setMessagingEnabled(WebView view, boolean enabled) {
402
     ((RNCWebView) view).setMessagingEnabled(enabled);
412
     ((RNCWebView) view).setMessagingEnabled(enabled);
981
     String injectedJS;
991
     String injectedJS;
982
     protected @Nullable
992
     protected @Nullable
983
     String injectedJSBeforeContentLoaded;
993
     String injectedJSBeforeContentLoaded;
994
+
995
+    /**
996
+     * android.webkit.WebChromeClient fundamentally does not support JS injection into frames other
997
+     * than the main frame, so these two properties are mostly here just for parity with iOS & macOS.
998
+     */
999
+    protected boolean injectedJavaScriptForMainFrameOnly = true;
1000
+    protected boolean injectedJavaScriptBeforeContentLoadedForMainFrameOnly = true;
1001
+
984
     protected boolean messagingEnabled = false;
1002
     protected boolean messagingEnabled = false;
985
     protected @Nullable
1003
     protected @Nullable
986
     RNCWebViewClient mRNCWebViewClient;
1004
     RNCWebViewClient mRNCWebViewClient;
1058
       injectedJSBeforeContentLoaded = js;
1076
       injectedJSBeforeContentLoaded = js;
1059
     }
1077
     }
1060
 
1078
 
1079
+    public void setInjectedJavaScriptForMainFrameOnly(boolean enabled) {
1080
+      injectedJavaScriptForMainFrameOnly = enabled;
1081
+    }
1082
+
1083
+    public void setInjectedJavaScriptBeforeContentLoadedForMainFrameOnly(boolean enabled) {
1084
+      injectedJavaScriptBeforeContentLoadedForMainFrameOnly = enabled;
1085
+    }
1086
+
1061
     protected RNCWebViewBridge createRNCWebViewBridge(RNCWebView webView) {
1087
     protected RNCWebViewBridge createRNCWebViewBridge(RNCWebView webView) {
1062
       return new RNCWebViewBridge(webView);
1088
       return new RNCWebViewBridge(webView);
1063
     }
1089
     }

+ 27
- 1
docs/Reference.md View File

7
 - [`source`](Reference.md#source)
7
 - [`source`](Reference.md#source)
8
 - [`automaticallyAdjustContentInsets`](Reference.md#automaticallyadjustcontentinsets)
8
 - [`automaticallyAdjustContentInsets`](Reference.md#automaticallyadjustcontentinsets)
9
 - [`injectedJavaScript`](Reference.md#injectedjavascript)
9
 - [`injectedJavaScript`](Reference.md#injectedjavascript)
10
-- [`injectedJavaScriptBeforeContentLoaded`](Reference.md#injectedJavaScriptBeforeContentLoaded)
10
+- [`injectedJavaScriptBeforeContentLoaded`](Reference.md#injectedjavascriptbeforecontentloaded)
11
+- [`injectedJavaScriptForMainFrameOnly`](Reference.md#injectedjavascriptformainframeonly)
12
+- [`injectedJavaScriptBeforeContentLoadedForMainFrameOnly`](Reference.md#injectedjavascriptbeforecontentloadedformainframeonly)
11
 - [`mediaPlaybackRequiresUserAction`](Reference.md#mediaplaybackrequiresuseraction)
13
 - [`mediaPlaybackRequiresUserAction`](Reference.md#mediaplaybackrequiresuseraction)
12
 - [`nativeConfig`](Reference.md#nativeconfig)
14
 - [`nativeConfig`](Reference.md#nativeconfig)
13
 - [`onError`](Reference.md#onerror)
15
 - [`onError`](Reference.md#onerror)
174
 
176
 
175
 ---
177
 ---
176
 
178
 
179
+### `injectedJavaScriptForMainFrameOnly`
180
+
181
+If `true` (default; mandatory for Android), loads the `injectedJavaScript` only into the main frame.
182
+
183
+If `false`, (only supported on iOS and macOS), loads it into all frames (e.g. iframes).
184
+
185
+| Type   | Required | Platform |
186
+| ------ | -------- | -------- |
187
+| bool | No       | iOS and macOS (only `true` supported for Android) |
188
+
189
+---
190
+
191
+### `injectedJavaScriptBeforeContentLoadedForMainFrameOnly`
192
+
193
+If `true` (default; mandatory for Android), loads the `injectedJavaScriptBeforeContentLoaded` only into the main frame.
194
+
195
+If `false`, (only supported on iOS and macOS), loads it into all frames (e.g. iframes).
196
+
197
+| Type   | Required | Platform |
198
+| ------ | -------- | -------- |
199
+| bool | No       | iOS and macOS (only `true` supported for Android) |
200
+
201
+---
202
+
177
 ### `mediaPlaybackRequiresUserAction`
203
 ### `mediaPlaybackRequiresUserAction`
178
 
204
 
179
 Boolean that determines whether HTML5 audio and video requires the user to tap them before they start playing. The default value is `true`. (Android API minimum version 17).
205
 Boolean that determines whether HTML5 audio and video requires the user to tap them before they start playing. The default value is `true`. (Android API minimum version 17).

+ 14
- 0
src/WebViewTypes.ts View File

225
   incognito?: boolean;
225
   incognito?: boolean;
226
   injectedJavaScript?: string;
226
   injectedJavaScript?: string;
227
   injectedJavaScriptBeforeContentLoaded?: string;
227
   injectedJavaScriptBeforeContentLoaded?: string;
228
+  injectedJavaScriptForMainFrameOnly?: boolean;
229
+  injectedJavaScriptBeforeContentLoadedForMainFrameOnly?: boolean;
228
   mediaPlaybackRequiresUserAction?: boolean;
230
   mediaPlaybackRequiresUserAction?: boolean;
229
   messagingEnabled: boolean;
231
   messagingEnabled: boolean;
230
   onScroll?: (event: NativeScrollEvent) => void;
232
   onScroll?: (event: NativeScrollEvent) => void;
853
    */
855
    */
854
   injectedJavaScriptBeforeContentLoaded?: string;
856
   injectedJavaScriptBeforeContentLoaded?: string;
855
 
857
 
858
+  /**
859
+   * If `true` (default; mandatory for Android), loads the `injectedJavaScript` only into the main frame.
860
+   * If `false` (only supported on iOS and macOS), loads it into all frames (e.g. iframes).
861
+   */
862
+  injectedJavaScriptForMainFrameOnly?: boolean;
863
+
864
+  /**
865
+   * If `true` (default; mandatory for Android), loads the `injectedJavaScriptBeforeContentLoaded` only into the main frame.
866
+   * If `false` (only supported on iOS and macOS), loads it into all frames (e.g. iframes).
867
+   */
868
+  injectedJavaScriptBeforeContentLoadedForMainFrameOnly?: boolean;
869
+
856
   /**
870
   /**
857
    * Boolean value that determines whether a horizontal scroll indicator is
871
    * Boolean value that determines whether a horizontal scroll indicator is
858
    * shown in the `WebView`. The default value is `true`.
872
    * shown in the `WebView`. The default value is `true`.