Skip to content

Commit df2b1fe

Browse files
committed
style: update to use material3 switches instead of homegrown mirror
Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent ad425f7 commit df2b1fe

4 files changed

Lines changed: 24 additions & 65 deletions

File tree

apps/flipcash/features/lab/src/main/kotlin/com/flipcash/app/lab/internal/LabsScreenContent.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ internal fun LabsScreenContent(viewModel: LabsScreenViewModel, onboarding: Boole
9797
}
9898
}
9999

100-
if (betaOverride) {
100+
if (showAllFlags) {
101101
item(contentType = "section_header") {
102102
SectionHeader(
103103
modifier = Modifier.padding(horizontal = CodeTheme.dimens.inset),
@@ -110,7 +110,7 @@ internal fun LabsScreenContent(viewModel: LabsScreenViewModel, onboarding: Boole
110110
if (feature.flag.isOptionFlag) {
111111
SettingsOptionRow(
112112
title = feature.flag.title,
113-
subtitle = feature.flag.message.takeIf { betaOverride },
113+
subtitle = feature.flag.message.takeIf { showAllFlags },
114114
options = feature.flag.options,
115115
selectedOption = feature.selectedOption ?: feature.flag.defaultOption,
116116
onOptionSelected = { optionKey ->
@@ -120,7 +120,7 @@ internal fun LabsScreenContent(viewModel: LabsScreenViewModel, onboarding: Boole
120120
} else {
121121
SettingsSwitchRow(
122122
title = feature.flag.title,
123-
subtitle = feature.flag.message.takeIf { betaOverride },
123+
subtitle = feature.flag.message.takeIf { showAllFlags },
124124
checked = feature.enabled
125125
) {
126126
betaFlagsController.set(feature.flag, !feature.enabled)

apps/flipcash/shared/theme/src/main/kotlin/com/flipcash/app/theme/internal/FlipcashDesignSystem.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ private val colors = with(Flipcash2ColorSpec) {
115115
divider = White10,
116116
dividerVariant = White05,
117117
trackColor = trackColor,
118-
toggleUncheckedTrackColor = secondary,
118+
toggleUncheckedTrackColor = Color(0xFF666666),
119119
cashBill = cashBill,
120120
cashBillDecorColor = Color.White.copy(0.60f),
121121
betaIndicator = BetaIndicator,

ui/components/src/main/kotlin/com/getcode/ui/components/SettingsSwitchRow.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ fun SettingsSwitchRow(
8888
}
8989

9090
CodeToggleSwitch(
91+
modifier = Modifier.padding(start = CodeTheme.dimens.grid.x3),
9192
enabled = enabled,
9293
checked = checked,
9394
onCheckedChange = null,
Lines changed: 19 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,33 @@
11
package com.getcode.ui.theme
22

3-
import androidx.compose.animation.core.animateFloatAsState
4-
import androidx.compose.foundation.Canvas
5-
import androidx.compose.foundation.gestures.detectTapGestures
6-
import androidx.compose.foundation.layout.size
7-
import androidx.compose.material.ContentAlpha
8-
import androidx.compose.material.SwitchColors
9-
import androidx.compose.material.SwitchDefaults
3+
import androidx.compose.material3.Switch
4+
import androidx.compose.material3.SwitchColors
5+
import androidx.compose.material3.SwitchDefaults
106
import androidx.compose.runtime.Composable
11-
import androidx.compose.runtime.getValue
127
import androidx.compose.ui.Modifier
13-
import androidx.compose.ui.geometry.CornerRadius
14-
import androidx.compose.ui.geometry.Offset
158
import androidx.compose.ui.graphics.Color
16-
import androidx.compose.ui.input.pointer.pointerInput
17-
import androidx.compose.ui.platform.LocalDensity
18-
import androidx.compose.ui.unit.dp
199
import com.getcode.theme.CodeTheme
2010
import com.getcode.theme.SystemGreen
2111
import com.getcode.theme.White
22-
import com.getcode.ui.core.addIf
2312

2413
object CodeToggleSwitchDefaults {
2514

15+
private const val DISABLED_ALPHA = 0.38f
16+
2617
val colors: SwitchColors
2718
@Composable get() = SwitchDefaults.colors(
28-
disabledCheckedThumbColor = Color(0xFFB2B9B5),
29-
disabledUncheckedThumbColor = Color(0xFFB2B9B5),
19+
disabledCheckedThumbColor = Color(0x80B2B9B5),
20+
disabledUncheckedThumbColor = Color(0x80B2B9B5),
3021
disabledCheckedTrackColor = Color(0xFF2A8A4B),
31-
disabledUncheckedTrackColor = CodeTheme.colors.toggleUncheckedTrackColor.copy(ContentAlpha.disabled),
22+
disabledUncheckedTrackColor = CodeTheme.colors.toggleUncheckedTrackColor.copy(DISABLED_ALPHA),
3223
checkedThumbColor = White,
3324
uncheckedThumbColor = White,
3425
checkedTrackColor = SystemGreen,
35-
checkedTrackAlpha = 1f,
36-
uncheckedTrackAlpha = 1f,
37-
uncheckedTrackColor = CodeTheme.colors.toggleUncheckedTrackColor
26+
uncheckedTrackColor = CodeTheme.colors.toggleUncheckedTrackColor,
27+
uncheckedBorderColor = Color.White.copy(0.15f),
28+
checkedBorderColor = SystemGreen,
29+
disabledUncheckedBorderColor = CodeTheme.colors.toggleUncheckedTrackColor.copy(DISABLED_ALPHA),
30+
disabledCheckedBorderColor = Color(0xFF2A8A4B),
3831
)
3932
}
4033

@@ -45,46 +38,11 @@ fun CodeToggleSwitch(
4538
enabled: Boolean = true,
4639
onCheckedChange: ((Boolean) -> Unit)? = null,
4740
) {
48-
val width = 51.dp
49-
val height = 31.dp
50-
val gapBetweenThumbAndTrackEdge = 2.dp
51-
52-
val thumbRadius = (height / 2) - gapBetweenThumbAndTrackEdge
53-
val animatePosition = animateFloatAsState(
54-
targetValue = if (checked) {
55-
with(LocalDensity.current) { (width - thumbRadius - gapBetweenThumbAndTrackEdge).toPx() }
56-
} else {
57-
with (LocalDensity.current) { (thumbRadius + gapBetweenThumbAndTrackEdge).toPx() }
58-
}, label = "thumb position"
41+
Switch(
42+
checked = checked,
43+
modifier = modifier,
44+
enabled = enabled,
45+
onCheckedChange = onCheckedChange,
46+
colors = CodeToggleSwitchDefaults.colors
5947
)
60-
61-
val colors = CodeToggleSwitchDefaults.colors
62-
val trackColor by colors.trackColor(enabled = enabled, checked = checked)
63-
val thumbColor by colors.thumbColor(enabled = enabled, checked = checked)
64-
Canvas(
65-
modifier = modifier
66-
.size(width = width, height = height)
67-
.addIf(onCheckedChange != null) {
68-
Modifier.pointerInput(Unit) {
69-
detectTapGestures(
70-
onTap = {
71-
onCheckedChange?.invoke(!checked)
72-
}
73-
)
74-
}
75-
}
76-
) {
77-
drawRoundRect(
78-
color = trackColor,
79-
cornerRadius = CornerRadius(x = 45.dp.toPx(), y = 45.dp.toPx())
80-
)
81-
drawCircle(
82-
color = thumbColor,
83-
radius = thumbRadius.toPx(),
84-
center = Offset(
85-
x = animatePosition.value,
86-
y = size.height / 2
87-
)
88-
)
89-
}
9048
}

0 commit comments

Comments
 (0)