File tree Expand file tree Collapse file tree 3 files changed +37
-2
lines changed Expand file tree Collapse file tree 3 files changed +37
-2
lines changed Original file line number Diff line number Diff line change @@ -83,6 +83,8 @@ function getViewManagerConfig(viewManagerName) {
83
83
*/
84
84
85
85
class ViewPager extends React . Component < ViewPagerProps > {
86
+ isScrolling = false ;
87
+
86
88
componentDidMount ( ) {
87
89
// On iOS we do it directly on the native side
88
90
if ( Platform . OS === 'android' ) {
@@ -114,6 +116,7 @@ class ViewPager extends React.Component<ViewPagerProps> {
114
116
if ( this . props . onPageScrollStateChanged ) {
115
117
this . props . onPageScrollStateChanged ( e ) ;
116
118
}
119
+ this . isScrolling = e . nativeEvent . pageScrollState === 'dragging' ;
117
120
} ;
118
121
119
122
_onPageSelected = ( e : PageSelectedEvent ) => {
@@ -159,6 +162,13 @@ class ViewPager extends React.Component<ViewPagerProps> {
159
162
) ;
160
163
} ;
161
164
165
+ _onMoveShouldSetResponderCapture = ( ) => {
166
+ if ( Platform . OS === 'ios' ) {
167
+ return this . isScrolling ;
168
+ }
169
+ return false ;
170
+ } ;
171
+
162
172
render ( ) {
163
173
return (
164
174
< NativeViewPager
@@ -168,6 +178,7 @@ class ViewPager extends React.Component<ViewPagerProps> {
168
178
onPageScroll = { this . _onPageScroll }
169
179
onPageScrollStateChanged = { this . _onPageScrollStateChanged }
170
180
onPageSelected = { this . _onPageSelected }
181
+ onMoveShouldSetResponderCapture = { this . _onMoveShouldSetResponderCapture }
171
182
children = { childrenWithOverriddenStyle ( this . props . children ) }
172
183
/>
173
184
) ;
Original file line number Diff line number Diff line change 7
7
* @format
8
8
* @flow strict-local
9
9
*/
10
-
10
+ import * as React from 'react' ;
11
+ import { View } from 'react-native' ;
11
12
import type { Node } from 'react' ;
12
13
import type { SyntheticEvent } from 'react-native/Libraries/Types/CoreEventTypes' ;
13
14
import type { ViewStyleProp } from 'react-native/Libraries/StyleSheet/StyleSheet' ;
14
15
16
+ type ViewProps = React . ElementProps < typeof View > ;
17
+ type ResponderCaptureType = $PropertyType <
18
+ ViewProps ,
19
+ 'onMoveShouldSetResponderCapture' ,
20
+ > ;
21
+
15
22
export type PageScrollState = 'idle' | 'dragging' | 'settling' ;
16
23
17
24
export type PageScrollEvent = SyntheticEvent <
@@ -95,6 +102,17 @@ export type ViewPagerProps = $ReadOnly<{|
95
102
96
103
style ?: ?ViewStyleProp ,
97
104
105
+ /**
106
+ * If a parent `View` wants to prevent a child `View` from becoming responder
107
+ * on a move, it should have this handler which returns `true`.
108
+ *
109
+ * `View.props.onMoveShouldSetResponderCapture: (event) => [true | false]`,
110
+ * where `event` is a synthetic touch event as described above.
111
+ *
112
+ * See http://facebook.github.io/react-native/docs/view.html#onMoveShouldsetrespondercapture
113
+ */
114
+ onMoveShouldSetResponderCapture ?: ?ResponderCaptureType ,
115
+
98
116
/**
99
117
* iOS only
100
118
*/
Original file line number Diff line number Diff line change @@ -10,6 +10,10 @@ export interface ViewPagerOnPageSelectedEventData {
10
10
position : number ;
11
11
}
12
12
13
+ export interface PageScrollStateChangedEvent {
14
+ pageScrollState : 'idle' | 'dragging' | 'settling' ;
15
+ }
16
+
13
17
export interface ViewPagerProps extends ReactNative . ViewProps {
14
18
/**
15
19
* Index of initial page that should be selected. Use `setPage` method to
@@ -50,7 +54,7 @@ export interface ViewPagerProps extends ReactNative.ViewProps {
50
54
* - settling, meaning that there was an interaction with the page scroller, and the
51
55
* page scroller is now finishing it's closing or opening animation
52
56
*/
53
- onPageScrollStateChanged ?: ( state : "Idle" | "Dragging" | "Settling" ) => void ;
57
+ onPageScrollStateChanged ?: ( event : ReactNative . NativeSyntheticEvent < PageScrollStateChangedEvent > ) => void ;
54
58
55
59
/**
56
60
* Determines whether the keyboard gets dismissed in response to a drag.
@@ -64,6 +68,8 @@ export interface ViewPagerProps extends ReactNative.ViewProps {
64
68
* edge-to-edge.
65
69
*/
66
70
pageMargin ?: number ;
71
+
72
+ onMoveShouldSetResponderCapture ?: ( event : any ) => boolean ;
67
73
68
74
/**
69
75
* iOS only
You can’t perform that action at this time.
0 commit comments