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

ScrollView weird behaviour when there are less items

Open shreyanshgoel9 opened this issue 1 year ago • 4 comments

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

  1. Installed React Native macOs, android simulator

  2. 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>

  3. 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

shreyanshgoel9 avatar Feb 05 '24 14:02 shreyanshgoel9

:warning: Missing Reproducible Example
:information_source: We could not detect a reproducible example in your issue report. Please provide either:
  • If your bug is UI related: a Snack
  • If your bug is build/update related: use our Reproducer Template. A reproducer needs to be in a GitHub repository under your username.

github-actions[bot] avatar Feb 05 '24 14:02 github-actions[bot]

Running into the same issue, using React Native 0.73.4. I have only been able to reproduce on physical Android devices.

Myst1024 avatar Feb 13 '24 23:02 Myst1024

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.

RakaDoank avatar Feb 16 '24 19:02 RakaDoank

Running into the same issue, using React Native 0.72.10.

kemplaw avatar Feb 17 '24 03:02 kemplaw

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

ulyavrubel avatar Feb 27 '24 10:02 ulyavrubel

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

Titozzz avatar Mar 12 '24 14:03 Titozzz

After testing with Snack, doesn't happen with SDK 49 but happens on 50. Looking through the commits now.

Titozzz avatar Mar 12 '24 14:03 Titozzz

https://github.com/facebook/react-native/commit/30c7e9dfa41348e96e946384c76f038ccd859896 is the culprit!

Titozzz avatar Mar 12 '24 17:03 Titozzz

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?

NickGerleman avatar Mar 12 '24 18:03 NickGerleman

I'll have to check tomorrow ! I'm home now 😬

Titozzz avatar Mar 12 '24 18:03 Titozzz

https://github.com/facebook/react-native/commit/30c7e9dfa41348e96e946384c76f038ccd859896#diff-067e69cd88e616e9605533a4be612685b607a7d1cd29f854ee77d713113cb170R612-R614 is the change that breaks things

Titozzz avatar Mar 13 '24 09:03 Titozzz

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:

  1. 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.
  2. There are more bugs here, that the issue ended up masking.

NickGerleman avatar Mar 13 '24 19:03 NickGerleman

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

Regin99 avatar Mar 18 '24 13:03 Regin99

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 ?

Titozzz avatar Mar 18 '24 18:03 Titozzz

This is the line that breaks it for me https://github.com/facebook/react-native/commit/30c7e9dfa41348e96e946384c76f038ccd859896#diff-067e69cd88e616e9605533a4be612685b607a7d1cd29f854ee77d713113cb170R612-R614.

(Verified with breakpoints)

Titozzz avatar Mar 18 '24 18:03 Titozzz

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

Regin99 avatar Mar 18 '24 19:03 Regin99

same issue here, any solutions?

hjun555 avatar Mar 21 '24 11:03 hjun555

same issue here, any solutions?

Look above

Regin99 avatar Mar 21 '24 11:03 Regin99

In case someone needs a fix without upgrading, setting contentContainerStyle to full width worked for me

<ScrollView horizontal contentContainerStyle={{ width: "100%" }}>

baez97 avatar Apr 15 '24 15:04 baez97

Was it fixed in both 0.73 and 0.74? What are the versions, please? I still see this bug in 0.73.4.

RobinBobin avatar May 02 '24 15:05 RobinBobin

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+

NickGerleman avatar May 02 '24 22:05 NickGerleman