Compare commits

..

48 Commits
1.3.0 ... 1.4.0

Author SHA1 Message Date
Lukas Wöhrl
25f14a1917 Fix min constraint incorrectly reducing available space
Summary:
If a min constraint exists. It incorrectly reduces the available space by that amount. This adds a test and fix for this.
Closes https://github.com/facebook/yoga/pull/501

Differential Revision: D4867146

Pulled By: emilsjolander

fbshipit-source-id: ceafe070bfe7f501929d316656ac44c4e1753059
2017-04-11 13:11:08 -07:00
Lukas Wöhrl
e9927377b5 Fix position on root node with RTL direction
Summary:
If the root node has a position and we have a RTL layout, that position must be like LTR direction. See #477.
Closes https://github.com/facebook/yoga/pull/502

Differential Revision: D4867144

Pulled By: emilsjolander

fbshipit-source-id: b5ad3d87e7054090da12d7665a3d1abe8496a548
2017-04-11 13:11:05 -07:00
Kazuki Sakamoto
3ea76f8a9b Add YogaConfig unit tests
Summary:
- depends on #497
Closes https://github.com/facebook/yoga/pull/498

Reviewed By: emilsjolander

Differential Revision: D4796199

Pulled By: splhack

fbshipit-source-id: c63f23da11a719b36c0d49e954b29c0016cad8c7
2017-04-10 14:26:51 -07:00
Kazuki Sakamoto
8a45ed9671 Add YGConfigGetInstanceCount
Summary:
- depends on #496
- For memory leak unit test
- Expose the API for C#
Closes https://github.com/facebook/yoga/pull/497

Reviewed By: emilsjolander

Differential Revision: D4796190

Pulled By: splhack

fbshipit-source-id: 99e4e78e8dfb3d459cf6cd7103ab252c3748e5a6
2017-04-10 14:26:51 -07:00
Kazuki Sakamoto
1520749351 Update YogaConfig
Summary:
- Bugfix: Retain managed YogaConfig to prevent releasing unmanaged YogaConfig
- Use the same YogaConfig in the copy constructor
- Expose Set/GetUseWebDefaults APIs
- Split YogaConfig out from YogaNode.cs
Closes https://github.com/facebook/yoga/pull/496

Reviewed By: emilsjolander

Differential Revision: D4796178

Pulled By: splhack

fbshipit-source-id: cafabdc051ca914af547acbbf3d2246a5618e8bb
2017-04-10 11:03:43 -07:00
birfincankafein
f66f52d1ba Make YogaLayout create programmatically. Make YogaNode of YogaLayout …
Summary:
Make YogaLayout constructible programmatically.
Make YogaLayout's YogaNode accessible from outside.
Closes https://github.com/facebook/yoga/pull/436

Differential Revision: D4850451

Pulled By: emilsjolander

fbshipit-source-id: 2821a6ef4160854244c0227a3c4c96369f7b2e64
2017-04-07 02:12:25 -07:00
Christine Abernathy
49e18738c3 Remove gists and fix iOS instructions
Summary:
Remove gists in code blocks. This also made it easier to fix the iOS sample app instructions in the getting started.

>Note: I also needed to update my gems as I was having problems running `bundle install`. The errors were around installing json v1.8.3. It was resolved by creating a new Gemfile.lock.

1. Build website and check changed pages (see attached Getting Started for an example)
2. Also check how it would look for mobile site (see attached index page)

Verified that the code snippets matched previous snippets and styling acceptable.

![yoga_gs](https://cloud.githubusercontent.com/assets/691109/24681238/1601fcc8-1949-11e7-8caa-5ac78a4c9a6b.png)
![yoga_index_mobile](https://cloud.githubusercontent.com/assets/691109/24681248/1ee3ea86-1949-11e7-9677-83056f93e385.png)
Closes https://github.com/facebook/yoga/pull/500

Differential Revision: D4834356

Pulled By: emilsjolander

fbshipit-source-id: f47dca4b7518822b195f0bd5076fbf852904372b
2017-04-05 05:43:21 -07:00
Lukas Wöhrl
586b57009a Optimize log print by using html format
Summary:
See facebook/yoga#453. Optimizes the node log print by generating some enum text via ```enum.py``` and moving printing to new functions to reduce boilerplate code.

Changes the log output to format the nodes in html to be able to copy paste it  into browsers for quick debugging.

Hides all default values.
Closes https://github.com/facebook/yoga/pull/479

Reviewed By: gkassabli

Differential Revision: D4802184

Pulled By: emilsjolander

fbshipit-source-id: 143bd63cbc31fb0755d711062cb4e6a448049ba3
2017-04-03 09:41:57 -07:00
Lukas Wöhrl
5112564f08 Don't transfer layout outputs to java for unset edges
Summary:
See facebook/yoga#483. We should not transfer the layout if the layout didn't change. (using ```hasNewLayout```). This also changes that the lock on the java node is only aquired if needed, and it holds the lock only for the time the values are set and not for the time all it's children are set.
Closes https://github.com/facebook/yoga/pull/484

Reviewed By: astreet

Differential Revision: D4802966

Pulled By: emilsjolander

fbshipit-source-id: e8a8f2280ad6b25b98fc68b07eac68e0ec80fe3e
2017-04-01 04:43:09 -07:00
Lukas Wöhrl
34726a9926 Fix xmlns import for android yoga library
Summary:
Fix xmlns import for yoga library by using `apk` instead of `lib` in the comment.
Closes https://github.com/facebook/yoga/pull/495

Reviewed By: emilsjolander

Differential Revision: D4802918

Pulled By: rspencer01

fbshipit-source-id: 9cef7709606e30e8e30af6e396866ac4900168bf
2017-03-30 09:32:11 -07:00
Lukas Wöhrl
5884ab7b76 Don't transfer layout outputs to java for nodes which don't have a new layout
Summary:
As suggested in facebook/yoga#484. This is the PR which only adds the part of using a local bool field for storing the hasLayoutFlag, to be able to pass the layout only if it has really changed.
Closes https://github.com/facebook/yoga/pull/492

Reviewed By: astreet

Differential Revision: D4786961

Pulled By: emilsjolander

fbshipit-source-id: cf3d354b93f6dcc3ef817ef73a47bd29e37d1848
2017-03-29 16:44:13 -07:00
Robert Spencer
60db018ce4 Fix native build script for deployments
Summary: The native build script didn't make the directories it needed, and thus only worked if you'd run it before :O

Reviewed By: emilsjolander

Differential Revision: D4794861

fbshipit-source-id: 69764ef1ddadf63333ce5d91dfa85bc943479fef
2017-03-29 07:42:59 -07:00
Robert Spencer
6b002bad3d Version bump of java library
Summary: Version bump as we have introduced `setUseWebDefaults`.

Reviewed By: emilsjolander

Differential Revision: D4794772

fbshipit-source-id: 0a42def3bec3f4f76caf6da01e3b9ab3679ebcb0
2017-03-29 06:56:13 -07:00
Emil Sjolander
5b173c1b61 Set web defaults when resetting
Summary: Set web defaults when resetting

Reviewed By: astreet

Differential Revision: D4779742

fbshipit-source-id: 5b8c5d7bd432a12984e4ebfd3187da3d680272cd
2017-03-29 03:12:33 -07:00
Emil Sjolander
bc2fb5c7ab Expose UseWebDefaults to java
Summary: Expose UseWebDefaults to java

Reviewed By: astreet

Differential Revision: D4779743

fbshipit-source-id: 65a4184af6fb959fefff5c2014522c551ca440d5
2017-03-29 03:12:33 -07:00
Emil Sjolander
ebdf82f491 Set hasNewLayout on children when changing their layout due to display none parent
Summary: Mark nodes as having a new layout when changing display to none recursively.

Reviewed By: astreet

Differential Revision: D4786615

fbshipit-source-id: 2f3a16661d37bc37939e8e7a551445886a06524e
2017-03-28 12:43:10 -07:00
Maël Nison
36f6fa9861 Fix tests of splitted config feature
Summary:
The following PR fixes the tests used in the javascript port (it modifies gentest.rb).

These changes don't yet pass, it seems something is segfaulting somewhere. I have to check if it comes from nbind, the yoga library, or the node bridge itself. There's also some fails on the browser build, but it might be the same issue.
Closes https://github.com/facebook/yoga/pull/487

Reviewed By: emilsjolander

Differential Revision: D4778870

Pulled By: astreet

fbshipit-source-id: 936fbca564ec89738c78e50c4402c53eb6867dec
2017-03-28 10:49:46 -07:00
Kazuki Sakamoto
91a34bb875 Support IL2CPP and fix stale handle
Summary:
- Unity IL2CPP (ENABLE_IL2CPP) requires the same code path with AOT compile.
- Clean up unneeded code in YGConfigHandle.
- YogaNode.Reset makes YGNodeHandle stale. Unmanaged side was reset by YGNodeReset, but YGNodeHandle keeps to retain the old managed handle. Release it.
Closes https://github.com/facebook/yoga/pull/491

Reviewed By: astreet

Differential Revision: D4765683

Pulled By: splhack

fbshipit-source-id: 83bfe19feb0e6ec45dc504e42b0c6c34e10af8e2
2017-03-27 08:12:22 -07:00
Kazuki Sakamoto
d342fb1879 Use Assert.Throws instead of ExpectedException
Summary:
Unity 5.6 doesn't have ExpectedException attribute.
Closes https://github.com/facebook/yoga/pull/486

Reviewed By: astreet

Differential Revision: D4739149

Pulled By: splhack

fbshipit-source-id: 9cc486a094c6e159b46fa7938669fecbf523c666
2017-03-27 08:12:22 -07:00
Emil Sjolander
b283572453 Revert D4716024: [yoga] Avoid transfering cached layout information to java
Summary: This reverts commit c30763a6fc7426d653c7a6ca129615cddb4140e9

Differential Revision: D4716024

fbshipit-source-id: 7276b4bbf072aa444c5ae9fd1a3d62ea87a0cec1
2017-03-17 13:27:18 -07:00
Shoaib Meenai
62a74a5ef9 Move -fPIC into YOGA_DEFS
Summary:
Move -fPIC from BUCK to YOGA_DEFS, so that it can be overridden when
building yoga inside another build tree (since the larger build tree
may need its own configuration for -fPIC). No change when building yoga
standalone.

Reviewed By: emilsjolander

Differential Revision: D4714782

fbshipit-source-id: c706336cda72b36045e744e4fcaea4c0899bcf38
2017-03-17 10:58:42 -07:00
Emil Sjolander
a14aeb27bb Avoid transfering cached layout information to java
Summary: Don't transfer layout outputs to java if the layout was cached as this means that it has already been transfered

Reviewed By: astreet

Differential Revision: D4716024

fbshipit-source-id: c30763a6fc7426d653c7a6ca129615cddb4140e9
2017-03-17 09:14:08 -07:00
Emil Sjolander
249d010dad Invalidate layout when node is removed from tree
Summary: The layout of a node is invalid once it leaves the tree. Let's reset it for safety in case it is added to another tree.

Reviewed By: astreet

Differential Revision: D4716022

fbshipit-source-id: 399cc64a4b3f5fd3fc469ea37bdd31abe474dc6c
2017-03-17 09:14:08 -07:00
Pascal Hartig
9b13fdeae4 Add YOGA_ROOTS to permit multiple definitions
Summary:
This changes the `YOGA_ROOT` to `YOGA_ROOTS` in `YOGA_DEFS`. This allows the
inclusion of Yoga in the exported Components libraries directory and
back-references to the nested dependencies within it.

Reviewed By: rspencer01

Differential Revision: D4721745

fbshipit-source-id: 2dc9d4a730076510aed02027cb6713f6326c588d
2017-03-16 10:41:59 -07:00
Robert Spencer
794b6b35ce YogaLayout perf tests
Summary: We would like to know some numbers on benchmarking `YogaLayout` against other layouts, particularly `LinearLayout`.  This implements a `BenchmarkActivity` to fill that need.

Reviewed By: emilsjolander

Differential Revision: D4565531

fbshipit-source-id: fe1c558beb603c3116ac3d0dd6654b0376dd6b8a
2017-03-15 09:11:24 -07:00
Maxime Ollivier
dcff4d3db2 Update .travis.yml to build iOS sample project
Summary: Closes https://github.com/facebook/yoga/pull/481

Differential Revision: D4713645

Pulled By: emilsjolander

fbshipit-source-id: b51eded585b59f50471e01271aabb5672b0682b1
2017-03-15 09:11:24 -07:00
Lukas Wöhrl
b94466e502 Fix align-content: center, flex-end alignment with margin
Summary:
This fixes ```align-content: center``` and ```align-content: flex-end``` when the child exceeds the parents size. See #476. It also fixes those layouts if the child has ```margin: auto``` set.
Closes https://github.com/facebook/yoga/pull/477

Differential Revision: D4697833

Pulled By: emilsjolander

fbshipit-source-id: d081ec7ea559a5f2bd3271c3a4dc272960beddfa
2017-03-15 05:31:38 -07:00
Dustin Shahidehpour
11052053d8 Upgrade sample project to use bulk update API.
Summary: Using the newer/recommended API in the sample project. #accept2ship

Reviewed By: emilsjolander

Differential Revision: D4698936

fbshipit-source-id: 07b61df897524cd38390ba48dfa2a2e10942329b
2017-03-13 12:11:54 -07:00
Dustin Shahidehpour
6ab3984bba Update README.md
Summary: Closes https://github.com/facebook/yoga/pull/478

Differential Revision: D4698444

Pulled By: dshahidehpour

fbshipit-source-id: 4e87f8f4922ff3888f27d97063495ab2a5edd5fd
2017-03-13 09:58:09 -07:00
Maxime Ollivier
136e0c7e52 undo iOS sample project build
Summary:
Temporarily remove the iOS sample project build.
Closes https://github.com/facebook/yoga/pull/475

Differential Revision: D4689718

Pulled By: emilsjolander

fbshipit-source-id: 9249e9d03dfdb60e222f8c3c0f496ec67122ed62
2017-03-10 10:12:19 -08:00
Kazuki Sakamoto
7e2ef926ea Add Workaround #if to GC test
Summary: Closes https://github.com/facebook/yoga/pull/474

Reviewed By: emilsjolander

Differential Revision: D4687978

Pulled By: splhack

fbshipit-source-id: 5b411e94f76c9846eadd2f01f0c8fd511fd6cdbf
2017-03-10 09:42:16 -08:00
Lukas Wöhrl
061981fb23 Align resolve function names to have similiar namings
Summary:
We have some resolve functions with ```YG**Resolve``` and others named ```YGResolve**```. This changes both to be named like the later one, as I think this is the grammatically better readable one.
Closes https://github.com/facebook/yoga/pull/471

Differential Revision: D4688997

Pulled By: emilsjolander

fbshipit-source-id: 38b5f84d4d39ed3effedf08188085b9efd96b4ce
2017-03-10 06:13:06 -08:00
Maxime Ollivier
3d6fb2f2e5 Update .travis.yml to build iOS sample project
Summary: Closes https://github.com/facebook/yoga/pull/472

Differential Revision: D4688993

Pulled By: emilsjolander

fbshipit-source-id: 9b5a16866c4258245a50582aa1110d54139a7ec2
2017-03-10 05:26:00 -08:00
Kazuki Sakamoto
a8e6123d47 Allow to reset measure and baseline functions
Summary:
Once measure and baseline functions are set, C# layer never calls YGNodeSetMeasure/BaselineFunc with NULL. This diff will fix the issue.
Closes https://github.com/facebook/yoga/pull/468

Reviewed By: emilsjolander

Differential Revision: D4676753

Pulled By: splhack

fbshipit-source-id: da34de2fc28adf320a18de2addffe9671cf1ecf9
2017-03-09 08:13:28 -08:00
Lukas Wöhrl
406c8a2117 Move pointscalefactor to config
Summary:
This adds some improvements to the new ```YGConfig```, it tackles #452 and moves the scalefactor into the config.
Closes https://github.com/facebook/yoga/pull/457

Differential Revision: D4675088

Pulled By: emilsjolander

fbshipit-source-id: 99b2c734d6c5139fe1dc8bdeb014bb038f0e337d
2017-03-09 07:35:07 -08:00
Robert Spencer
0445962bd4 Use camelCase for attributes
Summary: The android standard is `prefix_camelCase` such as `layout_marginLeft`.  This changes attributes like `yg_margin_left` to `yg_marginLeft`.

Reviewed By: emilsjolander

Differential Revision: D4681514

fbshipit-source-id: 76a80c24f19f3ee52329a2a254fe1f5fbcb40b9c
2017-03-09 06:26:34 -08:00
Lukas Wöhrl
09f0c2d8ce Take margin into account on max dimension
Summary:
We need to take the margin into account if we clip on max dimension. Fixes #466.
Closes https://github.com/facebook/yoga/pull/467

Differential Revision: D4681342

Pulled By: emilsjolander

fbshipit-source-id: 56311df9864a284d553c31f1c6db382f337f1fad
2017-03-09 03:56:00 -08:00
Lukas Wöhrl
8dea884a69 Fix typo in test class to use same name as the others
Summary:
Fixes a typo in the test class to use the same name as the other tests.
Closes https://github.com/facebook/yoga/pull/469

Differential Revision: D4681340

Pulled By: emilsjolander

fbshipit-source-id: a5e60b5e2aa74dc25e677a5579bb853492708c16
2017-03-09 03:42:56 -08:00
Robert Spencer
57898762a2 Bump NDK version and build all architectures
Summary: Until now we've been building only arm-v7 and x86 libraries.  This builds 64 bit versions too, and sets up the gradle script to publish them.  We also bump up the NDK version, and increase the min API to 21, as this is the first API supporting 64 bit NDK tools.

Reviewed By: emilsjolander

Differential Revision: D4674049

fbshipit-source-id: fbc87541fcaf72b83d376646c7aab70c317125e1
2017-03-09 03:12:42 -08:00
Lukas Wöhrl
01bf8d7b6c Add unittest for percentage width inside absolute layout
Summary:
Added unittest to constraint layout of percentage width inside absolute parent. See #454.
Closes https://github.com/facebook/yoga/pull/456

Differential Revision: D4674103

Pulled By: emilsjolander

fbshipit-source-id: 569a762e5a2b4ac80cd79bfbc9abfe57ada74dc9
2017-03-08 09:26:08 -08:00
Rui Marinho
af8d55c08e Missing project, Badges, ignore test on MacOS for a green build
Summary:
For some reason this Universal.csproj wasn't pulled from rozele PR.. i added the missing files.

Added badges for build and nuget for more exposure.

Ignore a failing unit test on MacOS for a green build.
Closes https://github.com/facebook/yoga/pull/464

Reviewed By: emilsjolander

Differential Revision: D4670392

Pulled By: splhack

fbshipit-source-id: 9ea3150b92039cab87ce8696db983fdf373c5388
2017-03-08 07:58:46 -08:00
Bryan Jennings
53398b42c6 Fix broken link, rename CONTRIBUTING to CONTRIBUTING.md
Summary:
Before:
There was a broken link in ./docs/README.md
CONTRIBUTING didn't render markup on Github

After:
All links to CONTRIBUTING.md are not broken anymore
CONTRIBUTING.md renders markup on Github
Closes https://github.com/facebook/yoga/pull/458

Differential Revision: D4673746

Pulled By: emilsjolander

fbshipit-source-id: 151c1f38789a96b61dfbb544fd11996098dc456d
2017-03-08 06:41:24 -08:00
Robert Spencer
1bf142e048 Separate annotation processors and include in java as provided
Summary:
With the current setup, the final aar contains `com.facebook.proguard.annotation.DoNotStrip`.  This is not needed (it is only used for proguard), and thus should not get published.

We move proguard annotations into its own project for this, and place it into `java/proguard-annotations`. Here we adopt the gradle convention of `src/main` to make for a nice, clean (one line!) gradle script.  As a different subproject, we can include this to `:yoga` as a `provided` dependency now, which doesn't include it in the output artifact.

Reviewed By: emilsjolander

Differential Revision: D4666572

fbshipit-source-id: a0cb26cb6c264065a0bd355b7d72ba02e3759560
2017-03-08 00:12:05 -08:00
Rui Marinho
0405c4f77d Update nuget and sln
Summary:
Update nuget CI
Closes https://github.com/facebook/yoga/pull/463

Reviewed By: emilsjolander

Differential Revision: D4666500

Pulled By: splhack

fbshipit-source-id: 1d77457d59eafe6de855a27b4f8a8567cd415b7b
2017-03-07 09:11:14 -08:00
Robert Spencer
61595763b0 Use SVGs for all badges
Summary: I accidentally used pngs for the bintray badges.  This renders ugly sometimes.  This corrects that.

Reviewed By: emilsjolander

Differential Revision: D4666641

fbshipit-source-id: df53f08a77be3067804d7671d673146f208a24fd
2017-03-07 09:11:14 -08:00
Robert Spencer
f6ecc8da7b Update readme with badges and YogaLayout badges
Summary: This adds bintray badges to the readme, and creates a readme for the android code.

Reviewed By: emilsjolander

Differential Revision: D4666314

fbshipit-source-id: a2549374f3e9c39c260160d1e32fb37801ff4208
2017-03-07 06:56:26 -08:00
Robert Spencer
32792a0de5 Gradle versionbump
Summary: Version 1.3

Reviewed By: emilsjolander

Differential Revision: D4666239

fbshipit-source-id: fad4b97b9947342ac91718d4f261184e7baf334a
2017-03-07 06:56:26 -08:00
Emil Sjolander
c3d60b55bd Bump podspec version
Summary: Bump podspec version

Reviewed By: dshahidehpour

Differential Revision: D4666248

fbshipit-source-id: 924aea76db5d68acbae7048d8542cab71122cbc2
2017-03-07 06:28:47 -08:00
139 changed files with 7697 additions and 911 deletions

View File

@@ -3,7 +3,7 @@
[android]
target = Google Inc.:Google APIs:19
[ndk]
ndk_version = 12.1.2977051
ndk_version = 13.1.3345770
compiler = clang
app_platform = android-19
cpu_abis = armv7, x86
app_platform = android-21
cpu_abis = arm64, armv7, x86, x86_64

View File

@@ -40,7 +40,11 @@ before_install:
# iOS
- |
if [[ $TARGET = "ios" ]]; then
brew outdated xctool || brew upgrade xctool
brew outdated xctool || brew upgrade xctool;
gem install xcpretty --no-document --quiet;
gem install cocoapods --pre --no-document --quiet;
pod repo update --silent;
pod install --project-directory=YogaKit/YogaKitSample/;
fi
# Emscripten (used for js tests)
@@ -102,7 +106,9 @@ script:
# iOS
- |
if [[ $TARGET = "ios" ]]; then
buck test --verbose 0 //YogaKit:YogaKitTests --config cxx.default_platform=iphonesimulator-x86_64
buck test --verbose 0 //YogaKit:YogaKitTests --config cxx.default_platform=iphonesimulator-x86_64 &&
set -o pipefail &&
xcodebuild build -workspace YogaKit/YogaKitSample/YogaKitSample.xcworkspace -scheme YogaKitSample -sdk iphonesimulator | xcpretty -c
fi
# Android

3
BUCK
View File

@@ -12,9 +12,8 @@ GMOCK_OVERRIDE_FLAGS = [
"-Wno-inconsistent-missing-override",
]
COMPILER_FLAGS = BASE_COMPILER_FLAGS + [
COMPILER_FLAGS = LIBRARY_COMPILER_FLAGS + [
"-std=c11",
"-fPIC",
]
TEST_COMPILER_FLAGS = BASE_COMPILER_FLAGS + GMOCK_OVERRIDE_FLAGS + ["-std=c++11"]

View File

@@ -1,4 +1,4 @@
# Yoga [![CocoaPods](https://img.shields.io/cocoapods/v/YogaKit.svg)](http://cocoapods.org/pods/YogaKit) [![npm](https://img.shields.io/npm/v/yoga-layout.svg)](https://www.npmjs.com/package/yoga-layout)
# Yoga [![CocoaPods](https://img.shields.io/cocoapods/v/YogaKit.svg)](http://cocoapods.org/pods/YogaKit) [![npm](https://img.shields.io/npm/v/yoga-layout.svg)](https://www.npmjs.com/package/yoga-layout) [![bintray](https://img.shields.io/bintray/v/facebook/maven/com.facebook.yoga:yoga.svg)](https://bintray.com/facebook/maven/com.facebook.yoga%3Ayoga/_latestVersion) [![NuGet](https://img.shields.io/nuget/v/Facebook.Yoga.svg)](https://www.nuget.org/packages/Facebook.Yoga)
[![C Status](https://badges.herokuapp.com/travis/facebook/yoga?env=TARGET=c&label=C)](https://travis-ci.org/facebook/yoga)
[![Java Status](https://badges.herokuapp.com/travis/facebook/yoga?env=TARGET=java&label=Java)](https://travis-ci.org/facebook/yoga)
@@ -7,6 +7,9 @@
[![JavaScript Status](https://badges.herokuapp.com/travis/facebook/yoga?env=TARGET=js&label=JavaScript)](https://travis-ci.org/facebook/yoga)
[![Android Status](https://badges.herokuapp.com/travis/facebook/yoga?env=TARGET=android&label=Android)](https://travis-ci.org/facebook/yoga)
[![Visual Studio Team services](https://img.shields.io/vso/build/rumar/fe6d27b5-e424-4f61-b8f6-e2ec2f8755fb/1.svg?label=vsts-windows)]()
[![Visual Studio Team services](https://img.shields.io/vso/build/rumar/fe6d27b5-e424-4f61-b8f6-e2ec2f8755fb/2.svg?label=vsts-osx)]()
## Building
Yoga builds with [buck](https://buckbuild.com). Make sure you install buck before contributing to Yoga. Yoga's main implementation is in C, with bindings to supported languages and frameworks. When making changes to Yoga please ensure the changes are also propagated to these bindings when applicable.

View File

@@ -1,10 +1,10 @@
YOGA_ROOT = '//...'
YOGA_ROOTS = ['//...']
JAVA_TARGET = '//java:java'
INFER_ANNOTATIONS_TARGET = '//lib/infer-annotations:infer-annotations'
JSR_305_TARGET = '//lib/jsr-305:jsr-305'
JUNIT_TARGET = '//lib/junit:junit'
PROGRUARD_ANNOTATIONS_TARGET = '//java/com/facebook/proguard/annotations:annotations'
PROGRUARD_ANNOTATIONS_TARGET = '//java/proguard-annotations/src/main/java/com/facebook/proguard/annotations:annotations'
SOLOADER_TARGET = '//lib/soloader:soloader'
GTEST_TARGET = '//lib/gtest:gtest'
JNI_TARGET = '//lib/jni:jni'
@@ -33,6 +33,10 @@ BASE_COMPILER_FLAGS = [
'-O3',
]
LIBRARY_COMPILER_FLAGS = BASE_COMPILER_FLAGS + [
'-fPIC',
]
def yoga_dep(dep):
return '//' + dep

View File

@@ -1,6 +1,6 @@
Pod::Spec.new do |spec|
spec.name = 'Yoga'
spec.version = '1.2.0'
spec.version = '1.3.0'
spec.license = { :type => 'BSD', :file => "LICENSE" }
spec.homepage = 'https://facebook.github.io/yoga/'
spec.documentation_url = 'https://facebook.github.io/yoga/docs/api/c/'
@@ -11,7 +11,7 @@ Pod::Spec.new do |spec|
spec.authors = 'Facebook'
spec.source = {
:git => 'https://github.com/facebook/yoga.git',
:tag => '1.2.0',
:tag => '1.3.0',
}
spec.module_name = 'yoga'

View File

@@ -1,6 +1,6 @@
podspec = Pod::Spec.new do |spec|
spec.name = 'YogaKit'
spec.version = '1.2.0'
spec.version = '1.3.0'
spec.license = { :type => 'BSD', :file => "LICENSE" }
spec.homepage = 'https://facebook.github.io/yoga/'
spec.documentation_url = 'https://facebook.github.io/yoga/docs/api/yogakit/'
@@ -11,14 +11,14 @@ podspec = Pod::Spec.new do |spec|
spec.authors = 'Facebook'
spec.source = {
:git => 'https://github.com/facebook/yoga.git',
:tag => '1.2.0',
:tag => '1.3.0',
}
spec.platform = :ios
spec.ios.deployment_target = '8.0'
spec.ios.frameworks = 'UIKit'
spec.dependency 'Yoga', '~> 1.2'
spec.dependency 'Yoga', '~> 1.3'
spec.source_files = 'YogaKit/Source/*.{h,m}'
spec.public_header_files = 'YogaKit/Source/{YGLayout,UIView+Yoga}.h'
spec.private_header_files = 'YogaKit/Source/YGLayout+Private.h'

View File

@@ -8,7 +8,7 @@
YogaKit is available to install via [CocoaPods](https://cocoapods.org/).
```
pod 'YogaKit', '~> 1.1'
pod 'YogaKit', '~> 1.3'
```
## Getting Started
@@ -19,4 +19,4 @@ We also have a sample project. To try it out, clone this repo and open `YogaKitS
## Contributing
We welcome all pull-requests! At Facebook we sync the open source version of `YogaKit` daily, so we're always testing the latest changes.
See the [CONTRIBUTING](https://github.com/facebook/yoga/blob/master/CONTRIBUTING) file for how to help out.
See the [CONTRIBUTING.md](https://github.com/facebook/yoga/blob/master/CONTRIBUTING.md) file for how to help out.

View File

@@ -4,9 +4,9 @@ PODS:
- IGListKit/Default (2.1.0):
- IGListKit/Diffing
- IGListKit/Diffing (2.1.0)
- Yoga (1.2.0)
- YogaKit (1.2.0):
- Yoga (~> 1.2)
- Yoga (1.3.0)
- YogaKit (1.3.0):
- Yoga (~> 1.3)
DEPENDENCIES:
- IGListKit (~> 2.1.0)
@@ -18,8 +18,8 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
IGListKit: b826c68ef7a4ae1626c09d4d3e1ea7a169e6c36e
Yoga: 20fc010c282cc5f3c27ce512de1329cd1e72b077
YogaKit: 72d5c8a806dc5cf2aa50c93a6dd88913cdbec6fe
Yoga: 2ed1d7accfef3610a67f58c0cf101a0662137f2c
YogaKit: cddeccc6a8d2aff563e4c738d3bddb290a6de4cb
PODFILE CHECKSUM: 216f8e7127767709e0e43f3711208d238fa5c404

View File

@@ -0,0 +1,101 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0820"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "13687D421DF8748300E7C260"
BuildableName = "YogaKitSample.app"
BlueprintName = "YogaKitSample"
ReferencedContainer = "container:YogaKitSample.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "638A944E1E215CC800A726AD"
BuildableName = "YogaKitSampleTests.xctest"
BlueprintName = "YogaKitSampleTests"
ReferencedContainer = "container:YogaKitSample.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "13687D421DF8748300E7C260"
BuildableName = "YogaKitSample.app"
BlueprintName = "YogaKitSample"
ReferencedContainer = "container:YogaKitSample.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "13687D421DF8748300E7C260"
BuildableName = "YogaKitSample.app"
BlueprintName = "YogaKitSample"
ReferencedContainer = "container:YogaKitSample.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "13687D421DF8748300E7C260"
BuildableName = "YogaKitSample.app"
BlueprintName = "YogaKitSample"
ReferencedContainer = "container:YogaKitSample.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>

View File

@@ -15,32 +15,38 @@ final class BasicViewController: UIViewController {
let root = self.view!
root.backgroundColor = .white
root.yoga.isEnabled = true
root.yoga.width = containerSize.width
root.yoga.height = containerSize.height
root.yoga.alignItems = .center
root.yoga.justifyContent = .center
root.configureLayout { (layout) in
layout.isEnabled = true
layout.width = containerSize.width
layout.height = containerSize.height
layout.alignItems = .center
layout.justifyContent = .center
}
let child1 = UIView()
child1.backgroundColor = .blue
child1.yoga.isEnabled = true
child1.yoga.width = 100
child1.yoga.height = 10
child1.yoga.marginBottom = 25
child1.configureLayout { (layout) in
layout.isEnabled = true
layout.width = 100
layout.height = 10
layout.marginBottom = 25
}
root.addSubview(child1)
let child2 = UIView()
child2.yoga.isEnabled = true
child2.yoga.alignSelf = .flexEnd
let child2 = UIView(frame: CGRect(x: 0, y: 0, width: 200, height: 200))
child2.backgroundColor = .green
child2.frame = CGRect(x: 0, y: 0, width: 200, height: 100)
child2.configureLayout { (layout) in
layout.isEnabled = true
layout.alignSelf = .flexEnd
}
root.addSubview(child2)
let child3 = UIView()
child3.yoga.isEnabled = true
child3.yoga.alignSelf = .flexStart
let child3 = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
child3.backgroundColor = .yellow
child3.frame = CGRect(x: 0, y: 0, width: 100, height: 100)
child3.configureLayout { (layout) in
layout.isEnabled = true
layout.alignSelf = .flexStart
}
root.addSubview(child3)
root.yoga.applyLayout(preservingOrigin: true)

View File

@@ -17,40 +17,50 @@ final class LayoutInclusionViewController: UIViewController {
override func viewDidLoad() {
let root = self.view!
root.backgroundColor = .white
root.yoga.isEnabled = true
root.yoga.flexDirection = .column
root.yoga.justifyContent = .spaceAround
root.configureLayout { (layout) in
layout.isEnabled = true
layout.flexDirection = .column
layout.justifyContent = .spaceAround
}
contentView.backgroundColor = .clear
contentView.layer.borderColor = UIColor.lightGray.cgColor
contentView.layer.borderWidth = 1.0
contentView.yoga.isEnabled = true
contentView.yoga.height = 300
contentView.yoga.width = self.view.bounds.size.width
contentView.yoga.flexDirection = .row
contentView.yoga.justifyContent = .center
contentView.yoga.paddingHorizontal = 25
contentView.configureLayout { (layout) in
layout.isEnabled = true
layout.height = 300
layout.width = self.view.bounds.size.width
layout.flexDirection = .row
layout.justifyContent = .center
layout.paddingHorizontal = 25
}
self.view.addSubview(contentView)
let redView = UIView(frame: .zero)
redView.backgroundColor = .red
redView.yoga.isEnabled = true
redView.yoga.flexGrow = 1
redView.yoga.flexShrink = 1
redView.configureLayout { (layout) in
layout.isEnabled = true
layout.flexGrow = 1
layout.flexShrink = 1
}
contentView.addSubview(redView)
disappearingView.backgroundColor = .blue
disappearingView.yoga.isEnabled = true
disappearingView.yoga.flexGrow = 1
disappearingView.configureLayout { (layout) in
layout.isEnabled = true
layout.flexGrow = 1
}
contentView.addSubview(disappearingView)
button.setTitle("Add Blue View", for: UIControlState.selected)
button.setTitle("Remove Blue View", for: UIControlState.normal)
button.addTarget(self, action: #selector(buttonWasTapped), for: UIControlEvents.touchUpInside)
button.yoga.isEnabled = true
button.yoga.height = 300
button.yoga.width = 300
button.yoga.alignSelf = .center
button.configureLayout { (layout) in
layout.isEnabled = true
layout.height = 300
layout.width = 300
layout.alignSelf = .center
}
root.addSubview(button)
root.yoga.applyLayout(preservingOrigin: false)

View File

@@ -15,9 +15,11 @@ final class SingleLabelCollectionCell: UICollectionViewCell {
override init(frame: CGRect) {
super.init(frame: frame)
contentView.yoga.isEnabled = true
contentView.yoga.flexDirection = .column
contentView.yoga.justifyContent = .flexEnd
contentView.configureLayout { (layout) in
layout.isEnabled = true
layout.flexDirection = .column
layout.justifyContent = .flexEnd
}
label.textAlignment = .center
label.numberOfLines = 1
@@ -26,9 +28,11 @@ final class SingleLabelCollectionCell: UICollectionViewCell {
let border = UIView(frame: .zero)
border.backgroundColor = .lightGray
border.yoga.isEnabled = true
border.yoga.height = 0.5
border.yoga.marginHorizontal = 25
border.configureLayout { (layout) in
layout.isEnabled = true
layout.height = 0.5
layout.marginHorizontal = 25
}
contentView.addSubview(border)
}

21
android/README.md Normal file
View File

@@ -0,0 +1,21 @@
# YogaLayout [![Platform](https://img.shields.io/badge/platforms-Android-orange.svg)](https://facebook.github.io/yoga/docs/api/android/) [![Languages](https://img.shields.io/badge/languages-Java-orange.svg)](https://facebook.github.io/yoga/docs/api/android/) [![Download](https://img.shields.io/bintray/v/facebook/maven/com.facebook.yoga.android:yoga-layout.svg)](https://bintray.com/facebook/maven/com.facebook.yoga.android%3Ayoga-layout/_latestVersion)
## Installation
YogaLayout is available via jcenter:
compile 'com.facebook.yoga.android:yoga-layout:1.2.0'
## Getting Started
Check out the docs [here](https://facebook.github.io/yoga/docs/api/android/).
We also have a sample project. To try it, clone the repo and run (with a device attached)
buck install -r android/sample
## Contributing
We welcome all pull-requests! At Facebook we sync the open source version of YogaKit daily, so we're always testing the latest changes.
See the CONTRIBUTING file for how to help out.

View File

@@ -6,7 +6,7 @@ apply plugin: 'maven-publish'
targetCompatibility = '1.7'
sourceCompatibility = '1.7'
version = '1.2.0'
version = '1.3.0'
group = 'com.facebook.yoga.android'
android {

View File

@@ -22,6 +22,8 @@
android:targetSdkVersion="19"
/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:label="@string/app_name"
android:icon="@drawable/ic_launcher"
@@ -42,6 +44,11 @@
</activity>
<activity
android:name=".BenchmarkActivity"
android:exported="false"
/>
</application>
</manifest>

View File

@@ -0,0 +1,113 @@
// Copyright 2004-present Facebook. All Rights Reserved.
package com.facebook.samples.yoga;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.Menu;
import android.support.v7.app.ActionBar;
import com.facebook.samples.yoga.R;
import com.facebook.yoga.android.YogaViewLayoutFactory;
public class BenchmarkActivity extends ActionBarActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
LayoutInflater.from(this).setFactory(YogaViewLayoutFactory.getInstance());
super.onCreate(savedInstanceState);
setContentView(R.layout.benchmark_select_layout);
ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
viewPager.setAdapter(new PagerAdapter(getSupportFragmentManager()));
final ActionBar actionBar = getSupportActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
ActionBar.TabListener tabListener = new ActionBar.TabListener() {
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
viewPager.setCurrentItem(tab.getPosition());
}
public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) {
}
public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) {
}
};
actionBar.addTab(
actionBar.newTab()
.setText("Inflate")
.setTabListener(tabListener));
actionBar.addTab(
actionBar.newTab()
.setText("Measure")
.setTabListener(tabListener));
actionBar.addTab(
actionBar.newTab()
.setText("Layout")
.setTabListener(tabListener));
viewPager.setOnPageChangeListener(
new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int position) {
// When swiping between pages, select the
// corresponding tab.
actionBar.setSelectedNavigationItem(position);
}
});
viewPager.setOffscreenPageLimit(3);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.action_bar_benchmark, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// There is only one option
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
this.finish();
return true;
}
public static class PagerAdapter extends FragmentPagerAdapter {
public PagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int i) {
switch (i) {
case 0:
return new BenchmarkInflate();
case 1:
return new BenchmarkMeasure();
default:
return new BenchmarkLayout();
}
}
@Override
public int getCount() {
return 3;
}
}
}

View File

@@ -0,0 +1,193 @@
// Copyright 2004-present Facebook. All Rights Reserved.
package com.facebook.samples.yoga;
import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.lang.Math;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.text.DateFormat;
import java.util.Date;
import android.content.Context;
import android.util.Log;
import android.os.Environment;
import static java.util.Collections.sort;
public class BenchmarkAggregator {
private final int GRAPH_WIDTH = 30;
private final int GRAPH_HEIGHT = 6;
private List<Long> times;
private boolean tracing;
private long lastTraceStart;
private boolean statsFresh;
private long mean;
private long variance;
private long stddev;
private long min;
private long max;
private long p10;
private long p50;
private long p90;
private String name;
public BenchmarkAggregator(String name) {
times = new ArrayList<>();
tracing = false;
this.name = name;
}
public void startTrace() {
if (tracing) {
throw new RuntimeException("Cannot start trace while running previous one");
}
tracing = true;
lastTraceStart = System.nanoTime();
}
public void endTrace() {
if (!tracing) {
throw new RuntimeException("Cannot stop trace if none are running!");
}
times.add(System.nanoTime() - lastTraceStart);
tracing = false;
statsFresh = false;
}
private void computeStats() {
if (statsFresh) {
return;
}
sort(times);
min = Long.MAX_VALUE;
max = -1;
mean = 0;
for (long f: times) {
mean += f;
if (f < min) {
min = f;
}
if (f > max) {
max = f;
}
}
mean /= times.size();
variance = 0;
for (long f: times) {
variance += (f-mean)*(f-mean);
}
variance /= times.size();
stddev = (long) Math.sqrt((double) variance);
p10 = times.get(times.size()*10/100);
p50 = times.get(times.size()*50/100);
p90 = times.get(times.size()*90/100);
statsFresh = true;
}
public String toString() {
computeStats();
return String.format(
"%s:\n" +
"| %d samples\n" +
"| Mean %.3f\u00B1%.3fms\n" + // plusminus
"| Min %.3fms ; Max %.3fms\n" +
"| p10 %.3fms ; p50 %.3fms ; p90 %.3fms\n" +
"%s",
name,
times.size(),
mean/10e6,
stddev/10e6,
min/10e6,
max/10e6,
p10/10e6,
p50/10e6,
p90/10e6,
makeGraph());
}
private String makeGraph() {
char canvas[][] = new char[GRAPH_HEIGHT][GRAPH_WIDTH];
for (int i = 0; i < GRAPH_HEIGHT; i++)
for (int j = 0; j < GRAPH_WIDTH; j++)
canvas[i][j] = ' ';
long bucketSize = (p90 - p10) / GRAPH_WIDTH+1;
int bucketCount[] = new int[GRAPH_WIDTH];
for (long time : times) {
if (time<p90 && time>p10) {
bucketCount[(int) ((time - p10) / bucketSize)]++;
}
}
int maxBucket = 0;
for (int i = 0; i < GRAPH_WIDTH; i++)
if (bucketCount[i] > maxBucket) {
maxBucket = bucketCount[i];
}
for (int i = 0; i < GRAPH_HEIGHT; i++)
for (int j = 0; j < GRAPH_WIDTH; j++)
if (i < bucketCount[j] * GRAPH_HEIGHT / maxBucket) {
canvas[i][j] = 'Z';
}
String graph = new String();
for (int i = 0; i < GRAPH_HEIGHT; i++)
{
int percentage = 100 * (GRAPH_HEIGHT - i - 1) * maxBucket / (times.size() * GRAPH_HEIGHT);
graph += String.format("| %2d%% ", percentage);
for (int j = 0; j < GRAPH_WIDTH; j++)
graph += canvas[GRAPH_HEIGHT-1-i][j];
graph += '\n';
}
graph += "| p10";
for (int i = 0; i < GRAPH_WIDTH-6; i++)
graph += " ";
graph += "p90\n";
return graph;
}
/**
* Dumps the collected times to a file on the device. This allows us to grab the raw data
* and perform more in-depth analysis.
*/
public void dump(Context context) {
String state = Environment.getExternalStorageState();
if (!Environment.MEDIA_MOUNTED.equals(state)) {
Log.e("YogaLayoutBenchmark","No external file storage");
return;
}
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
String filename = format.format(new Date()) + "_" + name.replace(' ','_');
File file = new File(context.getExternalFilesDir(
Environment.DIRECTORY_DOCUMENTS), filename);
try {
PrintWriter printWriter = new PrintWriter(file);
for (long l : times) {
printWriter.println(l);
}
printWriter.close();
Log.i("YogaLayoutBenchmark","Benchmark data saved in "+file.getPath());
} catch (java.io.IOException e) {
Log.e("YogaLayoutBenchmark", "Could not save benchmark data", e);
}
}
}

View File

@@ -0,0 +1,110 @@
// Copyright 2004-present Facebook. All Rights Reserved.
package com.facebook.samples.yoga;
import java.util.Random;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.LinearLayout;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.ArrayAdapter;
import android.widget.AdapterView;
import com.facebook.samples.yoga.R;
import com.facebook.yoga.android.YogaLayout;
public class BenchmarkFragment extends Fragment implements AdapterView.OnItemSelectedListener {
private LayoutInflater mInflater;
protected com.facebook.yoga.android.YogaLayout rootLayout;
protected int yogaLayout;
protected int linearLayout;
static final Random random = new Random();
static void randomizeText(View root) {
if (root instanceof TextView) {
((TextView) root).setText("" + random.nextInt(1000));
((TextView) root).setTextSize(10 + random.nextInt(20));
ViewParent parent = root.getParent();
if (parent instanceof YogaLayout) {
((YogaLayout) parent).invalidate(root);
}
} else if (root instanceof ViewGroup) {
for (int i = 0; i < ((ViewGroup) root).getChildCount(); i++) {
randomizeText(((ViewGroup) root).getChildAt(i));
}
}
}
public BenchmarkFragment() {
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(
LayoutInflater inflater,
ViewGroup container,
Bundle savedInstanceState) {
mInflater = inflater;
rootLayout = (YogaLayout) inflater.inflate(
R.layout.benchmark_fragment,
container,
false);
Spinner benchmarkSelect = (Spinner) rootLayout.findViewById(R.id.benchmarkSelect);
String[] items = new String[]{"Basic", "Typical", "Nested"};
ArrayAdapter<String> adapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_spinner_dropdown_item, items);
benchmarkSelect.setAdapter(adapter);
benchmarkSelect.setOnItemSelectedListener(this);
return rootLayout;
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
switch (pos) {
case 0:
yogaLayout = R.layout.benchmark_layout_1;
linearLayout = R.layout.benchmark_layout_1_linear;
break;
case 1:
yogaLayout = R.layout.benchmark_layout_2;
linearLayout = R.layout.benchmark_layout_2_linear;
break;
case 2:
default:
yogaLayout = R.layout.benchmark_layout_3;
linearLayout = R.layout.benchmark_layout_3_linear;
break;
}
updatePreview();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
yogaLayout = R.layout.benchmark_layout_1;
linearLayout = R.layout.benchmark_layout_1_linear;
updatePreview();
}
private void updatePreview() {
LinearLayout previewLayout = (LinearLayout) rootLayout.findViewById(R.id.preview);
View v = mInflater.inflate(yogaLayout, rootLayout, false);
v.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT));
previewLayout.removeAllViews();
previewLayout.addView(v);
}
}

View File

@@ -0,0 +1,65 @@
// Copyright 2004-present Facebook. All Rights Reserved.
package com.facebook.samples.yoga;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Button;
import android.view.ViewGroup;
import android.util.Log;
import com.facebook.samples.yoga.R;
public class BenchmarkInflate extends BenchmarkFragment {
@Override
public View onCreateView(
LayoutInflater inflater,
ViewGroup container,
Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
Button b = (Button) rootLayout.findViewById(R.id.btn);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startBenchmark();
}
});
return rootLayout;
}
protected void startBenchmark() {
LayoutInflater inflater = LayoutInflater.from(getActivity());
TextView textView = (TextView) rootLayout.findViewById(R.id.text);
final int ITERATIONS = 500;
inflater.inflate(yogaLayout, null);
inflater.inflate(linearLayout, null);
BenchmarkAggregator yogaInflationAggregator = new BenchmarkAggregator("Yoga Inflate");
BenchmarkAggregator linearInflationAggregator = new BenchmarkAggregator("Linear Inflate");
for (int i = 0; i < ITERATIONS; i++) {
yogaInflationAggregator.startTrace();
inflater.inflate(yogaLayout, null);
yogaInflationAggregator.endTrace();
linearInflationAggregator.startTrace();
inflater.inflate(linearLayout, null);
linearInflationAggregator.endTrace();
}
textView.setText(
yogaInflationAggregator.toString()+
"\n"+
linearInflationAggregator.toString());
Log.i(
"YogaLayoutBenchmark",
yogaInflationAggregator.toString()+
"\n"+
linearInflationAggregator.toString());
rootLayout.invalidate();
}
}

View File

@@ -0,0 +1,74 @@
// Copyright 2004-present Facebook. All Rights Reserved.
package com.facebook.samples.yoga;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import com.facebook.samples.yoga.R;
import java.util.Random;
public class BenchmarkLayout extends BenchmarkFragment {
@Override
public View onCreateView(
LayoutInflater inflater,
ViewGroup container,
Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
Button b = (Button) rootLayout.findViewById(R.id.btn);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startBenchmark();
}
});
return rootLayout;
}
protected void startBenchmark() {
LayoutInflater inflater = LayoutInflater.from(getActivity());
TextView textView = (TextView) rootLayout.findViewById(R.id.text);
Random random = new Random();
final int ITERATIONS = 500;
BenchmarkAggregator yogaInflationAggregator = new BenchmarkAggregator("Yoga Layout");
BenchmarkAggregator linearInflationAggregator = new BenchmarkAggregator("Linear Layout");
View yogaView = inflater.inflate(yogaLayout, null);
View linearView = inflater.inflate(linearLayout, null);
for (int i = 0; i < ITERATIONS; i++) {
randomizeText(yogaView);
randomizeText(linearView);
yogaView.measure(
View.MeasureSpec.makeMeasureSpec(1000, View.MeasureSpec.EXACTLY),
View.MeasureSpec.makeMeasureSpec(1000, View.MeasureSpec.EXACTLY));
linearView.measure(
View.MeasureSpec.makeMeasureSpec(1000, View.MeasureSpec.EXACTLY),
View.MeasureSpec.makeMeasureSpec(1000, View.MeasureSpec.EXACTLY));
yogaInflationAggregator.startTrace();
yogaView.layout(0, 0, yogaView.getMeasuredWidth(), yogaView.getMeasuredHeight());
yogaInflationAggregator.endTrace();
linearInflationAggregator.startTrace();
linearView.layout(0, 0, linearView.getMeasuredWidth(), linearView.getMeasuredHeight());
linearInflationAggregator.endTrace();
}
textView.setText(
yogaInflationAggregator.toString()+
"\n"+
linearInflationAggregator.toString());
Log.i(
"YogaLayoutBenchmark",
yogaInflationAggregator.toString()+
"\n"+
linearInflationAggregator.toString());
}
}

View File

@@ -0,0 +1,75 @@
// Copyright 2004-present Facebook. All Rights Reserved.
package com.facebook.samples.yoga;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import com.facebook.samples.yoga.R;
import java.util.Random;
public class BenchmarkMeasure extends BenchmarkFragment {
@Override
public View onCreateView(
LayoutInflater inflater,
ViewGroup container,
Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
Button b = (Button) rootLayout.findViewById(R.id.btn);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startBenchmark();
}
});
return rootLayout;
}
protected void startBenchmark() {
LayoutInflater inflater = LayoutInflater.from(getActivity());
TextView textView = (TextView) rootLayout.findViewById(R.id.text);
Random random = new Random();
final int ITERATIONS = 500;
BenchmarkAggregator yogaMeasureAggregator = new BenchmarkAggregator("Yoga Measure");
BenchmarkAggregator linearMeasureAggregator = new BenchmarkAggregator("Linear Measure");
View yogaView = inflater.inflate(yogaLayout, null);
View linearView = inflater.inflate(linearLayout, null);
for (int i = 0; i < ITERATIONS; i++) {
randomizeText(yogaView);
randomizeText(linearView);
yogaMeasureAggregator.startTrace();
yogaView.measure(
View.MeasureSpec.makeMeasureSpec(1000, View.MeasureSpec.EXACTLY),
View.MeasureSpec.makeMeasureSpec(1000, View.MeasureSpec.EXACTLY));
yogaMeasureAggregator.endTrace();
linearMeasureAggregator.startTrace();
linearView.measure(
View.MeasureSpec.makeMeasureSpec(1000, View.MeasureSpec.EXACTLY),
View.MeasureSpec.makeMeasureSpec(1000, View.MeasureSpec.EXACTLY));
linearMeasureAggregator.endTrace();
}
textView.setText(
yogaMeasureAggregator.toString()+
"\n"+
linearMeasureAggregator.toString());
Log.i(
"YogaLayoutBenchmark",
yogaMeasureAggregator.toString()+
"\n"+
linearMeasureAggregator.toString());
yogaMeasureAggregator.dump(getActivity());
linearMeasureAggregator.dump(getActivity());
}
}

View File

@@ -8,9 +8,13 @@
package com.facebook.samples.yoga;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.LayoutInflater;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.Menu;
import com.facebook.samples.yoga.R;
import com.facebook.soloader.SoLoader;
@@ -31,4 +35,20 @@ public class MainActivity extends ActionBarActivity {
setContentView(R.layout.main_layout);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.action_bar_home, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// There is only one option
Intent intent = new Intent(this, BenchmarkActivity.class);
startActivity(intent);
this.finish();
return true;
}
}

View File

@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="utf-8" ?>
<YogaLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yoga="http://schemas.android.com/apk/res-auto"
android:id="@+id/rt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
yoga:yg_flexDirection="column"
>
<VirtualYogaLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
yoga:yg_flexDirection="row"
yoga:yg_height="50dp"
>
<Button
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Run benchmark"
yoga:yg_flex="1"
/>
<Spinner
android:id="@+id/benchmarkSelect"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:spinnerMode="dropdown"
/>
</VirtualYogaLayout>
<TextView
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="10sp"
android:fontFamily="monospace"
yoga:yg_flex="1"
/>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="@color/yoga_grey"
/>
<LinearLayout
android:id="@+id/preview"
android:layout_width="match_parent"
android:layout_height="60dp"
android:orientation="horizontal"
/>
</YogaLayout>

View File

@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8" ?>
<YogaLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yoga="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="60dp"
yoga:yg_flexDirection="row"
yoga:yg_alignItems="center"
>
<View
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@color/yoga_blue"
yoga:yg_flex="0"
yoga:yg_marginAll="5dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/child_1_text"
yoga:yg_flex="0"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/child_2_text"
yoga:yg_flex="1"
yoga:yg_marginHorizontal="5dp"
/>
</YogaLayout>

View File

@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8" ?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center"
>
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_margin="5dp"
android:src="@drawable/ic_launcher"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/child_1_text"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:text="@string/child_2_text"
/>
</LinearLayout>

View File

@@ -0,0 +1,104 @@
<?xml version="1.0" encoding="utf-8" ?>
<YogaLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yoga="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="60dp"
yoga:yg_flexDirection="column"
yoga:yg_alignItems="stretch"
>
<View
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/yoga_blue"
yoga:yg_flex="1"
/>
<VirtualYogaLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
yoga:height="40dp"
yoga:yg_flexDirection="row"
yoga:yg_alignItems="stretch"
>
<View
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/yoga_blue"
yoga:yg_marginAll="10dp"
yoga:yg_aspectRatio="1"
/>
<VirtualYogaLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
yoga:height="40dp"
yoga:yg_flexDirection="column"
yoga:yg_alignItems="stretch"
yoga:yg_flex="1"
yoga:yg_justifyContent="space_around"
>
<VirtualYogaLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
yoga:height="8dp"
yoga:yg_flexDirection="row"
yoga:yg_alignItems="stretch"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/child_1_text"
android:textSize="5sp"
yoga:yg_flex="1"
/>
<View
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/yoga_blue"
yoga:yg_aspectRatio="1"
/>
</VirtualYogaLayout>
<VirtualYogaLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
yoga:height="8dp"
yoga:yg_flexDirection="row"
yoga:yg_alignItems="stretch"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/child_1_text"
android:textSize="5sp"
yoga:yg_flex="1"
/>
<View
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/yoga_blue"
yoga:yg_aspectRatio="1"
/>
</VirtualYogaLayout>
<VirtualYogaLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
yoga:height="8dp"
yoga:yg_flexDirection="row"
yoga:yg_alignItems="stretch"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/child_1_text"
android:textSize="5sp"
yoga:yg_flex="1"
/>
<View
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/yoga_blue"
yoga:yg_aspectRatio="1"
/>
</VirtualYogaLayout>
</VirtualYogaLayout>
</VirtualYogaLayout>
</YogaLayout>

View File

@@ -0,0 +1,96 @@
<?xml version="1.0" encoding="utf-8" ?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yoga="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="60dp"
android:orientation="vertical"
>
<View
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher"
android:background="@color/yoga_blue"
android:layout_weight="1"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:orientation="horizontal"
>
<View
android:layout_width="20dp"
android:layout_height="20dp"
android:src="@drawable/ic_launcher"
android:background="@color/yoga_blue"
android:layout_margin="10dp"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_weight="1"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="8dp"
android:orientation="horizontal"
android:layout_marginTop="4dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/child_1_text"
android:textSize="5sp"
android:layout_weight="1"
/>
<View
android:layout_width="8dp"
android:layout_height="8dp"
android:src="@drawable/ic_launcher"
android:background="@color/yoga_blue"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="8dp"
android:orientation="horizontal"
android:layout_marginTop="4dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/child_1_text"
android:textSize="5sp"
android:layout_weight="1"
/>
<View
android:layout_width="8dp"
android:layout_height="8dp"
android:src="@drawable/ic_launcher"
android:background="@color/yoga_blue"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="8dp"
android:orientation="horizontal"
android:layout_marginTop="4dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/child_1_text"
android:textSize="5sp"
android:layout_weight="1"
/>
<View
android:layout_width="8dp"
android:layout_height="8dp"
android:src="@drawable/ic_launcher"
android:background="@color/yoga_blue"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>

View File

@@ -0,0 +1,206 @@
<?xml version="1.0" encoding="utf-8" ?>
<YogaLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yoga="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
yoga:yg_alignItems="center"
yoga:yg_flexDirection="row"
yoga:yg_justifyContent="center"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/yoga_blue"
yoga:yg_marginLeft="10dp"
/>
<VirtualYogaLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
yoga:yg_flexDirection="column"
yoga:yg_flex="1"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/yoga_grey"
yoga:yg_marginLeft="10dp"
/>
<VirtualYogaLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
yoga:yg_flexDirection="row"
yoga:yg_flex="1"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/yoga_grey"
yoga:yg_marginLeft="10dp"
/>
<VirtualYogaLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
yoga:yg_flexDirection="row"
yoga:yg_flex="1"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/yoga_blue"
yoga:yg_marginLeft="10dp"
/>
<VirtualYogaLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
yoga:yg_flexDirection="row"
yoga:yg_flex="1"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/yoga_grey"
yoga:yg_marginLeft="10dp"
/>
<VirtualYogaLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
yoga:yg_flexDirection="row"
yoga:yg_flex="1"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/yoga_grey"
yoga:yg_marginLeft="10dp"
/>
<VirtualYogaLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
yoga:yg_flexDirection="column"
yoga:yg_flex="1"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/yoga_blue"
yoga:yg_marginLeft="10dp"
/>
<VirtualYogaLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
yoga:yg_flexDirection="row"
yoga:yg_flex="1"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/yoga_grey"
yoga:yg_marginLeft="10dp"
/>
<VirtualYogaLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
yoga:yg_flexDirection="row"
yoga:yg_flex="1"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/yoga_grey"
yoga:yg_marginLeft="10dp"
/>
<VirtualYogaLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
yoga:yg_flexDirection="row"
yoga:yg_flex="1"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/yoga_blue"
yoga:yg_marginLeft="10dp"
/>
<VirtualYogaLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
yoga:yg_flexDirection="row"
yoga:yg_flex="1"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/yoga_grey"
yoga:yg_marginLeft="10dp"
/>
<VirtualYogaLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
yoga:yg_flexDirection="column"
yoga:yg_flex="1"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/yoga_grey"
yoga:yg_marginLeft="10dp"
/>
<VirtualYogaLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
yoga:yg_flexDirection="row"
yoga:yg_flex="1"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/yoga_blue"
yoga:yg_marginLeft="10dp"
/>
<VirtualYogaLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
yoga:yg_flexDirection="row"
yoga:yg_flex="1"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/yoga_grey"
yoga:yg_marginLeft="10dp"
/>
<VirtualYogaLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
yoga:yg_flexDirection="row"
yoga:yg_flex="1"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/yoga_grey"
yoga:yg_marginLeft="10dp"
/>
<VirtualYogaLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
yoga:yg_flexDirection="row"
yoga:yg_flex="1"
>
</VirtualYogaLayout>
</VirtualYogaLayout>
</VirtualYogaLayout>
</VirtualYogaLayout>
</VirtualYogaLayout>
</VirtualYogaLayout>
</VirtualYogaLayout>
</VirtualYogaLayout>
</VirtualYogaLayout>
</VirtualYogaLayout>
</VirtualYogaLayout>
</VirtualYogaLayout>
</VirtualYogaLayout>
</VirtualYogaLayout>
</VirtualYogaLayout>
</YogaLayout>

View File

@@ -0,0 +1,204 @@
<?xml version="1.0" encoding="utf-8" ?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:background="@color/yoga_blue"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:background="@color/yoga_grey"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:background="@color/yoga_grey"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:background="@color/yoga_blue"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:background="@color/yoga_grey"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:background="@color/yoga_grey"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:background="@color/yoga_blue"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:background="@color/yoga_grey"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:background="@color/yoga_grey"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:background="@color/yoga_blue"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:background="@color/yoga_grey"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:background="@color/yoga_grey"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:background="@color/yoga_blue"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:background="@color/yoga_grey"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:background="@color/yoga_grey"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?>
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>

View File

@@ -18,10 +18,10 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/sample_children_background"
yoga:yg_margin_horizontal="10dp"
yoga:yg_margin_top="5dp"
yoga:yg_flex_direction="row"
yoga:yg_align_items="center"
yoga:yg_marginHorizontal="10dp"
yoga:yg_marginTop="5dp"
yoga:yg_flexDirection="row"
yoga:yg_alignItems="center"
>
<ImageView
android:layout_width="50dp"
@@ -35,17 +35,17 @@
android:text="@string/child_1_text"
android:textColor="@color/children_text"
yoga:yg_flex="1"
yoga:yg_margin_start="8dp"
yoga:yg_marginStart="8dp"
/>
</YogaLayout>
<YogaLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/sample_children_background"
yoga:yg_margin_horizontal="10dp"
yoga:yg_margin_top="5dp"
yoga:yg_flex_direction="row"
yoga:yg_align_items="center"
yoga:yg_marginHorizontal="10dp"
yoga:yg_marginTop="5dp"
yoga:yg_flexDirection="row"
yoga:yg_alignItems="center"
>
<ImageView
android:layout_width="50dp"
@@ -59,17 +59,17 @@
android:text="@string/child_2_text"
android:textColor="@color/children_text"
yoga:yg_flex="1"
yoga:yg_margin_start="8dp"
yoga:yg_marginStart="8dp"
/>
</YogaLayout>
<YogaLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/sample_children_background"
yoga:yg_margin_horizontal="10dp"
yoga:yg_margin_top="5dp"
yoga:yg_flex_direction="row"
yoga:yg_align_items="center"
yoga:yg_marginHorizontal="10dp"
yoga:yg_marginTop="5dp"
yoga:yg_flexDirection="row"
yoga:yg_alignItems="center"
>
<ImageView
android:layout_width="50dp"
@@ -83,17 +83,17 @@
android:text="@string/child_3_text"
android:textColor="@color/children_text"
yoga:yg_flex="1"
yoga:yg_margin_start="8dp"
yoga:yg_marginStart="8dp"
/>
</YogaLayout>
<YogaLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/sample_children_background"
yoga:yg_margin_horizontal="10dp"
yoga:yg_margin_top="5dp"
yoga:yg_flex_direction="row"
yoga:yg_align_items="center"
yoga:yg_marginHorizontal="10dp"
yoga:yg_marginTop="5dp"
yoga:yg_flexDirection="row"
yoga:yg_alignItems="center"
>
<ImageView
android:layout_width="50dp"
@@ -107,17 +107,17 @@
android:text="@string/child_4_text"
android:textColor="@color/children_text"
yoga:yg_flex="1"
yoga:yg_margin_start="8dp"
yoga:yg_marginStart="8dp"
/>
</YogaLayout>
<YogaLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/sample_children_background"
yoga:yg_margin_horizontal="10dp"
yoga:yg_margin_top="5dp"
yoga:yg_flex_direction="row"
yoga:yg_align_items="center"
yoga:yg_marginHorizontal="10dp"
yoga:yg_marginTop="5dp"
yoga:yg_flexDirection="row"
yoga:yg_alignItems="center"
>
<ImageView
android:layout_width="50dp"
@@ -131,7 +131,7 @@
android:text="@string/child_5_text"
android:textColor="@color/children_text"
yoga:yg_flex="1"
yoga:yg_margin_start="10dp"
yoga:yg_marginStart="10dp"
/>
</YogaLayout>
</YogaLayout>

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2014-present, Facebook, Inc.
All rights reserved.
This source code is licensed under the license found in the
LICENSE-examples file in the root directory of this source tree.
-->
<menu
xmlns:android="http://schemas.android.com/apk/res/android"
>
<item
android:id="@+id/action_home"
android:title="Home"
android:showAsAction="always"
/>
</menu>

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2014-present, Facebook, Inc.
All rights reserved.
This source code is licensed under the license found in the
LICENSE-examples file in the root directory of this source tree.
-->
<menu
xmlns:android="http://schemas.android.com/apk/res/android"
>
<item
android:id="@+id/action_benchmark"
android:title="Benchmark"
android:showAsAction="always"
/>
</menu>

View File

@@ -23,6 +23,7 @@ import android.util.SparseArray;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
import android.util.Log;
import com.facebook.yoga.android.R;
import com.facebook.yoga.YogaAlign;
@@ -51,7 +52,7 @@ import com.facebook.yoga.YogaWrap;
* <pre>{@code
* <YogaLayout
* xmlns:android="http://schemas.android.com/apk/res/android"
* xmlns:yoga="http://schemas.android.com/lib/com.facebook.yoga.android"
* xmlns:yoga="http://schemas.android.com/apk/com.facebook.yoga.android"
* android:layout_width="match_parent"
* android:layout_height="match_parent"
* yoga:flex_direction="row"
@@ -90,15 +91,20 @@ public class YogaLayout extends ViewGroup {
mYogaNode.setData(this);
mYogaNode.setMeasureFunction(new ViewMeasureFunction());
final LayoutParams layoutParams = new LayoutParams(context, attrs);
LayoutParams layoutParams = null;
if (attrs != null) {
layoutParams = new LayoutParams(context, attrs);
} else {
layoutParams = (LayoutParams) generateDefaultLayoutParams();
}
applyLayoutParams(layoutParams, mYogaNode, this);
}
YogaNode getYogaNode() {
public YogaNode getYogaNode() {
return mYogaNode;
}
YogaNode getYogaNodeForView(View view) {
public YogaNode getYogaNodeForView(View view) {
return mYogaNodes.get(view);
}
@@ -153,7 +159,11 @@ public class YogaLayout extends ViewGroup {
if (child instanceof YogaLayout) {
childNode = ((YogaLayout) child).getYogaNode();
} else {
childNode = new YogaNode();
if(mYogaNodes.containsKey(child)) {
childNode = mYogaNodes.get(child);
} else {
childNode = new YogaNode();
}
childNode.setData(child);
childNode.setMeasureFunction(new ViewMeasureFunction());
@@ -278,6 +288,7 @@ public class YogaLayout extends ViewGroup {
private void applyLayoutRecursive(YogaNode node, float xOffset, float yOffset) {
View view = (View) node.getData();
if (view != null && view != this) {
if (view.getVisibility() == GONE) {
return;
@@ -360,7 +371,6 @@ public class YogaLayout extends ViewGroup {
if (widthMode == MeasureSpec.AT_MOST) {
mYogaNode.setMaxWidth(widthSize);
}
mYogaNode.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
}
@@ -403,31 +413,31 @@ public class YogaLayout extends ViewGroup {
final int attribute = layoutParameters.numericAttributes.keyAt(i);
final float value = layoutParameters.numericAttributes.valueAt(i);
if (attribute == R.styleable.yoga_yg_align_content) {
if (attribute == R.styleable.yoga_yg_alignContent) {
node.setAlignContent(YogaAlign.fromInt(Math.round(value)));
} else if (attribute == R.styleable.yoga_yg_align_items) {
} else if (attribute == R.styleable.yoga_yg_alignItems) {
node.setAlignItems(YogaAlign.fromInt(Math.round(value)));
} else if (attribute == R.styleable.yoga_yg_align_self) {
} else if (attribute == R.styleable.yoga_yg_alignSelf) {
node.setAlignSelf(YogaAlign.fromInt(Math.round(value)));
} else if (attribute == R.styleable.yoga_yg_aspect_ratio) {
} else if (attribute == R.styleable.yoga_yg_aspectRatio) {
node.setAspectRatio(value);
} else if (attribute == R.styleable.yoga_yg_border_left) {
} else if (attribute == R.styleable.yoga_yg_borderLeft) {
node.setBorder(YogaEdge.LEFT, value);
} else if (attribute == R.styleable.yoga_yg_border_top) {
} else if (attribute == R.styleable.yoga_yg_borderTop) {
node.setBorder(YogaEdge.TOP, value);
} else if (attribute == R.styleable.yoga_yg_border_right) {
} else if (attribute == R.styleable.yoga_yg_borderRight) {
node.setBorder(YogaEdge.RIGHT, value);
} else if (attribute == R.styleable.yoga_yg_border_bottom) {
} else if (attribute == R.styleable.yoga_yg_borderBottom) {
node.setBorder(YogaEdge.BOTTOM, value);
} else if (attribute == R.styleable.yoga_yg_border_start) {
} else if (attribute == R.styleable.yoga_yg_borderStart) {
node.setBorder(YogaEdge.START, value);
} else if (attribute == R.styleable.yoga_yg_border_end) {
} else if (attribute == R.styleable.yoga_yg_borderEnd) {
node.setBorder(YogaEdge.END, value);
} else if (attribute == R.styleable.yoga_yg_border_horizontal) {
} else if (attribute == R.styleable.yoga_yg_borderHorizontal) {
node.setBorder(YogaEdge.HORIZONTAL, value);
} else if (attribute == R.styleable.yoga_yg_border_vertical) {
} else if (attribute == R.styleable.yoga_yg_borderVertical) {
node.setBorder(YogaEdge.VERTICAL, value);
} else if (attribute == R.styleable.yoga_yg_border_all) {
} else if (attribute == R.styleable.yoga_yg_borderAll) {
node.setBorder(YogaEdge.ALL, value);
} else if (attribute == R.styleable.yoga_yg_direction) {
node.setDirection(YogaDirection.fromInt(Math.round(value)));
@@ -435,83 +445,83 @@ public class YogaLayout extends ViewGroup {
node.setDisplay(YogaDisplay.fromInt(Math.round(value)));
} else if (attribute == R.styleable.yoga_yg_flex) {
node.setFlex(value);
} else if (attribute == R.styleable.yoga_yg_flex_basis) {
} else if (attribute == R.styleable.yoga_yg_flexBasis) {
node.setFlexBasis(value);
} else if (attribute == R.styleable.yoga_yg_flex_direction) {
} else if (attribute == R.styleable.yoga_yg_flexDirection) {
node.setFlexDirection(YogaFlexDirection.fromInt(Math.round(value)));
} else if (attribute == R.styleable.yoga_yg_flex_grow) {
} else if (attribute == R.styleable.yoga_yg_flexGrow) {
node.setFlexGrow(value);
} else if (attribute == R.styleable.yoga_yg_flex_shrink) {
} else if (attribute == R.styleable.yoga_yg_flexShrink) {
node.setFlexShrink(value);
} else if (attribute == R.styleable.yoga_yg_height) {
node.setHeight(value);
} else if (attribute == R.styleable.yoga_yg_margin_left) {
} else if (attribute == R.styleable.yoga_yg_marginLeft) {
node.setMargin(YogaEdge.LEFT, value);
} else if (attribute == R.styleable.yoga_yg_justify_content) {
} else if (attribute == R.styleable.yoga_yg_justifyContent) {
node.setJustifyContent(YogaJustify.fromInt(Math.round(value)));
} else if (attribute == R.styleable.yoga_yg_margin_top) {
} else if (attribute == R.styleable.yoga_yg_marginTop) {
node.setMargin(YogaEdge.TOP, value);
} else if (attribute == R.styleable.yoga_yg_margin_right) {
} else if (attribute == R.styleable.yoga_yg_marginRight) {
node.setMargin(YogaEdge.RIGHT, value);
} else if (attribute == R.styleable.yoga_yg_margin_bottom) {
} else if (attribute == R.styleable.yoga_yg_marginBottom) {
node.setMargin(YogaEdge.BOTTOM, value);
} else if (attribute == R.styleable.yoga_yg_margin_start) {
} else if (attribute == R.styleable.yoga_yg_marginStart) {
node.setMargin(YogaEdge.START, value);
} else if (attribute == R.styleable.yoga_yg_margin_end) {
} else if (attribute == R.styleable.yoga_yg_marginEnd) {
node.setMargin(YogaEdge.END, value);
} else if (attribute == R.styleable.yoga_yg_margin_horizontal) {
} else if (attribute == R.styleable.yoga_yg_marginHorizontal) {
node.setMargin(YogaEdge.HORIZONTAL, value);
} else if (attribute == R.styleable.yoga_yg_margin_vertical) {
} else if (attribute == R.styleable.yoga_yg_marginVertical) {
node.setMargin(YogaEdge.VERTICAL, value);
} else if (attribute == R.styleable.yoga_yg_margin_all) {
} else if (attribute == R.styleable.yoga_yg_marginAll) {
node.setMargin(YogaEdge.ALL, value);
} else if (attribute == R.styleable.yoga_yg_max_height) {
} else if (attribute == R.styleable.yoga_yg_maxHeight) {
node.setMaxHeight(value);
} else if (attribute == R.styleable.yoga_yg_max_width) {
} else if (attribute == R.styleable.yoga_yg_maxWidth) {
node.setMaxWidth(value);
} else if (attribute == R.styleable.yoga_yg_min_height) {
} else if (attribute == R.styleable.yoga_yg_minHeight) {
node.setMinHeight(value);
} else if (attribute == R.styleable.yoga_yg_min_width) {
} else if (attribute == R.styleable.yoga_yg_minWidth) {
node.setMinWidth(value);
} else if (attribute == R.styleable.yoga_yg_overflow) {
node.setOverflow(YogaOverflow.fromInt(Math.round(value)));
} else if (attribute == R.styleable.yoga_yg_padding_left) {
} else if (attribute == R.styleable.yoga_yg_paddingLeft) {
node.setPadding(YogaEdge.LEFT, value);
} else if (attribute == R.styleable.yoga_yg_padding_top) {
} else if (attribute == R.styleable.yoga_yg_paddingTop) {
node.setPadding(YogaEdge.TOP, value);
} else if (attribute == R.styleable.yoga_yg_padding_right) {
} else if (attribute == R.styleable.yoga_yg_paddingRight) {
node.setPadding(YogaEdge.RIGHT, value);
} else if (attribute == R.styleable.yoga_yg_padding_bottom) {
} else if (attribute == R.styleable.yoga_yg_paddingBottom) {
node.setPadding(YogaEdge.BOTTOM, value);
} else if (attribute == R.styleable.yoga_yg_padding_start) {
} else if (attribute == R.styleable.yoga_yg_paddingStart) {
node.setPadding(YogaEdge.START, value);
} else if (attribute == R.styleable.yoga_yg_padding_end) {
} else if (attribute == R.styleable.yoga_yg_paddingEnd) {
node.setPadding(YogaEdge.END, value);
} else if (attribute == R.styleable.yoga_yg_padding_horizontal) {
} else if (attribute == R.styleable.yoga_yg_paddingHorizontal) {
node.setPadding(YogaEdge.HORIZONTAL, value);
} else if (attribute == R.styleable.yoga_yg_padding_vertical) {
} else if (attribute == R.styleable.yoga_yg_paddingVertical) {
node.setPadding(YogaEdge.VERTICAL, value);
} else if (attribute == R.styleable.yoga_yg_padding_all) {
} else if (attribute == R.styleable.yoga_yg_paddingAll) {
node.setPadding(YogaEdge.ALL, value);
} else if (attribute == R.styleable.yoga_yg_position_left) {
} else if (attribute == R.styleable.yoga_yg_positionLeft) {
node.setPosition(YogaEdge.LEFT, value);
} else if (attribute == R.styleable.yoga_yg_position_top) {
} else if (attribute == R.styleable.yoga_yg_positionTop) {
node.setPosition(YogaEdge.TOP, value);
} else if (attribute == R.styleable.yoga_yg_position_right) {
} else if (attribute == R.styleable.yoga_yg_positionRight) {
node.setPosition(YogaEdge.RIGHT, value);
} else if (attribute == R.styleable.yoga_yg_position_bottom) {
} else if (attribute == R.styleable.yoga_yg_positionBottom) {
node.setPosition(YogaEdge.BOTTOM, value);
} else if (attribute == R.styleable.yoga_yg_position_start) {
} else if (attribute == R.styleable.yoga_yg_positionStart) {
node.setPosition(YogaEdge.START, value);
} else if (attribute == R.styleable.yoga_yg_position_end) {
} else if (attribute == R.styleable.yoga_yg_positionEnd) {
node.setPosition(YogaEdge.END, value);
} else if (attribute == R.styleable.yoga_yg_position_horizontal) {
} else if (attribute == R.styleable.yoga_yg_positionHorizontal) {
node.setPosition(YogaEdge.HORIZONTAL, value);
} else if (attribute == R.styleable.yoga_yg_position_vertical) {
} else if (attribute == R.styleable.yoga_yg_positionVertical) {
node.setPosition(YogaEdge.VERTICAL, value);
} else if (attribute == R.styleable.yoga_yg_position_all) {
} else if (attribute == R.styleable.yoga_yg_positionAll) {
node.setPosition(YogaEdge.ALL, value);
} else if (attribute == R.styleable.yoga_yg_position_type) {
} else if (attribute == R.styleable.yoga_yg_positionType) {
node.setPositionType(YogaPositionType.fromInt(Math.round(value)));
} else if (attribute == R.styleable.yoga_yg_width) {
node.setWidth(value);
@@ -525,23 +535,23 @@ public class YogaLayout extends ViewGroup {
final String value = layoutParameters.stringAttributes.valueAt(i);
if (value.equals("auto")) {
if (attribute == R.styleable.yoga_yg_margin_left) {
if (attribute == R.styleable.yoga_yg_marginLeft) {
node.setMarginAuto(YogaEdge.LEFT);
} else if (attribute == R.styleable.yoga_yg_margin_top) {
} else if (attribute == R.styleable.yoga_yg_marginTop) {
node.setMarginAuto(YogaEdge.TOP);
} else if (attribute == R.styleable.yoga_yg_margin_right) {
} else if (attribute == R.styleable.yoga_yg_marginRight) {
node.setMarginAuto(YogaEdge.RIGHT);
} else if (attribute == R.styleable.yoga_yg_margin_bottom) {
} else if (attribute == R.styleable.yoga_yg_marginBottom) {
node.setMarginAuto(YogaEdge.BOTTOM);
} else if (attribute == R.styleable.yoga_yg_margin_start) {
} else if (attribute == R.styleable.yoga_yg_marginStart) {
node.setMarginAuto(YogaEdge.START);
} else if (attribute == R.styleable.yoga_yg_margin_end) {
} else if (attribute == R.styleable.yoga_yg_marginEnd) {
node.setMarginAuto(YogaEdge.END);
} else if (attribute == R.styleable.yoga_yg_margin_horizontal) {
} else if (attribute == R.styleable.yoga_yg_marginHorizontal) {
node.setMarginAuto(YogaEdge.HORIZONTAL);
} else if (attribute == R.styleable.yoga_yg_margin_vertical) {
} else if (attribute == R.styleable.yoga_yg_marginVertical) {
node.setMarginAuto(YogaEdge.VERTICAL);
} else if (attribute == R.styleable.yoga_yg_margin_all) {
} else if (attribute == R.styleable.yoga_yg_marginAll) {
node.setMarginAuto(YogaEdge.ALL);
}
}
@@ -549,71 +559,71 @@ public class YogaLayout extends ViewGroup {
if (value.endsWith("%")) {
final float numericValue = Float.parseFloat(value.substring(0, value.length()-1));
if (attribute == R.styleable.yoga_yg_flex_basis) {
if (attribute == R.styleable.yoga_yg_flexBasis) {
node.setFlexBasisPercent(numericValue);
} else if (attribute == R.styleable.yoga_yg_height) {
node.setHeightPercent(numericValue);
} else if (attribute == R.styleable.yoga_yg_margin_left) {
} else if (attribute == R.styleable.yoga_yg_marginLeft) {
node.setMarginPercent(YogaEdge.LEFT, numericValue);
} else if (attribute == R.styleable.yoga_yg_margin_top) {
} else if (attribute == R.styleable.yoga_yg_marginTop) {
node.setMarginPercent(YogaEdge.TOP, numericValue);
} else if (attribute == R.styleable.yoga_yg_margin_right) {
} else if (attribute == R.styleable.yoga_yg_marginRight) {
node.setMarginPercent(YogaEdge.RIGHT, numericValue);
} else if (attribute == R.styleable.yoga_yg_margin_bottom) {
} else if (attribute == R.styleable.yoga_yg_marginBottom) {
node.setMarginPercent(YogaEdge.BOTTOM, numericValue);
} else if (attribute == R.styleable.yoga_yg_margin_start) {
} else if (attribute == R.styleable.yoga_yg_marginStart) {
node.setMarginPercent(YogaEdge.START, numericValue);
} else if (attribute == R.styleable.yoga_yg_margin_end) {
} else if (attribute == R.styleable.yoga_yg_marginEnd) {
node.setMarginPercent(YogaEdge.END, numericValue);
} else if (attribute == R.styleable.yoga_yg_margin_horizontal) {
} else if (attribute == R.styleable.yoga_yg_marginHorizontal) {
node.setMarginPercent(YogaEdge.HORIZONTAL, numericValue);
} else if (attribute == R.styleable.yoga_yg_margin_vertical) {
} else if (attribute == R.styleable.yoga_yg_marginVertical) {
node.setMarginPercent(YogaEdge.VERTICAL, numericValue);
} else if (attribute == R.styleable.yoga_yg_margin_all) {
} else if (attribute == R.styleable.yoga_yg_marginAll) {
node.setMarginPercent(YogaEdge.ALL, numericValue);
} else if (attribute == R.styleable.yoga_yg_max_height) {
} else if (attribute == R.styleable.yoga_yg_maxHeight) {
node.setMaxHeightPercent(numericValue);
} else if (attribute == R.styleable.yoga_yg_max_width) {
} else if (attribute == R.styleable.yoga_yg_maxWidth) {
node.setMaxWidthPercent(numericValue);
} else if (attribute == R.styleable.yoga_yg_min_height) {
} else if (attribute == R.styleable.yoga_yg_minHeight) {
node.setMinHeightPercent(numericValue);
} else if (attribute == R.styleable.yoga_yg_min_width) {
} else if (attribute == R.styleable.yoga_yg_minWidth) {
node.setMinWidthPercent(numericValue);
} else if (attribute == R.styleable.yoga_yg_padding_left) {
} else if (attribute == R.styleable.yoga_yg_paddingLeft) {
node.setPaddingPercent(YogaEdge.LEFT, numericValue);
} else if (attribute == R.styleable.yoga_yg_padding_top) {
} else if (attribute == R.styleable.yoga_yg_paddingTop) {
node.setPaddingPercent(YogaEdge.TOP, numericValue);
} else if (attribute == R.styleable.yoga_yg_padding_right) {
} else if (attribute == R.styleable.yoga_yg_paddingRight) {
node.setPaddingPercent(YogaEdge.RIGHT, numericValue);
} else if (attribute == R.styleable.yoga_yg_padding_bottom) {
} else if (attribute == R.styleable.yoga_yg_paddingBottom) {
node.setPaddingPercent(YogaEdge.BOTTOM, numericValue);
} else if (attribute == R.styleable.yoga_yg_padding_start) {
} else if (attribute == R.styleable.yoga_yg_paddingStart) {
node.setPaddingPercent(YogaEdge.START, numericValue);
} else if (attribute == R.styleable.yoga_yg_padding_end) {
} else if (attribute == R.styleable.yoga_yg_paddingEnd) {
node.setPaddingPercent(YogaEdge.END, numericValue);
} else if (attribute == R.styleable.yoga_yg_padding_horizontal) {
} else if (attribute == R.styleable.yoga_yg_paddingHorizontal) {
node.setPaddingPercent(YogaEdge.HORIZONTAL, numericValue);
} else if (attribute == R.styleable.yoga_yg_padding_vertical) {
} else if (attribute == R.styleable.yoga_yg_paddingVertical) {
node.setPaddingPercent(YogaEdge.VERTICAL, numericValue);
} else if (attribute == R.styleable.yoga_yg_padding_all) {
} else if (attribute == R.styleable.yoga_yg_paddingAll) {
node.setPaddingPercent(YogaEdge.ALL, numericValue);
} else if (attribute == R.styleable.yoga_yg_position_left) {
} else if (attribute == R.styleable.yoga_yg_positionLeft) {
node.setPositionPercent(YogaEdge.LEFT, numericValue);
} else if (attribute == R.styleable.yoga_yg_position_top) {
} else if (attribute == R.styleable.yoga_yg_positionTop) {
node.setPositionPercent(YogaEdge.TOP, numericValue);
} else if (attribute == R.styleable.yoga_yg_position_right) {
} else if (attribute == R.styleable.yoga_yg_positionRight) {
node.setPositionPercent(YogaEdge.RIGHT, numericValue);
} else if (attribute == R.styleable.yoga_yg_position_bottom) {
} else if (attribute == R.styleable.yoga_yg_positionBottom) {
node.setPositionPercent(YogaEdge.BOTTOM, numericValue);
} else if (attribute == R.styleable.yoga_yg_position_start) {
} else if (attribute == R.styleable.yoga_yg_positionStart) {
node.setPositionPercent(YogaEdge.START, numericValue);
} else if (attribute == R.styleable.yoga_yg_position_end) {
} else if (attribute == R.styleable.yoga_yg_positionEnd) {
node.setPositionPercent(YogaEdge.END, numericValue);
} else if (attribute == R.styleable.yoga_yg_position_horizontal) {
} else if (attribute == R.styleable.yoga_yg_positionHorizontal) {
node.setPositionPercent(YogaEdge.HORIZONTAL, numericValue);
} else if (attribute == R.styleable.yoga_yg_position_vertical) {
} else if (attribute == R.styleable.yoga_yg_positionVertical) {
node.setPositionPercent(YogaEdge.VERTICAL, numericValue);
} else if (attribute == R.styleable.yoga_yg_position_all) {
} else if (attribute == R.styleable.yoga_yg_positionAll) {
node.setPositionPercent(YogaEdge.ALL, numericValue);
} else if (attribute == R.styleable.yoga_yg_width) {
node.setWidthPercent(numericValue);

View File

@@ -12,7 +12,7 @@
<resources>
<declare-styleable name="yoga">
<attr name="yg_align_content" format="enum">
<attr name="yg_alignContent" format="enum">
<enum name="auto" value="0"/>
<enum name="flex_start" value="1"/>
<enum name="center" value="2"/>
@@ -21,7 +21,7 @@
<enum name="baseline" value="5"/>
</attr>
<attr name="yg_align_items" format="enum">
<attr name="yg_alignItems" format="enum">
<enum name="auto" value="0"/>
<enum name="flex_start" value="1"/>
<enum name="center" value="2"/>
@@ -30,7 +30,7 @@
<enum name="baseline" value="5"/>
</attr>
<attr name="yg_align_self" format="enum">
<attr name="yg_alignSelf" format="enum">
<enum name="auto" value="0"/>
<enum name="flex_start" value="1"/>
<enum name="center" value="2"/>
@@ -39,17 +39,17 @@
<enum name="baseline" value="5"/>
</attr>
<attr name="yg_aspect_ratio" format="float"/>
<attr name="yg_aspectRatio" format="float"/>
<attr name="yg_border_left" format="dimension"/>
<attr name="yg_border_top" format="dimension"/>
<attr name="yg_border_right" format="dimension"/>
<attr name="yg_border_bottom" format="dimension"/>
<attr name="yg_border_start" format="dimension"/>
<attr name="yg_border_end" format="dimension"/>
<attr name="yg_border_horizontal" format="dimension"/>
<attr name="yg_border_vertical" format="dimension"/>
<attr name="yg_border_all" format="dimension"/>
<attr name="yg_borderLeft" format="dimension"/>
<attr name="yg_borderTop" format="dimension"/>
<attr name="yg_borderRight" format="dimension"/>
<attr name="yg_borderBottom" format="dimension"/>
<attr name="yg_borderStart" format="dimension"/>
<attr name="yg_borderEnd" format="dimension"/>
<attr name="yg_borderHorizontal" format="dimension"/>
<attr name="yg_borderVertical" format="dimension"/>
<attr name="yg_borderAll" format="dimension"/>
<attr name="yg_direction" format="enum">
<enum name="inherit" value="0"/>
@@ -64,22 +64,22 @@
<attr name="yg_flex" format="float"/>
<attr name="yg_flex_basis" format="float|string"/>
<attr name="yg_flexBasis" format="float|string"/>
<attr name="yg_flex_direction" format="enum">
<attr name="yg_flexDirection" format="enum">
<enum name="column" value="0"/>
<enum name="column_reverse" value="1"/>
<enum name="row" value="2"/>
<enum name="row_reverse" value="3"/>
</attr>
<attr name="yg_flex_grow" format="float"/>
<attr name="yg_flexGrow" format="float"/>
<attr name="yg_flex_shrink" format="float"/>
<attr name="yg_flexShrink" format="float"/>
<attr name="yg_height" format="dimension|string"/>
<attr name="yg_justify_content" format="enum">
<attr name="yg_justifyContent" format="enum">
<enum name="flex_start" value="0"/>
<enum name="center" value="1"/>
<enum name="flex_end" value="2"/>
@@ -87,23 +87,23 @@
<enum name="space_around" value="4"/>
</attr>
<attr name="yg_margin_left" format="dimension|string"/>
<attr name="yg_margin_top" format="dimension|string"/>
<attr name="yg_margin_right" format="dimension|string"/>
<attr name="yg_margin_bottom" format="dimension|string"/>
<attr name="yg_margin_start" format="dimension|string"/>
<attr name="yg_margin_end" format="dimension|string"/>
<attr name="yg_margin_horizontal" format="dimension|string"/>
<attr name="yg_margin_vertical" format="dimension|string"/>
<attr name="yg_margin_all" format="dimension|string"/>
<attr name="yg_marginLeft" format="dimension|string"/>
<attr name="yg_marginTop" format="dimension|string"/>
<attr name="yg_marginRight" format="dimension|string"/>
<attr name="yg_marginBottom" format="dimension|string"/>
<attr name="yg_marginStart" format="dimension|string"/>
<attr name="yg_marginEnd" format="dimension|string"/>
<attr name="yg_marginHorizontal" format="dimension|string"/>
<attr name="yg_marginVertical" format="dimension|string"/>
<attr name="yg_marginAll" format="dimension|string"/>
<attr name="yg_max_height" format="dimension|string"/>
<attr name="yg_maxHeight" format="dimension|string"/>
<attr name="yg_max_width" format="dimension|string"/>
<attr name="yg_maxWidth" format="dimension|string"/>
<attr name="yg_min_height" format="dimension|string"/>
<attr name="yg_minHeight" format="dimension|string"/>
<attr name="yg_min_width" format="dimension|string"/>
<attr name="yg_minWidth" format="dimension|string"/>
<attr name="yg_overflow" format="enum">
<enum name="visible" value="0"/>
@@ -111,27 +111,27 @@
<enum name="scroll" value="2"/>
</attr>
<attr name="yg_padding_left" format="dimension|string"/>
<attr name="yg_padding_top" format="dimension|string"/>
<attr name="yg_padding_right" format="dimension|string"/>
<attr name="yg_padding_bottom" format="dimension|string"/>
<attr name="yg_padding_start" format="dimension|string"/>
<attr name="yg_padding_end" format="dimension|string"/>
<attr name="yg_padding_horizontal" format="dimension|string"/>
<attr name="yg_padding_vertical" format="dimension|string"/>
<attr name="yg_padding_all" format="dimension|string"/>
<attr name="yg_paddingLeft" format="dimension|string"/>
<attr name="yg_paddingTop" format="dimension|string"/>
<attr name="yg_paddingRight" format="dimension|string"/>
<attr name="yg_paddingBottom" format="dimension|string"/>
<attr name="yg_paddingStart" format="dimension|string"/>
<attr name="yg_paddingEnd" format="dimension|string"/>
<attr name="yg_paddingHorizontal" format="dimension|string"/>
<attr name="yg_paddingVertical" format="dimension|string"/>
<attr name="yg_paddingAll" format="dimension|string"/>
<attr name="yg_position_left" format="dimension|string"/>
<attr name="yg_position_top" format="dimension|string"/>
<attr name="yg_position_right" format="dimension|string"/>
<attr name="yg_position_bottom" format="dimension|string"/>
<attr name="yg_position_start" format="dimension|string"/>
<attr name="yg_position_end" format="dimension|string"/>
<attr name="yg_position_horizontal" format="dimension|string"/>
<attr name="yg_position_vertical" format="dimension|string"/>
<attr name="yg_position_all" format="dimension|string"/>
<attr name="yg_positionLeft" format="dimension|string"/>
<attr name="yg_positionTop" format="dimension|string"/>
<attr name="yg_positionRight" format="dimension|string"/>
<attr name="yg_positionBottom" format="dimension|string"/>
<attr name="yg_positionStart" format="dimension|string"/>
<attr name="yg_positionEnd" format="dimension|string"/>
<attr name="yg_positionHorizontal" format="dimension|string"/>
<attr name="yg_positionVertical" format="dimension|string"/>
<attr name="yg_positionAll" format="dimension|string"/>
<attr name="yg_position_type" format="enum">
<attr name="yg_positionType" format="enum">
<enum name="relative" value="0"/>
<enum name="absolute" value="1"/>
</attr>

View File

@@ -15,6 +15,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Native.cs" />
<Compile Include="$(MSBuildThisFileDirectory)YogaAlign.cs" />
<Compile Include="$(MSBuildThisFileDirectory)YogaBaselineFunc.cs" />
<Compile Include="$(MSBuildThisFileDirectory)YogaConfig.cs" />
<Compile Include="$(MSBuildThisFileDirectory)YogaConstants.cs" />
<Compile Include="$(MSBuildThisFileDirectory)YogaDimension.cs" />
<Compile Include="$(MSBuildThisFileDirectory)YogaDirection.cs" />

View File

@@ -28,7 +28,7 @@ namespace Facebook.Yoga
internal class YGNodeHandle : SafeHandle
{
#if (UNITY_IOS && !UNITY_EDITOR) || __IOS__
#if (UNITY_IOS && !UNITY_EDITOR) || ENABLE_IL2CPP || __IOS__
private GCHandle _managed;
#endif
@@ -46,27 +46,37 @@ namespace Facebook.Yoga
protected override bool ReleaseHandle()
{
#if (UNITY_IOS && !UNITY_EDITOR) || __IOS__
if (_managed.IsAllocated)
{
_managed.Free();
}
#if (UNITY_IOS && !UNITY_EDITOR) || ENABLE_IL2CPP || __IOS__
ReleaseManaged();
#endif
Native.YGNodeFree(this.handle);
GC.KeepAlive(this);
return true;
}
#if (UNITY_IOS && !UNITY_EDITOR) || __IOS__
#if (UNITY_IOS && !UNITY_EDITOR) || ENABLE_IL2CPP || __IOS__
public void SetContext(YogaNode node)
{
if (!_managed.IsAllocated)
{
#if ENABLE_IL2CPP
// Weak causes 'GCHandle value belongs to a different domain' error
_managed = GCHandle.Alloc(node);
#else
_managed = GCHandle.Alloc(node, GCHandleType.Weak);
#endif
Native.YGNodeSetContext(this.handle, GCHandle.ToIntPtr(_managed));
}
}
public void ReleaseManaged()
{
if (_managed.IsAllocated)
{
_managed.Free();
}
}
public static YogaNode GetManaged(IntPtr ygNodePtr)
{
var node =
@@ -83,10 +93,6 @@ namespace Facebook.Yoga
internal class YGConfigHandle : SafeHandle
{
#if (UNITY_IOS && !UNITY_EDITOR) || __IOS__
private GCHandle _managed;
#endif
private YGConfigHandle() : base(IntPtr.Zero, true)
{
}
@@ -101,12 +107,6 @@ namespace Facebook.Yoga
protected override bool ReleaseHandle()
{
#if (UNITY_IOS && !UNITY_EDITOR) || __IOS__
if (_managed.IsAllocated)
{
_managed.Free();
}
#endif
Native.YGConfigFree(this.handle);
GC.KeepAlive(this);
return true;
@@ -138,6 +138,9 @@ namespace Facebook.Yoga
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern int YGNodeGetInstanceCount();
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern int YGConfigGetInstanceCount();
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern void YGConfigSetExperimentalFeatureEnabled(
YGConfigHandle config,
@@ -149,6 +152,19 @@ namespace Facebook.Yoga
YGConfigHandle config,
YogaExperimentalFeature feature);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern void YGConfigSetUseWebDefaults(
YGConfigHandle config,
bool useWebDefaults);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern bool YGConfigGetUseWebDefaults(YGConfigHandle config);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern void YGConfigSetPointScaleFactor(
YGConfigHandle config,
float pixelsInPoint);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern void YGNodeInsertChild(
YGNodeHandle node,
@@ -429,9 +445,9 @@ namespace Facebook.Yoga
#endregion
#region IOS
#region AOT
#if (UNITY_IOS && !UNITY_EDITOR) || __IOS__
#if (UNITY_IOS && !UNITY_EDITOR) || ENABLE_IL2CPP || __IOS__
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr YGNodeGetContext(IntPtr node);

View File

@@ -0,0 +1,72 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
using System;
namespace Facebook.Yoga
{
public class YogaConfig
{
private Native.YGConfigHandle _ygConfig;
public YogaConfig()
{
_ygConfig = Native.YGConfigNew();
if (_ygConfig.IsInvalid)
{
throw new InvalidOperationException("Failed to allocate native memory");
}
}
internal Native.YGConfigHandle Handle
{
get {
return _ygConfig;
}
}
public void SetExperimentalFeatureEnabled(
YogaExperimentalFeature feature,
bool enabled)
{
Native.YGConfigSetExperimentalFeatureEnabled(_ygConfig, feature, enabled);
}
public bool IsExperimentalFeatureEnabled(YogaExperimentalFeature feature)
{
return Native.YGConfigIsExperimentalFeatureEnabled(_ygConfig, feature);
}
public bool UseWebDefaults
{
get
{
return Native.YGConfigGetUseWebDefaults(_ygConfig);
}
set
{
Native.YGConfigSetUseWebDefaults(_ygConfig, value);
}
}
public float PointScaleFactor
{
set
{
Native.YGConfigSetPointScaleFactor(_ygConfig, value);
}
}
public static int GetInstanceCount()
{
return Native.YGConfigGetInstanceCount();
}
}
}

View File

@@ -13,6 +13,9 @@ using System.Runtime.InteropServices;
#if __IOS__
using ObjCRuntime;
#endif
#if ENABLE_IL2CPP
using AOT;
#endif
namespace Facebook.Yoga
{
@@ -26,7 +29,7 @@ namespace Facebook.Yoga
public static Func Logger = null;
#if (UNITY_IOS && !UNITY_EDITOR) || __IOS__
#if (UNITY_IOS && !UNITY_EDITOR) || ENABLE_IL2CPP || __IOS__
[MonoPInvokeCallback(typeof(Func))]
#endif
public static void LoggerInternal(YogaLogLevel level, string message)

View File

@@ -12,60 +12,30 @@ using System.Collections;
using System.Collections.Generic;
using System.Text;
#if (UNITY_IOS && !UNITY_EDITOR) || __IOS__
#if (UNITY_IOS && !UNITY_EDITOR) || ENABLE_IL2CPP || __IOS__
using System.Runtime.InteropServices;
#endif
#if __IOS__
using ObjCRuntime;
#endif
#if ENABLE_IL2CPP
using AOT;
#endif
namespace Facebook.Yoga
{
public class YogaConfig
{
private Native.YGConfigHandle _ygConfig;
public YogaConfig()
{
_ygConfig = Native.YGConfigNew();
if (_ygConfig.IsInvalid)
{
throw new InvalidOperationException("Failed to allocate native memory");
}
}
internal Native.YGConfigHandle Handle {
get {
return _ygConfig;
}
}
public void SetExperimentalFeatureEnabled(
YogaExperimentalFeature feature,
bool enabled)
{
Native.YGConfigSetExperimentalFeatureEnabled(_ygConfig, feature, enabled);
}
public bool IsExperimentalFeatureEnabled(YogaExperimentalFeature feature)
{
return Native.YGConfigIsExperimentalFeatureEnabled(_ygConfig, feature);
}
}
public partial class YogaNode : IEnumerable<YogaNode>
{
private Native.YGNodeHandle _ygNode;
private YogaConfig _config;
private WeakReference _parent;
private List<YogaNode> _children;
private MeasureFunction _measureFunction;
private BaselineFunction _baselineFunction;
private object _data;
#if (UNITY_IOS && !UNITY_EDITOR) || __IOS__
private static YogaMeasureFunc _managedMeasure = MeasureInternalIOS;
private static YogaBaselineFunc _managedBaseline = BaselineInternalIOS;
#if (UNITY_IOS && !UNITY_EDITOR) || ENABLE_IL2CPP || __IOS__
private static YogaMeasureFunc _managedMeasure;
private static YogaBaselineFunc _managedBaseline;
#else
private YogaMeasureFunc _managedMeasure;
private YogaBaselineFunc _managedBaseline;
@@ -86,7 +56,15 @@ namespace Facebook.Yoga
{
YogaLogger.Initialize();
_ygNode = Native.YGNodeNewWithConfig(config.Handle);
if (config != null)
{
_config = config;
_ygNode = Native.YGNodeNewWithConfig(_config.Handle);
}
else
{
_ygNode = Native.YGNodeNew();
}
if (_ygNode.IsInvalid)
{
throw new InvalidOperationException("Failed to allocate native memory");
@@ -94,7 +72,7 @@ namespace Facebook.Yoga
}
public YogaNode(YogaNode srcNode)
: this()
: this(srcNode._config)
{
CopyStyle(srcNode);
}
@@ -106,6 +84,9 @@ namespace Facebook.Yoga
_data = null;
Native.YGNodeReset(_ygNode);
#if (UNITY_IOS && !UNITY_EDITOR) || ENABLE_IL2CPP || __IOS__
_ygNode.ReleaseManaged();
#endif
}
public bool IsDirty
@@ -616,12 +597,17 @@ namespace Facebook.Yoga
_measureFunction = measureFunction;
if (measureFunction != null)
{
#if (UNITY_IOS && !UNITY_EDITOR) || __IOS__
#if (UNITY_IOS && !UNITY_EDITOR) || ENABLE_IL2CPP || __IOS__
_managedMeasure = MeasureInternalAOT;
_ygNode.SetContext(this);
#else
_managedMeasure = MeasureInternal;
#endif
}
else
{
_managedMeasure = null;
}
Native.YGNodeSetMeasureFunc(_ygNode, _managedMeasure);
}
@@ -630,12 +616,17 @@ namespace Facebook.Yoga
_baselineFunction = baselineFunction;
if (baselineFunction != null)
{
#if (UNITY_IOS && !UNITY_EDITOR) || __IOS__
#if (UNITY_IOS && !UNITY_EDITOR) || ENABLE_IL2CPP || __IOS__
_managedBaseline = BaselineInternalAOT;
_ygNode.SetContext(this);
#else
_managedBaseline = BaselineInternal;
#endif
}
else
{
_managedBaseline = null;
}
Native.YGNodeSetBaselineFunc(_ygNode, _managedBaseline);
}
@@ -648,9 +639,9 @@ namespace Facebook.Yoga
Native.YGNodeStyleGetDirection(_ygNode));
}
#if (UNITY_IOS && !UNITY_EDITOR) || __IOS__
#if (UNITY_IOS && !UNITY_EDITOR) || ENABLE_IL2CPP || __IOS__
[MonoPInvokeCallback(typeof(YogaMeasureFunc))]
private static YogaSize MeasureInternalIOS(
private static YogaSize MeasureInternalAOT(
IntPtr ygNodePtr,
float width,
YogaMeasureMode widthMode,
@@ -677,9 +668,9 @@ namespace Facebook.Yoga
return _measureFunction(this, width, widthMode, height, heightMode);
}
#if (UNITY_IOS && !UNITY_EDITOR) || __IOS__
#if (UNITY_IOS && !UNITY_EDITOR) || ENABLE_IL2CPP || __IOS__
[MonoPInvokeCallback(typeof(YogaBaselineFunc))]
private static float BaselineInternalIOS(
private static float BaselineInternalAOT(
IntPtr ygNodePtr,
float width,
float height)

View File

@@ -0,0 +1,124 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{D6477AD6-9EDD-4EBA-8C60-CD31F77C52C6}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Facebook.Yoga</RootNamespace>
<AssemblyName>Facebook.Yoga</AssemblyName>
<DefaultLanguage>en-US</DefaultLanguage>
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
<TargetPlatformVersion>10.0.14393.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.10240.0</TargetPlatformMinVersion>
<MinimumVisualStudioVersion>14</MinimumVisualStudioVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<PlatformTarget>x86</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<NoWarn>;2008</NoWarn>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<PlatformTarget>x86</PlatformTarget>
<OutputPath>bin\x86\Release\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<Optimize>true</Optimize>
<NoWarn>;2008</NoWarn>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|ARM'">
<PlatformTarget>ARM</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\ARM\Debug\</OutputPath>
<DefineConstants>TRACE;DEBUG;NETFX_CORE;WINDOWS_UWP;WINDOWS_UWP_ARM</DefineConstants>
<NoWarn>;2008</NoWarn>
<DebugType>full</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|ARM'">
<PlatformTarget>ARM</PlatformTarget>
<OutputPath>bin\ARM\Release\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP;WINDOWS_UWP_ARM</DefineConstants>
<Optimize>true</Optimize>
<NoWarn>;2008</NoWarn>
<DebugType>pdbonly</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<PlatformTarget>x64</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<NoWarn>;2008</NoWarn>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<PlatformTarget>x64</PlatformTarget>
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
<Optimize>true</Optimize>
<NoWarn>;2008</NoWarn>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<ItemGroup>
<!-- A reference to the entire .Net Framework and Windows SDK are automatically included -->
<None Include="project.json" />
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>
<Import Project="..\..\Facebook.Yoga\Facebook.Yoga.Shared.projitems" Label="Shared" />
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '14.0' ">
<VisualStudioVersion>14.0</VisualStudioVersion>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@@ -0,0 +1,16 @@
{
"dependencies": {
"Microsoft.NETCore.UniversalWindowsPlatform": "5.1.0"
},
"frameworks": {
"uap10.0": {}
},
"runtimes": {
"win10-arm": {},
"win10-arm-aot": {},
"win10-x86": {},
"win10-x86-aot": {},
"win10-x64": {},
"win10-x64-aot": {}
}
}

View File

@@ -29,11 +29,16 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Facebook.Yoga.Desktop.Tests
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Facebook.Yoga.Universal.Tests", "Facebook.Yoga.Universal.Tests\Facebook.Yoga.Universal.Tests.csproj", "{0C76D2FE-6767-44FE-B03D-21B2076BAA73}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Universal", "Universal", "{6669329B-017F-45B3-8611-53AFD065E45C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Facebook.Yoga.Universal", "Facebook.Yoga.Universal\Facebook.Yoga.Universal.csproj", "{D6477AD6-9EDD-4EBA-8C60-CD31F77C52C6}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
..\Facebook.Yoga\Facebook.Yoga.Shared.projitems*{3aace384-fdec-4d91-a3b2-eeb21b46c9ad}*SharedItemsImports = 4
..\tests\Facebook.Yoga\Facebook.Yoga.Shared.Tests.projitems*{4edc82d9-a201-4831-8fe0-98f468f8e4ae}*SharedItemsImports = 13
..\Facebook.Yoga\Facebook.Yoga.Shared.projitems*{91c42d32-291d-4b72-90b4-551663d60b8b}*SharedItemsImports = 13
..\Facebook.Yoga\Facebook.Yoga.Shared.projitems*{d6477ad6-9edd-4eba-8c60-cd31f77c52c6}*SharedItemsImports = 4
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -118,6 +123,22 @@ Global
{0C76D2FE-6767-44FE-B03D-21B2076BAA73}.Release|ARM.ActiveCfg = Release|ARM
{0C76D2FE-6767-44FE-B03D-21B2076BAA73}.Release|x64.ActiveCfg = Release|x64
{0C76D2FE-6767-44FE-B03D-21B2076BAA73}.Release|x86.ActiveCfg = Release|x86
{D6477AD6-9EDD-4EBA-8C60-CD31F77C52C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D6477AD6-9EDD-4EBA-8C60-CD31F77C52C6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D6477AD6-9EDD-4EBA-8C60-CD31F77C52C6}.Debug|ARM.ActiveCfg = Debug|ARM
{D6477AD6-9EDD-4EBA-8C60-CD31F77C52C6}.Debug|ARM.Build.0 = Debug|ARM
{D6477AD6-9EDD-4EBA-8C60-CD31F77C52C6}.Debug|x64.ActiveCfg = Debug|x64
{D6477AD6-9EDD-4EBA-8C60-CD31F77C52C6}.Debug|x64.Build.0 = Debug|x64
{D6477AD6-9EDD-4EBA-8C60-CD31F77C52C6}.Debug|x86.ActiveCfg = Debug|x86
{D6477AD6-9EDD-4EBA-8C60-CD31F77C52C6}.Debug|x86.Build.0 = Debug|x86
{D6477AD6-9EDD-4EBA-8C60-CD31F77C52C6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D6477AD6-9EDD-4EBA-8C60-CD31F77C52C6}.Release|Any CPU.Build.0 = Release|Any CPU
{D6477AD6-9EDD-4EBA-8C60-CD31F77C52C6}.Release|ARM.ActiveCfg = Release|ARM
{D6477AD6-9EDD-4EBA-8C60-CD31F77C52C6}.Release|ARM.Build.0 = Release|ARM
{D6477AD6-9EDD-4EBA-8C60-CD31F77C52C6}.Release|x64.ActiveCfg = Release|x64
{D6477AD6-9EDD-4EBA-8C60-CD31F77C52C6}.Release|x64.Build.0 = Release|x64
{D6477AD6-9EDD-4EBA-8C60-CD31F77C52C6}.Release|x86.ActiveCfg = Release|x86
{D6477AD6-9EDD-4EBA-8C60-CD31F77C52C6}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -130,5 +151,6 @@ Global
{4EDC82D9-A201-4831-8FE0-98F468F8E4AE} = {39A2FFDA-C093-4FA6-8143-45B5019E7DAC}
{AC23F444-5545-4196-8B9F-5C1F6B3E7FB3} = {5289E508-8386-45A1-A12B-258A5899CD45}
{0C76D2FE-6767-44FE-B03D-21B2076BAA73} = {5289E508-8386-45A1-A12B-258A5899CD45}
{D6477AD6-9EDD-4EBA-8C60-CD31F77C52C6} = {6669329B-017F-45B3-8611-53AFD065E45C}
EndGlobalSection
EndGlobal

View File

@@ -1,4 +1,5 @@
#!/bin/sh
echo $ANDROID_SDK
if buck --version >/dev/null 2>&1; then true; else
echo "Building Buck!"
mkdir lib

View File

@@ -12,10 +12,6 @@
<description>A subset of CSS's flexbox layout algorithm and box model.</description>
<copyright>Copyright 2016 Facebook</copyright>
<tags>flexbox flex-box css layout css-layout yoga facebook native</tags>
<dependencies>
<group targetFramework=".NETStandard1.1" />
<group targetFramework="uap10.0" />
</dependencies>
</metadata>
<files>
<!-- build -->
@@ -28,7 +24,7 @@
<file src="..\yoga_windows\bin\Release\Facebook.Yoga.dll" target="lib\netstandard"/>
<!-- UAP -->
<file src="..\yoga_windows\bin\Release\Facebook.Yoga.dll" target="lib\uap10.0"/>
<file src="..\yoga_universal\bin\Release\Facebook.Yoga.dll" target="lib\uap10.0"/>
<!-- net45 -->
<file src="..\yoga_windows\bin\Release\Facebook.Yoga.dll" target="lib\net45" />
@@ -44,24 +40,24 @@
<file src="..\yoga_android\bin\Release\Facebook.Yoga.dll" target="lib\MonoAndroid" />
<!-- runtimes -->
<file src="..\yoga_windows\bin\x86\Release\Facebook.Yoga.dll" target="runtimes\win10-x86\lib\netstandard"/>
<file src="..\yoga_windows\bin\x86\Release\Facebook.Yoga.pdb" target="runtimes\win10-x86\lib\netstandard"/>
<file src="..\yoga_universal\bin\x86\Release\Facebook.Yoga.dll" target="runtimes\win10-x86\lib\netstandard1.0"/>
<file src="..\yoga_universal\bin\x86\Release\Facebook.Yoga.pdb" target="runtimes\win10-x86\lib\netstandard1.0"/>
<file src="..\yoga_windows\bin\x64\Release\Facebook.Yoga.dll" target="runtimes\win10-x64\lib\netstandard"/>
<file src="..\yoga_windows\bin\x64\Release\Facebook.Yoga.pdb" target="runtimes\win10-x64\lib\netstandard"/>
<file src="..\yoga_universal\bin\x64\Release\Facebook.Yoga.dll" target="runtimes\win10-x64\lib\netstandard1.0"/>
<file src="..\yoga_universal\bin\x64\Release\Facebook.Yoga.pdb" target="runtimes\win10-x64\lib\netstandard1.0"/>
<file src="..\yoga_windows\bin\ARM\Release\Facebook.Yoga.dll" target="runtimes\win10-arm\lib\netstandard"/>
<file src="..\yoga_windows\bin\ARM\Release\Facebook.Yoga.pdb" target="runtimes\win10-arm\lib\netstandard"/>
<file src="..\yoga_universal\bin\ARM\Release\Facebook.Yoga.dll" target="runtimes\win10-arm\lib\netstandard1.0"/>
<file src="..\yoga_universal\bin\ARM\Release\Facebook.Yoga.pdb" target="runtimes\win10-arm\lib\netstandard1.0"/>
<file src="..\yoga_windows\bin\x86\Release\Facebook.Yoga.dll" target="runtimes\win-x86\lib\netstandard"/>
<file src="..\yoga_windows\bin\x86\Release\Facebook.Yoga.pdb" target="runtimes\win-x86\lib\netstandard"/>
<file src="..\yoga_windows\bin\x86\Release\Facebook.Yoga.dll" target="runtimes\win-x86\lib\netstandard1.0"/>
<file src="..\yoga_windows\bin\x86\Release\Facebook.Yoga.pdb" target="runtimes\win-x86\lib\netstandard1.0"/>
<file src="..\yoga_windows\bin\x64\Release\Facebook.Yoga.dll" target="runtimes\win-x64\lib\netstandard"/>
<file src="..\yoga_windows\bin\x64\Release\Facebook.Yoga.pdb" target="runtimes\win-x64\lib\netstandard"/>
<file src="..\yoga_windows\bin\x64\Release\Facebook.Yoga.dll" target="runtimes\win-x64\lib\netstandard1.0"/>
<file src="..\yoga_windows\bin\x64\Release\Facebook.Yoga.pdb" target="runtimes\win-x64\lib\netstandard1.0"/>
<file src="..\yoga_windows\bin\ARM\Release\Facebook.Yoga.dll" target="runtimes\win8-arm\lib\netstandard"/>
<file src="..\yoga_windows\bin\ARM\Release\Facebook.Yoga.pdb" target="runtimes\win8-arm\lib\netstandard"/>
<file src="..\yoga_windows\bin\ARM\Release\Facebook.Yoga.dll" target="runtimes\win8-arm\lib\netstandard1.0"/>
<file src="..\yoga_windows\bin\ARM\Release\Facebook.Yoga.pdb" target="runtimes\win8-arm\lib\netstandard1.0"/>
<!-- Native -->

View File

@@ -22,6 +22,7 @@
<Compile Include="$(MSBuildThisFileDirectory)YGMinMaxDimensionTest.cs" />
<Compile Include="$(MSBuildThisFileDirectory)YGPaddingTest.cs" />
<Compile Include="$(MSBuildThisFileDirectory)YGRoundingTest.cs" />
<Compile Include="$(MSBuildThisFileDirectory)YogaConfigTest.cs" />
<Compile Include="$(MSBuildThisFileDirectory)YogaNodeSpacingTest.cs" />
<Compile Include="$(MSBuildThisFileDirectory)YogaNodeTest.cs" />
</ItemGroup>

View File

@@ -719,5 +719,31 @@ namespace Facebook.Yoga
Assert.AreEqual(40f, root_child0.LayoutHeight);
}
[Test]
public void Test_position_root_with_rtl_should_position_withoutdirection()
{
YogaConfig config = new YogaConfig();
YogaNode root = new YogaNode(config);
root.Left = 72;
root.Width = 52;
root.Height = 52;
root.StyleDirection = YogaDirection.LTR;
root.CalculateLayout();
Assert.AreEqual(72f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(52f, root.LayoutWidth);
Assert.AreEqual(52f, root.LayoutHeight);
root.StyleDirection = YogaDirection.RTL;
root.CalculateLayout();
Assert.AreEqual(72f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(52f, root.LayoutWidth);
Assert.AreEqual(52f, root.LayoutHeight);
}
}
}

View File

@@ -1587,5 +1587,233 @@ namespace Facebook.Yoga
Assert.AreEqual(20f, root_child3.LayoutHeight);
}
[Test]
public void Test_align_items_center_child_with_margin_bigger_than_parent()
{
YogaConfig config = new YogaConfig();
YogaNode root = new YogaNode(config);
root.JustifyContent = YogaJustify.Center;
root.AlignItems = YogaAlign.Center;
root.Width = 52;
root.Height = 52;
YogaNode root_child0 = new YogaNode(config);
root_child0.AlignItems = YogaAlign.Center;
root.Insert(0, root_child0);
YogaNode root_child0_child0 = new YogaNode(config);
root_child0_child0.MarginLeft = 10;
root_child0_child0.MarginRight = 10;
root_child0_child0.Width = 52;
root_child0_child0.Height = 52;
root_child0.Insert(0, root_child0_child0);
root.StyleDirection = YogaDirection.LTR;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(52f, root.LayoutWidth);
Assert.AreEqual(52f, root.LayoutHeight);
Assert.AreEqual(-10f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(72f, root_child0.LayoutWidth);
Assert.AreEqual(52f, root_child0.LayoutHeight);
Assert.AreEqual(10f, root_child0_child0.LayoutX);
Assert.AreEqual(0f, root_child0_child0.LayoutY);
Assert.AreEqual(52f, root_child0_child0.LayoutWidth);
Assert.AreEqual(52f, root_child0_child0.LayoutHeight);
root.StyleDirection = YogaDirection.RTL;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(52f, root.LayoutWidth);
Assert.AreEqual(52f, root.LayoutHeight);
Assert.AreEqual(-10f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(72f, root_child0.LayoutWidth);
Assert.AreEqual(52f, root_child0.LayoutHeight);
Assert.AreEqual(10f, root_child0_child0.LayoutX);
Assert.AreEqual(0f, root_child0_child0.LayoutY);
Assert.AreEqual(52f, root_child0_child0.LayoutWidth);
Assert.AreEqual(52f, root_child0_child0.LayoutHeight);
}
[Test]
public void Test_align_items_flex_end_child_with_margin_bigger_than_parent()
{
YogaConfig config = new YogaConfig();
YogaNode root = new YogaNode(config);
root.JustifyContent = YogaJustify.Center;
root.AlignItems = YogaAlign.Center;
root.Width = 52;
root.Height = 52;
YogaNode root_child0 = new YogaNode(config);
root_child0.AlignItems = YogaAlign.FlexEnd;
root.Insert(0, root_child0);
YogaNode root_child0_child0 = new YogaNode(config);
root_child0_child0.MarginLeft = 10;
root_child0_child0.MarginRight = 10;
root_child0_child0.Width = 52;
root_child0_child0.Height = 52;
root_child0.Insert(0, root_child0_child0);
root.StyleDirection = YogaDirection.LTR;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(52f, root.LayoutWidth);
Assert.AreEqual(52f, root.LayoutHeight);
Assert.AreEqual(-10f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(72f, root_child0.LayoutWidth);
Assert.AreEqual(52f, root_child0.LayoutHeight);
Assert.AreEqual(10f, root_child0_child0.LayoutX);
Assert.AreEqual(0f, root_child0_child0.LayoutY);
Assert.AreEqual(52f, root_child0_child0.LayoutWidth);
Assert.AreEqual(52f, root_child0_child0.LayoutHeight);
root.StyleDirection = YogaDirection.RTL;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(52f, root.LayoutWidth);
Assert.AreEqual(52f, root.LayoutHeight);
Assert.AreEqual(-10f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(72f, root_child0.LayoutWidth);
Assert.AreEqual(52f, root_child0.LayoutHeight);
Assert.AreEqual(10f, root_child0_child0.LayoutX);
Assert.AreEqual(0f, root_child0_child0.LayoutY);
Assert.AreEqual(52f, root_child0_child0.LayoutWidth);
Assert.AreEqual(52f, root_child0_child0.LayoutHeight);
}
[Test]
public void Test_align_items_center_child_without_margin_bigger_than_parent()
{
YogaConfig config = new YogaConfig();
YogaNode root = new YogaNode(config);
root.JustifyContent = YogaJustify.Center;
root.AlignItems = YogaAlign.Center;
root.Width = 52;
root.Height = 52;
YogaNode root_child0 = new YogaNode(config);
root_child0.AlignItems = YogaAlign.Center;
root.Insert(0, root_child0);
YogaNode root_child0_child0 = new YogaNode(config);
root_child0_child0.Width = 72;
root_child0_child0.Height = 72;
root_child0.Insert(0, root_child0_child0);
root.StyleDirection = YogaDirection.LTR;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(52f, root.LayoutWidth);
Assert.AreEqual(52f, root.LayoutHeight);
Assert.AreEqual(-10f, root_child0.LayoutX);
Assert.AreEqual(-10f, root_child0.LayoutY);
Assert.AreEqual(72f, root_child0.LayoutWidth);
Assert.AreEqual(72f, root_child0.LayoutHeight);
Assert.AreEqual(0f, root_child0_child0.LayoutX);
Assert.AreEqual(0f, root_child0_child0.LayoutY);
Assert.AreEqual(72f, root_child0_child0.LayoutWidth);
Assert.AreEqual(72f, root_child0_child0.LayoutHeight);
root.StyleDirection = YogaDirection.RTL;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(52f, root.LayoutWidth);
Assert.AreEqual(52f, root.LayoutHeight);
Assert.AreEqual(-10f, root_child0.LayoutX);
Assert.AreEqual(-10f, root_child0.LayoutY);
Assert.AreEqual(72f, root_child0.LayoutWidth);
Assert.AreEqual(72f, root_child0.LayoutHeight);
Assert.AreEqual(0f, root_child0_child0.LayoutX);
Assert.AreEqual(0f, root_child0_child0.LayoutY);
Assert.AreEqual(72f, root_child0_child0.LayoutWidth);
Assert.AreEqual(72f, root_child0_child0.LayoutHeight);
}
[Test]
public void Test_align_items_flex_end_child_without_margin_bigger_than_parent()
{
YogaConfig config = new YogaConfig();
YogaNode root = new YogaNode(config);
root.JustifyContent = YogaJustify.Center;
root.AlignItems = YogaAlign.Center;
root.Width = 52;
root.Height = 52;
YogaNode root_child0 = new YogaNode(config);
root_child0.AlignItems = YogaAlign.FlexEnd;
root.Insert(0, root_child0);
YogaNode root_child0_child0 = new YogaNode(config);
root_child0_child0.Width = 72;
root_child0_child0.Height = 72;
root_child0.Insert(0, root_child0_child0);
root.StyleDirection = YogaDirection.LTR;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(52f, root.LayoutWidth);
Assert.AreEqual(52f, root.LayoutHeight);
Assert.AreEqual(-10f, root_child0.LayoutX);
Assert.AreEqual(-10f, root_child0.LayoutY);
Assert.AreEqual(72f, root_child0.LayoutWidth);
Assert.AreEqual(72f, root_child0.LayoutHeight);
Assert.AreEqual(0f, root_child0_child0.LayoutX);
Assert.AreEqual(0f, root_child0_child0.LayoutY);
Assert.AreEqual(72f, root_child0_child0.LayoutWidth);
Assert.AreEqual(72f, root_child0_child0.LayoutHeight);
root.StyleDirection = YogaDirection.RTL;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(52f, root.LayoutWidth);
Assert.AreEqual(52f, root.LayoutHeight);
Assert.AreEqual(-10f, root_child0.LayoutX);
Assert.AreEqual(-10f, root_child0.LayoutY);
Assert.AreEqual(72f, root_child0.LayoutWidth);
Assert.AreEqual(72f, root_child0.LayoutHeight);
Assert.AreEqual(0f, root_child0_child0.LayoutX);
Assert.AreEqual(0f, root_child0_child0.LayoutY);
Assert.AreEqual(72f, root_child0_child0.LayoutWidth);
Assert.AreEqual(72f, root_child0_child0.LayoutHeight);
}
}
}

View File

@@ -1352,5 +1352,260 @@ namespace Facebook.Yoga
Assert.AreEqual(50f, root_child1.LayoutHeight);
}
[Test]
public void Test_margin_should_not_be_part_of_max_height()
{
YogaConfig config = new YogaConfig();
YogaNode root = new YogaNode(config);
root.Width = 250;
root.Height = 250;
YogaNode root_child0 = new YogaNode(config);
root_child0.MarginTop = 20;
root_child0.Width = 100;
root_child0.Height = 100;
root_child0.MaxHeight = 100;
root.Insert(0, root_child0);
root.StyleDirection = YogaDirection.LTR;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(250f, root.LayoutWidth);
Assert.AreEqual(250f, root.LayoutHeight);
Assert.AreEqual(0f, root_child0.LayoutX);
Assert.AreEqual(20f, root_child0.LayoutY);
Assert.AreEqual(100f, root_child0.LayoutWidth);
Assert.AreEqual(100f, root_child0.LayoutHeight);
root.StyleDirection = YogaDirection.RTL;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(250f, root.LayoutWidth);
Assert.AreEqual(250f, root.LayoutHeight);
Assert.AreEqual(150f, root_child0.LayoutX);
Assert.AreEqual(20f, root_child0.LayoutY);
Assert.AreEqual(100f, root_child0.LayoutWidth);
Assert.AreEqual(100f, root_child0.LayoutHeight);
}
[Test]
public void Test_margin_should_not_be_part_of_max_width()
{
YogaConfig config = new YogaConfig();
YogaNode root = new YogaNode(config);
root.Width = 250;
root.Height = 250;
YogaNode root_child0 = new YogaNode(config);
root_child0.MarginLeft = 20;
root_child0.Width = 100;
root_child0.MaxWidth = 100;
root_child0.Height = 100;
root.Insert(0, root_child0);
root.StyleDirection = YogaDirection.LTR;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(250f, root.LayoutWidth);
Assert.AreEqual(250f, root.LayoutHeight);
Assert.AreEqual(20f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(100f, root_child0.LayoutWidth);
Assert.AreEqual(100f, root_child0.LayoutHeight);
root.StyleDirection = YogaDirection.RTL;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(250f, root.LayoutWidth);
Assert.AreEqual(250f, root.LayoutHeight);
Assert.AreEqual(150f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(100f, root_child0.LayoutWidth);
Assert.AreEqual(100f, root_child0.LayoutHeight);
}
[Test]
public void Test_margin_auto_left_right_child_bigger_than_parent()
{
YogaConfig config = new YogaConfig();
YogaNode root = new YogaNode(config);
root.JustifyContent = YogaJustify.Center;
root.Width = 52;
root.Height = 52;
YogaNode root_child0 = new YogaNode(config);
root_child0.MarginLeft = YogaValue.Auto();
root_child0.MarginRight = YogaValue.Auto();
root_child0.Width = 72;
root_child0.Height = 72;
root.Insert(0, root_child0);
root.StyleDirection = YogaDirection.LTR;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(52f, root.LayoutWidth);
Assert.AreEqual(52f, root.LayoutHeight);
Assert.AreEqual(0f, root_child0.LayoutX);
Assert.AreEqual(-10f, root_child0.LayoutY);
Assert.AreEqual(72f, root_child0.LayoutWidth);
Assert.AreEqual(72f, root_child0.LayoutHeight);
root.StyleDirection = YogaDirection.RTL;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(52f, root.LayoutWidth);
Assert.AreEqual(52f, root.LayoutHeight);
Assert.AreEqual(-20f, root_child0.LayoutX);
Assert.AreEqual(-10f, root_child0.LayoutY);
Assert.AreEqual(72f, root_child0.LayoutWidth);
Assert.AreEqual(72f, root_child0.LayoutHeight);
}
[Test]
public void Test_margin_auto_left_child_bigger_than_parent()
{
YogaConfig config = new YogaConfig();
YogaNode root = new YogaNode(config);
root.JustifyContent = YogaJustify.Center;
root.Width = 52;
root.Height = 52;
YogaNode root_child0 = new YogaNode(config);
root_child0.MarginLeft = YogaValue.Auto();
root_child0.Width = 72;
root_child0.Height = 72;
root.Insert(0, root_child0);
root.StyleDirection = YogaDirection.LTR;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(52f, root.LayoutWidth);
Assert.AreEqual(52f, root.LayoutHeight);
Assert.AreEqual(0f, root_child0.LayoutX);
Assert.AreEqual(-10f, root_child0.LayoutY);
Assert.AreEqual(72f, root_child0.LayoutWidth);
Assert.AreEqual(72f, root_child0.LayoutHeight);
root.StyleDirection = YogaDirection.RTL;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(52f, root.LayoutWidth);
Assert.AreEqual(52f, root.LayoutHeight);
Assert.AreEqual(-20f, root_child0.LayoutX);
Assert.AreEqual(-10f, root_child0.LayoutY);
Assert.AreEqual(72f, root_child0.LayoutWidth);
Assert.AreEqual(72f, root_child0.LayoutHeight);
}
[Test]
public void Test_margin_fix_left_auto_right_child_bigger_than_parent()
{
YogaConfig config = new YogaConfig();
YogaNode root = new YogaNode(config);
root.JustifyContent = YogaJustify.Center;
root.Width = 52;
root.Height = 52;
YogaNode root_child0 = new YogaNode(config);
root_child0.MarginLeft = 10;
root_child0.MarginRight = YogaValue.Auto();
root_child0.Width = 72;
root_child0.Height = 72;
root.Insert(0, root_child0);
root.StyleDirection = YogaDirection.LTR;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(52f, root.LayoutWidth);
Assert.AreEqual(52f, root.LayoutHeight);
Assert.AreEqual(10f, root_child0.LayoutX);
Assert.AreEqual(-10f, root_child0.LayoutY);
Assert.AreEqual(72f, root_child0.LayoutWidth);
Assert.AreEqual(72f, root_child0.LayoutHeight);
root.StyleDirection = YogaDirection.RTL;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(52f, root.LayoutWidth);
Assert.AreEqual(52f, root.LayoutHeight);
Assert.AreEqual(-20f, root_child0.LayoutX);
Assert.AreEqual(-10f, root_child0.LayoutY);
Assert.AreEqual(72f, root_child0.LayoutWidth);
Assert.AreEqual(72f, root_child0.LayoutHeight);
}
[Test]
public void Test_margin_auto_left_fix_right_child_bigger_than_parent()
{
YogaConfig config = new YogaConfig();
YogaNode root = new YogaNode(config);
root.JustifyContent = YogaJustify.Center;
root.Width = 52;
root.Height = 52;
YogaNode root_child0 = new YogaNode(config);
root_child0.MarginLeft = YogaValue.Auto();
root_child0.MarginRight = 10;
root_child0.Width = 72;
root_child0.Height = 72;
root.Insert(0, root_child0);
root.StyleDirection = YogaDirection.LTR;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(52f, root.LayoutWidth);
Assert.AreEqual(52f, root.LayoutHeight);
Assert.AreEqual(0f, root_child0.LayoutX);
Assert.AreEqual(-10f, root_child0.LayoutY);
Assert.AreEqual(72f, root_child0.LayoutWidth);
Assert.AreEqual(72f, root_child0.LayoutHeight);
root.StyleDirection = YogaDirection.RTL;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(52f, root.LayoutWidth);
Assert.AreEqual(52f, root.LayoutHeight);
Assert.AreEqual(-30f, root_child0.LayoutX);
Assert.AreEqual(-10f, root_child0.LayoutY);
Assert.AreEqual(72f, root_child0.LayoutWidth);
Assert.AreEqual(72f, root_child0.LayoutHeight);
}
}
}

View File

@@ -957,5 +957,113 @@ namespace Facebook.Yoga
Assert.AreEqual(10f, root_child0.LayoutHeight);
}
[Test]
public void Test_min_width_in_flex_distribution()
{
YogaConfig config = new YogaConfig();
YogaNode root = new YogaNode(config);
root.FlexDirection = YogaFlexDirection.Row;
root.Width = 300;
root.Height = 300;
YogaNode root_child0 = new YogaNode(config);
root_child0.FlexGrow = 2;
root_child0.FlexShrink = 1;
root_child0.FlexBasis = 0.Percent();
root_child0.MinWidth = 100;
root_child0.MaxWidth = 200;
root.Insert(0, root_child0);
YogaNode root_child1 = new YogaNode(config);
root_child1.FlexGrow = 1;
root_child1.FlexShrink = 1;
root_child1.FlexBasis = 0.Percent();
root.Insert(1, root_child1);
YogaNode root_child2 = new YogaNode(config);
root_child2.FlexGrow = 1;
root_child2.FlexShrink = 1;
root_child2.FlexBasis = 0.Percent();
root.Insert(2, root_child2);
YogaNode root_child3 = new YogaNode(config);
root_child3.FlexGrow = 1;
root_child3.FlexShrink = 1;
root_child3.FlexBasis = 0.Percent();
root.Insert(3, root_child3);
YogaNode root_child4 = new YogaNode(config);
root_child4.FlexGrow = 1;
root_child4.FlexShrink = 1;
root_child4.FlexBasis = 0.Percent();
root.Insert(4, root_child4);
root.StyleDirection = YogaDirection.LTR;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(300f, root.LayoutWidth);
Assert.AreEqual(300f, root.LayoutHeight);
Assert.AreEqual(0f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(100f, root_child0.LayoutWidth);
Assert.AreEqual(300f, root_child0.LayoutHeight);
Assert.AreEqual(100f, root_child1.LayoutX);
Assert.AreEqual(0f, root_child1.LayoutY);
Assert.AreEqual(50f, root_child1.LayoutWidth);
Assert.AreEqual(300f, root_child1.LayoutHeight);
Assert.AreEqual(150f, root_child2.LayoutX);
Assert.AreEqual(0f, root_child2.LayoutY);
Assert.AreEqual(50f, root_child2.LayoutWidth);
Assert.AreEqual(300f, root_child2.LayoutHeight);
Assert.AreEqual(200f, root_child3.LayoutX);
Assert.AreEqual(0f, root_child3.LayoutY);
Assert.AreEqual(50f, root_child3.LayoutWidth);
Assert.AreEqual(300f, root_child3.LayoutHeight);
Assert.AreEqual(250f, root_child4.LayoutX);
Assert.AreEqual(0f, root_child4.LayoutY);
Assert.AreEqual(50f, root_child4.LayoutWidth);
Assert.AreEqual(300f, root_child4.LayoutHeight);
root.StyleDirection = YogaDirection.RTL;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(300f, root.LayoutWidth);
Assert.AreEqual(300f, root.LayoutHeight);
Assert.AreEqual(200f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(100f, root_child0.LayoutWidth);
Assert.AreEqual(300f, root_child0.LayoutHeight);
Assert.AreEqual(150f, root_child1.LayoutX);
Assert.AreEqual(0f, root_child1.LayoutY);
Assert.AreEqual(50f, root_child1.LayoutWidth);
Assert.AreEqual(300f, root_child1.LayoutHeight);
Assert.AreEqual(100f, root_child2.LayoutX);
Assert.AreEqual(0f, root_child2.LayoutY);
Assert.AreEqual(50f, root_child2.LayoutWidth);
Assert.AreEqual(300f, root_child2.LayoutHeight);
Assert.AreEqual(50f, root_child3.LayoutX);
Assert.AreEqual(0f, root_child3.LayoutY);
Assert.AreEqual(50f, root_child3.LayoutWidth);
Assert.AreEqual(300f, root_child3.LayoutHeight);
Assert.AreEqual(0f, root_child4.LayoutX);
Assert.AreEqual(0f, root_child4.LayoutY);
Assert.AreEqual(50f, root_child4.LayoutWidth);
Assert.AreEqual(300f, root_child4.LayoutHeight);
}
}
}

View File

@@ -1146,5 +1146,76 @@ namespace Facebook.Yoga
Assert.AreEqual(50f, root_child0_child0_child1.LayoutHeight);
}
[Test]
public void Test_percent_absolute_position()
{
YogaConfig config = new YogaConfig();
YogaNode root = new YogaNode(config);
root.Width = 60;
root.Height = 50;
YogaNode root_child0 = new YogaNode(config);
root_child0.FlexDirection = YogaFlexDirection.Row;
root_child0.PositionType = YogaPositionType.Absolute;
root_child0.Left = 50.Percent();
root_child0.Width = 100.Percent();
root_child0.Height = 50;
root.Insert(0, root_child0);
YogaNode root_child0_child0 = new YogaNode(config);
root_child0_child0.Width = 100.Percent();
root_child0.Insert(0, root_child0_child0);
YogaNode root_child0_child1 = new YogaNode(config);
root_child0_child1.Width = 100.Percent();
root_child0.Insert(1, root_child0_child1);
root.StyleDirection = YogaDirection.LTR;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(60f, root.LayoutWidth);
Assert.AreEqual(50f, root.LayoutHeight);
Assert.AreEqual(30f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(60f, root_child0.LayoutWidth);
Assert.AreEqual(50f, root_child0.LayoutHeight);
Assert.AreEqual(0f, root_child0_child0.LayoutX);
Assert.AreEqual(0f, root_child0_child0.LayoutY);
Assert.AreEqual(60f, root_child0_child0.LayoutWidth);
Assert.AreEqual(50f, root_child0_child0.LayoutHeight);
Assert.AreEqual(60f, root_child0_child1.LayoutX);
Assert.AreEqual(0f, root_child0_child1.LayoutY);
Assert.AreEqual(60f, root_child0_child1.LayoutWidth);
Assert.AreEqual(50f, root_child0_child1.LayoutHeight);
root.StyleDirection = YogaDirection.RTL;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(60f, root.LayoutWidth);
Assert.AreEqual(50f, root.LayoutHeight);
Assert.AreEqual(30f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(60f, root_child0.LayoutWidth);
Assert.AreEqual(50f, root_child0.LayoutHeight);
Assert.AreEqual(0f, root_child0_child0.LayoutX);
Assert.AreEqual(0f, root_child0_child0.LayoutY);
Assert.AreEqual(60f, root_child0_child0.LayoutWidth);
Assert.AreEqual(50f, root_child0_child0.LayoutHeight);
Assert.AreEqual(-60f, root_child0_child1.LayoutX);
Assert.AreEqual(0f, root_child0_child1.LayoutY);
Assert.AreEqual(60f, root_child0_child1.LayoutWidth);
Assert.AreEqual(50f, root_child0_child1.LayoutHeight);
}
}
}

View File

@@ -0,0 +1,136 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
using NUnit.Framework;
using System;
/**
* Tests for {@link YogaConfig}.
*/
namespace Facebook.Yoga
{
[TestFixture]
public class YogaConfigTest
{
[Test]
public void TestUseWebDefaults()
{
YogaNode node0 = new YogaNode(new YogaConfig{UseWebDefaults = true});
Assert.AreEqual(YogaFlexDirection.Row, node0.FlexDirection);
node0.Reset();
Assert.AreEqual(YogaFlexDirection.Row, node0.FlexDirection);
YogaConfig config = new YogaConfig();
config.UseWebDefaults = true;
YogaNode node1 = new YogaNode(config);
Assert.AreEqual(YogaFlexDirection.Row, node1.FlexDirection);
node1.Reset();
Assert.AreEqual(YogaFlexDirection.Row, node1.FlexDirection);
}
[Test]
public void TestDefaultConfig()
{
YogaNode node0 = new YogaNode();
Assert.AreEqual(YogaFlexDirection.Column, node0.FlexDirection);
YogaNode node1 = new YogaNode(new YogaConfig());
Assert.AreEqual(YogaFlexDirection.Column, node1.FlexDirection);
}
[Test]
public void TestCopyConstructor()
{
YogaNode srcNode = new YogaNode(new YogaConfig{UseWebDefaults = true});
YogaNode node0 = new YogaNode(srcNode);
Assert.AreEqual(YogaFlexDirection.Row, node0.FlexDirection);
node0.FlexDirection = YogaFlexDirection.Column;
Assert.AreEqual(YogaFlexDirection.Column, node0.FlexDirection);
node0.Reset();
Assert.AreEqual(YogaFlexDirection.Row, node0.FlexDirection);
YogaNode node1 = new YogaNode(srcNode)
{
FlexDirection = YogaFlexDirection.Column
};
Assert.AreEqual(YogaFlexDirection.Column, node1.FlexDirection);
node1.Reset();
Assert.AreEqual(YogaFlexDirection.Row, node1.FlexDirection);
}
public static void ForceGC()
{
YogaNodeTest.ForceGC();
}
[Test]
public void TestDestructor()
{
ForceGC();
int instanceCount = YogaConfig.GetInstanceCount();
TestDestructorForGC(instanceCount);
ForceGC();
Assert.AreEqual(instanceCount, YogaConfig.GetInstanceCount());
}
private void TestDestructorForGC(int instanceCount)
{
YogaConfig config = new YogaConfig();
Assert.IsNotNull(config);
Assert.AreEqual(instanceCount + 1, YogaConfig.GetInstanceCount());
config = null;
}
[Test]
public void TestRetainConfig()
{
ForceGC();
int nodeInstanceCount = YogaNode.GetInstanceCount();
int configInstanceCount = YogaConfig.GetInstanceCount();
TestRetainConfigForGC(nodeInstanceCount, configInstanceCount);
ForceGC();
Assert.AreEqual(nodeInstanceCount, YogaNode.GetInstanceCount());
Assert.AreEqual(configInstanceCount, YogaConfig.GetInstanceCount());
}
private void TestRetainConfigForGC(int nodeInstanceCount, int configInstanceCount)
{
ForceGC();
Assert.AreEqual(nodeInstanceCount, YogaNode.GetInstanceCount());
Assert.AreEqual(configInstanceCount, YogaConfig.GetInstanceCount());
YogaNode node = TestRetainConfigForGC2(nodeInstanceCount, configInstanceCount);
ForceGC();
Assert.IsNotNull(node);
Assert.AreEqual(configInstanceCount + 1, YogaConfig.GetInstanceCount());
Assert.AreEqual(nodeInstanceCount + 1, YogaNode.GetInstanceCount());
node = null;
}
private YogaNode TestRetainConfigForGC2(int nodeInstanceCount, int configInstanceCount)
{
YogaConfig config = new YogaConfig();
Assert.IsNotNull(config);
Assert.AreEqual(configInstanceCount + 1, YogaConfig.GetInstanceCount());
YogaNode node = new YogaNode(config);
Assert.IsNotNull(node);
Assert.AreEqual(nodeInstanceCount + 1, YogaNode.GetInstanceCount());
config = null;
return node;
}
}
}

View File

@@ -73,25 +73,22 @@ namespace Facebook.Yoga
}
[Test]
[ExpectedException("System.NullReferenceException")]
public void TestRemoveAtFromEmpty()
{
YogaNode parent = new YogaNode();
parent.RemoveAt(0);
Assert.Throws<NullReferenceException>(() => parent.RemoveAt(0));
}
[Test]
[ExpectedException("System.ArgumentOutOfRangeException")]
public void TestRemoveAtOutOfRange()
{
YogaNode parent = new YogaNode();
YogaNode child = new YogaNode();
parent.Insert(0, child);
parent.RemoveAt(1);
Assert.Throws<ArgumentOutOfRangeException>(() => parent.RemoveAt(1));
}
[Test]
[ExpectedException("System.InvalidOperationException")]
public void TestCannotAddChildToMultipleParents()
{
YogaNode parent1 = new YogaNode();
@@ -99,7 +96,7 @@ namespace Facebook.Yoga
YogaNode child = new YogaNode();
parent1.Insert(0, child);
parent2.Insert(0, child);
Assert.Throws<InvalidOperationException>(() => parent2.Insert(0, child));
}
[Test]
@@ -113,23 +110,21 @@ namespace Facebook.Yoga
}
[Test]
[ExpectedException("System.InvalidOperationException")]
public void TestResetParent()
{
YogaNode parent = new YogaNode();
YogaNode child = new YogaNode();
parent.Insert(0, child);
parent.Reset();
Assert.Throws<InvalidOperationException>(() => parent.Reset());
}
[Test]
[ExpectedException("System.InvalidOperationException")]
public void TestResetChild()
{
YogaNode parent = new YogaNode();
YogaNode child = new YogaNode();
parent.Insert(0, child);
child.Reset();
Assert.Throws<InvalidOperationException>(() => child.Reset());
}
[Test]
@@ -174,7 +169,6 @@ namespace Facebook.Yoga
}
[Test]
[ExpectedException("System.InvalidOperationException")]
public void TestChildWithMeasureFunc()
{
YogaNode node = new YogaNode();
@@ -182,19 +176,20 @@ namespace Facebook.Yoga
return MeasureOutput.Make(100, 150);
});
YogaNode child = new YogaNode();
node.Insert(0, child);
Assert.Throws<InvalidOperationException>(() => node.Insert(0, child));
}
[Test]
[ExpectedException("System.InvalidOperationException")]
public void TestMeasureFuncWithChild()
{
YogaNode node = new YogaNode();
YogaNode child = new YogaNode();
node.Insert(0, child);
node.SetMeasureFunction((_, width, widthMode, height, heightMode) => {
return MeasureOutput.Make(100, 150);
});
Assert.Throws<InvalidOperationException>(() =>
node.SetMeasureFunction((_, width, widthMode, height, heightMode) => {
return MeasureOutput.Make(100, 150);
})
);
}
[Test]
@@ -260,7 +255,7 @@ namespace Facebook.Yoga
parent.Insert(0, child0);
parent.Insert(0, child1);
parent.CalculateLayout();
Assert.AreEqual("{layout: {width: 100, height: 120, top: 0, left: 0}, flexDirection: 'column', alignItems: 'stretch', flexGrow: 0, flexShrink: 0, flexBasis: nan%, overflow: 'visible', width: 100pt, height: 120pt, children: [\n {layout: {width: 35, height: 45, top: 0, left: 0}, flexDirection: 'column', alignItems: 'stretch', flexGrow: 0, flexShrink: 0, flexBasis: nan%, overflow: 'visible', width: 35pt, height: 45pt, },\n {layout: {width: 30, height: 40, top: 45, left: 0}, flexDirection: 'column', alignItems: 'stretch', flexGrow: 0, flexShrink: 0, flexBasis: nan%, overflow: 'visible', width: 30pt, height: 40pt, },\n]},\n", parent.Print());
Assert.AreEqual("<div layout=\"width: 100; height: 120; top: 0; left: 0;\" style=\"width: 100px; height: 120px; \" >\n <div layout=\"width: 35; height: 45; top: 0; left: 0;\" style=\"width: 35px; height: 45px; \" ></div>\n <div layout=\"width: 30; height: 40; top: 45; left: 0;\" style=\"width: 30px; height: 40px; \" ></div>\n</div>", parent.Print());
}
[Test]
@@ -306,7 +301,7 @@ namespace Facebook.Yoga
Assert.AreEqual(90.Pt(), node4.MaxHeight);
}
private void ForceGC()
public static void ForceGC()
{
GC.Collect(GC.MaxGeneration);
GC.WaitForPendingFinalizers();
@@ -365,6 +360,7 @@ namespace Facebook.Yoga
child = null;
}
#if YOGA_ENABLE_GC_TEST
[Test]
public void TestParentDestructor()
{
@@ -386,6 +382,7 @@ namespace Facebook.Yoga
Assert.AreEqual(instanceCount + 1, YogaNode.GetInstanceCount());
parent.Insert(0, child);
}
#endif
[Test]
public void TestClearWithChildDestructor()

View File

@@ -11,14 +11,14 @@ GEM
coffee-script (2.4.1)
coffee-script-source
execjs
coffee-script-source (1.10.0)
coffee-script-source (1.12.2)
colorator (1.1.0)
ethon (0.9.1)
ethon (0.10.1)
ffi (>= 1.3.0)
execjs (2.7.0)
faraday (0.9.2)
faraday (0.12.0.1)
multipart-post (>= 1.2, < 3)
ffi (1.9.14)
ffi (1.9.18)
forwardable-extended (2.6.0)
gemoji (2.1.0)
github-pages (104)
@@ -51,10 +51,10 @@ GEM
octokit (~> 4.0)
public_suffix (~> 1.4)
typhoeus (~> 0.7)
html-pipeline (2.4.2)
html-pipeline (2.5.0)
activesupport (>= 2)
nokogiri (>= 1.4)
i18n (0.7.0)
i18n (0.8.1)
jekyll (3.3.0)
addressable (~> 2.4)
colorator (~> 1.0)
@@ -98,7 +98,7 @@ GEM
gemoji (~> 2.0)
html-pipeline (~> 2.2)
jekyll (>= 3.0)
json (1.8.3)
json (1.8.6)
kramdown (1.11.1)
liquid (3.0.6)
listen (3.0.6)
@@ -107,33 +107,33 @@ GEM
mercenary (0.3.6)
mini_portile2 (2.1.0)
minima (2.0.0)
minitest (5.9.1)
minitest (5.10.1)
multipart-post (2.0.0)
net-dns (0.8.0)
nokogiri (1.6.8.1)
nokogiri (1.7.1)
mini_portile2 (~> 2.1.0)
octokit (4.4.1)
sawyer (~> 0.7.0, >= 0.5.3)
octokit (4.6.2)
sawyer (~> 0.8.0, >= 0.5.3)
pathutil (0.14.0)
forwardable-extended (~> 2.6)
public_suffix (1.5.3)
rb-fsevent (0.9.8)
rb-inotify (0.9.7)
rb-inotify (0.9.8)
ffi (>= 0.5.0)
rouge (1.11.1)
safe_yaml (1.0.4)
sass (3.4.22)
sawyer (0.7.0)
addressable (>= 2.3.5, < 2.5)
faraday (~> 0.8, < 0.10)
sass (3.4.23)
sawyer (0.8.1)
addressable (>= 2.3.5, < 2.6)
faraday (~> 0.8, < 1.0)
terminal-table (1.7.3)
unicode-display_width (~> 1.1.1)
thread_safe (0.3.5)
thread_safe (0.3.6)
typhoeus (0.8.0)
ethon (>= 0.8.0)
tzinfo (1.2.2)
tzinfo (1.2.3)
thread_safe (~> 0.1)
unicode-display_width (1.1.1)
unicode-display_width (1.1.3)
PLATFORMS
ruby
@@ -142,4 +142,4 @@ DEPENDENCIES
github-pages (~> 104)
BUNDLED WITH
1.13.1
1.14.6

View File

@@ -4,7 +4,7 @@ This directory will contain the user, feature and API documentation for Yoga. Th
### Contributing
See [CONTRIBUTING.md](./CONTRIBUTING.md) for details on how to add or modify content.
See [CONTRIBUTING.md](https://github.com/facebook/yoga/blob/master/CONTRIBUTING.md) for details on how to add or modify content.
### Run the Site Locally

View File

@@ -6,15 +6,56 @@ permalink: /docs/api/android/
---
To include the java bindings and `.so` libraries, add to your build:
<script src="https://gist.github.com/rspencer01/e3cb51e789147b359d842aac6fa30f9f.js"></script>
There is an easy interface to Yoga called `YogaLayout`. This is a view group that lays out its children using Yoga. We recommend looking at the sample app for details on its usage. However, as an overview you can simply define XML layouts such as
<script src="https://gist.github.com/rspencer01/c1964b98f0c60de7c49683a049ed0640.js"></script>
```java
compile 'com.facebook.yoga:yoga:1.2.0'
```
There is an easy interface to Yoga called `YogaLayout`. This is a view group that lays out its children using Yoga. We recommend looking at the sample app for details on its usage. However, as an overview you can simply define XML layouts such as:
```xml
<?xml version="1.0" encoding="utf-8" ?>
<YogaLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yoga="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
yoga:align_items="stretch"
>
<YogaLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/sample_children_background"
yoga:margin_horizontal="10dp"
yoga:margin_top="5dp"
yoga:flex_direction="row"
yoga:align_items="center"
>
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:src="@drawable/ic_launcher"
yoga:flex="0"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/child_1_text"
android:textColor="@color/children_text"
yoga:flex="1"
yoga:margin_start="8dp"
/>
</YogaLayout>
</YogaLayout>
```
Note that there are some caveats, such as requiring the custom `YogaLayoutViewFactory` in order to have tags `YogaLayout` instead of `com.facebook.samples.yoga.YogaLayout`.
To include this in your project, add to your build:
<script src="https://gist.github.com/rspencer01/499a9e02185985bf3167f818d9c3398f.js"></script>
```java
compile 'com.facebook.yoga.android:yoga-layout:1.2.0'
```
## layout\_width and layout\_height

View File

@@ -10,7 +10,12 @@ permalink: /docs/api/c/
The following functions control the lifecycle of a `YGNodeRef`.
<script src="https://gist.github.com/emilsjolander/99e454d04df4765147f407bde131feca.js"></script>
```c
YGNodeRef YGNodeNew();
void YGNodeReset(YGNodeRef node);
void YGNodeFree(YGNodeRef node);
void YGNodeFreeRecursive(YGNodeRef node);
```
- `YGNodeReset` will reset a node to its initial state so it can be re-used without needing to re-allocate a new node.
- `YGNodeFreeRecursive` is mostly used for testing and will free not only the node itself but also its children.
@@ -19,19 +24,167 @@ The following functions control the lifecycle of a `YGNodeRef`.
The following functions help manage the children of a node.
<script src="https://gist.github.com/emilsjolander/7e162314294087bb78817c064d345afb.js"></script>
```c
void YGNodeInsertChild(YGNodeRef node, YGNodeRef child, uint32_t index);
void YGNodeRemoveChild(YGNodeRef node, YGNodeRef child);
YGNodeRef YGNodeGetChild(YGNodeRef node, uint32_t index);
uint32_t YGNodeChildCount(YGNodeRef node);
```
### Style getters & setters
The large part of Yoga's API consists of setters and getters for styles. These all follow the same general structure. Bellow are the function and enums used to control the various styles. For an in depth guide to how each style works see the getting started guide.
<script src="https://gist.github.com/emilsjolander/74913a3326d952ff5a65dabe5ce4baf8.js"></script>
```c
typedef enum YGDirection {
YGDirectionInherit,
YGDirectionLTR,
YGDirectionRTL,
} YGDirection;
void YGNodeStyleSetDirection(YGNodeRef node, YGDirection direction);
YGDirection YGNodeStyleGetDirection(YGNodeRef node);
typedef enum YGFlexDirection {
YGFlexDirectionColumn,
YGFlexDirectionColumnReverse,
YGFlexDirectionRow,
YGFlexDirectionRowReverse,
} YGFlexDirection;
void YGNodeStyleSetFlexDirection(YGNodeRef node,
YGFlexDirection flexDirection);
YGFlexDirection YGNodeStyleGetFlexDirection(YGNodeRef node);
typedef enum YGJustify {
YGJustifyFlexStart,
YGJustifyCenter,
YGJustifyFlexEnd,
YGJustifySpaceBetween,
YGJustifySpaceAround,
} YGJustify;
void YGNodeStyleSetJustifyContent(YGNodeRef node,
YGJustify justifyContent);
YGJustify YGNodeStyleGetJustifyContent(YGNodeRef node);
typedef enum YGAlign {
YGAlignAuto,
YGAlignFlexStart,
YGAlignCenter,
YGAlignFlexEnd,
YGAlignStretch,
} YGAlign;
void YGNodeStyleSetAlignContent(YGNodeRef node, YGAlign alignContent);
YGAlign YGNodeStyleGetAlignContent(YGNodeRef node);
void YGNodeStyleSetAlignItems(YGNodeRef node, YGAlign alignItems);
YGAlign YGNodeStyleGetAlignItems(YGNodeRef node);
void YGNodeStyleSetAlignSelf(YGNodeRef node, YGAlign alignSelf);
YGAlign YGNodeStyleGetAlignSelf(YGNodeRef node);
typedef enum YGPositionType {
YGPositionTypeRelative,
YGPositionTypeAbsolute,
} YGPositionType;
void YGNodeStyleSetPositionType(YGNodeRef node,
YGPositionType positionType);
YGPositionType YGNodeStyleGetPositionType(YGNodeRef node);
typedef enum YGWrap {
YGWrapNoWrap,
YGWrapWrap,
} YGWrap;
void YGNodeStyleSetFlexWrap(YGNodeRef node, YGWrap flexWrap);
YGWrap YGNodeStyleGetFlexWrap(YGNodeRef node);
typedef enum YGOverflow {
YGOverflowVisible,
YGOverflowHidden,
YGOverflowScroll,
} YGOverflow;
void YGNodeStyleSetOverflow(YGNodeRef node, YGOverflow overflow);
YGOverflow YGNodeStyleGetOverflow(YGNodeRef node);
void YGNodeStyleSetFlex(YGNodeRef node, float flex);
void YGNodeStyleSetFlexGrow(YGNodeRef node, float flexGrow);
float YGNodeStyleGetFlexGrow(YGNodeRef node);
void YGNodeStyleSetFlexShrink(YGNodeRef node, float flexShrink);
float YGNodeStyleGetFlexShrink(YGNodeRef node);
void YGNodeStyleSetFlexBasis(YGNodeRef node, float flexBasis);
float YGNodeStyleGetFlexBasis(YGNodeRef node);
typedef enum YGEdge {
YGEdgeLeft,
YGEdgeTop,
YGEdgeRight,
YGEdgeBottom,
YGEdgeStart,
YGEdgeEnd,
YGEdgeHorizontal,
YGEdgeVertical,
YGEdgeAll,
} YGEdge;
void YGNodeStyleSetPosition(YGNodeRef node, YGEdge edge, float position);
float YGNodeStyleGetPosition(YGNodeRef node, YGEdge edge);
void YGNodeStyleSetMargin(YGNodeRef node, YGEdge edge, float margin);
float YGNodeStyleGetMargin(YGNodeRef node, YGEdge edge);
void YGNodeStyleSetPadding(YGNodeRef node, YGEdge edge, float padding);
float YGNodeStyleGetPadding(YGNodeRef node, YGEdge edge);
void YGNodeStyleSetBorder(YGNodeRef node, YGEdge edge, float border);
float YGNodeStyleGetBorder(YGNodeRef node, YGEdge edge);
void YGNodeStyleSetWidth(YGNodeRef node, float width);
float YGNodeStyleGetWidth(YGNodeRef node);
void YGNodeStyleSetHeight(YGNodeRef node, float height);
float YGNodeStyleGetHeight(YGNodeRef node);
void YGNodeStyleSetMinWidth(YGNodeRef node, float minWidth);
float YGNodeStyleGetMinWidth(YGNodeRef node);
void YGNodeStyleSetMinHeight(YGNodeRef node, float minHeight);
float YGNodeStyleGetMinHeight(YGNodeRef node);
void YGNodeStyleSetMaxWidth(YGNodeRef node, float maxWidth);
float YGNodeStyleGetMaxWidth(YGNodeRef node);
void YGNodeStyleSetMaxHeight(YGNodeRef node, float maxHeight);
float YGNodeStyleGetMaxHeight(YGNodeRef node);
void YGNodeStyleSetAspectRatio(YGNodeRef node, float aspectRatio);
float YGNodeStyleGetAspectRatio(YGNodeRef node);
```
### Layout results
Once you have set up a tree of nodes with styles you will want to get the result of a layout calculation. Call `YGNodeCalculateLayout` with the desired width and height or `YGUndefined` to perform the layout calculation. Once this function returns the results of the layout calculation is stored on each node. Traverse the tree and retrieve the values from each node.
<script src="https://gist.github.com/emilsjolander/7c7c9c61b69daff5b925719065fb0dc9.js"></script>
```c
void YGNodeCalculateLayout(YGNodeRef node,
float availableWidth,
float availableHeight,
YGDirection parentDirection);
float YGNodeLayoutGetLeft(YGNodeRef node);
float YGNodeLayoutGetTop(YGNodeRef node);
float YGNodeLayoutGetRight(YGNodeRef node);
float YGNodeLayoutGetBottom(YGNodeRef node);
float YGNodeLayoutGetWidth(YGNodeRef node);
float YGNodeLayoutGetHeight(YGNodeRef node);
YGDirection YGNodeLayoutGetDirection(YGNodeRef node);
```
### Custom measurements
@@ -41,34 +194,103 @@ Certain nodes need the ability to measure themselves, the most common example is
> A measure function can only be attached to a leaf node in the hierarchy.
<script src="https://gist.github.com/emilsjolander/73f9118d8bd27f9cb3744c08f1e53a32.js"></script>
```c
typedef enum YGMeasureMode {
YGMeasureModeUndefined,
YGMeasureModeExactly,
YGMeasureModeAtMost,
} YGMeasureMode;
typedef struct YGSize {
float width;
float height;
} YGSize;
typedef YGSize (*YGMeasureFunc)(YGNodeRef node,
float width,
YGMeasureMode widthMode,
float height,
YGMeasureMode heightMode);
void YGNodeSetMeasureFunc(YGNodeRef node, YGMeasureFunc measureFunc);
YGMeasureFunc YGNodeGetMeasureFunc(YGNodeRef node);
void YGNodeMarkDirty(YGNodeRef node);
bool YGNodeIsDirty(YGNodeRef node);
```
### Context
Context is important when integrating Yoga into another layout system. Context allows you to associate another object with a `YGNodeRef`. This context can then be retrieved from a `YGNodeRef` when for example its measure function is called. This is what enables Yoga to rely on the Android and iOS system implementations of text measurement in React Native.
<script src="https://gist.github.com/emilsjolander/c3d23a1b880d59627e959f3447a9511b.js"></script>
```c
void YGNodeSetContext(YGNodeRef node, void *context);
void *YGNodeGetContext(YGNodeRef node);
```
### Logging
Yoga will by default log to stdout and stderr. You may however customize this to instead log to your own logger.
<script src="https://gist.github.com/emilsjolander/b538718ffd7a55efc80845468e0f063e.js"></script>
```c
typedef enum YGLogLevel {
YGLogLevelError,
YGLogLevelWarn,
YGLogLevelInfo,
YGLogLevelDebug,
YGLogLevelVerbose,
} YGLogLevel;
typedef int (*YGLogger)(YGLogLevel level, char *format, va_list args);
void YGSetLogger(YGLogger logger);
void YGLog(YGLogLevel level, char *message, ...);
```
### Experiments
Yoga has the concept of experiments. An experiment is a feature which is not yet stable. To enable a feature use the following functions. Once a feature has been tested and is ready to be released as a stable API we will remove its feature flag.
<script src="https://gist.github.com/emilsjolander/002516a55e10947e4bdcf5484eee8745.js"></script>
```c
typedef enum YGExperimentalFeature {
// Current experiments
} YGExperimentalFeature;
void YGSetExperimentalFeatureEnabled(YGExperimentalFeature feature,
bool enabled);
bool YGIsExperimentalFeatureEnabled(YGExperimentalFeature feature);
```
### Custom allocators
You may want to swap out the allocator used in Yoga. These functions allow that.
<script src="https://gist.github.com/emilsjolander/f45053d4f09a9faaf94a8fc071f0224f.js"></script>
```c
typedef void *(*YGMalloc)(size_t size);
typedef void *(*YGCalloc)(size_t count, size_t size);
typedef void *(*YGRealloc)(void *ptr, size_t size);
typedef void (*YGFree)(void *ptr);
void YGSetMemoryFuncs(YGMalloc cssMalloc,
YGCalloc cssCalloc,
YGRealloc cssRealloc,
YGFree cssFree);
```
### Printing
Yoga has some hooks to print debug information while calculating layout. With the printing APIs you can add additional information to a node when it is printed.
<script src="https://gist.github.com/emilsjolander/c9fbaba914d699ecc91841f4f5515f20.js"></script>
```c
typedef enum YGPrintOptions {
YGPrintOptionsLayout = 1,
YGPrintOptionsStyle = 2,
YGPrintOptionsChildren = 4,
} YGPrintOptions;
typedef void (*YGPrintFunc)(YGNodeRef node);
void YGNodeSetPrintFunc(YGNodeRef node, YGPrintFunc printFunc);
YGPrintFunc YGNodeGetPrintFunc(YGNodeRef node);
void YGNodePrint(YGNodeRef node, YGPrintOptions options);
```

View File

@@ -10,25 +10,176 @@ permalink: /docs/api/csharp/
Create a `YogaNode` via its default constructor or the static `Create()` builder method and use `Reset` if you want to pool and re-use nodes. The native memory of a `YogaNode` will automatically be freed when the node is garbage collected.
<script src="https://gist.github.com/emilsjolander/ce73212ee5fdb543d463822c3dd172b4.js"></script>
```csharp
YogaNode();
void Reset();
static YogaNode Create(
YogaDirection? styleDirection = null,
YogaFlexDirection? flexDirection = null,
YogaJustify? justifyContent = null,
YogaAlign? alignContent = null,
YogaAlign? alignItems = null,
YogaAlign? alignSelf = null,
YogaPositionType? positionType = null,
YogaWrap? wrap = null,
YogaOverflow? overflow = null,
float? flex = null,
float? flexGrow = null,
float? flexShrink = null,
float? flexBasis = null,
Spacing position = null,
Spacing margin = null,
Spacing padding = null,
Spacing border = null,
float? Width = null,
float? Height = null,
float? MaxWidth = null,
float? MaxHeight = null,
float? MinWidth = null,
float? MinHeight = null);
```
### Children
The following methods help manage the children of a node.
<script src="https://gist.github.com/emilsjolander/2b0ea738d3c24644fa98910b276620e4.js"></script>
```csharp
int Count { get };
YogaNode this[int index] { get };
void Insert(int index, YogaNode node);
void RemoveAt(int index);
void Clear();
int IndexOf(YogaNode node);
```
### Style getters & setters
The large part of Yoga's API consists of properties, setters, and getters for styles. These all follow the same general structure. Bellow are the function and enums used to control the various styles. For an in depth guide to how each style works see the getting started guide.
<script src="https://gist.github.com/emilsjolander/a84208768e0006b8421a322c40f98539.js"></script>
```csharp
enum YogaDirection
{
Inherit,
LTR,
RTL,
}
YogaDirection StyleDirection {get, set};
enum YogaFlexDirection
{
Column,
ColumnReverse,
Row,
RowReverse,
}
YogaFlexDirection FlexDirection {get, set};
enum YogaJustify
{
FlexStart,
Center,
FlexEnd,
SpaceBetween,
SpaceAround,
}
YogaJustify JustifyContent {get, set};
enum YogaAlign
{
Auto,
FlexStart,
Center,
FlexEnd,
Stretch,
}
YogaAlign AlignItems {get, set};
YogaAlign AlignSelf {get, set};
YogaAlign AlignContent {get, set};
enum YogaPositionType
{
Relative,
Absolute,
}
YogaPositionType PositionType {get, set};
enum YogaWrap
{
NoWrap,
Wrap,
}
YogaWrap Wrap {get, set};
enum YogaOverflow
{
Visible,
Hidden,
Scroll,
}
YogaOverflow Overflow {get, set};
float Flex {set};
float FlexGrow {get, set};
float FlexShrink {get, set};
float FlexBasis {get, set};
enum YogaEdge
{
Left,
Top,
Right,
Bottom,
Start,
End,
Horizontal,
Vertical,
All,
}
float GetMargin(YogaEdge edge);
void SetMargin(YogaEdge edge, float margin);
float GetPadding(YogaEdge edge);
void SetPadding(YogaEdge edge, float padding);
float GetBorder(YogaEdge edge);
void SetBorder(YogaEdge edge, float border);
float GetPosition(YogaEdge edge);
void SetPosition(YogaEdge edge, float position);
float Width {get, set};
float Height {get, set};
float MaxWidth {get, set};
float MinWidth {get, set};
float MaxHeight {get, set};
float MinHeight {get, set};
float AspectRatio {get, set};
```
### Layout results
Once you have set up a tree of nodes with styles you will want to get the result of a layout calculation. Call `CalculateLayout()` perform layout calculation. Once this function returns the results of the layout calculation is stored on each node. Traverse the tree and retrieve the values from each node.
<script src="https://gist.github.com/emilsjolander/b50acf9fc0877affeb0fc3e55b5c6b4c.js"></script>
```csharp
void CalculateLayout();
float LayoutX {get};
float LayoutY {get};
float LayoutWidth {get};
float LayoutHeight {get};
YogaDirection LayoutDirection {get};
```
### Custom measurements
@@ -38,16 +189,53 @@ Certain nodes need to ability to measure themselves, the most common example is
> A measure function can only be attached to a leaf node in the hierarchy.
<script src="https://gist.github.com/emilsjolander/57178307f515e5ea1ccfbedc05df429b.js"></script>
```csharp
enum YogaMeasureMode
{
Undefined,
Exactly,
AtMost,
}
public delegate long MeasureFunction(
YogaNode node,
float width,
YogaMeasureMode widthMode,
float height,
YogaMeasureMode heightMode);
class MeasureOutput
{
public static long Make(int width, int height);
}
void SetMeasureFunction(MeasureFunction measureFunction);
bool IsMeasureDefined();
bool IsDirty {get};
void MarkDirty();
```
### Data
Data is important when integrating Yoga into another layout system. Data allows you to associate another object with a `YogaNode`. This data can then be retrieved from a `YogaNode` when for example its measure function is called. This is what enables Yoga to rely on the Android system implementations of text measurement in React Native.
<script src="https://gist.github.com/emilsjolander/c099f826623d70fd6bf7dece14e76700.js"></script>
```csharp
object Data {get, set}
```
### Experiments
Yoga has the concept of experiments. An experiment is a feature which is not yet stable. To enable a feature use the following functions. Once a feature has been tested and is ready to be released as a stable API we will remove its feature flag.
<script src="https://gist.github.com/emilsjolander/97b2500918687826cdfe9429638f2d57.js"></script>
```csharp
enum YogaExperimentalFeature {
// Current experiments
}
static void setExperimentalFeatureEnabled(
YogaExperimentalFeature feature,
boolean enabled);
static boolean isExperimentalFeatureEnabled(
YogaExperimentalFeature feature);
```

View File

@@ -10,25 +10,166 @@ permalink: /docs/api/java/
Create a `YogaNode` via its default constructor and use `reset` if you want to pool and re-use nodes. The native memory of a `YogaNode` will automatically be freed when the node is garbage collected.
<script src="https://gist.github.com/emilsjolander/8775de8c778eb99a05a38e8257f0b4a7.js"></script>
```java
YogaNode();
void reset();
```
### Children
The following methods help manage the children of a node.
<script src="https://gist.github.com/emilsjolander/5d1c64d8d3be7f7942435c4f5bec45a5.js"></script>
```java
int getChildCount();
YogaNodeType getChildAt(int i);
void addChildAt(YogaNodeType child, int i);
YogaNodeType removeChildAt(int i);
YogaNodeType getParent();
int indexOf(YogaNodeType child);
```
### Style getters & setters
The large part of Yoga's API consists of setters and getters for styles. These all follow the same general structure. Bellow are the function and enums used to control the various styles. For an in depth guide to how each style works see the getting started guide.
<script src="https://gist.github.com/emilsjolander/f94ca2aa69441a3060a7c9f5126f202f.js"></script>
```java
enum YogaDirection {
INHERIT,
LTR,
RTL
}
YogaDirection getStyleDirection();
void setDirection(YogaDirection direction);
enum YogaFlexDirection {
COLUMN,
COLUMN_REVERSE,
ROW,
ROW_REVERSE
}
YogaFlexDirection getFlexDirection();
void setFlexDirection(YogaFlexDirection flexDirection);
enum YogaJustify {
FLEX_START,
CENTER,
FLEX_END,
SPACE_BETWEEN,
SPACE_AROUND
}
YogaJustify getJustifyContent();
void setJustifyContent(YogaJustify justifyContent);
enum YogaAlign {
AUTO,
FLEX_START,
CENTER,
FLEX_END,
STRETCH
}
YogaAlign getAlignItems();
void setAlignItems(YogaAlign alignItems);
YogaAlign getAlignSelf();
void setAlignSelf(YogaAlign alignSelf);
YogaAlign getAlignContent();
void setAlignContent(YogaAlign alignContent);
enum YogaPositionType {
RELATIVE,
ABSOLUTE
}
YogaPositionType getPositionType();
void setPositionType(YogaPositionType positionType);
enum YogaWrap {
NO_WRAP,
WRAP
}
void setWrap(YogaWrap flexWrap);
enum YogaOverflow {
VISIBLE,
HIDDEN,
SCROLL
}
YogaOverflow getOverflow();
void setOverflow(YogaOverflow overflow);
void setFlex(float flex);
float getFlexGrow();
void setFlexGrow(float flexGrow);
float getFlexShrink();
void setFlexShrink(float flexShrink);
float getFlexBasis();
void setFlexBasis(float flexBasis);
enum YogaEdge {
LEFT,
TOP,
RIGHT,
BOTTOM,
START,
END,
HORIZONTAL,
VERTICAL,
ALL
}
float getMargin(YogaEdge edge);
void setMargin(YogaEdge edge, float margin);
float getPadding(YogaEdge edge);
void setPadding(YogaEdge edge, float padding);
float getBorder(YogaEdge edge);
void setBorder(YogaEdge edge, float border);
float getPosition(YogaEdge edge);
void setPosition(YogaEdge edge, float position);
float getWidth();
void setWidth(float width);
float getHeight();
void setHeight(float height);
float getMaxWidth();
void setMaxWidth(float maxWidth);
float getMinWidth();
void setMinWidth(float minWidth);
float getMaxHeight();
void setMaxHeight(float maxHeight);
float getMinHeight();
void setMinHeight(float minHeight);
float getAspectRatio();
void setAspectRatio(float aspectRatio);
```
### Layout results
Once you have set up a tree of nodes with styles you will want to get the result of a layout calculation. Call `calculateLayout()` perform layout calculation. Once this function returns the results of the layout calculation is stored on each node. Traverse the tree and retrieve the values from each node.
<script src="https://gist.github.com/emilsjolander/613a80ae11abce423a4806521e1e315b.js"></script>
```java
void calculateLayout();
float getLayoutX();
float getLayoutY();
float getLayoutWidth();
float getLayoutHeight();
YogaDirection getLayoutDirection();
```
### Custom measurements
@@ -38,22 +179,74 @@ Certain nodes need to ability to measure themselves, the most common example is
> A measure function can only be attached to a leaf node in the hierarchy.
<script src="https://gist.github.com/emilsjolander/70fd958b87647abbba604956709a9026.js"></script>
```java
enum YogaMeasureMode {
UNDEFINED,
EXACTLY,
AT_MOST
}
interface YogaMeasureFunction {
long measure(
YogaNodeAPI node,
float width,
YogaMeasureMode widthMode,
float height,
YogaMeasureMode heightMode);
}
class YogaMeasureOutput {
static long make(int width, int height);
}
void setMeasureFunction(YogaMeasureFunction measureFunction);
boolean isMeasureDefined();
boolean isDirty();
void dirty();
```
### Data
Data is important when integrating Yoga into another layout system. Data allows you to associate another object with a `YogaNode`. This data can then be retrieved from a `YogaNode` when for example its measure function is called. This is what enables Yoga to rely on the Android system implementations of text measurement in React Native.
<script src="https://gist.github.com/emilsjolander/3f10f3fa91120960b71783780f528973.js"></script>
```java
void setData(Object data);
Object getData();
```
### Logging
Yoga will by default log to stdout and stderr (or logcat on Android). You may however customize this to instead log to your own logger.
<script src="https://gist.github.com/emilsjolander/6d012f5d48be0e98b7f9c2225c358f6e.js"></script>
```java
enum YogaLogLevel {
ERROR,
WARN,
INFO,
DEBUG,
VERBOSE
}
interface YogaLogger {
void log(YogaLogLevel level, String message);
}
void setLogger(YogaLogger logger);
```
### Experiments
Yoga has the concept of experiments. An experiment is a feature which is not yet stable. To enable a feature use the following functions. Once a feature has been tested and is ready to be released as a stable API we will remove its feature flag.
<script src="https://gist.github.com/emilsjolander/97b2500918687826cdfe9429638f2d57.js"></script>
```java
enum YogaExperimentalFeature {
// Current experiments
}
static void setExperimentalFeatureEnabled(
YogaExperimentalFeature feature,
boolean enabled);
static boolean isExperimentalFeatureEnabled(
YogaExperimentalFeature feature);
```

View File

@@ -19,13 +19,22 @@ For now we recommend including Yoga as a [git submodule](https://git-scm.com/doc
Yoga ships with an [iOS example](https://github.com/facebook/yoga/tree/master/YogaKit/YogaKitSample). To get it running:
<script src="https://gist.github.com/emilsjolander/903b16185b24c957acc4cd250c6e73d9.js"></script>
```sh
$ git clone https://github.com/facebook/yoga.git
$ cd open yoga/YogaKit/YogaKitSample/
$ pod install
$ open YogaKitSample.xcworkspace
```
#### Android
Yoga ships with an [Android example too](https://github.com/facebook/yoga/tree/master/android/sample). To get it running on an attached device (or emulator):
<script src="https://gist.github.com/rspencer01/a512f7cd24055c948675be15d48eba78.js"></script>
```sh
$ git clone https://github.com/facebook/yoga.git
$ cd yoga
$ buck install -r android/sample
```
Actually, this is more than just an example, and more a layout system for Android using Yoga in general (see `YogaLayout`). For more information see the [Android API section](/yoga/docs/api/android).
@@ -35,4 +44,15 @@ Yoga uses [Buck](https://buckbuild.com/) as its build system. Buck is not requir
If you are using Buck all you need to do is reference the language bindings you want to use in your `BUCK` file.
<script src="https://gist.github.com/emilsjolander/895b4ec79425882b8d4676b6545d6943.js"></script>
```sh
deps = [
# C
'//path/to/submodule/yoga:yoga',
# Java
'//path/to/submodule/yoga/java:jni',
# Objective-C
'//path/to/submodule/yoga/YogaKit:YogaKit',
]
```

View File

@@ -15,7 +15,23 @@ Yoga aims to be compatible with Flexbox according to the [w3 specification](http
Yoga has chosen to change the default values of some properties to better fit mobile layout use cases. The following CSS block describes the differences in default values from the [Flexbox w3 specification](https://www.w3.org/TR/css3-flexbox).
<script src="https://gist.github.com/emilsjolander/f9b3981cab44c51afa9ac446b8fdb60c.js"></script>
```css
div {
box-sizing: border-box;
position: relative;
display: flex;
flex-direction: column;
align-items: stretch;
flex-shrink: 0;
align-content: flex-start;
border-width: 0px;
margin: 0px;
padding: 0px;
min-width: 0px;
}
```
We have set up a [JSFiddle](https://jsfiddle.net/emilsjolander/jckmwztt/) so you can see these default values in action.

View File

@@ -1,15 +1,15 @@
.rougeHighlight { background-color: $code-bg; color: #93a1a1 }
.rougeHighlight { background-color: $code-bg; color: #000 }
.rougeHighlight .c { color: #586e75 } /* Comment */
.rougeHighlight .err { color: #93a1a1 } /* Error */
.rougeHighlight .g { color: #93a1a1 } /* Generic */
.rougeHighlight .k { color: #859900 } /* Keyword */
.rougeHighlight .l { color: #93a1a1 } /* Literal */
.rougeHighlight .n { color: #93a1a1 } /* Name */
.rougeHighlight .n { color: #795da3 } /* Name */
.rougeHighlight .o { color: #859900 } /* Operator */
.rougeHighlight .x { color: #cb4b16 } /* Other */
.rougeHighlight .p { color: #93a1a1 } /* Punctuation */
.rougeHighlight .p { color: #000000 } /* Punctuation */
.rougeHighlight .cm { color: #586e75 } /* Comment.Multiline */
.rougeHighlight .cp { color: #859900 } /* Comment.Preproc */
.rougeHighlight .c1 { color: #72c02c; } /* Comment.Single */
@@ -20,7 +20,7 @@
.rougeHighlight .gh { color: #cb4b16 } /* Generic.Heading */
.rougeHighlight .gi { color: #859900 } /* Generic.Inserted */
.rougeHighlight .go { color: #93a1a1 } /* Generic.Output */
.rougeHighlight .gp { color: #93a1a1 } /* Generic.Prompt */
.rougeHighlight .gp { color: #000000 } /* Generic.Prompt */
.rougeHighlight .gs { color: #93a1a1; font-weight: bold } /* Generic.Strong */
.rougeHighlight .gu { color: #cb4b16 } /* Generic.Subheading */
.rougeHighlight .gt { color: #93a1a1 } /* Generic.Traceback */
@@ -41,11 +41,11 @@
.rougeHighlight .ni { color: #cb4b16 } /* Name.Entity */
.rougeHighlight .ne { color: #cb4b16 } /* Name.Exception */
.rougeHighlight .nf { color: #268bd2 } /* Name.Function */
.rougeHighlight .nl { color: #93a1a1 } /* Name.Label */
.rougeHighlight .nl { color: #0086b3 } /* Name.Label */
.rougeHighlight .nn { color: #93a1a1 } /* Name.Namespace */
.rougeHighlight .nx { color: #93a1a1 } /* Name.Other */
.rougeHighlight .py { color: #93a1a1 } /* Name.Property */
.rougeHighlight .nt { color: #268bd2 } /* Name.Tag */
.rougeHighlight .nt { color: #63a35c } /* Name.Tag */
.rougeHighlight .nv { color: #268bd2 } /* Name.Variable */
.rougeHighlight .ow { color: #859900 } /* Operator.Word */
.rougeHighlight .w { color: #93a1a1 } /* Text.Whitespace */
@@ -72,11 +72,12 @@
.highlighter-rouge {
color: darken(#72c02c, 8%);
font: 800 12px/1.5em Hack, monospace;
font: 500 12px/1.8em "SFMono-Regular", Consolas, "Liberation Mono", Menlo, Courier, monospace;
max-width: 100%;
.rougeHighlight {
border-radius: 3px;
border: 1px solid #ccc;
margin: 20px 0;
padding: 0px;
overflow-x: scroll;
@@ -97,8 +98,9 @@
flex: 1 1;
&.gutter {
border-right: 1px solid lighten($code-bg, 10%);
color: lighten($code-bg, 15%);
border-right: 1px solid darken($code-bg, 10%);
color: darken($code-bg, 25%);
margin-left: 10px;
margin-right: 10px;
max-width: 40px;
padding-right: 10px;

View File

@@ -86,7 +86,7 @@ $sidenav-overlay: lighten($sidenav, 10%);
$sidenav-active: darken($sidenav, 10%);
{% endif %}
$code-bg: #002b36;
$code-bg: #ffffff;
$header-height: 34px;

View File

@@ -13,8 +13,28 @@ id: home
<div class="yoga" style="background-color: #303846; flex-grow: 1; height: 25px; align-self: center;"></div>
</div>
</div>
<div class="blockContent gistsample">
<script src="https://gist.github.com/emilsjolander/40685eadad702e0227374f3e33daaa12.js"></script>
<div class="blockContent">
<div markdown="1" style="width: 700px; max-width: 100%;">
```c
YGNodeRef root = YGNodeNew();
YGNodeStyleSetWidth(root, 500);
YGNodeStyleSetHeight(root, 120);
YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
YGNodeStyleSetPadding(root, YGEdgeAll, 20);
YGNodeRef image = YGNodeNew();
YGNodeStyleSetWidth(image, 80);
YGNodeStyleSetMargin(image, YGEdgeEnd, 20);
YGNodeRef text = YGNodeNew();
YGNodeStyleSetHeight(text, 25);
YGNodeStyleSetAlignSelf(text, YGAlignCenter);
YGNodeStyleSetFlexGrow(text, 1);
YGNodeInsertChild(root, image, 0);
YGNodeInsertChild(root, text, 1);
```
</div>
</div>
</div>
</div>
@@ -28,8 +48,28 @@ id: home
<div class="yoga" style="background-color: #303846; height: 25px; width: 100px;"></div>
</div>
</div>
<div class="blockContent gistsample">
<script src="https://gist.github.com/dshahidehpour/a426c443a1e02c5432b22b09c457ede0.js"></script>
<div class="blockContent">
<div markdown="1" style="width: 700px; max-width: 100%;">
```objc
UIView *root = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 300)];
[root configureLayoutWithBlock:^void(YGLayout *layout) {
layout.isEnabled = YES;
layout.alignItems = YGAlignCenter;
layout.justifyContent = YGJustifyContentCenter;
layout.padding = 20.0f;
}];
UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 150, 150)];
[image configureLayoutWithBlock:^void(YGLayout *layout) {
layout.isEnabled = YES;
layout.marginBottom = 20.0f;
}];
[root addSubview:image];
UILabel *text = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 25, 100)];
[root addSubview:text];
```
</div>
</div>
</div>
</div>
@@ -43,8 +83,31 @@ id: home
<div class="yoga" style="background-color: #97dccf; width: 50px; height: 50px; position: absolute; right: 20px; top: 20px;"></div>
</div>
</div>
<div class="blockContent gistsample">
<script src="https://gist.github.com/emilsjolander/f7b9b5dc2b97577bab2f1e6e1bf80b62.js"></script>
<div class="blockContent">
<div markdown="1" style="width: 700px; max-width: 100%;">
```java
YogaNode root = new YogaNode();
root.setWidth(500);
root.setHeight(300);
root.setAlignItems(CENTER);
root.setJustifyContent(CENTER);
root.setPadding(ALL, 20);
YogaNode text = new YogaNode();
text.setWidth(200);
text.setHeight(25);
YogaNode image = new YogaNode();
image.setWidth(50);
image.setHeight(50);
image.setPositionType(ABSOLUTE);
image.setPosition(END, 20);
image.setPosition(TOP, 20);
root.addChildAt(text, 0);
root.addChildAt(image, 1);
```
</div>
</div>
</div>
</div>
@@ -58,8 +121,26 @@ id: home
<div class="yoga" style="background-color: #303846; margin: 20px; height: 25px; width: 300px;"></div>
</div>
</div>
<div class="blockContent gistsample">
<script src="https://gist.github.com/emilsjolander/29b91608b66d56d3df81f53101ad9d8b.js"></script>
<div class="blockContent">
<div markdown="1" style="width: 700px; max-width: 100%;">
```csharp
YogaNode root = YogaNode.Create(
width: 500,
height: 300,
);
YogaNode image = YogaNode.Create(flexGrow: 1);
YogaNode text = YogaNode.Create(
width: 300,
height: 25,
margin: new Spacing(left: 20, top: 20, right: 20, bottom: 20),
);
root.Insert(image, 0);
root.Insert(text, 1);
```
</div>
</div>
</div>
</div>
@@ -76,8 +157,35 @@ id: home
</div>
</div>
</div>
<div class="blockContent gistsample">
<script src="https://gist.github.com/rspencer01/0b3e467a58ab56a23f60579ea193189f.js"></script>
<div class="blockContent">
<div markdown="1" style="width: 700px; max-width: 100%;">
```xml
<YogaLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
yoga:justify_content="stretch">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
yoga:flex="1"/>
<VirtualYogaLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
yoga:padding_all="20px"
yoga:flex_direction="row"
yoga:align_items="center">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
yoga:flex="1"
yoga:margin_start="20px"/>
</VirtualYogaLayout>
</YogaLayout>
```
</div>
</div>
</div>
</div>

View File

@@ -125,6 +125,16 @@ def to_java_upper(symbol):
out += c.upper()
return out
def to_log_lower(symbol):
symbol = str(symbol)
out = ''
for i in range(0, len(symbol)):
c = symbol[i]
if str.istitle(c) and i is not 0 and not str.istitle(symbol[i - 1]):
out += '-'
out += c.lower()
return out
root = os.path.dirname(os.path.abspath(__file__))
@@ -143,9 +153,28 @@ with open(root + '/yoga/YGEnums.h', 'w') as f:
else:
f.write(' YG%s%s,\n' % (name, value))
f.write('} YG_ENUM_END(YG%s);\n' % name)
f.write('WIN_EXPORT const char *YG%sToString(const YG%s value);\n' % (name, name))
f.write('\n')
f.write('YG_EXTERN_C_END\n')
# write out C body for printing
with open(root + '/yoga/YGEnums.c', 'w') as f:
f.write(LICENSE)
f.write('#include "YGEnums.h"\n\n')
for name, values in sorted(ENUMS.items()):
f.write('const char *YG%sToString(const YG%s value){\n' % (name, name))
f.write(' switch(value){\n')
for value in values:
if isinstance(value, tuple):
f.write(' case YG%s%s:\n' % (name, value[0]))
f.write(' return "%s";\n' % to_log_lower(value[0]))
else:
f.write(' case YG%s%s:\n' % (name, value))
f.write(' return "%s";\n' % to_log_lower(value))
f.write(' }\n')
f.write(' return "unknown";\n')
f.write('}\n\n')
# write out java files
for name, values in sorted(ENUMS.items()):
with open(root + '/java/com/facebook/yoga/Yoga%s.java' % name, 'w') as f:

View File

@@ -26,37 +26,40 @@
</div>
<div id="absolute_layout_align_items_and_justify_content_center" style="height: 100px; width: 110px; flex-grow: 1; align-items: center; justify-content: center;">
<div style="position: absolute; width: 60px; height: 40px;"></div>
<div style="position: absolute; width: 60px; height: 40px;"></div>
</div>
<div id="absolute_layout_align_items_and_justify_content_flex_end" style="height: 100px; width: 110px; flex-grow: 1; align-items: flex-end; justify-content: flex-end;">
<div style="position: absolute; width: 60px; height: 40px;"></div>
<div style="position: absolute; width: 60px; height: 40px;"></div>
</div>
<div id="absolute_layout_justify_content_center" style="height: 100px; width: 110px; flex-grow: 1; justify-content: center;">
<div style="position: absolute; width: 60px; height: 40px;"></div>
<div style="position: absolute; width: 60px; height: 40px;"></div>
</div>
<div id="absolute_layout_align_items_center" style="height: 100px; width: 110px; flex-grow: 1; align-items: center;">
<div style="position: absolute; width: 60px; height: 40px;"></div>
<div style="position: absolute; width: 60px; height: 40px;"></div>
</div>
<div id="absolute_layout_align_items_center_on_child_only" style="height: 100px; width: 110px; flex-grow: 1;">
<div style="position: absolute; width: 60px; height: 40px;align-self: center;"></div>
<div style="position: absolute; width: 60px; height: 40px;align-self: center;"></div>
</div>
<div id="absolute_layout_align_items_and_justify_content_center_and_top_position" style="height: 100px; width: 110px; flex-grow: 1; align-items: center; justify-content: center;">
<div style="position: absolute; width: 60px; height: 40px;top:10px;"></div>
<div style="position: absolute; width: 60px; height: 40px;top:10px;"></div>
</div>
<div id="absolute_layout_align_items_and_justify_content_center_and_bottom_position" style="height: 100px; width: 110px; flex-grow: 1; align-items: center; justify-content: center;">
<div style="position: absolute; width: 60px; height: 40px;bottom:10px;"></div>
<div style="position: absolute; width: 60px; height: 40px;bottom:10px;"></div>
</div>
<div id="absolute_layout_align_items_and_justify_content_center_and_left_position" style="height: 100px; width: 110px; flex-grow: 1; align-items: center; justify-content: center;">
<div style="position: absolute; width: 60px; height: 40px;left:5px;"></div>
<div style="position: absolute; width: 60px; height: 40px;left:5px;"></div>
</div>
<div id="absolute_layout_align_items_and_justify_content_center_and_right_position" style="height: 100px; width: 110px; flex-grow: 1; align-items: center; justify-content: center;">
<div style="position: absolute; width: 60px; height: 40px;right:5px;"></div>
<div style="position: absolute; width: 60px; height: 40px;right:5px;"></div>
</div>
<div id="position_root_with_rtl_should_position_withoutdirection" style="height: 52px; width: 52px; left: 72px; ">
</div>

View File

@@ -133,8 +133,6 @@
<div style="width: 50px; height: 20px;flex-direction:column;"></div>
</div>
<div id="align_baseline_multiline_row_and_column" style="width: 100px; height: 100px; flex-direction:row; align-items: baseline;flex-wrap:wrap;">
<div style="width: 50px; height: 50px;"></div>
<div style="width: 50px; height: 50px;flex-direction:column;">
@@ -145,3 +143,27 @@
</div>
<div style="width: 50px; height: 20px;"></div>
</div>
<div id="align_items_center_child_with_margin_bigger_than_parent" style="height: 52px; width: 52px; align-items: center; justify-content: center;">
<div style="align-items: center;">
<div style="width: 52px; height: 52px; margin-left: 10px; margin-right: 10px;"></div>
</div>
</div>
<div id="align_items_flex_end_child_with_margin_bigger_than_parent" style="height: 52px; width: 52px; align-items: center; justify-content: center;">
<div style="align-items: flex-end;">
<div style="width: 52px; height: 52px; margin-left: 10px; margin-right: 10px;"></div>
</div>
</div>
<div id="align_items_center_child_without_margin_bigger_than_parent" style="height: 52px; width: 52px; align-items: center; justify-content: center;">
<div style="align-items: center;">
<div style="width: 72px; height: 72px;"></div>
</div>
</div>
<div id="align_items_flex_end_child_without_margin_bigger_than_parent" style="height: 52px; width: 52px; align-items: center; justify-content: center;">
<div style="align-items: flex-end;">
<div style="width: 72px; height: 72px;"></div>
</div>
</div>

View File

@@ -116,3 +116,27 @@
<div style="width: 50px; height: 50px; margin-top:auto; margin-bottom:auto;"></div>
<div style="width: 50px; height: 50px;"></div>
</div>
<div id="margin_should_not_be_part_of_max_height" style="width: 250px; height: 250px;">
<div style="width: 100px; height: 100px; max-height: 100px; margin-top: 20px;"></div>
</div>
<div id="margin_should_not_be_part_of_max_width" style="width: 250px; height: 250px;">
<div style="width: 100px; height: 100px; max-width: 100px; margin-left: 20px;"></div>
</div>
<div id="margin_auto_left_right_child_bigger_than_parent" style="height: 52px; width: 52px; justify-content: center;">
<div style="width: 72px; height: 72px; margin-left: auto; margin-right:auto;"></div>
</div>
<div id="margin_auto_left_child_bigger_than_parent" style="height: 52px; width: 52px; justify-content: center;">
<div style="width: 72px; height: 72px; margin-left: auto;"></div>
</div>
<div id="margin_fix_left_auto_right_child_bigger_than_parent" style="height: 52px; width: 52px; justify-content: center;">
<div style="width: 72px; height: 72px; margin-left: 10px; margin-right: auto;"></div>
</div>
<div id="margin_auto_left_fix_right_child_bigger_than_parent" style="height: 52px; width: 52px; justify-content: center;">
<div style="width: 72px; height: 72px; margin-left: auto; margin-right: 10px;"></div>
</div>

View File

@@ -100,3 +100,10 @@
</div>
</div>
</div>
<div id="percent_absolute_position" style="width: 60px; height: 50px;">
<div style="height: 50px; width: 100%; left: 50%; position: absolute; flex-direction: row;">
<div style="width: 100%;"></div>
<div style="width: 100%;"></div>
</div>
</div>

View File

@@ -183,7 +183,7 @@ JavaEmitter.prototype = Object.create(Emitter.prototype, {
}},
YGNodeStyleSetDisplay:{value:function(nodeName, value) {
this.push(nodeName + '.setDisplay(' + toValueJavascript(value) + ');');
this.push(nodeName + '.setDisplay(' + toValueJava(value) + ');');
}},
YGNodeStyleSetFlexBasis:{value:function(nodeName, value) {

View File

@@ -43,10 +43,12 @@ JavascriptEmitter.prototype = Object.create(Emitter.prototype, {
emitTestPrologue:{value:function(name, experiments) {
this.push('it(' + JSON.stringify(name) + ', function () {');
this.pushIndent();
this.push('var config = Yoga.Config.create();');
this.push('');
if (experiments.length > 0) {
for (var i in experiments) {
this.push('Yoga.setExperimentalFeatureEnabled(Yoga.EXPERIMENTAL_FEATURE_' + toJavascriptUpper(experiments[i]) + ', true);');
this.push('config.setExperimentalFeatureEnabled(Yoga.EXPERIMENTAL_FEATURE_' + toJavascriptUpper(experiments[i]) + ', true);');
}
this.push('');
}
@@ -69,13 +71,8 @@ JavascriptEmitter.prototype = Object.create(Emitter.prototype, {
this.push('root.freeRecursive();');
this.popIndent();
this.push('}');
if (experiments.length > 0) {
this.push('');
for (var i in experiments) {
this.push('Yoga.setExperimentalFeatureEnabled(Yoga.EXPERIMENTAL_FEATURE_' + toJavascriptUpper(experiments[i]) + ', false);');
}
}
this.push('');
this.push('config.free();');
this.popIndent();
this.push('}');

View File

@@ -48,6 +48,8 @@ Dir['fixtures/*.html'].each do |file|
f.write eval(logs[2].message.sub(/^[^"]*/, '')).sub('YogaTest', name)
f.close
print logs[4]
f = File.open("../javascript/tests/Facebook.Yoga/#{name}.js", 'w')
f.write eval(logs[3].message.sub(/^[^"]*/, '')).sub('YogaTest', name)
f.close

View File

@@ -6,7 +6,7 @@ apply plugin: 'maven-publish'
targetCompatibility = '1.7'
sourceCompatibility = '1.7'
version = '1.2.0'
version = '1.3.1'
group = 'com.facebook.yoga'
// We currently build the native libraries with buck and bundle them together
@@ -44,6 +44,7 @@ preBuild.dependsOn buckBuildAndCopy
dependencies {
compile(name: 'jsr305')
compile(name: 'soloader-0.1.0', ext: 'aar')
provided(project(':yoga:proguard-annotations'))
}
task sourcesJar(type: Jar) {

View File

@@ -46,4 +46,9 @@ public class YogaConfig {
public void setExperimentalFeatureEnabled(YogaExperimentalFeature feature, boolean enabled) {
jni_YGConfigSetExperimentalFeatureEnabled(mNativePointer, feature.intValue(), enabled);
}
private native void jni_YGConfigSetUseWebDefaults(long nativePointer, boolean useWebDefaults);
public void setUseWebDefaults(boolean useWebDefaults) {
jni_YGConfigSetUseWebDefaults(mNativePointer, useWebDefaults);
}
}

View File

@@ -42,9 +42,14 @@ public class YogaNode implements YogaNodeAPI<YogaNode> {
private long mNativePointer;
private Object mData;
private boolean mHasSetPadding = false;
private boolean mHasSetMargin = false;
private boolean mHasSetBorder = false;
/* Those flags needs be in sync with YGJNI.cpp */
private final static int MARGIN = 1;
private final static int PADDING = 2;
private final static int BORDER = 4;
@DoNotStrip
private int mEdgeSetFlag = 0;
private boolean mHasSetPosition = false;
@DoNotStrip
@@ -81,6 +86,8 @@ public class YogaNode implements YogaNodeAPI<YogaNode> {
private float mBorderBottom = 0;
@DoNotStrip
private int mLayoutDirection = 0;
@DoNotStrip
private boolean mHasNewLayout = true;
private native long jni_YGNodeNew();
public YogaNode() {
@@ -111,15 +118,26 @@ public class YogaNode implements YogaNodeAPI<YogaNode> {
private native void jni_YGNodeReset(long nativePointer);
@Override
public void reset() {
mHasSetPadding = false;
mHasSetMargin = false;
mHasSetBorder = false;
mEdgeSetFlag = 0;
mHasSetPosition = false;
mHasNewLayout = true;
mWidth = YogaConstants.UNDEFINED;
mHeight = YogaConstants.UNDEFINED;
mTop = YogaConstants.UNDEFINED;
mLeft = YogaConstants.UNDEFINED;
mMarginLeft = 0;
mMarginTop = 0;
mMarginRight = 0;
mMarginBottom = 0;
mPaddingLeft = 0;
mPaddingTop = 0;
mPaddingRight = 0;
mPaddingBottom = 0;
mBorderLeft = 0;
mBorderTop = 0;
mBorderRight = 0;
mBorderBottom = 0;
mLayoutDirection = 0;
mMeasureFunction = null;
@@ -180,10 +198,9 @@ public class YogaNode implements YogaNodeAPI<YogaNode> {
jni_YGNodeCalculateLayout(mNativePointer, width, height);
}
private native boolean jni_YGNodeHasNewLayout(long nativePointer);
@Override
public boolean hasNewLayout() {
return jni_YGNodeHasNewLayout(mNativePointer);
return mHasNewLayout;
}
private native void jni_YGNodeMarkDirty(long nativePointer);
@@ -198,18 +215,17 @@ public class YogaNode implements YogaNodeAPI<YogaNode> {
return jni_YGNodeIsDirty(mNativePointer);
}
private native void jni_YGNodeMarkLayoutSeen(long nativePointer);
@Override
public void markLayoutSeen() {
jni_YGNodeMarkLayoutSeen(mNativePointer);
}
private native void jni_YGNodeCopyStyle(long dstNativePointer, long srcNativePointer);
@Override
public void copyStyle(YogaNode srcNode) {
jni_YGNodeCopyStyle(mNativePointer, srcNode.mNativePointer);
}
@Override
public void markLayoutSeen() {
mHasNewLayout = false;
}
private native int jni_YGNodeStyleGetDirection(long nativePointer);
@Override
public YogaDirection getStyleDirection() {
@@ -381,7 +397,7 @@ public class YogaNode implements YogaNodeAPI<YogaNode> {
private native Object jni_YGNodeStyleGetMargin(long nativePointer, int edge);
@Override
public YogaValue getMargin(YogaEdge edge) {
if (!mHasSetMargin) {
if (!((mEdgeSetFlag & MARGIN) == MARGIN)) {
return YogaValue.UNDEFINED;
}
return (YogaValue) jni_YGNodeStyleGetMargin(mNativePointer, edge.intValue());
@@ -390,28 +406,28 @@ public class YogaNode implements YogaNodeAPI<YogaNode> {
private native void jni_YGNodeStyleSetMargin(long nativePointer, int edge, float margin);
@Override
public void setMargin(YogaEdge edge, float margin) {
mHasSetMargin = true;
mEdgeSetFlag |= MARGIN;
jni_YGNodeStyleSetMargin(mNativePointer, edge.intValue(), margin);
}
private native void jni_YGNodeStyleSetMarginPercent(long nativePointer, int edge, float percent);
@Override
public void setMarginPercent(YogaEdge edge, float percent) {
mHasSetMargin = true;
mEdgeSetFlag |= MARGIN;
jni_YGNodeStyleSetMarginPercent(mNativePointer, edge.intValue(), percent);
}
private native void jni_YGNodeStyleSetMarginAuto(long nativePointer, int edge);
@Override
public void setMarginAuto(YogaEdge edge) {
mHasSetMargin = true;
mEdgeSetFlag |= MARGIN;
jni_YGNodeStyleSetMarginAuto(mNativePointer, edge.intValue());
}
private native Object jni_YGNodeStyleGetPadding(long nativePointer, int edge);
@Override
public YogaValue getPadding(YogaEdge edge) {
if (!mHasSetPadding) {
if (!((mEdgeSetFlag & PADDING) == PADDING)) {
return YogaValue.UNDEFINED;
}
return (YogaValue) jni_YGNodeStyleGetPadding(mNativePointer, edge.intValue());
@@ -420,21 +436,21 @@ public class YogaNode implements YogaNodeAPI<YogaNode> {
private native void jni_YGNodeStyleSetPadding(long nativePointer, int edge, float padding);
@Override
public void setPadding(YogaEdge edge, float padding) {
mHasSetPadding = true;
mEdgeSetFlag |= PADDING;
jni_YGNodeStyleSetPadding(mNativePointer, edge.intValue(), padding);
}
private native void jni_YGNodeStyleSetPaddingPercent(long nativePointer, int edge, float percent);
@Override
public void setPaddingPercent(YogaEdge edge, float percent) {
mHasSetPadding = true;
mEdgeSetFlag |= PADDING;
jni_YGNodeStyleSetPaddingPercent(mNativePointer, edge.intValue(), percent);
}
private native float jni_YGNodeStyleGetBorder(long nativePointer, int edge);
@Override
public float getBorder(YogaEdge edge) {
if (!mHasSetBorder) {
if (!((mEdgeSetFlag & BORDER) == BORDER)) {
return YogaConstants.UNDEFINED;
}
return jni_YGNodeStyleGetBorder(mNativePointer, edge.intValue());
@@ -443,7 +459,7 @@ public class YogaNode implements YogaNodeAPI<YogaNode> {
private native void jni_YGNodeStyleSetBorder(long nativePointer, int edge, float border);
@Override
public void setBorder(YogaEdge edge, float border) {
mHasSetBorder = true;
mEdgeSetFlag |= BORDER;
jni_YGNodeStyleSetBorder(mNativePointer, edge.intValue(), border);
}

View File

@@ -24,54 +24,74 @@ static void YGTransferLayoutDirection(YGNodeRef node, alias_ref<jobject> javaNod
}
static void YGTransferLayoutOutputsRecursive(YGNodeRef root) {
if (auto obj = YGNodeJobject(root)->lockLocal()) {
static auto widthField = obj->getClass()->getField<jfloat>("mWidth");
static auto heightField = obj->getClass()->getField<jfloat>("mHeight");
static auto leftField = obj->getClass()->getField<jfloat>("mLeft");
static auto topField = obj->getClass()->getField<jfloat>("mTop");
if(YGNodeGetHasNewLayout(root)){
if (auto obj = YGNodeJobject(root)->lockLocal()) {
static auto widthField = obj->getClass()->getField<jfloat>("mWidth");
static auto heightField = obj->getClass()->getField<jfloat>("mHeight");
static auto leftField = obj->getClass()->getField<jfloat>("mLeft");
static auto topField = obj->getClass()->getField<jfloat>("mTop");
static auto marginLeftField = obj->getClass()->getField<jfloat>("mMarginLeft");
static auto marginTopField = obj->getClass()->getField<jfloat>("mMarginTop");
static auto marginRightField = obj->getClass()->getField<jfloat>("mMarginRight");
static auto marginBottomField = obj->getClass()->getField<jfloat>("mMarginBottom");
static auto marginLeftField = obj->getClass()->getField<jfloat>("mMarginLeft");
static auto marginTopField = obj->getClass()->getField<jfloat>("mMarginTop");
static auto marginRightField = obj->getClass()->getField<jfloat>("mMarginRight");
static auto marginBottomField = obj->getClass()->getField<jfloat>("mMarginBottom");
static auto paddingLeftField = obj->getClass()->getField<jfloat>("mPaddingLeft");
static auto paddingTopField = obj->getClass()->getField<jfloat>("mPaddingTop");
static auto paddingRightField = obj->getClass()->getField<jfloat>("mPaddingRight");
static auto paddingBottomField = obj->getClass()->getField<jfloat>("mPaddingBottom");
static auto paddingLeftField = obj->getClass()->getField<jfloat>("mPaddingLeft");
static auto paddingTopField = obj->getClass()->getField<jfloat>("mPaddingTop");
static auto paddingRightField = obj->getClass()->getField<jfloat>("mPaddingRight");
static auto paddingBottomField = obj->getClass()->getField<jfloat>("mPaddingBottom");
static auto borderLeftField = obj->getClass()->getField<jfloat>("mBorderLeft");
static auto borderTopField = obj->getClass()->getField<jfloat>("mBorderTop");
static auto borderRightField = obj->getClass()->getField<jfloat>("mBorderRight");
static auto borderBottomField = obj->getClass()->getField<jfloat>("mBorderBottom");
static auto borderLeftField = obj->getClass()->getField<jfloat>("mBorderLeft");
static auto borderTopField = obj->getClass()->getField<jfloat>("mBorderTop");
static auto borderRightField = obj->getClass()->getField<jfloat>("mBorderRight");
static auto borderBottomField = obj->getClass()->getField<jfloat>("mBorderBottom");
obj->setFieldValue(widthField, YGNodeLayoutGetWidth(root));
obj->setFieldValue(heightField, YGNodeLayoutGetHeight(root));
obj->setFieldValue(leftField, YGNodeLayoutGetLeft(root));
obj->setFieldValue(topField, YGNodeLayoutGetTop(root));
static auto edgeSetFlagField = obj->getClass()->getField<jint>("mEdgeSetFlag");
static auto hasNewLayoutField = obj->getClass()->getField<jboolean>("mHasNewLayout");
obj->setFieldValue(marginLeftField, YGNodeLayoutGetMargin(root, YGEdgeLeft));
obj->setFieldValue(marginTopField, YGNodeLayoutGetMargin(root, YGEdgeTop));
obj->setFieldValue(marginRightField, YGNodeLayoutGetMargin(root, YGEdgeRight));
obj->setFieldValue(marginBottomField, YGNodeLayoutGetMargin(root, YGEdgeBottom));
/* Those flags needs be in sync with YogaNode.java */
const int MARGIN = 1;
const int PADDING = 2;
const int BORDER = 4;
obj->setFieldValue(paddingLeftField, YGNodeLayoutGetPadding(root, YGEdgeLeft));
obj->setFieldValue(paddingTopField, YGNodeLayoutGetPadding(root, YGEdgeTop));
obj->setFieldValue(paddingRightField, YGNodeLayoutGetPadding(root, YGEdgeRight));
obj->setFieldValue(paddingBottomField, YGNodeLayoutGetPadding(root, YGEdgeBottom));
int hasEdgeSetFlag = (int)obj->getFieldValue(edgeSetFlagField);
obj->setFieldValue(borderLeftField, YGNodeLayoutGetBorder(root, YGEdgeLeft));
obj->setFieldValue(borderTopField, YGNodeLayoutGetBorder(root, YGEdgeTop));
obj->setFieldValue(borderRightField, YGNodeLayoutGetBorder(root, YGEdgeRight));
obj->setFieldValue(borderBottomField, YGNodeLayoutGetBorder(root, YGEdgeBottom));
obj->setFieldValue(widthField, YGNodeLayoutGetWidth(root));
obj->setFieldValue(heightField, YGNodeLayoutGetHeight(root));
obj->setFieldValue(leftField, YGNodeLayoutGetLeft(root));
obj->setFieldValue(topField, YGNodeLayoutGetTop(root));
YGTransferLayoutDirection(root, obj);
if((hasEdgeSetFlag & MARGIN) == MARGIN){
obj->setFieldValue(marginLeftField, YGNodeLayoutGetMargin(root, YGEdgeLeft));
obj->setFieldValue(marginTopField, YGNodeLayoutGetMargin(root, YGEdgeTop));
obj->setFieldValue(marginRightField, YGNodeLayoutGetMargin(root, YGEdgeRight));
obj->setFieldValue(marginBottomField, YGNodeLayoutGetMargin(root, YGEdgeBottom));
}
for (uint32_t i = 0; i < YGNodeGetChildCount(root); i++) {
YGTransferLayoutOutputsRecursive(YGNodeGetChild(root, i));
if((hasEdgeSetFlag & PADDING) == PADDING){
obj->setFieldValue(paddingLeftField, YGNodeLayoutGetPadding(root, YGEdgeLeft));
obj->setFieldValue(paddingTopField, YGNodeLayoutGetPadding(root, YGEdgeTop));
obj->setFieldValue(paddingRightField, YGNodeLayoutGetPadding(root, YGEdgeRight));
obj->setFieldValue(paddingBottomField, YGNodeLayoutGetPadding(root, YGEdgeBottom));
}
if((hasEdgeSetFlag & BORDER) == BORDER){
obj->setFieldValue(borderLeftField, YGNodeLayoutGetBorder(root, YGEdgeLeft));
obj->setFieldValue(borderTopField, YGNodeLayoutGetBorder(root, YGEdgeTop));
obj->setFieldValue(borderRightField, YGNodeLayoutGetBorder(root, YGEdgeRight));
obj->setFieldValue(borderBottomField, YGNodeLayoutGetBorder(root, YGEdgeBottom));
}
obj->setFieldValue<jboolean>(hasNewLayoutField, true);
YGTransferLayoutDirection(root, obj);
YGNodeSetHasNewLayout(root, false);
for (uint32_t i = 0; i < YGNodeGetChildCount(root); i++) {
YGTransferLayoutOutputsRecursive(YGNodeGetChild(root, i));
}
} else {
YGLog(YGLogLevelError, "Java YGNode was GCed during layout calculation\n");
}
} else {
YGLog(YGLogLevelError, "Java YGNode was GCed during layout calculation\n");
}
}
@@ -242,14 +262,6 @@ void jni_YGNodeSetHasBaselineFunc(alias_ref<jobject>,
hasBaselineFunc ? YGJNIBaselineFunc : NULL);
}
jboolean jni_YGNodeHasNewLayout(alias_ref<jobject>, jlong nativePointer) {
return (jboolean) YGNodeGetHasNewLayout(_jlong2YGNodeRef(nativePointer));
}
void jni_YGNodeMarkLayoutSeen(alias_ref<jobject>, jlong nativePointer) {
YGNodeSetHasNewLayout(_jlong2YGNodeRef(nativePointer), false);
}
void jni_YGNodeCopyStyle(alias_ref<jobject>, jlong dstNativePointer, jlong srcNativePointer) {
YGNodeCopyStyle(_jlong2YGNodeRef(dstNativePointer), _jlong2YGNodeRef(srcNativePointer));
}
@@ -381,6 +393,11 @@ void jni_YGConfigSetExperimentalFeatureEnabled(alias_ref<jobject>, jlong nativeP
YGConfigSetExperimentalFeatureEnabled(config, static_cast<YGExperimentalFeature>(feature), enabled);
}
void jni_YGConfigSetUseWebDefaults(alias_ref<jobject>, jlong nativePointer, jboolean useWebDefaults) {
const YGConfigRef config = _jlong2YGConfigRef(nativePointer);
YGConfigSetUseWebDefaults(config, useWebDefaults);
}
jint jni_YGNodeGetInstanceCount(alias_ref<jclass> clazz) {
return YGNodeGetInstanceCount();
}
@@ -398,10 +415,8 @@ jint JNI_OnLoad(JavaVM *vm, void *) {
YGMakeNativeMethod(jni_YGNodeInsertChild),
YGMakeNativeMethod(jni_YGNodeRemoveChild),
YGMakeNativeMethod(jni_YGNodeCalculateLayout),
YGMakeNativeMethod(jni_YGNodeHasNewLayout),
YGMakeNativeMethod(jni_YGNodeMarkDirty),
YGMakeNativeMethod(jni_YGNodeIsDirty),
YGMakeNativeMethod(jni_YGNodeMarkLayoutSeen),
YGMakeNativeMethod(jni_YGNodeSetHasMeasureFunc),
YGMakeNativeMethod(jni_YGNodeSetHasBaselineFunc),
YGMakeNativeMethod(jni_YGNodeCopyStyle),
@@ -476,6 +491,7 @@ jint JNI_OnLoad(JavaVM *vm, void *) {
YGMakeNativeMethod(jni_YGConfigNew),
YGMakeNativeMethod(jni_YGConfigFree),
YGMakeNativeMethod(jni_YGConfigSetExperimentalFeatureEnabled),
YGMakeNativeMethod(jni_YGConfigSetUseWebDefaults),
});
});
}

View File

@@ -0,0 +1 @@
apply plugin: 'java'

View File

@@ -12,6 +12,6 @@ java_library(
srcs = glob(["*.java"]),
source = "1.7",
target = "1.7",
visibility = [YOGA_ROOT],
visibility = YOGA_ROOTS,
deps = [],
)

View File

@@ -703,4 +703,29 @@ public class YGAbsolutePositionTest {
assertEquals(40f, root_child0.getLayoutHeight(), 0.0f);
}
@Test
public void test_position_root_with_rtl_should_position_withoutdirection() {
YogaConfig config = new YogaConfig();
final YogaNode root = new YogaNode(config);
root.setPosition(YogaEdge.LEFT, 72f);
root.setWidth(52f);
root.setHeight(52f);
root.setDirection(YogaDirection.LTR);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(72f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(52f, root.getLayoutWidth(), 0.0f);
assertEquals(52f, root.getLayoutHeight(), 0.0f);
root.setDirection(YogaDirection.RTL);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(72f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(52f, root.getLayoutWidth(), 0.0f);
assertEquals(52f, root.getLayoutHeight(), 0.0f);
}
}

View File

@@ -1567,4 +1567,228 @@ public class YGAlignItemsTest {
assertEquals(20f, root_child3.getLayoutHeight(), 0.0f);
}
@Test
public void test_align_items_center_child_with_margin_bigger_than_parent() {
YogaConfig config = new YogaConfig();
final YogaNode root = new YogaNode(config);
root.setJustifyContent(YogaJustify.CENTER);
root.setAlignItems(YogaAlign.CENTER);
root.setWidth(52f);
root.setHeight(52f);
final YogaNode root_child0 = new YogaNode(config);
root_child0.setAlignItems(YogaAlign.CENTER);
root.addChildAt(root_child0, 0);
final YogaNode root_child0_child0 = new YogaNode(config);
root_child0_child0.setMargin(YogaEdge.LEFT, 10f);
root_child0_child0.setMargin(YogaEdge.RIGHT, 10f);
root_child0_child0.setWidth(52f);
root_child0_child0.setHeight(52f);
root_child0.addChildAt(root_child0_child0, 0);
root.setDirection(YogaDirection.LTR);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(52f, root.getLayoutWidth(), 0.0f);
assertEquals(52f, root.getLayoutHeight(), 0.0f);
assertEquals(-10f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(72f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(52f, root_child0.getLayoutHeight(), 0.0f);
assertEquals(10f, root_child0_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f);
assertEquals(52f, root_child0_child0.getLayoutWidth(), 0.0f);
assertEquals(52f, root_child0_child0.getLayoutHeight(), 0.0f);
root.setDirection(YogaDirection.RTL);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(52f, root.getLayoutWidth(), 0.0f);
assertEquals(52f, root.getLayoutHeight(), 0.0f);
assertEquals(-10f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(72f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(52f, root_child0.getLayoutHeight(), 0.0f);
assertEquals(10f, root_child0_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f);
assertEquals(52f, root_child0_child0.getLayoutWidth(), 0.0f);
assertEquals(52f, root_child0_child0.getLayoutHeight(), 0.0f);
}
@Test
public void test_align_items_flex_end_child_with_margin_bigger_than_parent() {
YogaConfig config = new YogaConfig();
final YogaNode root = new YogaNode(config);
root.setJustifyContent(YogaJustify.CENTER);
root.setAlignItems(YogaAlign.CENTER);
root.setWidth(52f);
root.setHeight(52f);
final YogaNode root_child0 = new YogaNode(config);
root_child0.setAlignItems(YogaAlign.FLEX_END);
root.addChildAt(root_child0, 0);
final YogaNode root_child0_child0 = new YogaNode(config);
root_child0_child0.setMargin(YogaEdge.LEFT, 10f);
root_child0_child0.setMargin(YogaEdge.RIGHT, 10f);
root_child0_child0.setWidth(52f);
root_child0_child0.setHeight(52f);
root_child0.addChildAt(root_child0_child0, 0);
root.setDirection(YogaDirection.LTR);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(52f, root.getLayoutWidth(), 0.0f);
assertEquals(52f, root.getLayoutHeight(), 0.0f);
assertEquals(-10f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(72f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(52f, root_child0.getLayoutHeight(), 0.0f);
assertEquals(10f, root_child0_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f);
assertEquals(52f, root_child0_child0.getLayoutWidth(), 0.0f);
assertEquals(52f, root_child0_child0.getLayoutHeight(), 0.0f);
root.setDirection(YogaDirection.RTL);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(52f, root.getLayoutWidth(), 0.0f);
assertEquals(52f, root.getLayoutHeight(), 0.0f);
assertEquals(-10f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(72f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(52f, root_child0.getLayoutHeight(), 0.0f);
assertEquals(10f, root_child0_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f);
assertEquals(52f, root_child0_child0.getLayoutWidth(), 0.0f);
assertEquals(52f, root_child0_child0.getLayoutHeight(), 0.0f);
}
@Test
public void test_align_items_center_child_without_margin_bigger_than_parent() {
YogaConfig config = new YogaConfig();
final YogaNode root = new YogaNode(config);
root.setJustifyContent(YogaJustify.CENTER);
root.setAlignItems(YogaAlign.CENTER);
root.setWidth(52f);
root.setHeight(52f);
final YogaNode root_child0 = new YogaNode(config);
root_child0.setAlignItems(YogaAlign.CENTER);
root.addChildAt(root_child0, 0);
final YogaNode root_child0_child0 = new YogaNode(config);
root_child0_child0.setWidth(72f);
root_child0_child0.setHeight(72f);
root_child0.addChildAt(root_child0_child0, 0);
root.setDirection(YogaDirection.LTR);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(52f, root.getLayoutWidth(), 0.0f);
assertEquals(52f, root.getLayoutHeight(), 0.0f);
assertEquals(-10f, root_child0.getLayoutX(), 0.0f);
assertEquals(-10f, root_child0.getLayoutY(), 0.0f);
assertEquals(72f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(72f, root_child0.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f);
assertEquals(72f, root_child0_child0.getLayoutWidth(), 0.0f);
assertEquals(72f, root_child0_child0.getLayoutHeight(), 0.0f);
root.setDirection(YogaDirection.RTL);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(52f, root.getLayoutWidth(), 0.0f);
assertEquals(52f, root.getLayoutHeight(), 0.0f);
assertEquals(-10f, root_child0.getLayoutX(), 0.0f);
assertEquals(-10f, root_child0.getLayoutY(), 0.0f);
assertEquals(72f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(72f, root_child0.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f);
assertEquals(72f, root_child0_child0.getLayoutWidth(), 0.0f);
assertEquals(72f, root_child0_child0.getLayoutHeight(), 0.0f);
}
@Test
public void test_align_items_flex_end_child_without_margin_bigger_than_parent() {
YogaConfig config = new YogaConfig();
final YogaNode root = new YogaNode(config);
root.setJustifyContent(YogaJustify.CENTER);
root.setAlignItems(YogaAlign.CENTER);
root.setWidth(52f);
root.setHeight(52f);
final YogaNode root_child0 = new YogaNode(config);
root_child0.setAlignItems(YogaAlign.FLEX_END);
root.addChildAt(root_child0, 0);
final YogaNode root_child0_child0 = new YogaNode(config);
root_child0_child0.setWidth(72f);
root_child0_child0.setHeight(72f);
root_child0.addChildAt(root_child0_child0, 0);
root.setDirection(YogaDirection.LTR);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(52f, root.getLayoutWidth(), 0.0f);
assertEquals(52f, root.getLayoutHeight(), 0.0f);
assertEquals(-10f, root_child0.getLayoutX(), 0.0f);
assertEquals(-10f, root_child0.getLayoutY(), 0.0f);
assertEquals(72f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(72f, root_child0.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f);
assertEquals(72f, root_child0_child0.getLayoutWidth(), 0.0f);
assertEquals(72f, root_child0_child0.getLayoutHeight(), 0.0f);
root.setDirection(YogaDirection.RTL);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(52f, root.getLayoutWidth(), 0.0f);
assertEquals(52f, root.getLayoutHeight(), 0.0f);
assertEquals(-10f, root_child0.getLayoutX(), 0.0f);
assertEquals(-10f, root_child0.getLayoutY(), 0.0f);
assertEquals(72f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(72f, root_child0.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f);
assertEquals(72f, root_child0_child0.getLayoutWidth(), 0.0f);
assertEquals(72f, root_child0_child0.getLayoutHeight(), 0.0f);
}
}

View File

@@ -1326,4 +1326,253 @@ public class YGMarginTest {
assertEquals(50f, root_child1.getLayoutHeight(), 0.0f);
}
@Test
public void test_margin_should_not_be_part_of_max_height() {
YogaConfig config = new YogaConfig();
final YogaNode root = new YogaNode(config);
root.setWidth(250f);
root.setHeight(250f);
final YogaNode root_child0 = new YogaNode(config);
root_child0.setMargin(YogaEdge.TOP, 20f);
root_child0.setWidth(100f);
root_child0.setHeight(100f);
root_child0.setMaxHeight(100f);
root.addChildAt(root_child0, 0);
root.setDirection(YogaDirection.LTR);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(250f, root.getLayoutWidth(), 0.0f);
assertEquals(250f, root.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
assertEquals(20f, root_child0.getLayoutY(), 0.0f);
assertEquals(100f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(100f, root_child0.getLayoutHeight(), 0.0f);
root.setDirection(YogaDirection.RTL);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(250f, root.getLayoutWidth(), 0.0f);
assertEquals(250f, root.getLayoutHeight(), 0.0f);
assertEquals(150f, root_child0.getLayoutX(), 0.0f);
assertEquals(20f, root_child0.getLayoutY(), 0.0f);
assertEquals(100f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(100f, root_child0.getLayoutHeight(), 0.0f);
}
@Test
public void test_margin_should_not_be_part_of_max_width() {
YogaConfig config = new YogaConfig();
final YogaNode root = new YogaNode(config);
root.setWidth(250f);
root.setHeight(250f);
final YogaNode root_child0 = new YogaNode(config);
root_child0.setMargin(YogaEdge.LEFT, 20f);
root_child0.setWidth(100f);
root_child0.setMaxWidth(100f);
root_child0.setHeight(100f);
root.addChildAt(root_child0, 0);
root.setDirection(YogaDirection.LTR);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(250f, root.getLayoutWidth(), 0.0f);
assertEquals(250f, root.getLayoutHeight(), 0.0f);
assertEquals(20f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(100f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(100f, root_child0.getLayoutHeight(), 0.0f);
root.setDirection(YogaDirection.RTL);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(250f, root.getLayoutWidth(), 0.0f);
assertEquals(250f, root.getLayoutHeight(), 0.0f);
assertEquals(150f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(100f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(100f, root_child0.getLayoutHeight(), 0.0f);
}
@Test
public void test_margin_auto_left_right_child_bigger_than_parent() {
YogaConfig config = new YogaConfig();
final YogaNode root = new YogaNode(config);
root.setJustifyContent(YogaJustify.CENTER);
root.setWidth(52f);
root.setHeight(52f);
final YogaNode root_child0 = new YogaNode(config);
root_child0.setMarginAuto(YogaEdge.LEFT);
root_child0.setMarginAuto(YogaEdge.RIGHT);
root_child0.setWidth(72f);
root_child0.setHeight(72f);
root.addChildAt(root_child0, 0);
root.setDirection(YogaDirection.LTR);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(52f, root.getLayoutWidth(), 0.0f);
assertEquals(52f, root.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
assertEquals(-10f, root_child0.getLayoutY(), 0.0f);
assertEquals(72f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(72f, root_child0.getLayoutHeight(), 0.0f);
root.setDirection(YogaDirection.RTL);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(52f, root.getLayoutWidth(), 0.0f);
assertEquals(52f, root.getLayoutHeight(), 0.0f);
assertEquals(-20f, root_child0.getLayoutX(), 0.0f);
assertEquals(-10f, root_child0.getLayoutY(), 0.0f);
assertEquals(72f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(72f, root_child0.getLayoutHeight(), 0.0f);
}
@Test
public void test_margin_auto_left_child_bigger_than_parent() {
YogaConfig config = new YogaConfig();
final YogaNode root = new YogaNode(config);
root.setJustifyContent(YogaJustify.CENTER);
root.setWidth(52f);
root.setHeight(52f);
final YogaNode root_child0 = new YogaNode(config);
root_child0.setMarginAuto(YogaEdge.LEFT);
root_child0.setWidth(72f);
root_child0.setHeight(72f);
root.addChildAt(root_child0, 0);
root.setDirection(YogaDirection.LTR);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(52f, root.getLayoutWidth(), 0.0f);
assertEquals(52f, root.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
assertEquals(-10f, root_child0.getLayoutY(), 0.0f);
assertEquals(72f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(72f, root_child0.getLayoutHeight(), 0.0f);
root.setDirection(YogaDirection.RTL);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(52f, root.getLayoutWidth(), 0.0f);
assertEquals(52f, root.getLayoutHeight(), 0.0f);
assertEquals(-20f, root_child0.getLayoutX(), 0.0f);
assertEquals(-10f, root_child0.getLayoutY(), 0.0f);
assertEquals(72f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(72f, root_child0.getLayoutHeight(), 0.0f);
}
@Test
public void test_margin_fix_left_auto_right_child_bigger_than_parent() {
YogaConfig config = new YogaConfig();
final YogaNode root = new YogaNode(config);
root.setJustifyContent(YogaJustify.CENTER);
root.setWidth(52f);
root.setHeight(52f);
final YogaNode root_child0 = new YogaNode(config);
root_child0.setMargin(YogaEdge.LEFT, 10f);
root_child0.setMarginAuto(YogaEdge.RIGHT);
root_child0.setWidth(72f);
root_child0.setHeight(72f);
root.addChildAt(root_child0, 0);
root.setDirection(YogaDirection.LTR);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(52f, root.getLayoutWidth(), 0.0f);
assertEquals(52f, root.getLayoutHeight(), 0.0f);
assertEquals(10f, root_child0.getLayoutX(), 0.0f);
assertEquals(-10f, root_child0.getLayoutY(), 0.0f);
assertEquals(72f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(72f, root_child0.getLayoutHeight(), 0.0f);
root.setDirection(YogaDirection.RTL);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(52f, root.getLayoutWidth(), 0.0f);
assertEquals(52f, root.getLayoutHeight(), 0.0f);
assertEquals(-20f, root_child0.getLayoutX(), 0.0f);
assertEquals(-10f, root_child0.getLayoutY(), 0.0f);
assertEquals(72f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(72f, root_child0.getLayoutHeight(), 0.0f);
}
@Test
public void test_margin_auto_left_fix_right_child_bigger_than_parent() {
YogaConfig config = new YogaConfig();
final YogaNode root = new YogaNode(config);
root.setJustifyContent(YogaJustify.CENTER);
root.setWidth(52f);
root.setHeight(52f);
final YogaNode root_child0 = new YogaNode(config);
root_child0.setMarginAuto(YogaEdge.LEFT);
root_child0.setMargin(YogaEdge.RIGHT, 10f);
root_child0.setWidth(72f);
root_child0.setHeight(72f);
root.addChildAt(root_child0, 0);
root.setDirection(YogaDirection.LTR);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(52f, root.getLayoutWidth(), 0.0f);
assertEquals(52f, root.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
assertEquals(-10f, root_child0.getLayoutY(), 0.0f);
assertEquals(72f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(72f, root_child0.getLayoutHeight(), 0.0f);
root.setDirection(YogaDirection.RTL);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(52f, root.getLayoutWidth(), 0.0f);
assertEquals(52f, root.getLayoutHeight(), 0.0f);
assertEquals(-30f, root_child0.getLayoutX(), 0.0f);
assertEquals(-10f, root_child0.getLayoutY(), 0.0f);
assertEquals(72f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(72f, root_child0.getLayoutHeight(), 0.0f);
}
}

View File

@@ -936,4 +936,111 @@ public class YGMinMaxDimensionTest {
assertEquals(10f, root_child0.getLayoutHeight(), 0.0f);
}
@Test
public void test_min_width_in_flex_distribution() {
YogaConfig config = new YogaConfig();
final YogaNode root = new YogaNode(config);
root.setFlexDirection(YogaFlexDirection.ROW);
root.setWidth(300f);
root.setHeight(300f);
final YogaNode root_child0 = new YogaNode(config);
root_child0.setFlexGrow(2f);
root_child0.setFlexShrink(1f);
root_child0.setFlexBasisPercent(0f);
root_child0.setMinWidth(100f);
root_child0.setMaxWidth(200f);
root.addChildAt(root_child0, 0);
final YogaNode root_child1 = new YogaNode(config);
root_child1.setFlexGrow(1f);
root_child1.setFlexShrink(1f);
root_child1.setFlexBasisPercent(0f);
root.addChildAt(root_child1, 1);
final YogaNode root_child2 = new YogaNode(config);
root_child2.setFlexGrow(1f);
root_child2.setFlexShrink(1f);
root_child2.setFlexBasisPercent(0f);
root.addChildAt(root_child2, 2);
final YogaNode root_child3 = new YogaNode(config);
root_child3.setFlexGrow(1f);
root_child3.setFlexShrink(1f);
root_child3.setFlexBasisPercent(0f);
root.addChildAt(root_child3, 3);
final YogaNode root_child4 = new YogaNode(config);
root_child4.setFlexGrow(1f);
root_child4.setFlexShrink(1f);
root_child4.setFlexBasisPercent(0f);
root.addChildAt(root_child4, 4);
root.setDirection(YogaDirection.LTR);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(300f, root.getLayoutWidth(), 0.0f);
assertEquals(300f, root.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(100f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(300f, root_child0.getLayoutHeight(), 0.0f);
assertEquals(100f, root_child1.getLayoutX(), 0.0f);
assertEquals(0f, root_child1.getLayoutY(), 0.0f);
assertEquals(50f, root_child1.getLayoutWidth(), 0.0f);
assertEquals(300f, root_child1.getLayoutHeight(), 0.0f);
assertEquals(150f, root_child2.getLayoutX(), 0.0f);
assertEquals(0f, root_child2.getLayoutY(), 0.0f);
assertEquals(50f, root_child2.getLayoutWidth(), 0.0f);
assertEquals(300f, root_child2.getLayoutHeight(), 0.0f);
assertEquals(200f, root_child3.getLayoutX(), 0.0f);
assertEquals(0f, root_child3.getLayoutY(), 0.0f);
assertEquals(50f, root_child3.getLayoutWidth(), 0.0f);
assertEquals(300f, root_child3.getLayoutHeight(), 0.0f);
assertEquals(250f, root_child4.getLayoutX(), 0.0f);
assertEquals(0f, root_child4.getLayoutY(), 0.0f);
assertEquals(50f, root_child4.getLayoutWidth(), 0.0f);
assertEquals(300f, root_child4.getLayoutHeight(), 0.0f);
root.setDirection(YogaDirection.RTL);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(300f, root.getLayoutWidth(), 0.0f);
assertEquals(300f, root.getLayoutHeight(), 0.0f);
assertEquals(200f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(100f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(300f, root_child0.getLayoutHeight(), 0.0f);
assertEquals(150f, root_child1.getLayoutX(), 0.0f);
assertEquals(0f, root_child1.getLayoutY(), 0.0f);
assertEquals(50f, root_child1.getLayoutWidth(), 0.0f);
assertEquals(300f, root_child1.getLayoutHeight(), 0.0f);
assertEquals(100f, root_child2.getLayoutX(), 0.0f);
assertEquals(0f, root_child2.getLayoutY(), 0.0f);
assertEquals(50f, root_child2.getLayoutWidth(), 0.0f);
assertEquals(300f, root_child2.getLayoutHeight(), 0.0f);
assertEquals(50f, root_child3.getLayoutX(), 0.0f);
assertEquals(0f, root_child3.getLayoutY(), 0.0f);
assertEquals(50f, root_child3.getLayoutWidth(), 0.0f);
assertEquals(300f, root_child3.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child4.getLayoutX(), 0.0f);
assertEquals(0f, root_child4.getLayoutY(), 0.0f);
assertEquals(50f, root_child4.getLayoutWidth(), 0.0f);
assertEquals(300f, root_child4.getLayoutHeight(), 0.0f);
}
}

View File

@@ -1126,4 +1126,74 @@ public class YGPercentageTest {
assertEquals(50f, root_child0_child0_child1.getLayoutHeight(), 0.0f);
}
@Test
public void test_percent_absolute_position() {
YogaConfig config = new YogaConfig();
final YogaNode root = new YogaNode(config);
root.setWidth(60f);
root.setHeight(50f);
final YogaNode root_child0 = new YogaNode(config);
root_child0.setFlexDirection(YogaFlexDirection.ROW);
root_child0.setPositionType(YogaPositionType.ABSOLUTE);
root_child0.setPositionPercent(YogaEdge.LEFT, 50f);
root_child0.setWidthPercent(100f);
root_child0.setHeight(50f);
root.addChildAt(root_child0, 0);
final YogaNode root_child0_child0 = new YogaNode(config);
root_child0_child0.setWidthPercent(100f);
root_child0.addChildAt(root_child0_child0, 0);
final YogaNode root_child0_child1 = new YogaNode(config);
root_child0_child1.setWidthPercent(100f);
root_child0.addChildAt(root_child0_child1, 1);
root.setDirection(YogaDirection.LTR);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(60f, root.getLayoutWidth(), 0.0f);
assertEquals(50f, root.getLayoutHeight(), 0.0f);
assertEquals(30f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(60f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(50f, root_child0.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f);
assertEquals(60f, root_child0_child0.getLayoutWidth(), 0.0f);
assertEquals(50f, root_child0_child0.getLayoutHeight(), 0.0f);
assertEquals(60f, root_child0_child1.getLayoutX(), 0.0f);
assertEquals(0f, root_child0_child1.getLayoutY(), 0.0f);
assertEquals(60f, root_child0_child1.getLayoutWidth(), 0.0f);
assertEquals(50f, root_child0_child1.getLayoutHeight(), 0.0f);
root.setDirection(YogaDirection.RTL);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(60f, root.getLayoutWidth(), 0.0f);
assertEquals(50f, root.getLayoutHeight(), 0.0f);
assertEquals(30f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(60f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(50f, root_child0.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f);
assertEquals(60f, root_child0_child0.getLayoutWidth(), 0.0f);
assertEquals(50f, root_child0_child0.getLayoutHeight(), 0.0f);
assertEquals(-60f, root_child0_child1.getLayoutX(), 0.0f);
assertEquals(0f, root_child0_child1.getLayoutY(), 0.0f);
assertEquals(60f, root_child0_child1.getLayoutWidth(), 0.0f);
assertEquals(50f, root_child0_child1.getLayoutHeight(), 0.0f);
}
}

View File

@@ -219,6 +219,14 @@ public class YogaNodeTest {
assertEquals(4, (int) node.getLayoutBorder(YogaEdge.BOTTOM));
}
@Test
public void testUseWebDefaults() {
final YogaConfig config = new YogaConfig();
config.setUseWebDefaults(true);
final YogaNode node = new YogaNode(config);
assertEquals(YogaFlexDirection.ROW, node.getFlexDirection());
}
@Test
public void testPercentPaddingOnRoot() {
final YogaNode node = new YogaNode();

View File

@@ -9,6 +9,7 @@
"sources": [
"sources/yoga/YGNodeList.c",
"sources/yoga/Yoga.c",
"sources/Config.cc",
"sources/Node.cc",
"sources/global.cc",
"sources/nbind.cc"

View File

@@ -4,7 +4,8 @@
[ "1==1", {
"cflags_cc": [
"-std=c++14"
"-std=c++14",
"-DNBIND_DUPLICATE_POINTERS"
],
"xcode_settings": {

View File

@@ -0,0 +1,42 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#include <yoga/Yoga.h>
#include "./Config.hh"
/* static */ Config * Config::create(void)
{
return new Config();
}
/* static */ void Config::destroy(Config * node)
{
delete node;
}
Config::Config(void)
: m_config(YGConfigNew())
{
}
Config::~Config(void)
{
YGConfigFree(m_config);
}
void Config::setExperimentalFeatureEnabled(int feature, bool enabled)
{
YGConfigSetExperimentalFeatureEnabled(m_config, static_cast<YGExperimentalFeature>(feature), enabled);
}
bool Config::isExperimentalFeatureEnabled(int feature) const
{
return YGConfigIsExperimentalFeatureEnabled(m_config, static_cast<YGExperimentalFeature>(feature));
}

View File

@@ -14,36 +14,39 @@
#include <yoga/Yoga.h>
class Config {
private:
YGConfigRef m_config;
Config(void)
: m_config(YGConfigNew())
{}
friend class Node;
public:
public:
static Config * create(void)
{
return new Config();
}
static Config * create(void);
static void destroy(Config * config)
{
delete config;
}
static void destroy(Config * config);
~Config(void)
{
YGConfigFree(m_config);
}
private:
void setExperimentalFeatureEnabled(int feature, bool enabled)
{
YGConfigSetExperimentalFeatureEnabled(m_config, static_cast<YGExperimentalFeature>(feature), enabled);
}
Config(void);
Config(Config const &) = delete;
public:
~Config(void);
public: // Prevent accidental copy
Config(Config const &) = delete;
Config const & operator=(Config const &) = delete;
public: // Setters
void setExperimentalFeatureEnabled(int feature, bool enabled);
public: // Getters
bool isExperimentalFeatureEnabled(int feature) const;
private:
YGConfigRef m_config;
Config const & operator=(Config const &) = delete;
};

View File

@@ -26,9 +26,14 @@ static YGSize globalMeasureFunc(YGNodeRef nodeRef, float width, YGMeasureMode wi
return ygSize;
}
/* static */ Node * Node::create(void)
/* static */ Node * Node::createDefault(void)
{
return new Node();
return new Node(nullptr);
}
/* static */ Node * Node::createWithConfig(Config * config)
{
return new Node(config);
}
/* static */ void Node::destroy(Node * node)
@@ -41,8 +46,8 @@ static YGSize globalMeasureFunc(YGNodeRef nodeRef, float width, YGMeasureMode wi
return reinterpret_cast<Node *>(YGNodeGetContext(nodeRef));
}
Node::Node(void)
: m_node(YGNodeNew())
Node::Node(Config * config)
: m_node(config != nullptr ? YGNodeNewWithConfig(config->m_config) : YGNodeNew())
, m_measureFunc(nullptr)
{
YGNodeSetContext(m_node, reinterpret_cast<void *>(this));

View File

@@ -24,8 +24,9 @@ class Node {
public:
static Node * create(void);
static Node * create(Config * config);
static Node * createDefault(void);
static Node * createWithConfig(Config * config);
static void destroy(Node * node);
public:
@@ -34,7 +35,7 @@ class Node {
private:
Node(void);
Node(Config * config);
public:

View File

@@ -169,6 +169,22 @@ module.exports = function (bind, lib) {
}
patch(lib.Config.prototype, `free`, function () {
// Since we handle the memory allocation ourselves (via lib.Config.create), we also need to handle the deallocation
lib.Config.destroy(this);
});
patch(lib.Node, `create`, function (_, config) {
// We decide the constructor we want to call depending on the parameters
return config ? lib.Node.createWithConfig(config) : lib.Node.createDefault();
});
patch(lib.Node.prototype, `free`, function () {
// Since we handle the memory allocation ourselves (via lib.Node.create), we also need to handle the deallocation
@@ -207,18 +223,6 @@ module.exports = function (bind, lib) {
});
function setExperimentalFeatureEnabled(... args) {
return lib.setExperimentalFeatureEnabled(... args);
}
function isExperimentalFeatureEnabled(... args) {
return lib.isExperimentalFeatureEnabled(... args);
}
function getInstanceCount(... args) {
return lib.getInstanceCount(... args);
@@ -231,15 +235,13 @@ module.exports = function (bind, lib) {
return Object.assign({
Config: lib.Config,
Node: lib.Node,
Layout,
Size,
Value,
setExperimentalFeatureEnabled,
isExperimentalFeatureEnabled,
getInstanceCount
}, constants);

View File

@@ -16,8 +16,6 @@
#include "./Config.hh"
#include "./global.hh"
#define NBIND_DUPLICATE_POINTERS true
#include <nbind/nbind.h>
NBIND_GLOBAL()
@@ -45,13 +43,18 @@ NBIND_CLASS(Value)
NBIND_CLASS(Config)
{
method(create);
method(destroy);
method(setExperimentalFeatureEnabled);
method(isExperimentalFeatureEnabled);
}
NBIND_CLASS(Node)
{
method(create);
method(createDefault);
method(createWithConfig);
method(destroy);
method(reset);

View File

@@ -12,6 +12,8 @@
var Yoga = Yoga || require("../../sources/entry-" + process.env.TEST_ENTRY);
it("absolute_layout_width_height_start_top", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setWidth(100);
@@ -51,9 +53,13 @@ it("absolute_layout_width_height_start_top", function () {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});
it("absolute_layout_width_height_end_bottom", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setWidth(100);
@@ -93,9 +99,13 @@ it("absolute_layout_width_height_end_bottom", function () {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});
it("absolute_layout_start_top_end_bottom", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setWidth(100);
@@ -135,9 +145,13 @@ it("absolute_layout_start_top_end_bottom", function () {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});
it("absolute_layout_width_height_start_top_end_bottom", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setWidth(100);
@@ -179,9 +193,13 @@ it("absolute_layout_width_height_start_top_end_bottom", function () {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});
it("do_not_clamp_height_of_absolute_node_to_height_of_its_overflow_hidden_parent", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW);
@@ -236,9 +254,13 @@ it("do_not_clamp_height_of_absolute_node_to_height_of_its_overflow_hidden_parent
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});
it("absolute_layout_within_border", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setMargin(Yoga.EDGE_LEFT, 10);
@@ -308,9 +330,13 @@ it("absolute_layout_within_border", function () {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});
it("absolute_layout_align_items_and_justify_content_center", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setJustifyContent(Yoga.JUSTIFY_CENTER);
@@ -351,9 +377,13 @@ it("absolute_layout_align_items_and_justify_content_center", function () {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});
it("absolute_layout_align_items_and_justify_content_flex_end", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setJustifyContent(Yoga.JUSTIFY_FLEX_END);
@@ -394,9 +424,13 @@ it("absolute_layout_align_items_and_justify_content_flex_end", function () {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});
it("absolute_layout_justify_content_center", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setJustifyContent(Yoga.JUSTIFY_CENTER);
@@ -436,9 +470,13 @@ it("absolute_layout_justify_content_center", function () {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});
it("absolute_layout_align_items_center", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setAlignItems(Yoga.ALIGN_CENTER);
@@ -478,9 +516,13 @@ it("absolute_layout_align_items_center", function () {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});
it("absolute_layout_align_items_center_on_child_only", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setFlexGrow(1);
@@ -520,9 +562,13 @@ it("absolute_layout_align_items_center_on_child_only", function () {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});
it("absolute_layout_align_items_and_justify_content_center_and_top_position", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setJustifyContent(Yoga.JUSTIFY_CENTER);
@@ -564,9 +610,13 @@ it("absolute_layout_align_items_and_justify_content_center_and_top_position", fu
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});
it("absolute_layout_align_items_and_justify_content_center_and_bottom_position", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setJustifyContent(Yoga.JUSTIFY_CENTER);
@@ -608,9 +658,13 @@ it("absolute_layout_align_items_and_justify_content_center_and_bottom_position",
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});
it("absolute_layout_align_items_and_justify_content_center_and_left_position", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setJustifyContent(Yoga.JUSTIFY_CENTER);
@@ -652,9 +706,13 @@ it("absolute_layout_align_items_and_justify_content_center_and_left_position", f
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});
it("absolute_layout_align_items_and_justify_content_center_and_right_position", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setJustifyContent(Yoga.JUSTIFY_CENTER);
@@ -696,5 +754,36 @@ it("absolute_layout_align_items_and_justify_content_center_and_right_position",
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});
it("position_root_with_rtl_should_position_withoutdirection", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setPosition(Yoga.EDGE_LEFT, 72);
root.setWidth(52);
root.setHeight(52);
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_LTR);
console.assert(72 === root.getComputedLeft(), "72 === root.getComputedLeft() (" + root.getComputedLeft() + ")");
console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")");
console.assert(52 === root.getComputedWidth(), "52 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
console.assert(52 === root.getComputedHeight(), "52 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_RTL);
console.assert(72 === root.getComputedLeft(), "72 === root.getComputedLeft() (" + root.getComputedLeft() + ")");
console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")");
console.assert(52 === root.getComputedWidth(), "52 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
console.assert(52 === root.getComputedHeight(), "52 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
} finally {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});

View File

@@ -12,6 +12,8 @@
var Yoga = Yoga || require("../../sources/entry-" + process.env.TEST_ENTRY);
it("align_content_flex_start", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW);
@@ -110,9 +112,13 @@ it("align_content_flex_start", function () {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});
it("align_content_flex_start_without_height_on_children", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setFlexWrap(Yoga.WRAP_WRAP);
@@ -207,9 +213,13 @@ it("align_content_flex_start_without_height_on_children", function () {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});
it("align_content_flex_start_with_flex", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setFlexWrap(Yoga.WRAP_WRAP);
@@ -310,9 +320,13 @@ it("align_content_flex_start_with_flex", function () {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});
it("align_content_flex_end", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setAlignContent(Yoga.ALIGN_FLEX_END);
@@ -411,9 +425,13 @@ it("align_content_flex_end", function () {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});
it("align_content_stretch", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setAlignContent(Yoga.ALIGN_STRETCH);
@@ -507,9 +525,13 @@ it("align_content_stretch", function () {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});
it("align_content_spacebetween", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW);
@@ -609,9 +631,13 @@ it("align_content_spacebetween", function () {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});
it("align_content_spacearound", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW);
@@ -711,9 +737,13 @@ it("align_content_spacearound", function () {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});
it("align_content_stretch_row", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW);
@@ -808,9 +838,13 @@ it("align_content_stretch_row", function () {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});
it("align_content_stretch_row_with_children", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW);
@@ -921,9 +955,13 @@ it("align_content_stretch_row_with_children", function () {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});
it("align_content_stretch_row_with_flex", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW);
@@ -1024,9 +1062,13 @@ it("align_content_stretch_row_with_flex", function () {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});
it("align_content_stretch_row_with_flex_no_shrink", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW);
@@ -1126,9 +1168,13 @@ it("align_content_stretch_row_with_flex_no_shrink", function () {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});
it("align_content_stretch_row_with_margin", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW);
@@ -1231,9 +1277,13 @@ it("align_content_stretch_row_with_margin", function () {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});
it("align_content_stretch_row_with_padding", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW);
@@ -1336,9 +1386,13 @@ it("align_content_stretch_row_with_padding", function () {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});
it("align_content_stretch_row_with_single_row", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW);
@@ -1391,9 +1445,13 @@ it("align_content_stretch_row_with_single_row", function () {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});
it("align_content_stretch_row_with_fixed_height", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW);
@@ -1489,9 +1547,13 @@ it("align_content_stretch_row_with_fixed_height", function () {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});
it("align_content_stretch_row_with_max_height", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW);
@@ -1587,9 +1649,13 @@ it("align_content_stretch_row_with_max_height", function () {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});
it("align_content_stretch_row_with_min_height", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW);
@@ -1685,9 +1751,13 @@ it("align_content_stretch_row_with_min_height", function () {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});
it("align_content_stretch_column", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setAlignContent(Yoga.ALIGN_STRETCH);
@@ -1800,9 +1870,13 @@ it("align_content_stretch_column", function () {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});
it("align_content_stretch_is_not_overriding_align_items", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setAlignContent(Yoga.ALIGN_STRETCH);
@@ -1857,5 +1931,7 @@ it("align_content_stretch_is_not_overriding_align_items", function () {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});

View File

@@ -12,6 +12,8 @@
var Yoga = Yoga || require("../../sources/entry-" + process.env.TEST_ENTRY);
it("align_items_stretch", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setWidth(100);
@@ -47,9 +49,13 @@ it("align_items_stretch", function () {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});
it("align_items_center", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setAlignItems(Yoga.ALIGN_CENTER);
@@ -87,9 +93,13 @@ it("align_items_center", function () {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});
it("align_items_flex_start", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setAlignItems(Yoga.ALIGN_FLEX_START);
@@ -127,9 +137,13 @@ it("align_items_flex_start", function () {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});
it("align_items_flex_end", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setAlignItems(Yoga.ALIGN_FLEX_END);
@@ -167,9 +181,13 @@ it("align_items_flex_end", function () {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});
it("align_baseline", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW);
@@ -223,9 +241,13 @@ it("align_baseline", function () {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});
it("align_baseline_child", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW);
@@ -294,9 +316,13 @@ it("align_baseline_child", function () {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});
it("align_baseline_child_multiline", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW);
@@ -412,9 +438,13 @@ it("align_baseline_child_multiline", function () {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});
it("align_baseline_child_multiline_override", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW);
@@ -532,9 +562,13 @@ it("align_baseline_child_multiline_override", function () {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});
it("align_baseline_child_multiline_no_override_on_secondline", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW);
@@ -651,9 +685,13 @@ it("align_baseline_child_multiline_no_override_on_secondline", function () {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});
it("align_baseline_child_top", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW);
@@ -723,9 +761,13 @@ it("align_baseline_child_top", function () {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});
it("align_baseline_child_top2", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW);
@@ -795,9 +837,13 @@ it("align_baseline_child_top2", function () {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});
it("align_baseline_double_nested_child", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW);
@@ -881,9 +927,13 @@ it("align_baseline_double_nested_child", function () {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});
it("align_baseline_column", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setAlignItems(Yoga.ALIGN_BASELINE);
@@ -936,9 +986,13 @@ it("align_baseline_column", function () {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});
it("align_baseline_child_margin", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW);
@@ -1015,9 +1069,13 @@ it("align_baseline_child_margin", function () {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});
it("align_baseline_child_padding", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW);
@@ -1094,9 +1152,13 @@ it("align_baseline_child_padding", function () {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});
it("align_baseline_multiline", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW);
@@ -1211,9 +1273,13 @@ it("align_baseline_multiline", function () {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});
it("align_baseline_multiline_column", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setAlignItems(Yoga.ALIGN_BASELINE);
@@ -1327,9 +1393,13 @@ it("align_baseline_multiline_column", function () {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});
it("align_baseline_multiline_column2", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setAlignItems(Yoga.ALIGN_BASELINE);
@@ -1443,9 +1513,13 @@ it("align_baseline_multiline_column2", function () {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});
it("align_baseline_multiline_row_and_column", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW);
@@ -1560,5 +1634,247 @@ it("align_baseline_multiline_row_and_column", function () {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});
it("align_items_center_child_with_margin_bigger_than_parent", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setJustifyContent(Yoga.JUSTIFY_CENTER);
root.setAlignItems(Yoga.ALIGN_CENTER);
root.setWidth(52);
root.setHeight(52);
var root_child0 = Yoga.Node.create(config);
root_child0.setAlignItems(Yoga.ALIGN_CENTER);
root.insertChild(root_child0, 0);
var root_child0_child0 = Yoga.Node.create(config);
root_child0_child0.setMargin(Yoga.EDGE_LEFT, 10);
root_child0_child0.setMargin(Yoga.EDGE_RIGHT, 10);
root_child0_child0.setWidth(52);
root_child0_child0.setHeight(52);
root_child0.insertChild(root_child0_child0, 0);
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_LTR);
console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")");
console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")");
console.assert(52 === root.getComputedWidth(), "52 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
console.assert(52 === root.getComputedHeight(), "52 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
console.assert(-10 === root_child0.getComputedLeft(), "-10 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")");
console.assert(72 === root_child0.getComputedWidth(), "72 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")");
console.assert(52 === root_child0.getComputedHeight(), "52 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
console.assert(10 === root_child0_child0.getComputedLeft(), "10 === root_child0_child0.getComputedLeft() (" + root_child0_child0.getComputedLeft() + ")");
console.assert(0 === root_child0_child0.getComputedTop(), "0 === root_child0_child0.getComputedTop() (" + root_child0_child0.getComputedTop() + ")");
console.assert(52 === root_child0_child0.getComputedWidth(), "52 === root_child0_child0.getComputedWidth() (" + root_child0_child0.getComputedWidth() + ")");
console.assert(52 === root_child0_child0.getComputedHeight(), "52 === root_child0_child0.getComputedHeight() (" + root_child0_child0.getComputedHeight() + ")");
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_RTL);
console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")");
console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")");
console.assert(52 === root.getComputedWidth(), "52 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
console.assert(52 === root.getComputedHeight(), "52 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
console.assert(-10 === root_child0.getComputedLeft(), "-10 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")");
console.assert(72 === root_child0.getComputedWidth(), "72 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")");
console.assert(52 === root_child0.getComputedHeight(), "52 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
console.assert(10 === root_child0_child0.getComputedLeft(), "10 === root_child0_child0.getComputedLeft() (" + root_child0_child0.getComputedLeft() + ")");
console.assert(0 === root_child0_child0.getComputedTop(), "0 === root_child0_child0.getComputedTop() (" + root_child0_child0.getComputedTop() + ")");
console.assert(52 === root_child0_child0.getComputedWidth(), "52 === root_child0_child0.getComputedWidth() (" + root_child0_child0.getComputedWidth() + ")");
console.assert(52 === root_child0_child0.getComputedHeight(), "52 === root_child0_child0.getComputedHeight() (" + root_child0_child0.getComputedHeight() + ")");
} finally {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});
it("align_items_flex_end_child_with_margin_bigger_than_parent", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setJustifyContent(Yoga.JUSTIFY_CENTER);
root.setAlignItems(Yoga.ALIGN_CENTER);
root.setWidth(52);
root.setHeight(52);
var root_child0 = Yoga.Node.create(config);
root_child0.setAlignItems(Yoga.ALIGN_FLEX_END);
root.insertChild(root_child0, 0);
var root_child0_child0 = Yoga.Node.create(config);
root_child0_child0.setMargin(Yoga.EDGE_LEFT, 10);
root_child0_child0.setMargin(Yoga.EDGE_RIGHT, 10);
root_child0_child0.setWidth(52);
root_child0_child0.setHeight(52);
root_child0.insertChild(root_child0_child0, 0);
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_LTR);
console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")");
console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")");
console.assert(52 === root.getComputedWidth(), "52 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
console.assert(52 === root.getComputedHeight(), "52 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
console.assert(-10 === root_child0.getComputedLeft(), "-10 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")");
console.assert(72 === root_child0.getComputedWidth(), "72 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")");
console.assert(52 === root_child0.getComputedHeight(), "52 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
console.assert(10 === root_child0_child0.getComputedLeft(), "10 === root_child0_child0.getComputedLeft() (" + root_child0_child0.getComputedLeft() + ")");
console.assert(0 === root_child0_child0.getComputedTop(), "0 === root_child0_child0.getComputedTop() (" + root_child0_child0.getComputedTop() + ")");
console.assert(52 === root_child0_child0.getComputedWidth(), "52 === root_child0_child0.getComputedWidth() (" + root_child0_child0.getComputedWidth() + ")");
console.assert(52 === root_child0_child0.getComputedHeight(), "52 === root_child0_child0.getComputedHeight() (" + root_child0_child0.getComputedHeight() + ")");
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_RTL);
console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")");
console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")");
console.assert(52 === root.getComputedWidth(), "52 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
console.assert(52 === root.getComputedHeight(), "52 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
console.assert(-10 === root_child0.getComputedLeft(), "-10 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")");
console.assert(72 === root_child0.getComputedWidth(), "72 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")");
console.assert(52 === root_child0.getComputedHeight(), "52 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
console.assert(10 === root_child0_child0.getComputedLeft(), "10 === root_child0_child0.getComputedLeft() (" + root_child0_child0.getComputedLeft() + ")");
console.assert(0 === root_child0_child0.getComputedTop(), "0 === root_child0_child0.getComputedTop() (" + root_child0_child0.getComputedTop() + ")");
console.assert(52 === root_child0_child0.getComputedWidth(), "52 === root_child0_child0.getComputedWidth() (" + root_child0_child0.getComputedWidth() + ")");
console.assert(52 === root_child0_child0.getComputedHeight(), "52 === root_child0_child0.getComputedHeight() (" + root_child0_child0.getComputedHeight() + ")");
} finally {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});
it("align_items_center_child_without_margin_bigger_than_parent", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setJustifyContent(Yoga.JUSTIFY_CENTER);
root.setAlignItems(Yoga.ALIGN_CENTER);
root.setWidth(52);
root.setHeight(52);
var root_child0 = Yoga.Node.create(config);
root_child0.setAlignItems(Yoga.ALIGN_CENTER);
root.insertChild(root_child0, 0);
var root_child0_child0 = Yoga.Node.create(config);
root_child0_child0.setWidth(72);
root_child0_child0.setHeight(72);
root_child0.insertChild(root_child0_child0, 0);
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_LTR);
console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")");
console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")");
console.assert(52 === root.getComputedWidth(), "52 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
console.assert(52 === root.getComputedHeight(), "52 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
console.assert(-10 === root_child0.getComputedLeft(), "-10 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
console.assert(-10 === root_child0.getComputedTop(), "-10 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")");
console.assert(72 === root_child0.getComputedWidth(), "72 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")");
console.assert(72 === root_child0.getComputedHeight(), "72 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
console.assert(0 === root_child0_child0.getComputedLeft(), "0 === root_child0_child0.getComputedLeft() (" + root_child0_child0.getComputedLeft() + ")");
console.assert(0 === root_child0_child0.getComputedTop(), "0 === root_child0_child0.getComputedTop() (" + root_child0_child0.getComputedTop() + ")");
console.assert(72 === root_child0_child0.getComputedWidth(), "72 === root_child0_child0.getComputedWidth() (" + root_child0_child0.getComputedWidth() + ")");
console.assert(72 === root_child0_child0.getComputedHeight(), "72 === root_child0_child0.getComputedHeight() (" + root_child0_child0.getComputedHeight() + ")");
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_RTL);
console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")");
console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")");
console.assert(52 === root.getComputedWidth(), "52 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
console.assert(52 === root.getComputedHeight(), "52 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
console.assert(-10 === root_child0.getComputedLeft(), "-10 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
console.assert(-10 === root_child0.getComputedTop(), "-10 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")");
console.assert(72 === root_child0.getComputedWidth(), "72 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")");
console.assert(72 === root_child0.getComputedHeight(), "72 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
console.assert(0 === root_child0_child0.getComputedLeft(), "0 === root_child0_child0.getComputedLeft() (" + root_child0_child0.getComputedLeft() + ")");
console.assert(0 === root_child0_child0.getComputedTop(), "0 === root_child0_child0.getComputedTop() (" + root_child0_child0.getComputedTop() + ")");
console.assert(72 === root_child0_child0.getComputedWidth(), "72 === root_child0_child0.getComputedWidth() (" + root_child0_child0.getComputedWidth() + ")");
console.assert(72 === root_child0_child0.getComputedHeight(), "72 === root_child0_child0.getComputedHeight() (" + root_child0_child0.getComputedHeight() + ")");
} finally {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});
it("align_items_flex_end_child_without_margin_bigger_than_parent", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setJustifyContent(Yoga.JUSTIFY_CENTER);
root.setAlignItems(Yoga.ALIGN_CENTER);
root.setWidth(52);
root.setHeight(52);
var root_child0 = Yoga.Node.create(config);
root_child0.setAlignItems(Yoga.ALIGN_FLEX_END);
root.insertChild(root_child0, 0);
var root_child0_child0 = Yoga.Node.create(config);
root_child0_child0.setWidth(72);
root_child0_child0.setHeight(72);
root_child0.insertChild(root_child0_child0, 0);
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_LTR);
console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")");
console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")");
console.assert(52 === root.getComputedWidth(), "52 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
console.assert(52 === root.getComputedHeight(), "52 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
console.assert(-10 === root_child0.getComputedLeft(), "-10 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
console.assert(-10 === root_child0.getComputedTop(), "-10 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")");
console.assert(72 === root_child0.getComputedWidth(), "72 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")");
console.assert(72 === root_child0.getComputedHeight(), "72 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
console.assert(0 === root_child0_child0.getComputedLeft(), "0 === root_child0_child0.getComputedLeft() (" + root_child0_child0.getComputedLeft() + ")");
console.assert(0 === root_child0_child0.getComputedTop(), "0 === root_child0_child0.getComputedTop() (" + root_child0_child0.getComputedTop() + ")");
console.assert(72 === root_child0_child0.getComputedWidth(), "72 === root_child0_child0.getComputedWidth() (" + root_child0_child0.getComputedWidth() + ")");
console.assert(72 === root_child0_child0.getComputedHeight(), "72 === root_child0_child0.getComputedHeight() (" + root_child0_child0.getComputedHeight() + ")");
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_RTL);
console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")");
console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")");
console.assert(52 === root.getComputedWidth(), "52 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
console.assert(52 === root.getComputedHeight(), "52 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
console.assert(-10 === root_child0.getComputedLeft(), "-10 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
console.assert(-10 === root_child0.getComputedTop(), "-10 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")");
console.assert(72 === root_child0.getComputedWidth(), "72 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")");
console.assert(72 === root_child0.getComputedHeight(), "72 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
console.assert(0 === root_child0_child0.getComputedLeft(), "0 === root_child0_child0.getComputedLeft() (" + root_child0_child0.getComputedLeft() + ")");
console.assert(0 === root_child0_child0.getComputedTop(), "0 === root_child0_child0.getComputedTop() (" + root_child0_child0.getComputedTop() + ")");
console.assert(72 === root_child0_child0.getComputedWidth(), "72 === root_child0_child0.getComputedWidth() (" + root_child0_child0.getComputedWidth() + ")");
console.assert(72 === root_child0_child0.getComputedHeight(), "72 === root_child0_child0.getComputedHeight() (" + root_child0_child0.getComputedHeight() + ")");
} finally {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});

View File

@@ -12,6 +12,8 @@
var Yoga = Yoga || require("../../sources/entry-" + process.env.TEST_ENTRY);
it("align_self_center", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setWidth(100);
@@ -49,9 +51,13 @@ it("align_self_center", function () {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});
it("align_self_flex_end", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setWidth(100);
@@ -89,9 +95,13 @@ it("align_self_flex_end", function () {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});
it("align_self_flex_start", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setWidth(100);
@@ -129,9 +139,13 @@ it("align_self_flex_start", function () {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});
it("align_self_flex_end_override_flex_start", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setAlignItems(Yoga.ALIGN_FLEX_START);
@@ -170,9 +184,13 @@ it("align_self_flex_end_override_flex_start", function () {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});
it("align_self_baseline", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW);
@@ -242,5 +260,7 @@ it("align_self_baseline", function () {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});

View File

@@ -12,6 +12,8 @@
var Yoga = Yoga || require("../../sources/entry-" + process.env.TEST_ENTRY);
it("border_no_size", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setBorder(Yoga.EDGE_LEFT, 10);
@@ -35,9 +37,13 @@ it("border_no_size", function () {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});
it("border_container_match_child", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setBorder(Yoga.EDGE_LEFT, 10);
@@ -76,9 +82,13 @@ it("border_container_match_child", function () {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});
it("border_flex_child", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setBorder(Yoga.EDGE_LEFT, 10);
@@ -119,9 +129,13 @@ it("border_flex_child", function () {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});
it("border_stretch_child", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setBorder(Yoga.EDGE_LEFT, 10);
@@ -161,9 +175,13 @@ it("border_stretch_child", function () {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});
it("border_center_child", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setJustifyContent(Yoga.JUSTIFY_CENTER);
@@ -205,5 +223,7 @@ it("border_center_child", function () {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});

Some files were not shown because too many files have changed in this diff Show More