From 38e61ee21374410d5a03cc82f63dc9ef75b4025e Mon Sep 17 00:00:00 2001 From: nd-02110114 Date: Mon, 5 Nov 2018 15:00:56 +0900 Subject: [PATCH] flow strict --- .../ViewPager/ViewPagerAndroid.android.js | 36 ++++++++++++++----- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/Libraries/Components/ViewPager/ViewPagerAndroid.android.js b/Libraries/Components/ViewPager/ViewPagerAndroid.android.js index 3b98308b0265..8531d7f166a1 100644 --- a/Libraries/Components/ViewPager/ViewPagerAndroid.android.js +++ b/Libraries/Components/ViewPager/ViewPagerAndroid.android.js @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. * * @format - * @flow + * @flow strict-local */ 'use strict'; @@ -19,11 +19,31 @@ const requireNativeComponent = require('requireNativeComponent'); const NativeAndroidViewPager = requireNativeComponent('AndroidViewPager'); +import type {SyntheticEvent} from 'CoreEventTypes'; import type {ViewStyleProp} from 'StyleSheet'; const VIEWPAGER_REF = 'viewPager'; -type Event = Object; +type PageScrollState = 'idle' | 'dragging' | 'settling'; + +type PageScrollEvent = SyntheticEvent< + $ReadOnly<{| + position: number, + offset: number, + |}>, +>; + +type PageScrollStateChangedEvent = SyntheticEvent< + $ReadOnly<{| + pageScrollState: PageScrollState, + |}>, +>; + +type PageSelectedEvent = SyntheticEvent< + $ReadOnly<{| + position: number, + |}>, +>; export type ViewPagerScrollState = $Enum<{ idle: string, @@ -47,7 +67,7 @@ type Props = $ReadOnly<{| * Value x means that (1 - x) fraction of the page at "position" index is * visible, and x fraction of the next page is visible. */ - onPageScroll?: ?Function, + onPageScroll?: ?(e: PageScrollEvent) => void, /** * Function called when the page scrolling state has changed. @@ -57,7 +77,7 @@ type Props = $ReadOnly<{| * - settling, meaning that there was an interaction with the page scroller, and the * page scroller is now finishing it's closing or opening animation */ - onPageScrollStateChanged?: ?Function, + onPageScrollStateChanged?: ?(e: PageScrollState) => void, /** * This callback will be called once ViewPager finish navigating to selected page @@ -65,7 +85,7 @@ type Props = $ReadOnly<{| * callback will have following fields: * - position - index of page that has been selected */ - onPageSelected?: ?Function, + onPageSelected?: ?(e: PageSelectedEvent) => void, /** * Blank space to show between pages. This is only visible while scrolling, pages are still @@ -194,7 +214,7 @@ class ViewPagerAndroid extends React.Component { }); }; - _onPageScroll = (e: Event) => { + _onPageScroll = (e: PageScrollEvent) => { if (this.props.onPageScroll) { this.props.onPageScroll(e); } @@ -203,13 +223,13 @@ class ViewPagerAndroid extends React.Component { } }; - _onPageScrollStateChanged = (e: Event) => { + _onPageScrollStateChanged = (e: PageScrollStateChangedEvent) => { if (this.props.onPageScrollStateChanged) { this.props.onPageScrollStateChanged(e.nativeEvent.pageScrollState); } }; - _onPageSelected = (e: Event) => { + _onPageSelected = (e: PageSelectedEvent) => { if (this.props.onPageSelected) { this.props.onPageSelected(e); }