Nizomiddin Toshpulatov 4 年之前
父節點
當前提交
8cc3a124eb
No account linked to committer's email address
共有 2 個文件被更改,包括 38 次插入2 次删除
  1. 34
    0
      docs/Reference.md
  2. 4
    2
      src/WebViewTypes.ts

+ 34
- 0
docs/Reference.md 查看文件

@@ -22,6 +22,7 @@ This document lays out the current public properties and methods for the React N
22 22
 - [`onMessage`](Reference.md#onmessage)
23 23
 - [`onNavigationStateChange`](Reference.md#onnavigationstatechange)
24 24
 - [`onContentProcessDidTerminate`](Reference.md#oncontentprocessdidterminate)
25
+- [`onScroll`](Reference.md#onscroll)
25 26
 - [`originWhitelist`](Reference.md#originwhitelist)
26 27
 - [`renderError`](Reference.md#rendererror)
27 28
 - [`renderLoading`](Reference.md#renderloading)
@@ -578,6 +579,39 @@ url
578 579
 
579 580
 ---
580 581
 
582
+### `onScroll`[⬆](#props-index)<!-- Link generated with jump2header -->
583
+
584
+Function that is invoked when the scroll event is fired in the `WebView`.
585
+
586
+| Type     | Required | Platform                |
587
+| -------- | -------- | ----------------------- |
588
+| function | No       | iOS, macOS, Android, Windows |
589
+
590
+Example:
591
+
592
+```jsx
593
+<Webview
594
+  source={{ uri: 'https://reactnative.dev' }}
595
+  onScroll={syntheticEvent => {
596
+    const { contentOffset } = syntheticEvent.nativeEvent
597
+    console.table(contentOffset)
598
+  }}
599
+/>
600
+```
601
+
602
+Function passed to `onScroll` is called with a SyntheticEvent wrapping a nativeEvent with these properties:
603
+
604
+```
605
+contentInset
606
+contentOffset
607
+contentSize
608
+layoutMeasurement
609
+velocity
610
+zoomScale
611
+```
612
+
613
+---
614
+
581 615
 ### `originWhitelist`[⬆](#props-index)<!-- Link generated with jump2header -->
582 616
 
583 617
 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
src/WebViewTypes.ts 查看文件

@@ -167,6 +167,8 @@ export type WebViewHttpErrorEvent = NativeSyntheticEvent<WebViewHttpError>;
167 167
 
168 168
 export type WebViewRenderProcessGoneEvent = NativeSyntheticEvent<WebViewRenderProcessGoneDetail>;
169 169
 
170
+export type WebViewScrollEvent = NativeSyntheticEvent<NativeScrollEvent>;
171
+
170 172
 export type DataDetectorTypes =
171 173
   | 'phoneNumber'
172 174
   | 'link'
@@ -259,7 +261,7 @@ export interface CommonNativeWebViewProps extends ViewProps {
259 261
   javaScriptCanOpenWindowsAutomatically?: boolean;
260 262
   mediaPlaybackRequiresUserAction?: boolean;
261 263
   messagingEnabled: boolean;
262
-  onScroll?: (event: NativeScrollEvent) => void;
264
+  onScroll?: (event: WebViewScrollEvent) => void;
263 265
   onLoadingError: (event: WebViewErrorEvent) => void;
264 266
   onLoadingFinish: (event: WebViewNavigationEvent) => void;
265 267
   onLoadingProgress: (event: WebViewProgressEvent) => void;
@@ -913,7 +915,7 @@ export interface WebViewSharedProps extends ViewProps {
913 915
   /**
914 916
    * Function that is invoked when the `WebView` scrolls.
915 917
    */
916
-  onScroll?: (event: NativeScrollEvent) => void;
918
+  onScroll?: (event: WebViewScrollEvent) => void;
917 919
 
918 920
   /**
919 921
    * Function that is invoked when the `WebView` has finished loading.