ios – SwiftUI View inside UIView

[ad_1]

I’m attempting to inject a SwiftUI view within a UIView, and it’s exhibiting my SwiftUI view however the body is approach off and I can’t determine why.

That is my SwiftUI View:

@out there(iOS 14.0, *)
struct AvailablePointsSummary: View {
    
    @State non-public var factors: PointsResponse? = nil
    
    var physique: some View {
        if let factors = factors {
            GroupBox(
                label:  SummaryLabelView(labelText: "Accessible Factors")
            ) {
                SummaryRow(title: "Money Factors", quantity: Float(factors.cashoutPoints).withCommas())
                SummaryRow(title: "Promo Factors", quantity: Float(factors.availablePromoPoints ?? 0).withCommas())
            }
            .body(width: 380, top: 160)
        } else {
            Textual content("Loading...")
                .onAppear {
                    getPoints()
                }
        }

    }
    
    func getPoints() {
        PointsService().getPointsResponse { factors in
            DispatchQueue.primary.async {
                self.factors = factors
            }
        }
    }
    
}

@out there(iOS 14.0, *)
var availPointsSummary = UIHostingController(rootView: AvailablePointsSummary())

Setup in my UIViewController

func setupAvailablePoints(){
        let pointView = availPointsSummary.view
        pointView?.translatesAutoresizingMaskIntoConstraints = false
        pointView?.body = CGRect(x: 0, y: 0, width: 380, top: 160)
        
        self.availPointsView.addSubview(pointView!)
        self.addChild(availPointsSummary)
    }

enter image description here

And the consequence
enter image description here

[ad_2]

Leave a Reply