From 068cee0278cf73192d1c9c2a2d843a2a6021732c Mon Sep 17 00:00:00 2001 From: Alex Vanyo Date: Thu, 2 May 2024 17:28:39 -0700 Subject: [PATCH] Add workaround for state loss bug Change-Id: I7ac4495c8e3ada419358688c61214c33c0d4040e --- .../samples/apps/nowinandroid/ui/NiaApp.kt | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/app/src/main/kotlin/com/google/samples/apps/nowinandroid/ui/NiaApp.kt b/app/src/main/kotlin/com/google/samples/apps/nowinandroid/ui/NiaApp.kt index 8cbabc247..4c8232a26 100644 --- a/app/src/main/kotlin/com/google/samples/apps/nowinandroid/ui/NiaApp.kt +++ b/app/src/main/kotlin/com/google/samples/apps/nowinandroid/ui/NiaApp.kt @@ -16,6 +16,7 @@ package com.google.samples.apps.nowinandroid.ui +import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.WindowInsets @@ -199,15 +200,7 @@ internal fun NiaApp( ) } - NiaNavHost( - appState = appState, - onShowSnackbar = { message, action -> - snackbarHostState.showSnackbar( - message = message, - actionLabel = action, - duration = Short, - ) == ActionPerformed - }, + Box( modifier = if (shouldShowTopAppBar) { Modifier.consumeWindowInsets( WindowInsets.safeDrawing.only(WindowInsetsSides.Top), @@ -215,7 +208,18 @@ internal fun NiaApp( } else { Modifier }, - ) + ) { + NiaNavHost( + appState = appState, + onShowSnackbar = { message, action -> + snackbarHostState.showSnackbar( + message = message, + actionLabel = action, + duration = Short, + ) == ActionPerformed + }, + ) + } } // TODO: We may want to add padding or spacer when the snackbar is shown so that