Skip to content

Commit

Permalink
Add support for SwiftUI
Browse files Browse the repository at this point in the history
  • Loading branch information
steprescott committed Oct 27, 2022
1 parent 932006e commit b21afb6
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Sources/Share/Link.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,22 @@ extension Share {
self.shareValue = shareValue
}

public func title(_ title: String) -> Link {
public func title(_ title: String?) -> Link {
self.title = title
return self
}

public func icon(_ url: URL) -> Link {
public func icon(_ url: URL?) -> Link {
icon = url
return self
}

public func image(_ url: URL) -> Link {
public func image(_ url: URL?) -> Link {
self.image = url
return self
}

public func video(_ url: URL) -> Link {
public func video(_ url: URL?) -> Link {
self.video = url
return self
}
Expand Down
35 changes: 35 additions & 0 deletions Sources/Share/Sheet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,38 @@ extension Share {
}
}
#endif

#if canImport(SwiftUI)
import SwiftUI

@available(iOS 13.0, *)
extension Share.Sheet {

public struct View: UIViewControllerRepresentable, ShareDelegate {
public typealias Action = ((Share.Service.Status) -> ())

let sharable: Sharable

var onStatusChange: Action = { _ in }

public func didChange(status: Share.Service.Status) {
onStatusChange(status)
}

public func onStatusChange(_ action: @escaping Action) -> View {
View(sharable: sharable, onStatusChange: action)
}

public func makeUIViewController(context: UIViewControllerRepresentableContext<View>) -> UIActivityViewController {
return Share.Sheet(for: sharable, delegate: self)
}

public func updateUIViewController(_ uiViewController: UIActivityViewController, context: UIViewControllerRepresentableContext<View>) {}
}

public func view() -> View {
.init(sharable: sharable)
}
}

#endif

0 comments on commit b21afb6

Please sign in to comment.