yoga: YogaKit does not correctly account for composite UIView when doing layout

I’ve been trying to render an instance of MKMapView but failed to do so.

Here is a code that works without using Yoga

import UIKit
import MapKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        let m = MKMapView()
        m.frame.size = CGSize(width: self.view.frame.size.width, height: 100)
        self.view.addSubview(m)
    }

}

which renders the following view

simulator screen shot dec 19 2016 1 24 12 am

but when I try to render a same map view using Yoga with the following code

import UIKit
import MapKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        let m = MKMapView()

        self.view.yg_usesYoga = true
        self.view.yg_setWidth(self.view.bounds.size.width)
        self.view.yg_setHeight(self.view.bounds.size.height)
        
        m.yg_usesYoga = true
        m.yg_setWidth(self.view.bounds.size.width)
        m.yg_setHeight(100)
        
        self.view.addSubview(m)
        self.view.yg_applyLayout()
    }

}

I get this

simulator screen shot dec 19 2016 1 26 10 am

Which is basically a “white” map

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 16 (8 by maintainers)

Commits related to this issue

Most upvoted comments

The fix for this landed in 835bb1c. I’m going to close this, but feel free to open if something else arises!

@emilsjolander Oops! sorry didn’t see that. You were right it worked! Now the map renders correctly. I’ll prepare a PR. Thanks a lot helping me!