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:
parent
8d7ada9e72
commit
afacef0146
4 changed files with 25 additions and 12 deletions
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()
|
callback?.onRoomDetailsClicked()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onEventClicked(event: TimelineItem.Event) {
|
override fun onEventClicked(event: TimelineItem.Event): Boolean {
|
||||||
processEventClicked(event)
|
return processEventClicked(event)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPreviewAttachments(attachments: ImmutableList<Attachment>) {
|
override fun onPreviewAttachments(attachments: ImmutableList<Attachment>) {
|
||||||
|
|
@ -239,8 +239,8 @@ class MessagesFlowNode @AssistedInject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun processEventClicked(event: TimelineItem.Event) {
|
private fun processEventClicked(event: TimelineItem.Event): Boolean {
|
||||||
when (event.content) {
|
return when (event.content) {
|
||||||
is TimelineItemImageContent -> {
|
is TimelineItemImageContent -> {
|
||||||
val navTarget = NavTarget.MediaViewer(
|
val navTarget = NavTarget.MediaViewer(
|
||||||
mediaInfo = MediaInfo(
|
mediaInfo = MediaInfo(
|
||||||
|
|
@ -253,6 +253,7 @@ class MessagesFlowNode @AssistedInject constructor(
|
||||||
thumbnailSource = event.content.thumbnailSource,
|
thumbnailSource = event.content.thumbnailSource,
|
||||||
)
|
)
|
||||||
overlay.show(navTarget)
|
overlay.show(navTarget)
|
||||||
|
true
|
||||||
}
|
}
|
||||||
is TimelineItemStickerContent -> {
|
is TimelineItemStickerContent -> {
|
||||||
/* Sticker may have an empty url and no thumbnail
|
/* Sticker may have an empty url and no thumbnail
|
||||||
|
|
@ -269,6 +270,9 @@ class MessagesFlowNode @AssistedInject constructor(
|
||||||
thumbnailSource = event.content.thumbnailSource,
|
thumbnailSource = event.content.thumbnailSource,
|
||||||
)
|
)
|
||||||
overlay.show(navTarget)
|
overlay.show(navTarget)
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
is TimelineItemVideoContent -> {
|
is TimelineItemVideoContent -> {
|
||||||
|
|
@ -283,6 +287,7 @@ class MessagesFlowNode @AssistedInject constructor(
|
||||||
thumbnailSource = event.content.thumbnailSource,
|
thumbnailSource = event.content.thumbnailSource,
|
||||||
)
|
)
|
||||||
overlay.show(navTarget)
|
overlay.show(navTarget)
|
||||||
|
true
|
||||||
}
|
}
|
||||||
is TimelineItemFileContent -> {
|
is TimelineItemFileContent -> {
|
||||||
val navTarget = NavTarget.MediaViewer(
|
val navTarget = NavTarget.MediaViewer(
|
||||||
|
|
@ -296,6 +301,7 @@ class MessagesFlowNode @AssistedInject constructor(
|
||||||
thumbnailSource = event.content.thumbnailSource,
|
thumbnailSource = event.content.thumbnailSource,
|
||||||
)
|
)
|
||||||
overlay.show(navTarget)
|
overlay.show(navTarget)
|
||||||
|
true
|
||||||
}
|
}
|
||||||
is TimelineItemAudioContent -> {
|
is TimelineItemAudioContent -> {
|
||||||
val navTarget = NavTarget.MediaViewer(
|
val navTarget = NavTarget.MediaViewer(
|
||||||
|
|
@ -309,6 +315,7 @@ class MessagesFlowNode @AssistedInject constructor(
|
||||||
thumbnailSource = null,
|
thumbnailSource = null,
|
||||||
)
|
)
|
||||||
overlay.show(navTarget)
|
overlay.show(navTarget)
|
||||||
|
true
|
||||||
}
|
}
|
||||||
is TimelineItemLocationContent -> {
|
is TimelineItemLocationContent -> {
|
||||||
val navTarget = NavTarget.LocationViewer(
|
val navTarget = NavTarget.LocationViewer(
|
||||||
|
|
@ -316,8 +323,9 @@ class MessagesFlowNode @AssistedInject constructor(
|
||||||
description = event.content.description,
|
description = event.content.description,
|
||||||
)
|
)
|
||||||
overlay.show(navTarget)
|
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.LocalTimelineItemPresenterFactories
|
||||||
import io.element.android.features.messages.impl.timeline.di.TimelineItemPresenterFactories
|
import io.element.android.features.messages.impl.timeline.di.TimelineItemPresenterFactories
|
||||||
import io.element.android.features.messages.impl.timeline.model.TimelineItem
|
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.mediaplayer.api.MediaPlayer
|
||||||
import io.element.android.libraries.di.RoomScope
|
import io.element.android.libraries.di.RoomScope
|
||||||
import io.element.android.libraries.matrix.api.core.EventId
|
import io.element.android.libraries.matrix.api.core.EventId
|
||||||
|
|
@ -48,7 +49,7 @@ class MessagesNode @AssistedInject constructor(
|
||||||
@Assisted plugins: List<Plugin>,
|
@Assisted plugins: List<Plugin>,
|
||||||
private val room: MatrixRoom,
|
private val room: MatrixRoom,
|
||||||
private val analyticsService: AnalyticsService,
|
private val analyticsService: AnalyticsService,
|
||||||
private val presenterFactory: MessagesPresenter.Factory,
|
presenterFactory: MessagesPresenter.Factory,
|
||||||
private val timelineItemPresenterFactories: TimelineItemPresenterFactories,
|
private val timelineItemPresenterFactories: TimelineItemPresenterFactories,
|
||||||
private val mediaPlayer: MediaPlayer,
|
private val mediaPlayer: MediaPlayer,
|
||||||
) : Node(buildContext, plugins = plugins), MessagesNavigator {
|
) : Node(buildContext, plugins = plugins), MessagesNavigator {
|
||||||
|
|
@ -58,7 +59,7 @@ class MessagesNode @AssistedInject constructor(
|
||||||
|
|
||||||
interface Callback : Plugin {
|
interface Callback : Plugin {
|
||||||
fun onRoomDetailsClicked()
|
fun onRoomDetailsClicked()
|
||||||
fun onEventClicked(event: TimelineItem.Event)
|
fun onEventClicked(event: TimelineItem.Event): Boolean
|
||||||
fun onPreviewAttachments(attachments: ImmutableList<Attachment>)
|
fun onPreviewAttachments(attachments: ImmutableList<Attachment>)
|
||||||
fun onUserDataClicked(userId: UserId)
|
fun onUserDataClicked(userId: UserId)
|
||||||
fun onShowEventDebugInfoClicked(eventId: EventId?, debugInfo: TimelineItemDebugInfo)
|
fun onShowEventDebugInfoClicked(eventId: EventId?, debugInfo: TimelineItemDebugInfo)
|
||||||
|
|
@ -85,8 +86,8 @@ class MessagesNode @AssistedInject constructor(
|
||||||
callback?.onRoomDetailsClicked()
|
callback?.onRoomDetailsClicked()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onEventClicked(event: TimelineItem.Event) {
|
private fun onEventClicked(event: TimelineItem.Event): Boolean {
|
||||||
callback?.onEventClicked(event)
|
return callback?.onEventClicked(event).orFalse()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onPreviewAttachments(attachments: ImmutableList<Attachment>) {
|
private fun onPreviewAttachments(attachments: ImmutableList<Attachment>) {
|
||||||
|
|
|
||||||
|
|
@ -117,7 +117,7 @@ fun MessagesView(
|
||||||
state: MessagesState,
|
state: MessagesState,
|
||||||
onBackPressed: () -> Unit,
|
onBackPressed: () -> Unit,
|
||||||
onRoomDetailsClicked: () -> Unit,
|
onRoomDetailsClicked: () -> Unit,
|
||||||
onEventClicked: (event: TimelineItem.Event) -> Unit,
|
onEventClicked: (event: TimelineItem.Event) -> Boolean,
|
||||||
onUserDataClicked: (UserId) -> Unit,
|
onUserDataClicked: (UserId) -> Unit,
|
||||||
onPreviewAttachments: (ImmutableList<Attachment>) -> Unit,
|
onPreviewAttachments: (ImmutableList<Attachment>) -> Unit,
|
||||||
onSendLocationClicked: () -> Unit,
|
onSendLocationClicked: () -> Unit,
|
||||||
|
|
@ -148,7 +148,10 @@ fun MessagesView(
|
||||||
|
|
||||||
fun onMessageClicked(event: TimelineItem.Event) {
|
fun onMessageClicked(event: TimelineItem.Event) {
|
||||||
Timber.v("OnMessageClicked= ${event.id}")
|
Timber.v("OnMessageClicked= ${event.id}")
|
||||||
onEventClicked(event)
|
val hideKeyboard = onEventClicked(event)
|
||||||
|
if (hideKeyboard) {
|
||||||
|
localView.hideKeyboard()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onMessageLongClicked(event: TimelineItem.Event) {
|
fun onMessageLongClicked(event: TimelineItem.Event) {
|
||||||
|
|
@ -569,7 +572,7 @@ internal fun MessagesViewPreview(@PreviewParameter(MessagesStateProvider::class)
|
||||||
state = state,
|
state = state,
|
||||||
onBackPressed = {},
|
onBackPressed = {},
|
||||||
onRoomDetailsClicked = {},
|
onRoomDetailsClicked = {},
|
||||||
onEventClicked = {},
|
onEventClicked = { false },
|
||||||
onPreviewAttachments = {},
|
onPreviewAttachments = {},
|
||||||
onUserDataClicked = {},
|
onUserDataClicked = {},
|
||||||
onSendLocationClicked = {},
|
onSendLocationClicked = {},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue