Skip to content

Commit 67b592c

Browse files
Fix empty share sheet when sharing a video from the full-screen media viewer (#1418)
1 parent 8d09cad commit 67b592c

4 files changed

Lines changed: 41 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
1515
- Redesign the thread replies divider in the message replies list [#1354](https://github.com/GetStream/stream-chat-swiftui/pull/1354)
1616

1717
### 🐞 Fixed
18+
- Fix empty share sheet when sharing a video from the full-screen media viewer [#1418](https://github.com/GetStream/stream-chat-swiftui/pull/1418)
1819
- Fix swipe-to-reply icon layout for outgoing messages and RTL [#1402](https://github.com/GetStream/stream-chat-swiftui/pull/1402)
1920
- Fix unwanted border on the Edit button in Channel Info [#1402](https://github.com/GetStream/stream-chat-swiftui/pull/1402)
2021
- Fix send button icon not mirroring in RTL layouts [#1397](https://github.com/GetStream/stream-chat-swiftui/pull/1397)

Sources/StreamChatSwiftUI/ChatMessageList/Gallery/MediaViewer.swift

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ public struct MediaViewer<Factory: ViewFactory>: View {
110110
viewFactory.makeMediaViewerFooterView(
111111
options: MediaViewerFooterViewOptions(
112112
shareContent: sharingContent,
113+
shareFallbackURL: sharingFallbackURL,
113114
selected: selected,
114115
totalCount: mediaAttachments.count,
115116
gridShown: $gridShown
@@ -151,6 +152,14 @@ public struct MediaViewer<Factory: ViewFactory>: View {
151152
[]
152153
}
153154
}
155+
156+
/// Used when there is no in-memory ``UIImage`` (videos never populate ``loadedImages``; images may still be loading).
157+
private var sharingFallbackURL: URL? {
158+
guard loadedImages[selected] == nil,
159+
selected >= 0,
160+
selected < mediaAttachments.count else { return nil }
161+
return mediaAttachments[selected].url
162+
}
154163
}
155164

156165
struct GridMediaView<Factory: ViewFactory>: View {
@@ -192,20 +201,28 @@ public struct MediaViewerFooterView: View {
192201
@Injected(\.tokens) private var tokens
193202

194203
let shareContent: [UIImage]
204+
let shareFallbackURL: URL?
195205
let selected: Int
196206
let totalCount: Int
197207
@Binding var gridShown: Bool
198208

199-
public init(shareContent: [UIImage], selected: Int, totalCount: Int, gridShown: Binding<Bool>) {
209+
public init(
210+
shareContent: [UIImage],
211+
shareFallbackURL: URL? = nil,
212+
selected: Int,
213+
totalCount: Int,
214+
gridShown: Binding<Bool>
215+
) {
200216
self.shareContent = shareContent
217+
self.shareFallbackURL = shareFallbackURL
201218
self.selected = selected
202219
self.totalCount = totalCount
203220
_gridShown = gridShown
204221
}
205222

206223
public var body: some View {
207224
HStack {
208-
ShareButtonView(content: shareContent)
225+
ShareButtonView(content: shareActivityItems)
209226

210227
Spacer()
211228

@@ -228,6 +245,16 @@ public struct MediaViewerFooterView: View {
228245
.frame(height: 48 + tokens.spacingSm * 2)
229246
.background(Color(colors.backgroundCoreElevation1))
230247
}
248+
249+
private var shareActivityItems: [Any] {
250+
if !shareContent.isEmpty {
251+
return shareContent
252+
}
253+
if let shareFallbackURL {
254+
return [shareFallbackURL]
255+
}
256+
return []
257+
}
231258
}
232259

233260
// MARK: - Toolbar

Sources/StreamChatSwiftUI/ViewFactory/DefaultViewFactory.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ extension ViewFactory {
395395
) -> some View {
396396
MediaViewerFooterView(
397397
shareContent: options.shareContent,
398+
shareFallbackURL: options.shareFallbackURL,
398399
selected: options.selected,
399400
totalCount: options.totalCount,
400401
gridShown: options.gridShown

Sources/StreamChatSwiftUI/ViewFactory/Options/AttachmentViewFactoryOptions.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,15 +310,24 @@ public final class MediaViewerToolbarModifierOptions: Sendable {
310310
public final class MediaViewerFooterViewOptions: Sendable {
311311
/// The content available for sharing (e.g. loaded images).
312312
public let shareContent: [UIImage]
313+
/// URL to share when ``shareContent`` is empty (e.g. video attachments, or an image still loading).
314+
public let shareFallbackURL: URL?
313315
/// The currently selected media index (zero-based).
314316
public let selected: Int
315317
/// The total number of media attachments.
316318
public let totalCount: Int
317319
/// Binding that controls whether the grid sheet is shown.
318320
public let gridShown: Binding<Bool>
319321

320-
public init(shareContent: [UIImage], selected: Int, totalCount: Int, gridShown: Binding<Bool>) {
322+
public init(
323+
shareContent: [UIImage],
324+
shareFallbackURL: URL? = nil,
325+
selected: Int,
326+
totalCount: Int,
327+
gridShown: Binding<Bool>
328+
) {
321329
self.shareContent = shareContent
330+
self.shareFallbackURL = shareFallbackURL
322331
self.selected = selected
323332
self.totalCount = totalCount
324333
self.gridShown = gridShown

0 commit comments

Comments
 (0)