fix(ts): onScroll event type (#1631)

* Fix onScroll event type

* Update documentation

* Address PR feedback
This commit is contained in:
Nizomiddin Toshpulatov
2020-12-05 20:29:37 +01:00
committed by GitHub
parent d08d000a54
commit 84b7177d21
2 changed files with 38 additions and 2 deletions
+34
View File
@@ -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
View File
@@ -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.