-
Notifications
You must be signed in to change notification settings - Fork 428
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
Navigating back to a bottom tab route from a stack route that includes a PagerView causes the app to crash directly. #906
Comments
up for this, also experienced this issue with the new arch using RN 0.76.1 |
Yup, facing the same issue |
same issue |
@MrRefactor Can you check this error for us? |
I will check it |
this is a critical issue same here, can we downgrade react native (if yes which version) or any quick solution |
what version of react native and react-native-pager-view are you using? |
Hi all I found a solution and it's woking like charm look you have to follow one thing here : simply disable newArchEnabled=false in gradle properties, This is a problem with newArch |
"react": "18.3.1", But i though this is cause of newArch |
I can also see you used dependencies from my PR with bump to 76.1, did it work without disabling new arch? |
No without disabling PR it's not working, I am also looking into Your Kotlin Files, but didn't find any thing This is the error - java.lang.IllegalArgumentException: Scrapped or attached views may not be recycled. isScrap:false isAttached:true androidx.viewpager2.widget.ViewPager2$RecyclerViewImpl - This is from your side which is causing crash Unhandled SoftException com.facebook.react.bridge.AssertionException: Expected to run on UI thread! from - com.swmansion.rnscreens.Screen |
Same problem here with "react-native": "0.76.1" and "react-native-pager-view": "^6.5.0". I am using the new arc. |
@MrRefactor This is only issue of this library, Just checked with latest version of react native screen's new update, Please check this |
GitHub Issue: Fix for Incorrect View Removal in RecyclerDescription: After debugging this issue, I identified a possible cause and solution. The problem arises from the incorrect removal of a view during the recycling process. Specifically, the existing code does not ensure that the view is properly detached from its parent before being removed, which can lead to unexpected behavior, such as layout issues or white screens. Current Code: fun removeViewAt(parent: NestedScrollableHost, index: Int) {
val pager = getViewPager(parent)
val adapter = pager.adapter as ViewPagerAdapter?
// Remove the child view from the adapter
adapter?.removeChildAt(index)
// Force a layout refresh to ensure proper rendering
refreshViewChildrenLayout(pager)
} Issue with Current Code:
Proposed Solution: The updated code ensures:
fun removeViewAt(parent: NestedScrollableHost, index: Int) {
val pager = getViewPager(parent)
val adapter = pager.adapter as ViewPagerAdapter?
// Retrieve the child view at the specified index
val child = adapter?.getChildAt(index)
// Ensure the child is detached from its parent before removal
if (child != null && child.parent != null) {
(child.parent as? ViewGroup)?.removeView(child)
}
// Remove the child view from the adapter
adapter?.removeChildAt(index)
// Post a layout refresh to the ViewPager
pager.post {
pager.invalidate() // Force the view to redraw
pager.requestLayout() // Request a new layout pass
}
} Why This Works:
Next Steps:
|
I tested this solution in my application using a fork of the project, and it worked perfectly with these changes. The issues I was experiencing were resolved, and no further problems occurred. |
I will check it tomorrow, thanks for help |
Can confirm a complete crash on Android. However, on iOS it leads to a similar issue. If you move back from the stack route and then to the stack route again, you cannot press anything in the pager view. Additionally, if you go back once again, the whole screen is frozen. I dont know if that is related, however it is happening with the same screens as for Android, but with this behavior instead of a full crash. |
+1 This fix works for Android, but what's about iOS? Somebody know how can fix it? |
Please create separated issue for iOS, android merged in https://github.com/callstack/react-native-pager-view/releases/tag/v6.5.1 |
@MrRefactor i got an other issue when you fix this error: |
@MrRefactor Running into this too on |
Please provide repro repository. |
Thanks, @MrRefactor , This fixed my issue and running well on 0.76.1 with new arch |
here is demo repo https://github.com/duongnguyen17/pager-vew-demo |
I can also confirm the issue with ViewPager2 does not support direct child views. On paper app, no new architecture. |
I've opened a PR for |
@radko93 I have just tested ur PR on failing reproduction repo, its working fine. |
Environment
Platform
Android
Dependencies
"react-native-pager-view": "^6.4.1",
"@react-navigation/bottom-tabs": "^6.6.1",
"@react-navigation/native": "^6.1.18",
"@react-navigation/native-stack": "^6.11.0",
Description
When I nest an A-Screen in react-navigation/native-stack, which uses react-navigation/bottom-tabs for routing, in one of the tabs of A-One-screen, I can route to an external stack screen, which we'll call B screen. If B screen uses PagerView, the app crashes when navigating to 'A-Screen' with navigation.navigate('A-Screen'). However, if PagerView is removed, everything works fine.
test.mp4
The text was updated successfully, but these errors were encountered: