# @react-native-minimal-webview/extensions

Native hooks for [react-native-minimal-webview](<https://github.com/RasmusKard/react-native-minimal-webview>) that bring back react-native-webview props, such as `onScroll` and `basicAuthCredential`, and add JS-answered dialogs.

## Setup

It has the same [requirements](<https://github.com/RasmusKard/react-native-minimal-webview#requirements>) as react-native-minimal-webview. Install the two packages together, then rebuild the app, since this package has native code:

```sh
npx expo install react-native-minimal-webview @react-native-minimal-webview/extensions
```

Each extension is a function whose result goes into the [`extensions`](<https://rasmuskard.github.io/react-native-minimal-webview/typescript/react-native-minimal-webview/interfaces/WebViewProps/#extensions>) prop of `<WebView>`:

```tsx
import { basicAuthCredential, onScroll } from '@react-native-minimal-webview/extensions';
import { WebView } from 'react-native-minimal-webview';

export function Browser() {
  return (
    <WebView
      source={{ uri: 'https://example.com' }}
      style={{ flex: 1 }}
      extensions={[
        basicAuthCredential({ username: 'user', password: 'secret' }),
        onScroll(({ contentOffset }) => console.log(contentOffset.y)),
      ]}
    />
  );
}
```

Each extension's platforms, and how to vendor one to change it, are in the package's [README](<https://github.com/RasmusKard/react-native-minimal-webview/blob/main/extensions/README.md>).

## Extensions

One function per extension, whose result goes into the core's `extensions` prop.

| Function | Description |
| --- | --- |
| [androidLayerType](<https://rasmuskard.github.io/react-native-minimal-webview/typescript/extensions/functions/androidLayerType/index.md>) | Sets the WebView's layer type, and keeps it on the WebView that replaces one whose renderer crashed: react-native-webview's `androidLayerType`. |
| [basicAuthCredential](<https://rasmuskard.github.io/react-native-minimal-webview/typescript/extensions/functions/basicAuthCredential/index.md>) | Answers HTTP auth challenges with `credential`: react-native-webview's `basicAuthCredential`. |
| [dialogs](<https://rasmuskard.github.io/react-native-minimal-webview/typescript/extensions/functions/dialogs/index.md>) | Answers the page's `alert`, `confirm` and `prompt` with `onDialog` instead of the native dialogs; the page waits for the answer. |
| [downloadManager](<https://rasmuskard.github.io/react-native-minimal-webview/typescript/extensions/functions/downloadManager/index.md>) | Saves the page's `http:` and `https:` downloads into the device's Downloads folder with Android's Download Manager, whose notification shows the progress, and shows a toast: react-native-webview's Android downloads, with its `downloadingMessage`. |
| [googleMobileAds](<https://rasmuskard.github.io/react-native-minimal-webview/typescript/extensions/functions/googleMobileAds/index.md>) | Registers the WebView with the Google Mobile Ads SDK, Google's WebView API for Ads ([Android](<https://developers.google.com/admob/android/browser/webview/api-for-ads>), [iOS](<https://developers.google.com/admob/ios/browser/webview/api-for-ads>)), so that AdSense and Ad Manager ads on the page get the app's signals. |
| [hideKeyboardAccessoryView](<https://rasmuskard.github.io/react-native-minimal-webview/typescript/extensions/functions/hideKeyboardAccessoryView/index.md>) | Hides the bar above the keyboard (previous, next, done) for the page's inputs: react-native-webview's `hideKeyboardAccessoryView`. |
| [incognito](<https://rasmuskard.github.io/react-native-minimal-webview/typescript/extensions/functions/incognito/index.md>) | Starts the WebView without the cookies and cache stored before: react-native-webview's `incognito`. |
| [keyboardDisplayRequiresUserAction](<https://rasmuskard.github.io/react-native-minimal-webview/typescript/extensions/functions/keyboardDisplayRequiresUserAction/index.md>) | With `required` false, a page script's `focus()` on an input shows the keyboard, as a tap does: react-native-webview's `keyboardDisplayRequiresUserAction`. |
| [menuItems](<https://rasmuskard.github.io/react-native-minimal-webview/typescript/extensions/functions/menuItems/index.md>) | The text selection menu: react-native-webview's `menuItems`, `suppressMenuItems` and `onCustomMenuSelection`. |
| [nestedScrollEnabled](<https://rasmuskard.github.io/react-native-minimal-webview/typescript/extensions/functions/nestedScrollEnabled/index.md>) | Keeps a swipe that starts on the page for the page, inside a scrolling parent such as a `ScrollView`: react-native-webview's `nestedScrollEnabled`. |
| [onLoadSubResourceError](<https://rasmuskard.github.io/react-native-minimal-webview/typescript/extensions/functions/onLoadSubResourceError/index.md>) | Calls `handler` for each of the page's requests that fails, such as an image, a script or an iframe, but not the main frame's, which goes to `onError`: react-native-webview's `onLoadSubResourceError`. |
| [onScroll](<https://rasmuskard.github.io/react-native-minimal-webview/typescript/extensions/functions/onScroll/index.md>) | Calls `handler` on each change of the scroll offset, with no throttling: react-native-webview's `onScroll`. |
| [refreshControlLightMode](<https://rasmuskard.github.io/react-native-minimal-webview/typescript/extensions/functions/refreshControlLightMode/index.md>) | Makes the pull-to-refresh spinner white, for dark pages: react-native-webview's `refreshControlLightMode`. |
| [removeIosKeyboardObserver](<https://rasmuskard.github.io/react-native-minimal-webview/typescript/extensions/functions/removeIosKeyboardObserver/index.md>) | Stops the WebView from insetting its scroll view for the keyboard, for an app whose own native code handles the keyboard: react-native-webview's `removeIosKeyboardObserver`. |
| [transparentBackground](<https://rasmuskard.github.io/react-native-minimal-webview/typescript/extensions/functions/transparentBackground/index.md>) | Makes the WebView itself transparent, so that the views behind it show where the page paints no background: react-native-webview's `style={{ backgroundColor: 'transparent' }}`. |

## Values

What the functions take.

| Type Alias | Description |
| --- | --- |
| [AndroidLayerType](<https://rasmuskard.github.io/react-native-minimal-webview/typescript/extensions/type-aliases/AndroidLayerType/index.md>) | A layer type of Android's `View.setLayerType`, for [androidLayerType](<https://rasmuskard.github.io/react-native-minimal-webview/typescript/extensions/functions/androidLayerType/index.md>). |
| [BasicAuthCredential](<https://rasmuskard.github.io/react-native-minimal-webview/typescript/extensions/type-aliases/BasicAuthCredential/index.md>) | A user name and password, for [basicAuthCredential](<https://rasmuskard.github.io/react-native-minimal-webview/typescript/extensions/functions/basicAuthCredential/index.md>). |
| [MenuItem](<https://rasmuskard.github.io/react-native-minimal-webview/typescript/extensions/type-aliases/MenuItem/index.md>) | An item of the text selection menu, for [menuItems](<https://rasmuskard.github.io/react-native-minimal-webview/typescript/extensions/functions/menuItems/index.md>). |
| [SuppressMenuItem](<https://rasmuskard.github.io/react-native-minimal-webview/typescript/extensions/type-aliases/SuppressMenuItem/index.md>) | A system item of the text selection menu, by react-native-webview's name, for [menuItems](<https://rasmuskard.github.io/react-native-minimal-webview/typescript/extensions/functions/menuItems/index.md>). |

## Events

What the handlers receive.

| Type Alias | Description |
| --- | --- |
| [CustomMenuSelectionEvent](<https://rasmuskard.github.io/react-native-minimal-webview/typescript/extensions/type-aliases/CustomMenuSelectionEvent/index.md>) | An item chosen from the text selection menu, for [menuItems](<https://rasmuskard.github.io/react-native-minimal-webview/typescript/extensions/functions/menuItems/index.md>): what react-native-webview's event has in `nativeEvent`. |
| [Dialog](<https://rasmuskard.github.io/react-native-minimal-webview/typescript/extensions/type-aliases/Dialog/index.md>) | A page's `alert`, `confirm` or `prompt`, for [dialogs](<https://rasmuskard.github.io/react-native-minimal-webview/typescript/extensions/functions/dialogs/index.md>). |
| [ScrollEvent](<https://rasmuskard.github.io/react-native-minimal-webview/typescript/extensions/type-aliases/ScrollEvent/index.md>) | A scroll, for [onScroll](<https://rasmuskard.github.io/react-native-minimal-webview/typescript/extensions/functions/onScroll/index.md>), in points (iOS) or dp (Android): what react-native-webview's event has in `nativeEvent`. |
| [SubResourceErrorEvent](<https://rasmuskard.github.io/react-native-minimal-webview/typescript/extensions/type-aliases/SubResourceErrorEvent/index.md>) | A failed request that isn't the main frame's, for [onLoadSubResourceError](<https://rasmuskard.github.io/react-native-minimal-webview/typescript/extensions/functions/onLoadSubResourceError/index.md>): shaped as the core's `LoadErrorEvent` for a network error. |
