react-native-minimal-webview 1.1.0 → 1.2.1

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.
Files changed (74) hide show
  1. package/README.md +35 -31
  2. package/android/src/main/java/expo/modules/minimalwebview/Hooks.kt +1 -6
  3. package/android/src/main/java/expo/modules/minimalwebview/MinimalWebView.kt +56 -31
  4. package/android/src/main/java/expo/modules/minimalwebview/MinimalWebViewClients.kt +3 -2
  5. package/android/src/main/java/expo/modules/minimalwebview/MinimalWebViewModule.kt +16 -4
  6. package/android/src/main/java/expo/modules/minimalwebview/MinimalWebViewNavigation.kt +3 -3
  7. package/android/src/main/java/expo/modules/minimalwebview/MinimalWebViewScripts.kt +5 -7
  8. package/android/src/main/java/expo/modules/minimalwebview/PlatformSettings.kt +47 -36
  9. package/android/src/main/java/expo/modules/minimalwebview/PullToRefresh.kt +2 -2
  10. package/android/src/main/java/expo/modules/minimalwebview/requests/Downloads.kt +7 -8
  11. package/android/src/main/java/expo/modules/minimalwebview/requests/FullscreenVideo.kt +2 -2
  12. package/android/src/main/java/expo/modules/minimalwebview/requests/Permissions.kt +4 -5
  13. package/build/WebView.d.ts +4 -10
  14. package/build/WebView.d.ts.map +1 -1
  15. package/build/WebView.js +60 -103
  16. package/build/WebView.js.map +1 -1
  17. package/build/bridge/createBridge.d.ts +17 -11
  18. package/build/bridge/createBridge.d.ts.map +1 -1
  19. package/build/bridge/createBridge.js +32 -44
  20. package/build/bridge/createBridge.js.map +1 -1
  21. package/build/bridge/endpoint.d.ts +1 -3
  22. package/build/bridge/endpoint.d.ts.map +1 -1
  23. package/build/bridge/endpoint.js +2 -2
  24. package/build/bridge/endpoint.js.map +1 -1
  25. package/build/bridge/origins.d.ts +5 -2
  26. package/build/bridge/origins.d.ts.map +1 -1
  27. package/build/bridge/origins.js +15 -4
  28. package/build/bridge/origins.js.map +1 -1
  29. package/build/bridge/pageClient.generated.d.ts +1 -1
  30. package/build/bridge/pageClient.generated.d.ts.map +1 -1
  31. package/build/bridge/pageClient.generated.js +1 -1
  32. package/build/bridge/pageClient.generated.js.map +1 -1
  33. package/build/index.d.ts +1 -1
  34. package/build/index.d.ts.map +1 -1
  35. package/build/index.js +1 -1
  36. package/build/index.js.map +1 -1
  37. package/build/{defaultNavigationRules.d.ts → navigationRules.d.ts} +10 -1
  38. package/build/navigationRules.d.ts.map +1 -0
  39. package/build/navigationRules.js +93 -0
  40. package/build/navigationRules.js.map +1 -0
  41. package/build/refStore.d.ts.map +1 -1
  42. package/build/refStore.js +13 -17
  43. package/build/refStore.js.map +1 -1
  44. package/build/types.d.ts +66 -40
  45. package/build/types.d.ts.map +1 -1
  46. package/ios/DelegateProxy.swift +35 -30
  47. package/ios/Loads.swift +4 -4
  48. package/ios/MRWInvoke.h +8 -0
  49. package/ios/MRWInvoke.m +39 -24
  50. package/ios/MinimalWebView+Dialogs.swift +4 -2
  51. package/ios/MinimalWebView+Navigation.swift +23 -13
  52. package/ios/MinimalWebView+Scripts.swift +6 -1
  53. package/ios/MinimalWebView.swift +78 -29
  54. package/ios/MinimalWebViewModule.swift +1 -0
  55. package/ios/NavigationRules.swift +15 -15
  56. package/ios/PlatformSettings.swift +2 -13
  57. package/ios/SharedCookies.swift +1 -2
  58. package/mocks/MinimalWebView.ts +5 -0
  59. package/package.json +9 -8
  60. package/src/WebView.tsx +74 -117
  61. package/src/bridge/createBridge.ts +45 -53
  62. package/src/bridge/endpoint.ts +3 -5
  63. package/src/bridge/origins.ts +18 -6
  64. package/src/bridge/pageClient.generated.ts +1 -1
  65. package/src/index.ts +1 -1
  66. package/src/navigationRules.ts +111 -0
  67. package/src/refStore.ts +15 -19
  68. package/src/types.ts +66 -40
  69. package/build/defaultNavigationRules.d.ts.map +0 -1
  70. package/build/defaultNavigationRules.js +0 -22
  71. package/build/defaultNavigationRules.js.map +0 -1
  72. package/ios/MRWExceptions.h +0 -9
  73. package/ios/MRWExceptions.m +0 -10
  74. package/src/defaultNavigationRules.ts +0 -24
@@ -0,0 +1,111 @@
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
+ ]);
25
+
26
+ /** Each rule field's kind, from its type, so that a field missing here, or not in the type, fails to compile. */
27
+ const RULE_FIELDS = new Map(
28
+ Object.entries({
29
+ scheme: 'list',
30
+ host: 'list',
31
+ path: 'list',
32
+ query: 'list',
33
+ mainFrame: 'flag',
34
+ newWindow: 'flag',
35
+ userInitiated: 'flag',
36
+ action: 'action',
37
+ } satisfies {
38
+ [K in keyof NavigationRule]-?: NonNullable<NavigationRule[K]> extends readonly string[]
39
+ ? 'list'
40
+ : NonNullable<NavigationRule[K]> extends boolean
41
+ ? 'flag'
42
+ : 'action';
43
+ })
44
+ );
45
+ const ACTIONS: unknown[] = Object.keys({
46
+ allow: 0,
47
+ block: 0,
48
+ external: 0,
49
+ ask: 0,
50
+ } satisfies Record<NavigationRule['action'], 0>);
51
+
52
+ /** A value as a warning shows it. */
53
+ const shown = (value: unknown) => {
54
+ try {
55
+ return JSON.stringify(value) ?? String(value);
56
+ } catch {
57
+ // A BigInt, a circular value or a throwing toJSON: the message runs in production too, so it must not throw.
58
+ return typeof value === 'bigint' ? String(value) : Object.prototype.toString.call(value);
59
+ }
60
+ };
61
+
62
+ /** What a field of each kind takes, as a warning says it, and the check. */
63
+ const FIELD_KINDS = {
64
+ list: {
65
+ takes: 'an array of strings',
66
+ ok: (value: unknown) =>
67
+ Array.isArray(value) && value.every((entry) => typeof entry === 'string'),
68
+ },
69
+ flag: { takes: 'true or false', ok: (value: unknown) => typeof value === 'boolean' },
70
+ action: { takes: `one of ${shown(ACTIONS)}`, ok: (value: unknown) => ACTIONS.includes(value) },
71
+ };
72
+
73
+ function ruleProblem(rule: unknown) {
74
+ if (typeof rule !== 'object' || rule === null) return `must be an object, not ${shown(rule)}`;
75
+ // A missing action is checked as an undefined one; any other field may be undefined (unset).
76
+ for (const [key, value] of Object.entries({ action: undefined, ...rule })) {
77
+ const kind = RULE_FIELDS.get(key);
78
+ if (!kind) return `unknown key ${shown(key)}`;
79
+ if ((value !== undefined || kind === 'action') && !FIELD_KINDS[kind].ok(value))
80
+ return `${key} must be ${FIELD_KINDS[kind].takes}, not ${shown(value)}`;
81
+ }
82
+ return undefined;
83
+ }
84
+
85
+ /**
86
+ * The rules as the core gets them, and a warning for each malformed one. The core skips an unknown key and a
87
+ * non-boolean flag, which would widen a rule (`hosts` would match every host), so a malformed rule becomes a `block`
88
+ * one. The same array when none is malformed.
89
+ */
90
+ export function checkNavigationRules(given: unknown): {
91
+ checked: NavigationRule[];
92
+ warnings: string[];
93
+ } {
94
+ if (!Array.isArray(given))
95
+ return {
96
+ checked: [],
97
+ warnings: [`navigationRules: must be an array, not ${shown(given)}; treated as []`],
98
+ };
99
+ // Array.from, not map: map skips a sparse array's holes, which would reach native unchecked.
100
+ const problems = Array.from(given, ruleProblem);
101
+ return {
102
+ checked: (problems.some(Boolean)
103
+ ? Array.from(given, (rule: unknown, i) => (problems[i] ? { action: 'block' } : rule))
104
+ : given) as NavigationRule[],
105
+ warnings: problems.flatMap((problem, i) =>
106
+ problem
107
+ ? [`navigationRules[${i}]: ${problem}; it blocks every navigation that reaches it`]
108
+ : []
109
+ ),
110
+ };
111
+ }
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: it passes on the WebView's state, and lets go at unmount. */
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): Attachment;
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
- return {
71
- update: (next) => attached === handle && set(next),
72
- detach() {
73
- if (attached !== handle) return;
74
- attached = null;
75
- set(INITIAL_STATE);
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
- const attached = adapter.attach(handle, last.current);
110
- attachment.current = attached;
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
- attachment.current?.update(state);
115
+ adapter?.update(handle, state);
120
116
  return was;
121
117
  };
122
118
  }
package/src/types.ts CHANGED
@@ -14,6 +14,7 @@ import type {
14
14
  /**
15
15
  * What the WebView loads: a URL, or an HTML string.
16
16
  * @see [Local files example](https://rasmuskard.github.io/react-native-minimal-webview/guides/examples/#local-files)
17
+ * @see [Bundled page folder example](https://rasmuskard.github.io/react-native-minimal-webview/guides/examples/#load-a-bundled-page-folder)
17
18
  * @group WebView
18
19
  */
19
20
  export type WebViewSource =
@@ -211,7 +212,8 @@ export type NavigationState = {
211
212
  * - `failed`: a network or SSL error, or a renderer crash, cut it off.
212
213
  * - `cancelled`: it never showed a page (a stop before the response, a download, a 204, a redirect the rules blocked,
213
214
  * 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.
215
+ * a 204 is `finished` below iOS 26.2. On iOS a load replaced before it commits doesn't end: `loading` stays true and
216
+ * the newer load's outcome ends both.
215
217
  *
216
218
  * On Android with an Android System WebView older than 146, a load that never commits changes nothing here.
217
219
  */
@@ -242,20 +244,21 @@ export type ProcessGoneEvent = {
242
244
  */
243
245
  cause: 'crash' | 'memory' | 'unknown';
244
246
  /**
245
- * Whether the core reloads the page after the crash.
247
+ * Whether the core reloads the page after the crash. The reload waits until the view is in a visible window and
248
+ * the app is not in the background; a `load()`, `reload()` or new `source` meanwhile loads instead.
246
249
  *
247
250
  * - iOS: in place.
248
- * - Android: in a new WebView, once the view's window is visible. The history is restored unless the `source` page
249
- * was on screen. The props are applied again, but not what `call` set.
251
+ * - Android: in a new WebView. The history is restored, unless the `source` page was on screen and reloads. The
252
+ * props are applied again, but not what `call` set.
250
253
  *
251
254
  * It is false when:
252
255
  *
253
256
  * - a POST `source` is on screen: as in a browser, it isn't sent again unasked;
254
257
  * - 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).
258
+ * {@link WebViewRef.reload | reload()} or {@link WebViewRef.load | load()} (on iOS also a `source` change).
256
259
  *
257
- * While false the view is blank. Leave `reload()` to the user, as a retry button: called from `onProcessGone` it
258
- * sends the POST again, or starts the crash loop over.
260
+ * While false the view is blank. Leave `reload()` and `load()` to the user, as a retry button: called from
261
+ * `onProcessGone`, `reload()` sends the POST again, and either starts the crash loop over.
259
262
  * @see [Loading and error screens example](https://rasmuskard.github.io/react-native-minimal-webview/guides/examples/#loading-and-error-screens)
260
263
  */
261
264
  recovered: boolean;
@@ -371,7 +374,7 @@ type PayloadArg<Payload> = undefined extends Payload ? [payload?: Payload] : [pa
371
374
  * latest 1000 are kept: an older call rejects with `unavailable`.
372
375
  *
373
376
  * 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 in flight with `navigated`.
377
+ * Unmounting rejects the calls the page got with `navigated`, and the queued ones with `unavailable`.
375
378
  *
376
379
  * The page's `window.nativeBridge` has the same four methods, from its side: {@link PageBridge}.
377
380
  * @see [Bridge example](https://rasmuskard.github.io/react-native-minimal-webview/guides/examples/#the-bridge)
@@ -705,7 +708,8 @@ export type AndroidSettings = {
705
708
  *
706
709
  * - On: `javaScriptEnabled`, `domStorageEnabled`, `supportMultipleWindows`, `builtInZoomControls`,
707
710
  * `useWideViewPort`, `loadWithOverviewMode` and, with Android System WebView 146 and newer,
708
- * `backForwardCacheEnabled`.
711
+ * `backForwardCacheEnabled`. Older ones refuse `backForwardCacheEnabled: true`, in this prop and in `call`:
712
+ * a page restored from the cache there reports no load end.
709
713
  * - Off: `allowFileAccess`, `allowContentAccess`, `displayZoomControls` and `downloadFaviconsEnabled`.
710
714
  * - `mixedContentMode`: `MIXED_CONTENT_NEVER_ALLOW`.
711
715
  *
@@ -825,15 +829,14 @@ export type ErrorCode =
825
829
  export type CodedError = Error & { code: ErrorCode };
826
830
 
827
831
  /**
828
- * What the WebView loads, its settings, and the callbacks for its events and the page's requests.
832
+ * The props of `<WebView>`, of which only `source` is required.
829
833
  *
830
- * The ones from React Native's `ViewProps` (`style`, `testID`, `nativeID`, the accessibility props, layout and touch
831
- * events) go to the native view.
834
+ * React Native's `ViewProps` (`style`, `testID`, `nativeID`, the accessibility props, layout and touch events) go to
835
+ * the native view.
832
836
  *
833
837
  * Every `on…` callback is read when its event or request comes, so adding, changing or removing one applies to the
834
- * next, and a request without one gets the default described on its prop.
835
- *
836
- * One that answers a request and throws (or rejects) is logged with `console.error` and gives the refusing answer:
838
+ * next. A request without its callback gets the default its prop describes; one whose callback throws or rejects is
839
+ * logged with `console.error` and gets the refusing answer:
837
840
  *
838
841
  * - `onNavigationRequest`: `block`
839
842
  * - `onOpenExternal`: null (the core opens nothing)
@@ -844,16 +847,15 @@ export type CodedError = Error & { code: ErrorCode };
844
847
  * The `signal` such a callback gets aborts when the core stops waiting for its answer (the page moved on, crashed or
845
848
  * unmounted), and a late answer is dropped.
846
849
  *
847
- * JS dialogs (`alert`, `confirm`, `prompt`) and HTTP auth have no prop.
850
+ * JS dialogs (`alert`, `confirm`, `prompt`) and HTTP auth have no prop: `dialogs` and `basicAuthCredential` of
851
+ * `@react-native-minimal-webview/extensions` take them over, or a native hook does. Without one:
848
852
  *
849
853
  * - iOS dialogs: a `UIAlertController` titled with the frame's host, or `JavaScript` for a frame without one
850
854
  * (`data:`, sandboxed, `file:`). One shows at a time; one that comes while another shows is cancelled.
851
- * - Android dialogs: WebView's own.
855
+ * - Android dialogs: WebView's own. One still on screen when its WebView unmounts stays there, and a WebView older
856
+ * than 149 then gets no touches until the app restarts. The `dialogs` extension shows no native dialog.
852
857
  * - HTTP auth: cancelled on Android. On iOS WebKit's default handling applies, so without a stored credential the
853
858
  * site's 401 page shows.
854
- *
855
- * `dialogs` and `basicAuthCredential` of `@react-native-minimal-webview/extensions` take them over, or a native hook
856
- * does.
857
859
  * @sortStrategy source-order
858
860
  * @group WebView
859
861
  */
@@ -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 goes to the rules, and on Android so
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,11 +991,13 @@ 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 waits for it;
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
- * Android needs nothing: `CookieManager` is shared app-wide, and flushed when the app goes to the background. A
994
- * WebView on another `android.webView.profile` has that profile's cookies instead.
998
+ * Android needs nothing: `CookieManager` is shared app-wide, React Native's `fetch` uses it too, and it is flushed
999
+ * when the app goes to the background. A WebView on another `android.webView.profile` has that profile's cookies
1000
+ * instead.
995
1001
  * @default `false`
996
1002
  * @ios
997
1003
  * @see [Cookies example](https://rasmuskard.github.io/react-native-minimal-webview/guides/examples/#cookies)
@@ -1068,7 +1074,8 @@ export interface WebViewProps extends Omit<ViewProps, 'children'> {
1068
1074
  /**
1069
1075
  * Every navigation the rules, or their defaults, decided.
1070
1076
  *
1071
- * Not reported: the `source` load, reloads, back/forward, a form POST, and a navigation a native hook decides.
1077
+ * Not reported: the `source` load, {@link WebViewRef.load | load}, reloads, back/forward, a form POST, and a
1078
+ * navigation a native hook decides.
1072
1079
  * @see [Navigation rules example](https://rasmuskard.github.io/react-native-minimal-webview/guides/examples/#navigation-rules)
1073
1080
  */
1074
1081
  onNavigation?: (event: NavigationEvent) => void;
@@ -1086,6 +1093,9 @@ export interface WebViewProps extends Omit<ViewProps, 'children'> {
1086
1093
  * with an Android System WebView older than 146, an SSL error on a back/forward load isn't reported.
1087
1094
  *
1088
1095
  * A renderer crash isn't reported here: it makes the cut-off load's `outcome` `failed` and calls `onProcessGone`.
1096
+ *
1097
+ * On Android it also gets a `network` error with code `-1` when no WebView can be made, because Android System
1098
+ * WebView is missing, disabled or updating; {@link WebViewRef.reload | reload()} tries again.
1089
1099
  * @see [Loading and error screens example](https://rasmuskard.github.io/react-native-minimal-webview/guides/examples/#loading-and-error-screens)
1090
1100
  */
1091
1101
  onError?: (event: LoadErrorEvent) => void;
@@ -1115,9 +1125,10 @@ export interface WebViewProps extends Omit<ViewProps, 'children'> {
1115
1125
  * return a promise:
1116
1126
  *
1117
1127
  * - 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 first effect
1120
- * can come before the view exists), then reject with `unavailable`. In the background they don't wait.
1128
+ * - Pending when the WebView unmounts: the four reject with `navigated`, and a waiting `load` does nothing.
1129
+ * - Just mounted: the four and `load` wait up to about a second for the view (on Android, a call from the parent's
1130
+ * first effect can come before the view exists), then the four reject with `unavailable` and `load` does nothing. In
1131
+ * the background they don't wait.
1121
1132
  * @sortStrategy source-order
1122
1133
  * @group WebView
1123
1134
  */
@@ -1131,6 +1142,22 @@ export type WebViewRef = {
1131
1142
  goBack(): void;
1132
1143
  /** Goes forward one page; does nothing unless `canGoForward`. */
1133
1144
  goForward(): void;
1145
+ /**
1146
+ * Loads `url` in place, as a navigation the app started, in a new history entry; the page on screen loads again in
1147
+ * its own. It leaves `source` as it is: a re-render with the same `source` still loads nothing. Together with a
1148
+ * `source` change, which of the two ends on screen depends on the platform and on timing: do one or the other.
1149
+ *
1150
+ * It starts the {@link ProcessGoneEvent.recovered | crash recovery} limit over. A `javascript:` URL loads nothing
1151
+ * (in development, with a warning): run a script with {@link WebViewRef.evaluate | evaluate}. Any other URL goes to
1152
+ * the platform, and one it can't load, such as an unknown scheme, ends with `outcome` `failed`; on iOS a string that
1153
+ * isn't a URL loads nothing, with a warning.
1154
+ *
1155
+ * A `file://` URL:
1156
+ *
1157
+ * - iOS: reads only within its directory.
1158
+ * - Android: needs `android.settings.allowFileAccess`, which lets a `file:` page read any file the app can.
1159
+ */
1160
+ load(url: string): void;
1134
1161
  /**
1135
1162
  * Reloads the page; after a failed load, retries it (the `source` again, with its headers, when that failed), and
1136
1163
  * loads the `source` when nothing is loaded.
@@ -1167,13 +1194,14 @@ export type WebViewRef = {
1167
1194
  */
1168
1195
  get(key: string): Promise<unknown>;
1169
1196
  /**
1170
- * Calls a platform method, `root.method`, and resolves with its result through JSON. It acts on the WebView as it is
1171
- * when the call arrives: a navigation doesn't reject it.
1197
+ * Calls a platform method, `root.method`, with `args`, and resolves with its result through JSON.
1172
1198
  *
1173
- * The roots are those of {@link WebViewRef.get | get}. On Android `method` is a public method of the root's object;
1174
- * on iOS an Objective-C selector.
1199
+ * The roots are those of {@link WebViewRef.get | get}. On iOS `method` is an Objective-C selector; on Android a
1200
+ * public method of the root's object. Leave a trailing completion handler (iOS) or `ValueCallback` (Android) out of
1201
+ * `args`: the call resolves with what it reports, or on iOS rejects with its error.
1175
1202
  *
1176
- * Rejects with a {@link CodedError}: `not_found`, `unavailable` or `native_error`.
1203
+ * It acts on the WebView as it is when the call arrives: a navigation doesn't reject it. Rejects with a
1204
+ * {@link CodedError}: `not_found`, `unavailable` or `native_error`.
1177
1205
  *
1178
1206
  * The core owns, and so rejects:
1179
1207
  *
@@ -1185,11 +1213,9 @@ export type WebViewRef = {
1185
1213
  * `resumeTimers`, `evaluateJavascript` and remote debugging
1186
1214
  * ({@link AndroidWebView.setWebContentsDebuggingEnabled}).
1187
1215
  *
1188
- * A trailing completion handler (iOS) or `ValueCallback` (Android) is left out of `args`: the call resolves with what
1189
- * it reports, or on iOS rejects with its error. On iOS, a selector whose completion handler isn't in this package's
1190
- * SDK headers, or reports something other than an object, an error or an integer, rejects with `native_error`. On
1191
- * Android, a method that takes `args` as they are wins over one that also takes a callback, and a `null` in the
1192
- * callback's place passes none.
1216
+ * On iOS, a selector whose completion handler isn't in this package's SDK headers, or reports something other than
1217
+ * an object, an error or an integer, rejects with `native_error`. On Android, a method that takes `args` as they are
1218
+ * wins over one that also takes a callback, and a `null` in the callback's place passes none.
1193
1219
  *
1194
1220
  * One mistake the signature can't catch crashes the app: on iOS an object argument of the wrong class, and on Android
1195
1221
  * a `null` listener or callback other than the trailing `ValueCallback`, once WebView calls it. For a method that
@@ -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"}
@@ -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
@@ -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
- ]);