Focus of textarea goes shortly away and comes back

I have following in the footer of a SilicaListview. When pushing the send button, keyboard goes very shortly away, and then comes back and gives focus again to the Textarea.

Is there a possibility to avoid that focus shortly goes away, and that keyboard just stays open and focus is kept to the textarea?

            footer :         Column {
                id: replyColumn
                width: parent.width

                Item {
                    id: inputRow
                    width: parent.width
                    height: replyField.height


                    TextArea {
                        id: replyField
                        width: parent.width - attachButton.width - sendButton.width - 2 * Theme.paddingSmall - Theme.horizontalPageMargin
                        //: Label for message
                        //% "Message"
                        label: qsTrId("message-la-message")
                        //: Placeholder for send message
                        //% "Send message"
                        placeholderText: qsTrId("message-ph-sendmessage")
                        hideLabelOnEmptyField: false
                        backgroundStyle: TextEditor.FilledBackground
                        horizontalAlignment: TextInput.AlignLeft
    //                    height: Math.min(implicitHeight, Theme.itemSizeExtraLarge * 2)
                        Component.onCompleted: {
                            page.replyFieldRef = replyField
                            replyField.text = Drafts.loadDraft(roomId)


                        }

                    }

                    Row {
                        id: buttonRow
                        anchors.right: parent.right
                        anchors.bottom: parent.bottom
                        spacing: Theme.paddingSmall

                        Button {
                            id: attachButton
                            width: Theme.iconSizeMedium + 2 * Theme.paddingSmall
                            height: width
                            icon.source: "image://theme/icon-m-attach"
                            onClicked:
                                pageStack.animatorPush(Qt.resolvedUrl("ImageSelectPage.qml"))
                        }

                        Button {
                            id: sendButton
                            width: Theme.iconSizeMedium + 2 * Theme.paddingSmall
                            height: width
                            icon.source: "image://theme/icon-m-send"
                            onClicked: {
                                if (replyField.text !== "") {
                                    //: Notification when sending message
                                    //% "Sending message"
                                    Notices.show(qsTrId("message-no-messagesending"), Notice.Short, Notice.Center)
                                    console.log("fake send, no backend call")
                                    matrixSession.sendTextMessage(roomId, replyField.text)
                                    replyField.forceActiveFocus()
                                }
                            }
                        }
                    }
                }

            }

3 Likes

Well, once you click sendButton, it gets focus, the textarea loses focus ergo the VKB goes away. Then you call forceActiveFocus and it appears again.

To quote a great movie:

I am drowning and you are describing the water.

I have no immediate solution, except you could trigger the sending using EnterKey.onClicked from the VKB - but usually that’s not what you want in text messages.

Maybe if you move the send button into rightItem that issue goes away but I haven’t tested that.

4 Likes

Great, the rightItem suggestion works. Thanks a lot!

2 Likes

Real champ! Thank you Nephros for being so valuable member of the community❤

3 Likes