Fix manual edit on Tracker's chapter doesn't work (must hit Done on keyboard to work)
This commit is contained in:
parent
bc16959170
commit
4909d0ce57
1 changed files with 20 additions and 13 deletions
|
|
@ -15,6 +15,7 @@ import androidx.compose.foundation.lazy.itemsIndexed
|
||||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
import androidx.compose.foundation.text.BasicTextField
|
import androidx.compose.foundation.text.BasicTextField
|
||||||
|
import androidx.compose.foundation.text.KeyboardActions
|
||||||
import androidx.compose.foundation.text.KeyboardOptions
|
import androidx.compose.foundation.text.KeyboardOptions
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
|
|
@ -147,23 +148,29 @@ private fun <T> WheelPicker(
|
||||||
}
|
}
|
||||||
|
|
||||||
val scope = rememberCoroutineScope()
|
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(
|
BasicTextField(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.align(Alignment.Center)
|
.align(Alignment.Center)
|
||||||
.showSoftKeyboard(true)
|
.showSoftKeyboard(true)
|
||||||
.clearFocusOnSoftKeyboardHide {
|
// KMK -->
|
||||||
scope.launch {
|
.clearFocusOnSoftKeyboardHide { onDone() },
|
||||||
items
|
/* clearFocusOnSoftKeyboardHide doesn't work because onSoftKeyboardHide won't trigger
|
||||||
.indexOfFirst { it.toString() == value.text }
|
a recomposition => use keyboardActions instead */
|
||||||
.takeIf { it >= 0 }
|
keyboardActions = KeyboardActions(onDone = { onDone() }),
|
||||||
?.apply {
|
// KMK <--
|
||||||
internalOnSelectionChanged(this)
|
|
||||||
lazyListState.scrollToItem(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
showManualInput = false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
value = value,
|
value = value,
|
||||||
onValueChange = { value = it },
|
onValueChange = { value = it },
|
||||||
singleLine = true,
|
singleLine = true,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue