Skip to content

Conversation

@Freddy03h
Copy link

@Freddy03h Freddy03h commented Mar 18, 2025

Hi!

I've been using RecyclerListView (and now FlashList) for many years in my project.

I've applied many patches to address different issues, but I’ve noticed that many of them share the same root cause: a probable floating-point precision issue related to React Native's onLayout event.


Here’s an example of the event.nativeEvent.layout output for seven identical horizontal list components with different data:

Capture d’écran 2025-03-18 à 16 29 38

Those affected by the floating-point issue experienced problems such as being unable to click on an item or scroll to the last item


There are many ways to handle this issue, but we don’t want to rely on external dependencies. Instead, we want to track only the changes that produce actual visual differences on screen.

In other words, we don’t want to simply Math.round the values, as that would prevent us from detecting changes smaller than 1 dp. On a device with a pixel ratio of 3, we need to track changes as small as 0.333333 (which corresponds to StyleSheet.hairlineWidth).

That’s why I believe PixelRatio.roundToNearestPixel is a good candidate for this fix: regardless of the reason for the onLayout changes, if a change isn’t significant enough to produce a visible difference on screen, then no action should be taken.

@Freddy03h Freddy03h changed the title fix onLayout floating point numbers with roundToNearestPixel fix onLayout floating point numbers using roundToNearestPixel Mar 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant