Compose Modifier

onConsumedWindowInsetsChanged

Calls block with the WindowInsets that have been consumed, either by consumeWindowInsets or one of the padding Modifiers, such as imePadding.

withConsumedInsetsSample

@OptIn(ExperimentalLayoutApi::class)
@Sampled
fun withConsumedInsetsSample() {
    class SampleActivity : ComponentActivity() {
        override fun onCreate(savedInstanceState: Bundle?) {
            WindowCompat.setDecorFitsSystemWindows(window, false)
            super.onCreate(savedInstanceState)
            setContent {
                val remainingInsets = remember { MutableWindowInsets() }
                val safeContent = WindowInsets.safeContent
                Box(
                    Modifier.navigationBarsPadding().onConsumedWindowInsetsChanged {
                        consumedWindowInsets ->
                        remainingInsets.insets = safeContent.exclude(consumedWindowInsets)
                    }
                ) {
                    // padding can be used without recomposition when insets change.
                    val padding = remainingInsets.asPaddingValues()
                    Box(Modifier.padding(padding))
                }
            }
        }
    }
}
Jetpack Compose beyond MaterialFree components, screens and templates for apps that don’t look like Google’s. Copy them into your app, or let your coding agent add them.Browse for free

Content updated: