Skip to content

Commit cef9739

Browse files
authored
reset multi-tap state after one second delay (#1106)
1 parent 4120fa2 commit cef9739

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

app/src/main/java/com/dessalines/thumbkey/ui/components/keyboard/KeyboardKey.kt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ import com.dessalines.thumbkey.utils.toPx
7676
import kotlin.math.abs
7777
import kotlin.math.max
7878
import kotlin.math.min
79+
import kotlin.time.Duration.Companion.seconds
80+
import kotlin.time.TimeMark
81+
import kotlin.time.TimeSource
7982

8083
@OptIn(ExperimentalFoundationApi::class)
8184
@Composable
@@ -85,7 +88,7 @@ fun KeyboardKey(
8588
// key will attempt to capture it instead. This is derived automatically from the keyboard
8689
// layout, and should not be set directly in the keyboard definition.
8790
ghostKey: KeyItemC? = null,
88-
lastAction: MutableState<KeyAction?>,
91+
lastAction: MutableState<Pair<KeyAction, TimeMark>?>,
8992
animationHelperSpeed: Int,
9093
animationSpeed: Int,
9194
autoCapitalize: Boolean,
@@ -210,14 +213,14 @@ fun KeyboardKey(
210213
onClick = {
211214
// Set the last key info, and the tap count
212215
val cAction = key.center.action
213-
lastAction.value?.let { lastAction ->
214-
if (lastAction == cAction && !ime.didCursorMove()) {
216+
lastAction.value?.let { (lastAction, time) ->
217+
if (time.elapsedNow() < 1.seconds && lastAction == cAction && !ime.didCursorMove()) {
215218
tapCount += 1
216219
} else {
217220
tapCount = 0
218221
}
219222
}
220-
lastAction.value = cAction
223+
lastAction.value = Pair(cAction, TimeSource.Monotonic.markNow())
221224

222225
// Set the correct action
223226
val action = tapActions[tapCount % tapActions.size]
@@ -562,7 +565,7 @@ fun KeyboardKey(
562565

563566
// Set tapCount and lastAction to avoid issues with multitap after slide
564567
tapCount = 0
565-
lastAction.value = action
568+
lastAction.value = Pair(action, TimeSource.Monotonic.markNow())
566569

567570
// Reset the drags
568571
offsetX = 0f

app/src/main/java/com/dessalines/thumbkey/ui/components/keyboard/KeyboardScreen.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ import com.dessalines.thumbkey.utils.TAG
7272
import com.dessalines.thumbkey.utils.getKeyboardMode
7373
import com.dessalines.thumbkey.utils.keyboardPositionToAlignment
7474
import com.dessalines.thumbkey.utils.toBool
75+
import kotlin.time.TimeMark
7576

7677
@Composable
7778
fun KeyboardScreen(
@@ -96,7 +97,7 @@ fun KeyboardScreen(
9697
}
9798

9899
// TODO get rid of this crap
99-
val lastAction = remember { mutableStateOf<KeyAction?>(null) }
100+
val lastAction = remember { mutableStateOf<Pair<KeyAction, TimeMark>?>(null) }
100101

101102
val keyboardDefinition =
102103
KeyboardLayout.entries.sortedBy { it.ordinal }[

0 commit comments

Comments
 (0)