Michael Marshall
11/15/2024, 5:31 PMWindowInsets
are going crazy, is anyone experiencing the same thing? 😵 Why are my Scaffold content padding and status bar insets so big?? Here's a debug point values snapshot
ScaffoldContentPadding = {PaddingValuesImpl@41561} PaddingValues(start=0.0.dp, top=105.454544.dp, end=0.0.dp, bottom=104.0.dp)
WindowInsets.safeContent = {UnionInsets@41563} (((systemBars(0, 290, 0, 66) ∪ ime(0, 0, 0, 0)) ∪ displayCutout(0, 136, 0, 0)) ∪ (((tappableElement(0, 136, 0, 0) ∪ mandatorySystemGestures(0, 169, 0, 88)) ∪ systemGestures(82, 169, 82, 88)) ∪ waterfall(left=0, top=0, right=0, bottom=0)))
WindowInsets.safeDrawing = {UnionInsets@41564} ((systemBars(0, 290, 0, 66) ∪ ime(0, 0, 0, 0)) ∪ displayCutout(0, 136, 0, 0))
WindowInsets.safeGestures = {UnionInsets@41565} (((tappableElement(0, 136, 0, 0) ∪ mandatorySystemGestures(0, 169, 0, 88)) ∪ systemGestures(82, 169, 82, 88)) ∪ waterfall(left=0, top=0, right=0, bottom=0))
Michael Marshall
11/15/2024, 5:35 PMNavHost
. I've set enableEdgeToEdge()
in my activity onCreate
.
Initially I was getting 0 for all WindowsInsets values on the screen Compose code, until I forced the configuration to update by rotating my Pixel 5 device from portrait to landscape (and back again). This seems like a bug?
Anyway, I somehow fixed that by forcing the insets to be fetched immediately:
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
installSplashScreen()
enableEdgeToEdge()
// We don't use any theme XML files, so we need to hide this here
actionBar?.hide()
setContent {
// Some buggy nonsense in insets going on. Without this (to shock em awake?) all insets are 0 until a configuration change...
WindowInsets.safeContent
MyTheme {
MainScreen()
}
}
}
}
But now I have the insets too big issue as above 🙃
My Compose version "1.7.5", but I've also tried it on "1.7.0".Stylianos Gakis
11/15/2024, 5:38 PMactionBar?.hide()
do there?
What is your root theme of your app? Why not do something like Theme.AppCompat.Light.NoActionBar
so that you get no action bar at all in the first place?Michael Marshall
11/15/2024, 5:40 PMStylianos Gakis
11/15/2024, 5:40 PMStylianos Gakis
11/15/2024, 5:41 PMI've attempted to remove all the theming XML files and use Compose only as far as I canSure, but you should still set some things in your xml. You can't get around that, compose is not initialized on the very first frames, like when the splash screen is showing for example
Stylianos Gakis
11/15/2024, 5:42 PMMichael Marshall
11/15/2024, 5:43 PMScaffold(
bottomBar = {
MyNavigationBar(
selectedTab = MainTab.ChatList,
selectTab = navigateToTab,
)
},
) { contentPadding ->
LazyColumn(
modifier = Modifier
.statusBarsPadding() // This adds the huge gap
.fillMaxSize(),
contentPadding = contentPadding.copy(top = 0.dp),
) {
// my list content is in here
}
}
Michael Marshall
11/15/2024, 5:44 PMMichael Marshall
11/15/2024, 6:29 PMStylianos Gakis
11/15/2024, 6:48 PMMichael Marshall
11/15/2024, 6:51 PMMichael Marshall
11/15/2024, 6:57 PMefemoney
11/16/2024, 1:33 PMTheme.xxx.NoActionBar
or some descendant 🙂.
Android has evolved a lot but there was/is a feature where System UI draws the “action bar” for your app. Obvsly that would go into insets if you had something like fitsSystemWindows
turned on (because the action bar is technically provided by the system)
For anyone else checking this out, to configure an android app (or particular activity) to handle insets for the best experience (as of Nov 2024) you need to:
• Set the application / specific activity theme to some xxx.NoActionBar
descendant
• Set android:windowSoftInputMode="adjustResize"
on the activity in the manifest
• On the activity, using androidx activity-ktx
, call enableEdgeToEdge(...)
• Within compose hierarchy, use the insets API.