SkillAgentSearch skills...

Webview

ReScript bindings for react-native-webview

Install / Use

/learn @rescript-react-native/Webview
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

@rescript-react-native/webview

Build Status Version ReScript Forum

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.phoneNumberDataDetectorTypes.linkDataDetectorTypes.addressDataDetectorTypes.calendarEventDataDetectorTypes.noneDataDetectorTypes.allDataDetectorTypes.trackingNumberDataDetectorTypes.flightNumberDataDetectorTypes.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.clickNavigationType.formsubmitNavigationType.backforwardNavigationType.reloadNavigationType.formresubmitNavigationType.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
  • uri specifies the URI (local or remote) to load in the WebView.
  • method specifies HTTP Method to use, defaults to `GET. Only `GET and `POST are supported on Android.
  • headers specifies additional HTTP headers to send with the request. This can only be used with `GET requests on Android.
  • body specifies 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 `POST requests on Android.
Source.html

Creates a static HTML source

html: (~html: string=?, ~baseUrl: string=?, unit) => t
  • html specifies static HTML to display in the WebView as string.
  • baseUrl specifies 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.nodeHandle
  • url: string
  • title: string
  • loading: bool
  • canGoBack: bool
  • canGoForward: bool

Js.t(webViewError)

Has the below keys, which can be accessed with ##.

  • target: ReactNative.NativeTypes.nodeHandle
  • url: string
  • title: string
  • loading: bool
  • canGoBack: bool
  • canGoForward: bool
  • description: string
  • domain: option(string)
  • code: int
  • didFailProvisionalNavigation: option(bool)

Note: domain key only exists on iOS

Js.t(webViewHttpError)

Has the below keys, which can be accessed with ##.

  • target: ReactNative.NativeTypes.nodeHandle
  • url: string
  • title: string
  • loading: bool
  • canGoBack: bool
  • canGoForward: bool
  • description: string
  • statusCode: int

Note: description key only exists on iOS

Js.t(webViewMessage)

Has the below keys, which can be accessed with ##.

  • target: ReactNative.NativeTypes.nodeHandle
  • url: string
  • title: string
  • loading: bool
  • canGoBack: bool
  • canGoForward: bool
  • data: string

Js.t(webViewNativeProgressEvent)

Has the below keys, which can be accessed with ##.

  • target: ReactNative.NativeTypes.nodeHandle
  • url: string
  • title: string
  • loading: bool
  • canGoBack: bool
  • canGoForward: bool
  • progress: float

Js.t(webViewNavigation)

Has the below keys, which can be accessed with ##.

  • target: ReactNative.NativeTypes.nodeHandle
  • url: string
  • title: string
  • loading: bool
  • canGoBack: bool
  • canGoForward: bool
  • navigationType: ReactNativeWebView_NavigationType.t
  • mainDocumentURL: option(string)

Js.t(webViewShouldStartLoadWithRequest)

Has the below keys, which can be accessed with ##.

  • target: ReactNative.NativeTypes.nodeHandle
  • url: string
  • title: string
  • loading: bool
  • canGoBack: bool
  • canGoForward: bool
  • navigationType: ReactNativeWebView_NavigationType.t
  • mainDocumentURL: 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.

Props

`ref: r

View on GitHub
GitHub Stars8
CategoryDevelopment
Updated1y ago
Forks3

Languages

ReScript

Security Score

75/100

Audited on Aug 2, 2024

No findings