Berkeli Alashov
05/21/2022, 5:24 AMbuildFeatures { compose true }
to existing android app's build.gradle.
When some screens are opened, everything works as expected. But when navigated away to another fragment and then back, fragment become uninitialized. uninitialized = as if fragment layouts were just inflated without any other fragment code. Adding breakpoints reveal that all lifecycle events happen (onCreate/View) and fragment code is run (ex, data from viewModel is set to views). Adding delayed navigateButton.performClick()
to onViewCreated works (i.e code to navigate to next fragment is run and navigates to next screen):
launchAndRepeatWithViewLifecycle {
launch {
button.setText("Navigating in 3 seconds...")
delay(3000)
button.performClick()
}
}
Above code changes the text of the button initially and navigates away. But when fragment is restored from backstack, the button text stays the same unchanged (whatever it was in xml) but performClick works.
It's really weird since the fragment is actually running when it looks like it's uninitialized and it only happens to some fragments.
Some more details:
It only starts happening when buildFeatures.compose=true
, just adding lib androidx.compose.ui:ui
doesn't have issue (compose still works when importing composables from other modules using ComposeView).
I have tried upgrading to latest versions (including alphas) of navigation, lifecycle, compose, activity/fragment-ktx
I couldn't reproduce this by using same library versions in minimal app..
LayoutInspector doesn't show double views or anything like that
Any help is appreciated.