facebook / react-native

A framework for building native applications using React
https://reactnative.dev
MIT License
118.17k stars 24.21k forks source link

ScrollView doesn't scroll when overflows the parent view #46008

Open rjritik1137 opened 1 month ago

rjritik1137 commented 1 month ago

Description

If we have a parent view, and render Touch like elements, (for eg. - Button, Pressable, TouchableOpacity) outside the Parent View with overflow:'visible' the Touch works fine. But if I render a ScrollView outside the parent view, it doesn't scroll.

Steps to reproduce

https://snack.expo.dev/@rtk_jain/scrollview-does-not-work-when-overflowing

React Native Version

0.74.3

Affected Platforms

Runtime - Android, Runtime - iOS, Runtime - Web

Output of npx react-native info

System:
  OS: macOS 14.4
  CPU: (12) arm64 Apple M3 Pro
  Memory: 82.45 MB / 18.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 20.15.1
    path: ~/.nvm/versions/node/v20.15.1/bin/node
  Yarn:
    version: 3.6.4
    path: ~/.nvm/versions/node/v20.15.1/bin/yarn
  npm:
    version: 10.7.0
    path: ~/.nvm/versions/node/v20.15.1/bin/npm
  Watchman:
    version: 2024.07.15.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.15.2
    path: /opt/homebrew/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.5
      - iOS 17.5
      - macOS 14.5
      - tvOS 17.5
      - visionOS 1.2
      - watchOS 10.5
  Android SDK:
    API Levels:
      - "29"
      - "30"
      - "33"
      - "34"
    Build Tools:
      - 29.0.2
      - 30.0.3
      - 33.0.0
      - 34.0.0
      - 35.0.0
    System Images:
      - android-29 | ARM 64 v8a
      - android-29 | Intel x86 Atom
      - android-29 | Intel x86_64 Atom
      - android-29 | Google APIs ARM 64 v8a
      - android-29 | Google APIs Intel x86 Atom
      - android-29 | Google APIs Intel x86_64 Atom
      - android-29 | Google Play ARM 64 v8a
      - android-29 | Google Play Intel x86 Atom
      - android-29 | Google Play Intel x86_64 Atom
    Android NDK: Not Found
IDEs:
  Android Studio: 2024.1 AI-241.18034.62.2411.12071903
  Xcode:
    version: 15.4/15F31d
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.10
    path: /usr/bin/javac
  Ruby:
    version: 2.6.10
    path: /usr/bin/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.74.3
    wanted: 0.74.3
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: true
  newArchEnabled: false

Stacktrace or Logs

No Stack Trace

Reproducer

https://snack.expo.dev/@rtk_jain/scrollview-does-not-work-when-overflowing

Screenshots and Videos

No response

react-native-bot commented 1 month ago
:warning: Newer Version of React Native is Available!
:information_source: You are on a supported minor version, but it looks like there's a newer patch available - 0.74.5. Please upgrade to the highest patch for your minor or latest and verify if the issue persists (alternatively, create a new project and repro the issue in it). If it does not repro, please let us know so we can close out this issue. This helps us ensure we are looking at issues that still exist in the most recent releases.
react-native-bot commented 1 month ago
:warning: Newer Version of React Native is Available!
:information_source: You are on a supported minor version, but it looks like there's a newer patch available - undefined. Please upgrade to the highest patch for your minor or latest and verify if the issue persists (alternatively, create a new project and repro the issue in it). If it does not repro, please let us know so we can close out this issue. This helps us ensure we are looking at issues that still exist in the most recent releases.
Hwirin-Kim commented 1 month ago

Just to clarify, did you position the ScrollView with absolute inside the parent? If so, I had the same issue.

I fixed it by using the ScrollView from react-native-gesture-handler. It worked perfectly in my case. You might want to try that approach.

I'm using React Native version "react-native": "0.72.4".

rjritik1137 commented 4 weeks ago

@Hwirin-Kim Yes, it's inside absolute. But It doesn't matter if the scrollview is inside an absolute view or a normal view. The issue is, if Clickable elements are being positioned outside of the parent container. They are responding. But's it's not the same with ScrollView. I will try probably ScrollView from react-native-gesture-handler, but before that I would want to know why it's happening.

alpenmilch commented 3 weeks ago

Perhaps Android does not support touchment on overflow content. In this commit, rn add touchment support on overflow view, the touch event will be dispatch to js code on overflow content, so those touchable will receive it and act correctly. The ScrollView also will receive the touch movement event in JS side, you can catch it in onTouchMove callback, but it won't scroll because the Motion Event is not dispatched to the actual Android ScrollView.

rjritik1137 commented 2 weeks ago

@alpenmilch Isn't that unexpected behaviour? If the scrollView is visible outside the parent with overflow property. The developer/user would expect it to scroll.