@@ -20,15 +20,17 @@ import type {
20
20
21
21
const React = require ( 'react' ) ;
22
22
const ReactNative = require ( 'react-native' ) ;
23
- const { UIManager} = ReactNative ;
23
+
24
+ const { Platform, UIManager} = ReactNative ;
24
25
25
26
const dismissKeyboard = require ( 'react-native/Libraries/Utilities/dismissKeyboard' ) ;
26
27
27
28
import { childrenWithOverriddenStyle } from "./utils" ;
28
29
29
30
const NativeAndroidViewPager = require ( './AndroidViewPagerNativeComponent' ) ;
30
31
31
- const VIEWPAGER_REF = 'viewPager' ;
32
+ const VIEW_PAGER_REF = 'viewPager' ;
33
+ const VIEW_MANAGER_NAME = Platform . OS === 'android' ? 'AndroidViewPager' : 'RNCViewPager' ;
32
34
33
35
function getViewManagerConfig ( viewManagerName ) {
34
36
if ( ! UIManager . getViewManagerConfig ) {
@@ -82,23 +84,29 @@ function getViewManagerConfig(viewManagerName) {
82
84
83
85
class ViewPagerAndroid extends React . Component < ViewPagerProps > {
84
86
componentDidMount ( ) {
85
- if ( this . props . initialPage != null ) {
86
- this . setPageWithoutAnimation ( this . props . initialPage ) ;
87
+ // On iOS we do it directly on the native side
88
+ if ( Platform . OS === 'android' ) {
89
+ if ( this . props . initialPage != null ) {
90
+ this . setPageWithoutAnimation ( this . props . initialPage ) ;
91
+ }
87
92
}
88
93
}
89
94
90
95
/* $FlowFixMe(>=0.78.0 site=react_native_android_fb) This issue was found
91
96
* when making Flow check .android.js files. */
92
97
getInnerViewNode = ( ) : ReactComponent => {
93
- return this . refs [ VIEWPAGER_REF ] . getInnerViewNode ( ) ;
98
+ return this . refs [ VIEW_PAGER_REF ] . getInnerViewNode ( ) ;
94
99
} ;
95
100
96
101
_onPageScroll = ( e : PageScrollEvent ) => {
97
102
if ( this . props . onPageScroll ) {
98
103
this . props . onPageScroll ( e ) ;
99
104
}
100
- if ( this . props . keyboardDismissMode === 'on-drag' ) {
101
- dismissKeyboard ( ) ;
105
+ // Not implemented on iOS yet
106
+ if ( Platform . OS === 'android' ) {
107
+ if ( this . props . keyboardDismissMode === 'on-drag' ) {
108
+ dismissKeyboard ( ) ;
109
+ }
102
110
}
103
111
} ;
104
112
@@ -121,7 +129,7 @@ class ViewPagerAndroid extends React.Component<ViewPagerProps> {
121
129
setPage = ( selectedPage : number ) => {
122
130
UIManager . dispatchViewManagerCommand (
123
131
ReactNative . findNodeHandle ( this ) ,
124
- getViewManagerConfig ( 'AndroidViewPager' ) . Commands . setPage ,
132
+ getViewManagerConfig ( VIEW_MANAGER_NAME ) . Commands . setPage ,
125
133
[ selectedPage ] ,
126
134
) ;
127
135
} ;
@@ -133,7 +141,7 @@ class ViewPagerAndroid extends React.Component<ViewPagerProps> {
133
141
setPageWithoutAnimation = ( selectedPage : number ) => {
134
142
UIManager . dispatchViewManagerCommand (
135
143
ReactNative . findNodeHandle ( this ) ,
136
- getViewManagerConfig ( 'AndroidViewPager' ) . Commands
144
+ getViewManagerConfig ( VIEW_MANAGER_NAME ) . Commands
137
145
. setPageWithoutAnimation ,
138
146
[ selectedPage ] ,
139
147
) ;
@@ -143,7 +151,7 @@ class ViewPagerAndroid extends React.Component<ViewPagerProps> {
143
151
return (
144
152
< NativeAndroidViewPager
145
153
{ ...this . props }
146
- ref = { VIEWPAGER_REF }
154
+ ref = { VIEW_PAGER_REF }
147
155
style = { this . props . style }
148
156
onPageScroll = { this . _onPageScroll }
149
157
onPageScrollStateChanged = { this . _onPageScrollStateChanged }
0 commit comments