5
5
* LICENSE file in the root directory of this source tree.
6
6
*
7
7
* @format
8
- * @flow
8
+ * @flow strict-local
9
9
*/
10
10
11
11
'use strict' ;
@@ -19,11 +19,31 @@ const requireNativeComponent = require('requireNativeComponent');
19
19
20
20
const NativeAndroidViewPager = requireNativeComponent ( 'AndroidViewPager' ) ;
21
21
22
+ import type { SyntheticEvent } from 'CoreEventTypes' ;
22
23
import type { ViewStyleProp } from 'StyleSheet' ;
23
24
24
25
const VIEWPAGER_REF = 'viewPager' ;
25
26
26
- type Event = Object ;
27
+ type PageScrollState = 'idle' | 'dragging' | 'settling' ;
28
+
29
+ type PageScrollEvent = SyntheticEvent <
30
+ $ReadOnly < { |
31
+ position : number ,
32
+ offset : number ,
33
+ | } > ,
34
+ > ;
35
+
36
+ type PageScrollStateChangedEvent = SyntheticEvent <
37
+ $ReadOnly < { |
38
+ pageScrollState : PageScrollState ,
39
+ | } > ,
40
+ > ;
41
+
42
+ type PageSelectedEvent = SyntheticEvent <
43
+ $ReadOnly < { |
44
+ position : number ,
45
+ | } > ,
46
+ > ;
27
47
28
48
export type ViewPagerScrollState = $Enum < {
29
49
idle : string ,
@@ -47,7 +67,7 @@ type Props = $ReadOnly<{|
47
67
* Value x means that (1 - x) fraction of the page at "position" index is
48
68
* visible, and x fraction of the next page is visible.
49
69
*/
50
- onPageScroll ?: ?Function ,
70
+ onPageScroll ?: ?( e : PageScrollEvent ) => void ,
51
71
52
72
/**
53
73
* Function called when the page scrolling state has changed.
@@ -57,15 +77,15 @@ type Props = $ReadOnly<{|
57
77
* - settling, meaning that there was an interaction with the page scroller, and the
58
78
* page scroller is now finishing it's closing or opening animation
59
79
*/
60
- onPageScrollStateChanged ?: ?Function ,
80
+ onPageScrollStateChanged ?: ?( e : PageScrollState ) => void ,
61
81
62
82
/**
63
83
* This callback will be called once ViewPager finish navigating to selected page
64
84
* (when user swipes between pages). The `event.nativeEvent` object passed to this
65
85
* callback will have following fields:
66
86
* - position - index of page that has been selected
67
87
*/
68
- onPageSelected ?: ?Function ,
88
+ onPageSelected ?: ?( e : PageSelectedEvent ) => void ,
69
89
70
90
/**
71
91
* Blank space to show between pages. This is only visible while scrolling, pages are still
@@ -194,7 +214,7 @@ class ViewPagerAndroid extends React.Component<Props> {
194
214
} ) ;
195
215
} ;
196
216
197
- _onPageScroll = ( e : Event ) = > {
217
+ _onPageScroll = ( e : PageScrollEvent ) = > {
198
218
if ( this . props . onPageScroll ) {
199
219
this . props . onPageScroll ( e ) ;
200
220
}
@@ -203,13 +223,13 @@ class ViewPagerAndroid extends React.Component<Props> {
203
223
}
204
224
} ;
205
225
206
- _onPageScrollStateChanged = ( e : Event ) = > {
226
+ _onPageScrollStateChanged = ( e : PageScrollStateChangedEvent ) = > {
207
227
if ( this . props . onPageScrollStateChanged ) {
208
228
this . props . onPageScrollStateChanged ( e . nativeEvent . pageScrollState ) ;
209
229
}
210
230
} ;
211
231
212
- _onPageSelected = ( e : Event ) = > {
232
+ _onPageSelected = ( e : PageSelectedEvent ) = > {
213
233
if ( this . props . onPageSelected ) {
214
234
this . props . onPageSelected ( e ) ;
215
235
}
0 commit comments