@react-native-minimal-webview/extensions¶
Native hooks for 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 as react-native-minimal-webview. Install the two packages together, then rebuild the app, since this package has native code:
Each extension is a function whose result goes into the
extensions prop of <WebView>:
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.
Extensions¶
One function per extension, whose result goes into the core's extensions prop.
| Function | Description |
|---|---|
| androidLayerType | Sets the WebView's layer type, and keeps it on the WebView that replaces one whose renderer crashed: react-native-webview's androidLayerType. |
| basicAuthCredential | Answers HTTP auth challenges with credential: react-native-webview's basicAuthCredential. |
| dialogs | Answers the page's alert, confirm and prompt with onDialog instead of the native dialogs; the page waits for the answer. |
| downloadManager | 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 | Registers the WebView with the Google Mobile Ads SDK, Google's WebView API for Ads (Android, iOS), so that AdSense and Ad Manager ads on the page get the app's signals. |
| hideKeyboardAccessoryView | Hides the bar above the keyboard (previous, next, done) for the page's inputs: react-native-webview's hideKeyboardAccessoryView. |
| incognito | Starts the WebView without the cookies and cache stored before: react-native-webview's incognito. |
| keyboardDisplayRequiresUserAction | With required false, a page script's focus() on an input shows the keyboard, as a tap does: react-native-webview's keyboardDisplayRequiresUserAction. |
| menuItems | The text selection menu: react-native-webview's menuItems, suppressMenuItems and onCustomMenuSelection. |
| nestedScrollEnabled | 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 | 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 | Calls handler on each change of the scroll offset, with no throttling: react-native-webview's onScroll. |
| refreshControlLightMode | Makes the pull-to-refresh spinner white, for dark pages: react-native-webview's refreshControlLightMode. |
| removeIosKeyboardObserver | 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 | 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 | A layer type of Android's View.setLayerType, for androidLayerType. |
| BasicAuthCredential | A user name and password, for basicAuthCredential. |
| MenuItem | An item of the text selection menu, for menuItems. |
| SuppressMenuItem | A system item of the text selection menu, by react-native-webview's name, for menuItems. |
Events¶
What the handlers receive.
| Type Alias | Description |
|---|---|
| CustomMenuSelectionEvent | An item chosen from the text selection menu, for menuItems: what react-native-webview's event has in nativeEvent. |
| Dialog | A page's alert, confirm or prompt, for dialogs. |
| ScrollEvent | A scroll, for onScroll, in points (iOS) or dp (Android): what react-native-webview's event has in nativeEvent. |
| SubResourceErrorEvent | A failed request that isn't the main frame's, for onLoadSubResourceError: shaped as the core's LoadErrorEvent for a network error. |