Stylianos Gakis
08/30/2023, 10:32 AMModifier.windowInsetsPadding
nor Modifier.windowInsetsTopHeight
and the equivalents?
My use case is that I got a layout where for one of the items, I want the contentPadding: PaddingValues
parameter that it takes to respect insets, but doing something like PaddingValues(horizontal = 16.dp) + WindowInsets.safeDrawing.asPaddingValues()
means that it simply gets the insets even if they are consumed, since that’s how asPaddingValues
works.
From what I can tell, this functionality hooked together though some ModifierLocals which modifiers like windowInsetsTopHeight
respect by being ModifierLocalConsumer
themselves, so I don’t see a good entrypoint for my code to get the benefits of the existing functionality there.
Is there some way for me to get access to it in a reasonable non-hacky way since ModifierLocalConsumedWindowInsets
is internal in the foundation compose package?Stylianos Gakis
08/30/2023, 10:42 AMModifier
with the current APIs?
And if not, for my use case regarding using non-consumed insets for contentPadding
of a composable, is there something else I can do?Alex Vanyo
08/30/2023, 5:02 PMModifier.onConsumedWindowInsetsChanged
, which allows pulling out the consumed insets and using that in measurement or layout.Stylianos Gakis
08/30/2023, 10:03 PMvar consumedWindowInsets by remember { mutableStateOf(WindowInsets(0.dp)) }
MyComposable(
contentPadding = PaddingValues(horizontal = 16.dp) + WindowInsets.safeDrawing.exclude(consumedWindowInsets).only(WindowInsetsSides.Horizontal).asPaddingValues(),
modifier = Modifier.onConsumedWindowInsetsChanged { consumedWindowInsets = it },
)
I guess that this means that for the first composition I will be wrongly assuming that the consumed window insets are 0.dp, since I need to initialize it with something until the lambda runs for the first time. But it works!! which is the important bit here.
I was looking here https://developer.android.com/jetpack/compose/layouts/insets#padding-modifiers for a solution to my issue, but I couldn’t find anything. Is this function mentioned anywhere else which I may have missed? I would love to read more about it to make sure I am using it correctly too if any such docs exist.Timo Drick
09/19/2023, 2:39 PM