11import {
22 Animated ,
3- Dimensions ,
43 FlatList ,
54 I18nManager ,
65 Platform ,
@@ -104,8 +103,8 @@ class Onboarding extends Component {
104103 } ) ;
105104 } ;
106105
107- _onLayout = ( ) => {
108- const { width, height } = Dimensions . get ( 'window' ) ;
106+ _onLayout = ( event ) => {
107+ const { width, height } = event . nativeEvent . layout ;
109108 this . setState ( { width, height } ) ;
110109 } ;
111110
@@ -154,8 +153,8 @@ class Onboarding extends Component {
154153 title = { title }
155154 subtitle = { subtitle }
156155 background = { background }
157- width = { this . state . width || Dimensions . get ( 'window' ) . width }
158- height = { this . state . height || Dimensions . get ( 'window' ) . height }
156+ width = { this . state . width }
157+ height = { this . state . height }
159158 containerStyles = { containerStyles }
160159 imageContainerStyles = { imageContainerStyles }
161160 allowFontScaling = { allowFontScalingText }
@@ -252,14 +251,13 @@ class Onboarding extends Component {
252251 }
253252 : onSkip ;
254253
255- const windowWidth = Dimensions . get ( 'window' ) . width ;
256-
257254 return (
258255 < Animated . View
259256 onLayout = { this . _onLayout }
260257 style = { { flex : 1 , backgroundColor, justifyContent : 'center' } }
261258 >
262259 { controlStatusBar && < StatusBar barStyle = { barStyle } /> }
260+ { this . state . width !== null && this . state . height !== null && (
263261 < FlatList
264262 ref = { ( list ) => {
265263 this . flatList = list ;
@@ -274,7 +272,7 @@ class Onboarding extends Component {
274272 viewabilityConfig = { itemVisibleHotfix }
275273 initialNumToRender = { 1 }
276274 getItemLayout = { ( _data , index ) => (
277- { length : windowWidth , offset : windowWidth * index , index}
275+ { length : this . state . width , offset : this . state . width * index , index}
278276 ) }
279277 extraData = {
280278 this . state . width // ensure that the list re-renders on orientation change
@@ -285,6 +283,7 @@ class Onboarding extends Component {
285283 scrollEventThrottle = { 16 }
286284 { ...flatlistProps }
287285 />
286+ ) }
288287 { showPagination && (
289288 < SafeAreaView style = { bottomBarHighlight ? styles . overlay : { } } >
290289 < Pagination
0 commit comments