Created
October 29, 2019 18:53
-
-
Save dbolella/edfc81b95d5cea4a5738242cb76c6a0f to your computer and use it in GitHub Desktop.
Lacking implementation of LinkPreview in SwiftUI
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
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