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

fix(Android): going back on fabric with nested list #2383

Merged
merged 10 commits into from
Oct 9, 2024

Conversation

alduzy
Copy link
Member

@alduzy alduzy commented Oct 3, 2024

Description

This PR intents to fix crash happening on Android (fabric) when navigating back from a screen with nested list.

Before

The crash happens whenever the nested list is visible on the screen, as shown below:

Screenshot 2024-10-03 at 16 12 16 Screenshot 2024-10-03 at 16 12 25 Screenshot 2024-10-03 at 16 12 34 Screenshot 2024-10-03 at 16 12 40 Screenshot 2024-10-03 at 16 12 47

After

Screen.Recording.2024-10-08.at.13.58.22.mov

Nested lists are rendered as ViewGroups, thus the check for ReactScrollView fails. This PR fixes the issue by checking wether the view is an indirect child of a ScrollView with removeClippedSubviews enabled.

Fixes: #2341

Changes

  • added isInsideScrollViewWithRemoveClippedSubviews check to startTransitionRecursive
  • modified Test2282.tsx repro

Test code and steps to reproduce

  • use Test2282.tsx repro

Checklist

  • Included code example that can be used to test this change
  • Ensured that CI passes

@alduzy alduzy marked this pull request as ready for review October 8, 2024 12:06
@alduzy alduzy changed the title [WIP] fix(Android): going back on fabric with nested list fix(Android): going back on fabric with nested list Oct 8, 2024
Copy link
Member

@WoLewicki WoLewicki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic keeps on growing and I am not happy about it at all. But until we find better way of handling it, I think we have to try and fix those edge cases.

Copy link
Member

@kkafar kkafar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really don't like the idea of iterating up the whole tree for each child for each transition, but I guess that is better than crashing 🤷🏻‍♂️

We should add a comment above this function that it serves purposes of a workaround, refer to the startTransitionRecursive function and link this PR.

Also: do we actually know what changed that this started crashing (maybe in react-native)? Because it looks like the root cause of the issue is on react-native side. The issue reporter of #2341 noted that this happens since 0.75 onwards. What has changed? @WoLewicki do you have some context?

return false
}
var parentView = child.parent
while (parentView is ViewGroup && parentView !is ScreenStack) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be enough to check for Screen, right? Screen will be direct descendant of ScreenStack and we don't want to look further up. Am I right here?

Suggested change
while (parentView is ViewGroup && parentView !is ScreenStack) {
while (parentView is ViewGroup && parentView !is Screen) {

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The loop actually finishes quicker with this check for ScreenStack. It's because the ActionMenuView goes through the loop as well and there's no Screen between it and the ScreenStack. I didn't want to add yet another check for that.

android/src/main/java/com/swmansion/rnscreens/Screen.kt Outdated Show resolved Hide resolved
@WoLewicki
Copy link
Member

What has changed? @WoLewicki do you have some context?

Nope, but would be nice to find out what changed and maybe iterate on it to handle it in core instead.

@alduzy alduzy requested a review from kkafar October 8, 2024 15:48
Copy link
Member

@kkafar kkafar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we're good. Thank you!

@alduzy alduzy merged commit b67af86 into main Oct 9, 2024
4 checks passed
@alduzy alduzy deleted the @alduzy/fabric-going-back-with-nested-list branch October 9, 2024 07:57
ja1ns pushed a commit to WiseOwlTech/react-native-screens that referenced this pull request Oct 9, 2024
…#2383)

## Description

This PR intents to fix crash happening on Android (fabric) when
navigating back from a screen with nested list.

### Before 
The crash happens whenever the nested list is visible on the screen, as
shown below:

| ✅  | ❌ | ❌ | ❌  | ✅  |
|----------|----------|----------|----------|----------|
| <img width="247" alt="Screenshot 2024-10-03 at 16 12 16"
src="https://github.com/user-attachments/assets/55f36653-9451-48a1-b4fc-9d419622fe2b">
| <img width="247" alt="Screenshot 2024-10-03 at 16 12 25"
src="https://github.com/user-attachments/assets/5cc1af46-4418-40de-9391-6dc5168e08af">
| <img width="247" alt="Screenshot 2024-10-03 at 16 12 34"
src="https://github.com/user-attachments/assets/d2ec614a-fbeb-4717-8aeb-328e3a890cd6">
| <img width="247" alt="Screenshot 2024-10-03 at 16 12 40"
src="https://github.com/user-attachments/assets/5d634fbd-45c9-4612-9dcf-25cf8b9295a0">
| <img width="247" alt="Screenshot 2024-10-03 at 16 12 47"
src="https://github.com/user-attachments/assets/0881dd80-ff98-4ba2-992e-933d549eed19">
|

### After


https://github.com/user-attachments/assets/fb36d030-ef53-493d-a8cc-38be670ee504

Nested lists are rendered as ViewGroups, thus the check for
ReactScrollView fails. This PR fixes the issue by checking wether the
view is an indirect child of a ScrollView with
[removeClippedSubviews](https://reactnative.dev/docs/optimizing-flatlist-configuration#removeclippedsubviews)
enabled.

Fixes: software-mansion#2341

## Changes

- added `isInsideScrollViewWithRemoveClippedSubviews` check to
`startTransitionRecursive`
- modified `Test2282.tsx` repro

<!--

## Screenshots / GIFs

Here you can add screenshots / GIFs documenting your change.

You can add before / after section if you're changing some behavior.

### Before

### After

-->

## Test code and steps to reproduce

- use `Test2282.tsx` repro

## Checklist

- [x] Included code example that can be used to test this change
- [x] Ensured that CI passes
alduzy added a commit that referenced this pull request Oct 14, 2024
## Description

This PR handles yet another case for going back on fabric. In the
previous one
(#2383) I
omitted a case where a horizontal list is simply rendered w/o being
nested in any other list!

Fixes #2341 

## Changes

- updated `Test2292.tsx` repro
- handle `parentView is ReactHorizontalScrollView`

<!--

## Screenshots / GIFs

Here you can add screenshots / GIFs documenting your change.

You can add before / after section if you're changing some behavior.

### Before

### After

-->

## Test code and steps to reproduce

- use `Test2282.tsx` repro

## Checklist

- [x] Included code example that can be used to test this change
- [x] Ensured that CI passes
kkafar pushed a commit that referenced this pull request Oct 25, 2024
This PR intents to fix crash happening on Android (fabric) when
navigating back from a screen with nested list.

The crash happens whenever the nested list is visible on the screen, as
shown below:

| ✅  | ❌ | ❌ | ❌  | ✅  |
|----------|----------|----------|----------|----------|
| <img width="247" alt="Screenshot 2024-10-03 at 16 12 16"
src="https://github.com/user-attachments/assets/55f36653-9451-48a1-b4fc-9d419622fe2b">
| <img width="247" alt="Screenshot 2024-10-03 at 16 12 25"
src="https://github.com/user-attachments/assets/5cc1af46-4418-40de-9391-6dc5168e08af">
| <img width="247" alt="Screenshot 2024-10-03 at 16 12 34"
src="https://github.com/user-attachments/assets/d2ec614a-fbeb-4717-8aeb-328e3a890cd6">
| <img width="247" alt="Screenshot 2024-10-03 at 16 12 40"
src="https://github.com/user-attachments/assets/5d634fbd-45c9-4612-9dcf-25cf8b9295a0">
| <img width="247" alt="Screenshot 2024-10-03 at 16 12 47"
src="https://github.com/user-attachments/assets/0881dd80-ff98-4ba2-992e-933d549eed19">
|

https://github.com/user-attachments/assets/fb36d030-ef53-493d-a8cc-38be670ee504

Nested lists are rendered as ViewGroups, thus the check for
ReactScrollView fails. This PR fixes the issue by checking wether the
view is an indirect child of a ScrollView with
[removeClippedSubviews](https://reactnative.dev/docs/optimizing-flatlist-configuration#removeclippedsubviews)
enabled.

Fixes: #2341

- added `isInsideScrollViewWithRemoveClippedSubviews` check to
`startTransitionRecursive`
- modified `Test2282.tsx` repro

<!--

Here you can add screenshots / GIFs documenting your change.

You can add before / after section if you're changing some behavior.

-->

- use `Test2282.tsx` repro

- [x] Included code example that can be used to test this change
- [x] Ensured that CI passes

(cherry picked from commit b67af86)
kkafar pushed a commit that referenced this pull request Oct 25, 2024
## Description

This PR handles yet another case for going back on fabric. In the
previous one
(#2383) I
omitted a case where a horizontal list is simply rendered w/o being
nested in any other list!

Fixes #2341

## Changes

- updated `Test2292.tsx` repro
- handle `parentView is ReactHorizontalScrollView`

<!--

## Screenshots / GIFs

Here you can add screenshots / GIFs documenting your change.

You can add before / after section if you're changing some behavior.

### Before

### After

-->

## Test code and steps to reproduce

- use `Test2282.tsx` repro

## Checklist

- [x] Included code example that can be used to test this change
- [x] Ensured that CI passes

(cherry picked from commit d40e108)
kkafar added a commit that referenced this pull request Nov 15, 2024
## Description

This PR intents to fix going back on fabric issue when using a `View`
with
[removeClippedSubviews](https://reactnative.dev/docs/view#removeclippedsubviews)
prop set to true.

Previous bug fixes addressed this issue primarily for FlatLists, where
it's set to true by default on Android. See
#2383.

Additionally, this PR greatly improves the performance of
`startTransitionRecursive` as it does not climb up the tree in search
for a parent with `removeClippedSubview` set to true anymore.

Fixes #2491 .

## Changes

- removed redundant code
- updated `Test2282.tsx` repro

<!--

## Screenshots / GIFs

Here you can add screenshots / GIFs documenting your change.

You can add before / after section if you're changing some behavior.

### Before

### After

-->

## Test code and steps to reproduce

- use `Test2282.tsx` repro

## Checklist

- [x] Included code example that can be used to test this change
- [x] Ensured that CI passes

---------

Co-authored-by: Kacper Kafara <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Android RN 0.75.3, app crashes when returning to the previous screen
3 participants