From 13875e61f8f1b16eb2e83467706d8cfc092609ae Mon Sep 17 00:00:00 2001 From: Stefan Ceriu Date: Fri, 13 Dec 2024 17:34:19 +0200 Subject: [PATCH] Fix `MediaFileRoomTimelineContent` tap gesture taking over media event timeline taps. --- .../AudioFileEventsTimelineView.swift | 3 +- .../FileMediaEventsTimelineView.swift | 3 +- .../AudioRoomTimelineView.swift | 10 ++++--- .../FileRoomTimelineView.swift | 29 +++++++++++-------- 4 files changed, 25 insertions(+), 20 deletions(-) diff --git a/ElementX/Sources/Screens/MediaEventsTimelineScreen/View/TimelineViews/AudioFileEventsTimelineView.swift b/ElementX/Sources/Screens/MediaEventsTimelineScreen/View/TimelineViews/AudioFileEventsTimelineView.swift index 7786bc7997..b1175e1838 100644 --- a/ElementX/Sources/Screens/MediaEventsTimelineScreen/View/TimelineViews/AudioFileEventsTimelineView.swift +++ b/ElementX/Sources/Screens/MediaEventsTimelineScreen/View/TimelineViews/AudioFileEventsTimelineView.swift @@ -12,8 +12,7 @@ struct AudioMediaEventsTimelineView: View { let timelineItem: AudioRoomTimelineItem var body: some View { - MediaFileRoomTimelineContent(timelineItemID: timelineItem.id, - filename: timelineItem.content.filename, + MediaFileRoomTimelineContent(filename: timelineItem.content.filename, fileSize: timelineItem.content.fileSize, caption: timelineItem.content.caption, formattedCaption: timelineItem.content.formattedCaption, diff --git a/ElementX/Sources/Screens/MediaEventsTimelineScreen/View/TimelineViews/FileMediaEventsTimelineView.swift b/ElementX/Sources/Screens/MediaEventsTimelineScreen/View/TimelineViews/FileMediaEventsTimelineView.swift index 30d9251fe1..4c07806830 100644 --- a/ElementX/Sources/Screens/MediaEventsTimelineScreen/View/TimelineViews/FileMediaEventsTimelineView.swift +++ b/ElementX/Sources/Screens/MediaEventsTimelineScreen/View/TimelineViews/FileMediaEventsTimelineView.swift @@ -12,8 +12,7 @@ struct FileMediaEventsTimelineView: View { let timelineItem: FileRoomTimelineItem var body: some View { - MediaFileRoomTimelineContent(timelineItemID: timelineItem.id, - filename: timelineItem.content.filename, + MediaFileRoomTimelineContent(filename: timelineItem.content.filename, fileSize: timelineItem.content.fileSize, caption: timelineItem.content.caption, formattedCaption: timelineItem.content.formattedCaption, diff --git a/ElementX/Sources/Screens/Timeline/View/TimelineItemViews/AudioRoomTimelineView.swift b/ElementX/Sources/Screens/Timeline/View/TimelineItemViews/AudioRoomTimelineView.swift index 468d0f1ce7..2759361f35 100644 --- a/ElementX/Sources/Screens/Timeline/View/TimelineItemViews/AudioRoomTimelineView.swift +++ b/ElementX/Sources/Screens/Timeline/View/TimelineItemViews/AudioRoomTimelineView.swift @@ -9,18 +9,20 @@ import Foundation import SwiftUI struct AudioRoomTimelineView: View { + @Environment(\.timelineContext) private var context let timelineItem: AudioRoomTimelineItem var body: some View { TimelineStyler(timelineItem: timelineItem) { - MediaFileRoomTimelineContent(timelineItemID: timelineItem.id, - filename: timelineItem.content.filename, + MediaFileRoomTimelineContent(filename: timelineItem.content.filename, fileSize: timelineItem.content.fileSize, caption: timelineItem.content.caption, formattedCaption: timelineItem.content.formattedCaption, additionalWhitespaces: timelineItem.additionalWhitespaces(), - isAudioFile: true) - .accessibilityLabel(L10n.commonAudio) + isAudioFile: true) { + context?.send(viewAction: .mediaTapped(itemID: timelineItem.id)) + } + .accessibilityLabel(L10n.commonAudio) } } } diff --git a/ElementX/Sources/Screens/Timeline/View/TimelineItemViews/FileRoomTimelineView.swift b/ElementX/Sources/Screens/Timeline/View/TimelineItemViews/FileRoomTimelineView.swift index 3c041d5f26..3911714189 100644 --- a/ElementX/Sources/Screens/Timeline/View/TimelineItemViews/FileRoomTimelineView.swift +++ b/ElementX/Sources/Screens/Timeline/View/TimelineItemViews/FileRoomTimelineView.swift @@ -9,17 +9,19 @@ import Compound import SwiftUI struct FileRoomTimelineView: View { + @Environment(\.timelineContext) private var context let timelineItem: FileRoomTimelineItem var body: some View { TimelineStyler(timelineItem: timelineItem) { - MediaFileRoomTimelineContent(timelineItemID: timelineItem.id, - filename: timelineItem.content.filename, + MediaFileRoomTimelineContent(filename: timelineItem.content.filename, fileSize: timelineItem.content.fileSize, caption: timelineItem.content.caption, formattedCaption: timelineItem.content.formattedCaption, - additionalWhitespaces: timelineItem.additionalWhitespaces()) - .accessibilityLabel(L10n.commonFile) + additionalWhitespaces: timelineItem.additionalWhitespaces()) { + context?.send(viewAction: .mediaTapped(itemID: timelineItem.id)) + } + .accessibilityLabel(L10n.commonFile) } } } @@ -27,9 +29,6 @@ struct FileRoomTimelineView: View { // MARK: Content struct MediaFileRoomTimelineContent: View { - @Environment(\.timelineContext) private var context - - let timelineItemID: TimelineItemIdentifier let filename: String let fileSize: UInt? let caption: String? @@ -37,16 +36,22 @@ struct MediaFileRoomTimelineContent: View { let additionalWhitespaces: Int var isAudioFile = false - var icon: KeyPath { + var onMediaTap: (() -> Void)? = nil + + private var icon: KeyPath { isAudioFile ? \.audio : \.attachment } var body: some View { VStack(alignment: .leading, spacing: 8) { - filePreview - .onTapGesture { - context?.send(viewAction: .mediaTapped(itemID: timelineItemID)) - } + if let onMediaTap { + filePreview + .onTapGesture { + onMediaTap() + } + } else { + filePreview + } if let formattedCaption { FormattedBodyText(attributedString: formattedCaption,