From 84b7177d2181ce6527de6a7432f91d52f8cb4be3 Mon Sep 17 00:00:00 2001 From: Nizomiddin Toshpulatov Date: Sat, 5 Dec 2020 20:29:37 +0100 Subject: [PATCH] fix(ts): onScroll event type (#1631) * Fix onScroll event type * Update documentation * Address PR feedback --- docs/Reference.md | 34 ++++++++++++++++++++++++++++++++++ src/WebViewTypes.ts | 6 ++++-- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/docs/Reference.md b/docs/Reference.md index bcd1dc3..13b42e4 100644 --- a/docs/Reference.md +++ b/docs/Reference.md @@ -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) + +Function that is invoked when the scroll event is fired in the `WebView`. + +| Type | Required | Platform | +| -------- | -------- | ----------------------- | +| function | No | iOS, macOS, Android, Windows | + +Example: + +```jsx + { + 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) 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://*". diff --git a/src/WebViewTypes.ts b/src/WebViewTypes.ts index 4ed6ac0..532c0d3 100644 --- a/src/WebViewTypes.ts +++ b/src/WebViewTypes.ts @@ -167,6 +167,8 @@ export type WebViewHttpErrorEvent = NativeSyntheticEvent; export type WebViewRenderProcessGoneEvent = NativeSyntheticEvent; +export type WebViewScrollEvent = NativeSyntheticEvent; + 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.