Skip to content

Commit 57869ef

Browse files
nissy-devfacebook-github-bot
authored andcommitted
Flow strict in ViewPagerAndroid.android.js (facebook#22134)
Summary: Related to facebook#22100 Turn Flow strict mode on for Libraries/Components/ViewPager/ViewPagerAndroid.android.js - [x] npm run prettier - [x] npm run flow-check-ios - [x] npm run flow-check-android [GENERAL] [ENHANCEMENT] [Libraries/Components/ViewPager/ViewPagerAndroid.android.js] - Flow strict mode Pull Request resolved: facebook#22134 Differential Revision: D12930719 Pulled By: TheSavior fbshipit-source-id: 9519f31b7af27f0497e42fd51f18c19be3692823
1 parent e2004d2 commit 57869ef

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

Libraries/Components/ViewPager/ViewPagerAndroid.android.js

+28-8
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* LICENSE file in the root directory of this source tree.
66
*
77
* @format
8-
* @flow
8+
* @flow strict-local
99
*/
1010

1111
'use strict';
@@ -19,11 +19,31 @@ const requireNativeComponent = require('requireNativeComponent');
1919

2020
const NativeAndroidViewPager = requireNativeComponent('AndroidViewPager');
2121

22+
import type {SyntheticEvent} from 'CoreEventTypes';
2223
import type {ViewStyleProp} from 'StyleSheet';
2324

2425
const VIEWPAGER_REF = 'viewPager';
2526

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+
>;
2747

2848
export type ViewPagerScrollState = $Enum<{
2949
idle: string,
@@ -47,7 +67,7 @@ type Props = $ReadOnly<{|
4767
* Value x means that (1 - x) fraction of the page at "position" index is
4868
* visible, and x fraction of the next page is visible.
4969
*/
50-
onPageScroll?: ?Function,
70+
onPageScroll?: ?(e: PageScrollEvent) => void,
5171

5272
/**
5373
* Function called when the page scrolling state has changed.
@@ -57,15 +77,15 @@ type Props = $ReadOnly<{|
5777
* - settling, meaning that there was an interaction with the page scroller, and the
5878
* page scroller is now finishing it's closing or opening animation
5979
*/
60-
onPageScrollStateChanged?: ?Function,
80+
onPageScrollStateChanged?: ?(e: PageScrollState) => void,
6181

6282
/**
6383
* This callback will be called once ViewPager finish navigating to selected page
6484
* (when user swipes between pages). The `event.nativeEvent` object passed to this
6585
* callback will have following fields:
6686
* - position - index of page that has been selected
6787
*/
68-
onPageSelected?: ?Function,
88+
onPageSelected?: ?(e: PageSelectedEvent) => void,
6989

7090
/**
7191
* 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> {
194214
});
195215
};
196216

197-
_onPageScroll = (e: Event) => {
217+
_onPageScroll = (e: PageScrollEvent) => {
198218
if (this.props.onPageScroll) {
199219
this.props.onPageScroll(e);
200220
}
@@ -203,13 +223,13 @@ class ViewPagerAndroid extends React.Component<Props> {
203223
}
204224
};
205225

206-
_onPageScrollStateChanged = (e: Event) => {
226+
_onPageScrollStateChanged = (e: PageScrollStateChangedEvent) => {
207227
if (this.props.onPageScrollStateChanged) {
208228
this.props.onPageScrollStateChanged(e.nativeEvent.pageScrollState);
209229
}
210230
};
211231

212-
_onPageSelected = (e: Event) => {
232+
_onPageSelected = (e: PageSelectedEvent) => {
213233
if (this.props.onPageSelected) {
214234
this.props.onPageSelected(e);
215235
}

0 commit comments

Comments
 (0)