Macaw
Macaw copied to clipboard
Issue with SVGImage and SwiftUI
Hello,
if I use SwiftUI, the SVGImage is either blank or not correctly scaled (depending on each SVG file). The same files work correctly on the Storyboard.
This is my code:
import SwiftUI
import Macaw
struct CountryRow: View {
var body: some View {
Text("Task data goes here")
}
}
struct MapRow: View {
var body: some View {
HStack {
SVGImage(name: "albaniaLow")
.frame(width: 50, height: 50)
Text("hello")
Spacer()
}
}
}
struct SVGImage: UIViewRepresentable {
// a binding allows for dynamic updates to the shown image
@Binding var name: String
init(name: Binding<String>) {
_name = name
}
// convenience constructor to allow for a constant image name
init(name: String) {
_name = .constant(name)
}
func makeUIView(context: Context) -> SVGView {
let svgView = SVGView()
svgView.backgroundColor = UIColor(white: 1.0, alpha: 0.0) // otherwise the background is black
svgView.contentMode = .scaleAspectFit
return svgView
}
func updateUIView(_ uiView: SVGView, context: Context) {
uiView.fileName = name
}
}
struct CountriesUIView: View {
var body: some View {
NavigationView {
List {
MapRow()
Section(header: Text("Continent 1")) {
CountryRow()
}
Section(header: Text("Continent 2")) {
CountryRow()
}
}.navigationBarTitle("Navigation")
}
}
}
struct CountriesUIView_Previews: PreviewProvider {
static var previews: some View {
CountriesUIView()
}
}
Am I doing something wrong? Thank you in advance.
Same issue
Need help
@GDGapps any chance you found a solution?