Fix keyboard not auto-opening when editing a message (#6412)
* fix: auto-open keyboard when editing a message * fix: show keyboard on focused editor view instead of root view
This commit is contained in:
parent
e1e82cef08
commit
a30aed6a21
2 changed files with 10 additions and 8 deletions
|
|
@ -706,14 +706,14 @@ class MessageComposerPresenter(
|
||||||
val draft = createDraftFromState(markdownTextEditorState, richTextEditorState)
|
val draft = createDraftFromState(markdownTextEditorState, richTextEditorState)
|
||||||
updateDraft(draft, isVolatile = true).join()
|
updateDraft(draft, isVolatile = true).join()
|
||||||
}
|
}
|
||||||
setText(newComposerMode.content, markdownTextEditorState, richTextEditorState)
|
setText(newComposerMode.content, markdownTextEditorState, richTextEditorState, requestFocus = true)
|
||||||
}
|
}
|
||||||
is MessageComposerMode.EditCaption -> {
|
is MessageComposerMode.EditCaption -> {
|
||||||
if (currentComposerMode.isEditing.not()) {
|
if (currentComposerMode.isEditing.not()) {
|
||||||
val draft = createDraftFromState(markdownTextEditorState, richTextEditorState)
|
val draft = createDraftFromState(markdownTextEditorState, richTextEditorState)
|
||||||
updateDraft(draft, isVolatile = true).join()
|
updateDraft(draft, isVolatile = true).join()
|
||||||
}
|
}
|
||||||
setText(newComposerMode.content, markdownTextEditorState, richTextEditorState)
|
setText(newComposerMode.content, markdownTextEditorState, richTextEditorState, requestFocus = true)
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
// When coming from edit, just clear the composer as it'd be weird to reset a volatile draft in this scenario.
|
// When coming from edit, just clear the composer as it'd be weird to reset a volatile draft in this scenario.
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,6 @@ import androidx.compose.runtime.rememberUpdatedState
|
||||||
import androidx.compose.ui.platform.LocalView
|
import androidx.compose.ui.platform.LocalView
|
||||||
import androidx.compose.ui.viewinterop.AndroidView
|
import androidx.compose.ui.viewinterop.AndroidView
|
||||||
import io.element.android.libraries.androidutils.ui.awaitWindowFocus
|
import io.element.android.libraries.androidutils.ui.awaitWindowFocus
|
||||||
import io.element.android.libraries.androidutils.ui.isKeyboardVisible
|
|
||||||
import io.element.android.libraries.androidutils.ui.showKeyboard
|
import io.element.android.libraries.androidutils.ui.showKeyboard
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -42,12 +41,15 @@ internal fun <T> SoftKeyboardEffect(
|
||||||
// Await window focus in case returning from a dialog
|
// Await window focus in case returning from a dialog
|
||||||
view.awaitWindowFocus()
|
view.awaitWindowFocus()
|
||||||
|
|
||||||
if (!view.isKeyboardVisible()) {
|
// First, focus the correct editor view
|
||||||
// Show the keyboard, temporarily using the root view for focus
|
latestOnRequestFocus()
|
||||||
view.showKeyboard(andRequestFocus = true)
|
|
||||||
|
|
||||||
// Refocus to the correct view
|
// Show keyboard on the focused editor view rather than the root view,
|
||||||
latestOnRequestFocus()
|
// as some devices require showSoftInput on the actual input view.
|
||||||
|
// Using post to run after the current focus pass completes.
|
||||||
|
view.post {
|
||||||
|
val focusedView = view.findFocus() ?: view
|
||||||
|
focusedView.showKeyboard()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue