react-native
react-native copied to clipboard
Fix android layout event lossy conversion
Summary:
Fix https://github.com/facebook/react-native/issues/32814 and https://github.com/facebook/react-native/issues/26906
I've tried PixelRatio.roundToNearestPixel(), which also returns a float number that has lost precision
Changelog:
[ANDROID] [BREAKING] - Fix android layout event lossy conversion
Test Plan:
The test should verify that originWidth == width returns true
const ratio = PixelRatio.get();
const originWidth = PixelRatio.roundToNearestPixel(301);
console.log('PixelRatio.get()', ratio)
const printEventWidth = (eventName, width) => {
console.log(eventName, originWidth, width, originWidth == width);
};
return (
<ScrollView
style={{ width: originWidth, height: '100%' }}
onLayout={({ nativeEvent: { layout: { width }}}) => {
printEventWidth('onLayout', width);
}}
onScroll={({ nativeEvent: { layoutMeasurement: { width }}}) => {
printEventWidth('onScroll', width);
}}
onContentSizeChange={(width) => {
printEventWidth('onContentSizeChange', width);
}}
>
<View style={{ width: '100%', height: 2000 }}></View>
</ScrollView>
);
Before
// PixelRatio.get() 2.75
// onContentSizeChange 301.09090909090907 301.0909118652344 false
// onLayout 301.09090909090907 301.0909118652344 false
// onScroll 301.09090909090907 301.0909118652344 false
After
// PixelRatio.get() 2.75
// onContentSizeChange 301.09090909090907 301.09090909090907 true
// onLayout 301.09090909090907 301.09090909090907 true
// onScroll 301.09090909090907 301.09090909090907 true
| Platform | Engine | Arch | Size (bytes) | Diff |
|---|---|---|---|---|
| android | hermes | arm64-v8a | 17,636,595 | -20 |
| android | hermes | armeabi-v7a | n/a | -- |
| android | hermes | x86 | n/a | -- |
| android | hermes | x86_64 | n/a | -- |
| android | jsc | arm64-v8a | 21,018,347 | -5 |
| android | jsc | armeabi-v7a | n/a | -- |
| android | jsc | x86 | n/a | -- |
| android | jsc | x86_64 | n/a | -- |
Base commit: d077239fff600d41d093dfeca87f6744bd7f1cd3 Branch: main
This PR is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.
This PR was closed because it has been stalled for 7 days with no activity.