windowInsetsTopHeight

Compose Modifier

Common
fun Modifier.windowInsetsTopHeight(insets: WindowInsets) =
    this.then(
        DerivedHeightModifier(
            insets,
            debugInspectorInfo {
                name = "insetsTopHeight"
                properties["insets"] = insets
            },
            topCalc,
        )
    )

Sets the height to that of insets at the top of the screen.

When used, the WindowInsets will respect the consumed insets from windowInsetsPadding and consumeWindowInsets, but won't consume any insets.

Code Examples

insetsTopHeightSample

fun insetsTopHeightSample() {
    class SampleActivity : ComponentActivity() {
        override fun onCreate(savedInstanceState: Bundle?) {
            WindowCompat.setDecorFitsSystemWindows(window, false)
            super.onCreate(savedInstanceState)
            setContent {
                Box(Modifier.fillMaxSize()) {
                    // Background for status bar at the top
                    Box(
                        Modifier.windowInsetsTopHeight(WindowInsets.statusBars)
                            .fillMaxWidth()
                            .align(Alignment.TopCenter)
                            .background(Color.Red)
                    )
                    // app content
                }
            }
        }
    }
}