Summary: X-link: https://github.com/facebook/react-native/pull/41019 ### Changes made - Regenerated tests (as some aspect ratio tests seem to be out of date compared to the fixtures) - Added SpaceEvenly variant to the "Align" enums (via enums.py) - Implemented `align-content: space-evenly` alignment in CalculateLayout.cpp - Added generated tests `align-content: space-evenly` - Updated NumericBitfield test to account for the fact that the Align enum now requires more bits (this bit could do with being reviewed as I am not 100% certain that it's valid to just update the test like this). ### Changes not made - Any attempt to improve the spec-compliance of content alignment in general (e.g. I think https://github.com/facebook/yoga/pull/1013 probably still needs to happen) Pull Request resolved: https://github.com/facebook/yoga/pull/1422 Reviewed By: yungsters Differential Revision: D50305438 Pulled By: NickGerleman fbshipit-source-id: ef9f6f14220a0db066bc30db8dd690a4a82a0b00
yoga-layout
This package provides prebuilt JavaScript bindings for the Yoga layout engine. Both WebAssembly and asm.js variants are packaged, with the optimal loaded based on platform.
Usage
The default entrypoint provides an asynchronous loader function to return a Yoga instance.
import {loadYoga, Align} from 'yoga-layout';
const Yoga = await loadYoga();
const node = Yoga.Node.create();
node.setAlignContent(Align.Center);
An alternative synchronous API is provided for compatibility, but requires using asm.js in browsers instead of WebAssembly, leading to worse performance and larger assets.
import Yoga, {Align} from 'yoga-layout/sync';
const node = Yoga.Node.create();
node.setAlignContent(Align.Center);
Objects created by Yoga.<>.create()
are not automatically garbage collected and should be freed once they are no longer in use.
// Free a config
config.free();
// Free a tree of Nodes
node.freeRecursive();
// Free a single Node
node.free();
Selecting WebAssembly or asm.js
For better performance and smaller packages, WebAssembly is preferred to asm.js where available. yoga-layout
tries to provide the right default using export maps so that platforms which can take advantage of WebAssembly use it by default.
Different entrypoints are exposed to choose a flavor explicitly.
import {loadYoga} from 'yoga-layout/wasm-async';
Using TypeScript
This package provides out-of-the-box TypeScript typings so long as tsc
is configured to support ESM resolution. It is recommended to set moduleResolution: 'bundler'
or moduleResolution: node16
in your tsconfig.json
according to your environment.
Contributing
Requirements
- Emscripten SDK
- CMake >= 3.13
- (Optional) ninja, for faster builds
Building
git clone https://github.com/facebook/yoga.git
cd yoga/javascript
yarn install
yarn build
Testing
# Build and test all entrypoints
yarn test
# Build and test a specific entrypoint
yarn test:asmjs-sync