upgrade yoga-layout
Summary: - upgraded to yoga-layout@1.9.3 - set default values correctly - catch errors Reviewed By: emilsjolander Differential Revision: D7001154 fbshipit-source-id: 49527576c61ce109ba0af0f50c981cf5c2c7d41a
This commit is contained in:
committed by
Facebook Github Bot
parent
ae9703712a
commit
b318c4c5c9
@@ -18,7 +18,7 @@
|
|||||||
"immutable": "^4.0.0-rc.9",
|
"immutable": "^4.0.0-rc.9",
|
||||||
"react-helmet": "^5.2.0",
|
"react-helmet": "^5.2.0",
|
||||||
"react-syntax-highlighter": "^7.0.0",
|
"react-syntax-highlighter": "^7.0.0",
|
||||||
"yoga-layout": "^1.9.0"
|
"yoga-layout": "^1.9.3"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"gatsby"
|
"gatsby"
|
||||||
|
@@ -3,9 +3,7 @@ import yoga from 'yoga-layout/dist/entry-browser';
|
|||||||
import LayoutRecord from './LayoutRecord';
|
import LayoutRecord from './LayoutRecord';
|
||||||
import PositionRecord from './PositionRecord';
|
import PositionRecord from './PositionRecord';
|
||||||
import type {LayoutRecordT} from './LayoutRecord';
|
import type {LayoutRecordT} from './LayoutRecord';
|
||||||
import type {Yoga$Direction /* Yoga$Node */} from 'yoga-layout';
|
import type {Yoga$Direction, Yoga$Node} from 'yoga-layout';
|
||||||
|
|
||||||
type Yoga$Node = any;
|
|
||||||
|
|
||||||
const enumLookup = {
|
const enumLookup = {
|
||||||
flexDirection: {
|
flexDirection: {
|
||||||
|
@@ -85,7 +85,7 @@ export default class Editor extends Component<Props> {
|
|||||||
<h2>
|
<h2>
|
||||||
Basis
|
Basis
|
||||||
<InfoText doclink="/docs/flex">
|
<InfoText doclink="/docs/flex">
|
||||||
The factor of remaining space should be given to this node
|
Default size of a node along the main axis
|
||||||
</InfoText>
|
</InfoText>
|
||||||
</h2>
|
</h2>
|
||||||
<EditValue
|
<EditValue
|
||||||
@@ -233,7 +233,7 @@ export default class Editor extends Component<Props> {
|
|||||||
</h2>
|
</h2>
|
||||||
<EditValue
|
<EditValue
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="none"
|
placeholder="auto"
|
||||||
property="aspectRatio"
|
property="aspectRatio"
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
value={node ? node.aspectRatio : undefined}
|
value={node ? node.aspectRatio : undefined}
|
||||||
|
@@ -51,8 +51,8 @@ export type LayoutRecordT = RecordOf<{
|
|||||||
}>;
|
}>;
|
||||||
|
|
||||||
const r: LayoutRecordT = Record({
|
const r: LayoutRecordT = Record({
|
||||||
width: 100,
|
width: 'auto',
|
||||||
height: 100,
|
height: 'auto',
|
||||||
justifyContent: yoga.JUSTIFY_FLEX_START,
|
justifyContent: yoga.JUSTIFY_FLEX_START,
|
||||||
alignItems: yoga.ALIGN_STRETCH,
|
alignItems: yoga.ALIGN_STRETCH,
|
||||||
alignSelf: yoga.ALIGN_AUTO,
|
alignSelf: yoga.ALIGN_AUTO,
|
||||||
@@ -69,10 +69,10 @@ const r: LayoutRecordT = Record({
|
|||||||
flexShrink: 1,
|
flexShrink: 1,
|
||||||
children: List(),
|
children: List(),
|
||||||
aspectRatio: 'auto',
|
aspectRatio: 'auto',
|
||||||
minWidth: undefined,
|
minWidth: NaN,
|
||||||
maxWidth: undefined,
|
maxWidth: NaN,
|
||||||
minHeight: undefined,
|
minHeight: NaN,
|
||||||
maxHeight: undefined,
|
maxHeight: NaN,
|
||||||
});
|
});
|
||||||
|
|
||||||
export default r;
|
export default r;
|
||||||
|
@@ -14,17 +14,17 @@ import {Record} from 'immutable';
|
|||||||
import type {RecordOf} from 'immutable';
|
import type {RecordOf} from 'immutable';
|
||||||
|
|
||||||
export type PositionRecordT = RecordOf<{
|
export type PositionRecordT = RecordOf<{
|
||||||
top: string,
|
top: string | number,
|
||||||
right: string,
|
right: string | number,
|
||||||
bottom: string,
|
bottom: string | number,
|
||||||
left: string,
|
left: string | number,
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
const r: PositionRecordT = Record({
|
const r: PositionRecordT = Record({
|
||||||
top: '',
|
top: 0,
|
||||||
right: '',
|
right: 0,
|
||||||
bottom: '',
|
bottom: 0,
|
||||||
left: '',
|
left: 0,
|
||||||
});
|
});
|
||||||
|
|
||||||
export default r;
|
export default r;
|
||||||
|
@@ -14,13 +14,12 @@ import React, {Component} from 'react';
|
|||||||
import yoga, {Node} from 'yoga-layout/dist/entry-browser';
|
import yoga, {Node} from 'yoga-layout/dist/entry-browser';
|
||||||
import PositionGuide from './PositionGuide';
|
import PositionGuide from './PositionGuide';
|
||||||
import PositionRecord from './PositionRecord';
|
import PositionRecord from './PositionRecord';
|
||||||
|
import LayoutRecord from './LayoutRecord';
|
||||||
import type {LayoutRecordT} from './LayoutRecord';
|
import type {LayoutRecordT} from './LayoutRecord';
|
||||||
import type {Yoga$Direction} from 'yoga-layout';
|
import type {Yoga$Direction, Yoga$Node} from 'yoga-layout';
|
||||||
|
|
||||||
import './YogaNode.css';
|
import './YogaNode.css';
|
||||||
|
|
||||||
type Yoga$Node = any;
|
|
||||||
|
|
||||||
type ComputedLayout = {|
|
type ComputedLayout = {|
|
||||||
left: number,
|
left: number,
|
||||||
top: number,
|
top: number,
|
||||||
@@ -105,51 +104,53 @@ export default class YogaNode extends Component<Props, State> {
|
|||||||
|
|
||||||
createYogaNodes = (layoutDefinition: LayoutRecordT): Yoga$Node => {
|
createYogaNodes = (layoutDefinition: LayoutRecordT): Yoga$Node => {
|
||||||
const root = Node.create();
|
const root = Node.create();
|
||||||
root.setWidth(layoutDefinition.width);
|
|
||||||
root.setHeight(layoutDefinition.height);
|
|
||||||
root.setMinWidth(layoutDefinition.minWidth);
|
|
||||||
root.setMaxWidth(layoutDefinition.maxWidth);
|
|
||||||
root.setMinHeight(layoutDefinition.minHeight);
|
|
||||||
root.setMaxHeight(layoutDefinition.maxHeight);
|
|
||||||
root.setJustifyContent(layoutDefinition.justifyContent);
|
|
||||||
root.setAlignItems(layoutDefinition.alignItems);
|
|
||||||
root.setAlignSelf(layoutDefinition.alignSelf);
|
|
||||||
root.setAlignContent(layoutDefinition.alignContent);
|
|
||||||
root.setFlexGrow(layoutDefinition.flexGrow);
|
|
||||||
root.setFlexShrink(layoutDefinition.flexShrink);
|
|
||||||
|
|
||||||
root.setPadding(yoga.EDGE_TOP, layoutDefinition.padding.top);
|
const defaultLayout = LayoutRecord({});
|
||||||
root.setPadding(yoga.EDGE_RIGHT, layoutDefinition.padding.right);
|
[
|
||||||
root.setPadding(yoga.EDGE_BOTTOM, layoutDefinition.padding.bottom);
|
'width',
|
||||||
root.setPadding(yoga.EDGE_LEFT, layoutDefinition.padding.left);
|
'height',
|
||||||
|
'minWidth',
|
||||||
|
'maxWidth',
|
||||||
|
'minHeight',
|
||||||
|
'maxHeight',
|
||||||
|
'justifyContent',
|
||||||
|
'alignItems',
|
||||||
|
'alignSelf',
|
||||||
|
'alignContent',
|
||||||
|
'flexGrow',
|
||||||
|
'flexShrink',
|
||||||
|
'positionType',
|
||||||
|
'aspectRatio',
|
||||||
|
'flexWrap',
|
||||||
|
'flexDirection',
|
||||||
|
].forEach(key => {
|
||||||
|
try {
|
||||||
|
const value =
|
||||||
|
layoutDefinition[key] === ''
|
||||||
|
? defaultLayout[key]
|
||||||
|
: layoutDefinition[key];
|
||||||
|
root[`set${key[0].toUpperCase()}${key.substr(1)}`](value);
|
||||||
|
} catch (e) {}
|
||||||
|
});
|
||||||
|
|
||||||
root.setBorder(yoga.EDGE_TOP, layoutDefinition.border.top);
|
['padding', 'margin', 'position', 'border'].forEach(key => {
|
||||||
root.setBorder(yoga.EDGE_RIGHT, layoutDefinition.border.right);
|
['top', 'right', 'bottom', 'left'].forEach(direction => {
|
||||||
root.setBorder(yoga.EDGE_BOTTOM, layoutDefinition.border.bottom);
|
try {
|
||||||
root.setBorder(yoga.EDGE_LEFT, layoutDefinition.border.left);
|
root[`set${key[0].toUpperCase()}${key.substr(1)}`](
|
||||||
|
yoga[`EDGE_${direction.toUpperCase()}`],
|
||||||
root.setMargin(yoga.EDGE_TOP, layoutDefinition.margin.top);
|
layoutDefinition[key][direction] || 0,
|
||||||
root.setMargin(yoga.EDGE_RIGHT, layoutDefinition.margin.right);
|
);
|
||||||
root.setMargin(yoga.EDGE_BOTTOM, layoutDefinition.margin.bottom);
|
} catch (e) {}
|
||||||
root.setMargin(yoga.EDGE_LEFT, layoutDefinition.margin.left);
|
});
|
||||||
|
});
|
||||||
root.setPosition(yoga.EDGE_TOP, layoutDefinition.position.top);
|
|
||||||
root.setPosition(yoga.EDGE_RIGHT, layoutDefinition.position.right);
|
|
||||||
root.setPosition(yoga.EDGE_BOTTOM, layoutDefinition.position.bottom);
|
|
||||||
root.setPosition(yoga.EDGE_LEFT, layoutDefinition.position.left);
|
|
||||||
|
|
||||||
root.setPositionType(layoutDefinition.positionType);
|
|
||||||
|
|
||||||
root.setDisplay(yoga.DISPLAY_FLEX);
|
root.setDisplay(yoga.DISPLAY_FLEX);
|
||||||
root.setAspectRatio(layoutDefinition.aspectRatio);
|
|
||||||
root.setFlexWrap(layoutDefinition.flexWrap);
|
|
||||||
root.setFlexDirection(layoutDefinition.flexDirection);
|
|
||||||
(layoutDefinition.children || [])
|
(layoutDefinition.children || [])
|
||||||
.map(this.createYogaNodes)
|
.map(this.createYogaNodes)
|
||||||
.forEach((node, i) => {
|
.forEach((node, i) => {
|
||||||
root.insertChild(node, i);
|
root.insertChild(node, i);
|
||||||
});
|
});
|
||||||
|
|
||||||
return root;
|
return root;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -56,7 +56,11 @@ export default class Playground extends Component<Props, State> {
|
|||||||
layoutDefinition: {
|
layoutDefinition: {
|
||||||
width: 500,
|
width: 500,
|
||||||
height: 500,
|
height: 500,
|
||||||
children: [{}, {}, []],
|
children: [
|
||||||
|
{width: 100, height: 100},
|
||||||
|
{width: 100, height: 100},
|
||||||
|
{width: 100, height: 100},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
direction: yoga.DIRECTION_LTR,
|
direction: yoga.DIRECTION_LTR,
|
||||||
maxDepth: 3,
|
maxDepth: 3,
|
||||||
@@ -142,7 +146,9 @@ export default class Playground extends Component<Props, State> {
|
|||||||
const {selectedNodePath, layoutDefinition} = this.state;
|
const {selectedNodePath, layoutDefinition} = this.state;
|
||||||
if (selectedNodePath) {
|
if (selectedNodePath) {
|
||||||
const path = getPath(selectedNodePath).concat('children');
|
const path = getPath(selectedNodePath).concat('children');
|
||||||
const updatedChildren = layoutDefinition.getIn(path).push(LayoutRecord());
|
const updatedChildren = layoutDefinition
|
||||||
|
.getIn(path)
|
||||||
|
.push(LayoutRecord({width: 100, height: 100}));
|
||||||
this.modifyAtPath(
|
this.modifyAtPath(
|
||||||
path,
|
path,
|
||||||
updatedChildren,
|
updatedChildren,
|
||||||
|
@@ -9798,9 +9798,9 @@ yeast@0.1.2:
|
|||||||
version "0.1.2"
|
version "0.1.2"
|
||||||
resolved "https://registry.yarnpkg.com/yeast/-/yeast-0.1.2.tgz#008e06d8094320c372dbc2f8ed76a0ca6c8ac419"
|
resolved "https://registry.yarnpkg.com/yeast/-/yeast-0.1.2.tgz#008e06d8094320c372dbc2f8ed76a0ca6c8ac419"
|
||||||
|
|
||||||
yoga-layout@^1.9.0:
|
yoga-layout@^1.9.3:
|
||||||
version "1.9.0"
|
version "1.9.3"
|
||||||
resolved "https://registry.yarnpkg.com/yoga-layout/-/yoga-layout-1.9.0.tgz#84c77dc5fc79dde58715442632c4ad152f25cfe6"
|
resolved "https://registry.yarnpkg.com/yoga-layout/-/yoga-layout-1.9.3.tgz#f851935187f6d2945639b79c57ee0eac2fb7d886"
|
||||||
dependencies:
|
dependencies:
|
||||||
autogypi "^0.2.2"
|
autogypi "^0.2.2"
|
||||||
nbind "^0.3.14"
|
nbind "^0.3.14"
|
||||||
|
Reference in New Issue
Block a user