Skip to content

Commit

Permalink
Flow strict in ViewPagerAndroid.android.js (#22134)
Browse files Browse the repository at this point in the history
Summary:
Related to #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: #22134

Differential Revision: D12930719

Pulled By: TheSavior

fbshipit-source-id: 9519f31b7af27f0497e42fd51f18c19be3692823
  • Loading branch information
nissy-dev authored and facebook-github-bot committed Nov 5, 2018
1 parent f9050e0 commit 636e146
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions Libraries/Components/ViewPager/ViewPagerAndroid.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*
* @format
* @flow
* @flow strict-local
*/

'use strict';
Expand All @@ -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,
Expand All @@ -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.
Expand All @@ -57,15 +77,15 @@ 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
* (when user swipes between pages). The `event.nativeEvent` object passed to this
* 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
Expand Down Expand Up @@ -194,7 +214,7 @@ class ViewPagerAndroid extends React.Component<Props> {
});
};

_onPageScroll = (e: Event) => {
_onPageScroll = (e: PageScrollEvent) => {
if (this.props.onPageScroll) {
this.props.onPageScroll(e);
}
Expand All @@ -203,13 +223,13 @@ class ViewPagerAndroid extends React.Component<Props> {
}
};

_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);
}
Expand Down

0 comments on commit 636e146

Please sign in to comment.