Created
September 27, 2017 04:06
-
-
Save andrewliebchen/de1dda37636b2af6d8d9ab79d328d5e8 to your computer and use it in GitHub Desktop.
Yoga in Framer, v1
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" | |
# Establish a root node | |
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) | |
# Create some children | |
child1 = yoga.Node.create() | |
child1.setFlex(1) | |
child2 = yoga.Node.create() | |
child2.setFlex(3) | |
child2.setMargin(yoga.EDGE_LEFT, 20) | |
# Add the children to the root | |
root.insertChild(child1, 0) | |
root.insertChild(child2, 1) | |
# Calculate layout | |
root.calculateLayout() | |
# Map children to Framer layers | |
for i in [0...root.getChildCount()] | |
child = root.getChild i | |
@layer = new Layer | |
width: child.getComputedWidth() | |
height: child.getComputedHeight() | |
x: child.getComputedLeft() | |
y: child.getComputedTop() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment