Corrected the actionButton color of snackbar according the light/dark theme.

This commit is contained in:
MohitMaliFtechiz 2025-03-10 15:25:37 +05:30 committed by MohitMaliFtechiz
parent f24e28ed45
commit 3162d38ff9
2 changed files with 14 additions and 50 deletions

View File

@ -18,6 +18,7 @@
package org.kiwix.kiwixmobile.core.extensions
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Snackbar
import androidx.compose.material3.SnackbarDuration
@ -27,21 +28,28 @@ import androidx.compose.material3.SnackbarResult
import androidx.compose.runtime.Composable
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
import org.kiwix.kiwixmobile.core.ui.theme.DenimBlue400
/**
* A custom Snackbar host for displaying snackbars with a consistent style in the Kiwix app.
* A custom SnackbarHost for displaying snackbars with theme-aware action button colors.
*
* This Composable wraps the default [SnackbarHost] and applies a custom action text color
* using the primary color from the Material theme.
* This function ensures that the action button color follows the app's theme:
* - In **light mode**, the action button color is `DenimBlue400`.
* - In **dark mode**, the action button color is `surface`, similar to the XML-based styling.
*
* @param snackbarHostState The state that controls the visibility and content of the Snackbar.
* @param snackbarHostState The state that controls the Snackbar display.
*/
@Composable
fun KiwixSnackbarHost(snackbarHostState: SnackbarHostState) {
val actionColor = if (isSystemInDarkTheme()) {
MaterialTheme.colorScheme.surface
} else {
DenimBlue400
}
SnackbarHost(hostState = snackbarHostState) { snackbarData ->
Snackbar(
snackbarData = snackbarData,
actionColor = MaterialTheme.colorScheme.primary
actionColor = actionColor
)
}
}
@ -57,7 +65,7 @@ fun SnackbarHostState.snack(
lifecycleScope.launch {
val result = showSnackbar(
message = message,
actionLabel = actionLabel,
actionLabel = actionLabel?.uppercase(),
duration = snackbarDuration
)
if (result == SnackbarResult.ActionPerformed) {

View File

@ -25,9 +25,6 @@ import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Delete
import androidx.compose.material.icons.filled.Share
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
@ -40,14 +37,9 @@ import androidx.compose.ui.graphics.vector.rememberVectorPainter
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight.Companion.SemiBold
import androidx.compose.ui.tooling.preview.Preview
import org.kiwix.kiwixmobile.core.R
import org.kiwix.kiwixmobile.core.ui.models.ActionMenuItem
import org.kiwix.kiwixmobile.core.ui.models.IconItem
import org.kiwix.kiwixmobile.core.ui.models.IconItem.Drawable
import org.kiwix.kiwixmobile.core.ui.models.IconItem.Vector
import org.kiwix.kiwixmobile.core.ui.theme.Black
import org.kiwix.kiwixmobile.core.ui.theme.KiwixTheme
import org.kiwix.kiwixmobile.core.ui.theme.White
import org.kiwix.kiwixmobile.core.utils.ComposeDimens.KIWIX_APP_BAR_HEIGHT
import org.kiwix.kiwixmobile.core.utils.ComposeDimens.SIXTEEN_DP
@ -112,39 +104,3 @@ private fun ActionMenu(actionMenuItems: List<ActionMenuItem>) {
}
}
}
@Preview(name = "NightMode", uiMode = android.content.res.Configuration.UI_MODE_NIGHT_YES)
@Preview(name = "LightMode", uiMode = android.content.res.Configuration.UI_MODE_NIGHT_NO)
@Composable
fun PreviewKiwixAppBar() {
KiwixTheme {
KiwixAppBar(
R.string.note,
{
NavigationIcon(
iconItem = IconItem.Drawable(R.drawable.ic_close_white_24dp),
onClick = {}
)
},
listOf(
ActionMenuItem(
Vector(Icons.Default.Delete),
R.string.delete,
{},
isEnabled = false
),
ActionMenuItem(
Vector(Icons.Default.Share),
R.string.share,
{},
isEnabled = true
),
ActionMenuItem(
Drawable(R.drawable.ic_save),
R.string.save,
{}
)
),
)
}
}