Created
September 27, 2017 04:39
-
-
Save andrewliebchen/3d4a73dbc9c85b9ca5f07e73ecd8aca0 to your computer and use it in GitHub Desktop.
Yoga in Framer, v2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ yoga } = require "npm" | |
root = yoga.Node.create() | |
root.setWidth(Screen.width) | |
root.setHeight(Screen.height) | |
root.setPadding(yoga.EDGE_ALL, 20) | |
root.setDisplay(yoga.DISPLAY_FLEX) | |
root.setFlexDirection(yoga.FLEX_DIRECTION_ROW) | |
childA = new Layer | |
backgroundColor: 'blue' | |
label: 'Sidebar' | |
childA.layout = yoga.Node.create() | |
childA.layout.setFlex(1) | |
childB = new Layer | |
backgroundColor: 'magenta' | |
label: 'Main' | |
childB.layout = yoga.Node.create() | |
childB.layout.setFlex(3) | |
childB.layout.setMargin(yoga.EDGE_LEFT, 20) | |
root.insertChild childA.layout, 0 | |
root.insertChild childB.layout, 1 | |
mapLayout = (root, children) -> | |
root.calculateLayout() | |
for child in children | |
layout = child.layout | |
child.props = | |
width: layout.getComputedWidth() | |
height: layout.getComputedHeight() | |
x: layout.getComputedLeft() | |
y: layout.getComputedTop() | |
mapLayout root, [childA, childB] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment