mirror of
https://github.com/status-im/react-native-webview.git
synced 2026-08-31 03:31:05 +00:00
fix(ts): onScroll event type (#1631)
* Fix onScroll event type * Update documentation * Address PR feedback
This commit is contained in:
@@ -22,6 +22,7 @@ This document lays out the current public properties and methods for the React N
|
||||
- [`onMessage`](Reference.md#onmessage)
|
||||
- [`onNavigationStateChange`](Reference.md#onnavigationstatechange)
|
||||
- [`onContentProcessDidTerminate`](Reference.md#oncontentprocessdidterminate)
|
||||
- [`onScroll`](Reference.md#onscroll)
|
||||
- [`originWhitelist`](Reference.md#originwhitelist)
|
||||
- [`renderError`](Reference.md#rendererror)
|
||||
- [`renderLoading`](Reference.md#renderloading)
|
||||
@@ -580,6 +581,39 @@ url
|
||||
|
||||
---
|
||||
|
||||
### `onScroll`[⬆](#props-index)<!-- Link generated with jump2header -->
|
||||
|
||||
Function that is invoked when the scroll event is fired in the `WebView`.
|
||||
|
||||
| Type | Required | Platform |
|
||||
| -------- | -------- | ----------------------- |
|
||||
| function | No | iOS, macOS, Android, Windows |
|
||||
|
||||
Example:
|
||||
|
||||
```jsx
|
||||
<Webview
|
||||
source={{ uri: 'https://reactnative.dev' }}
|
||||
onScroll={syntheticEvent => {
|
||||
const { contentOffset } = syntheticEvent.nativeEvent
|
||||
console.table(contentOffset)
|
||||
}}
|
||||
/>
|
||||
```
|
||||
|
||||
Function passed to `onScroll` is called with a SyntheticEvent wrapping a nativeEvent with these properties:
|
||||
|
||||
```
|
||||
contentInset
|
||||
contentOffset
|
||||
contentSize
|
||||
layoutMeasurement
|
||||
velocity
|
||||
zoomScale
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### `originWhitelist`[⬆](#props-index)<!-- Link generated with jump2header -->
|
||||
|
||||
List of origin strings to allow being navigated to. The strings allow wildcards and get matched against _just_ the origin (not the full URL). If the user taps to navigate to a new page but the new page is not in this whitelist, the URL will be handled by the OS. The default whitelisted origins are "http://*" and "https://*".
|
||||
|
||||
+4
-2
@@ -167,6 +167,8 @@ export type WebViewHttpErrorEvent = NativeSyntheticEvent<WebViewHttpError>;
|
||||
|
||||
export type WebViewRenderProcessGoneEvent = NativeSyntheticEvent<WebViewRenderProcessGoneDetail>;
|
||||
|
||||
export type WebViewScrollEvent = NativeSyntheticEvent<NativeScrollEvent>;
|
||||
|
||||
export type DataDetectorTypes =
|
||||
| 'phoneNumber'
|
||||
| 'link'
|
||||
@@ -259,7 +261,7 @@ export interface CommonNativeWebViewProps extends ViewProps {
|
||||
javaScriptCanOpenWindowsAutomatically?: boolean;
|
||||
mediaPlaybackRequiresUserAction?: boolean;
|
||||
messagingEnabled: boolean;
|
||||
onScroll?: (event: NativeScrollEvent) => void;
|
||||
onScroll?: (event: WebViewScrollEvent) => void;
|
||||
onLoadingError: (event: WebViewErrorEvent) => void;
|
||||
onLoadingFinish: (event: WebViewNavigationEvent) => void;
|
||||
onLoadingProgress: (event: WebViewProgressEvent) => void;
|
||||
@@ -921,7 +923,7 @@ export interface WebViewSharedProps extends ViewProps {
|
||||
/**
|
||||
* Function that is invoked when the `WebView` scrolls.
|
||||
*/
|
||||
onScroll?: (event: NativeScrollEvent) => void;
|
||||
onScroll?: (event: WebViewScrollEvent) => void;
|
||||
|
||||
/**
|
||||
* Function that is invoked when the `WebView` has finished loading.
|
||||
|
||||
Reference in New Issue
Block a user