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

Android app crash when navigate back if i use FlashList: Unhandled SoftException com.facebook.react.bridge.AssertionException: Expected to run on UI thread! #2530

Open
duongnguyen17 opened this issue Nov 21, 2024 · 19 comments · May be fixed by #2532
Labels
Platform: Android This issue is specific to Android Repro provided A reproduction with a snack or repo is provided

Comments

@duongnguyen17
Copy link

Description

My Android app crash when i navigate back from a screen use flash list.
Android studio log error:
Unhandled SoftException
com.facebook.react.bridge.AssertionException: Expected to run on UI thread!
at com.facebook.react.bridge.SoftAssertions.assertCondition(SoftAssertions.kt:37)
at com.facebook.react.bridge.UiThreadUtil.assertOnUiThread(UiThreadUtil.java:46)
at com.facebook.react.views.view.ReactViewGroup.handleAddView(ReactViewGroup.java:570)
at com.facebook.react.views.view.ReactViewGroup.addView(ReactViewGroup.java:607)
at android.view.ViewGroup.addView(ViewGroup.java:5025)
at android.view.ViewGroup.addView(ViewGroup.java:4997)
at com.swmansion.rnscreens.Screen.startTransitionRecursive(Screen.kt:412)
at com.swmansion.rnscreens.Screen.startTransitionRecursive(Screen.kt:415)
at com.swmansion.rnscreens.Screen.startTransitionRecursive(Screen.kt:415)
at com.swmansion.rnscreens.Screen.startTransitionRecursive(Screen.kt:415)
at com.swmansion.rnscreens.Screen.startTransitionRecursive(Screen.kt:415)
at com.swmansion.rnscreens.Screen.startTransitionRecursive(Screen.kt:415)
at com.swmansion.rnscreens.Screen.startTransitionRecursive(Screen.kt:415)
at com.swmansion.rnscreens.Screen.startTransitionRecursive(Screen.kt:415)
at com.swmansion.rnscreens.Screen.startTransitionRecursive(Screen.kt:415)
at com.swmansion.rnscreens.Screen.startTransitionRecursive(Screen.kt:415)
at com.swmansion.rnscreens.Screen.startTransitionRecursive(Screen.kt:415)
at com.swmansion.rnscreens.Screen.startRemovalTransition(Screen.kt:380)
at com.swmansion.rnscreens.NativeProxy.notifyScreenRemoved(NativeProxy.kt:48)
at com.facebook.jni.NativeRunnable.run(Native Method)
at android.os.Handler.handleCallback(Handler.java:959)
at android.os.Handler.dispatchMessage(Handler.java:100)
at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
at android.os.Looper.loopOnce(Looper.java:232)
at android.os.Looper.loop(Looper.java:317)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl.lambda$startNewBackgroundThread$2(MessageQueueThreadImpl.java:217)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$$ExternalSyntheticLambda1.run(D8$$SyntheticClass:0)
at java.lang.Thread.run(Thread.java:1012)

flashlist.webm

Steps to reproduce

  1. Press "Go to Details" button
  2. At Detail screen, navigate back

Snack or a link to a repository

https://github.com/duongnguyen17/pager-vew-demo

Screens version

4.2.0

React Native version

0.76.2

Platforms

Android

JavaScript runtime

Hermes

Workflow

None

Architecture

Fabric (New Architecture)

Build type

Debug mode

Device

Android emulator

Device model

No response

Acknowledgements

Yes

@github-actions github-actions bot added Repro provided A reproduction with a snack or repo is provided Platform: Android This issue is specific to Android labels Nov 21, 2024
@kkafar
Copy link
Member

kkafar commented Nov 21, 2024

Is that a crash or only soft exception is logged?

@shankarRxo
Copy link

Facing same issue
Unhandled SoftException com.facebook.react.bridge.AssertionException: Expected to run on UI thread!

@duongnguyen17
Copy link
Author

Is that a crash or only soft exception is logged?
That is a crash

@kkafar
Copy link
Member

kkafar commented Nov 21, 2024

Okay, I've opened the fix in #2532 - if anyone would confirm that it fixes the issue I would be grateful

@kkafar
Copy link
Member

kkafar commented Nov 21, 2024

Once I get confirmation I'll be able to release this

@shankarRxo
Copy link

Okay, I've opened the fix in #2532 - if anyone would confirm that it fixes the issue I would be grateful

Facing another issue

@kkafar
Copy link
Member

kkafar commented Nov 21, 2024

@shankarRxo namely? :D

@DrZoidberg09
Copy link

Almost the same happens on iOS. It does not completely crash, but the FlashList screen is distorted and you cannot press anything anymore.

See here:

callstack/react-native-pager-view#917

Not sure if it comes from pager view, screens or both.

@akylbek-hostaways
Copy link

akylbek-hostaways commented Nov 21, 2024

@kkafar I also have similar issue, but I'm using FlatList.
Stack trace from sentry:

android.widget.AdapterView in addView at line 489
com.swmansion.rnscreens.Screen in l at line 87
com.swmansion.rnscreens.Screen in l at line 95
11
com.swmansion.rnscreens.Screen in k at line 8
com.swmansion.rnscreens.ScreenStackViewManager in prepareOutTransition at line 3
com.swmansion.rnscreens.ScreenStackViewManager in removeViewAt at line 4
com.swmansion.rnscreens.ScreenStackViewManager in removeViewAt at line 2
com.facebook.react.uimanager.NativeViewHierarchyManager in manageChildren at line 149
com.swmansion.reanimated.layoutReanimation.ReanimatedNativeHierarchyManager in manageChildren at line 8
com.facebook.react.uimanager.UIViewOperationQueue$ManageChildrenOperation in execute at line 15
com.facebook.react.uimanager.UIViewOperationQueue$1 in run at line 145
com.facebook.react.uimanager.UIViewOperationQueue in flushPendingBatches at line 54
com.facebook.react.uimanager.UIViewOperationQueue in w at line 1
com.facebook.react.uimanager.UIViewOperationQueue$DispatchUIFrameCallback in doFrameGuarded at line 32
com.facebook.react.uimanager.GuardedFrameCallback in doFrame at line 1
com.facebook.react.modules.core.ReactChoreographer$1 in doFrame at line 47
android.view.Choreographer$CallbackRecord in run at line 1404
android.view.Choreographer$CallbackRecord in run at line 1415
android.view.Choreographer in doCallbacks at line 1015
android.view.Choreographer in doFrame at line 941
android.view.Choreographer$FrameDisplayEventReceiver in run at line 1389
android.os.Handler in handleCallback at line 959
android.os.Handler in dispatchMessage at line 100
android.os.Looper in loopOnce at line 232
android.os.Looper in loop at line 317
android.app.ActivityThread in main at line 8592
java.lang.reflect.Method in invoke
com.android.internal.os.RuntimeInit$MethodAndArgsCaller in run at line 580
com.android.internal.os.ZygoteInit in main at line 878

Screenshot_1732201561

"react-native-screens": "^4.2.0", "react-native": "^0.75.4", newArchEnabled=false

@duongnguyen17
Copy link
Author

duongnguyen17 commented Nov 21, 2024

Okay, I've opened the fix in #2532 - if anyone would confirm that it fixes the issue I would be grateful

The issue has been fixed but i got an other issue make my android app crash:

FATAL EXCEPTION: main
Process: com.awesomeproject, PID: 10025
java.lang.IllegalStateException: CellRendererComponent outer view should always be CellContainer. Learn more here: https://shopify.github.io/flash-list/docs/usage#cellrenderercomponent.
at com.shopify.reactnative.flash_list.AutoLayoutView.fixLayout(AutoLayoutView.kt:66)
at com.shopify.reactnative.flash_list.AutoLayoutView.dispatchDraw(AutoLayoutView.kt:32)
at android.view.View.updateDisplayListIfDirty(View.java:23683)
at android.view.View.draw(View.java:24573)
at android.view.ViewGroup.drawChild(ViewGroup.java:4537)
at com.facebook.react.views.view.ReactViewGroup.drawChild(ReactViewGroup.java:1029)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4298)
at com.facebook.react.views.view.ReactViewGroup.dispatchDraw(ReactViewGroup.java:980)
at android.view.View.updateDisplayListIfDirty(View.java:23683)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4521)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4494)
at android.view.View.updateDisplayListIfDirty(View.java:23646)
at android.view.View.draw(View.java:24573)
at android.view.ViewGroup.drawChild(ViewGroup.java:4537)
at com.facebook.react.views.view.ReactViewGroup.drawChild(ReactViewGroup.java:1029)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4298)
at com.facebook.react.views.view.ReactViewGroup.dispatchDraw(ReactViewGroup.java:980)
at android.view.View.updateDisplayListIfDirty(View.java:23683)
at android.view.View.draw(View.java:24573)
at android.view.ViewGroup.drawChild(ViewGroup.java:4537)
at com.facebook.react.views.view.ReactViewGroup.drawChild(ReactViewGroup.java:1029)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4298)
at com.facebook.react.views.view.ReactViewGroup.dispatchDraw(ReactViewGroup.java:980)
at android.view.View.draw(View.java:24845)
at com.facebook.react.views.view.ReactViewGroup.draw(ReactViewGroup.java:970)
at android.view.View.updateDisplayListIfDirty(View.java:23692)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4521)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4494)
at android.view.View.updateDisplayListIfDirty(View.java:23646)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4521)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4494)
at android.view.View.updateDisplayListIfDirty(View.java:23646)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4521)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4494)
at android.view.View.updateDisplayListIfDirty(View.java:23646)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4521)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4494)
at android.view.View.updateDisplayListIfDirty(View.java:23646)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4521)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4494)
at android.view.View.updateDisplayListIfDirty(View.java:23646)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4521)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4494)
at android.view.View.updateDisplayListIfDirty(View.java:23646)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4521)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4494)
at android.view.View.updateDisplayListIfDirty(View.java:23646)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4521)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4494)
at android.view.View.updateDisplayListIfDirty(View.java:23646)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4521)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4494)
at android.view.View.updateDisplayListIfDirty(View.java:23646)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4521)

Should I report this bug to FlashList?
issue

@akylbek-hostaways
Copy link

@kkafar I also have similar issue, but I'm using FlatList. Stack trace from sentry:

android.widget.AdapterView in addView at line 489
com.swmansion.rnscreens.Screen in l at line 87
com.swmansion.rnscreens.Screen in l at line 95
11
com.swmansion.rnscreens.Screen in k at line 8
com.swmansion.rnscreens.ScreenStackViewManager in prepareOutTransition at line 3
com.swmansion.rnscreens.ScreenStackViewManager in removeViewAt at line 4
com.swmansion.rnscreens.ScreenStackViewManager in removeViewAt at line 2
com.facebook.react.uimanager.NativeViewHierarchyManager in manageChildren at line 149
com.swmansion.reanimated.layoutReanimation.ReanimatedNativeHierarchyManager in manageChildren at line 8
com.facebook.react.uimanager.UIViewOperationQueue$ManageChildrenOperation in execute at line 15
com.facebook.react.uimanager.UIViewOperationQueue$1 in run at line 145
com.facebook.react.uimanager.UIViewOperationQueue in flushPendingBatches at line 54
com.facebook.react.uimanager.UIViewOperationQueue in w at line 1
com.facebook.react.uimanager.UIViewOperationQueue$DispatchUIFrameCallback in doFrameGuarded at line 32
com.facebook.react.uimanager.GuardedFrameCallback in doFrame at line 1
com.facebook.react.modules.core.ReactChoreographer$1 in doFrame at line 47
android.view.Choreographer$CallbackRecord in run at line 1404
android.view.Choreographer$CallbackRecord in run at line 1415
android.view.Choreographer in doCallbacks at line 1015
android.view.Choreographer in doFrame at line 941
android.view.Choreographer$FrameDisplayEventReceiver in run at line 1389
android.os.Handler in handleCallback at line 959
android.os.Handler in dispatchMessage at line 100
android.os.Looper in loopOnce at line 232
android.os.Looper in loop at line 317
android.app.ActivityThread in main at line 8592
java.lang.reflect.Method in invoke
com.android.internal.os.RuntimeInit$MethodAndArgsCaller in run at line 580
com.android.internal.os.ZygoteInit in main at line 878

Screenshot_1732201561

"react-native-screens": "^4.2.0", "react-native": "^0.75.4", newArchEnabled=false

Update: I tried to using FlashList, and I don't have this issue with your fix

@kkafar
Copy link
Member

kkafar commented Nov 21, 2024

@duongnguyen17 This might be still related to react-native-screens, namely it might be caused by the workaround. But I won't be able to fix this here, we need the changes to land in react-native core.

The best thing I can suggest for you right now is to build react native from source and apply this patch: facebook/react-native#47634
and comment out this code in react-native-screens:

if (child is ReactClippingViewGroup &&
child.removeClippedSubviews &&
child !is ReactScrollView &&
child !is ReactHorizontalScrollView
) {
// We need to workaround the issue until our changes land in core.
// Some views do not accept any children or have set amount and they throw
// when we want to brute-forcefully manipulate that.
// Is this ugly? Very. Do we have better option before changes land in core?
// I'm not aware of any.
try {
for (j in 0 until child.childCount) {
child.addView(View(context))
}
} catch (_: Exception) {
}
}
:/

@akylbek-hostaways
Copy link

@kkafar Could my problem with FlatList be related to react-native bug?

@duongnguyen17
Copy link
Author

@duongnguyen17 This might be still related to react-native-screens, namely it might be caused by the workaround. But I won't be able to fix this here, we need the changes to land in react-native core.

The best thing I can suggest for you right now is to build react native from source and apply this patch: facebook/react-native#47634 and comment out this code in react-native-screens:

if (child is ReactClippingViewGroup &&
child.removeClippedSubviews &&
child !is ReactScrollView &&
child !is ReactHorizontalScrollView
) {
// We need to workaround the issue until our changes land in core.
// Some views do not accept any children or have set amount and they throw
// when we want to brute-forcefully manipulate that.
// Is this ugly? Very. Do we have better option before changes land in core?
// I'm not aware of any.
try {
for (j in 0 until child.childCount) {
child.addView(View(context))
}
} catch (_: Exception) {
}
}

:/

@kkafar Thank you very much for your help 😁
it work!

@kkafar
Copy link
Member

kkafar commented Nov 21, 2024

@akylbek-hostaways I believe this is the same case. Your code crashes because of our workaround in react-native-screens. We have to add this workaround, because there is other inherent issue in react-native - it does not handle cases where some views might be a part of Android Transition. We're working on it currently, but it might take even few weeks.

The best way to go @akylbek-hostaways right now is with my suggestion above ([link])(#2530 (comment))

@kkafar
Copy link
Member

kkafar commented Nov 21, 2024

@duongnguyen17 glad to hear that. We'll try to sort these things up, so that patches are not required to make things work

@duongnguyen17
Copy link
Author

duongnguyen17 commented Nov 21, 2024

@kkafar but if i comment the code you mentioned, i can't fix the issue with the react-native-pager-view
so i think i will wait for the next version. hihi 😁

@duongnguyen17
Copy link
Author

@kkafar you are my hope 😇

@shankarRxo
Copy link

@shankarRxo namely? :D

java.lang.IllegalStateException: CellRendererComponent outer view should always be CellContainer. Learn more here: https://shopify.github.io/flash-list/docs/usage#cellrenderercomponent.

related to flashList

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Platform: Android This issue is specific to Android Repro provided A reproduction with a snack or repo is provided
Projects
None yet
5 participants