FlatList: onViewableItemsChanged is broken if pagingEnabled is true #1798
Labels
bug: react-native
Bug associated with upstream React Native vendor code
priority: low
project:react-native-web
Issue associated with react-native-web
The problem
Hi, we are using
onViewableItemsChanged
to do the impression tracking of items withFlatList
, but we currently facing a problem withFlatList
whenpagingEnabled
is true.If
pagingEnabled
is true, we get all the items(include items not in the screen) fromviewableItems
inonViewableItemsChanged
when scroll to the first item, get nothing when scroll to the second or after.How to reproduce
Simplified test case:
Codesandbox
Steps to reproduce:
FlatList
and see the log ofviewableItems
,viewableItems
will log all the items when scroll to the first item, which is unexpected.pagingEnabled
inFlatList
FlatList
again and see theviewableItems
works as expected.Expected behavior
Correctly get visible items from
viewableItems
inonViewableItemsChanged
.Environment (include versions). Did this work in previous versions?
Here is our currently used version
But this issue also occurs with the Codesandbox version
Inspection
Took a look into the code using chrome debugger, found something wrong below
react-native-web/packages/react-native-web/src/exports/UIManager/index.js
Lines 27 to 31 in 6624a70
In our case, the
relativeRect.left
has the same value ofleft
returns bygetRect(node)
, so all the items will have the same x which is 0, this will only happen ifpagingEnabled
is trueWorkaround
Currently we override
CellRendererComponent
's onLayout to fix this problemThe text was updated successfully, but these errors were encountered: