@exodus/react-native-webview 11.26.1-exodus.5 → 11.26.1-exodus.6

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.
@@ -0,0 +1,25 @@
1
+ package com.reactnativecommunity.webview;
2
+
3
+ import java.util.Arrays;
4
+ import java.util.Collections;
5
+ import java.util.List;
6
+
7
+ import com.facebook.react.ReactPackage;
8
+ import com.facebook.react.bridge.NativeModule;
9
+ import com.facebook.react.bridge.ReactApplicationContext;
10
+ import com.facebook.react.uimanager.ViewManager;
11
+
12
+ public class RNCWebViewPackage implements ReactPackage {
13
+ @Override
14
+ public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
15
+ return Arrays.<NativeModule>asList(
16
+ new RNCWebViewModule(reactContext),
17
+ new RNCWebViewUtils(reactContext)
18
+ );
19
+ }
20
+
21
+ @Override
22
+ public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
23
+ return Arrays.<ViewManager>asList(new RNCWebViewManager());
24
+ }
25
+ }
@@ -0,0 +1,51 @@
1
+ package com.reactnativecommunity.webview;
2
+
3
+ import android.webkit.WebView;
4
+
5
+ import com.facebook.react.bridge.Promise;
6
+ import com.facebook.react.bridge.ReactApplicationContext;
7
+ import com.facebook.react.bridge.ReactContextBaseJavaModule;
8
+ import com.facebook.react.uimanager.ThemedReactContext;
9
+ import com.facebook.react.bridge.ReactMethod;
10
+ import com.facebook.react.bridge.UiThreadUtil;
11
+
12
+ public class RNCWebViewUtils extends ReactContextBaseJavaModule {
13
+ public static final String NAME = "RNCWebViewUtils";
14
+
15
+ ReactApplicationContext mCallerContext;
16
+
17
+ public RNCWebViewUtils(ReactApplicationContext reactContext) {
18
+ super(reactContext);
19
+ mCallerContext = reactContext;
20
+ }
21
+
22
+ @Override
23
+ public String getName() {
24
+ return NAME;
25
+ }
26
+
27
+ @ReactMethod
28
+ public void getWebViewDefaultUserAgent(final Promise promise) {
29
+ UiThreadUtil.runOnUiThread(new Runnable() {
30
+ @Override
31
+ public void run() {
32
+ try {
33
+ WebView webView = new WebView(mCallerContext);
34
+
35
+ // in case we ever use our own UA we need to unset it first the get the original
36
+ String currentUA = webView.getSettings().getUserAgentString();
37
+ webView.getSettings().setUserAgentString(null);
38
+ String webViewUA = webView.getSettings().getUserAgentString();
39
+
40
+ // Revert to overriden UA string
41
+ webView.getSettings().setUserAgentString(currentUA);
42
+
43
+ promise.resolve(webViewUA);
44
+ }
45
+ catch (Exception e) {
46
+ promise.reject(NAME, e.getMessage());
47
+ }
48
+ }
49
+ });
50
+ }
51
+ }
package/index.js CHANGED
@@ -1,4 +1,7 @@
1
- import WebView from './lib/WebView';
1
+ import WebView, {
2
+ RNCWebViewUtils,
3
+ getWebViewDefaultUserAgent,
4
+ } from './lib/WebView';
2
5
 
3
- export { WebView };
6
+ export { WebView, RNCWebViewUtils, getWebViewDefaultUserAgent };
4
7
  export default WebView;
@@ -1,4 +1,4 @@
1
- import React, { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef } from 'react';
1
+ import React, { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
2
2
  import { Text, View, NativeModules, } from 'react-native';
3
3
  import BatchedBridge from 'react-native/Libraries/BatchedBridge/BatchedBridge';
4
4
  // @ts-expect-error react-native doesn't have this type
@@ -7,6 +7,14 @@ import invariant from 'invariant';
7
7
  import RNCWebView from "./WebViewNativeComponent.android";
8
8
  import { defaultOriginWhitelist, defaultRenderError, defaultRenderLoading, useWebWiewLogic, versionPasses, } from './WebViewShared';
9
9
  import styles from './WebView.styles';
10
+ const { getWebViewDefaultUserAgent } = NativeModules.RNCWebViewUtils;
11
+ let userAgentPromise;
12
+ async function getUserAgent() {
13
+ if (!userAgentPromise)
14
+ userAgentPromise = getWebViewDefaultUserAgent();
15
+ const userAgent = await userAgentPromise;
16
+ return userAgent || 'unknown';
17
+ }
10
18
  const codegenNativeCommands = codegenNativeCommandsUntyped;
11
19
  const Commands = codegenNativeCommands({
12
20
  supportedCommands: ['goBack', 'goForward', 'reload', 'stopLoading', /* 'injectJavaScript', */ 'requestFocus', 'postMessage', 'clearFormData', 'clearCache', 'clearHistory', 'loadUrl'],
@@ -70,7 +78,12 @@ const WebViewComponent = forwardRef(({ overScrollMode = 'always', javaScriptEnab
70
78
  useEffect(() => {
71
79
  BatchedBridge.registerCallableModule(messagingModuleName, directEventCallbacks);
72
80
  }, [messagingModuleName, directEventCallbacks]);
73
- const userAgent = 'chrome/200'; // TODO
81
+ const [userAgent, setUserAgent] = useState();
82
+ useEffect(() => {
83
+ getUserAgent().then(setUserAgent);
84
+ }, []);
85
+ if (!userAgent)
86
+ return null; // stop the rendering until userAgent is known
74
87
  const version = (_a = userAgent.match(/chrome\/((?:[0-9]+\.)+[0-9]+)/i)) === null || _a === void 0 ? void 0 : _a[1];
75
88
  if (!(versionPasses(version, minimumChromeVersion) && versionPasses(version, hardMinimumChromeVersion))) {
76
89
  return (<View style={{ alignSelf: 'flex-start' }}>
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "Thibault Malbranche <malbranche.thibault@gmail.com>"
10
10
  ],
11
11
  "license": "MIT",
12
- "version": "11.26.1-exodus.5",
12
+ "version": "11.26.1-exodus.6",
13
13
  "homepage": "https://github.com/ExodusMovement/react-native-webview#readme",
14
14
  "scripts": {
15
15
  "android": "react-native run-android",
@@ -1,15 +0,0 @@
1
- package com.reactnativecommunity.webview
2
-
3
- import com.facebook.react.ReactPackage
4
- import com.facebook.react.bridge.ReactApplicationContext
5
-
6
-
7
- class RNCWebViewPackage: ReactPackage {
8
- override fun createNativeModules(reactContext: ReactApplicationContext) = listOf(
9
- RNCWebViewModule(reactContext)
10
- )
11
-
12
- override fun createViewManagers(reactContext: ReactApplicationContext) = listOf(
13
- RNCWebViewManager()
14
- )
15
- }