react-native-minimal-webview 1.0.1 → 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 +19 -32
- package/android/src/main/java/expo/modules/minimalwebview/MinimalWebView.kt +55 -26
- package/android/src/main/java/expo/modules/minimalwebview/MinimalWebViewClients.kt +3 -3
- package/android/src/main/java/expo/modules/minimalwebview/MinimalWebViewModule.kt +2 -1
- package/android/src/main/java/expo/modules/minimalwebview/MinimalWebViewNavigation.kt +8 -8
- package/android/src/main/java/expo/modules/minimalwebview/MinimalWebViewScripts.kt +5 -7
- package/android/src/main/java/expo/modules/minimalwebview/PlatformSettings.kt +32 -44
- 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 -107
- package/build/WebView.js.map +1 -1
- package/build/bridge/createBridge.d.ts +19 -13
- package/build/bridge/createBridge.d.ts.map +1 -1
- package/build/bridge/createBridge.js +33 -45
- package/build/bridge/createBridge.js.map +1 -1
- package/build/bridge/endpoint.d.ts +3 -8
- package/build/bridge/endpoint.d.ts.map +1 -1
- package/build/bridge/endpoint.js +2 -3
- 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 -19
- package/build/refStore.js.map +1 -1
- package/build/types.d.ts +55 -35
- package/build/types.d.ts.map +1 -1
- package/ios/DelegateProxy.swift +32 -30
- package/ios/DocumentEnd.swift +1 -2
- package/ios/Hooks.swift +28 -28
- package/ios/Loads.swift +5 -4
- package/ios/MRWInvoke.h +10 -9
- package/ios/MRWInvoke.m +39 -24
- package/ios/MinimalWebView+Navigation.swift +18 -16
- package/ios/MinimalWebView+Scripts.swift +0 -8
- package/ios/MinimalWebView.podspec +0 -1
- package/ios/MinimalWebView.swift +77 -35
- package/ios/MinimalWebViewModule.swift +1 -0
- package/ios/NavigationRules.swift +15 -15
- package/ios/OriginRules.swift +6 -0
- package/ios/PlatformSettings.swift +3 -22
- package/ios/Recovery.swift +6 -5
- package/ios/SharedCookies.swift +1 -2
- package/package.json +7 -3
- package/src/WebView.tsx +50 -123
- package/src/bridge/createBridge.ts +48 -56
- package/src/bridge/endpoint.ts +6 -9
- package/src/bridge/origins.ts +18 -6
- package/src/bridge/pageClient.generated.ts +1 -1
- package/src/bridge/pageClient.ts +3 -7
- package/src/bridge/protocol.ts +1 -1
- package/src/index.ts +1 -1
- package/src/navigationRules.ts +111 -0
- package/src/refStore.ts +15 -21
- package/src/types.ts +56 -35
- 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/index.ts
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
export { AndroidWebView, WebView } from './WebView';
|
|
24
24
|
export { createWebViewRef, useWebViewState } from './refStore';
|
|
25
25
|
export { createBridge } from './bridge/createBridge';
|
|
26
|
-
export { defaultNavigationRules } from './
|
|
26
|
+
export { defaultNavigationRules } from './navigationRules';
|
|
27
27
|
export { reactNativeWebViewMessages } from './reactNativeWebViewMessages';
|
|
28
28
|
export { AndroidConstants, IOSConstants } from './platform.generated';
|
|
29
29
|
export type {
|
|
@@ -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
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// The ref store: each ref object's navigation state and the WebView handle attached to it, behind createWebViewRef,
|
|
2
|
-
// useWebViewState and WebView's `ref`.
|
|
3
1
|
import {
|
|
4
2
|
type Ref,
|
|
5
3
|
type RefObject,
|
|
@@ -24,11 +22,12 @@ const INITIAL_STATE: NavigationState = {
|
|
|
24
22
|
outcome: null,
|
|
25
23
|
};
|
|
26
24
|
|
|
27
|
-
/** A mounted WebView's hold on its ref:
|
|
28
|
-
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. */
|
|
29
26
|
type Adapter = {
|
|
30
27
|
nav: WebViewRefObject;
|
|
31
|
-
attach(handle: WebViewRef, state: NavigationState):
|
|
28
|
+
attach(handle: WebViewRef, state: NavigationState): void;
|
|
29
|
+
update(handle: WebViewRef, state: NavigationState): void;
|
|
30
|
+
detach(handle: WebViewRef): void;
|
|
32
31
|
};
|
|
33
32
|
|
|
34
33
|
/** The navigation object behind each ref object: created by createWebViewRef, or made on first use for a plain ref. */
|
|
@@ -69,14 +68,14 @@ function createAdapter(): Adapter {
|
|
|
69
68
|
}
|
|
70
69
|
attached = handle;
|
|
71
70
|
set(initial);
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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);
|
|
80
79
|
},
|
|
81
80
|
};
|
|
82
81
|
}
|
|
@@ -103,22 +102,17 @@ export function useAttach(
|
|
|
103
102
|
handle: WebViewRef
|
|
104
103
|
): (state: NavigationState) => NavigationState {
|
|
105
104
|
const last = useRef(INITIAL_STATE);
|
|
106
|
-
const attachment = useRef<Attachment>(undefined);
|
|
107
105
|
const adapter = ref && typeof ref === 'object' ? adapterFor(ref) : undefined;
|
|
108
106
|
useImperativeHandle(adapter?.nav === ref ? undefined : ref, () => handle, [handle]);
|
|
109
107
|
useLayoutEffect(() => {
|
|
110
108
|
if (!adapter) return undefined;
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
return () => {
|
|
114
|
-
attached.detach();
|
|
115
|
-
attachment.current = undefined;
|
|
116
|
-
};
|
|
109
|
+
adapter.attach(handle, last.current);
|
|
110
|
+
return () => adapter.detach(handle);
|
|
117
111
|
}, [adapter, handle]);
|
|
118
112
|
return (state) => {
|
|
119
113
|
const was = last.current;
|
|
120
114
|
last.current = state;
|
|
121
|
-
|
|
115
|
+
adapter?.update(handle, state);
|
|
122
116
|
return was;
|
|
123
117
|
};
|
|
124
118
|
}
|
package/src/types.ts
CHANGED
|
@@ -37,8 +37,6 @@ export type WebViewSource =
|
|
|
37
37
|
*
|
|
38
38
|
* Its `Content-Type` is `application/x-www-form-urlencoded` unless iOS `headers` set one; Android ignores
|
|
39
39
|
* `headers` for a POST.
|
|
40
|
-
*
|
|
41
|
-
* `reload()` sends the POST again; {@link ProcessGoneEvent.recovered | crash recovery} doesn't.
|
|
42
40
|
*/
|
|
43
41
|
body?: string;
|
|
44
42
|
/**
|
|
@@ -213,7 +211,8 @@ export type NavigationState = {
|
|
|
213
211
|
* - `failed`: a network or SSL error, or a renderer crash, cut it off.
|
|
214
212
|
* - `cancelled`: it never showed a page (a stop before the response, a download, a 204, a redirect the rules blocked,
|
|
215
213
|
* a load a newer one replaced); a stop after the page arrived is `cancelled` on iOS but `finished` on Android, and
|
|
216
|
-
* 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.
|
|
217
216
|
*
|
|
218
217
|
* On Android with an Android System WebView older than 146, a load that never commits changes nothing here.
|
|
219
218
|
*/
|
|
@@ -244,20 +243,21 @@ export type ProcessGoneEvent = {
|
|
|
244
243
|
*/
|
|
245
244
|
cause: 'crash' | 'memory' | 'unknown';
|
|
246
245
|
/**
|
|
247
|
-
* 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.
|
|
248
248
|
*
|
|
249
249
|
* - iOS: in place.
|
|
250
|
-
* - Android: in a new WebView
|
|
251
|
-
*
|
|
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.
|
|
252
252
|
*
|
|
253
253
|
* It is false when:
|
|
254
254
|
*
|
|
255
255
|
* - a POST `source` is on screen: as in a browser, it isn't sent again unasked;
|
|
256
256
|
* - more than 3 crashes happened in 60 s (counted for the whole app on Android), until the next
|
|
257
|
-
* {@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).
|
|
258
258
|
*
|
|
259
|
-
* While false the view is blank. Leave `reload()` to the user, as a retry button: called from
|
|
260
|
-
* 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.
|
|
261
261
|
* @see [Loading and error screens example](https://rasmuskard.github.io/react-native-minimal-webview/guides/examples/#loading-and-error-screens)
|
|
262
262
|
*/
|
|
263
263
|
recovered: boolean;
|
|
@@ -324,8 +324,6 @@ export type BridgeHandler<Params = unknown, Result = unknown> = (
|
|
|
324
324
|
* - `params` or a payload is required where its type doesn't allow `undefined`.
|
|
325
325
|
* - A method's `params` and `result` are left out when it has none.
|
|
326
326
|
* - Every key is required: `{}` for a side that handles nothing.
|
|
327
|
-
* - The method and event maps are `type`s or written inline, not `interfaces`: an interface has no index signature, so
|
|
328
|
-
* it doesn't satisfy `Record`.
|
|
329
327
|
*
|
|
330
328
|
* Params, results and payloads cross as JSON: a `Date` arrives as its ISO string, a `Map` or `Set` as `{}`, `NaN`
|
|
331
329
|
* as `null`, and `undefined` properties and functions are left out. A handler's result that JSON can't encode (a
|
|
@@ -342,6 +340,16 @@ export type BridgeSchema = {
|
|
|
342
340
|
events: Record<string, unknown>;
|
|
343
341
|
};
|
|
344
342
|
|
|
343
|
+
/**
|
|
344
|
+
* The constraint on a schema type `S`: a {@link BridgeSchema} keyed by `S`'s own names, so an `interface` satisfies it.
|
|
345
|
+
* @group Bridge
|
|
346
|
+
*/
|
|
347
|
+
export type SchemaOf<S> = {
|
|
348
|
+
[Side in keyof BridgeSchema]: {
|
|
349
|
+
[K in keyof S[Side & keyof S]]: BridgeSchema[Side][string];
|
|
350
|
+
};
|
|
351
|
+
};
|
|
352
|
+
|
|
345
353
|
type ParamsOf<Method> = 'params' extends keyof Method ? Method['params' & keyof Method] : undefined;
|
|
346
354
|
type ResultOf<Method> = 'result' extends keyof Method ? Method['result' & keyof Method] : unknown;
|
|
347
355
|
type CallArgs<Method> =
|
|
@@ -365,13 +373,13 @@ type PayloadArg<Payload> = undefined extends Payload ? [payload?: Payload] : [pa
|
|
|
365
373
|
* latest 1000 are kept: an older call rejects with `unavailable`.
|
|
366
374
|
*
|
|
367
375
|
* The page's own calls don't wait: one made before React Native has registered its method rejects with `not_found`.
|
|
368
|
-
* Unmounting rejects the calls
|
|
376
|
+
* Unmounting rejects the calls the page got with `navigated`, and the queued ones with `unavailable`.
|
|
369
377
|
*
|
|
370
378
|
* The page's `window.nativeBridge` has the same four methods, from its side: {@link PageBridge}.
|
|
371
379
|
* @see [Bridge example](https://rasmuskard.github.io/react-native-minimal-webview/guides/examples/#the-bridge)
|
|
372
380
|
* @group Bridge
|
|
373
381
|
*/
|
|
374
|
-
export type Bridge<Schema extends
|
|
382
|
+
export type Bridge<Schema extends SchemaOf<Schema> = BridgeSchema> = {
|
|
375
383
|
/**
|
|
376
384
|
* Answers `nativeBridge.call(method, params)` from the page, for a method of the schema's `reactNative`.
|
|
377
385
|
*
|
|
@@ -426,7 +434,7 @@ export type Bridge<Schema extends BridgeSchema = BridgeSchema> = {
|
|
|
426
434
|
* @see [In the page example](https://rasmuskard.github.io/react-native-minimal-webview/guides/examples/#in-the-page)
|
|
427
435
|
* @group Bridge
|
|
428
436
|
*/
|
|
429
|
-
export type PageBridge<Schema extends
|
|
437
|
+
export type PageBridge<Schema extends SchemaOf<Schema> = BridgeSchema> = {
|
|
430
438
|
/**
|
|
431
439
|
* Answers `bridge.call(method, params)` from React Native, for a method of the schema's `page`.
|
|
432
440
|
*
|
|
@@ -496,7 +504,6 @@ export type BridgeOptions = {
|
|
|
496
504
|
export type FileRequest = {
|
|
497
505
|
/** Its `accept` list, lowercased and without invalid entries: MIME types and extensions (`.pdf`). */
|
|
498
506
|
accept: string[];
|
|
499
|
-
/** Its `multiple` attribute. */
|
|
500
507
|
multiple: boolean;
|
|
501
508
|
/** Its `capture` attribute: the page wants the camera. */
|
|
502
509
|
capture: boolean;
|
|
@@ -535,7 +542,8 @@ export type Download = {
|
|
|
535
542
|
uri: string;
|
|
536
543
|
/**
|
|
537
544
|
* A plain file name without a path. The page chose it, like the content and `mimeType`, so don't open the file as
|
|
538
|
-
* trusted.
|
|
545
|
+
* trusted. On Android a `data:` or `blob:` link's name is guessed instead: WebView doesn't pass its `download`
|
|
546
|
+
* attribute.
|
|
539
547
|
*/
|
|
540
548
|
filename: string;
|
|
541
549
|
mimeType: string;
|
|
@@ -555,7 +563,6 @@ export type Download = {
|
|
|
555
563
|
*/
|
|
556
564
|
export type DownloadFailure =
|
|
557
565
|
| {
|
|
558
|
-
/** Tells it from a {@link Download}. */
|
|
559
566
|
ok: false;
|
|
560
567
|
kind: 'network' | 'data';
|
|
561
568
|
/** Empty on iOS when the download failed before its response came. */
|
|
@@ -721,13 +728,11 @@ export type AndroidSettings = {
|
|
|
721
728
|
/**
|
|
722
729
|
* An event a native hook sent with `emit` or `ask`.
|
|
723
730
|
* @typeParam N - The event's name, to type one hook's events.
|
|
724
|
-
* @typeParam P - Its payload.
|
|
725
731
|
* @group Native hooks
|
|
726
732
|
*/
|
|
727
733
|
export type HookEvent<N extends string = string, P = Record<string, unknown>> = {
|
|
728
734
|
/** The name the hook sent it with, such as `pageLoaded`. */
|
|
729
735
|
name: N;
|
|
730
|
-
/** What the hook sent with it. */
|
|
731
736
|
payload: P;
|
|
732
737
|
};
|
|
733
738
|
|
|
@@ -875,7 +880,9 @@ export interface WebViewProps extends Omit<ViewProps, 'children'> {
|
|
|
875
880
|
* it, those keys apply; unset, they are the platform's own user agent.
|
|
876
881
|
*
|
|
877
882
|
* To append to the default one instead, set `ios.configuration.applicationNameForUserAgent` and, on Android,
|
|
878
|
-
* `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.
|
|
879
886
|
*
|
|
880
887
|
* A change applies from the next navigation.
|
|
881
888
|
*/
|
|
@@ -898,8 +905,8 @@ export interface WebViewProps extends Omit<ViewProps, 'children'> {
|
|
|
898
905
|
*
|
|
899
906
|
* These skip the rules:
|
|
900
907
|
*
|
|
901
|
-
* - the `source` load, reloads and back/forward; a redirect of the `source` load
|
|
902
|
-
* 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;
|
|
903
910
|
* - a form POST, on either platform, an iframe's to the main frame (`target=_top`) included: it loads in place; one
|
|
904
911
|
* to a new window loads in place on iOS and isn't shown on Android (the request may still reach the server);
|
|
905
912
|
* - `about:`, `data:` and `javascript:`, which load in place, except as a new window
|
|
@@ -976,7 +983,7 @@ export interface WebViewProps extends Omit<ViewProps, 'children'> {
|
|
|
976
983
|
* Pull down at the top of the page to reload: `UIRefreshControl` on iOS, `SwipeRefreshLayout` on Android, where a
|
|
977
984
|
* pull inside a scrolled inner scroller (`overflow: auto` or `scroll`) scrolls it instead.
|
|
978
985
|
*
|
|
979
|
-
* It reloads as {@link WebViewRef.reload | reload()} does,
|
|
986
|
+
* It reloads as {@link WebViewRef.reload | reload()} does, but leaves the
|
|
980
987
|
* {@link ProcessGoneEvent.recovered | crash recovery} limit in place. A change applies at once.
|
|
981
988
|
* @default `false`
|
|
982
989
|
*/
|
|
@@ -984,7 +991,8 @@ export interface WebViewProps extends Omit<ViewProps, 'children'> {
|
|
|
984
991
|
/**
|
|
985
992
|
* Syncs cookies between `HTTPCookieStorage`, which holds the cookies of native requests, and the WebView:
|
|
986
993
|
*
|
|
987
|
-
* - `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;
|
|
988
996
|
* - the WebView into `HTTPCookieStorage` on every cookie change, deletions included, as it happens.
|
|
989
997
|
*
|
|
990
998
|
* Android needs nothing: `CookieManager` is shared app-wide, and flushed when the app goes to the background. A
|
|
@@ -1065,7 +1073,8 @@ export interface WebViewProps extends Omit<ViewProps, 'children'> {
|
|
|
1065
1073
|
/**
|
|
1066
1074
|
* Every navigation the rules, or their defaults, decided.
|
|
1067
1075
|
*
|
|
1068
|
-
* 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.
|
|
1069
1078
|
* @see [Navigation rules example](https://rasmuskard.github.io/react-native-minimal-webview/guides/examples/#navigation-rules)
|
|
1070
1079
|
*/
|
|
1071
1080
|
onNavigation?: (event: NavigationEvent) => void;
|
|
@@ -1092,12 +1101,7 @@ export interface WebViewProps extends Omit<ViewProps, 'children'> {
|
|
|
1092
1101
|
* Android's WebViews share one renderer, so each of them reports its death.
|
|
1093
1102
|
*/
|
|
1094
1103
|
onProcessGone?: (event: ProcessGoneEvent) => void;
|
|
1095
|
-
/**
|
|
1096
|
-
* `loading` went true.
|
|
1097
|
-
*
|
|
1098
|
-
* On Android with an Android System WebView older than 146, that is when the page commits (its response arrives),
|
|
1099
|
-
* not when the load starts, and a load that never commits fires neither this nor `onLoadEnd`.
|
|
1100
|
-
*/
|
|
1104
|
+
/** {@link NavigationState.loading | loading} went true. */
|
|
1101
1105
|
onLoadStart?: (state: NavigationState) => void;
|
|
1102
1106
|
/** `loading` went false: `state.outcome` says how the load ended. */
|
|
1103
1107
|
onLoadEnd?: (state: NavigationState) => void;
|
|
@@ -1117,9 +1121,10 @@ export interface WebViewProps extends Omit<ViewProps, 'children'> {
|
|
|
1117
1121
|
* return a promise:
|
|
1118
1122
|
*
|
|
1119
1123
|
* - After an unmount: the navigation methods do nothing and the four promise methods reject with `unavailable`.
|
|
1120
|
-
* - Pending when the WebView unmounts: the four reject with `navigated
|
|
1121
|
-
* - Just mounted: the four wait up to about a second for the view (on Android, a call from the parent's
|
|
1122
|
-
* 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.
|
|
1123
1128
|
* @sortStrategy source-order
|
|
1124
1129
|
* @group WebView
|
|
1125
1130
|
*/
|
|
@@ -1133,6 +1138,22 @@ export type WebViewRef = {
|
|
|
1133
1138
|
goBack(): void;
|
|
1134
1139
|
/** Goes forward one page; does nothing unless `canGoForward`. */
|
|
1135
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;
|
|
1136
1157
|
/**
|
|
1137
1158
|
* Reloads the page; after a failed load, retries it (the `source` again, with its headers, when that failed), and
|
|
1138
1159
|
* loads the `source` when nothing is loaded.
|
|
@@ -1140,7 +1161,7 @@ export type WebViewRef = {
|
|
|
1140
1161
|
* Sends a POST `source` again, and lifts the limit on {@link ProcessGoneEvent.recovered | crash recovery}.
|
|
1141
1162
|
*/
|
|
1142
1163
|
reload(): void;
|
|
1143
|
-
/** Stops the load
|
|
1164
|
+
/** Stops the load; its {@link NavigationState.outcome | outcome} says how the load ended. */
|
|
1144
1165
|
stopLoading(): void;
|
|
1145
1166
|
/**
|
|
1146
1167
|
* Runs an expression (not statements) in the page's main frame and awaits it.
|
|
@@ -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
|
-
]);
|