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: do not add views on transition to ViewPager2 #2527

Closed
wants to merge 3 commits into from

Conversation

radko93
Copy link
Contributor

@radko93 radko93 commented Nov 20, 2024

Description

There is an issue in react-native-pager-view that happens when you unmount a screen with ViewPager2 in it. As you cannot add views to ViewPager2 directly. This change omits it. I can reproduce it on paper but Fabric seems also to be affected.

Fixes callstack/react-native-pager-view#906.

Changes

  • Fixes crash when transitioning with ViewPager2 mounted

Test code and steps to reproduce

The repro is linked in the original issue.

Checklist

@radko93
Copy link
Contributor Author

radko93 commented Nov 20, 2024

I also had an issue with expo-video crashing in the same scenario so I'm adding that to the PR as well.
telegram-cloud-photo-size-4-5904763039482234137-y

@kkafar
Copy link
Member

kkafar commented Nov 20, 2024

Hey, while this is good patch for your particular case we won't go this way.
I've opened a PR to core in order to fix the real issue cause there: facebook/react-native#47634.

Here I'll patch this in a bit different manner

@radko93
Copy link
Contributor Author

radko93 commented Nov 20, 2024

@kkafar thanks for making the effort for fixing the cause of the problem, much appreciated. I will of course leave it to your discretion, but I would argue that it will impact many developers before it lands in core and they manage to update. So while this is not ideal, as temporary measure it might work to fix issues with pager view and expo video. It's hard to narrow down this issue on Fabric because the stacktrace is not very clear there.

@kkafar
Copy link
Member

kkafar commented Nov 21, 2024

If you have capacity to patch your project with #2531 and let me know whether it resolves it issue it would be great.

kkafar added a commit that referenced this pull request Nov 21, 2024
…child (#2531)

## Description

Attempt to patch changes from
#2495. It
improved the situation in most of the cases
but caused crashes in cases where we tried to insert subviews into
viewgroups that have any kind of assertions on their child count, e.g.
`NestedScrollView` or `ViewPager`.

Fixes #2529
Supersedes #2527 

## Changes

In this PR I do two things:

* apply the workaround only to views that could actually have clipped
subviews
* catch any kind of exception thrown on view insertion; if one is thrown
we stop to add subviews for given child

## Test code and steps to reproduce

Test2282 works in both configurations (complex screen with nested
flatlists + my simple reproduction of the issue)

## Checklist

- [ ] Included code example that can be used to test this change
- [ ] Updated TS types
- [ ] Updated documentation: <!-- For adding new props to native-stack
-->
- [ ]
https://github.com/software-mansion/react-native-screens/blob/main/guides/GUIDE_FOR_LIBRARY_AUTHORS.md
- [ ]
https://github.com/software-mansion/react-native-screens/blob/main/native-stack/README.md
- [ ]
https://github.com/software-mansion/react-native-screens/blob/main/src/types.tsx
- [ ]
https://github.com/software-mansion/react-native-screens/blob/main/src/native-stack/types.tsx
- [ ] Ensured that CI passes
@kkafar
Copy link
Member

kkafar commented Nov 21, 2024

I'll close the PR as it should be superseded and the issue should be handled by #2531

Thank you for investigating this!

In case something still does not work for you let me know

@kkafar kkafar closed this Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants