Skip to content

Instantly share code, notes, and snippets.

@dbolella
Created October 29, 2019 18:53
Show Gist options
  • Save dbolella/edfc81b95d5cea4a5738242cb76c6a0f to your computer and use it in GitHub Desktop.
Save dbolella/edfc81b95d5cea4a5738242cb76c6a0f to your computer and use it in GitHub Desktop.
Lacking implementation of LinkPreview in SwiftUI
struct ContentView: View {
var body: some View {
VStack {
URLPreview(previewURL: URL(string: "https://medium.com")!)
.aspectRatio(contentMode: .fit)
.padding()
}
}
}
struct URLPreview : UIViewRepresentable {
var previewURL:URL
func makeUIView(context: Context) -> LPLinkView {
let view = LPLinkView(url: previewURL)
let provider = LPMetadataProvider()
provider.startFetchingMetadata(for: previewURL) { (metadata, error) in
if let md = metadata {
DispatchQueue.main.async {
view.metadata = md
view.sizeToFit()
}
}
}
return view
}
func updateUIView(_ uiView: LPLinkView, context: UIViewRepresentableContext<URLPreview>) {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment