I’m facing weird issue with software keyboard and ...
# compose
j
I’m facing weird issue with software keyboard and textField focus. I’ve a note textfield in “note-detail” screen which has got
Copy code
Modifier.clearFocusOnKeyboardDismiss
custom modifier which clears the textfield focus once softkeyboard is dismissed. It works fine until I move to “note-share” composable. Once I move to note-share composable and come back to note detail this time clearFocusOnKeyboardDismiss stops working, it doesn’t clears the focus. Refer this video.
z
What does your modifier look like? And what version of compose are you using?
j
Modifier to the note textfiled
Copy code
NoteTextField(
    textFieldValue = viewmodel.noteTextFieldState,
    onNoteChange = viewmodel::setOnNoteChange,
    isFocused = viewmodel.currentlyEditing == Note,
    onFocusChanged = {
        if (it.isFocused) {
            viewmodel.setCurrentlyEditingState(Note)
        }
    },
    shouldPadToNavigationBars = viewmodel.noteBackgroundChangerBottomSheetVisible,
    onSoftKeyboardDismissed = {
        viewmodel.setCurrentlyEditingState(None)
    },
    modifier = Modifier
        .padding(
            start = horizontalStartSpacing,
            end = horizontalEndSpacing,
            top = 8.dp
        )
        .fillMaxSize()
        .imePadding(),
    editable = textFieldEditable,
)
compose_version = ‘1.2.0-alpha08’
z
That looks like a composable, not a modifier, and I don’t see
clearFocusOnKeyboardDismiss
mentioned anywhere. That said, a parameter named
isFocused
seems suspicious, since the actual focus state of the field is determined and owned by the focus system itself, you can’t hoist that state. Can you share the implementation of
NoteTextField
as well?
j
heyy any update on this one?
z
Sorry, i got busy with a conference and this fell through the cracks. There are a couple places here where I could see race conditions happening, and again having two sources of truth for focus seems like something that will just produce all kinds of fun bugs. Without stepping through the code for your particular project I’m not sure exactly what’s going wrong, but I’d start by fixing those issues first..