Skip to content

Commit

Permalink
Merge pull request #1 from tsuzukihashi/feature/sharesheet
Browse files Browse the repository at this point in the history
add: ShareActivityItemSource
  • Loading branch information
tsuzukihashi authored Jul 15, 2024
2 parents 95b0103 + ceaa8f6 commit 6680948
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
27 changes: 27 additions & 0 deletions Sources/TsuzuKit/Utils/Share/ShareActivityItemSource.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import Foundation
import LinkPresentation

public class ShareActivityItemSource: NSObject, UIActivityItemSource {
var shareText: String
var shareImage: UIImage
var linkMetaData = LPLinkMetadata()

public init(shareText: String, shareImage: UIImage) {
self.shareText = shareText
self.shareImage = shareImage
linkMetaData.title = shareText
super.init()
}

public func activityViewControllerPlaceholderItem(_ activityViewController: UIActivityViewController) -> Any {
return UIImage(named: "AppIcon") as Any
}

public func activityViewController(_ activityViewController: UIActivityViewController, itemForActivityType activityType: UIActivity.ActivityType?) -> Any? {
return nil
}

public func activityViewControllerLinkMetadata(_ activityViewController: UIActivityViewController) -> LPLinkMetadata? {
return linkMetaData
}
}
27 changes: 27 additions & 0 deletions Sources/TsuzuKit/Utils/Share/ShareSheet.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import Foundation
import SwiftUI

public struct ShareSheet: UIViewControllerRepresentable {
let image: UIImage
let text: String

public init(photo: UIImage, text: String) {
self.image = photo
self.text = text
}

public func makeUIViewController(context: Context) -> UIActivityViewController {
let itemSource = ShareActivityItemSource(shareText: text, shareImage: image)
let activityItems: [Any] = [image, text, itemSource]

let controller = UIActivityViewController(
activityItems: activityItems,
applicationActivities: nil
)

return controller
}

public func updateUIViewController(_ vc: UIActivityViewController, context: Context) {
}
}

0 comments on commit 6680948

Please sign in to comment.