wix / react-native-navigation

A complete native navigation solution for React Native
https://wix.github.io/react-native-navigation/
MIT License
13.04k stars 2.67k forks source link

TitleBarReactButtonView cannot be cast to com.facebook.react.views.view.ReactViewGroup #7382

Closed eliaslecomte closed 2 years ago

eliaslecomte commented 2 years ago

πŸ› Bug Report

We are seeing Sentry reports that our app crashes when closing a few screens. We are having a hard time reproducing it, but the stack trace is clear.

Stack trace

java.lang.ClassCastException: com.reactnativenavigation.views.stack.topbar.titlebar.TitleBarReactButtonView cannot be cast to com.facebook.react.views.view.ReactViewGroup
    at com.facebook.react.views.view.ReactClippingViewManager.getChildCount(ReactClippingViewManager.java:1)
    at com.facebook.react.uimanager.NativeViewHierarchyManager.dropView(NativeViewHierarchyManager.java:11)
    at com.facebook.react.uimanager.NativeViewHierarchyManager.removeRootView(NativeViewHierarchyManager.java:5)
    at com.facebook.react.uimanager.UIViewOperationQueue$RemoveRootViewOperation.execute(UIViewOperationQueue.java:1)
    at com.facebook.react.uimanager.UIViewOperationQueue$1.run(UIViewOperationQueue.java:18)
    at com.facebook.react.uimanager.UIViewOperationQueue.flushPendingBatches(UIViewOperationQueue.java:10)
    at com.facebook.react.uimanager.UIViewOperationQueue.access$2600(UIViewOperationQueue.java:1)
    at com.facebook.react.uimanager.UIViewOperationQueue$2.runGuarded(UIViewOperationQueue.java:1)
    at com.facebook.react.bridge.GuardedRunnable.run(GuardedRunnable.java:1)
    at android.os.Handler.handleCallback(Handler.java:938)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loopOnce(Looper.java:226)
    at android.os.Looper.loop(Looper.java:313)
    at android.app.ActivityThread.main(ActivityThread.java:8582)
    at java.lang.reflect.Method.invoke(Method.java)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:563)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1133)

To Reproduce

  1. Open multiple screens
  2. Use close or back button to close them all

Expected behavior

All the screens are closed and no cast exception happens.

Actual Behavior

A ClassCastException occurred causing the app to get terminated.

Your Environment

Are you willing to resolve this issue by submitting a Pull Request?

swabbass commented 2 years ago

Could not reproduce it, Can you try to upgrade to the latest navigation version 7.24.1, and see if still occur? maybe try to reproduce it in a minimal project or our playground?

eliaslecomte commented 2 years ago

Hi πŸ‘‹, we do keep our dependencies to date. So I do hope the error will eventually go away. I can't reproduce it myself, so I don't think that I can make a helpful reproduction.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you believe the issue is still relevant, please test on the latest version and report back. Thank you for your contributions.

zzorba commented 2 years ago

I'm seeing this issue as well, running react-native-navigation 7.25.1.

I kind of suspect it might be related to the use of gesture-handler or reanimated.

eliaslecomte commented 2 years ago

We also use those 2 dependencies.

swabbass commented 2 years ago

I think if we cannot reproduce it in an exclusive project where it contains only RNN, it is really hard to know why this flow happens, it could be another library like reanimated that manipulates the view hierarchy, but first, let's try to reproduce it, since we need a starting point to start diagnosis and analysis of what is really happening, and that is missing right know which make things ambiguous.

zzorba commented 2 years ago

So I encountered a somewhat similar crash when views were being popped on android, but instead of a cast error is manifested as a NullPointerException.

A pending fix fo react-native corrected the issue, but it seemed to only happen on my screens with top bar button components (vs button icons which work fine).

It’s a shot in the dark, but I’ll see if a sample project can show it today.

zzorba commented 2 years ago

So I'm not positive if this is the same crash or not, but I managed to make a minimal reproduction repo of a crash related to removing (popping) screens when BottomTabs + TopBarButtonComponents are being used: https://github.com/wix/react-native-navigation/issues/7435 Filed it as a separate issue since I am not positive it is the same root cause, despite being a similar symptom.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you believe the issue is still relevant, please test on the latest version and report back. Thank you for your contributions.

stale[bot] commented 2 years ago

The issue has been closed for inactivity.

haveneersrobin commented 2 years ago

This is still an issue in 7.25.1... Please reopen

haveneersrobin commented 2 years ago

@swabbass please re-open this issue :)

zzorba commented 2 years ago

This is still an issue on 7.28.0, could we please re-open it.

zzorba commented 2 years ago

As a test, I tried removing the use of (right) TopBarButtonComponents on pushed components and my crashes on Android are gone. I still have a custom TopBarComponent in the left position, but it is on a root screen (not one that was pushed + merged in), and I suspect that is the difference.

Still have never been able to make this happen on a simulator, but what was crashing hundreds of times per day now is 'fixed' by not using the feature, so I'm fairly confident this is the source of the problem.