mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-24 13:08:46 +00:00
Add polish to usernames UX.
This commit is contained in:
committed by
Nicholas Tinsley
parent
ec96b4e3aa
commit
38d5d3ad1b
@@ -177,9 +177,11 @@ object Buttons {
|
||||
onClick: () -> Unit,
|
||||
@DrawableRes iconResId: Int,
|
||||
@StringRes labelResId: Int,
|
||||
modifier: Modifier = Modifier
|
||||
modifier: Modifier = Modifier,
|
||||
enabled: Boolean = true
|
||||
) {
|
||||
ActionButton(
|
||||
enabled = enabled,
|
||||
onClick = onClick,
|
||||
label = stringResource(labelResId),
|
||||
modifier = modifier
|
||||
|
||||
74
core-ui/src/main/java/org/signal/core/ui/Snackbars.kt
Normal file
74
core-ui/src/main/java/org/signal/core/ui/Snackbars.kt
Normal file
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright 2024 Signal Messenger, LLC
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
package org.signal.core.ui
|
||||
|
||||
import android.content.res.Configuration
|
||||
import androidx.compose.material3.Snackbar
|
||||
import androidx.compose.material3.SnackbarData
|
||||
import androidx.compose.material3.SnackbarDuration
|
||||
import androidx.compose.material3.SnackbarHost
|
||||
import androidx.compose.material3.SnackbarHostState
|
||||
import androidx.compose.material3.SnackbarVisuals
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import org.signal.core.ui.theme.LocalSnackbarColors
|
||||
import org.signal.core.ui.theme.SignalTheme
|
||||
|
||||
/**
|
||||
* Properly themed Snackbars. Since these use internal color state, we need to
|
||||
* use a local provider to pass the properly themed colors around. These composables
|
||||
* allow for quick and easy access to the proper theming for snackbars.
|
||||
*/
|
||||
object Snackbars {
|
||||
@Composable
|
||||
fun Host(snackbarHostState: SnackbarHostState) {
|
||||
SnackbarHost(hostState = snackbarHostState) {
|
||||
Default(snackbarData = it)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
internal fun Default(snackbarData: SnackbarData) {
|
||||
val colors = LocalSnackbarColors.current
|
||||
Snackbar(
|
||||
snackbarData = snackbarData,
|
||||
containerColor = colors.color,
|
||||
contentColor = colors.contentColor,
|
||||
actionColor = colors.actionColor,
|
||||
actionContentColor = colors.actionContentColor,
|
||||
dismissActionContentColor = colors.dismissActionContentColor
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
private fun SnackbarLightPreview() {
|
||||
SignalTheme {
|
||||
Snackbars.Default(snackbarData = SampleSnackbarData)
|
||||
}
|
||||
}
|
||||
|
||||
@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES)
|
||||
@Composable
|
||||
private fun SnackbarDarkPreview() {
|
||||
SignalTheme {
|
||||
Snackbars.Default(snackbarData = SampleSnackbarData)
|
||||
}
|
||||
}
|
||||
|
||||
private object SampleSnackbarData : SnackbarData {
|
||||
override val visuals = object : SnackbarVisuals {
|
||||
override val actionLabel: String = "Action Label"
|
||||
override val duration: SnackbarDuration = SnackbarDuration.Short
|
||||
override val message: String = "Message"
|
||||
override val withDismissAction: Boolean = true
|
||||
}
|
||||
|
||||
override fun dismiss() = Unit
|
||||
|
||||
override fun performAction() = Unit
|
||||
}
|
||||
@@ -168,14 +168,31 @@ private val darkColorScheme = darkColorScheme(
|
||||
outline = Color(0xFF5C5E65)
|
||||
)
|
||||
|
||||
private val lightSnackbarColors = SnackbarColors(
|
||||
color = darkColorScheme.surface,
|
||||
contentColor = darkColorScheme.onSurface,
|
||||
actionColor = darkColorScheme.primary,
|
||||
actionContentColor = darkColorScheme.primary,
|
||||
dismissActionContentColor = darkColorScheme.onSurface
|
||||
)
|
||||
|
||||
private val darkSnackbarColors = SnackbarColors(
|
||||
color = darkColorScheme.surfaceVariant,
|
||||
contentColor = darkColorScheme.onSurfaceVariant,
|
||||
actionColor = darkColorScheme.primary,
|
||||
actionContentColor = darkColorScheme.primary,
|
||||
dismissActionContentColor = darkColorScheme.onSurfaceVariant
|
||||
)
|
||||
|
||||
@Composable
|
||||
fun SignalTheme(
|
||||
isDarkMode: Boolean = LocalContext.current.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES,
|
||||
content: @Composable () -> Unit
|
||||
) {
|
||||
val extendedColors = if (isDarkMode) darkExtendedColors else lightExtendedColors
|
||||
val snackbarColors = if (isDarkMode) darkSnackbarColors else lightSnackbarColors
|
||||
|
||||
CompositionLocalProvider(LocalExtendedColors provides extendedColors) {
|
||||
CompositionLocalProvider(LocalExtendedColors provides extendedColors, LocalSnackbarColors provides snackbarColors) {
|
||||
MaterialTheme(
|
||||
colorScheme = if (isDarkMode) darkColorScheme else lightColorScheme,
|
||||
typography = typography,
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2024 Signal Messenger, LLC
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
package org.signal.core.ui.theme
|
||||
|
||||
import androidx.compose.runtime.Immutable
|
||||
import androidx.compose.runtime.staticCompositionLocalOf
|
||||
import androidx.compose.ui.graphics.Color
|
||||
|
||||
/**
|
||||
* Borrowed from [androidx.compose.material3.Snackbar]
|
||||
*
|
||||
* Works in conjunction with [org.signal.core.ui.Snackbars] for properly
|
||||
* themed snackbars in light and dark modes.
|
||||
*/
|
||||
@Immutable
|
||||
data class SnackbarColors(
|
||||
val color: Color,
|
||||
val contentColor: Color,
|
||||
val actionColor: Color,
|
||||
val actionContentColor: Color,
|
||||
val dismissActionContentColor: Color
|
||||
)
|
||||
|
||||
val LocalSnackbarColors = staticCompositionLocalOf {
|
||||
SnackbarColors(
|
||||
color = Color.Unspecified,
|
||||
contentColor = Color.Unspecified,
|
||||
actionColor = Color.Unspecified,
|
||||
actionContentColor = Color.Unspecified,
|
||||
dismissActionContentColor = Color.Unspecified
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user