Coming from Yoga
venik started as a port of Yoga and its test suite is Yoga’s, ported. Given the same tree it produces the same boxes. It is not a drop-in replacement though: the API is different, and the defaults follow CSS instead of Yoga.
Defaults follow CSS
| Property | venik (and CSS) | Yoga |
|---|---|---|
flex-direction |
row |
column |
flex-shrink |
1 |
0 |
align-content |
stretch |
flex-start |
position |
static |
relative |
flex: n |
n 1 0 |
n 1 0 in web mode, otherwise n 0 auto |
A tree written against Yoga’s defaults needs setFlexDirection(FlexDirection.Column), setFlexShrink(0) and setAlignContent(Align.FlexStart) wherever it relied on them. There is no setUseWebDefaults because there is nothing left to opt into.
Absolute positioning
Because position: static is the default, an absolutely positioned node is placed relative to the nearest positioned ancestor, as in CSS, rather than its parent as in Yoga. Give the parent position: relative to get Yoga’s behaviour. See Containing block.
API differences
- Nodes and configs are created with
new Node()andnew Config(). There is nofree()orfreeRecursive(); the garbage collector reclaims them. - The parent of a node is the
ownerfield, andhasNewLayoutis a field rather than a method. Set it tofalseafter applying a node’s layout. - Measure functions receive
SizingModevalues (StretchFit,MaxContent,FitContent) instead of Yoga’sMeasureMode, and the node is the last argument rather than the first. See Measure functions. - Percentages are strings such as
"50%",autois the string"auto", and a value is unset withundefined. - Style getters return the node’s own immutable value object, and
getComputedLayout()returns one shared object, so reading styles and layout allocates nothing. - Errata and experimental feature flags are gone.
One quirk kept on purpose
Flexbox defines an automatic minimum size for flex items, so that min-width: auto keeps an item from shrinking below its content. Finding that size needs an extra measure pass, so venik follows every released Yoga and treats min-width: auto and min-height: auto as 0. Set an explicit minimum to keep an item from shrinking below its content.