Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Badge's border for subtle variants #412

Merged
merged 1 commit into from
Apr 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package kiwi.orbit.compose.catalog.screens

import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
Expand Down Expand Up @@ -313,7 +314,7 @@ private fun BadgeScreenInner() {
BadgeRow("Custom themed") {
BadgePrimitive(
backgroundColor = OrbitTheme.colors.info.subtle,
borderColor = OrbitTheme.colors.info.strong,
borderStroke = BorderStroke(0.5.dp, OrbitTheme.colors.info.strong),
contentColor = OrbitTheme.colors.content.normal,
icon = { Icon(painter = Icons.Close, contentDescription = null) },
) {
Expand Down
28 changes: 13 additions & 15 deletions ui/src/main/java/kiwi/orbit/compose/ui/controls/Badge.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import kiwi.orbit.compose.ui.controls.internal.OrbitPreviews
import kiwi.orbit.compose.ui.controls.internal.Preview
import kiwi.orbit.compose.ui.foundation.Colors
import kiwi.orbit.compose.ui.foundation.LocalColors
import kiwi.orbit.compose.ui.foundation.ProvideMergedTextStyle
import kiwi.orbit.compose.ui.foundation.asCriticalTheme
import kiwi.orbit.compose.ui.foundation.asInfoTheme
import kiwi.orbit.compose.ui.foundation.asNeutralSubtleStrongTheme
Expand Down Expand Up @@ -209,21 +208,20 @@ private fun Badge(
content: @Composable RowScope.() -> Unit,
modifier: Modifier = Modifier,
) {
CompositionLocalProvider(LocalColors provides colors) {
ThemedSurface(
subtle = subtle,
shape = BadgeShape,
val backgroundColor = when (subtle) {
true -> colors.primary.subtle
false -> colors.primary.normal
}
CompositionLocalProvider(
LocalColors provides colors,
) {
BadgePrimitive(
backgroundColor = backgroundColor,
backgroundBrush = null,
borderStroke = null,
icon = icon,
content = content,
modifier = modifier,
borderStrokeWidth = BadgeStrokeWidth,
contentPadding = BadgeContentPadding,
horizontalArrangement = BadgeArrangement,
verticalAlignment = BadgeAlignment,
content = {
ProvideMergedTextStyle(OrbitTheme.typography.bodySmallMedium) {
icon()
content()
}
},
)
}
}
Expand Down
33 changes: 21 additions & 12 deletions ui/src/main/java/kiwi/orbit/compose/ui/controls/BadgeCircle.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package kiwi.orbit.compose.ui.controls

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.requiredHeight
import androidx.compose.foundation.layout.requiredWidth
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.Alignment
Expand All @@ -17,7 +17,6 @@ import kiwi.orbit.compose.ui.controls.internal.OrbitPreviews
import kiwi.orbit.compose.ui.controls.internal.Preview
import kiwi.orbit.compose.ui.foundation.Colors
import kiwi.orbit.compose.ui.foundation.LocalColors
import kiwi.orbit.compose.ui.foundation.ProvideMergedTextStyle
import kiwi.orbit.compose.ui.foundation.asCriticalTheme
import kiwi.orbit.compose.ui.foundation.asInfoTheme
import kiwi.orbit.compose.ui.foundation.asNeutralSubtleStrongTheme
Expand Down Expand Up @@ -155,26 +154,31 @@ private fun BadgeCircle(
) {
val height = with(LocalDensity.current) {
OrbitTheme.typography.bodySmallMedium.lineHeight.toDp() +
BadgeContentPadding.calculateTopPadding() +
BadgeContentPadding.calculateBottomPadding()
BadgeDefaults.ContentPadding.calculateTopPadding() +
BadgeDefaults.ContentPadding.calculateBottomPadding()
}
val backgroundColor = when (subtle) {
true -> colors.primary.subtle
false -> colors.primary.normal
}
CompositionLocalProvider(
LocalColors provides colors,
) {
ThemedSurface(
BadgePrimitive(
modifier = modifier
.requiredHeight(height)
.requiredWidth(height),
subtle = subtle,
shape = CircleShape,
borderStrokeWidth = BadgeStrokeWidth,
backgroundColor = backgroundColor,
backgroundBrush = null,
borderStroke = null,
horizontalArrangement = Arrangement.Center,
verticalAlignment = Alignment.CenterVertically,
) {
ProvideMergedTextStyle(OrbitTheme.typography.bodySmallMedium) {
contentPadding = ContentPadding,
icon = {},
content = {
Text(text = value.toString(), maxLines = 1, overflow = TextOverflow.Visible)
}
}
},
)
}
}

Expand Down Expand Up @@ -215,3 +219,8 @@ internal fun BadgeCirclePreview() {
}
}
}

private val ContentPadding = PaddingValues(
top = BadgeDefaults.ContentPadding.calculateTopPadding(),
bottom = BadgeDefaults.ContentPadding.calculateBottomPadding(),
)
63 changes: 42 additions & 21 deletions ui/src/main/java/kiwi/orbit/compose/ui/controls/BadgePrimitive.kt
Original file line number Diff line number Diff line change
@@ -1,53 +1,74 @@
package kiwi.orbit.compose.ui.controls

import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import kiwi.orbit.compose.ui.OrbitTheme
import kiwi.orbit.compose.ui.controls.internal.background
import kiwi.orbit.compose.ui.foundation.ContentEmphasis
import kiwi.orbit.compose.ui.foundation.LocalContentColor
import kiwi.orbit.compose.ui.foundation.LocalContentEmphasis
import kiwi.orbit.compose.ui.foundation.LocalTextStyle
import kiwi.orbit.compose.ui.foundation.ProvideMergedTextStyle
import kiwi.orbit.compose.ui.foundation.contentColorFor

@Composable
public fun BadgePrimitive(
backgroundColor: Color,
modifier: Modifier = Modifier,
borderColor: Color = Color.Unspecified,
borderStroke: BorderStroke? = null,
contentColor: Color = contentColorFor(backgroundColor),
backgroundBrush: Brush? = null,
horizontalArrangement: Arrangement.Horizontal = BadgeDefaults.HorizontalArrangement,
verticalAlignment: Alignment.Vertical = BadgeDefaults.VerticalAlignment,
contentPadding: PaddingValues = BadgeDefaults.ContentPadding,
icon: @Composable RowScope.() -> Unit = {},
content: @Composable RowScope.() -> Unit,
) {
ThemedSurface(
modifier = modifier,
backgroundColor = backgroundColor,
backgroundBrush = backgroundBrush,
contentColor = contentColor,
border = when (borderColor) {
Color.Unspecified -> null
else -> BorderStroke(BadgeStrokeWidth, borderColor)
},
shape = BadgeShape,
contentPadding = BadgeContentPadding,
verticalAlignment = BadgeAlignment,
horizontalArrangement = BadgeArrangement,
// remove style color to fallback to proper LocalContentColor
val textStyle = LocalTextStyle.current.copy(
color = Color.Unspecified,
)
CompositionLocalProvider(
LocalContentEmphasis provides ContentEmphasis.Normal,
LocalContentColor provides contentColor,
LocalTextStyle provides textStyle,
) {
ProvideMergedTextStyle(OrbitTheme.typography.bodySmallMedium) {
icon()
content()
Row(
modifier = modifier
.then(if (borderStroke != null) Modifier.border(borderStroke, BadgeShape) else Modifier)
.background(backgroundColor, backgroundBrush, BadgeShape)
.padding(contentPadding),
horizontalArrangement = horizontalArrangement,
verticalAlignment = verticalAlignment,
) {
ProvideMergedTextStyle(OrbitTheme.typography.bodySmallMedium) {
icon()
content()
}
}
}
}

internal val BadgeAlignment = Alignment.CenterVertically
internal val BadgeArrangement = Arrangement.spacedBy(4.dp)
internal val BadgeContentPadding = PaddingValues(horizontal = 8.dp, vertical = 4.dp)
public object BadgeDefaults {
public val HorizontalArrangement: Arrangement.Horizontal =
Arrangement.spacedBy(4.dp)
public val VerticalAlignment: Alignment.Vertical =
Alignment.CenterVertically
public val ContentPadding: PaddingValues =
PaddingValues(horizontal = 8.dp, vertical = 4.dp)
}

internal val BadgeShape = RoundedCornerShape(50)
internal val BadgeStrokeWidth = 0.5.dp

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package kiwi.orbit.compose.ui.controls.internal

import androidx.compose.foundation.background
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Shape

internal fun Modifier.background(color: Color, brush: Brush?, shape: Shape): Modifier =
when (brush) {
null -> background(color, shape)
else -> background(brush, shape)
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading