File tree Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -237,6 +237,13 @@ export default class ViewPager extends PureComponent {
237
237
}
238
238
239
239
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
240
247
return {
241
248
length : this . state . width + this . props . pageMargin ,
242
249
offset : ( this . state . width + this . props . pageMargin ) * index ,
@@ -310,8 +317,12 @@ export default class ViewPager extends PureComponent {
310
317
data = { pageDataArray }
311
318
renderItem = { this . renderRow }
312
319
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 } }
315
326
/>
316
327
</ View >
317
328
) ;
You can’t perform that action at this time.
0 commit comments