2af08813c0bbef4061418468ccff57806b83ac6f.svn-base
4.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _yogaLayoutPrebuilt = _interopRequireDefault(require("yoga-layout-prebuilt"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const applyPositionStyles = (node, style) => {
if (!style.position) {
node.setPositionType(NaN);
}
if (style.position === 'absolute') {
node.setPositionType(_yogaLayoutPrebuilt.default.POSITION_TYPE_ABSOLUTE);
}
};
const applyMarginStyles = (node, style) => {
node.setMargin(_yogaLayoutPrebuilt.default.EDGE_START, style.marginLeft || style.marginX || style.margin || 0);
node.setMargin(_yogaLayoutPrebuilt.default.EDGE_END, style.marginRight || style.marginX || style.margin || 0);
node.setMargin(_yogaLayoutPrebuilt.default.EDGE_TOP, style.marginTop || style.marginY || style.margin || 0);
node.setMargin(_yogaLayoutPrebuilt.default.EDGE_BOTTOM, style.marginBottom || style.marginY || style.margin || 0);
};
const applyPaddingStyles = (node, style) => {
node.setPadding(_yogaLayoutPrebuilt.default.EDGE_LEFT, style.paddingLeft || style.paddingX || style.padding || 0);
node.setPadding(_yogaLayoutPrebuilt.default.EDGE_RIGHT, style.paddingRight || style.paddingX || style.padding || 0);
node.setPadding(_yogaLayoutPrebuilt.default.EDGE_TOP, style.paddingTop || style.paddingY || style.padding || 0);
node.setPadding(_yogaLayoutPrebuilt.default.EDGE_BOTTOM, style.paddingBottom || style.paddingY || style.padding || 0);
};
const applyFlexStyles = (node, style) => {
node.setFlexGrow(style.flexGrow || 0);
node.setFlexShrink(typeof style.flexShrink === 'number' ? style.flexShrink : 1);
if (style.flexDirection === 'row') {
node.setFlexDirection(_yogaLayoutPrebuilt.default.FLEX_DIRECTION_ROW);
}
if (style.flexDirection === 'row-reverse') {
node.setFlexDirection(_yogaLayoutPrebuilt.default.FLEX_DIRECTION_ROW_REVERSE);
}
if (style.flexDirection === 'column') {
node.setFlexDirection(_yogaLayoutPrebuilt.default.FLEX_DIRECTION_COLUMN);
}
if (style.flexDirection === 'column-reverse') {
node.setFlexDirection(_yogaLayoutPrebuilt.default.FLEX_DIRECTION_COLUMN_REVERSE);
}
if (typeof style.flexBasis === 'number') {
node.setFlexBasis(style.flexBasis);
} else if (typeof style.flexBasis === 'string') {
node.setFlexBasisPercent(parseInt(style.flexBasis, 10));
} else {
// This should be replaced with node.setFlexBasisAuto() when new Yoga release is out
node.setFlexBasis(NaN);
}
if (style.alignItems === 'stretch' || !style.alignItems) {
node.setAlignItems(_yogaLayoutPrebuilt.default.ALIGN_STRETCH);
}
if (style.alignItems === 'flex-start') {
node.setAlignItems(_yogaLayoutPrebuilt.default.ALIGN_FLEX_START);
}
if (style.alignItems === 'center') {
node.setAlignItems(_yogaLayoutPrebuilt.default.ALIGN_CENTER);
}
if (style.alignItems === 'flex-end') {
node.setAlignItems(_yogaLayoutPrebuilt.default.ALIGN_FLEX_END);
}
if (style.justifyContent === 'flex-start' || !style.justifyContent) {
node.setJustifyContent(_yogaLayoutPrebuilt.default.JUSTIFY_FLEX_START);
}
if (style.justifyContent === 'center') {
node.setJustifyContent(_yogaLayoutPrebuilt.default.JUSTIFY_CENTER);
}
if (style.justifyContent === 'flex-end') {
node.setJustifyContent(_yogaLayoutPrebuilt.default.JUSTIFY_FLEX_END);
}
if (style.justifyContent === 'space-between') {
node.setJustifyContent(_yogaLayoutPrebuilt.default.JUSTIFY_SPACE_BETWEEN);
}
if (style.justifyContent === 'space-around') {
node.setJustifyContent(_yogaLayoutPrebuilt.default.JUSTIFY_SPACE_AROUND);
}
};
const applyDimensionStyles = (node, style) => {
if (typeof style.width === 'number') {
node.setWidth(style.width);
} else if (typeof style.width === 'string') {
node.setWidthPercent(parseInt(style.width, 10));
} else {
node.setWidthAuto();
}
if (typeof style.height === 'number') {
node.setHeight(style.height);
} else if (typeof style.height === 'string') {
node.setHeightPercent(parseInt(style.height, 10));
} else {
node.setHeightAuto();
}
if (typeof style.minWidth === 'string') {
node.setMinWidthPercent(parseInt(style.minWidth, 10));
} else {
node.setMinWidth(style.minWidth || 0);
}
if (typeof style.minHeight === 'string') {
node.setMinHeightPercent(parseInt(style.minHeight, 10));
} else {
node.setMinHeight(style.minHeight || 0);
}
};
var _default = (node, style = {}) => {
applyPositionStyles(node, style);
applyMarginStyles(node, style);
applyPaddingStyles(node, style);
applyFlexStyles(node, style);
applyDimensionStyles(node, style);
};
exports.default = _default;