Skip to content

Commit a85b179

Browse files
committed
library: Cancel transition on quick click
1 parent 9a0b5e9 commit a85b179

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

gradle/libs.versions.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ androidx-window = "1.3.0"
99
compose-plugin = "1.7.0"
1010
dokka = "1.9.20"
1111
kotlin = "2.0.21"
12+
kotlinx-datetime = "0.6.0"
1213

1314
[libraries]
1415
androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activity-compose" }
1516
androidx-window = { group = "androidx.window", name = "window", version.ref = "androidx-window" }
1617
jetbrains-compose-window-size = { module = "org.jetbrains.compose.material3:material3-window-size-class", version.ref = "compose-plugin" }
18+
jetbrains-kotlinx-datetime = { module = "org.jetbrains.kotlinx:kotlinx-datetime", version.ref = "kotlinx-datetime" }
1719

1820
[plugins]
1921
android-application = { id = "com.android.application", version.ref = "androidGradlePlugin" }

miuix/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ kotlin {
4747
implementation(compose.ui)
4848
implementation(compose.components.resources)
4949
implementation(libs.jetbrains.compose.window.size)
50+
implementation(libs.jetbrains.kotlinx.datetime)
5051
}
5152
}
5253
}

miuix/src/commonMain/kotlin/top/yukonga/miuix/kmp/utils/Indication.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import androidx.compose.ui.node.DelegatableNode
1515
import androidx.compose.ui.node.DrawModifierNode
1616
import androidx.compose.ui.node.invalidateDraw
1717
import kotlinx.coroutines.launch
18+
import kotlinx.datetime.Clock
1819

1920
/**
2021
* Miuix default [Indication] that draws a rectangular overlay when pressed.
@@ -37,6 +38,8 @@ class MiuixIndication(
3738
private var isHovered = false
3839
private var isFocused = false
3940
private var isPopupExpanded = false
41+
private var lastClickTime = 0L
42+
private val clickThreshold = 300L
4043
private val animatedAlpha = Animatable(0f)
4144

4245
override fun onAttach() {
@@ -62,6 +65,11 @@ class MiuixIndication(
6265

6366
is PressInteraction.Cancel, is PressInteraction.Release -> {
6467
isPressed = false
68+
val currentTime = Clock.System.now().toEpochMilliseconds()
69+
if (currentTime - lastClickTime < clickThreshold) {
70+
animatedAlpha.snapTo(0f)
71+
}
72+
lastClickTime = currentTime
6573
if (!isHovered && !isFocused && !isPopupExpanded) {
6674
animatedAlpha.animateTo(0f)
6775
} else if (isPopupExpanded) {

0 commit comments

Comments
 (0)