I have a problem with window insets (being always 0). Nothing works, neither `WindowInsets.navigatio...
s
I have a problem with window insets (being always 0). Nothing works, neither
WindowInsets.navigationBars.getBottom(LocalDensity.current)
nor the
navigationBarsPadding()
-modifier. This occurs when I have composable inside a
ComposeView
which itself is inside an
AndroidView
. Maybe this double injection screws up the insets? This is used as a way to show a
Fragment
inside an
Activity
which only uses
ComponentActivity.setContent()
to get into compose and everything else is handled inside compose only (e.g. navigating to different screens and some of those are simple composables but some are legacy fragments)
s
If you do put the same window insets code right before you do this loop of going from
compose -> fragment -> compose
so by doing
compose -> Get insets here -> fragment -> compose
Do you get the right insets? If I were you I’d try to do a minimal repro of this, to see that it’s not me breaking this somehow, or if it’s that this doesn’t work at all anyway. Sorry for pinging you @Alex Vanyo but if there’s someone who might know if this should work normally I think it would be you, so would be great if you could help out here 😊
s
Most likely composition locals are not propagated through ComposeView here Consider calling setParentCompositionContext on init with context of outer composition
a
You may also need to set
ComposeView.consumeWindowInsets
to
false
for your outermost
ComposeView
, to allow inset information to propagate to contained views: https://developer.android.com/reference/kotlin/androidx/compose/ui/platform/ComposeView#(androidx.compose.ui.platfor[…]seView).consumeWindowInsets() There’s also a known limitation for consumption on the Compose side given by https://issuetracker.google.com/issues/243778587. I’m not sure if
setParentCompositionContext
covers modifier locals that insets use?
s
Ah, it is a modifier local, my bad then
s
Thank you for your great responses (learned a lot). I have solved my problem by simply checking if the fragment is using compose (only) or actually using the legacy view system and not adding an
AndroidView
if it doesn't 🙂
a
Please, android specific compise issues should be posted on #compose-android not #compose
1550 Views