Skip to content

Instantly share code, notes, and snippets.

@JagCesar
Created July 25, 2022 15:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JagCesar/6a47b2e6d1f3569bbe31fccc21241433 to your computer and use it in GitHub Desktop.
Save JagCesar/6a47b2e6d1f3569bbe31fccc21241433 to your computer and use it in GitHub Desktop.
SwiftUI SharedWithAttributionView
import SwiftUI
import SharedWithYou
#if os(iOS) || os(tvOS)
struct SharedWithAttributionView: UIViewRepresentable {
let highlight: SWHighlight
let displayContext: SWAttributionView.DisplayContext
let backgroundStyle: SWAttributionView.BackgroundStyle
func makeUIView(context: Context) -> some UIView {
let view = SWAttributionView()
view.highlight = highlight
view.preferredMaxLayoutWidth = .greatestFiniteMagnitude
view.horizontalAlignment = .leading
view.displayContext = displayContext
view.backgroundStyle = backgroundStyle
return view
}
func updateUIView(_ uiView: UIViewType, context: Context) {
}
}
#elseif os(macOS)
struct SharedWithAttributionView: NSViewRepresentable {
let highlight: SWHighlight
let displayContext: SWAttributionView.DisplayContext
let backgroundStyle: SWAttributionView.BackgroundStyle
func makeNSView(context: Context) -> some NSView {
let view = SWAttributionView()
view.highlight = highlight
view.preferredMaxLayoutWidth = .greatestFiniteMagnitude
view.horizontalAlignment = .leading
view.displayContext = displayContext
view.backgroundStyle = backgroundStyle
return view
}
func updateNSView(_ nsView: NSViewType, context: Context) {
}
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment