Skip to content

Commit 89cf616

Browse files
VisibleMarkovfacebook-github-bot
authored andcommitted
AndroidViewPagers.js (#22995)
Summary: [Android][Changed] - All the imports connected to `requireNativeComponent` in `ViewPager` was moved to a separate file. Issue in focus: #22990 Pull Request resolved: facebook/react-native#22995 Differential Revision: D13760459 Pulled By: cpojer fbshipit-source-id: fca1633ce933ea4909ef81d7bbe8123d654e24fb
1 parent b442f90 commit 89cf616

File tree

2 files changed

+115
-4
lines changed

2 files changed

+115
-4
lines changed

AndroidViewPagerNativeComponent.js

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @format
8+
* @flow
9+
*/
10+
11+
'use strict';
12+
13+
const requireNativeComponent = require('requireNativeComponent');
14+
15+
import type {SyntheticEvent} from 'CoreEventTypes';
16+
import type {NativeComponent} from 'ReactNative';
17+
import type {Node} from 'React';
18+
import type {ViewStyleProp} from 'StyleSheet';
19+
20+
type PageScrollState = 'idle' | 'dragging' | 'settling';
21+
22+
type PageScrollEvent = SyntheticEvent<
23+
$ReadOnly<{|
24+
position: number,
25+
offset: number,
26+
|}>,
27+
>;
28+
29+
type PageScrollStateChangedEvent = SyntheticEvent<
30+
$ReadOnly<{|
31+
pageScrollState: PageScrollState,
32+
|}>,
33+
>;
34+
35+
type PageSelectedEvent = SyntheticEvent<
36+
$ReadOnly<{|
37+
position: number,
38+
|}>,
39+
>;
40+
41+
type NativeProps = $ReadOnly<{|
42+
/**
43+
* Index of initial page that should be selected. Use `setPage` method to
44+
* update the page, and `onPageSelected` to monitor page changes
45+
*/
46+
initialPage?: ?number,
47+
48+
/**
49+
* Executed when transitioning between pages (ether because of animation for
50+
* the requested page change or when user is swiping/dragging between pages)
51+
* The `event.nativeEvent` object for this callback will carry following data:
52+
* - position - index of first page from the left that is currently visible
53+
* - offset - value from range [0,1) describing stage between page transitions.
54+
* Value x means that (1 - x) fraction of the page at "position" index is
55+
* visible, and x fraction of the next page is visible.
56+
*/
57+
onPageScroll?: ?(e: PageScrollEvent) => void,
58+
59+
/**
60+
* Function called when the page scrolling state has changed.
61+
* The page scrolling state can be in 3 states:
62+
* - idle, meaning there is no interaction with the page scroller happening at the time
63+
* - dragging, meaning there is currently an interaction with the page scroller
64+
* - settling, meaning that there was an interaction with the page scroller, and the
65+
* page scroller is now finishing it's closing or opening animation
66+
*/
67+
onPageScrollStateChanged?: ?(e: PageScrollStateChangedEvent) => void,
68+
69+
/**
70+
* This callback will be called once ViewPager finish navigating to selected page
71+
* (when user swipes between pages). The `event.nativeEvent` object passed to this
72+
* callback will have following fields:
73+
* - position - index of page that has been selected
74+
*/
75+
onPageSelected?: ?(e: PageSelectedEvent) => void,
76+
77+
/**
78+
* Blank space to show between pages. This is only visible while scrolling, pages are still
79+
* edge-to-edge.
80+
*/
81+
pageMargin?: ?number,
82+
83+
/**
84+
* Whether enable showing peekFraction or not. If this is true, the preview of
85+
* last and next page will show in current screen. Defaults to false.
86+
*/
87+
88+
peekEnabled?: ?boolean,
89+
90+
/**
91+
* Determines whether the keyboard gets dismissed in response to a drag.
92+
* - 'none' (the default), drags do not dismiss the keyboard.
93+
* - 'on-drag', the keyboard is dismissed when a drag begins.
94+
*/
95+
keyboardDismissMode?: ?('none' | 'on-drag'),
96+
97+
/**
98+
* When false, the content does not scroll.
99+
* The default value is true.
100+
*/
101+
scrollEnabled?: ?boolean,
102+
103+
children?: Node,
104+
105+
style?: ?ViewStyleProp,
106+
|}>;
107+
108+
type ViewPagerNativeType = Class<NativeComponent<NativeProps>>;
109+
110+
module.exports = ((requireNativeComponent(
111+
'AndroidViewPager',
112+
): any): ViewPagerNativeType);

ViewPagerAndroid.android.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ const ReactNative = require('ReactNative');
1515
const UIManager = require('UIManager');
1616

1717
const dismissKeyboard = require('dismissKeyboard');
18-
const requireNativeComponent = require('requireNativeComponent');
1918

20-
const NativeAndroidViewPager = requireNativeComponent('AndroidViewPager');
19+
const NativeAndroidViewPager = require('AndroidViewPagerNativeComponent');
2120

2221
import type {SyntheticEvent} from 'CoreEventTypes';
2322
import type {ViewStyleProp} from 'StyleSheet';
@@ -77,7 +76,7 @@ type Props = $ReadOnly<{|
7776
* - settling, meaning that there was an interaction with the page scroller, and the
7877
* page scroller is now finishing it's closing or opening animation
7978
*/
80-
onPageScrollStateChanged?: ?(e: PageScrollState) => void,
79+
onPageScrollStateChanged?: ?(e: PageScrollStateChangedEvent) => void,
8180

8281
/**
8382
* This callback will be called once ViewPager finish navigating to selected page
@@ -225,7 +224,7 @@ class ViewPagerAndroid extends React.Component<Props> {
225224

226225
_onPageScrollStateChanged = (e: PageScrollStateChangedEvent) => {
227226
if (this.props.onPageScrollStateChanged) {
228-
this.props.onPageScrollStateChanged(e.nativeEvent.pageScrollState);
227+
this.props.onPageScrollStateChanged(e);
229228
}
230229
};
231230

0 commit comments

Comments
 (0)