Skip to content

Commit 7833297

Browse files
authored
Make MediaItem and MediaAttachmentContentView public to allow customization. (#935)
1 parent a4d06da commit 7833297

File tree

3 files changed

+40
-9
lines changed

3 files changed

+40
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
55

66
### ✅ Added
77
- Add option to scroll to and open a channel from the channel list [#932](https://github.com/GetStream/stream-chat-swiftui/pull/932)
8+
- Make `MediaItem` and `MediaAttachmentContentView` public to allow customization [#935](https://github.com/GetStream/stream-chat-swiftui/pull/935)
89

910
### 🐞 Fixed
1011
- Show attachment title instead of URL in the `FileAttachmentPreview` view [#930](https://github.com/GetStream/stream-chat-swiftui/pull/930)

Sources/StreamChatSwiftUI/ChatChannel/ChannelInfo/MediaAttachmentsView.swift

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public struct MediaAttachmentsView<Factory: ViewFactory>: View {
102102
}
103103
}
104104

105-
struct MediaAttachmentContentView<Factory: ViewFactory>: View {
105+
public struct MediaAttachmentContentView<Factory: ViewFactory>: View {
106106
@State private var galleryShown = false
107107

108108
let factory: Factory
@@ -112,7 +112,23 @@ struct MediaAttachmentContentView<Factory: ViewFactory>: View {
112112
let itemWidth: CGFloat
113113
let index: Int
114114

115-
var body: some View {
115+
public init(
116+
factory: Factory,
117+
mediaItem: MediaItem,
118+
mediaAttachment: MediaAttachment,
119+
allMediaAttachments: [MediaAttachment],
120+
itemWidth: CGFloat,
121+
index: Int
122+
) {
123+
self.factory = factory
124+
self.mediaItem = mediaItem
125+
self.mediaAttachment = mediaAttachment
126+
self.allMediaAttachments = allMediaAttachments
127+
self.itemWidth = itemWidth
128+
self.index = index
129+
}
130+
131+
public var body: some View {
116132
Button {
117133
galleryShown = true
118134
} label: {

Sources/StreamChatSwiftUI/ChatChannel/ChannelInfo/MediaAttachmentsViewModel.swift

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,29 @@ class MediaAttachmentsViewModel: ObservableObject, ChatMessageSearchControllerDe
106106
}
107107
}
108108

109-
struct MediaItem: Identifiable {
110-
let id: String
111-
let isVideo: Bool
112-
let message: ChatMessage
109+
public struct MediaItem: Identifiable {
110+
public let id: String
111+
public let isVideo: Bool
112+
public let message: ChatMessage
113113

114-
var videoAttachment: ChatMessageVideoAttachment?
115-
var imageAttachment: ChatMessageImageAttachment?
114+
public var videoAttachment: ChatMessageVideoAttachment?
115+
public var imageAttachment: ChatMessageImageAttachment?
116116

117-
var mediaAttachment: MediaAttachment? {
117+
public init(
118+
id: String,
119+
isVideo: Bool,
120+
message: ChatMessage,
121+
videoAttachment: ChatMessageVideoAttachment?,
122+
imageAttachment: ChatMessageImageAttachment?
123+
) {
124+
self.id = id
125+
self.isVideo = isVideo
126+
self.message = message
127+
self.videoAttachment = videoAttachment
128+
self.imageAttachment = imageAttachment
129+
}
130+
131+
public var mediaAttachment: MediaAttachment? {
118132
if let videoAttachment {
119133
return MediaAttachment(url: videoAttachment.videoURL, type: .video)
120134
} else if let imageAttachment {

0 commit comments

Comments
 (0)