Files
yoga/javascript
Nick Gerleman f32d37a3d5 Deprecate YGConfigSetUseLegacyStretchBehaviour (#37117)
Summary:
X-link: https://github.com/facebook/react-native/pull/37117

Pull Request resolved: https://github.com/facebook/yoga/pull/1265

This deprecates `YGConfigSetUseLegacyStretchBehaviour` and `YGConfigGetUseLegacyStretchBehaviour`and points users to errata APIs instead. Using the C API will fire deprecation warnings, which should create errors in builds with `-Werror`, though they can be ignored if truly needed (like we do with the language bindings which need to expose their own deprecated interface).

Reviewed By: rshest

Differential Revision: D45337198

fbshipit-source-id: 7f069623e38834171f5702382bbf47c37a556a22
2023-04-30 08:20:05 -07:00
..
2022-12-28 01:27:12 -08:00
2022-12-28 01:27:12 -08:00
2023-02-20 19:54:03 -08:00
2022-12-30 14:29:42 -08:00
2022-12-28 01:27:12 -08:00
2022-12-28 01:27:12 -08:00

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

  1. Emscripten SDK
  2. CMake >= 3.13
  3. (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