react-native-minimal-webview 1.1.0 → 1.2.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.
- package/android/src/main/java/expo/modules/minimalwebview/Hooks.kt +1 -6
- package/android/src/main/java/expo/modules/minimalwebview/MinimalWebView.kt +34 -22
- package/android/src/main/java/expo/modules/minimalwebview/MinimalWebViewClients.kt +3 -2
- package/android/src/main/java/expo/modules/minimalwebview/MinimalWebViewModule.kt +2 -1
- package/android/src/main/java/expo/modules/minimalwebview/MinimalWebViewNavigation.kt +3 -3
- package/android/src/main/java/expo/modules/minimalwebview/MinimalWebViewScripts.kt +5 -7
- package/android/src/main/java/expo/modules/minimalwebview/PlatformSettings.kt +29 -34
- package/android/src/main/java/expo/modules/minimalwebview/PullToRefresh.kt +2 -2
- package/android/src/main/java/expo/modules/minimalwebview/requests/Downloads.kt +7 -8
- package/android/src/main/java/expo/modules/minimalwebview/requests/FullscreenVideo.kt +2 -2
- package/android/src/main/java/expo/modules/minimalwebview/requests/Permissions.kt +4 -5
- package/build/WebView.d.ts +1 -9
- package/build/WebView.d.ts.map +1 -1
- package/build/WebView.js +37 -100
- package/build/WebView.js.map +1 -1
- package/build/bridge/createBridge.d.ts +17 -11
- package/build/bridge/createBridge.d.ts.map +1 -1
- package/build/bridge/createBridge.js +32 -44
- package/build/bridge/createBridge.js.map +1 -1
- package/build/bridge/endpoint.d.ts +1 -3
- package/build/bridge/endpoint.d.ts.map +1 -1
- package/build/bridge/endpoint.js +2 -2
- package/build/bridge/endpoint.js.map +1 -1
- package/build/bridge/origins.d.ts +5 -2
- package/build/bridge/origins.d.ts.map +1 -1
- package/build/bridge/origins.js +15 -4
- package/build/bridge/origins.js.map +1 -1
- package/build/bridge/pageClient.generated.d.ts +1 -1
- package/build/bridge/pageClient.generated.d.ts.map +1 -1
- package/build/bridge/pageClient.generated.js +1 -1
- package/build/bridge/pageClient.generated.js.map +1 -1
- package/build/index.d.ts +1 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +1 -1
- package/build/index.js.map +1 -1
- package/build/{defaultNavigationRules.d.ts → navigationRules.d.ts} +10 -1
- package/build/navigationRules.d.ts.map +1 -0
- package/build/navigationRules.js +93 -0
- package/build/navigationRules.js.map +1 -0
- package/build/refStore.d.ts.map +1 -1
- package/build/refStore.js +13 -17
- package/build/refStore.js.map +1 -1
- package/build/types.d.ts +39 -16
- package/build/types.d.ts.map +1 -1
- package/ios/DelegateProxy.swift +32 -30
- package/ios/Loads.swift +4 -4
- package/ios/MRWInvoke.h +8 -0
- package/ios/MRWInvoke.m +39 -24
- package/ios/MinimalWebView+Navigation.swift +17 -14
- package/ios/MinimalWebView.swift +72 -28
- package/ios/MinimalWebViewModule.swift +1 -0
- package/ios/NavigationRules.swift +15 -15
- package/ios/PlatformSettings.swift +2 -13
- package/ios/SharedCookies.swift +1 -2
- package/package.json +1 -1
- package/src/WebView.tsx +50 -114
- package/src/bridge/createBridge.ts +45 -53
- package/src/bridge/endpoint.ts +3 -5
- package/src/bridge/origins.ts +18 -6
- package/src/bridge/pageClient.generated.ts +1 -1
- package/src/index.ts +1 -1
- package/src/navigationRules.ts +111 -0
- package/src/refStore.ts +15 -19
- package/src/types.ts +39 -16
- package/build/defaultNavigationRules.d.ts.map +0 -1
- package/build/defaultNavigationRules.js +0 -22
- package/build/defaultNavigationRules.js.map +0 -1
- package/ios/MRWExceptions.h +0 -9
- package/ios/MRWExceptions.m +0 -10
- package/src/defaultNavigationRules.ts +0 -24
package/src/refStore.ts
CHANGED
|
@@ -22,11 +22,12 @@ const INITIAL_STATE: NavigationState = {
|
|
|
22
22
|
outcome: null,
|
|
23
23
|
};
|
|
24
24
|
|
|
25
|
-
/** A mounted WebView's hold on its ref:
|
|
26
|
-
type Attachment = { update(state: NavigationState): void; detach(): void };
|
|
25
|
+
/** A mounted WebView's hold on its ref: `handle` passes on the WebView's state, and lets go at unmount. */
|
|
27
26
|
type Adapter = {
|
|
28
27
|
nav: WebViewRefObject;
|
|
29
|
-
attach(handle: WebViewRef, state: NavigationState):
|
|
28
|
+
attach(handle: WebViewRef, state: NavigationState): void;
|
|
29
|
+
update(handle: WebViewRef, state: NavigationState): void;
|
|
30
|
+
detach(handle: WebViewRef): void;
|
|
30
31
|
};
|
|
31
32
|
|
|
32
33
|
/** The navigation object behind each ref object: created by createWebViewRef, or made on first use for a plain ref. */
|
|
@@ -67,14 +68,14 @@ function createAdapter(): Adapter {
|
|
|
67
68
|
}
|
|
68
69
|
attached = handle;
|
|
69
70
|
set(initial);
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
71
|
+
},
|
|
72
|
+
update(handle, next) {
|
|
73
|
+
if (attached === handle) set(next);
|
|
74
|
+
},
|
|
75
|
+
detach(handle) {
|
|
76
|
+
if (attached !== handle) return;
|
|
77
|
+
attached = null;
|
|
78
|
+
set(INITIAL_STATE);
|
|
78
79
|
},
|
|
79
80
|
};
|
|
80
81
|
}
|
|
@@ -101,22 +102,17 @@ export function useAttach(
|
|
|
101
102
|
handle: WebViewRef
|
|
102
103
|
): (state: NavigationState) => NavigationState {
|
|
103
104
|
const last = useRef(INITIAL_STATE);
|
|
104
|
-
const attachment = useRef<Attachment>(undefined);
|
|
105
105
|
const adapter = ref && typeof ref === 'object' ? adapterFor(ref) : undefined;
|
|
106
106
|
useImperativeHandle(adapter?.nav === ref ? undefined : ref, () => handle, [handle]);
|
|
107
107
|
useLayoutEffect(() => {
|
|
108
108
|
if (!adapter) return undefined;
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
return () => {
|
|
112
|
-
attached.detach();
|
|
113
|
-
attachment.current = undefined;
|
|
114
|
-
};
|
|
109
|
+
adapter.attach(handle, last.current);
|
|
110
|
+
return () => adapter.detach(handle);
|
|
115
111
|
}, [adapter, handle]);
|
|
116
112
|
return (state) => {
|
|
117
113
|
const was = last.current;
|
|
118
114
|
last.current = state;
|
|
119
|
-
|
|
115
|
+
adapter?.update(handle, state);
|
|
120
116
|
return was;
|
|
121
117
|
};
|
|
122
118
|
}
|
package/src/types.ts
CHANGED
|
@@ -211,7 +211,8 @@ export type NavigationState = {
|
|
|
211
211
|
* - `failed`: a network or SSL error, or a renderer crash, cut it off.
|
|
212
212
|
* - `cancelled`: it never showed a page (a stop before the response, a download, a 204, a redirect the rules blocked,
|
|
213
213
|
* a load a newer one replaced); a stop after the page arrived is `cancelled` on iOS but `finished` on Android, and
|
|
214
|
-
* a 204 is `finished` on iOS 17.
|
|
214
|
+
* a 204 is `finished` on iOS 17. On iOS a load replaced before it commits doesn't end: `loading` stays true and
|
|
215
|
+
* the newer load's outcome ends both.
|
|
215
216
|
*
|
|
216
217
|
* On Android with an Android System WebView older than 146, a load that never commits changes nothing here.
|
|
217
218
|
*/
|
|
@@ -242,20 +243,21 @@ export type ProcessGoneEvent = {
|
|
|
242
243
|
*/
|
|
243
244
|
cause: 'crash' | 'memory' | 'unknown';
|
|
244
245
|
/**
|
|
245
|
-
* Whether the core reloads the page after the crash.
|
|
246
|
+
* Whether the core reloads the page after the crash. The reload waits until the view is in a visible window and
|
|
247
|
+
* the app is not in the background; a `load()`, `reload()` or new `source` meanwhile loads instead.
|
|
246
248
|
*
|
|
247
249
|
* - iOS: in place.
|
|
248
|
-
* - Android: in a new WebView
|
|
249
|
-
*
|
|
250
|
+
* - Android: in a new WebView. The history is restored unless the `source` page was on screen. The props are
|
|
251
|
+
* applied again, but not what `call` set.
|
|
250
252
|
*
|
|
251
253
|
* It is false when:
|
|
252
254
|
*
|
|
253
255
|
* - a POST `source` is on screen: as in a browser, it isn't sent again unasked;
|
|
254
256
|
* - more than 3 crashes happened in 60 s (counted for the whole app on Android), until the next
|
|
255
|
-
* {@link WebViewRef.reload | reload()} (on iOS also a `source` change).
|
|
257
|
+
* {@link WebViewRef.reload | reload()} or {@link WebViewRef.load | load()} (on iOS also a `source` change).
|
|
256
258
|
*
|
|
257
|
-
* While false the view is blank. Leave `reload()` to the user, as a retry button: called from
|
|
258
|
-
* sends the POST again,
|
|
259
|
+
* While false the view is blank. Leave `reload()` and `load()` to the user, as a retry button: called from
|
|
260
|
+
* `onProcessGone`, `reload()` sends the POST again, and either starts the crash loop over.
|
|
259
261
|
* @see [Loading and error screens example](https://rasmuskard.github.io/react-native-minimal-webview/guides/examples/#loading-and-error-screens)
|
|
260
262
|
*/
|
|
261
263
|
recovered: boolean;
|
|
@@ -371,7 +373,7 @@ type PayloadArg<Payload> = undefined extends Payload ? [payload?: Payload] : [pa
|
|
|
371
373
|
* latest 1000 are kept: an older call rejects with `unavailable`.
|
|
372
374
|
*
|
|
373
375
|
* The page's own calls don't wait: one made before React Native has registered its method rejects with `not_found`.
|
|
374
|
-
* Unmounting rejects the calls
|
|
376
|
+
* Unmounting rejects the calls the page got with `navigated`, and the queued ones with `unavailable`.
|
|
375
377
|
*
|
|
376
378
|
* The page's `window.nativeBridge` has the same four methods, from its side: {@link PageBridge}.
|
|
377
379
|
* @see [Bridge example](https://rasmuskard.github.io/react-native-minimal-webview/guides/examples/#the-bridge)
|
|
@@ -878,7 +880,9 @@ export interface WebViewProps extends Omit<ViewProps, 'children'> {
|
|
|
878
880
|
* it, those keys apply; unset, they are the platform's own user agent.
|
|
879
881
|
*
|
|
880
882
|
* To append to the default one instead, set `ios.configuration.applicationNameForUserAgent` and, on Android,
|
|
881
|
-
* `android.settings.userAgentString` to `AndroidWebView.defaultUserAgent` plus your suffix.
|
|
883
|
+
* `android.settings.userAgentString` to `AndroidWebView.defaultUserAgent` plus your suffix. A change to
|
|
884
|
+
* {@link IOSSettings.configuration | ios.configuration} recreates the WebView: for a suffix that changes, read
|
|
885
|
+
* `navigator.userAgent` once with {@link WebViewRef.evaluate | evaluate()} and set `userAgent` to it plus the suffix.
|
|
882
886
|
*
|
|
883
887
|
* A change applies from the next navigation.
|
|
884
888
|
*/
|
|
@@ -901,8 +905,8 @@ export interface WebViewProps extends Omit<ViewProps, 'children'> {
|
|
|
901
905
|
*
|
|
902
906
|
* These skip the rules:
|
|
903
907
|
*
|
|
904
|
-
* - the `source` load, reloads and back/forward; a redirect of the `source` load
|
|
905
|
-
* does a redirect of a reload or back/forward;
|
|
908
|
+
* - the `source` load, {@link WebViewRef.load | load}, reloads and back/forward; a redirect of the `source` load or
|
|
909
|
+
* a `load` goes to the rules, and on Android so does a redirect of a reload or back/forward;
|
|
906
910
|
* - a form POST, on either platform, an iframe's to the main frame (`target=_top`) included: it loads in place; one
|
|
907
911
|
* to a new window loads in place on iOS and isn't shown on Android (the request may still reach the server);
|
|
908
912
|
* - `about:`, `data:` and `javascript:`, which load in place, except as a new window
|
|
@@ -987,7 +991,8 @@ export interface WebViewProps extends Omit<ViewProps, 'children'> {
|
|
|
987
991
|
/**
|
|
988
992
|
* Syncs cookies between `HTTPCookieStorage`, which holds the cookies of native requests, and the WebView:
|
|
989
993
|
*
|
|
990
|
-
* - `HTTPCookieStorage` into the WebView before each `source` load, which
|
|
994
|
+
* - `HTTPCookieStorage` into the WebView before each `source` load and {@link WebViewRef.load | load}, which wait
|
|
995
|
+
* for it;
|
|
991
996
|
* - the WebView into `HTTPCookieStorage` on every cookie change, deletions included, as it happens.
|
|
992
997
|
*
|
|
993
998
|
* Android needs nothing: `CookieManager` is shared app-wide, and flushed when the app goes to the background. A
|
|
@@ -1068,7 +1073,8 @@ export interface WebViewProps extends Omit<ViewProps, 'children'> {
|
|
|
1068
1073
|
/**
|
|
1069
1074
|
* Every navigation the rules, or their defaults, decided.
|
|
1070
1075
|
*
|
|
1071
|
-
* Not reported: the `source` load, reloads, back/forward, a form POST, and a
|
|
1076
|
+
* Not reported: the `source` load, {@link WebViewRef.load | load}, reloads, back/forward, a form POST, and a
|
|
1077
|
+
* navigation a native hook decides.
|
|
1072
1078
|
* @see [Navigation rules example](https://rasmuskard.github.io/react-native-minimal-webview/guides/examples/#navigation-rules)
|
|
1073
1079
|
*/
|
|
1074
1080
|
onNavigation?: (event: NavigationEvent) => void;
|
|
@@ -1115,9 +1121,10 @@ export interface WebViewProps extends Omit<ViewProps, 'children'> {
|
|
|
1115
1121
|
* return a promise:
|
|
1116
1122
|
*
|
|
1117
1123
|
* - After an unmount: the navigation methods do nothing and the four promise methods reject with `unavailable`.
|
|
1118
|
-
* - Pending when the WebView unmounts: the four reject with `navigated
|
|
1119
|
-
* - Just mounted: the four wait up to about a second for the view (on Android, a call from the parent's
|
|
1120
|
-
* can come before the view exists), then reject with `unavailable
|
|
1124
|
+
* - Pending when the WebView unmounts: the four reject with `navigated`, and a waiting `load` does nothing.
|
|
1125
|
+
* - Just mounted: the four and `load` wait up to about a second for the view (on Android, a call from the parent's
|
|
1126
|
+
* first effect can come before the view exists), then the four reject with `unavailable` and `load` does nothing. In
|
|
1127
|
+
* the background they don't wait.
|
|
1121
1128
|
* @sortStrategy source-order
|
|
1122
1129
|
* @group WebView
|
|
1123
1130
|
*/
|
|
@@ -1131,6 +1138,22 @@ export type WebViewRef = {
|
|
|
1131
1138
|
goBack(): void;
|
|
1132
1139
|
/** Goes forward one page; does nothing unless `canGoForward`. */
|
|
1133
1140
|
goForward(): void;
|
|
1141
|
+
/**
|
|
1142
|
+
* Loads `url` in place, as a navigation the app started, in a new history entry; the page on screen loads again in
|
|
1143
|
+
* its own. It leaves `source` as it is: a re-render with the same `source` still loads nothing. Together with a
|
|
1144
|
+
* `source` change, which of the two ends on screen depends on the platform and on timing: do one or the other.
|
|
1145
|
+
*
|
|
1146
|
+
* It starts the {@link ProcessGoneEvent.recovered | crash recovery} limit over. A `javascript:` URL loads nothing
|
|
1147
|
+
* (in development, with a warning): run a script with {@link WebViewRef.evaluate | evaluate}. Any other URL goes to
|
|
1148
|
+
* the platform, and one it can't load, such as an unknown scheme, ends with `outcome` `failed`; on iOS a string that
|
|
1149
|
+
* isn't a URL loads nothing, with a warning.
|
|
1150
|
+
*
|
|
1151
|
+
* A `file://` URL:
|
|
1152
|
+
*
|
|
1153
|
+
* - iOS: reads only within its directory.
|
|
1154
|
+
* - Android: needs `android.settings.allowFileAccess`, which lets a `file:` page read any file the app can.
|
|
1155
|
+
*/
|
|
1156
|
+
load(url: string): void;
|
|
1134
1157
|
/**
|
|
1135
1158
|
* Reloads the page; after a failed load, retries it (the `source` again, with its headers, when that failed), and
|
|
1136
1159
|
* loads the `source` when nothing is loaded.
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"defaultNavigationRules.d.ts","sourceRoot":"","sources":["../src/defaultNavigationRules.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAO9C;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,sBAAsB,EAAE,SAAS,cAAc,EAI1D,CAAC"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
const freeze = (value) => {
|
|
2
|
-
Object.values(value).forEach((field) => typeof field === 'object' && freeze(field));
|
|
3
|
-
return Object.freeze(value);
|
|
4
|
-
};
|
|
5
|
-
/**
|
|
6
|
-
* The rules `navigationRules` has when it is unset: `file:` is blocked, http(s) loads in place, and any other scheme
|
|
7
|
-
* opens externally from the main frame when a user gesture started it ({@link NavigationRule.userInitiated}).
|
|
8
|
-
*
|
|
9
|
-
* Anything else, an iframe's or one without a gesture, is blocked, so a page opens an app only right after the user's
|
|
10
|
-
* tap, click or key press, as each platform counts them. On iOS that leaves out the redirect after a form POST, such
|
|
11
|
-
* as an OAuth `myapp://callback`: an `external` rule for its scheme before these opens it.
|
|
12
|
-
*
|
|
13
|
-
* Frozen; spread it after your own rules to keep it.
|
|
14
|
-
* @see [Navigation rules example](https://rasmuskard.github.io/react-native-minimal-webview/guides/examples/#navigation-rules)
|
|
15
|
-
* @group Navigation
|
|
16
|
-
*/
|
|
17
|
-
export const defaultNavigationRules = freeze([
|
|
18
|
-
{ scheme: ['file'], action: 'block' },
|
|
19
|
-
{ scheme: ['http', 'https'], action: 'allow' },
|
|
20
|
-
{ mainFrame: true, userInitiated: true, action: 'external' },
|
|
21
|
-
]);
|
|
22
|
-
//# sourceMappingURL=defaultNavigationRules.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"defaultNavigationRules.js","sourceRoot":"","sources":["../src/defaultNavigationRules.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,GAAG,CAAmB,KAAQ,EAAK,EAAE;IAC/C,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,KAAe,CAAC,CAAC,CAAC;IAC9F,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC9B,CAAC,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAA8B,MAAM,CAAmB;IACxF,EAAE,MAAM,EAAE,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE;IACrC,EAAE,MAAM,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE;IAC9C,EAAE,SAAS,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE;CAC7D,CAAC,CAAC"}
|
package/ios/MRWExceptions.h
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
#import <Foundation/Foundation.h>
|
|
2
|
-
|
|
3
|
-
NS_ASSUME_NONNULL_BEGIN
|
|
4
|
-
|
|
5
|
-
/// Runs `block` and returns the Objective-C exception it raised as `name: reason`, or nil. Swift can't catch those;
|
|
6
|
-
/// Key-Value Coding raises one for an unknown key or a value a setter rejects.
|
|
7
|
-
FOUNDATION_EXPORT NSString *_Nullable MRWCatchException(void (NS_NOESCAPE ^block)(void)) NS_REFINED_FOR_SWIFT;
|
|
8
|
-
|
|
9
|
-
NS_ASSUME_NONNULL_END
|
package/ios/MRWExceptions.m
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
#import "MRWExceptions.h"
|
|
2
|
-
|
|
3
|
-
NSString *MRWCatchException(void (NS_NOESCAPE ^block)(void)) {
|
|
4
|
-
@try {
|
|
5
|
-
block();
|
|
6
|
-
return nil;
|
|
7
|
-
} @catch (NSException *exception) {
|
|
8
|
-
return [NSString stringWithFormat:@"%@: %@", exception.name, exception.reason ?: @""];
|
|
9
|
-
}
|
|
10
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { NavigationRule } from './types';
|
|
2
|
-
|
|
3
|
-
const freeze = <T extends object>(value: T): T => {
|
|
4
|
-
Object.values(value).forEach((field) => typeof field === 'object' && freeze(field as object));
|
|
5
|
-
return Object.freeze(value);
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* The rules `navigationRules` has when it is unset: `file:` is blocked, http(s) loads in place, and any other scheme
|
|
10
|
-
* opens externally from the main frame when a user gesture started it ({@link NavigationRule.userInitiated}).
|
|
11
|
-
*
|
|
12
|
-
* Anything else, an iframe's or one without a gesture, is blocked, so a page opens an app only right after the user's
|
|
13
|
-
* tap, click or key press, as each platform counts them. On iOS that leaves out the redirect after a form POST, such
|
|
14
|
-
* as an OAuth `myapp://callback`: an `external` rule for its scheme before these opens it.
|
|
15
|
-
*
|
|
16
|
-
* Frozen; spread it after your own rules to keep it.
|
|
17
|
-
* @see [Navigation rules example](https://rasmuskard.github.io/react-native-minimal-webview/guides/examples/#navigation-rules)
|
|
18
|
-
* @group Navigation
|
|
19
|
-
*/
|
|
20
|
-
export const defaultNavigationRules: readonly NavigationRule[] = freeze<NavigationRule[]>([
|
|
21
|
-
{ scheme: ['file'], action: 'block' },
|
|
22
|
-
{ scheme: ['http', 'https'], action: 'allow' },
|
|
23
|
-
{ mainFrame: true, userInitiated: true, action: 'external' },
|
|
24
|
-
]);
|