summaryrefslogtreecommitdiffhomepage
path: root/android
diff options
context:
space:
mode:
authorsaber safavi <saber.safavi@codic.se>2023-03-24 10:04:37 +0100
committerAlbin <albin@mullvad.net>2023-04-11 11:11:58 +0200
commit09e642051ebda29955aa7868a60c83bfb6865f0b (patch)
tree71e674c8ae3e62e0f3a07eaf3882cec2b0df4430 /android
parent256311c5195d9c8698a30d16baf0b1be9f268e4c (diff)
downloadmullvadvpn-09e642051ebda29955aa7868a60c83bfb6865f0b.tar.xz
mullvadvpn-09e642051ebda29955aa7868a60c83bfb6865f0b.zip
Make it possible to enable/disable the compose switch
Co-authored-by: Albin <albin@mullvad.net>
Diffstat (limited to 'android')
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/component/Switch.kt21
1 files changed, 17 insertions, 4 deletions
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/component/Switch.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/component/Switch.kt
index 1b1117afb9..2c0adcf4cf 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/component/Switch.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/component/Switch.kt
@@ -3,6 +3,7 @@ package net.mullvad.mullvadvpn.compose.component
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.gestures.detectTapGestures
+import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
@@ -20,6 +21,8 @@ import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
+import net.mullvad.mullvadvpn.compose.theme.AlphaActive
+import net.mullvad.mullvadvpn.compose.theme.AlphaInactive
import net.mullvad.mullvadvpn.compose.theme.MullvadGreen
import net.mullvad.mullvadvpn.compose.theme.MullvadRed
import net.mullvad.mullvadvpn.compose.theme.MullvadWhite
@@ -27,7 +30,10 @@ import net.mullvad.mullvadvpn.compose.theme.MullvadWhite
@Preview
@Composable
private fun PreviewSwitch() {
- CellSwitch(isChecked = false, onCheckedChange = null)
+ Column {
+ CellSwitch(isChecked = true, onCheckedChange = null)
+ CellSwitch(isChecked = false, onCheckedChange = null, isEnabled = false)
+ }
}
@Composable
@@ -36,6 +42,7 @@ fun CellSwitch(
onCheckedChange: ((Boolean) -> Unit)?,
modifier: Modifier = Modifier,
scale: Float = 1f,
+ isEnabled: Boolean = true,
thumbCheckedTrackColor: Color = MullvadGreen,
thumbUncheckedTrackColor: Color = MullvadRed,
thumbColor: Color = MullvadWhite
@@ -66,7 +73,7 @@ fun CellSwitch(
.size(width = width, height = height)
.scale(scale = scale)
.pointerInput(Unit) {
- if (onCheckedChange != null) {
+ if (onCheckedChange != null && isEnabled) {
detectTapGestures(onTap = { onCheckedChange(!isChecked) })
}
}
@@ -74,20 +81,26 @@ fun CellSwitch(
// Track
drawRoundRect(
color = thumbColor,
+ alpha = if (isEnabled) AlphaActive else AlphaInactive,
cornerRadius = CornerRadius(x = 15.dp.toPx(), y = 15.dp.toPx()),
style =
Stroke(
width = 2.dp.toPx(),
miter = 6.dp.toPx(),
cap = StrokeCap.Square,
- ),
+ )
)
// Thumb
drawCircle(
color = if (isChecked) thumbCheckedTrackColor else thumbUncheckedTrackColor,
+ alpha = if (isEnabled) AlphaActive else AlphaInactive,
radius = thumbRadius.toPx(),
- center = Offset(x = animatePosition.value, y = size.height / 2)
+ center =
+ Offset(
+ x = animatePosition.value,
+ y = size.height / 2,
+ )
)
}