Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[flow-strict] Flow strict in ViewPagerAndroid.android.js #22134

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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