From fb622871ff4738ce853ee04c1057c345c81c2c1c Mon Sep 17 00:00:00 2001 From: Jay Ohms Date: Thu, 28 Apr 2022 15:04:28 -0400 Subject: [PATCH] Post to the message queue when resetting a NavHostFragment and waiting for it to complete. This works around a bug seen in Basecamp where resetting the NavHostFragment and then recreating the Activity to update its theme would cause the app to crash. --- .../hotwire/turbo/session/TurboSessionNavHostFragment.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/turbo/src/main/kotlin/dev/hotwire/turbo/session/TurboSessionNavHostFragment.kt b/turbo/src/main/kotlin/dev/hotwire/turbo/session/TurboSessionNavHostFragment.kt index 2385ac2e..1ea5b1d2 100644 --- a/turbo/src/main/kotlin/dev/hotwire/turbo/session/TurboSessionNavHostFragment.kt +++ b/turbo/src/main/kotlin/dev/hotwire/turbo/session/TurboSessionNavHostFragment.kt @@ -47,7 +47,12 @@ abstract class TurboSessionNavHostFragment : NavHostFragment() { currentNavDestination.clearBackStack { session.reset() initControllerGraph() - onReset() + + if (view == null) { + onReset() + } else { + requireView().post { onReset() } + } } } }