Is it somehow possible to override the provided `WindowInsets` for a platform? Id like to mimic the ...
z
Is it somehow possible to override the provided
WindowInsets
for a platform? Id like to mimic the system UI of Android on Desktop for some of my screenshots.
s
Iโ€™d say try to provide a fake inset number for the
ModifierLocalConsumedWindowInsets
which the inset modifiers seem to be using, but it looks like thatโ€™s internal in the foundation.layout library. But maybe I am missing something and you can create something that is a
ModifierLocalProvider<WindowInsets>
and provide your own insets in there without having to access the internal value itself. Maybe can get some inspiration from here https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/[โ€ฆ]PaddingModifier&amp;ss=androidx%2Fplatform%2Fframeworks%2Fsupport and provide just a hardcoded WindowInsets value? ๐Ÿ‘€ I have no idea how modifier locals work and how similar they are to composition locals, but I assume they work the same way, propagating down the tree of your composables
z
Ahh, thank you! I wouldnt have thought of that myself. Will try it out later today and share the results ๐Ÿ˜ƒ
s
Do tell if it works (or doesnโ€™t), I am curious ๐Ÿ‘€ ๐Ÿ˜…
z
The TL;DR; is that I dont think I can make that work because the key for it is marked
internal
. BUT, I dont think I fully understand how it all mangles together (sorry, I dont have time to look deeper into it right now ๐Ÿ˜…). I can for example use
Modifier.windowInsetsPadding(bottom=48.dp)
which under the hood uses said key to provide some insets, but I think my scaffold eats that up since its just generic insets, and as such not excluded in the scaffold logic? Whereas I would need to specifically use
WindowInsets.navigationBar
in order for it to pass through to my NavigationBar, etc. Dunno if that makes sense, fwiw the desktop logic:
actual val WindowInsets.Companion.navigationBars: WindowInsets get() = ZeroInsets
is what Im trying to override, so that my NavigationBar actually has that extra padding, instead of it being added to my entire layout (=system navigation bar doesnt have same color as in app NavigationBar).
s
It was worth a try ๐Ÿ˜…
z
Oh well ๐Ÿ˜„ I wonder if I can make it work with reflection? This is just used in tests, so performance isnt that big of a deal ๐Ÿ™‚