Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inverted Flatlist not working when scrolled #44151

Closed
WoLewicki opened this issue Apr 18, 2024 · 6 comments
Closed

Inverted Flatlist not working when scrolled #44151

WoLewicki opened this issue Apr 18, 2024 · 6 comments
Labels
Component: FlatList Issue: Author Provided Repro This issue can be reproduced in Snack or an attached project. p: Software Mansion Partner: Software Mansion Partner Resolution: Fixed A PR that fixes this issue has been merged. Type: New Architecture Issues and PRs related to new architecture (Fabric/Turbo Modules)

Comments

@WoLewicki
Copy link
Contributor

WoLewicki commented Apr 18, 2024

Description

On new arch, when FlatList is inverted, after scrolling the elements don't fire their onPress since the information about their position must be calculated wrongly. There is probably a bug with this method:

return {-contentOffset.x, -contentOffset.y + stateData.scrollAwayPaddingTop};
when we invert the FlatList.

Steps to reproduce

  1. Scroll
  2. See that the onPress is not fired.

React Native Version

0.73.6

Affected Platforms

Runtime - Android
Runtime - iOS

Areas

Fabric - The New Renderer

Output of npx react-native info

System:
  OS: macOS 14.3
  CPU: (12) arm64 Apple M3 Pro
  Memory: 83.02 MB / 18.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 20.10.0
    path: ~/.nvm/versions/node/v20.10.0/bin/node
  Yarn:
    version: 1.22.19
    path: /opt/homebrew/bin/yarn
  npm:
    version: 10.2.3
    path: ~/.nvm/versions/node/v20.10.0/bin/npm
  Watchman:
    version: 2023.11.27.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.14.3
    path: /Users/wojciechlewicki/.rvm/gems/ruby-3.2.1/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.4
      - iOS 17.4
      - macOS 14.4
      - tvOS 17.4
      - visionOS 1.1
      - watchOS 10.4
  Android SDK:
    API Levels:
      - "26"
      - "27"
      - "28"
      - "29"
      - "30"
      - "31"
      - "32"
      - "33"
      - "34"
    Build Tools:
      - 28.0.3
      - 29.0.2
      - 30.0.2
      - 30.0.3
      - 31.0.0
      - 32.0.0
      - 32.1.0
      - 33.0.0
      - 33.0.1
      - 34.0.0
    System Images:
      - android-28 | Google ARM64-V8a Play ARM 64 v8a
      - android-29 | Google Play ARM 64 v8a
      - android-31 | Google Play ARM 64 v8a
      - android-32 | Google APIs ARM 64 v8a
      - android-33 | Google Play ARM 64 v8a
      - android-34 | Google Play ARM 64 v8a
    Android NDK: 22.1.7171670
IDEs:
  Android Studio: 2023.2 AI-232.10300.40.2321.11567975
  Xcode:
    version: 15.3/15E204a
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 18.0.2
    path: /opt/homebrew/opt/openjdk@18/bin/javac
  Ruby:
    version: 3.2.1
    path: /Users/wojciechlewicki/.rvm/rubies/ruby-3.2.1/bin/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.73.6
    wanted: 0.73.6
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: Not found
  newArchEnabled: false

Stacktrace or Logs

None here

Reproducer

https://github.com/WoLewicki/reproducer-react-native/tree/%40wolewicki/flatlist-inverted

Screenshots and Videos

No response

@WoLewicki WoLewicki added Needs: Triage 🔍 Type: New Architecture Issues and PRs related to new architecture (Fabric/Turbo Modules) labels Apr 18, 2024
@roryabraham
Copy link

@WoLewicki thanks for producing this minimal reproduction. Should we update the reproducer to use RN 0.74.0-rc.9 rather than 0.73.6 and see if it's still reproducible?

@roryabraham
Copy link

@cortinico
Copy link
Contributor

Thanks @WoLewicki and @roryabraham for providing a reproducer and verifying against 0.74.0

This is (sadly) as known issue. The root cause is that for inverted flatlist we use a transform which is sometimes causing problems with measurements on Fabric (resulting in missed clicks). I remember discussing this with a lot of folks (@sammy-SC @javache @kmagiera @tomekzaw et. al.)

We were already aware of this issue and it's higher up on our agenda to fix.
We'll update more on this issue as we have actionable next steps.

@cortinico cortinico added Issue: Author Provided Repro This issue can be reproduced in Snack or an attached project. and removed Needs: Triage 🔍 labels Apr 19, 2024
@WoLewicki
Copy link
Contributor Author

@kosmydel has just found a potential fix for the problem, he'll link the PR here when he makes one 🚀

@kosmydel
Copy link
Contributor

Hey, here is a potential fix for this issue.

facebook-github-bot pushed a commit that referenced this issue Jun 12, 2024
Summary:
This PR solves [this issue](#44151).
Inverted FlatList doesn't work (elements cannot be clicked) when the list is scrolled.

## Changelog:

<!-- Help reviewers and the release process by writing your own changelog entry.

Pick one each for the category and type tags:

[ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message

For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->
[GENERAL] [FIXED] - Fix clicking items on the inverted FlatList on the new architecture

Pull Request resolved: #44168

Test Plan:
# Steps
1. `buck2 install catalyst-ios` or `buck2 install catalyst-android`
2. Go to `RNTester Browser - Fabric` -> `FlatList` -> `Inverted`
3. Toggle inverted to `true`
4. Scroll to the top
5. Tap down and drag to either left or right
6. Expected is to have Red highlighted (which indicate Press Down) when dragged.

## iOS
| Before | After |
|-----------------------|----------------------|
|  https://pxl.cl/53vCW  |  https://pxl.cl/53vDq |

## Android
| Before | After |
|-----------------------|----------------------|
|  https://pxl.cl/53vFp |  https://pxl.cl/53vFG |

## Reproducing steps from OSS

1. Use this reproducer: https://github.com/WoLewicki/reproducer-react-native/tree/%40wolewicki/flatlist-inverted
2. Apply changes from this PR & build the app.
3. Scroll a bit the list, so it changes the position.
4. The `onPress` should be fired when the button is clicked.
5. Do the following tests:
  1. Add a `horizontal` prop to the FlatList - verify everything works.
  2. Remove a `inverted` prop - verify everything works.
  3. Remove a `inverted` prop and add a `horizontal` prop - verify everything works.
6. Test different combinations of transforms of the FlatList, example:
```javascript
      <FlatList
        inverted
        horizontal
        style={{
          transform: [
            {scaleY: -1},
            {scaleY: -2},
            {scaleY: -0.5},
            {translateY: 20},
            {translateY: -10},
            {skewX: '10deg'},
            {rotateX: '10deg'},
          ],
        }}
      />
```

<details>

<summary>Reproducrer</summary>

https://github.com/facebook/react-native/assets/104823336/28cfe607-43e8-4f80-bbfb-59085ae0f986

</details>

<details>

<summary>RN tester</summary>

https://github.com/facebook/react-native/assets/104823336/e00cd488-d98f-4ece-9cab-b8a7212acb04

</details>

Reviewed By: arushikesarwani94

Differential Revision: D56441112

Pulled By: realsoelynn

fbshipit-source-id: 82c47f6bcc1f25cfbbd55aedf9652052bb86cf47
@realsoelynn
Copy link
Contributor

PR is merged. 3753b7a

Thanks everyone for your contribution 🥳

@cortinico cortinico added the Resolution: Fixed A PR that fixes this issue has been merged. label Jun 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: FlatList Issue: Author Provided Repro This issue can be reproduced in Snack or an attached project. p: Software Mansion Partner: Software Mansion Partner Resolution: Fixed A PR that fixes this issue has been merged. Type: New Architecture Issues and PRs related to new architecture (Fabric/Turbo Modules)
Projects
None yet
Development

No branches or pull requests

6 participants