-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from tsuzukihashi/feature/sharesheet
add: ShareActivityItemSource
- Loading branch information
Showing
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
Sources/TsuzuKit/Utils/Share/ShareActivityItemSource.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,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 | ||
} | ||
} |
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,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) { | ||
} | ||
} |