Bradleycorn
11/19/2025, 6:19 PM@Composable
fun ImmersiveContent() {
val view = LocalView.current
DisposableEffect(Unit) {
val window = (view.context as? Activity)?.window ?: return@DisposableEffect onDispose {}
val insetsController = WindowCompat.getInsetsController(window, view)
// Enable immersive mode
insetsController.apply {
hide(WindowInsetsCompat.Type.systemBars())
systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
}
// Restore when composable leaves
onDispose {
insetsController.show(WindowInsetsCompat.Type.systemBars())
}
}
// Your content here
}Ian Lake
11/19/2025, 6:29 PMAnimatedContent / NavDisplay / etc since the new screen will enter composition (its DisposableEffect starts) first, then the old screen will leave composition (calling its onDispose), which leaves you in a non-immersive stateIan Lake
11/19/2025, 6:30 PMIan Lake
11/19/2025, 6:33 PMDisposableEffect to add a counter when it enters and decrement the counter when it is disposed)Ian Lake
11/19/2025, 6:34 PMLocalActivity instead of casting your context, the insets stuff looks fineStylianos Gakis
11/19/2025, 6:42 PMBradleycorn
11/19/2025, 7:09 PM