mirror of
https://github.com/kavishdevar/librepods.git
synced 2026-02-10 19:52:24 +00:00
android: fix switch styling
This commit is contained in:
@@ -79,7 +79,6 @@ fun StyledSwitch(
|
|||||||
checked: Boolean,
|
checked: Boolean,
|
||||||
onCheckedChange: (Boolean) -> Unit,
|
onCheckedChange: (Boolean) -> Unit,
|
||||||
enabled: Boolean = true,
|
enabled: Boolean = true,
|
||||||
indpendent: Boolean = true,
|
|
||||||
) {
|
) {
|
||||||
val isDarkTheme = isSystemInDarkTheme()
|
val isDarkTheme = isSystemInDarkTheme()
|
||||||
|
|
||||||
@@ -135,7 +134,6 @@ fun StyledSwitch(
|
|||||||
.height(trackHeight)
|
.height(trackHeight)
|
||||||
.onSizeChanged { trackWidthPx.floatValue = it.width.toFloat() }
|
.onSizeChanged { trackWidthPx.floatValue = it.width.toFloat() }
|
||||||
)
|
)
|
||||||
|
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.padding(horizontal = 2.dp)
|
.padding(horizontal = 2.dp)
|
||||||
@@ -178,7 +176,9 @@ fun StyledSwitch(
|
|||||||
{ RoundedCornerShape(thumbHeight / 2) },
|
{ RoundedCornerShape(thumbHeight / 2) },
|
||||||
highlight = {
|
highlight = {
|
||||||
val progress = progressAnimation.value
|
val progress = progressAnimation.value
|
||||||
Highlight.AmbientDefault.copy(alpha = progress)
|
Highlight.AmbientDefault.copy(
|
||||||
|
alpha = progress
|
||||||
|
)
|
||||||
},
|
},
|
||||||
shadow = {
|
shadow = {
|
||||||
Shadow(
|
Shadow(
|
||||||
@@ -188,21 +188,23 @@ fun StyledSwitch(
|
|||||||
},
|
},
|
||||||
layerBlock = {
|
layerBlock = {
|
||||||
val progress = progressAnimation.value
|
val progress = progressAnimation.value
|
||||||
val scale = lerp(1f, 1.6f, progress)
|
val scale = lerp(1f, 1.5f, progress)
|
||||||
scaleX = scale
|
scaleX = scale
|
||||||
scaleY = scale
|
scaleY = scale
|
||||||
},
|
},
|
||||||
onDrawBackdrop = { drawScope ->
|
onDrawBackdrop = { drawScope ->
|
||||||
drawIntoCanvas { canvas ->
|
drawIntoCanvas { canvas ->
|
||||||
canvas.save()
|
canvas.save()
|
||||||
canvas.drawRect(0f, 0f, size.width, size.height, Paint().apply {
|
canvas.drawRect(
|
||||||
color = if (indpendent) {
|
left = 0f,
|
||||||
if (isDarkTheme) Color(0xFF000000) else Color(0xFFF2F2F7)
|
top = 0f,
|
||||||
} else {
|
right = size.width,
|
||||||
if (isDarkTheme) Color(0xFF1C1C1E) else Color(0xFFFFFFFF)
|
bottom = size.height,
|
||||||
|
paint = Paint().apply {
|
||||||
|
color = if (isDarkTheme) Color(0xFF1C1C1E) else Color(0xFFF2F2F7)
|
||||||
}
|
}
|
||||||
})
|
)
|
||||||
scale(0.75f) {
|
scale(0.7f) {
|
||||||
drawScope()
|
drawScope()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -246,7 +248,7 @@ fun StyledSwitch(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES)
|
@Preview(uiMode = Configuration.UI_MODE_NIGHT_NO)
|
||||||
@Composable
|
@Composable
|
||||||
fun StyledSwitchPreview() {
|
fun StyledSwitchPreview() {
|
||||||
val isDarkTheme = isSystemInDarkTheme()
|
val isDarkTheme = isSystemInDarkTheme()
|
||||||
@@ -255,7 +257,7 @@ fun StyledSwitchPreview() {
|
|||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.background(backgroundColor)
|
.background(backgroundColor)
|
||||||
.width(100.dp)
|
.width(100.dp)
|
||||||
.height(400.dp),
|
.height(150.dp),
|
||||||
contentAlignment = Alignment.Center
|
contentAlignment = Alignment.Center
|
||||||
) {
|
) {
|
||||||
val checked = remember { mutableStateOf(true) }
|
val checked = remember { mutableStateOf(true) }
|
||||||
@@ -265,7 +267,6 @@ fun StyledSwitchPreview() {
|
|||||||
checked.value = it
|
checked.value = it
|
||||||
},
|
},
|
||||||
enabled = true,
|
enabled = true,
|
||||||
indpendent = false
|
|
||||||
)
|
)
|
||||||
// LaunchedEffect(Unit) {
|
// LaunchedEffect(Unit) {
|
||||||
// delay(1000)
|
// delay(1000)
|
||||||
|
|||||||
@@ -157,8 +157,7 @@ fun StyledToggle(
|
|||||||
checked = it
|
checked = it
|
||||||
cb()
|
cb()
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
indpendent = true
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -245,8 +244,7 @@ fun StyledToggle(
|
|||||||
checked = it
|
checked = it
|
||||||
cb()
|
cb()
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
indpendent = false
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -367,8 +365,7 @@ fun StyledToggle(
|
|||||||
checked = it
|
checked = it
|
||||||
cb()
|
cb()
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
indpendent = true
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -455,8 +452,7 @@ fun StyledToggle(
|
|||||||
checked = it
|
checked = it
|
||||||
cb()
|
cb()
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
indpendent = false
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -605,8 +601,7 @@ fun StyledToggle(
|
|||||||
checked = it
|
checked = it
|
||||||
cb()
|
cb()
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
indpendent = true
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -687,8 +682,7 @@ fun StyledToggle(
|
|||||||
checked = it
|
checked = it
|
||||||
cb()
|
cb()
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
indpendent = false
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user