Skip to content

Commit c76fa97

Browse files
committed
fix: reset IME keyboard mode after sending a message
Call InputMethodManager.restartInput() after send to switch the keyboard back from emoji/sticker mode to the standard text input mode. Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent f4f57d8 commit c76fa97

4 files changed

Lines changed: 16 additions & 2 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,5 @@ serviceAccount.json
4141
# Maestro screenshot test artifacts
4242
maestro/screenshots/results/
4343
maestro/screenshots/diffs/
44+
45+
docs/superpowers/

apps/flipcash/features/messenger/src/main/kotlin/com/flipcash/app/messenger/internal/ChatViewModel.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.flipcash.app.messenger.internal
22

33
import androidx.compose.foundation.text.input.TextFieldState
44
import androidx.compose.foundation.text.input.clearText
5+
import androidx.compose.foundation.text.input.setTextAndPlaceCursorAtEnd
56
import androidx.compose.runtime.snapshotFlow
67
import androidx.lifecycle.viewModelScope
78
import androidx.paging.PagingData
@@ -465,7 +466,7 @@ internal class ChatViewModel @Inject constructor(
465466
val chatId = stateFlow.value.chatId ?: return@onEach
466467
if (textToSend.isBlank()) return@onEach
467468

468-
stateFlow.value.chatInputState.clearText()
469+
stateFlow.value.chatInputState.setTextAndPlaceCursorAtEnd("")
469470

470471
viewModelScope.launch {
471472
chatCoordinator.sendMessage(chatId, textToSend)

apps/flipcash/features/messenger/src/main/kotlin/com/flipcash/app/messenger/internal/screens/MessengerScreen.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,10 @@ private fun UserControlBottomBar(
303303
focusRequester = focusRequester,
304304
hint = "Message",
305305
state = state.chatInputState,
306-
onSendMessage = { dispatch(ChatViewModel.Event.SendMessage) },
306+
onSendMessage = {
307+
dispatch(ChatViewModel.Event.SendMessage)
308+
keyboard.restartInput()
309+
},
307310
)
308311

309312
LaunchedEffect(Unit) {

ui/components/src/main/kotlin/com/getcode/ui/utils/Keyboard.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package com.getcode.ui.utils
22

33
import android.annotation.SuppressLint
4+
import android.content.Context
45
import android.view.View
56
import android.view.ViewTreeObserver
7+
import android.view.inputmethod.InputMethodManager
68
import androidx.compose.runtime.Composable
79
import androidx.compose.runtime.DisposableEffect
810
import androidx.compose.runtime.State
@@ -55,6 +57,12 @@ class KeyboardController(
5557
softwareController?.hide()
5658
}
5759

60+
fun restartInput() {
61+
val imm = view.context.getSystemService(Context.INPUT_METHOD_SERVICE)
62+
as InputMethodManager
63+
imm.restartInput(view)
64+
}
65+
5866
fun hideIfVisible(block: () -> Unit = { }) {
5967
coroutineScope.launch {
6068
if (visible) {

0 commit comments

Comments
 (0)