Skip to content

Commit

Permalink
Remove PropTypes from ViewerPagerAndroid.android.js (#21347)
Browse files Browse the repository at this point in the history
Summary:
related #21342

This is a first PR for this repo.
So, if there are any problem, please tell me 🙇

TODO
* delete props types
* apply read only interface

CheckList
 - [x] `yarn prettier`
 - [x] `yarn flow-check-android`
Pull Request resolved: #21347

Differential Revision: D10095503

Pulled By: TheSavior

fbshipit-source-id: fd1adb5edf19234ae8ae9f3fe732b03a521eb82b
  • Loading branch information
nissy-dev authored and facebook-github-bot committed Sep 28, 2018
1 parent e3ae85d commit 00b1f93
Showing 1 changed file with 70 additions and 83 deletions.
153 changes: 70 additions & 83 deletions Libraries/Components/ViewPager/ViewPagerAndroid.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

'use strict';

const DeprecatedViewPropTypes = require('DeprecatedViewPropTypes');
const PropTypes = require('prop-types');
const React = require('React');
const ReactNative = require('ReactNative');
const UIManager = require('UIManager');
Expand All @@ -21,6 +19,8 @@ const requireNativeComponent = require('requireNativeComponent');

const NativeAndroidViewPager = requireNativeComponent('AndroidViewPager');

import type {ViewStyleProp} from 'StyleSheet';

const VIEWPAGER_REF = 'viewPager';

type Event = Object;
Expand All @@ -31,6 +31,73 @@ export type ViewPagerScrollState = $Enum<{
settling: string,
}>;

type Props = $ReadOnly<{|
/**
* Index of initial page that should be selected. Use `setPage` method to
* update the page, and `onPageSelected` to monitor page changes
*/
initialPage?: ?number,

/**
* Executed when transitioning between pages (ether because of animation for
* the requested page change or when user is swiping/dragging between pages)
* The `event.nativeEvent` object for this callback will carry following data:
* - position - index of first page from the left that is currently visible
* - offset - value from range [0,1) describing stage between page transitions.
* 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,

/**
* Function called when the page scrolling state has changed.
* The page scrolling state can be in 3 states:
* - idle, meaning there is no interaction with the page scroller happening at the time
* - dragging, meaning there is currently an interaction with the page scroller
* - 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,

/**
* 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,

/**
* Blank space to show between pages. This is only visible while scrolling, pages are still
* edge-to-edge.
*/
pageMargin?: ?number,

/**
* Whether enable showing peekFraction or not. If this is true, the preview of
* last and next page will show in current screen. Defaults to false.
*/

peekEnabled?: ?boolean,

/**
* Determines whether the keyboard gets dismissed in response to a drag.
* - 'none' (the default), drags do not dismiss the keyboard.
* - 'on-drag', the keyboard is dismissed when a drag begins.
*/
keyboardDismissMode?: ?('none' | 'on-drag'),

/**
* When false, the content does not scroll.
* The default value is true.
*/
scrollEnabled?: ?boolean,

children?: React.Node,

style?: ?ViewStyleProp,
|}>;

/**
* Container that allows to flip left and right between child views. Each
* child view of the `ViewPagerAndroid` will be treated as a separate page
Expand Down Expand Up @@ -72,84 +139,8 @@ export type ViewPagerScrollState = $Enum<{
* }
* ```
*/
class ViewPagerAndroid extends React.Component<{
initialPage?: number,
onPageScroll?: Function,
onPageScrollStateChanged?: Function,
onPageSelected?: Function,
pageMargin?: number,
peekEnabled?: boolean,
keyboardDismissMode?: 'none' | 'on-drag',
scrollEnabled?: boolean,
}> {
/* $FlowFixMe(>=0.78.0 site=react_native_android_fb) This issue was found
* when making Flow check .android.js files. */
static propTypes = {
...DeprecatedViewPropTypes,
/**
* Index of initial page that should be selected. Use `setPage` method to
* update the page, and `onPageSelected` to monitor page changes
*/
initialPage: PropTypes.number,

/**
* Executed when transitioning between pages (ether because of animation for
* the requested page change or when user is swiping/dragging between pages)
* The `event.nativeEvent` object for this callback will carry following data:
* - position - index of first page from the left that is currently visible
* - offset - value from range [0,1) describing stage between page transitions.
* 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: PropTypes.func,

/**
* Function called when the page scrolling state has changed.
* The page scrolling state can be in 3 states:
* - idle, meaning there is no interaction with the page scroller happening at the time
* - dragging, meaning there is currently an interaction with the page scroller
* - 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: PropTypes.func,

/**
* 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: PropTypes.func,

/**
* Blank space to show between pages. This is only visible while scrolling, pages are still
* edge-to-edge.
*/
pageMargin: PropTypes.number,

/**
* Determines whether the keyboard gets dismissed in response to a drag.
* - 'none' (the default), drags do not dismiss the keyboard.
* - 'on-drag', the keyboard is dismissed when a drag begins.
*/
keyboardDismissMode: PropTypes.oneOf([
'none', // default
'on-drag',
]),

/**
* When false, the content does not scroll.
* The default value is true.
*/
scrollEnabled: PropTypes.bool,

/**
* Whether enable showing peekFraction or not. If this is true, the preview of
* last and next page will show in current screen. Defaults to false.
*/
peekEnabled: PropTypes.bool,
};

class ViewPagerAndroid extends React.Component<Props> {
componentDidMount() {
if (this.props.initialPage != null) {
this.setPageWithoutAnimation(this.props.initialPage);
Expand All @@ -168,8 +159,6 @@ class ViewPagerAndroid extends React.Component<{
// Override styles so that each page will fill the parent. Native component
// will handle positioning of elements, so it's not important to offset
// them correctly.
/* $FlowFixMe(>=0.78.0 site=react_native_android_fb) This issue was found
* when making Flow check .android.js files. */
return React.Children.map(this.props.children, function(child) {
if (!child) {
return null;
Expand Down Expand Up @@ -256,8 +245,6 @@ class ViewPagerAndroid extends React.Component<{
<NativeAndroidViewPager
{...this.props}
ref={VIEWPAGER_REF}
/* $FlowFixMe(>=0.78.0 site=react_native_android_fb) This issue was
* found when making Flow check .android.js files. */
style={this.props.style}
onPageScroll={this._onPageScroll}
onPageScrollStateChanged={this._onPageScrollStateChanged}
Expand Down

0 comments on commit 00b1f93

Please sign in to comment.