From 4909d0ce575652a4157e4d3b699362c34e2b1c2d Mon Sep 17 00:00:00 2001 From: "Cuong M. Tran" Date: Sat, 15 Jun 2024 18:48:59 +0700 Subject: [PATCH] Fix manual edit on Tracker's chapter doesn't work (must hit Done on keyboard to work) --- .../core/components/WheelPicker.kt | 33 +++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/presentation-core/src/main/java/tachiyomi/presentation/core/components/WheelPicker.kt b/presentation-core/src/main/java/tachiyomi/presentation/core/components/WheelPicker.kt index 9cbb156c6..623072642 100644 --- a/presentation-core/src/main/java/tachiyomi/presentation/core/components/WheelPicker.kt +++ b/presentation-core/src/main/java/tachiyomi/presentation/core/components/WheelPicker.kt @@ -15,6 +15,7 @@ import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.text.BasicTextField +import androidx.compose.foundation.text.KeyboardActions import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text @@ -147,23 +148,29 @@ private fun WheelPicker( } val scope = rememberCoroutineScope() + fun onDone() { + scope.launch { + items + .indexOfFirst { it.toString() == value.text } + .takeIf { it >= 0 } + ?.apply { + internalOnSelectionChanged(this) + lazyListState.scrollToItem(this) + } + + showManualInput = false + } + } BasicTextField( modifier = Modifier .align(Alignment.Center) .showSoftKeyboard(true) - .clearFocusOnSoftKeyboardHide { - scope.launch { - items - .indexOfFirst { it.toString() == value.text } - .takeIf { it >= 0 } - ?.apply { - internalOnSelectionChanged(this) - lazyListState.scrollToItem(this) - } - - showManualInput = false - } - }, + // KMK --> + .clearFocusOnSoftKeyboardHide { onDone() }, + /* clearFocusOnSoftKeyboardHide doesn't work because onSoftKeyboardHide won't trigger + a recomposition => use keyboardActions instead */ + keyboardActions = KeyboardActions(onDone = { onDone() }), + // KMK <-- value = value, onValueChange = { value = it }, singleLine = true,