Skip to content

Commit 02e4517

Browse files
committed
[9.0.0] clearCache, clearFormData, clear History, requestFocus methods added
1 parent 2e23c7e commit 02e4517

File tree

5 files changed

+75
-3
lines changed

5 files changed

+75
-3
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog of `@reason-react-native/webview`
22

3+
## 9.0.0 - 2020-03-19
4+
5+
- `clearCache`, `clearFormData`, `clearHistory`, `requestFocus` methods added
6+
- `injectedJavaScriptForMainFrameOnly`, `injectedJavaScriptBeforeContentLoaded`,
7+
`injectedJavaScriptBeforeContentLoadedForMainFrameOnly` props added
8+
39
## 7.4.0 - 2019-10-06
410

511
Initial release.

README.md

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,9 @@ Does not store any data within the lifetime of the `WebView.`
511511

512512
#### `injectedJavaScript: string`
513513

514-
Specifies JavaScript that will be injected into the web page when loaded. The string should evaluate to a valid type (e.g. `true`) and not otherwise throw an exception.
514+
Specifies JavaScript that will be injected into the web page when loaded. The string should evaluate to a valid type (e.g. `true`) and not otherwise throw an exception.
515+
516+
Example below passes`window.location` as a JSON object to be handled by the function passed to `onMessage`
515517

516518
```reason
517519
let injectedJavaScript = "(function() {
@@ -529,6 +531,45 @@ Note that the JavaScript will only be run once when the page is loaded for the f
529531

530532
Refer to the [Communicating between JS and Native](https://github.com/react-native-community/react-native-webview/blob/master/docs/Guide.md#communicating-between-js-and-native) guide for more information.
531533

534+
On iOS, also refer to documentation on [WKUserScriptInjectionTimeAtDocumentEnd](https://developer.apple.com/documentation/webkit/wkuserscriptinjectiontime/wkuserscriptinjectiontimeatdocumentend?language=objc).
535+
536+
#### `injectedJavaScriptForMainFrameOnly: bool`
537+
538+
_iOS only_
539+
Script specified with `injectedJavaScript` will be loaded for all frames (main frame and iframes) when `false`, defaults to `true` (only for the main frame).
540+
541+
#### `injectedJavaScriptBeforeContentLoaded: string`
542+
543+
_iOS only_
544+
Specifies JavaScript that will be injected into the web page after the document element is created, but before any other content is loaded. The string should evaluate to a valid type (e.g. `true`) and not otherwise throw an exception.
545+
546+
547+
Example below passes`window.location` as a JSON object to be handled by the function passed to `onMessage`
548+
549+
```reason
550+
let injectedJavaScript = "(function() {
551+
window.ReactNativeWebView.postMessage(JSON.stringify(window.location));
552+
})();";
553+
554+
<ReactNativeWebView
555+
source=ReactNativeWebView.Source.uri(~uri="https://facebook.github.io/react-native", ())
556+
injectedJavaScriptBeforeContentLoaded=injectedJavaScript
557+
onMessage={e => Js.Console.warn(e##nativeEvent##data)}
558+
/>
559+
```
560+
561+
Refer to the [Communicating between JS and Native](https://github.com/react-native-community/react-native-webview/blob/master/docs/Guide.md#communicating-between-js-and-native) guide for more information.
562+
563+
Also refer to documentation on [WKUserScriptInjectionTimeAtDocumentStart](https://developer.apple.com/documentation/webkit/wkuserscriptinjectiontime/wkuserscriptinjectiontimeatdocumentstart?language=objc).
564+
565+
#### `injectedJavaScriptBeforeContentLoadedForMainFrameOnly: bool`
566+
567+
_iOS only_
568+
Script specified with `injectedJavaScriptBeforeContentLoaded` will be loaded for all frames (main frame and iframes) when `false`, defaults to `true` (only for the main frame).
569+
570+
Note that it may not be possible to inject JS into iframes in this stage of the page lifecycle, therefore exercise caution when setting to `false`.
571+
572+
532573
#### `javaScriptEnabled: bool`
533574

534575
_Android only_
@@ -753,6 +794,24 @@ switch (ref -> React.Ref.current -> Js.Nullable.toOption) {
753794
};
754795
```
755796

797+
#### `clearFormData: element => unit`
798+
799+
_Android only_
800+
Removes the autocomplete popup (if present) from the currently focused form field.
801+
802+
#### `clearCache: element => unit`
803+
804+
_Android only_
805+
Clears the resource cache for all WebViews in the application.
806+
807+
#### `clearHistory: element => unit`
808+
809+
_Android only_
810+
Clears WebView's internal back/forward list
811+
812+
#### `requestFocus: element => unit`
813+
Request focus for the WebView.
814+
756815
#### `goBack: element => unit`
757816

758817
Navigates back one page in the WebView history.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"name": "@reason-react-native/webview",
3-
"version": "7.4.0",
3+
"version": "9.0.0",
44
"publishConfig": {
55
"access": "public"
66
},
77
"author": "sgny (https://github.com/sgny)",
88
"peerDependencies": {
9-
"react-native-webview": "~7.4.0"
9+
"react-native-webview": "~9.0.0"
1010
},
1111
"repository": "https://github.com/reason-react-native/webview.git",
1212
"license": "MIT",

src/ReactNativeWebView.re

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ external make:
161161
~hideKeyboardAccessoryView: bool=?,
162162
~incognito: bool=?,
163163
~injectedJavaScript: string=?,
164+
~injectedJavaScriptForMainFrameOnly: bool=?,
165+
~injectedJavaScriptBeforeContentLoaded: string=?,
166+
~injectedJavaScriptBeforeContentLoadedForMainFrameOnly: bool=?,
164167
~javaScriptEnabled: bool=?,
165168
~keyboardDisplayRequiresUserAction: bool=?,
166169
~mediaPlaybackRequiresUserAction: bool=?,

src/ReactNativeWebView_Methods.re

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
module Make = (T: {type t;}) => {
2+
[@bs.send] external clearFormData: T.t => unit = "clearFormData";
3+
[@bs.send] external clearCache: T.t => unit = "clearCache";
4+
[@bs.send] external clearHistory: T.t => unit = "clearHistory";
5+
[@bs.send] external requestFocus: T.t => unit = "requestFocus";
26
[@bs.send] external goForward: T.t => unit = "goForward";
37
[@bs.send] external goBack: T.t => unit = "goBack";
48
[@bs.send] external reload: T.t => unit = "reload";

0 commit comments

Comments
 (0)