Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
Animated,
Dimensions,
FlatList,
I18nManager,
Platform,
Expand Down Expand Up @@ -104,8 +103,8 @@ class Onboarding extends Component {
});
};

_onLayout = () => {
const { width, height } = Dimensions.get('window');
_onLayout = (event) => {
const { width, height } = event.nativeEvent.layout;
this.setState({ width, height });
};

Expand Down Expand Up @@ -154,8 +153,8 @@ class Onboarding extends Component {
title={title}
subtitle={subtitle}
background={background}
width={this.state.width || Dimensions.get('window').width}
height={this.state.height || Dimensions.get('window').height}
width={this.state.width}
height={this.state.height}
containerStyles={containerStyles}
imageContainerStyles={imageContainerStyles}
allowFontScaling={allowFontScalingText}
Expand Down Expand Up @@ -252,14 +251,13 @@ class Onboarding extends Component {
}
: onSkip;

const windowWidth = Dimensions.get('window').width;

return (
<Animated.View
onLayout={this._onLayout}
style={{ flex: 1, backgroundColor, justifyContent: 'center' }}
>
{controlStatusBar && <StatusBar barStyle={barStyle} />}
{this.state.width !== null && this.state.height !== null && (
<FlatList
ref={(list) => {
this.flatList = list;
Expand All @@ -274,7 +272,7 @@ class Onboarding extends Component {
viewabilityConfig={itemVisibleHotfix}
initialNumToRender={1}
getItemLayout={(_data, index) => (
{length: windowWidth, offset: windowWidth * index, index}
{length: this.state.width, offset: this.state.width * index, index}
)}
extraData={
this.state.width // ensure that the list re-renders on orientation change
Expand All @@ -285,6 +283,7 @@ class Onboarding extends Component {
scrollEventThrottle={16}
{...flatlistProps}
/>
)}
{showPagination && (
<SafeAreaView style={bottomBarHighlight ? styles.overlay : {}}>
<Pagination
Expand Down