Skip to content

Commit

Permalink
Fix MediaFileRoomTimelineContent tap gesture taking over media even…
Browse files Browse the repository at this point in the history
…t timeline taps.
  • Loading branch information
stefanceriu committed Dec 13, 2024
1 parent b0f4f42 commit 13875e6
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,44 +9,49 @@ 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)
}
}
}

// MARK: Content

struct MediaFileRoomTimelineContent: View {
@Environment(\.timelineContext) private var context

let timelineItemID: TimelineItemIdentifier
let filename: String
let fileSize: UInt?
let caption: String?
let formattedCaption: AttributedString?
let additionalWhitespaces: Int
var isAudioFile = false

var icon: KeyPath<CompoundIcons, Image> {
var onMediaTap: (() -> Void)? = nil

private var icon: KeyPath<CompoundIcons, Image> {
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,
Expand Down

0 comments on commit 13875e6

Please sign in to comment.