library: pad snackbar above nav bar, dedup repeat messages (#630)
- Commit
fe4267f4ef4133ce15a9d6675d486bd1186684e5- Author
- vayun-mathur <[email protected]>
- When
- 2026-08-31 17:00 UTC (3 months ago)
- Parents
b9c9b9d
Diff
library/src/main/java/com/vayunmathur/library/util/AppMessages.kt
diff --git a/library/src/main/java/com/vayunmathur/library/util/AppMessages.kt b/library/src/main/java/com/vayunmathur/library/util/AppMessages.ktindex 7c9362020c..4f5dcf3cb1 100644--- a/library/src/main/java/com/vayunmathur/library/util/AppMessages.kt+++ b/library/src/main/java/com/vayunmathur/library/util/AppMessages.kt@@ -40,13 +40,30 @@ object AppMessages { val messages: SharedFlow<Message> = _messages.asSharedFlow() + /** Window within which an identical, actionless message is suppressed as a repeat. */+ private const val DEDUP_WINDOW_MS = 3_000L+ private var lastText: String? = null+ private var lastAtMs: Long = 0L+ /** * Post a message from anywhere - ViewModel, worker, or a plain Activity. * * Never suspends and never fails; if nothing is collecting, the message is * dropped.+ *+ * Identical actionless messages posted within [DEDUP_WINDOW_MS] are dropped so a+ * repeatedly-failing operation (e.g. an update retrying, or a per-package install+ * callback firing for a batch) doesn't spam the same snackbar. See issue #630. */ fun show(text: String, actionLabel: String? = null, duration: Duration = Duration.Short, onAction: (() -> Unit)? = null) {+ if (actionLabel == null) {+ val now = System.currentTimeMillis()+ synchronized(this) {+ if (text == lastText && now - lastAtMs < DEDUP_WINDOW_MS) return+ lastText = text+ lastAtMs = now+ }+ } _messages.tryEmit(Message(text, actionLabel, onAction, duration)) } }
library/src/main/java/com/vayunmathur/library/util/Navigation.kt
diff --git a/library/src/main/java/com/vayunmathur/library/util/Navigation.kt b/library/src/main/java/com/vayunmathur/library/util/Navigation.ktindex 2f07e2d2a2..ffc19ed39c 100644--- a/library/src/main/java/com/vayunmathur/library/util/Navigation.kt+++ b/library/src/main/java/com/vayunmathur/library/util/Navigation.kt@@ -26,6 +26,7 @@ import androidx.compose.foundation.layout.WindowInsets import androidx.compose.foundation.layout.consumeWindowInsets import androidx.compose.foundation.layout.ime import androidx.compose.foundation.layout.imePadding+import androidx.compose.foundation.layout.navigationBarsPadding import androidx.compose.foundation.layout.union import androidx.compose.foundation.layout.padding import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi@@ -487,7 +488,17 @@ fun <T: NavKey> MainNavigation( contentWindowInsets = WindowInsets(), containerColor = resolvedContainerColor, contentColor = resolvedContentColor,- snackbarHost = { SnackbarHost(snackbarHostState) },+ // The scaffold disables automatic insets (contentWindowInsets = WindowInsets()), so the+ // snackbar host must apply its own navigation-bar and IME padding — otherwise messages+ // render behind the system navigation bar and are hidden (issue #630).+ snackbarHost = {+ SnackbarHost(+ snackbarHostState,+ modifier = Modifier+ .navigationBarsPadding()+ .imePadding(),+ )+ }, bottomBar = bottomBar ) { paddingValues -> CompositionLocalProvider(