Webview
ReScript bindings for react-native-webview
Install / Use
/learn @rescript-react-native/WebviewREADME
@rescript-react-native/webview
ReScript bindings for
react-native-webview.
Exposed as the ReactNativeWebView module.
@rescript-react-native/webview X.y.* means it's compatible with
@react-native-community/react-native-webview X.y.*
Installation
When
react-native-webview
is properly installed & configured by following their installation instructions,
you can install the bindings:
npm install @rescript-react-native/webview
# or
yarn add @rescript-react-native/webview
@rescript-react-native/webview should be added to bs-dependencies in your
bsconfig.json. For example,
{
//...
"bs-dependencies": [
"@rescript/react",
"rescript-react-native",
// ...
+ "@rescript-react-native/webview"
],
//...
}
Usage
Types
DataDetectorTypes.t
Valid values are:
• DataDetectorTypes.phoneNumber
• DataDetectorTypes.link
• DataDetectorTypes.address
• DataDetectorTypes.calendarEvent
• DataDetectorTypes.none
• DataDetectorTypes.all
• DataDetectorTypes.trackingNumber
• DataDetectorTypes.flightNumber
• DataDetectorTypes.lookupSuggestion
DecelerationRate.t
Values may be created using DecelerationRate.value
value: float => t
Other valid values are DecelerationRate.normal and DecelerationRate.fast which are equivalent to specifying 0.998 and 0.99 and match the underlying iOS settings for UIScrollViewDecelerationRateNormal and UIScrollViewDecelerationRateFast respectively.
NavigationType.t
Valid values are:
• NavigationType.click
• NavigationType.formsubmit
• NavigationType.backforward
• NavigationType.reload
• NavigationType.formresubmit
• NavigationType.other
Source.t
Source to be loaded in the WebView, as specified by the [source(#source-source.t) prop can be either a URI or static HTML.
Source.uri
Creates a URI source
uri:
(
~uri: string=?,
~method: [
| `CONNECT
| `DELETE
| `GET
| `HEAD
| `OPTIONS
| `PATCH
| `POST
| `PUT
| `TRACE
]
=?,
~headers: Js.t('a)=?,
~body: string=?,
unit
) =>
t
urispecifies the URI (local or remote) to load in the WebView.methodspecifies HTTP Method to use, defaults to`GET. Only`GETand`POSTare supported on Android.headersspecifies additional HTTP headers to send with the request. This can only be used with`GETrequests on Android.bodyspecifies HTTP body to send with the request. This must be a valid UTF-8 string, and will be sent exactly as specified, with no additional encoding (e.g. URL-escaping or base64) applied. This can only be used with`POSTrequests on Android.
Source.html
Creates a static HTML source
html: (~html: string=?, ~baseUrl: string=?, unit) => t
htmlspecifies static HTML to display in the WebView asstring.baseUrlspecifies the base URL to be used for any relative links in the HTML. It is also used for the origin header with CORS requests made from the WebView. Refer to Android WebView Docs.
UnionCallback.t
Type of function passed to the onLoadEnd prop, to handle the union type webViewNavigationOrError. Defined as
ReactNative.Event.syntheticEvent(Js.t(webViewNavigationOrError)) => unit
UnionCallback.make
Creates a function of type UnionCallback.t
make:
(
~navigationCallback: WebViewNavigationEvent.t => unit,
~errorCallback: WebViewErrorEvent.t => unit
) =>
t;
UnionCallback.uncurriedMake
Creates a function of type UnionCallback.t
uncurriedMake:
(
~navigationCallback:(. webViewNavigationEvent) => unit,
~errorCallback:(. webViewErrorEvent) => unit
) =>
t;
element
Represents a WebView instance, to be used with methods.
nativeConfig
Should be constructed as below:
nativeConfig:
(
~component: React.component('a)=?,
~props: Js.t('b)=?,
~viewManager: Js.t('c)=?
) =>
nativeConfig
You may refer to iOS↗ and Android↗ specific guides on how to create a custom WebView.
ref
React ref intended to access a WebView instance. Defined as
type ref = React.Ref.t(Js.nullable(element))
Js.t(webViewNativeEvent)
Has the below keys, which can be accessed with ##.
target: ReactNative.NativeTypes.nodeHandleurl: stringtitle: stringloading: boolcanGoBack: boolcanGoForward: bool
Js.t(webViewError)
Has the below keys, which can be accessed with ##.
target: ReactNative.NativeTypes.nodeHandleurl: stringtitle: stringloading: boolcanGoBack: boolcanGoForward: booldescription: stringdomain: option(string)code: intdidFailProvisionalNavigation: option(bool)
Note: domain key only exists on iOS
Js.t(webViewHttpError)
Has the below keys, which can be accessed with ##.
target: ReactNative.NativeTypes.nodeHandleurl: stringtitle: stringloading: boolcanGoBack: boolcanGoForward: booldescription: stringstatusCode: int
Note: description key only exists on iOS
Js.t(webViewMessage)
Has the below keys, which can be accessed with ##.
target: ReactNative.NativeTypes.nodeHandleurl: stringtitle: stringloading: boolcanGoBack: boolcanGoForward: booldata: string
Js.t(webViewNativeProgressEvent)
Has the below keys, which can be accessed with ##.
target: ReactNative.NativeTypes.nodeHandleurl: stringtitle: stringloading: boolcanGoBack: boolcanGoForward: boolprogress: float
Js.t(webViewNavigation)
Has the below keys, which can be accessed with ##.
target: ReactNative.NativeTypes.nodeHandleurl: stringtitle: stringloading: boolcanGoBack: boolcanGoForward: boolnavigationType: ReactNativeWebView_NavigationType.tmainDocumentURL: option(string)
Js.t(webViewShouldStartLoadWithRequest)
Has the below keys, which can be accessed with ##.
target: ReactNative.NativeTypes.nodeHandleurl: stringtitle: stringloading: boolcanGoBack: boolcanGoForward: boolnavigationType: ReactNativeWebView_NavigationType.tmainDocumentURL: option(string)lockIdentifier: int
webViewErrorEvent
wraps Js.t(webViewError) in ReactNative.Event.syntheticEvent
type WebViewErrorEvent.t =
ReactNative.Event.syntheticEvent(Js.t(webViewError));
passed to the handler specified for onError
webViewHttpErrorEvent
wraps Js.t(webViewHttpError) in ReactNative.Event.syntheticEvent
type WebViewHttpErrorEvent.t =
ReactNative.Event.syntheticEvent(Js.t(webViewHttpError));
passed to the handler specified for onHttpError
webViewMessageEvent
wraps Js.t(webViewMessage) in ReactNative.Event.syntheticEvent
type WebViewMessageEvent.t =
ReactNative.Event.syntheticEvent(Js.t(webViewMessage));
passed to the handler specified for onMessage
webViewNavigationEvent
wraps Js.t(webViewNavigation) in ReactNative.Event.syntheticEvent
type WebViewNavigationEvent.t =
ReactNative.Event.syntheticEvent(Js.t(webViewNavigation));
passed to handlers specified for onLoad or onLoadStart
webViewProgressEvent
wraps Js.t(webViewNativeProgressEvent) in ReactNative.Event.syntheticEvent
type WebViewProgressEvent.t =
ReactNative.Event.syntheticEvent(Js.t(webViewNativeProgressEvent));
passed to the handler specified for onLoadProgress
webViewTerminatedEvent
wraps Js.t(webViewNativeEvent) in ReactNative.Event.syntheticEvent
type WebViewTerminatedEvent.t =
ReactNative.Event.syntheticEvent(webViewNativeEvent);
passed to the handler specified for onContentProcessDidTerminate
webViewNavigationOrError
Union type passed to the handler specified for onLoadEnd, is of type webViewNavigationEvent if loading succeeds and webViewErrorEvent if it fails.
Refer to UnionCallback.t for information on how to create the appropriate handler.
