From 8cfe19cd1328b89c68fcd11244a6cec780830624 Mon Sep 17 00:00:00 2001 From: DeathKhan Date: Wed, 18 Nov 2026 12:13:04 -0600 Subject: [PATCH] fix(apps): B in the folder name field saves the name and returns to the title (#2534) * fix(apps): B in the folder name field saves the name and returns to the title With a controller, B in the folder name field only hid the keyboard and left focus in the field. The field now takes B as its way out: the keyboard goes, the name is saved and focus lands on the folder title. AdbTextField gets an optional onBack for this; fields without it behave as before. * fix(apps): closing the bottom-screen keyboard also leaves the folder name field With typing on the bottom screen, B is handled there and only cleared focus, so the folder name was not saved. A field with onBack now leaves through it on that path too. * fix(apps): the folder sheet hands B to the name field while renaming The sheet's own B handler sits above the name field and could take the press first, closing the folder. While the name is being edited the sheet now treats B as leaving the field: the keyboard goes, the name is saved and focus lands on the title. * chore: drop the added comments * Return focus to the folder title once the frame settles after renaming * Only let the active typing request close the field --------- Co-authored-by: maxjivi05 --- .../droiddeck/launcher/ui/AndroidAppsPage.kt | 27 +++++++++++++++++-- .../launcher/ui/WirelessAdbFixPage.kt | 8 ++++-- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/ui/AndroidAppsPage.kt b/app/src/main/java/com/droiddeck/launcher/ui/AndroidAppsPage.kt index 4303dde0fe..8904f2c2d4 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/AndroidAppsPage.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/AndroidAppsPage.kt @@ -848,13 +848,28 @@ private fun FolderSheet( renaming = false } val firstApp = remember { FocusRequester() } + val title = remember { FocusRequester() } + var toTitle by remember { mutableStateOf(false) } + var titleFocused by remember { mutableStateOf(false) } + val sheetView = androidx.compose.ui.platform.LocalView.current + val leaveName = { + if (renaming) { + (ctx.getSystemService(android.content.Context.INPUT_METHOD_SERVICE) as? android.view.inputmethod.InputMethodManager) + ?.hideSoftInputFromWindow(sheetView.windowToken, 0) + toTitle = true + commit() + } + } val inputMode = LocalInputModeManager.current.inputMode val ff = LocalFrontFocus.current val grid = rememberLazyGridState() var closing by remember { mutableStateOf(false) } var inside by remember { mutableStateOf(false) } LaunchedEffect(renaming, inputMode) { - if (!renaming && !closing && inputMode == InputMode.Keyboard && apps.isNotEmpty()) { + if (!renaming && !closing && toTitle) { + focusWithinFrames({ titleFocused || closing }) { title } + toTitle = false + } else if (!renaming && !closing && inputMode == InputMode.Keyboard && apps.isNotEmpty()) { grid.scrollToItem(0) androidx.compose.runtime.withFrameNanos { } // After touch, focus starts outside the page and the first request is turned to the page's own entry, behind the sheet. Ask until it is in here. @@ -885,6 +900,12 @@ private fun FolderSheet( .clip(Shape16).background(pal.surfaceVariant.copy(alpha = 0.97f)) .glideBorder(false, Shape16, pal.signal, pal.signal.copy(alpha = 0.22f)) .pointerInput(Unit) { awaitEachGesture { awaitFirstDown(requireUnconsumed = false).consume() } } + .onPreviewKeyEvent { event -> + val k = event.nativeKeyEvent + if (!renaming || k.keyCode != KeyEvent.KEYCODE_BUTTON_B) return@onPreviewKeyEvent false + if (k.action == KeyEvent.ACTION_DOWN && k.repeatCount == 0) leaveName() + true + } .controllerBack(close) .onFocusChanged { inside = it.hasFocus } .focusProperties { @@ -901,7 +922,7 @@ private fun FolderSheet( AdbTextField( value = name, onValueChange = { name = it.take(40) }, label = stringResource(R.string.apps_folder_name), keyboardType = KeyboardType.Text, imeAction = ImeAction.Done, compact = true, showLabel = false, - placeholder = folder.name, focusOnShow = true, onDone = { commit() }, + placeholder = folder.name, focusOnShow = true, onDone = { commit() }, onBack = leaveName, ) } else { val src = remember { MutableInteractionSource() } @@ -914,6 +935,8 @@ private fun FolderSheet( modifier = Modifier.clip(Shape12) .background(if (hot) pal.signal.copy(alpha = 0.12f) else colors.onBackground.copy(alpha = 0.07f)) .glideBorder(hot, Shape12, pal.signal) + .focusRequester(title) + .onFocusChanged { titleFocused = it.isFocused } .hoverable(src) .clickable(interactionSource = src, indication = LocalIndication.current, onClickLabel = stringResource(R.string.apps_folder_rename), role = Role.Button, onClick = rename) .controllerConfirm(onClick = rename) diff --git a/app/src/main/java/com/droiddeck/launcher/ui/WirelessAdbFixPage.kt b/app/src/main/java/com/droiddeck/launcher/ui/WirelessAdbFixPage.kt index a685e414f3..276f82f79f 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/WirelessAdbFixPage.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/WirelessAdbFixPage.kt @@ -365,8 +365,10 @@ internal fun AdbTextField( onDone: (() -> Unit)? = null, focusOnShow: Boolean = false, showLabel: Boolean = true, + onBack: (() -> Unit)? = null, ) { val context = LocalContext.current + val onBackLatest = rememberUpdatedState(onBack) val focusAsked = remember { booleanArrayOf(false) } val palette = LocalPalette.current val onValueChangeLatest = rememberUpdatedState(onValueChange) @@ -384,7 +386,8 @@ internal fun AdbTextField( fun typeOnBottom(editText: EditText): Boolean { if (!bottomTypingLatest.value || !DualScreenPanel.attached) return false val text = editText.text.toString() - val request = TypingRequest( + lateinit var request: TypingRequest + request = TypingRequest( TextFieldValue(text, TextRange(editText.selectionStart.coerceIn(0, text.length), editText.selectionEnd.coerceIn(0, text.length))), ImeOptions(singleLine = true, keyboardType = keyboardType, imeAction = imeAction), { next -> @@ -392,7 +395,7 @@ internal fun AdbTextField( editText.setSelection(next.selection.start.coerceIn(0, next.text.length), next.selection.end.coerceIn(0, next.text.length)) }, { action -> editText.onEditorAction(imeActionFlag(action)) }, - { editText.post { editText.clearFocus() } }, + { editText.post { if (typingRequest[0] === request) onBackLatest.value?.invoke() ?: editText.clearFocus() } }, ) typingRequest[0] = request DualScreenPanel.startTyping(request) @@ -463,6 +466,7 @@ internal fun AdbTextField( ?.isVisible(androidx.core.view.WindowInsetsCompat.Type.ime()) == true if (hidingKeyboard) (view.context.getSystemService(android.content.Context.INPUT_METHOD_SERVICE) as? android.view.inputmethod.InputMethodManager) ?.hideSoftInputFromWindow(view.windowToken, 0) + onBackLatest.value?.let { hidingKeyboard = true; it() } } hidingKeyboard }