Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: Using yoga in Swift ```swift import UIKit import yoga let YGUndefined = Float.nan UIGraphicsBeginImageContextWithOptions(CGSize(width: 1, height: 1), true, 0) let scale = UIGraphicsGetCurrentContext()?.ctm.a ?? 1 UIGraphicsEndImageContext() let config = YGConfigNew() YGConfigSetUseWebDefaults(config, true) YGConfigSetPointScaleFactor(config, Float(scale)) let root = YGNodeNewWithConfig(config) YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow) YGNodeStyleSetFlexWrap(root, YGWrapWrap) YGNodeStyleSetWidth(root, 200) for i in 0..<4 { let leaf = YGNodeNewWithConfig(config) YGNodeStyleSetAspectRatio(leaf, 1) YGNodeStyleSetWidthPercent(leaf, 50) YGNodeInsertChild(root, leaf, UInt32(i)) } YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGNodeStyleGetDirection(root)) for i in 0..<4 { let leaf = YGNodeGetChild(root, UInt32(i)) let left = YGNodeLayoutGetLeft(leaf) let top = YGNodeLayoutGetTop(leaf) let width = YGNodeLayoutGetWidth(leaf) let height = YGNodeLayoutGetHeight(leaf) print("leaf \(i): origin: \(left), \(top), size: \(width), \(height)") } let width = YGNodeLayoutGetWidth(root) let height = YGNodeLayoutGetHeight(root) print("root size: \(width), \(height)") YGNodeFreeRecursive(root) YGConfigFree(config) ``` Pull Request resolved: #1339 Reviewed By: cipolleschi Differential Revision: D48166958 Pulled By: NickGerleman fbshipit-source-id: 72fef99729d01c7ba291b11f047cf75fd39f7630
- Loading branch information