Skip to content

Commit

Permalink
Hide the keyboard when navigating from the chat room screen (#3878)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmartinesp authored Nov 15, 2024
1 parent bb69e1e commit 8420c82
Showing 1 changed file with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ fun MessagesView(
// This is needed because the composer is inside an AndroidView that can't be affected by the FocusManager in Compose
val localView = LocalView.current

fun hidingKeyboard(block: () -> Unit) {
localView.hideKeyboard()
block()
}

fun onContentClick(event: TimelineItem.Event) {
Timber.v("onMessageClick= ${event.id}")
val hideKeyboard = onEventContentClick(event)
Expand All @@ -152,13 +157,14 @@ fun MessagesView(

fun onMessageLongClick(event: TimelineItem.Event) {
Timber.v("OnMessageLongClicked= ${event.id}")
localView.hideKeyboard()
state.actionListState.eventSink(
ActionListEvents.ComputeForMessage(
event = event,
userEventPermissions = state.userEventPermissions,
hidingKeyboard {
state.actionListState.eventSink(
ActionListEvents.ComputeForMessage(
event = event,
userEventPermissions = state.userEventPermissions,
)
)
)
}
}

fun onActionSelected(action: TimelineItemAction, event: TimelineItem.Event) {
Expand Down Expand Up @@ -189,13 +195,8 @@ fun MessagesView(
roomAvatar = state.roomAvatar.dataOrNull(),
heroes = state.heroes,
roomCallState = state.roomCallState,
onBackClick = {
// Since the textfield is now based on an Android view, this is no longer done automatically.
// We need to hide the keyboard when navigating out of this screen.
localView.hideKeyboard()
onBackClick()
},
onRoomDetailsClick = onRoomDetailsClick,
onBackClick = { hidingKeyboard { onBackClick() } },
onRoomDetailsClick = { hidingKeyboard { onRoomDetailsClick() } },
onJoinCallClick = onJoinCallClick,
)
}
Expand All @@ -208,7 +209,7 @@ fun MessagesView(
.consumeWindowInsets(padding),
onContentClick = ::onContentClick,
onMessageLongClick = ::onMessageLongClick,
onUserDataClick = onUserDataClick,
onUserDataClick = { hidingKeyboard { onUserDataClick(it) } },
onLinkClick = onLinkClick,
onReactionClick = ::onEmojiReactionClick,
onReactionLongClick = ::onEmojiReactionLongClick,
Expand Down

0 comments on commit 8420c82

Please sign in to comment.