exyte / Macaw

Powerful and easy-to-use vector graphics Swift library with SVG support
MIT License
6.01k stars 554 forks source link

Resize to frame using .scaleAspectFit via UIViewRepresentable [Question] #682

Closed nadirabid closed 4 years ago

nadirabid commented 4 years ago

Love this library - brings huge missing SVG support to SwiftUI in general.

I'm struggling to understand how Macaw respects frame sizing. The following is the basic code I'm working with:

struct SVGViewController: UIViewRepresentable {
    func makeUIView(context: Context) -> SVGView {
        let rootNode = try! SVGParser.parse(resource: "Duck", ofType: "svg")
        let view = SVGView(node: rootNode, frame: CGRect.zero)
        view.contentMode = .scaleAspectFit

        return view
    }

    func updateUIView(_ activityIndicator: SVGView, context: Context) {

    }
}

struct MacawSVGView: View {
    var body: some View {
        SVGViewController().frame(width: 50, height: 100)
    }
}

Really the goal is simple - understand how Macaw can automatically scale the SVG to fit within the frame.

I did read about Content Mode removed preserveAspectRatio. Also note I'm working off from master as it seems to have Swift Package Manager support.

nadirabid commented 4 years ago

Alright - I think I tried everything. I assume there's a bug but any help would be greatly appreciated!

nadirabid commented 4 years ago

Went another route entirely. Closing

icearith commented 2 years ago

any suggestions to solve this bug?

gunhansancar commented 2 years ago

@nadirabid what did you do? @icearith did you find a solution?