1
- import React , { ReactElement } from 'react' ;
2
- import { Platform , UIManager , Keyboard } from 'react-native' ;
3
- import ReactNative , { I18nManager } from 'react-native' ;
1
+ import React from 'react' ;
2
+ import { Platform , Keyboard } from 'react-native' ;
3
+ import { I18nManager } from 'react-native' ;
4
4
import type {
5
5
PagerViewOnPageScrollEvent ,
6
6
PagerViewOnPageSelectedEvent ,
@@ -9,7 +9,9 @@ import type {
9
9
} from './types' ;
10
10
11
11
import { childrenWithOverriddenStyle } from './utils' ;
12
- import PagerViewView , { NativeCommands } from './PagerViewViewNativeComponent' ;
12
+ import PagerViewView , {
13
+ Commands as PagerViewCommands ,
14
+ } from './PagerViewViewNativeComponent' ;
13
15
14
16
/**
15
17
* Container that allows to flip left and right between child views. Each
@@ -55,7 +57,7 @@ import PagerViewView, { NativeCommands } from './PagerViewViewNativeComponent';
55
57
56
58
export class PagerView extends React . Component < PagerViewProps > {
57
59
private isScrolling = false ;
58
- private PagerView = React . createRef < NativeCommands > ( ) ;
60
+ pagerView : React . ElementRef < typeof PagerViewView > | null = null ;
59
61
60
62
private _onPageScroll = ( e : PagerViewOnPageScrollEvent ) => {
61
63
if ( this . props . onPageScroll ) {
@@ -90,20 +92,19 @@ export class PagerView extends React.Component<PagerViewProps> {
90
92
* The transition between pages will be animated.
91
93
*/
92
94
public setPage = ( selectedPage : number ) => {
93
- //@ts -ignore FIX IT
94
- this . PagerView . current ?. setPage ( this . PagerView . current , selectedPage ) ;
95
+ if ( this . pagerView ) {
96
+ PagerViewCommands . setPage ( this . pagerView , selectedPage ) ;
97
+ }
95
98
} ;
96
99
97
100
/**
98
101
* A helper function to scroll to a specific page in the PagerView.
99
102
* The transition between pages will *not* be animated.
100
103
*/
101
104
public setPageWithoutAnimation = ( selectedPage : number ) => {
102
- //@ts -ignore FIX IT
103
- this . PagerView . current ?. setPageWithoutAnimation (
104
- this . PagerView . current ,
105
- selectedPage
106
- ) ;
105
+ if ( this . pagerView ) {
106
+ PagerViewCommands . setPageWithoutAnimation ( this . pagerView , selectedPage ) ;
107
+ }
107
108
} ;
108
109
109
110
/**
@@ -112,11 +113,9 @@ export class PagerView extends React.Component<PagerViewProps> {
112
113
* imperative solution is more useful (e.g. for not blocking an animation)
113
114
*/
114
115
public setScrollEnabled = ( scrollEnabled : boolean ) => {
115
- //@ts -ignore FIX IT
116
- this . PagerView . current ?. setScrollEnabled (
117
- this . PagerView . current ,
118
- scrollEnabled
119
- ) ;
116
+ if ( this . pagerView ) {
117
+ PagerViewCommands . setScrollEnabled ( this . pagerView , scrollEnabled ) ;
118
+ }
120
119
} ;
121
120
122
121
private _onMoveShouldSetResponderCapture = ( ) => {
@@ -138,7 +137,9 @@ export class PagerView extends React.Component<PagerViewProps> {
138
137
return (
139
138
< PagerViewView
140
139
{ ...this . props }
141
- ref = { this . PagerView as any /** TODO: Fix ref type */ }
140
+ ref = { ( ref ) => {
141
+ this . pagerView = ref ;
142
+ } }
142
143
style = { this . props . style }
143
144
layoutDirection = { this . deducedLayoutDirection }
144
145
onPageScroll = { this . _onPageScroll }
0 commit comments