Skip to content

Commit e62907c

Browse files
infostreamsExilz
authored andcommitted
Don’t use getItemLayout
Same reason as meliorence/react-native-snap-carousel@ce3bf06
1 parent f05ce1c commit e62907c

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/libraries/ViewPager/index.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,13 @@ export default class ViewPager extends PureComponent {
237237
}
238238

239239
getItemLayout (data, index) {
240+
// this method is called 'getItemLayout', but it is not actually used
241+
// as the 'getItemLayout' function for the FlatList. We use it within
242+
// the code on this page though. The reason for this is that working
243+
// with 'getItemLayout' for FlatList is buggy. You might end up with
244+
// unrendered / missing content. Therefore we work around it, as
245+
// described here
246+
// https://github.com/facebook/react-native/issues/15734#issuecomment-330616697
240247
return {
241248
length: this.state.width + this.props.pageMargin,
242249
offset: (this.state.width + this.props.pageMargin) * index,
@@ -310,8 +317,12 @@ export default class ViewPager extends PureComponent {
310317
data={pageDataArray}
311318
renderItem={this.renderRow}
312319
onLayout={this.onLayout}
313-
getItemLayout={this.getItemLayout}
314-
initialScrollIndex={(this.props.initialPage || undefined)}
320+
321+
// use contentOffset instead of initialScrollIndex so that we don't have
322+
// to use the buggy 'getItemLayout' prop. See
323+
// https://github.com/facebook/react-native/issues/15734#issuecomment-330616697 and
324+
// https://github.com/facebook/react-native/issues/14945#issuecomment-354651271
325+
contentOffset = {{x: this.getScrollOffsetOfPage(parseInt(this.props.initialPage)), y:0}}
315326
/>
316327
</View>
317328
);

0 commit comments

Comments
 (0)