Hide keyboard when tapping on a message in the timeline (#2187)
* Hide keyboard when tapping on a message in the timeline if it would result in navigating to another screen
This commit is contained in:
committed by
GitHub
parent
cc13df3efc
commit
3954612a72
1
changelog.d/2182.bugfix
Normal file
1
changelog.d/2182.bugfix
Normal file
@@ -0,0 +1 @@
|
||||
Hide keyboard when tapping on a message in the timeline.
|
||||
@@ -139,8 +139,8 @@ class MessagesFlowNode @AssistedInject constructor(
|
||||
callback?.onRoomDetailsClicked()
|
||||
}
|
||||
|
||||
override fun onEventClicked(event: TimelineItem.Event) {
|
||||
processEventClicked(event)
|
||||
override fun onEventClicked(event: TimelineItem.Event): Boolean {
|
||||
return processEventClicked(event)
|
||||
}
|
||||
|
||||
override fun onPreviewAttachments(attachments: ImmutableList<Attachment>) {
|
||||
@@ -239,8 +239,8 @@ class MessagesFlowNode @AssistedInject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
private fun processEventClicked(event: TimelineItem.Event) {
|
||||
when (event.content) {
|
||||
private fun processEventClicked(event: TimelineItem.Event): Boolean {
|
||||
return when (event.content) {
|
||||
is TimelineItemImageContent -> {
|
||||
val navTarget = NavTarget.MediaViewer(
|
||||
mediaInfo = MediaInfo(
|
||||
@@ -253,6 +253,7 @@ class MessagesFlowNode @AssistedInject constructor(
|
||||
thumbnailSource = event.content.thumbnailSource,
|
||||
)
|
||||
overlay.show(navTarget)
|
||||
true
|
||||
}
|
||||
is TimelineItemStickerContent -> {
|
||||
/* Sticker may have an empty url and no thumbnail
|
||||
@@ -269,6 +270,9 @@ class MessagesFlowNode @AssistedInject constructor(
|
||||
thumbnailSource = event.content.thumbnailSource,
|
||||
)
|
||||
overlay.show(navTarget)
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
is TimelineItemVideoContent -> {
|
||||
@@ -283,6 +287,7 @@ class MessagesFlowNode @AssistedInject constructor(
|
||||
thumbnailSource = event.content.thumbnailSource,
|
||||
)
|
||||
overlay.show(navTarget)
|
||||
true
|
||||
}
|
||||
is TimelineItemFileContent -> {
|
||||
val navTarget = NavTarget.MediaViewer(
|
||||
@@ -296,6 +301,7 @@ class MessagesFlowNode @AssistedInject constructor(
|
||||
thumbnailSource = event.content.thumbnailSource,
|
||||
)
|
||||
overlay.show(navTarget)
|
||||
true
|
||||
}
|
||||
is TimelineItemAudioContent -> {
|
||||
val navTarget = NavTarget.MediaViewer(
|
||||
@@ -309,6 +315,7 @@ class MessagesFlowNode @AssistedInject constructor(
|
||||
thumbnailSource = null,
|
||||
)
|
||||
overlay.show(navTarget)
|
||||
true
|
||||
}
|
||||
is TimelineItemLocationContent -> {
|
||||
val navTarget = NavTarget.LocationViewer(
|
||||
@@ -316,8 +323,9 @@ class MessagesFlowNode @AssistedInject constructor(
|
||||
description = event.content.description,
|
||||
)
|
||||
overlay.show(navTarget)
|
||||
true
|
||||
}
|
||||
else -> Unit
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ import io.element.android.features.messages.impl.attachments.Attachment
|
||||
import io.element.android.features.messages.impl.timeline.di.LocalTimelineItemPresenterFactories
|
||||
import io.element.android.features.messages.impl.timeline.di.TimelineItemPresenterFactories
|
||||
import io.element.android.features.messages.impl.timeline.model.TimelineItem
|
||||
import io.element.android.libraries.core.bool.orFalse
|
||||
import io.element.android.libraries.mediaplayer.api.MediaPlayer
|
||||
import io.element.android.libraries.di.RoomScope
|
||||
import io.element.android.libraries.matrix.api.core.EventId
|
||||
@@ -48,7 +49,7 @@ class MessagesNode @AssistedInject constructor(
|
||||
@Assisted plugins: List<Plugin>,
|
||||
private val room: MatrixRoom,
|
||||
private val analyticsService: AnalyticsService,
|
||||
private val presenterFactory: MessagesPresenter.Factory,
|
||||
presenterFactory: MessagesPresenter.Factory,
|
||||
private val timelineItemPresenterFactories: TimelineItemPresenterFactories,
|
||||
private val mediaPlayer: MediaPlayer,
|
||||
) : Node(buildContext, plugins = plugins), MessagesNavigator {
|
||||
@@ -58,7 +59,7 @@ class MessagesNode @AssistedInject constructor(
|
||||
|
||||
interface Callback : Plugin {
|
||||
fun onRoomDetailsClicked()
|
||||
fun onEventClicked(event: TimelineItem.Event)
|
||||
fun onEventClicked(event: TimelineItem.Event): Boolean
|
||||
fun onPreviewAttachments(attachments: ImmutableList<Attachment>)
|
||||
fun onUserDataClicked(userId: UserId)
|
||||
fun onShowEventDebugInfoClicked(eventId: EventId?, debugInfo: TimelineItemDebugInfo)
|
||||
@@ -85,8 +86,8 @@ class MessagesNode @AssistedInject constructor(
|
||||
callback?.onRoomDetailsClicked()
|
||||
}
|
||||
|
||||
private fun onEventClicked(event: TimelineItem.Event) {
|
||||
callback?.onEventClicked(event)
|
||||
private fun onEventClicked(event: TimelineItem.Event): Boolean {
|
||||
return callback?.onEventClicked(event).orFalse()
|
||||
}
|
||||
|
||||
private fun onPreviewAttachments(attachments: ImmutableList<Attachment>) {
|
||||
|
||||
@@ -117,7 +117,7 @@ fun MessagesView(
|
||||
state: MessagesState,
|
||||
onBackPressed: () -> Unit,
|
||||
onRoomDetailsClicked: () -> Unit,
|
||||
onEventClicked: (event: TimelineItem.Event) -> Unit,
|
||||
onEventClicked: (event: TimelineItem.Event) -> Boolean,
|
||||
onUserDataClicked: (UserId) -> Unit,
|
||||
onPreviewAttachments: (ImmutableList<Attachment>) -> Unit,
|
||||
onSendLocationClicked: () -> Unit,
|
||||
@@ -148,7 +148,10 @@ fun MessagesView(
|
||||
|
||||
fun onMessageClicked(event: TimelineItem.Event) {
|
||||
Timber.v("OnMessageClicked= ${event.id}")
|
||||
onEventClicked(event)
|
||||
val hideKeyboard = onEventClicked(event)
|
||||
if (hideKeyboard) {
|
||||
localView.hideKeyboard()
|
||||
}
|
||||
}
|
||||
|
||||
fun onMessageLongClicked(event: TimelineItem.Event) {
|
||||
@@ -569,7 +572,7 @@ internal fun MessagesViewPreview(@PreviewParameter(MessagesStateProvider::class)
|
||||
state = state,
|
||||
onBackPressed = {},
|
||||
onRoomDetailsClicked = {},
|
||||
onEventClicked = {},
|
||||
onEventClicked = { false },
|
||||
onPreviewAttachments = {},
|
||||
onUserDataClicked = {},
|
||||
onSendLocationClicked = {},
|
||||
|
||||
Reference in New Issue
Block a user