Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement getItemLayout on FlatList #136

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
7 changes: 6 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import NextButton from './buttons/NextButton';
import DoneButton from './buttons/DoneButton';

// hotfix: https://github.com/facebook/react-native/issues/16710
const itemVisibleHotfix = { itemVisiblePercentThreshold: 100 };
const itemVisibleHotfix = { itemVisiblePercentThreshold: 99 };

class Onboarding extends Component {
constructor(props) {
Expand Down Expand Up @@ -179,6 +179,8 @@ class Onboarding extends Component {
}
: onSkip;

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

return (
<Animated.View
onLayout={this._onLayout}
Expand All @@ -198,6 +200,9 @@ class Onboarding extends Component {
onViewableItemsChanged={this.onSwipePageChange}
viewabilityConfig={itemVisibleHotfix}
initialNumToRender={1}
getItemLayout={(_data, index) => (
{length: windowWidth, offset: windowWidth * index, index}
)}
extraData={
this.state.width // ensure that the list re-renders on orientation change
}
Expand Down