react-native-web
react-native-web copied to clipboard
FlatList's onScroll fires without any scrolling
I'm experiencing a bug with FlatList - after some clicks on the elements of the list (in my case it's an react-select) the onScroll callback fires, by some reason (however, no any scrolling happened actually)
I can't describe exact circumstances of how and why that is happening - just wanna start a discussion, maybe we will find some people experiencing this bug too
I'll leave additional notes if I find something
Found something interesting about the event passed to the callback:
nativeEvent: {
contentSize,
layoutMeasurement,
contentOffset,
}
I do an calculation:
const distanceFromEnd = contentSize.height - layoutMeasurement.height - contentOffset.y
Theoretically it should be always a positive value (and normally it is). But in this bug case it equals -2. So I simply do nothing if it's negative:
if (distanceFromEnd < 0) return false
It's enough for my exact case. However, it's still weird that the scroll event is called at all. This hack is just a hack. The callback should not be fired at first place
Looks like the values of nativeEvent are belonging to the selector div I click, not the FlatList.
Normal (typical) case:
contentSize: {
height: 1213
width: 1014
}
layoutMeasurement: {
height: 704
width: 1014
}
contentOffset: {
x: 0
y: 45
}
distanceFromEnd = 464 <----- good value, true distance that is scrollable, under the visible area
Bug case:
contentSize: {
height: 80
width: 172
}
layoutMeasurement: {
height: 79 <----- it's a size
width: 174 <----- of my selector
}
contentOffset: {
x: 0
y: 3
}
distanceFromEnd = -2
Were you able to get to some solution?
My issue is my list is just keeps firing onEndReached events on web.
@ziaulrehman40 I mentioned in my post, I've used a hack - I simply do nothing on distanceFromEnd < 0. It still weird it's firing at all
Got the same issue. When will we fix this?
Got the same issue. When will we fix this?
Set a view as it's father. And set 'height: 100vh', can fix it.
Closing this old issue because VirtualizedList/FlatList will be developed exclusively out of the RN monorepo in the future. There may still be an issue in other code that's part of RNW, so feel free to create a new issue with latest info if needed.