ios – Prevent Swift UI Link Preview from rounding corners


I have a basic Link Preview where I define custom sizing. Im running into the issue where the corners are automatically rounding. I tried using some modifiers and link preview attributes to prevent this rounding but it doesn’t work. I only want the top corners to round but haven’t been able to achieve this.

Adding .cornerRadius(0) to GroupPreviewView doesn’t work.


import LinkPresentation
import UIKit
import SwiftUI

struct MainGroupLink: View {
    let url: URL
    @State var size: CGFloat = .zero
    @State var size2: CGFloat = .zero
    @State var meta: LPLinkMetadata? = nil
    
    var body: some View {
        VStack {
            GroupPreviewView(url: url, width: $size, height: $size2, meta: $popRoot.cachedMetadata[url])
                .frame(width: size, height: size2, alignment: .leading)
                .aspectRatio(contentMode: .fill)
        }
    }
}

    struct GroupPreviewView: UIViewRepresentable {
        let url: URL
        @Binding var width: CGFloat
        @Binding var height: CGFloat
        @Binding var meta: LPLinkMetadata?
        
        func makeUIView(context: Context) -> UIView {
            let linkView = CustomLinkView()
      
            let provider = LPMetadataProvider()
            provider.startFetchingMetadata(for: url) { metaData, error in
                guard let data = metaData, error == nil else { return }
                DispatchQueue.main.async {
                    linkView.metadata = data
                    linkView.layer.cornerRadius = 0
                    linkView.clipsToBounds = true
                    meta = data

                    self.width = 200
                    self.height = 200
                }
            }
            return linkView
        }
        func updateUIView(_ uiView: UIView, context: Context) { }
    } 

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img