react-native
react-native copied to clipboard
ScrollView weird behaviour when there are less items
Description
When the scrollview container is bigger than total item width, on scroll the items start sticking on right on android. Tested on physical device as well
https://github.com/facebook/react-native/assets/136585177/6ed7efe5-9436-46c5-b5d8-e34236b496af
Steps to reproduce
-
Installed React Native macOs, android simulator
-
Write this code
<ScrollView horizontal={true} style={{backgroundColor: 'green'}}> <View style={{ height: 40, width: 50, marginRight: 20, backgroundColor: 'red', }} /> <View style={{ height: 40, width: 50, marginRight: 20, backgroundColor: 'red', }} /> </ScrollView>
-
Scroll horizontal to reproduce
React Native Version
0.73.3
Affected Platforms
Runtime - Android
Output of npx react-native info
System:
OS: macOS 14.1.2
CPU: (8) arm64 Apple M1 Pro
Memory: 87.98 MB / 16.00 GB
Shell:
version: "5.9"
path: /bin/zsh
Binaries:
Node:
version: 18.12.1
path: ~/.nvm/versions/node/v18.12.1/bin/node
Yarn:
version: 1.22.19
path: ~/.nvm/versions/node/v18.12.1/bin/yarn
npm:
version: 8.19.2
path: ~/.nvm/versions/node/v18.12.1/bin/npm
Watchman:
version: 2023.08.14.00
path: /opt/homebrew/bin/watchman
Managers:
CocoaPods:
version: 1.14.2
path: /opt/homebrew/opt/ruby/bin/pod
SDKs:
iOS SDK:
Platforms:
- DriverKit 23.2
- iOS 17.2
- macOS 14.2
- tvOS 17.2
- visionOS 1.0
- watchOS 10.2
Android SDK: Not Found
IDEs:
Android Studio: 2022.3 AI-223.8836.35.2231.10811636
Xcode:
version: 15.2/15C500b
path: /usr/bin/xcodebuild
Languages:
Java:
version: 20.0.2
path: /opt/homebrew/opt/openjdk/bin/javac
Ruby:
version: 3.2.2
path: /opt/homebrew/opt/ruby/bin/ruby
npmPackages:
"@react-native-community/cli": Not Found
react:
installed: 18.2.0
wanted: 18.2.0
react-native:
installed: 0.73.3
wanted: 0.73.3
react-native-macos: Not Found
npmGlobalPackages:
"*react-native*": Not Found
Android:
hermesEnabled: true
newArchEnabled: false
iOS:
hermesEnabled: true
newArchEnabled: false
Stacktrace or Logs
-
Reproducer
Screenshots and Videos
No response
:warning: | Missing Reproducible Example |
---|---|
:information_source: | We could not detect a reproducible example in your issue report. Please provide either:
|
Running into the same issue, using React Native 0.73.4. I have only been able to reproduce on physical Android devices.
I also have this issue. I can reproduce this in physical Android device (API 33) and Android simulator (API 34). So far, no problem on iOS simulator.
I actually wanted to write this earlier. I remember i get this issue since i upgraded the RN to 0.73.0 from 0.72.7, until now currently on 0.73.4.
Running into the same issue, using React Native 0.72.10.
Running into the same issue, using React Native 0.73.4. Reproducible on Android only
Steps to Reproduce
<ScrollView horizontal>
...
</ScrollView>
Demo
https://snack.expo.dev/@uvrubel/rn-scrollview-horizontal
https://github.com/facebook/react-native/assets/52666724/1f17dabd-1832-4089-8787-e38b028b7410
Can confirm this is not something that was here before (but cannot easily bisect). I can reproduce on 0.73.2 and 0.73.6
After testing with Snack, doesn't happen with SDK 49 but happens on 50. Looking through the commits now.
https://github.com/facebook/react-native/commit/30c7e9dfa41348e96e946384c76f038ccd859896 is the culprit!
Whoah, that's a crazy effect.
The interesting logic here is gated on:
mReactScrollViewScrollState.getLayoutDirection() == LAYOUT_DIRECTION_RTL
https://github.com/facebook/react-native/blob/30c7e9dfa41348e96e946384c76f038ccd859896/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollView.java#L1308
@Titozzz is this path being hit on physical device?
I'll have to check tomorrow ! I'm home now 😬
https://github.com/facebook/react-native/commit/30c7e9dfa41348e96e946384c76f038ccd859896#diff-067e69cd88e616e9605533a4be612685b607a7d1cd29f854ee77d713113cb170R612-R614 is the change that breaks things
Huh. That was to fix another bug, where flinging to the edge would sometimes start scrolling backwards (https://github.com/facebook/react-native/issues/38236 is one report, though I think I saw others after the fact).
The version clamp was based on a linked Android bug report being fixed, and seeing incorrect behavior in emulator. So I think there might be a couple possibilities:
- Different behavior on another Android version. @Titozzz do you remember version in emulator vs device where you could or couldn’t repro this? If we can only repro on some devices, I wonder if this might be the case.
- There are more bugs here, that the issue ended up masking.
30c7e9d#diff-067e69cd88e616e9605533a4be612685b607a7d1cd29f854ee77d713113cb170R612-R614 is the change that breaks things
Even if i fully downgrade android scroll logic (ReactAndroid/src/.../views/scroll) to 0.72.4 version, bug is still reproduced. Interesting fact, that shopify's flashlist reproduce this bug too. Are u sure that this changes breaks things?
Tested on emulator 30, 34 api RN 0.73.5
Yep you are using prefab probably! https://reactnative.dev/contributing/how-to-build-from-source#update-your-project-to-build-from-source Did you do that ?
This is the line that breaks it for me https://github.com/facebook/react-native/commit/30c7e9dfa41348e96e946384c76f038ccd859896#diff-067e69cd88e616e9605533a4be612685b607a7d1cd29f854ee77d713113cb170R612-R614.
(Verified with breakpoints)
Yep you are using prefab probably! https://reactnative.dev/contributing/how-to-build-from-source#update-your-project-to-build-from-source Did you do that ?
Yeah, my mistake. I'm forgot bout prefabs. Thank you
same issue here, any solutions?
same issue here, any solutions?
Look above
In case someone needs a fix without upgrading, setting contentContainerStyle
to full width worked for me
<ScrollView horizontal contentContainerStyle={{ width: "100%" }}>
Was it fixed in both 0.73 and 0.74? What are the versions, please? I still see this bug in 0.73.4.
Was it fixed in both 0.73 and 0.74? What are the versions, please? I still see this bug in 0.73.4.
Available in 0.73.7+