react-native-web icon indicating copy to clipboard operation
react-native-web copied to clipboard

FlatList's onScroll fires without any scrolling

Open jerrygreen opened this issue 6 years ago • 7 comments

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

jerrygreen avatar Mar 17 '19 13:03 jerrygreen

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

jerrygreen avatar Mar 17 '19 17:03 jerrygreen

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

jerrygreen avatar Mar 17 '19 17:03 jerrygreen

Were you able to get to some solution?

My issue is my list is just keeps firing onEndReached events on web.

ziaulrehman40 avatar Aug 26 '19 11:08 ziaulrehman40

@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

jerrygreen avatar Aug 26 '19 12:08 jerrygreen

Got the same issue. When will we fix this?

Uysim avatar Jun 23 '20 14:06 Uysim

Got the same issue. When will we fix this?

brizer avatar Oct 09 '21 08:10 brizer

Set a view as it's father. And set 'height: 100vh', can fix it.

brizer avatar Oct 09 '21 08:10 brizer

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.

necolas avatar Mar 27 '23 21:03 necolas