Summary: Pull Request resolved: https://github.com/facebook/yoga/pull/1500 Inspired by the frequent usage of Expo snacks to run RN, to repro Yoga issues, this replaces the Playground port with a new ground up Playground UI. This UI right now is pretty simple, with a JSX editor which creates a Yoga tree, which is then rendered using the WebAssembly variant of Yoga. There are a lot of ways we can continue to improve this, but this merges the foundation. Subjectively, I find this more useful as a tool to play with Yoga behavior than the GUI. This also replaces some of the bits of the homepage, and adds a playground entrypoint (though it's pretty identical to the one I've been testing on the home page). Reviewed By: yungsters Differential Revision: D51963201 fbshipit-source-id: 1265cb1784151b685686e189d47ecd42cbacdf8f
yoga-layout
This package provides prebuilt WebAssembly bindings for the Yoga layout engine.
Usage
import {Yoga, Align} from 'yoga-layout';
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();
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.
ES Modules
yoga-layout
is only provided as an ES Module, relying on top-level await. This allows providing a synchronous API, while still allowing async WebAssembly compilation in browsers, and will allow eventual usage of ESM/WASM interop.
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