generated from element-hq/.github
-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Media gallery - support for files and voice messages (#3605)
* Move the voice message views to where they belong * Add separate struct for each media events timeline view * Add support for all the different media gallery message types and get the files section working
- Loading branch information
1 parent
606eb0a
commit 114255c
Showing
30 changed files
with
374 additions
and
112 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
...s/Screens/MediaEventsTimelineScreen/View/TimelineViews/ImageMediaEventsTimelineView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// | ||
// Copyright 2022-2024 New Vector Ltd. | ||
// | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
// Please see LICENSE in the repository root for full details. | ||
// | ||
|
||
import Compound | ||
import SwiftUI | ||
|
||
struct ImageMediaEventsTimelineView: View { | ||
@Environment(\.timelineContext) private var context | ||
let timelineItem: ImageRoomTimelineItem | ||
|
||
var body: some View { | ||
loadableImage | ||
.accessibilityElement(children: .ignore) | ||
.accessibilityLabel(L10n.commonImage) | ||
} | ||
|
||
@ViewBuilder | ||
private var loadableImage: some View { | ||
if timelineItem.content.contentType == .gif { | ||
LoadableImage(mediaSource: timelineItem.content.imageInfo.source, | ||
mediaType: .timelineItem(uniqueID: timelineItem.id.uniqueID.id), | ||
blurhash: timelineItem.content.blurhash, | ||
size: timelineItem.content.imageInfo.size, | ||
mediaProvider: context?.mediaProvider) { | ||
placeholder | ||
} | ||
.mediaGalleryTimelineAspectRatio(imageInfo: timelineItem.content.imageInfo) | ||
} else { | ||
LoadableImage(mediaSource: timelineItem.content.thumbnailInfo?.source ?? timelineItem.content.imageInfo.source, | ||
mediaType: .timelineItem(uniqueID: timelineItem.id.uniqueID.id), | ||
blurhash: timelineItem.content.blurhash, | ||
size: timelineItem.content.thumbnailInfo?.size ?? timelineItem.content.imageInfo.size, | ||
mediaProvider: context?.mediaProvider) { | ||
placeholder | ||
} | ||
.mediaGalleryTimelineAspectRatio(imageInfo: timelineItem.content.thumbnailInfo ?? timelineItem.content.imageInfo) | ||
} | ||
} | ||
|
||
private var placeholder: some View { | ||
Rectangle() | ||
.foregroundColor(.compound.bgSubtleSecondary) | ||
.opacity(0.3) | ||
} | ||
} | ||
|
||
private extension View { | ||
@ViewBuilder | ||
func mediaGalleryTimelineAspectRatio(imageInfo: ImageInfoProxy?) -> some View { | ||
aspectRatio(imageInfo?.aspectRatio, contentMode: .fill) | ||
} | ||
} | ||
|
||
struct ImageMediaEventsTimelineView_Previews: PreviewProvider, TestablePreview { | ||
static let viewModel = TimelineViewModel.mock | ||
|
||
static var previews: some View { | ||
ImageMediaEventsTimelineView(timelineItem: makeTimelineItem()) | ||
.frame(width: 100, height: 100) | ||
.environmentObject(viewModel.context) | ||
.environment(\.timelineContext, viewModel.context) | ||
.previewLayout(.sizeThatFits) | ||
.background(.black) | ||
} | ||
|
||
private static func makeTimelineItem() -> ImageRoomTimelineItem { | ||
ImageRoomTimelineItem(id: .randomEvent, | ||
timestamp: .mock, | ||
isOutgoing: false, | ||
isEditable: false, | ||
canBeRepliedTo: true, | ||
isThreaded: false, | ||
sender: .init(id: "Bob"), | ||
content: .init(filename: "image.jpg", | ||
imageInfo: .mockImage, | ||
thumbnailInfo: .mockThumbnail, | ||
contentType: .jpeg)) | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...reens/MediaEventsTimelineScreen/View/TimelineViews/SeparatorMediaEventsTimelineView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// | ||
// Copyright 2022-2024 New Vector Ltd. | ||
// | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
// Please see LICENSE in the repository root for full details. | ||
// | ||
|
||
import Compound | ||
import SwiftUI | ||
|
||
struct SeparatorMediaEventsTimelineView: View { | ||
let group: MediaEventsTimelineGroup | ||
|
||
var body: some View { | ||
Text(group.title) | ||
.font(.compound.bodySMSemibold) | ||
.foregroundColor(.compound.textPrimary) | ||
.frame(alignment: .center) | ||
.padding(.vertical, 16) | ||
} | ||
} | ||
|
||
struct SeparatorMediaEventsTimelineView_Previews: PreviewProvider, TestablePreview { | ||
static var previews: some View { | ||
let item = SeparatorRoomTimelineItem(id: .virtual(uniqueID: .init(id: "Separator")), | ||
timestamp: .mock) | ||
|
||
SeparatorMediaEventsTimelineView(group: .init(id: item.id.uniqueID.id, | ||
title: "Group", | ||
items: [])) | ||
} | ||
} |
Oops, something went wrong.