Summary: current `MeasureFunc` is stricter than the previous one and when it returns only one dimension object yoga throw `TypeError: Missing field: "height"` or `TypeError: Missing field: "width"` this is a breaking change and `react-pdf` use this feature a lot, so i wanna return the previous behavior back codesandbox with reproduction on `yoga-layout-prebuilt`: https://codesandbox.io/s/yoga-layout-measure-callback-wrong-data-1l9133 Pull Request resolved: https://github.com/facebook/yoga/pull/1219 Reviewed By: NickGerleman Differential Revision: D42778696 Pulled By: jacdebug fbshipit-source-id: 2fb87be74f456ee34273655f2c47f62360001895
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_CENTER } 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_CENTER } 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.
A specific entrypoint may be specified on platforms which do not understand export conditions.
import { loadYoga } from "yoga-layout/dist/entrypoint/wasm-async";
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