2018-02-13 03:50:31 -08:00
|
|
|
---
|
2018-02-19 02:55:30 -08:00
|
|
|
path: "/getting-started/standalone"
|
2018-02-13 03:50:31 -08:00
|
|
|
title: "Standalone"
|
|
|
|
hasPlayground: false
|
|
|
|
---
|
|
|
|
|
2018-02-13 07:34:42 -08:00
|
|
|
# Standalone
|
|
|
|
|
|
|
|
Adding Yoga to a project is as simple as adding the dependency to your package manager of choice.
|
|
|
|
|
|
|
|
### Android
|
|
|
|
|
|
|
|
```groovy
|
|
|
|
dependencies {
|
2022-10-04 08:29:28 -07:00
|
|
|
implementation 'com.facebook.yoga.android:yoga-layout:x.x.x'
|
2018-02-13 07:34:42 -08:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
### Javascript
|
|
|
|
|
2018-03-22 04:12:02 -07:00
|
|
|
The JavaScript bindings for Yoga can be used from node.js and within the browser.
|
2019-02-19 04:45:45 -08:00
|
|
|
When using Yoga from node.js the native library is used, in browsers a pure JS
|
2023-08-14 21:20:59 -07:00
|
|
|
version is used (cross-compiled using [emscripten](https://emscripten.org/)).
|
2018-03-22 04:12:02 -07:00
|
|
|
|
2018-02-13 07:34:42 -08:00
|
|
|
```
|
|
|
|
$> yarn add yoga-layout
|
|
|
|
```
|
|
|
|
|
2023-08-14 21:20:59 -07:00
|
|
|
This is an example on how to use Yoga in JavaScript. For a full API reference,
|
|
|
|
have a look at the [TypeScript type definitions](https://github.com/facebook/yoga/blob/main/javascript/src/wrapAssembly.d.ts).
|
2018-03-22 04:12:02 -07:00
|
|
|
|
|
|
|
```js
|
2023-08-14 21:20:59 -07:00
|
|
|
import {loadYoga} from 'yoga-layout';
|
2018-03-22 04:12:02 -07:00
|
|
|
|
2023-08-14 21:20:59 -07:00
|
|
|
const Yoga = await loadYoga();
|
|
|
|
const root = Yoga.Node.create();
|
2018-03-22 04:12:02 -07:00
|
|
|
root.setWidth(500);
|
|
|
|
root.setHeight(300);
|
2023-08-14 21:20:59 -07:00
|
|
|
root.setJustifyContent(Yoga.JUSTIFY_CENTER);
|
|
|
|
root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW);
|
2018-03-22 04:12:02 -07:00
|
|
|
|
2023-08-14 21:20:59 -07:00
|
|
|
const node1 = Yoga.Node.create();
|
2018-03-22 04:12:02 -07:00
|
|
|
node1.setWidth(100);
|
|
|
|
node1.setHeight(100);
|
|
|
|
|
2023-08-14 21:20:59 -07:00
|
|
|
const node2 = Yoga.Node.create();
|
2018-03-22 04:12:02 -07:00
|
|
|
node2.setWidth(100);
|
|
|
|
node2.setHeight(100);
|
|
|
|
|
|
|
|
root.insertChild(node1, 0);
|
|
|
|
root.insertChild(node2, 1);
|
|
|
|
|
2023-08-14 21:20:59 -07:00
|
|
|
root.calculateLayout(500, 300, Yoga.DIRECTION_LTR);
|
2018-03-22 04:12:02 -07:00
|
|
|
console.log(root.getComputedLayout());
|
|
|
|
// {left: 0, top: 0, width: 500, height: 300}
|
|
|
|
console.log(node1.getComputedLayout());
|
|
|
|
// {left: 150, top: 0, width: 100, height: 100}
|
|
|
|
console.log(node2.getComputedLayout());
|
|
|
|
// {left: 250, top: 0, width: 100, height: 100}
|
|
|
|
```
|
|
|
|
|
2018-02-13 07:34:42 -08:00
|
|
|
### iOS
|
|
|
|
|
|
|
|
```
|
|
|
|
pod 'YogaKit', '~> 1.7'
|
|
|
|
```
|
|
|
|
|
|
|
|
## Including Yoga From Source
|
|
|
|
|
|
|
|
If you plan to include Yoga from Source in a C++ project then all you have to do is inlude
|
|
|
|
the top level `yoga` folder. Make sure to look at the top level `BUCK` file to ensure you build
|
|
|
|
using the same compiler flags.
|