react-native-minimal-webview 0.0.0-stage → 1.0.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.
Files changed (118) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +130 -2
  3. package/android/build.gradle +26 -0
  4. package/android/consumer-rules.pro +4 -0
  5. package/android/src/main/AndroidManifest.xml +2 -0
  6. package/android/src/main/java/expo/modules/minimalwebview/Asks.kt +44 -0
  7. package/android/src/main/java/expo/modules/minimalwebview/DocumentEnd.kt +31 -0
  8. package/android/src/main/java/expo/modules/minimalwebview/Hooks.kt +496 -0
  9. package/android/src/main/java/expo/modules/minimalwebview/MinimalWebView.kt +510 -0
  10. package/android/src/main/java/expo/modules/minimalwebview/MinimalWebViewClients.kt +359 -0
  11. package/android/src/main/java/expo/modules/minimalwebview/MinimalWebViewModule.kt +245 -0
  12. package/android/src/main/java/expo/modules/minimalwebview/MinimalWebViewNavigation.kt +199 -0
  13. package/android/src/main/java/expo/modules/minimalwebview/MinimalWebViewScripts.kt +191 -0
  14. package/android/src/main/java/expo/modules/minimalwebview/NavigationRules.kt +113 -0
  15. package/android/src/main/java/expo/modules/minimalwebview/PlatformSettings.kt +306 -0
  16. package/android/src/main/java/expo/modules/minimalwebview/PullToRefresh.kt +76 -0
  17. package/android/src/main/java/expo/modules/minimalwebview/requests/Downloads.kt +258 -0
  18. package/android/src/main/java/expo/modules/minimalwebview/requests/FileUpload.kt +44 -0
  19. package/android/src/main/java/expo/modules/minimalwebview/requests/FullscreenVideo.kt +87 -0
  20. package/android/src/main/java/expo/modules/minimalwebview/requests/Permissions.kt +77 -0
  21. package/build/WebView.d.ts +99 -0
  22. package/build/WebView.d.ts.map +1 -0
  23. package/build/WebView.js +448 -0
  24. package/build/WebView.js.map +1 -0
  25. package/build/bridge/createBridge.d.ts +32 -0
  26. package/build/bridge/createBridge.d.ts.map +1 -0
  27. package/build/bridge/createBridge.js +135 -0
  28. package/build/bridge/createBridge.js.map +1 -0
  29. package/build/bridge/endpoint.d.ts +35 -0
  30. package/build/bridge/endpoint.d.ts.map +1 -0
  31. package/build/bridge/endpoint.js +100 -0
  32. package/build/bridge/endpoint.js.map +1 -0
  33. package/build/bridge/origins.d.ts +25 -0
  34. package/build/bridge/origins.d.ts.map +1 -0
  35. package/build/bridge/origins.js +60 -0
  36. package/build/bridge/origins.js.map +1 -0
  37. package/build/bridge/pageClient.generated.d.ts +3 -0
  38. package/build/bridge/pageClient.generated.d.ts.map +1 -0
  39. package/build/bridge/pageClient.generated.js +4 -0
  40. package/build/bridge/pageClient.generated.js.map +1 -0
  41. package/build/bridge/protocol.d.ts +50 -0
  42. package/build/bridge/protocol.d.ts.map +1 -0
  43. package/build/bridge/protocol.js +52 -0
  44. package/build/bridge/protocol.js.map +1 -0
  45. package/build/defaultNavigationRules.d.ts +16 -0
  46. package/build/defaultNavigationRules.d.ts.map +1 -0
  47. package/build/defaultNavigationRules.js +23 -0
  48. package/build/defaultNavigationRules.js.map +1 -0
  49. package/build/index.d.ts +31 -0
  50. package/build/index.d.ts.map +1 -0
  51. package/build/index.js +30 -0
  52. package/build/index.js.map +1 -0
  53. package/build/platform.generated.d.ts +702 -0
  54. package/build/platform.generated.d.ts.map +1 -0
  55. package/build/platform.generated.js +199 -0
  56. package/build/platform.generated.js.map +1 -0
  57. package/build/reactNativeWebViewDefaults.d.ts +21 -0
  58. package/build/reactNativeWebViewDefaults.d.ts.map +1 -0
  59. package/build/reactNativeWebViewDefaults.js +12 -0
  60. package/build/reactNativeWebViewDefaults.js.map +1 -0
  61. package/build/reactNativeWebViewMessages.d.ts +22 -0
  62. package/build/reactNativeWebViewMessages.d.ts.map +1 -0
  63. package/build/reactNativeWebViewMessages.js +30 -0
  64. package/build/reactNativeWebViewMessages.js.map +1 -0
  65. package/build/refStore.d.ts +31 -0
  66. package/build/refStore.d.ts.map +1 -0
  67. package/build/refStore.js +113 -0
  68. package/build/refStore.js.map +1 -0
  69. package/build/types.d.ts +1127 -0
  70. package/build/types.d.ts.map +1 -0
  71. package/build/types.defaults.d.ts +8 -0
  72. package/build/types.defaults.d.ts.map +1 -0
  73. package/build/types.defaults.js +17 -0
  74. package/build/types.defaults.js.map +1 -0
  75. package/build/types.js +2 -0
  76. package/build/types.js.map +1 -0
  77. package/expo-module.config.json +9 -0
  78. package/ios/Asks.swift +45 -0
  79. package/ios/DelegateProxy.swift +162 -0
  80. package/ios/DocumentEnd.swift +23 -0
  81. package/ios/DownloadName.swift +12 -0
  82. package/ios/Downloads.swift +51 -0
  83. package/ios/Hooks.swift +308 -0
  84. package/ios/Loads.swift +44 -0
  85. package/ios/MRWExceptions.h +9 -0
  86. package/ios/MRWExceptions.m +10 -0
  87. package/ios/MRWInvoke.h +23 -0
  88. package/ios/MRWInvoke.m +187 -0
  89. package/ios/MinimalWebView+Dialogs.swift +99 -0
  90. package/ios/MinimalWebView+Navigation.swift +244 -0
  91. package/ios/MinimalWebView+Scripts.swift +92 -0
  92. package/ios/MinimalWebView.docc/MinimalWebView.md +13 -0
  93. package/ios/MinimalWebView.podspec +32 -0
  94. package/ios/MinimalWebView.swift +512 -0
  95. package/ios/MinimalWebViewModule.swift +110 -0
  96. package/ios/NavigationRules.swift +123 -0
  97. package/ios/OriginRules.swift +35 -0
  98. package/ios/PlatformCompletions.generated.swift +39 -0
  99. package/ios/PlatformSettings.swift +247 -0
  100. package/ios/ReadAccess.swift +19 -0
  101. package/ios/Recovery.swift +25 -0
  102. package/ios/SharedCookies.swift +59 -0
  103. package/package.json +94 -4
  104. package/src/WebView.tsx +623 -0
  105. package/src/bridge/createBridge.ts +176 -0
  106. package/src/bridge/endpoint.ts +119 -0
  107. package/src/bridge/origins.ts +62 -0
  108. package/src/bridge/pageClient.generated.ts +5 -0
  109. package/src/bridge/pageClient.ts +68 -0
  110. package/src/bridge/protocol.ts +78 -0
  111. package/src/defaultNavigationRules.ts +25 -0
  112. package/src/index.ts +37 -0
  113. package/src/platform.generated.ts +694 -0
  114. package/src/reactNativeWebViewDefaults.ts +13 -0
  115. package/src/reactNativeWebViewMessages.ts +32 -0
  116. package/src/refStore.ts +164 -0
  117. package/src/types.defaults.ts +24 -0
  118. package/src/types.ts +1194 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026 Rasmus Kard
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,131 @@
1
- # Temporary Holding Version
1
+ # react-native-minimal-webview
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A React Native WebView that hands you the iOS and Android WebView APIs, instead of wrapping each one in a prop.
4
+
5
+ It runs on iOS and Android as an Expo module.
6
+
7
+ [Install](#install) ·
8
+ [API reference](https://rasmuskard.github.io/react-native-minimal-webview/typescript/react-native-minimal-webview/) ·
9
+ [Examples](guides/examples.md) ·
10
+ [Native hooks](guides/native-hooks.md) ·
11
+ [Migrating from react-native-webview](guides/migrating-from-react-native-webview.md) ·
12
+ [Extensions](https://rasmuskard.github.io/react-native-minimal-webview/typescript/extensions/) ·
13
+ [MIT license](https://github.com/RasmusKard/react-native-minimal-webview/blob/main/LICENSE)
14
+
15
+ ## Why it exists
16
+
17
+ react-native-webview wraps each platform API in a prop of its own. When one isn't wrapped, you wait for an upstream
18
+ PR, or patch or fork the package, even if the change is one platform call.
19
+
20
+ This package passes the platform APIs through instead:
21
+
22
+ - `ios` and `android` props: any setting, by its platform name.
23
+ - The ref's `get` and `call`: properties and methods, by name.
24
+ - [Native hooks](guides/native-hooks.md): the `WKWebView` or `WebView` itself, in your own Swift or Kotlin
25
+ module.
26
+
27
+ ```tsx
28
+ import { useRef } from 'react';
29
+ import { Button, Platform } from 'react-native';
30
+ import { WebView, type WebViewRef } from 'react-native-minimal-webview';
31
+
32
+ export function Browser() {
33
+ const ref = useRef<WebViewRef>(null);
34
+ const pageDown = () => {
35
+ if (Platform.OS === 'android') ref.current?.call('webView.pageDown', [true]);
36
+ };
37
+ return (
38
+ <>
39
+ <Button title="Page down" onPress={pageDown} />
40
+ <WebView
41
+ ref={ref}
42
+ source={{ uri: 'https://example.com' }}
43
+ style={{ flex: 1 }}
44
+ ios={{ scrollView: { bounces: false } }}
45
+ android={{ settings: { textZoom: 120 } }}
46
+ />
47
+ </>
48
+ );
49
+ }
50
+ ```
51
+
52
+ A setting or method a newer SDK adds works without a release of this package: see
53
+ [`ios`](https://rasmuskard.github.io/react-native-minimal-webview/typescript/react-native-minimal-webview/interfaces/WebViewProps/#ios),
54
+ [`android`](https://rasmuskard.github.io/react-native-minimal-webview/typescript/react-native-minimal-webview/interfaces/WebViewProps/#android) and
55
+ [`call`](https://rasmuskard.github.io/react-native-minimal-webview/typescript/react-native-minimal-webview/type-aliases/WebViewRef/#call).
56
+
57
+ ## What it changes from react-native-webview
58
+
59
+ ![The app sends rules and settings to the native WebView core and gets state and events back; the core answers the page's navigations; the bridge links the app and allowed origins](guides/how-it-works.svg)
60
+
61
+ The core adds only what the platform APIs lack:
62
+
63
+ | | react-native-webview | react-native-minimal-webview |
64
+ | -------------------------- | ---------------------------------------------------- | ------------------------------------------- |
65
+ | Navigation decisions | `onShouldStartLoadWithRequest`, a JS round trip each | `navigationRules`, matched natively |
66
+ | Page messaging | `postMessage` strings, any page | Typed promise bridge, `allowedOrigins` only |
67
+ | Navigation state | `onNavigationStateChange` events you keep in state | `useWebViewState(ref)` |
68
+ | Page camera and microphone | Granted to any page on Android, after asking the OS | Your app answers `onPermissionRequest` |
69
+
70
+ The [migration guide](guides/migrating-from-react-native-webview.md) covers each react-native-webview prop that works differently here.
71
+
72
+ ## When to use something else
73
+
74
+ - Old architecture, Windows or macOS: react-native-webview supports them, this package doesn't. Neither runs on web.
75
+ - Expo Go: the package has native code, so it needs a development build.
76
+
77
+ ## Install
78
+
79
+ ```sh
80
+ npx expo install react-native-minimal-webview
81
+ ```
82
+
83
+ Then rebuild the app (`npx expo run:ios`, `npx expo run:android`).
84
+
85
+ A bare React Native app adds Expo modules first, then installs with its package manager:
86
+
87
+ ```sh
88
+ npx install-expo-modules@latest
89
+ npm install react-native-minimal-webview # or: yarn add, pnpm add
90
+ npx pod-install
91
+ ```
92
+
93
+ ### Requirements
94
+
95
+ | Platform | Minimum |
96
+ | ------------ | ------------------------------------------------------------------------------ |
97
+ | iOS | 17.0: `ios.deploymentTarget: '17.0'`, for example with `expo-build-properties` |
98
+ | Android | API 29: `android.minSdkVersion: 29`, for example with `expo-build-properties` |
99
+ | Expo SDK | 53 (React Native 0.79, React 19) |
100
+ | Architecture | New architecture only |
101
+
102
+ Some features need a newer Android System WebView: [which ones](guides/android-system-webview.md).
103
+
104
+ ## Usage
105
+
106
+ ```tsx
107
+ import { WebView } from 'react-native-minimal-webview';
108
+
109
+ export function Browser() {
110
+ return <WebView source={{ uri: 'https://example.com' }} style={{ flex: 1 }} />;
111
+ }
112
+ ```
113
+
114
+ Then pick what you need:
115
+
116
+ | To | See |
117
+ | --------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
118
+ | Show the URL, progress or a back button | [Navigation state](guides/examples.md#navigation-state) |
119
+ | Keep the WebView on your sites, open the rest externally | [Navigation rules](guides/examples.md#navigation-rules) |
120
+ | Call the page from the app, and the app from the page | [The bridge](guides/examples.md#the-bridge) |
121
+ | Change a WebView setting | [Platform settings](guides/examples.md#platform-settings) |
122
+ | Share cookies with native requests | [Cookies](guides/examples.md#cookies) |
123
+ | Run a script on every page | [Scripts](guides/examples.md#scripts) |
124
+ | Load bundled HTML | [Local files](guides/examples.md#local-files) |
125
+ | Answer file pickers, permissions and downloads | [Page requests](guides/examples.md#page-requests) |
126
+ | Use the native `WKWebView` or `WebView` | [Native hooks](guides/native-hooks.md) |
127
+ | Bring back `basicAuthCredential`, `onScroll` and other react-native-webview props | [@react-native-minimal-webview/extensions](https://rasmuskard.github.io/react-native-minimal-webview/typescript/extensions/) |
128
+
129
+ ## Contributing
130
+
131
+ [CONTRIBUTING.md](https://github.com/RasmusKard/react-native-minimal-webview/blob/main/.github/CONTRIBUTING.md) has the setup, the checks and the on-device suites.
@@ -0,0 +1,26 @@
1
+ plugins {
2
+ id 'com.android.library'
3
+ id 'expo-module-gradle-plugin'
4
+ }
5
+
6
+ group = 'expo.modules.minimalwebview'
7
+ version = '0.1.0' // expo-autolinking requires it
8
+
9
+ android {
10
+ namespace "expo.modules.minimalwebview"
11
+ defaultConfig {
12
+ minSdkVersion 29
13
+ versionName project.version // Expo SDK 53's module plugin requires it
14
+ consumerProguardFiles 'consumer-rules.pro'
15
+ }
16
+ // -PmrwCoverage: JaCoCo for the unit tests (.github/CONTRIBUTING.md); without it, the build is unchanged
17
+ if (providers.gradleProperty('mrwCoverage').present) buildTypes.debug.enableUnitTestCoverage = true
18
+ }
19
+
20
+ dependencies {
21
+ api 'androidx.webkit:webkit:1.17.1' // hooks build on it: WebViewClientCompat clients, WebViewCompat.setProfile
22
+ implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0' // pullToRefresh
23
+ implementation 'androidx.activity:activity:1.8.0' // fullscreenVideo: back press exits fullscreen
24
+ testImplementation 'junit:junit:4.13.2'
25
+ testImplementation 'org.json:json:20250517' // the real org.json; Android's is a stub in JVM tests
26
+ }
@@ -0,0 +1,4 @@
1
+ # The `android` settings prop finds androidx.webkit's compat setters and getters by name (PlatformSettings.kt).
2
+ # R8 would otherwise strip or rename the ones the app's own code never calls.
3
+ -keep class androidx.webkit.WebSettingsCompat { public static *; }
4
+ -keep class androidx.webkit.WebViewCompat { public static *; }
@@ -0,0 +1,2 @@
1
+ <manifest>
2
+ </manifest>
@@ -0,0 +1,44 @@
1
+ package expo.modules.minimalwebview
2
+
3
+
4
+ /**
5
+ * Every `ask` (a page request, a navigation request or a hook's) waits here, by id, until JS answers it through [answer]
6
+ * or native gives up (null, and the core's `askCancelled` to JS): a Document end, a timeout or the platform. [send] puts an
7
+ * event on the view's `onHookEvent`, which reaches the app's extensions' `onEvent`. Main thread only.
8
+ */
9
+ internal class Asks(private val send: (Map<String, Any?>) -> Unit) {
10
+ private val pending = mutableMapOf<Int, (Any?) -> Unit>()
11
+ private var nextId = 0
12
+ /** The view closed: JS is unmounted, and a hook may still hold its context. */
13
+ private var closed = false
14
+
15
+ /** Sends the ask to JS and returns its id, for [cancel]. Once the view closed it answers null at once. */
16
+ fun ask(key: String, name: String, payload: Map<String, Any?>, onAnswer: (Any?) -> Unit): Int {
17
+ if (closed) {
18
+ onAnswer(null)
19
+ return 0 // no ask: cancel(0) finds nothing
20
+ }
21
+ val id = ++nextId
22
+ pending[id] = onAnswer
23
+ send(mapOf("key" to key, "name" to name, "payload" to payload, "askId" to id))
24
+ return id
25
+ }
26
+
27
+ /** JS's answer. One for an ask that was answered or cancelled already is dropped. */
28
+ fun answer(id: Int, value: Any?) {
29
+ pending.remove(id)?.invoke(value)
30
+ }
31
+
32
+ /** Native gives up on an ask: its callback gets null, and JS aborts the handler's signal unless [tell] is false. */
33
+ fun cancel(id: Int, tell: Boolean = true) {
34
+ val onAnswer = pending.remove(id) ?: return
35
+ if (tell) send(mapOf("key" to "core", "name" to "askCancelled", "payload" to mapOf("askId" to id)))
36
+ onAnswer(null)
37
+ }
38
+
39
+ /** Cancels every pending ask. At closing JS isn't told: it aborts its own handlers at unmount. */
40
+ fun documentEnded(reason: DocumentEnd) {
41
+ if (reason == DocumentEnd.CLOSING) closed = true
42
+ pending.keys.toList().forEach { cancel(it, tell = reason != DocumentEnd.CLOSING) }
43
+ }
44
+ }
@@ -0,0 +1,31 @@
1
+ package expo.modules.minimalwebview
2
+
3
+ /**
4
+ * Why a Document ended, as [WebViewContext.onDocumentEnd] and [WebViewContext.onDestroyed] report it.
5
+ *
6
+ * A Document is the main-frame page a WebView shows now: from a navigation's commit, a back-forward-cache restore or a
7
+ * failed load's error page included, to the next commit, a renderer crash or the view closing.
8
+ *
9
+ * The first commit after a WebView is made, at mount or after a crash, opens one and ends nothing.
10
+ *
11
+ * A Document doesn't end at a same-document navigation (`pushState`, `replaceState`, a hash change), a sub-frame
12
+ * navigation, a load that never commits (a stop, a download, a 204), the view leaving the window or the app going to
13
+ * the background.
14
+ */
15
+ enum class DocumentEnd {
16
+ /**
17
+ * A main-frame navigation committed in the same WebView while a Document was open: a load, a form submit, back or
18
+ * forward, a reload, an html source, a `window.open` loaded in place, a back-forward-cache restore or a failed
19
+ * load's error page.
20
+ */
21
+ COMMITTED,
22
+
23
+ /**
24
+ * The renderer died: this WebView goes, its hooks detach (their [WebViewContext.onDestroyed] handlers run), and
25
+ * they attach again to the one that replaces it, with a new context. Its first commit opens the next Document.
26
+ */
27
+ CRASHED,
28
+
29
+ /** The view is closing: this WebView goes for good, and its hooks detach after this. */
30
+ CLOSING
31
+ }