mirror of
https://github.com/oxen-io/session-android.git
synced 2025-02-19 21:18:27 +00:00
Add Color to ButtonType to support Fill and PrimaryFill
This commit is contained in:
parent
f06d53c746
commit
acbe4de25a
@ -89,8 +89,7 @@ private fun NotificationRadioButton(
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.contentDescription(contentDescription),
|
||||
type = ButtonType.Outline,
|
||||
color = LocalColors.current.text,
|
||||
type = ButtonType.Outline(LocalColors.current.text),
|
||||
border = BorderStroke(
|
||||
width = ButtonDefaults.OutlinedBorderSize,
|
||||
color = if (selected) LocalColors.current.primary else LocalColors.current.borders
|
||||
|
@ -38,7 +38,9 @@ interface Colors {
|
||||
val backgroundBubbleReceived: Color
|
||||
val textBubbleReceived: Color
|
||||
val backgroundBubbleSent: Color get() = primary
|
||||
val buttonFilled: Color
|
||||
val primaryButtonFillText: Color
|
||||
val primaryButtonFill: Color
|
||||
val buttonFill: Color
|
||||
val buttonOutline: Color
|
||||
val qrCodeContent: Color
|
||||
val qrCodeBackground: Color
|
||||
@ -56,7 +58,9 @@ data class ClassicDark(override val primary: Color = primaryGreen): Colors {
|
||||
override val textBubbleSent = Color.Black
|
||||
override val backgroundBubbleReceived = classicDark2
|
||||
override val textBubbleReceived = Color.White
|
||||
override val buttonFilled = primary
|
||||
override val primaryButtonFillText = Color.Black
|
||||
override val primaryButtonFill = primary
|
||||
override val buttonFill = text
|
||||
override val buttonOutline = primary
|
||||
override val qrCodeContent = background
|
||||
override val qrCodeBackground = text
|
||||
@ -74,7 +78,9 @@ data class ClassicLight(override val primary: Color = primaryGreen): Colors {
|
||||
override val textBubbleSent = Color.Black
|
||||
override val backgroundBubbleReceived = classicLight4
|
||||
override val textBubbleReceived = classicLight4
|
||||
override val buttonFilled = classicLight0
|
||||
override val primaryButtonFillText = Color.White
|
||||
override val primaryButtonFill = classicLight0
|
||||
override val buttonFill = classicLight0
|
||||
override val buttonOutline = classicLight0
|
||||
override val qrCodeContent = text
|
||||
override val qrCodeBackground = backgroundSecondary
|
||||
@ -92,7 +98,9 @@ data class OceanDark(override val primary: Color = primaryBlue): Colors {
|
||||
override val textBubbleSent = Color.Black
|
||||
override val backgroundBubbleReceived = oceanDark4
|
||||
override val textBubbleReceived = oceanDark4
|
||||
override val buttonFilled = primary
|
||||
override val primaryButtonFillText = Color.Black
|
||||
override val primaryButtonFill = primary
|
||||
override val buttonFill = text
|
||||
override val buttonOutline = primary
|
||||
override val qrCodeContent = background
|
||||
override val qrCodeBackground = text
|
||||
@ -110,7 +118,9 @@ data class OceanLight(override val primary: Color = primaryBlue): Colors {
|
||||
override val textBubbleSent = oceanLight1
|
||||
override val backgroundBubbleReceived = oceanLight4
|
||||
override val textBubbleReceived = oceanLight1
|
||||
override val buttonFilled = oceanLight1
|
||||
override val primaryButtonFillText = Color.White
|
||||
override val primaryButtonFill = oceanLight1
|
||||
override val buttonFill = oceanLight1
|
||||
override val buttonOutline = oceanLight1
|
||||
override val qrCodeContent = text
|
||||
override val qrCodeBackground = backgroundSecondary
|
||||
|
@ -16,7 +16,6 @@ import androidx.compose.foundation.layout.RowScope
|
||||
import androidx.compose.foundation.layout.heightIn
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material.ButtonColors
|
||||
import androidx.compose.material.ButtonDefaults
|
||||
import androidx.compose.material.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
@ -29,7 +28,6 @@ import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.Shape
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.tooling.preview.PreviewParameter
|
||||
import androidx.compose.ui.unit.dp
|
||||
@ -37,7 +35,6 @@ import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.collectLatest
|
||||
import kotlinx.coroutines.flow.filter
|
||||
import network.loki.messenger.R
|
||||
import org.thoughtcrime.securesms.ui.GetString
|
||||
import org.thoughtcrime.securesms.ui.LaunchedEffectAsync
|
||||
import org.thoughtcrime.securesms.ui.PreviewTheme
|
||||
import org.thoughtcrime.securesms.ui.SessionColorsParameterProvider
|
||||
@ -46,7 +43,6 @@ import org.thoughtcrime.securesms.ui.buttonShape
|
||||
import org.thoughtcrime.securesms.ui.color.Colors
|
||||
import org.thoughtcrime.securesms.ui.color.LocalColors
|
||||
import org.thoughtcrime.securesms.ui.contentDescription
|
||||
import org.thoughtcrime.securesms.ui.extraSmall
|
||||
import kotlin.time.Duration
|
||||
import kotlin.time.Duration.Companion.seconds
|
||||
|
||||
@ -56,14 +52,13 @@ import kotlin.time.Duration.Companion.seconds
|
||||
@Composable
|
||||
fun Button(
|
||||
onClick: () -> Unit,
|
||||
color: Color,
|
||||
type: ButtonType,
|
||||
modifier: Modifier = Modifier,
|
||||
enabled: Boolean = true,
|
||||
style: ButtonStyle = ButtonStyle.Large,
|
||||
shape: Shape = buttonShape,
|
||||
border: BorderStroke? = type.border(color, enabled),
|
||||
colors: ButtonColors = type.buttonColors(color),
|
||||
border: BorderStroke? = type.border(enabled),
|
||||
colors: ButtonColors = type.buttonColors(),
|
||||
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
|
||||
contentPadding: PaddingValues = type.contentPadding,
|
||||
content: @Composable RowScope.() -> Unit
|
||||
@ -95,38 +90,34 @@ fun Button(
|
||||
fun Button(
|
||||
text: String,
|
||||
onClick: () -> Unit,
|
||||
color: Color,
|
||||
type: ButtonType,
|
||||
modifier: Modifier = Modifier,
|
||||
enabled: Boolean = true,
|
||||
size: ButtonStyle = ButtonStyle.Large,
|
||||
style: ButtonStyle = ButtonStyle.Large,
|
||||
shape: Shape = buttonShape,
|
||||
border: BorderStroke? = type.border(color, enabled),
|
||||
colors: ButtonColors = type.buttonColors(color),
|
||||
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
|
||||
) {
|
||||
Button(onClick, color, type, modifier, enabled, size, shape, border, colors, interactionSource) {
|
||||
Button(onClick, type, modifier, enabled, style, shape, interactionSource = interactionSource) {
|
||||
Text(text)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable fun FillButton(text: String, modifier: Modifier = Modifier, enabled: Boolean = true, onClick: () -> Unit) {
|
||||
Button(text, onClick, LocalColors.current.buttonOutline, ButtonType.Fill, modifier, enabled)
|
||||
Button(text, onClick, ButtonType.Fill, modifier, enabled)
|
||||
}
|
||||
|
||||
@Composable fun PrimaryFillButton(text: String, modifier: Modifier = Modifier, enabled: Boolean = true, onClick: () -> Unit) {
|
||||
Button(text, onClick, LocalColors.current.primary, ButtonType.Fill, modifier, enabled)
|
||||
Button(text, onClick, ButtonType.PrimaryFill, modifier, enabled)
|
||||
}
|
||||
|
||||
@Composable fun OutlineButton(text: String, modifier: Modifier = Modifier, color: Color = LocalColors.current.buttonOutline, enabled: Boolean = true, onClick: () -> Unit) {
|
||||
Button(text, onClick, color, ButtonType.Outline, modifier, enabled)
|
||||
Button(text, onClick, ButtonType.Outline(color), modifier, enabled)
|
||||
}
|
||||
|
||||
@Composable fun OutlineButton(modifier: Modifier = Modifier, color: Color = LocalColors.current.buttonOutline, enabled: Boolean = true, onClick: () -> Unit, content: @Composable RowScope.() -> Unit) {
|
||||
Button(
|
||||
onClick = onClick,
|
||||
color = color,
|
||||
type = ButtonType.Outline,
|
||||
type = ButtonType.Outline(color),
|
||||
modifier = modifier,
|
||||
enabled = enabled,
|
||||
content = content
|
||||
@ -134,18 +125,18 @@ fun Button(
|
||||
}
|
||||
|
||||
@Composable fun PrimaryOutlineButton(text: String, modifier: Modifier = Modifier, enabled: Boolean = true, onClick: () -> Unit) {
|
||||
Button(text, onClick, LocalColors.current.primary, ButtonType.Outline, modifier, enabled)
|
||||
Button(text, onClick, ButtonType.Outline(LocalColors.current.primary), modifier, enabled)
|
||||
}
|
||||
|
||||
@Composable fun SlimOutlineButton(onClick: () -> Unit, modifier: Modifier = Modifier, color: Color = LocalColors.current.text, enabled: Boolean = true, content: @Composable RowScope.() -> Unit) {
|
||||
Button(onClick, color, ButtonType.Outline, modifier, enabled, ButtonStyle.Slim, content = content)
|
||||
Button(onClick, ButtonType.Outline(color), modifier, enabled, ButtonStyle.Slim, content = content)
|
||||
}
|
||||
|
||||
/**
|
||||
* Courtesy [SlimOutlineButton] implementation for buttons that just display text.
|
||||
*/
|
||||
@Composable fun SlimOutlineButton(text: String, modifier: Modifier = Modifier, color: Color = LocalColors.current.text, enabled: Boolean = true, onClick: () -> Unit) {
|
||||
Button(text, onClick, color, ButtonType.Outline, modifier, enabled, ButtonStyle.Slim)
|
||||
Button(text, onClick, ButtonType.Outline(color), modifier, enabled, ButtonStyle.Slim)
|
||||
}
|
||||
|
||||
@Composable
|
||||
@ -170,8 +161,7 @@ fun OutlineCopyButton(
|
||||
modifier = modifier.contentDescription(R.string.AccessibilityId_copy_button),
|
||||
interactionSource = interactionSource,
|
||||
style = style,
|
||||
type = ButtonType.Outline,
|
||||
color = color,
|
||||
type = ButtonType.Outline(color),
|
||||
onClick = onClick
|
||||
) {
|
||||
TemporaryClickedContent(
|
||||
@ -219,10 +209,9 @@ fun BorderlessButton(
|
||||
) {
|
||||
Button(
|
||||
onClick = onClick,
|
||||
color = color,
|
||||
modifier = modifier,
|
||||
style = ButtonStyle.Borderless,
|
||||
type = ButtonType.Borderless,
|
||||
type = ButtonType.Borderless(color),
|
||||
content = content
|
||||
)
|
||||
}
|
||||
@ -288,6 +277,7 @@ private fun VariousButtons(
|
||||
verticalArrangement = Arrangement.spacedBy(8.dp)
|
||||
) {
|
||||
PrimaryFillButton("Primary Fill") {}
|
||||
FillButton("Fill Button") {}
|
||||
OutlineButton("Outline Button") {}
|
||||
SlimOutlineButton("Slim Outline") {}
|
||||
SlimOutlineButton("Slim Primary", color = LocalColors.current.buttonOutline) {}
|
||||
|
@ -14,19 +14,19 @@ interface ButtonType {
|
||||
val contentPadding: PaddingValues get() = ButtonDefaults.ContentPadding
|
||||
|
||||
@Composable
|
||||
fun border(color: Color, enabled: Boolean): BorderStroke?
|
||||
fun border(enabled: Boolean): BorderStroke?
|
||||
@Composable
|
||||
fun buttonColors(color: Color): ButtonColors
|
||||
fun buttonColors(): ButtonColors
|
||||
|
||||
object Outline: ButtonType {
|
||||
class Outline(private val color: Color): ButtonType {
|
||||
@Composable
|
||||
override fun border(color: Color, enabled: Boolean) =
|
||||
override fun border(enabled: Boolean) =
|
||||
BorderStroke(
|
||||
width = LocalDimensions.current.borderStroke,
|
||||
color = if (enabled) color else LocalColors.current.disabled
|
||||
)
|
||||
@Composable
|
||||
override fun buttonColors(color: Color) = ButtonDefaults.buttonColors(
|
||||
override fun buttonColors() = ButtonDefaults.buttonColors(
|
||||
contentColor = color,
|
||||
backgroundColor = Color.Unspecified,
|
||||
disabledContentColor = LocalColors.current.disabled,
|
||||
@ -36,23 +36,35 @@ interface ButtonType {
|
||||
|
||||
object Fill: ButtonType {
|
||||
@Composable
|
||||
override fun border(color: Color, enabled: Boolean) = null
|
||||
override fun border(enabled: Boolean) = null
|
||||
@Composable
|
||||
override fun buttonColors(color: Color) = ButtonDefaults.buttonColors(
|
||||
override fun buttonColors() = ButtonDefaults.buttonColors(
|
||||
contentColor = LocalColors.current.background,
|
||||
backgroundColor = color,
|
||||
backgroundColor = LocalColors.current.buttonFill,
|
||||
disabledContentColor = LocalColors.current.disabled,
|
||||
disabledBackgroundColor = Color.Unspecified
|
||||
)
|
||||
}
|
||||
|
||||
object Borderless: ButtonType {
|
||||
object PrimaryFill: ButtonType {
|
||||
@Composable
|
||||
override fun border(enabled: Boolean) = null
|
||||
@Composable
|
||||
override fun buttonColors() = ButtonDefaults.buttonColors(
|
||||
contentColor = LocalColors.current.primaryButtonFillText,
|
||||
backgroundColor = LocalColors.current.primaryButtonFill,
|
||||
disabledContentColor = LocalColors.current.disabled,
|
||||
disabledBackgroundColor = Color.Unspecified
|
||||
)
|
||||
}
|
||||
|
||||
class Borderless(private val color: Color): ButtonType {
|
||||
override val contentPadding: PaddingValues
|
||||
get() = PaddingValues(horizontal = 16.dp, vertical = 12.dp)
|
||||
@Composable
|
||||
override fun border(color: Color, enabled: Boolean) = null
|
||||
override fun border(enabled: Boolean) = null
|
||||
@Composable
|
||||
override fun buttonColors(color: Color) = ButtonDefaults.outlinedButtonColors(
|
||||
override fun buttonColors() = ButtonDefaults.outlinedButtonColors(
|
||||
contentColor = color,
|
||||
backgroundColor = Color.Transparent,
|
||||
disabledContentColor = LocalColors.current.disabled
|
||||
|
Loading…
x
Reference in New Issue
Block a user