@exodus/react-native-webview 11.26.1-exodus.13 → 11.26.1-exodus.15

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 (176) hide show
  1. package/android/.gradle/7.1/dependencies-accessors/dependencies-accessors.lock +0 -0
  2. package/android/.gradle/7.1/dependencies-accessors/gc.properties +0 -0
  3. package/android/.gradle/7.1/executionHistory/executionHistory.bin +0 -0
  4. package/android/.gradle/7.1/executionHistory/executionHistory.lock +0 -0
  5. package/android/.gradle/7.1/fileChanges/last-build.bin +0 -0
  6. package/android/.gradle/7.1/fileHashes/fileHashes.bin +0 -0
  7. package/android/.gradle/7.1/fileHashes/fileHashes.lock +0 -0
  8. package/android/.gradle/7.1/gc.properties +0 -0
  9. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  10. package/android/.gradle/buildOutputCleanup/cache.properties +2 -0
  11. package/android/.gradle/buildOutputCleanup/outputFiles.bin +0 -0
  12. package/android/.gradle/checksums/checksums.lock +0 -0
  13. package/android/.gradle/checksums/md5-checksums.bin +0 -0
  14. package/android/.gradle/checksums/sha1-checksums.bin +0 -0
  15. package/android/.gradle/vcs-1/gc.properties +0 -0
  16. package/android/.idea/compiler.xml +6 -0
  17. package/android/.idea/gradle.xml +17 -0
  18. package/android/.idea/jarRepositories.xml +30 -0
  19. package/android/.idea/libraries/Gradle__androidx_annotation_annotation_1_1_0.xml +13 -0
  20. package/android/.idea/libraries/Gradle__androidx_appcompat_appcompat_1_0_2_aar.xml +16 -0
  21. package/android/.idea/libraries/Gradle__androidx_arch_core_core_common_2_0_0.xml +11 -0
  22. package/android/.idea/libraries/Gradle__androidx_arch_core_core_runtime_2_0_0_aar.xml +13 -0
  23. package/android/.idea/libraries/Gradle__androidx_asynclayoutinflater_asynclayoutinflater_1_0_0_aar.xml +13 -0
  24. package/android/.idea/libraries/Gradle__androidx_autofill_autofill_1_1_0_aar.xml +16 -0
  25. package/android/.idea/libraries/Gradle__androidx_collection_collection_1_0_0.xml +11 -0
  26. package/android/.idea/libraries/Gradle__androidx_coordinatorlayout_coordinatorlayout_1_0_0_aar.xml +16 -0
  27. package/android/.idea/libraries/Gradle__androidx_core_core_1_1_0_aar.xml +16 -0
  28. package/android/.idea/libraries/Gradle__androidx_cursoradapter_cursoradapter_1_0_0_aar.xml +13 -0
  29. package/android/.idea/libraries/Gradle__androidx_customview_customview_1_0_0_aar.xml +13 -0
  30. package/android/.idea/libraries/Gradle__androidx_documentfile_documentfile_1_0_0_aar.xml +13 -0
  31. package/android/.idea/libraries/Gradle__androidx_drawerlayout_drawerlayout_1_0_0_aar.xml +16 -0
  32. package/android/.idea/libraries/Gradle__androidx_fragment_fragment_1_0_0_aar.xml +16 -0
  33. package/android/.idea/libraries/Gradle__androidx_interpolator_interpolator_1_0_0_aar.xml +13 -0
  34. package/android/.idea/libraries/Gradle__androidx_legacy_legacy_support_core_ui_1_0_0_aar.xml +13 -0
  35. package/android/.idea/libraries/Gradle__androidx_legacy_legacy_support_core_utils_1_0_0_aar.xml +13 -0
  36. package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_common_2_0_0.xml +11 -0
  37. package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_livedata_2_0_0_aar.xml +13 -0
  38. package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_livedata_core_2_0_0_aar.xml +13 -0
  39. package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_runtime_2_0_0_aar.xml +13 -0
  40. package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_viewmodel_2_0_0_aar.xml +13 -0
  41. package/android/.idea/libraries/Gradle__androidx_loader_loader_1_0_0_aar.xml +13 -0
  42. package/android/.idea/libraries/Gradle__androidx_localbroadcastmanager_localbroadcastmanager_1_0_0_aar.xml +13 -0
  43. package/android/.idea/libraries/Gradle__androidx_print_print_1_0_0_aar.xml +16 -0
  44. package/android/.idea/libraries/Gradle__androidx_slidingpanelayout_slidingpanelayout_1_0_0_aar.xml +13 -0
  45. package/android/.idea/libraries/Gradle__androidx_swiperefreshlayout_swiperefreshlayout_1_0_0_aar.xml +16 -0
  46. package/android/.idea/libraries/Gradle__androidx_vectordrawable_vectordrawable_1_0_1_aar.xml +13 -0
  47. package/android/.idea/libraries/Gradle__androidx_vectordrawable_vectordrawable_animated_1_0_0_aar.xml +13 -0
  48. package/android/.idea/libraries/Gradle__androidx_versionedparcelable_versionedparcelable_1_1_0_aar.xml +13 -0
  49. package/android/.idea/libraries/Gradle__androidx_viewpager_viewpager_1_0_0_aar.xml +13 -0
  50. package/android/.idea/libraries/Gradle__androidx_webkit_webkit_1_4_0_aar.xml +16 -0
  51. package/android/.idea/libraries/Gradle__com_facebook_fbjni_fbjni_java_only_0_2_2.xml +13 -0
  52. package/android/.idea/libraries/Gradle__com_facebook_fresco_drawee_2_5_0_aar.xml +15 -0
  53. package/android/.idea/libraries/Gradle__com_facebook_fresco_fbcore_2_5_0_aar.xml +18 -0
  54. package/android/.idea/libraries/Gradle__com_facebook_fresco_fresco_2_5_0_aar.xml +18 -0
  55. package/android/.idea/libraries/Gradle__com_facebook_fresco_imagepipeline_2_5_0_aar.xml +18 -0
  56. package/android/.idea/libraries/Gradle__com_facebook_fresco_imagepipeline_base_2_5_0_aar.xml +18 -0
  57. package/android/.idea/libraries/Gradle__com_facebook_fresco_imagepipeline_native_2_5_0_aar.xml +15 -0
  58. package/android/.idea/libraries/Gradle__com_facebook_fresco_imagepipeline_okhttp3_2_5_0_aar.xml +15 -0
  59. package/android/.idea/libraries/Gradle__com_facebook_fresco_memory_type_ashmem_2_5_0_aar.xml +15 -0
  60. package/android/.idea/libraries/Gradle__com_facebook_fresco_memory_type_java_2_5_0_aar.xml +15 -0
  61. package/android/.idea/libraries/Gradle__com_facebook_fresco_memory_type_native_2_5_0_aar.xml +15 -0
  62. package/android/.idea/libraries/Gradle__com_facebook_fresco_nativeimagefilters_2_5_0_aar.xml +15 -0
  63. package/android/.idea/libraries/Gradle__com_facebook_fresco_nativeimagetranscoder_2_5_0_aar.xml +15 -0
  64. package/android/.idea/libraries/Gradle__com_facebook_fresco_ui_common_2_5_0_aar.xml +15 -0
  65. package/android/.idea/libraries/Gradle__com_facebook_infer_annotation_infer_annotation_0_18_0.xml +13 -0
  66. package/android/.idea/libraries/Gradle__com_facebook_react_react_native_0_68_5_aar.xml +16 -0
  67. package/android/.idea/libraries/Gradle__com_facebook_soloader_annotation_0_10_3.xml +13 -0
  68. package/android/.idea/libraries/Gradle__com_facebook_soloader_nativeloader_0_10_3.xml +13 -0
  69. package/android/.idea/libraries/Gradle__com_facebook_soloader_soloader_0_10_3_aar.xml +15 -0
  70. package/android/.idea/libraries/Gradle__com_facebook_yoga_proguard_annotations_1_19_0.xml +13 -0
  71. package/android/.idea/libraries/Gradle__com_google_code_findbugs_jsr305_3_0_2.xml +13 -0
  72. package/android/.idea/libraries/Gradle__com_squareup_okhttp3_okhttp_4_9_2.xml +13 -0
  73. package/android/.idea/libraries/Gradle__com_squareup_okhttp3_okhttp_urlconnection_4_9_2.xml +13 -0
  74. package/android/.idea/libraries/Gradle__com_squareup_okio_okio_2_9_0.xml +13 -0
  75. package/android/.idea/libraries/Gradle__javax_inject_javax_inject_1.xml +13 -0
  76. package/android/.idea/libraries/Gradle__org_jetbrains_annotations_13_0.xml +13 -0
  77. package/android/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_annotations_jvm_1_3_72.xml +13 -0
  78. package/android/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_1_6_0.xml +13 -0
  79. package/android/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_common_1_6_0.xml +13 -0
  80. package/android/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_jdk7_1_4_10.xml +13 -0
  81. package/android/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_jdk8_1_4_10.xml +13 -0
  82. package/android/.idea/misc.xml +9 -0
  83. package/android/.idea/modules/android.androidTest.iml +129 -0
  84. package/android/.idea/modules/android.iml +40 -0
  85. package/android/.idea/modules/android.main.iml +124 -0
  86. package/android/.idea/modules/android.unitTest.iml +124 -0
  87. package/android/.idea/modules.xml +11 -0
  88. package/android/.idea/vcs.xml +6 -0
  89. package/{example/android → android}/gradle/wrapper/gradle-wrapper.jar +0 -0
  90. package/{example/android → android}/gradle/wrapper/gradle-wrapper.properties +1 -1
  91. package/android/gradlew +185 -0
  92. package/android/local.properties +8 -0
  93. package/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java +16 -0
  94. package/android/src/main/java/com/reactnativecommunity/webview/events/TopNewWindowEvent.kt +25 -0
  95. package/lib/WebView.android.js +4 -3
  96. package/lib/WebViewShared.d.ts +4 -2
  97. package/lib/WebViewShared.js +7 -1
  98. package/lib/WebViewTypes.d.ts +13 -0
  99. package/package.json +1 -1
  100. package/.all-contributorsrc +0 -185
  101. package/.circleci/config.yml +0 -66
  102. package/.eslintignore +0 -2
  103. package/.eslintrc.js +0 -94
  104. package/.flowconfig +0 -88
  105. package/.flowconfig.android +0 -88
  106. package/.gitattributes +0 -12
  107. package/.github/CODEOWNERS +0 -1
  108. package/.github/ISSUE_TEMPLATE/bug-report.md +0 -42
  109. package/.github/ISSUE_TEMPLATE/feature_request.md +0 -30
  110. package/.github/workflows/android-ci.yml +0 -35
  111. package/.github/workflows/detox.yml +0 -20
  112. package/.github/workflows/ios-ci.yml +0 -31
  113. package/.github/workflows/scripts/install-vs-features.ps1 +0 -108
  114. package/.github/workflows/stale.yml +0 -17
  115. package/.gitignore +0 -62
  116. package/.prettierrc.js +0 -10
  117. package/.releaserc +0 -15
  118. package/.vscode/settings.json +0 -9
  119. package/babel.config.js +0 -11
  120. package/bin/setup +0 -26
  121. package/docs/Contributing.md +0 -102
  122. package/docs/Custom-Android.md +0 -222
  123. package/docs/Custom-iOS.md +0 -236
  124. package/docs/Debugging.md +0 -101
  125. package/docs/Getting-Started.md +0 -142
  126. package/docs/Guide.md +0 -613
  127. package/docs/Reference.md +0 -1639
  128. package/example/.gitignore +0 -14
  129. package/example/.watchmanconfig +0 -1
  130. package/example/App.tsx +0 -262
  131. package/example/android/build.gradle +0 -15
  132. package/example/android/gradle.properties +0 -34
  133. package/example/android/gradlew +0 -234
  134. package/example/android/settings.gradle +0 -12
  135. package/example/app.json +0 -20
  136. package/example/assets/test.html +0 -9
  137. package/example/babel.config.js +0 -3
  138. package/example/examples/Alerts.tsx +0 -72
  139. package/example/examples/ApplePay.tsx +0 -23
  140. package/example/examples/Background.tsx +0 -54
  141. package/example/examples/Downloads.tsx +0 -57
  142. package/example/examples/Injection.tsx +0 -161
  143. package/example/examples/LocalPageLoad.tsx +0 -16
  144. package/example/examples/Messaging.tsx +0 -63
  145. package/example/examples/NativeWebpage.tsx +0 -22
  146. package/example/examples/Scrolling.tsx +0 -68
  147. package/example/examples/Uploads.tsx +0 -69
  148. package/example/index.js +0 -9
  149. package/example/ios/Podfile +0 -8
  150. package/example/ios/Podfile.lock +0 -445
  151. package/jest-setups/jest.setup.js +0 -8
  152. package/jest.config.js +0 -184
  153. package/lib/WebView.android.d.ts.map +0 -1
  154. package/lib/WebView.d.ts.map +0 -1
  155. package/lib/WebView.ios.d.ts.map +0 -1
  156. package/lib/WebView.styles.d.ts.map +0 -1
  157. package/lib/WebViewNativeComponent.android.d.ts.map +0 -1
  158. package/lib/WebViewNativeComponent.ios.d.ts.map +0 -1
  159. package/lib/WebViewShared.d.ts.map +0 -1
  160. package/lib/WebViewTypes.d.ts.map +0 -1
  161. package/lib/index.d.ts.map +0 -1
  162. package/metro.config.js +0 -57
  163. package/src/WebView.android.tsx +0 -246
  164. package/src/WebView.ios.tsx +0 -221
  165. package/src/WebView.styles.ts +0 -44
  166. package/src/WebView.tsx +0 -18
  167. package/src/WebViewNativeComponent.android.ts +0 -8
  168. package/src/WebViewNativeComponent.ios.ts +0 -8
  169. package/src/WebViewShared.tsx +0 -257
  170. package/src/WebViewTypes.ts +0 -920
  171. package/src/__tests__/WebViewShared-test.js +0 -208
  172. package/src/__tests__/__snapshots__/WebViewShared-test.js.snap +0 -8
  173. package/src/index.ts +0 -4
  174. package/tsconfig.json +0 -24
  175. package/yarn.lock +0 -13397
  176. /package/{example/android → android}/gradlew.bat +0 -0
package/docs/Guide.md DELETED
@@ -1,613 +0,0 @@
1
- # React Native WebView Guide
2
-
3
- This document walks you through the most common use cases for React Native WebView. It doesn't cover [the full API](Reference.md), but after reading it and looking at the sample code snippets you should have a good sense for how the WebView works and common patterns for using the WebView.
4
-
5
- _This guide is currently a work in progress._
6
-
7
- ## Guide Index
8
-
9
- - [Basic Inline HTML](Guide.md#basic-inline-html)
10
- - [Basic URL Source](Guide.md#basic-url-source)
11
- - [Loading local HTML files](Guide.md#loading-local-html-files)
12
- - [Controlling navigation state changes](Guide.md#controlling-navigation-state-changes)
13
- - [Add support for File Upload](Guide.md#add-support-for-file-upload)
14
- - [Multiple files upload](Guide.md#multiple-files-upload)
15
- - [Add support for File Download](Guide.md#add-support-for-file-download)
16
- - [Communicating between JS and Native](Guide.md#communicating-between-js-and-native)
17
- - [Working with custom headers, sessions, and cookies](Guide.md#working-with-custom-headers-sessions-and-cookies)
18
- - [Page navigation gesture and button support](Guide.md#page-navigation-gesture-and-button-support)
19
-
20
- ### Basic inline HTML
21
-
22
- The simplest way to use the WebView is to simply pipe in the HTML you want to display. Note that setting an `html` source requires the [originWhiteList](Reference.md#originWhiteList) property to be set to `['*']`.
23
-
24
- ```js
25
- import React, { Component } from 'react';
26
- import { WebView } from 'react-native-webview';
27
-
28
- class MyInlineWeb extends Component {
29
- render() {
30
- return (
31
- <WebView
32
- originWhitelist={['*']}
33
- source={{ html: '<h1>This is a static HTML source!</h1>' }}
34
- />
35
- );
36
- }
37
- }
38
- ```
39
-
40
- Passing a new static html source will cause the WebView to rerender.
41
-
42
- ### Basic URL Source
43
-
44
- This is the most common use-case for WebView.
45
-
46
- ```js
47
- import React, { Component } from 'react';
48
- import { WebView } from 'react-native-webview';
49
-
50
- class MyWeb extends Component {
51
- render() {
52
- return <WebView source={{ uri: 'https://reactnative.dev/' }} />;
53
- }
54
- }
55
- ```
56
-
57
- ### Loading local HTML files
58
-
59
- Note: This is currently not working as discussed in [#428](https://github.com/react-native-webview/react-native-webview/issues/428) and [#518](https://github.com/react-native-webview/react-native-webview/issues/518). Possible workarounds include bundling all assets with webpack or similar, or running a [local webserver](https://github.com/futurepress/react-native-static-server).
60
-
61
- <details><summary>Show non-working method</summary>
62
-
63
- Sometimes you would have bundled an HTML file along with the app and would like to load the HTML asset into your WebView. To do this on iOS and Windows, you can just import the html file like any other asset as shown below.
64
-
65
- ```js
66
- import React, { Component } from 'react';
67
- import { WebView } from 'react-native-webview';
68
-
69
- const myHtmlFile = require('./my-asset-folder/local-site.html');
70
-
71
- class MyWeb extends Component {
72
- render() {
73
- return <WebView source={myHtmlFile} />;
74
- }
75
- }
76
- ```
77
-
78
- However on Android, you need to place the HTML file inside your android project's asset directory. For example, if `local-site.html` is your HTML file and you'd like to load it into the webview, you should move the file to your project's android asset directory which is `your-project/android/app/src/main/assets/`. Then you can load the html file as shown in the following code block
79
-
80
- ```js
81
- import React, { Component } from 'react';
82
- import { WebView } from 'react-native-webview';
83
-
84
- class MyWeb extends Component {
85
- render() {
86
- return (
87
- <WebView source={{ uri: 'file:///android_asset/local-site.html' }} />
88
- );
89
- }
90
- }
91
- ```
92
-
93
- </details>
94
-
95
- ### Controlling navigation state changes
96
-
97
- Sometimes you want to intercept a user tapping on a link in your webview and do something different than navigating there in the webview. Here's some example code on how you might do that using the `onNavigationStateChange` function.
98
-
99
- ```js
100
- import React, { Component } from 'react';
101
- import { WebView } from 'react-native-webview';
102
-
103
- class MyWeb extends Component {
104
- webview = null;
105
-
106
- render() {
107
- return (
108
- <WebView
109
- ref={(ref) => (this.webview = ref)}
110
- source={{ uri: 'https://reactnative.dev/' }}
111
- onNavigationStateChange={this.handleWebViewNavigationStateChange}
112
- />
113
- );
114
- }
115
-
116
- handleWebViewNavigationStateChange = (newNavState) => {
117
- // newNavState looks something like this:
118
- // {
119
- // url?: string;
120
- // title?: string;
121
- // loading?: boolean;
122
- // canGoBack?: boolean;
123
- // canGoForward?: boolean;
124
- // }
125
- const { url } = newNavState;
126
- if (!url) return;
127
-
128
- // handle certain doctypes
129
- if (url.includes('.pdf')) {
130
- this.webview.stopLoading();
131
- // open a modal with the PDF viewer
132
- }
133
-
134
- // one way to handle a successful form submit is via query strings
135
- if (url.includes('?message=success')) {
136
- this.webview.stopLoading();
137
- // maybe close this view?
138
- }
139
-
140
- // one way to handle errors is via query string
141
- if (url.includes('?errors=true')) {
142
- this.webview.stopLoading();
143
- }
144
-
145
- // redirect somewhere else
146
- if (url.includes('google.com')) {
147
- const newURL = 'https://reactnative.dev/';
148
- const redirectTo = 'window.location = "' + newURL + '"';
149
- this.webview.injectJavaScript(redirectTo);
150
- }
151
- };
152
- }
153
- ```
154
-
155
- ### Add support for File Upload
156
-
157
- ##### iOS
158
-
159
- For iOS, all you need to do is specify the permissions in your `ios/[project]/Info.plist` file:
160
-
161
- Photo capture:
162
-
163
- ```
164
- <key>NSCameraUsageDescription</key>
165
- <string>Take pictures for certain activities</string>
166
- ```
167
-
168
- Gallery selection:
169
-
170
- ```
171
- <key>NSPhotoLibraryUsageDescription</key>
172
- <string>Select pictures for certain activities</string>
173
- ```
174
-
175
- Video recording:
176
-
177
- ```
178
- <key>NSMicrophoneUsageDescription</key>
179
- <string>Need microphone access for recording videos</string>
180
- ```
181
-
182
- ##### Android
183
-
184
- Add permission in AndroidManifest.xml:
185
-
186
- ```xml
187
- <manifest ...>
188
- ......
189
-
190
- <!-- this is required only for Android 4.1-5.1 (api 16-22) -->
191
- <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
192
-
193
- ......
194
- </manifest>
195
- ```
196
-
197
- ###### Camera option availability in uploading for Android
198
-
199
- If the file input indicates that images or video is desired with [`accept`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#accept), then the WebView will attempt to provide options to the user to use their camera to take a picture or video.
200
-
201
- Normally, apps that do not have permission to use the camera can prompt the user to use an external app so that the requesting app has no need for permission. However, Android has made a special exception for this around the camera to reduce confusion for users. If an app _can_ request the camera permission because it has been declared, and the user has not granted the permission, it may not fire an intent that would use the camera (`MediaStore.ACTION_IMAGE_CAPTURE` or `MediaStore.ACTION_VIDEO_CAPTURE`). In this scenario, it is up to the developer to request camera permission before a file upload directly using the camera is necessary.
202
-
203
- ##### Check for File Upload support, with `static isFileUploadSupported()`
204
-
205
- File Upload using `<input type="file" />` is not supported for Android 4.4 KitKat (see [details](https://github.com/delight-im/Android-AdvancedWebView/issues/4#issuecomment-70372146)):
206
-
207
- ```
208
- import { WebView } from "react-native-webview";
209
-
210
- WebView.isFileUploadSupported().then(res => {
211
- if (res === true) {
212
- // file upload is supported
213
- } else {
214
- // not file upload support
215
- }
216
- });
217
-
218
- ```
219
-
220
- ##### MacOS
221
-
222
- Add read access for `User Selected File` in `Signing & Capabilities` tab under `App Sandbox`:
223
-
224
- <img width="856" alt="settings screenshot" src="https://user-images.githubusercontent.com/36531255/200541359-dde130d0-169e-4b58-8b2f-205442d76fdd.png">
225
-
226
- Note: Attempting to open a file input without this permission will crash the webview.
227
-
228
- ### Multiple Files Upload
229
-
230
- You can control **single** or **multiple** file selection by specifing the [`multiple`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#multiple) attribute on your `input` element:
231
-
232
- ```
233
- // multiple file selection
234
- <input type="file" multiple />
235
-
236
- // single file selection
237
- <input type="file" />
238
- ```
239
-
240
- ### Add support for File Download
241
-
242
- ##### iOS
243
-
244
- On iOS, you are going to have to supply your own code to download files. You can supply an `onFileDownload` callback
245
- to the WebView component as a prop. If RNCWebView determines that a file download needs to take place, the URL where you can download the file
246
- will be given to `onFileDownload`. From that callback you can then download that file however you would like to do so.
247
-
248
- NOTE: iOS 13+ is needed for the best possible download experience. On iOS 13 Apple added an API for accessing HTTP response headers, which
249
- is used to determine if an HTTP response should be a download. On iOS 12 or older, only MIME types that cannot be rendered by the webview will
250
- trigger calls to `onFileDownload`.
251
-
252
- Example:
253
-
254
- ```javascript
255
- onFileDownload = ({ nativeEvent }) => {
256
- const { downloadUrl } = nativeEvent;
257
- // --> Your download code goes here <--
258
- };
259
- ```
260
-
261
- To be able to save images to the gallery you need to specify this permission in your `ios/[project]/Info.plist` file:
262
-
263
- ```
264
- <key>NSPhotoLibraryAddUsageDescription</key>
265
- <string>Save pictures for certain activities.</string>
266
- ```
267
-
268
- ##### Android
269
-
270
- On Android, integration with the DownloadManager is built-in.
271
- Add this permission in AndroidManifest.xml (only required if your app supports Android versions lower than 10):
272
-
273
- ```xml
274
- <manifest ...>
275
- ......
276
-
277
- <!-- this is required to save files on Android versions lower than 10 -->
278
- <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
279
-
280
- ......
281
- </manifest>
282
- ```
283
-
284
- ### Communicating between JS and Native
285
-
286
- You will often find yourself wanting to send messages to the web pages loaded by your webviews and also receiving messages back from those web pages.
287
-
288
- To accomplish this, React Native WebView exposes three different options:
289
-
290
- 1. React Native -> Web: The `injectedJavaScript` prop
291
- 2. React Native -> Web: The `injectJavaScript` method
292
- 3. Web -> React Native: The `postMessage` method and `onMessage` prop
293
-
294
- #### The `injectedJavaScript` prop
295
-
296
- This is a script that runs immediately after the web page loads for the first time. It only runs once, even if the page is reloaded or navigated away.
297
-
298
- ```jsx
299
- import React, { Component } from 'react';
300
- import { View } from 'react-native';
301
- import { WebView } from 'react-native-webview';
302
-
303
- export default class App extends Component {
304
- render() {
305
- const runFirst = `
306
- document.body.style.backgroundColor = 'red';
307
- setTimeout(function() { window.alert('hi') }, 2000);
308
- true; // note: this is required, or you'll sometimes get silent failures
309
- `;
310
- return (
311
- <View style={{ flex: 1 }}>
312
- <WebView
313
- source={{
314
- uri: 'https://github.com/react-native-webview/react-native-webview',
315
- }}
316
- onMessage={(event) => {}}
317
- injectedJavaScript={runFirst}
318
- />
319
- </View>
320
- );
321
- }
322
- }
323
- ```
324
-
325
- This runs the JavaScript in the `runFirst` string once the page is loaded. In this case, you can see that both the body style was changed to red and the alert showed up after 2 seconds. An `onMessage` event is required as well to inject the JavaScript code into the WebView.
326
-
327
- By setting `injectedJavaScriptForMainFrameOnly: false`, the JavaScript injection will occur on all frames (not just the main frame) if supported for the given platform. For example, if a page contains an iframe, the javascript will be injected into that iframe as well with this set to `false`. (Note this is not supported on Android.) There is also `injectedJavaScriptBeforeContentLoadedForMainFrameOnly` for injecting prior to content loading. Read more about this in the [Reference](./Reference.md#injectedjavascriptformainframeonly).
328
-
329
- <img alt="screenshot of Github repo" width="200" src="https://user-images.githubusercontent.com/1479215/53609254-e5dc9c00-3b7a-11e9-9118-bc4e520ce6ca.png" />
330
-
331
- _Under the hood_
332
-
333
- > On iOS, ~~`injectedJavaScript` runs a method on WebView called `evaluateJavaScript:completionHandler:`~~ – this is no longer true as of version `8.2.0`. Instead, we use a `WKUserScript` with injection time `WKUserScriptInjectionTimeAtDocumentEnd`. As a consequence, `injectedJavaScript` no longer returns an evaluation value nor logs a warning to the console. In the unlikely event that your app depended upon this behaviour, please see migration steps [here](https://github.com/react-native-webview/react-native-webview/pull/1119#issuecomment-574919464) to retain equivalent behaviour.
334
- > On Android, `injectedJavaScript` runs a method on the Android WebView called `evaluateJavascriptWithFallback`
335
- > On Windows, `injectedJavaScript` runs a method on the WinRT/C++ WebView called `InvokeScriptAsync`
336
-
337
- #### The `injectedJavaScriptBeforeContentLoaded` prop
338
-
339
- This is a script that runs **before** the web page loads for the first time. It only runs once, even if the page is reloaded or navigated away. This is useful if you want to inject anything into the window, localstorage, or document prior to the web code executing.
340
-
341
- ```jsx
342
- import React, { Component } from 'react';
343
- import { View } from 'react-native';
344
- import { WebView } from 'react-native-webview';
345
-
346
- export default class App extends Component {
347
- render() {
348
- const runFirst = `
349
- window.isNativeApp = true;
350
- true; // note: this is required, or you'll sometimes get silent failures
351
- `;
352
- return (
353
- <View style={{ flex: 1 }}>
354
- <WebView
355
- source={{
356
- uri: 'https://github.com/react-native-webview/react-native-webview',
357
- }}
358
- injectedJavaScriptBeforeContentLoaded={runFirst}
359
- />
360
- </View>
361
- );
362
- }
363
- }
364
- ```
365
-
366
- This runs the JavaScript in the `runFirst` string before the page is loaded. In this case, the value of `window.isNativeApp` will be set to true before the web code executes.
367
-
368
- > **Warning**
369
- > On Android, this may work, but it is not 100% reliable (see [#1609](https://github.com/react-native-webview/react-native-webview/issues/1609) and [#1099](https://github.com/react-native-webview/react-native-webview/pull/1099)).
370
-
371
- By setting `injectedJavaScriptBeforeContentLoadedForMainFrameOnly: false`, the JavaScript injection will occur on all frames (not just the top frame) if supported for the given platform. However, although support for `injectedJavaScriptBeforeContentLoadedForMainFrameOnly: false` has been implemented for iOS and macOS, [it is not clear](https://github.com/react-native-webview/react-native-webview/pull/1119#issuecomment-600275750) that it is actually possible to inject JS into iframes at this point in the page lifecycle, and so relying on the expected behaviour of this prop when set to `false` is not recommended.
372
-
373
- > On iOS, ~~`injectedJavaScriptBeforeContentLoaded` runs a method on WebView called `evaluateJavaScript:completionHandler:`~~ – this is no longer true as of version `8.2.0`. Instead, we use a `WKUserScript` with injection time `WKUserScriptInjectionTimeAtDocumentStart`. As a consequence, `injectedJavaScriptBeforeContentLoaded` no longer returns an evaluation value nor logs a warning to the console. In the unlikely event that your app depended upon this behaviour, please see migration steps [here](https://github.com/react-native-webview/react-native-webview/pull/1119#issuecomment-574919464) to retain equivalent behaviour.
374
- > On Android, `injectedJavaScript` runs a method on the Android WebView called `evaluateJavascriptWithFallback`
375
- > Note on Android Compatibility: For applications targeting `Build.VERSION_CODES.N` or later, JavaScript state from an empty WebView is no longer persisted across navigations like `loadUrl(java.lang.String)`. For example, global variables and functions defined before calling `loadUrl(java.lang.String)` will not exist in the loaded page. Applications should use the Android Native API `addJavascriptInterface(Object, String)` instead to persist JavaScript objects across navigations.
376
-
377
- #### The `injectJavaScript` method
378
-
379
- While convenient, the downside to the previously mentioned `injectedJavaScript` prop is that it only runs once. That's why we also expose a method on the webview ref called `injectJavaScript` (note the slightly different name!).
380
-
381
- ```jsx
382
- import React, { Component } from 'react';
383
- import { View } from 'react-native';
384
- import { WebView } from 'react-native-webview';
385
-
386
- export default class App extends Component {
387
- render() {
388
- const run = `
389
- document.body.style.backgroundColor = 'blue';
390
- true;
391
- `;
392
-
393
- setTimeout(() => {
394
- this.webref.injectJavaScript(run);
395
- }, 3000);
396
-
397
- return (
398
- <View style={{ flex: 1 }}>
399
- <WebView
400
- ref={(r) => (this.webref = r)}
401
- source={{
402
- uri: 'https://github.com/react-native-webview/react-native-webview',
403
- }}
404
- />
405
- </View>
406
- );
407
- }
408
- }
409
- ```
410
-
411
- After 3 seconds, this code turns the background blue:
412
-
413
- <img alt="Screenshot of app showing injected javascript" width="200" src="https://user-images.githubusercontent.com/1479215/53670433-93a98280-3c2f-11e9-85a5-0e4650993817.png" />
414
-
415
- _Under the hood_
416
-
417
- > On iOS, `injectJavaScript` calls WebView's `evaluateJS:andThen:`
418
- > On Android, `injectJavaScript` calls Android WebView's `evaluateJavascriptWithFallback` method
419
-
420
- #### The `window.ReactNativeWebView.postMessage` method and `onMessage` prop
421
-
422
- Being able to send JavaScript to the web page is great, but what about when the web page wants to communicate back to your React Native code? This is where `window.ReactNativeWebView.postMessage` and the `onMessage` prop come in.
423
-
424
- You _must_ set `onMessage` or the `window.ReactNativeWebView.postMessage` method will not be injected into the web page.
425
-
426
- `window.ReactNativeWebView.postMessage` only accepts one argument which must be a string.
427
-
428
- ```jsx
429
- import React, { Component } from 'react';
430
- import { View } from 'react-native';
431
- import { WebView } from 'react-native-webview';
432
-
433
- export default class App extends Component {
434
- render() {
435
- const html = `
436
- <html>
437
- <head></head>
438
- <body>
439
- <script>
440
- setTimeout(function () {
441
- window.ReactNativeWebView.postMessage("Hello!")
442
- }, 2000)
443
- </script>
444
- </body>
445
- </html>
446
- `;
447
-
448
- return (
449
- <View style={{ flex: 1 }}>
450
- <WebView
451
- source={{ html }}
452
- onMessage={(event) => {
453
- alert(event.nativeEvent.data);
454
- }}
455
- />
456
- </View>
457
- );
458
- }
459
- }
460
- ```
461
-
462
- This code will result in this alert:
463
-
464
- <img alt="Alert showing communication from web page to React Native" width="200" src="https://user-images.githubusercontent.com/1479215/53671269-7e822300-3c32-11e9-9937-7ddc34ba8af3.png" />
465
-
466
- ### Working with custom headers, sessions, and cookies
467
-
468
- #### Setting Custom Headers
469
-
470
- In React Native WebView, you can set a custom header like this:
471
-
472
- ```jsx
473
- <WebView
474
- source={{
475
- uri: 'http://example.com',
476
- headers: {
477
- 'my-custom-header-key': 'my-custom-header-value',
478
- },
479
- }}
480
- />
481
- ```
482
-
483
- This will set the header on the first load, but not on subsequent page navigations.
484
-
485
- In order to work around this, you can track the current URL, intercept new page loads, and navigate to them yourself ([original credit for this technique to Chirag Shah from Big Binary](https://blog.bigbinary.com/2016/07/26/passing-request-headers-on-each-webview-request-in-react-native.html)):
486
-
487
- ```jsx
488
- const CustomHeaderWebView = (props) => {
489
- const { uri, onLoadStart, ...restProps } = props;
490
- const [currentURI, setURI] = useState(props.source.uri);
491
- const newSource = { ...props.source, uri: currentURI };
492
-
493
- return (
494
- <WebView
495
- {...restProps}
496
- source={newSource}
497
- onShouldStartLoadWithRequest={(request) => {
498
- // If we're loading the current URI, allow it to load
499
- if (request.url === currentURI) return true;
500
- // We're loading a new URL -- change state first
501
- setURI(request.url);
502
- return false;
503
- }}
504
- />
505
- );
506
- };
507
-
508
- <CustomHeaderWebView
509
- source={{
510
- uri: 'http://example.com',
511
- headers: {
512
- 'my-custom-header-key': 'my-custom-header-value',
513
- },
514
- }}
515
- />;
516
- ```
517
-
518
- #### Managing Cookies
519
-
520
- You can set cookies on the React Native side using the [@react-native-community/cookies](https://github.com/react-native-community/cookies) package.
521
-
522
- When you do, you'll likely want to enable the [sharedCookiesEnabled](Reference.md#sharedCookiesEnabled) prop as well.
523
-
524
- ```jsx
525
- const App = () => {
526
- return (
527
- <WebView
528
- source={{ uri: 'http://example.com' }}
529
- sharedCookiesEnabled={true}
530
- />
531
- );
532
- };
533
- ```
534
-
535
- If you'd like to send custom cookies in the WebView itself, you can do so in a custom header, like this:
536
-
537
- ```jsx
538
- const App = () => {
539
- return (
540
- <WebView
541
- source={{
542
- uri: 'http://example.com',
543
- headers: {
544
- Cookie: 'cookie1=asdf; cookie2=dfasdfdas',
545
- },
546
- }}
547
- sharedCookiesEnabled={true}
548
- />
549
- );
550
- };
551
- ```
552
-
553
- Note that these cookies will only be sent on the first request unless you use the technique above for [setting custom headers on each page load](#Setting-Custom-Headers).
554
-
555
- ### Page navigation gesture and button support
556
- We can provide support for conventional mobile page navigation: forward/back swipe gestures on iOS and the hardware back button/gesture on Android.
557
-
558
- For iOS, you'll just need to use the [`allowsbackforwardnavigationgestures`](Reference.md#allowsbackforwardnavigationgestures) prop.
559
-
560
- For Android, you need to use `BackHandler.addEventListener` and hook that up to call `goBack` on the `WebView`.
561
-
562
- With functional React components, you can use `useRef` and `useEffect` (you'll need to import them from React if you aren't already) to allow users to navigate to the previous page when they press the back button like so:
563
- ```jsx
564
- import React, {
565
- useEffect,
566
- useRef,
567
- } from 'react';
568
- import {
569
- BackHandler,
570
- Platform,
571
- } from 'react-native';
572
- ```
573
-
574
- ```jsx
575
- const webViewRef = useRef(null);
576
- const onAndroidBackPress = () => {
577
- if (webViewRef.current) {
578
- webViewRef.current.goBack();
579
- return true; // prevent default behavior (exit app)
580
- }
581
- return false;
582
- };
583
-
584
- useEffect(() => {
585
- if (Platform.OS === 'android') {
586
- BackHandler.addEventListener('hardwareBackPress', onAndroidBackPress);
587
- return () => {
588
- BackHandler.removeEventListener('hardwareBackPress', onAndroidBackPress);
589
- };
590
- }
591
- }, []);
592
- ```
593
-
594
- And add this prop to your `WebView` component:
595
- ```jsx
596
- <WebView
597
- ref={webViewRef}
598
- />
599
- ```
600
-
601
- ### Hardware Silence Switch
602
-
603
- There are some inconsistencies in how the hardware silence switch is handled between embedded `audio` and `video` elements and between iOS and Android platforms.
604
-
605
- Audio on `iOS` will be muted when the hardware silence switch.
606
-
607
- Video on `iOS` will always ignore the hardware silence switch.
608
-
609
- ## Translations
610
-
611
- This file is available at:
612
-
613
- - [Brazilian portuguese](Guide.portuguese.md)