Skip to content

Commit

Permalink
Share for actual image from Carousel Viewer
Browse files Browse the repository at this point in the history
The ellipsis (share button) allows you to share actual image from the full screen carousel viewer in timeline.

Changelog-Changes: Share for actual image from Carousel Viewer
Signed-off-by: Swift Coder  <[email protected]>
  • Loading branch information
scoder1747 committed Nov 5, 2024
1 parent e800156 commit 47d99ac
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
14 changes: 9 additions & 5 deletions damus/Views/Images/FullScreenCarouselView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct FullScreenCarouselView<Content: View>: View {
@Environment(\.presentationMode) var presentationMode

@State var showMenu = true

@State private var imageDict: [URL: UIImage] = [:]
let settings: UserSettingsStore
@Binding var selectedIndex: Int
let content: (() -> Content)?
Expand Down Expand Up @@ -59,7 +59,7 @@ struct FullScreenCarouselView<Content: View>: View {
ForEach(urls.indices, id: \.self) { index in
VStack {
if case .video = urls[safe: index] {
ImageContainerView(video_controller: video_controller, url: urls[index], settings: settings)
ImageContainerView(video_controller: video_controller, url: urls[index], settings: settings, imageDict: $imageDict)
.clipped() // SwiftUI hack from https://stackoverflow.com/a/74401288 to make playback controls show up within the TabView
.aspectRatio(contentMode: .fit)
.padding(.top, Theme.safeAreaInsets?.top)
Expand All @@ -71,7 +71,7 @@ struct FullScreenCarouselView<Content: View>: View {
}
else {
ZoomableScrollView {
ImageContainerView(video_controller: video_controller, url: urls[index], settings: settings)
ImageContainerView(video_controller: video_controller, url: urls[index], settings: settings, imageDict: $imageDict)
.aspectRatio(contentMode: .fit)
.padding(.top, Theme.safeAreaInsets?.top)
.padding(.bottom, Theme.safeAreaInsets?.bottom)
Expand Down Expand Up @@ -102,8 +102,12 @@ struct FullScreenCarouselView<Content: View>: View {
.foregroundColor(.white)

if let url = urls[safe: selectedIndex],
case .image = url {
ShareLink(item: url.url) {
let image = imageDict[url.url] {

ShareLink(item: Image(uiImage: image),
preview: SharePreview(NSLocalizedString("Shared Picture",
comment: "Label for the preview of the image being picture"),
image: Image(uiImage: image))) {
Image(systemName: "ellipsis")
.foregroundColor(.white)
.frame(width: 33, height: 33)
Expand Down
11 changes: 8 additions & 3 deletions damus/Views/Images/ImageContainerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,18 @@ struct ImageContainerView: View {
let url: MediaUrl
let settings: UserSettingsStore

@Binding var imageDict: [URL: UIImage]
@State private var image: UIImage?
@State private var showShareSheet = false

private struct ImageHandler: ImageModifier {
@Binding var handler: UIImage?
@Binding var imageDict: [URL: UIImage]
let url: URL

func modify(_ image: UIImage) -> UIImage {
handler = image
imageDict[url] = image
return image
}
}
Expand All @@ -32,7 +36,7 @@ struct ImageContainerView: View {
.configure { view in
view.framePreloadCount = 3
}
.imageModifier(ImageHandler(handler: $image))
.imageModifier(ImageHandler(handler: $image, imageDict: $imageDict, url: url))
.kfClickable()
.clipped()
.modifier(ImageContextMenuModifier(url: url, image: image, settings: settings, showShareSheet: $showShareSheet))
Expand All @@ -58,10 +62,11 @@ fileprivate let test_video_url = URL(string: "http://cdn.jb55.com/s/zaps-build.m

struct ImageContainerView_Previews: PreviewProvider {
static var previews: some View {
@State var imageDict: [URL: UIImage] = [:]
Group {
ImageContainerView(video_controller: test_damus_state.video, url: .image(test_image_url), settings: test_damus_state.settings)
ImageContainerView(video_controller: test_damus_state.video, url: .image(test_image_url), settings: test_damus_state.settings, imageDict: $imageDict)
.previewDisplayName("Image")
ImageContainerView(video_controller: test_damus_state.video, url: .video(test_video_url), settings: test_damus_state.settings)
ImageContainerView(video_controller: test_damus_state.video, url: .video(test_video_url), settings: test_damus_state.settings, imageDict: $imageDict)
.previewDisplayName("Video")
}
.environmentObject(OrientationTracker())
Expand Down

0 comments on commit 47d99ac

Please sign in to comment.