Compare commits

..

164 Commits

Author SHA1 Message Date
Georgiy Kassabli
b5c2b09780 Revert D4456312: Fix for Yoga test failure for flexing with min stack dimension
Summary: This reverts commit 82a39bc93cf3bf2374b968e9f7403397e752908e

Differential Revision: D4456312

fbshipit-source-id: 6b396f0a8b67619308456599377238b75d0c1ab3
2017-02-07 05:18:19 -08:00
Antonio Corrado
46817a38c3 Setting min=max dimension is treated as setting dimension
Summary: If a node has minDimension and maxDimension set at the same value, yoga will treat it as having a set dimension, doing less calculations.

Reviewed By: emilsjolander

Differential Revision: D4492395

fbshipit-source-id: 3f4293548399e006aa808b9586d24e77c7df1f21
2017-02-06 14:41:37 -08:00
Georgiy Kassabli
52f3471405 Fix for Yoga test failure for flexing with min stack dimension
Summary: Test fails when we have flexible child and min/max layout dimension. Yoga should flex the child to minimal size, while in reality Yoga flexes it to maximal size

Reviewed By: emilsjolander

Differential Revision: D4456312

fbshipit-source-id: 82a39bc93cf3bf2374b968e9f7403397e752908e
2017-02-06 13:00:42 -08:00
Lukas Wöhrl
e567502750 Added property display: flex and none
Summary:
Fix #241 and successor for #302

Added new property ```display``` with ```YGDisplayFlex``` and ```YGDisplayNone```. Allows to hide nodes from the layout without the need to remove it from the DOM.
Closes https://github.com/facebook/yoga/pull/369

Reviewed By: astreet

Differential Revision: D4501141

Pulled By: emilsjolander

fbshipit-source-id: 0dfeee381f6d1e4bbba81926126b83dd7abab9d6
2017-02-06 09:39:37 -08:00
Dustin Shahidehpour
c1cdc1de58 Fix warnings about icon assets.
Summary:
I incorrectly sized some assets, as a result, the sample project had some warnings about it when you built. This fixes it.
Closes https://github.com/facebook/yoga/pull/377

Differential Revision: D4515193

Pulled By: dshahidehpour

fbshipit-source-id: 3af6e79a17777bec3798bbf7294af5716f65e37a
2017-02-06 07:39:33 -08:00
Dustin Shahidehpour
f2c41f366f Made YogaKitSample build again, use cocoapods, add icon images.
Summary: The Sample app needed some love. It wouldn't build because of some import errors, adding files is very manual, and it looked bad. I have fixed all of these things.

Reviewed By: amonshiz

Differential Revision: D4508624

fbshipit-source-id: bda40defb167ef871d8d0d5bb853d8905b9682d8
2017-02-03 13:39:35 -08:00
Emil Sjolander
56d06e27cf Pass parent with down with calculateLayout to allow percentages on root node
Summary: For percentage paddings/margins/sizes to work on the root node we need to have the ability to pass down the parent sizes. This has always been possible with the C API but was never exposed to java. This diff exposes this functionality.

Reviewed By: astreet

Differential Revision: D4501016

fbshipit-source-id: 0c9502e86ff200c021c78afb7ac4b48cf11b3bdb
2017-02-03 11:24:57 -08:00
Emil Sjolander
93e327f4a5 Return raw edge style value now that we have layout outputs for them
Summary: Previously we needed to be able to return a computed value from the style edge getters to correctly handle things like RTL in frameworks such as React Native. However we now have a more correct solution with is to expose layout outputs for these edge values. This means we can go back to returning the raw value set for padding/margin/border like we do with other styles.

Reviewed By: astreet

Differential Revision: D4500892

fbshipit-source-id: e7c26bdda9ecbfc76b6cf1f384f8cf9f38284120
2017-02-03 11:24:57 -08:00
Dustin Shahidehpour
687668a4b3 Move podspec to root directory.
Summary: For our YogaKit sample project we want to add Cocoapods support and reference the local podspec. Unfortunately, this won't work unless the podspec lives in the root directory.

Reviewed By: emilsjolander

Differential Revision: D4507887

fbshipit-source-id: 919a8c8506768c90e50b3ae27deb51394db021e6
2017-02-03 10:24:55 -08:00
Emil Sjolander
cfeac79130 Fix percentage calculation when parent size is undefined
Summary: If parent size was undefined and node specified percentage size it would pass does an exact measure mode with an undefined value which broke an assertion.

Reviewed By: gkassabli

Differential Revision: D4494265

fbshipit-source-id: 9efef9e39a1b66af2d0f144575a96c919d60dbf7
2017-02-03 05:40:00 -08:00
Emil Sjolander
4227e36ca5 Add tests for wrapping to child size
Summary: Add tests for container wrapping child size

Reviewed By: gkassabli

Differential Revision: D4494263

fbshipit-source-id: bebfdd4a180b0ccd8dbb14e566613f1e64fabd7a
2017-02-03 05:40:00 -08:00
Emil Sjolander
be1c9f249e Take parent size into account when determining if style dim is defined
Summary: Ensure that a percentage size is only "defined" if the parent size is defined.

Reviewed By: gkassabli

Differential Revision: D4494258

fbshipit-source-id: 36c31444cbd113a820b067fe9e7b9560ae1d4df7
2017-02-03 05:40:00 -08:00
Lukas Wöhrl
511a129a7e Generate enums in sorted order
Summary:
This PR forces the order of the generated enums in alphabetically order. This is needed to have a predictable order of the enums across different python versions. Which reduces the pain for merging multiple enum additions.
Closes https://github.com/facebook/yoga/pull/370

Reviewed By: gkassabli

Differential Revision: D4501140

Pulled By: emilsjolander

fbshipit-source-id: 66c0ed9e4ea7a5990578b53b0a7e400c13dd53a9
2017-02-03 04:24:36 -08:00
Emil Sjolander
d62ca8c518 Use fromInt() instead of indexing values() as it allocates a new array
Summary: values() create a shallow copy of the underlying array every time as there are no immutable arrays in java. By using fromInt() we avoid this allocation.

Reviewed By: pasqualeanatriello

Differential Revision: D4494371

fbshipit-source-id: 11cff65114803e185bc67a96da0bf2a2c4a3e6d9
2017-02-02 15:39:33 -08:00
Pascal Hartig
30413265c7 Remove docs/CONTRIBUTING.md
Summary: Remove the outdated `CONTRIBUTING.md`.

Reviewed By: emilsjolander

Differential Revision: D4500973

fbshipit-source-id: 955395887330287f9973bfc21714a2c24c1fac2a
2017-02-02 05:54:39 -08:00
Pascal Hartig
bd5d8a77c9 Restore basedir format.sh behavior
Summary: Ensure that `format.sh` can be run from anywhere with the same results.

Reviewed By: emilsjolander

Differential Revision: D4494367

fbshipit-source-id: cbd2cc36476a0a54a77a732cbe1b79388f7e0c46
2017-02-01 02:39:33 -08:00
Pascal Hartig
326ae15532 Format C/C++ files
Summary: Run new `format.sh`.

Reviewed By: emilsjolander

Differential Revision: D4481501

fbshipit-source-id: 5791bee9919b44282d1549029ff8e078f253ddf8
2017-01-31 09:40:19 -08:00
Pascal Hartig
9afb65da34 Regenerate test comments
Reviewed By: emilsjolander

Differential Revision: D4482049

fbshipit-source-id: c30a6550ed175811df29c24ba03af92f3bd32713
2017-01-31 09:40:19 -08:00
Pascal Hartig
fe7643c84a Update gentest to match formatter
Reviewed By: emilsjolander

Differential Revision: D4482028

fbshipit-source-id: c6e1e0ecb0475fba62d25858c9e9960eab2701dc
2017-01-31 09:40:19 -08:00
Pascal Hartig
6daad3ae66 Update format.sh
Summary:
The format.sh was referring to an outdated `benchmarks/` directory and left out
a bunch of other C/C++ files. This updates it to cover all but the build
artifacts and vendored libraries in `lib/`.

Reviewed By: emilsjolander

Differential Revision: D4481490

fbshipit-source-id: 056e00359f794d0aa999fd65ec1ef0c657738867
2017-01-31 09:40:18 -08:00
Maël Nison
44590b8907 Updates the js build
Summary:
I've updated the js build. Let's see what Travis thinks of it!
Closes https://github.com/facebook/yoga/pull/365

Reviewed By: dshahidehpour

Differential Revision: D4488099

Pulled By: emilsjolander

fbshipit-source-id: d56ee2ccbfec84f766fcfdec9bcc9c5f610a6b0e
2017-01-31 08:39:32 -08:00
orta
4400b52aab Add support for showing the YogaKit README on CocoaPods.org
Summary:
Hey there, congrats on the launch - we use React Native at Artsy, and I've been wondering about what Yoga + Jest Snapshots for RN looks like but haven't had the time to explore that yet.

With https://github.com/CocoaPods/cocoadocs.org/pull/501 I added the ability to customize the location of the README for the front-page of the CocoaPods site. That is being deployed as I speak, so it should be available the next time you decide to ship a version of Yoga.

I also fixed the capitalisation of CocoaPods, and removed a redundant CocoaPods badge on your initial README.
Closes https://github.com/facebook/yoga/pull/366

Reviewed By: emilsjolander

Differential Revision: D4488011

Pulled By: dshahidehpour

fbshipit-source-id: 6c0c4efc23a69e1fcb936214b159b49217218b49
2017-01-31 07:39:45 -08:00
Dustin Shahidehpour
c217553cf8 Add README.md
Summary: This gives YogaKit its' own readme. #accept2ship

Reviewed By: emilsjolander

Differential Revision: D4482411

fbshipit-source-id: 24ddab586d9a12a8419ae8811fa4d03b27c1a19e
2017-01-30 11:09:45 -08:00
Emil Sjolander
6ad5003149 Align Yoga and YogaKit pod specs
Summary: Make the two podspecs more consistent with each other.

Reviewed By: dshahidehpour

Differential Revision: D4481945

fbshipit-source-id: ab782abecd709c763b4e931b6839a5cae6346281
2017-01-30 08:54:35 -08:00
Lukas Wöhrl
7c77b0e48c Fix syntax error in YGMarginTest.html
Summary:
Fixes wrongly used  ```;``` inside style declaration.
Closes https://github.com/facebook/yoga/pull/360

Reviewed By: astreet

Differential Revision: D4476067

Pulled By: emilsjolander

fbshipit-source-id: 332cdcd9a832eebc68a6d73840c1d5a10078eb66
2017-01-30 08:39:35 -08:00
Dustin Shahidehpour
7b36118df4 Add issue template.
Summary: When people file issues, they are (in-general) missing a lot of useful information. This template will now be included when people file issues. More info here: https://github.com/blog/2111-issue-and-pull-request-templates

Reviewed By: emilsjolander

Differential Revision: D4481713

fbshipit-source-id: 8c173e282438d5156d50fe40c581e18730d6a5af
2017-01-30 07:39:38 -08:00
Dustin Shahidehpour
7f0dbe5356 Add deployment target to podspec.
Summary: Without specifying the deployment target, it was default to iOS 4.3. This would cause a build error because we are `unable to synthesize weak properties` which didn't come around until iOS 5. Setting default target to iOS 8.

Reviewed By: emilsjolander

Differential Revision: D4481772

fbshipit-source-id: d3be88d0f73533c6242fc1d9045c70ad4628fd21
2017-01-30 07:39:38 -08:00
Maël Nison
b87fc217df Silents errors when running copy-sources
Summary:
Being a environment test, `npm run is-monolithic` is expected to fail when pulling the package from npm and to succeed when pulling it from github. Unfortunately, when returning false, npm will throw a tantrum by default if not explicitely disabled. It's not a hard failure, the build still complete, but it's better this way.
Closes https://github.com/facebook/yoga/pull/362

Reviewed By: gkassabli

Differential Revision: D4480608

Pulled By: emilsjolander

fbshipit-source-id: 0832a2158647f49b5230e2f658997f94774cec5b
2017-01-30 06:24:33 -08:00
Emil Sjolander
625dc4bf44 Version bump
Summary: Bump version and publish to npm + cocoapods

Reviewed By: dshahidehpour

Differential Revision: D4479027

fbshipit-source-id: 42aa81de1a5a07e3a2814670ad1cf3774519b353
2017-01-28 11:09:35 -08:00
Rui Marinho
34736a4929 Add Xamarin Android support
Summary:
Adds a Xamarin Android support for Yoga and respective tests. Closes #276 with this PR all Xamarin platforms will be covered

Need to figure a better strategy for the build names for buck with splhack .

It's failing 3 tests related with YogaNode and the GC :) classic!

![screenshot_1484353863](https://cloud.githubusercontent.com/assets/1235097/21950981/61020212-d9f8-11e6-80e1-185bd1707f9a.png)

```
Facebook.Yoga.Android.Tests.dll : 660.87 ms
 : 678.788 ms
Tests run: 130, Passed: 127, Failed: 3, Skipped: 0, Inconclusive: 0
```
Closes https://github.com/facebook/yoga/pull/340

Reviewed By: emilsjolander

Differential Revision: D4475370

Pulled By: splhack

fbshipit-source-id: f050f10415e68e9808f629b843682b0f87cca065
2017-01-27 17:54:34 -08:00
Emil Sjolander
4f37cde043 re-generate js build
Summary: npm run build:all

Reviewed By: dshahidehpour

Differential Revision: D4477027

fbshipit-source-id: 107e13134145df18a788e079be467b27d1893118
2017-01-27 14:24:40 -08:00
Guido Marucci Blas
7df60376ff CocoaPods support.
Summary:
This supersedes #309 and #305.

This is still a **work-in-progress.**

**TODO**

 - [x] Create Xcode project that builds an iOS framework
 - [x] Fix failing tests on Xcode
 - [ ] Make `pod lib lint` pass and make sure YogaKit can be included using CocoaPods
 - [ ] Add `pod lib lint` to .travis.yml
 - [x] Migrate to travis osx image with Xcode 8.2

**FOLLOW-UP**
  - [ ] Make YogaKitSample use framework built by new Xcode project.
  - [ ] Make Travis to upload prebuilt versions of the framework. More [here](https://github.com/Carthage/Carthage#use-travis-ci-to-upload-your-tagged-prebuild-frameworks)
  - [ ] Upgrade github/jekyll docs about installation using Cocoapods/Carthage
Closes https://github.com/facebook/yoga/pull/352

Reviewed By: emilsjolander

Differential Revision: D4471950

Pulled By: dshahidehpour

fbshipit-source-id: 8f30c69f9a487b26aa2e5f3b66841334b01b0ab1
2017-01-27 10:09:48 -08:00
Emil Sjolander
7fa4adb0d9 Fix aspectratio with margins
Summary: aspect ratio did not account for the widths and heights being including padding. This diff fixes that.

Reviewed By: astreet

Differential Revision: D4473024

fbshipit-source-id: 5a747e2f267b077203bb3b63e4c152847dc30774
2017-01-27 10:09:48 -08:00
Kazuki Sakamoto
abb91ae77b Remove deprecated code
Summary: - Remove classes and methods marked as `Obsolete`

Reviewed By: emilsjolander

Differential Revision: D4474945

fbshipit-source-id: 43552fa638c8b321603858a862a386c5296db2fa
2017-01-27 09:09:36 -08:00
Dustin Shahidehpour
a4b1ac83f4 Update README.md to include Pod Shield
Summary: Closes https://github.com/facebook/yoga/pull/356

Differential Revision: D4471126

Pulled By: dshahidehpour

fbshipit-source-id: 362a92225c8267cb89b12b45a98f69adf726c42d
2017-01-26 14:40:07 -08:00
Emil Sjolander
8775cdc13f Format and run codegen
Summary: run format & gentest scripts. Some of the javascript tests had not been generated recently by the looks of it.

Reviewed By: dshahidehpour

Differential Revision: D4459455

fbshipit-source-id: fc1eca58fe897c8f4a2571638b4f7035d023b479
2017-01-26 13:39:42 -08:00
Maël Nison
db732ce9fa Add YGLayoutGetBorder, counterpart of YGLayoutGetPadding
Summary:
Followup of #335, fix #326. This commit add the `YGLayoutGetBorder(node, edge)` function, which correctly takes RTL/LTR into account when resolving `EDGE_START` & `EDGE_END`.
Closes https://github.com/facebook/yoga/pull/344

Reviewed By: dshahidehpour

Differential Revision: D4459950

Pulled By: emilsjolander

fbshipit-source-id: b57eb7a5b1c181a364913c3200a3794a2b7b31a6
2017-01-26 13:39:42 -08:00
Lukas Wöhrl
7c09244c39 Fix absolute position if align-item or justify-content is center or flex-end
Summary:
Fix #310 (```center```)

additionally fixes if ```flex-end``` is set.
Closes https://github.com/facebook/yoga/pull/349

Reviewed By: dshahidehpour

Differential Revision: D4458528

Pulled By: emilsjolander

fbshipit-source-id: f073c80bfc3ea6675cb95b00283074d10e91a042
2017-01-26 13:39:41 -08:00
Dustin Shahidehpour
2cc2a5f2ff Add podspec for C-Library.
Summary: This is the first step to adding cocoapods support to YogaKit. We are going to publish a `Yoga` framework to the store that we can use as a dependency. This will also allow developers to build their own abstractions easily using the core API.

Reviewed By: nlutsenko, emilsjolander

Differential Revision: D4466788

fbshipit-source-id: 8f08bdbf524e57c88f7fc3400c4ba6ad58f98d7f
2017-01-26 10:39:36 -08:00
Lukas Wöhrl
e4b50f2a8d Fix unnecessary measure calls
Summary:
Fix #334
Closes https://github.com/facebook/yoga/pull/347

Reviewed By: dshahidehpour

Differential Revision: D4455438

Pulled By: emilsjolander

fbshipit-source-id: 013c89e71757d9048708ec85cbb6af9f33ac1ea6
2017-01-24 19:09:32 -08:00
Emil Sjolander
a2a84532ff Dont constrain absolute children to zero sized parents
Summary: Absolute children should not be constraint to the size of their parent if the parent does not have a size as this was causes the layout of the child to be skipped.

Reviewed By: gkassabli

Differential Revision: D4453612

fbshipit-source-id: e8269521560d2f42b2d6f0f0ff264a1605a57d79
2017-01-24 17:09:34 -08:00
Emil Sjolander
d391323129 Use findClassStatic instead of findClassLocal
Summary: We are saving the class reference in a static variable to should be using findClassStatic to ensure the reference is always valid.

Reviewed By: mhorowitz

Differential Revision: D4420352

fbshipit-source-id: 8c66c1b2213fe295334a9bdc4e1dd7e1a4285aae
2017-01-24 15:54:31 -08:00
David Hart
ab28ecf31b Improve test readability
Summary:
I did some stylistic changes to the Objective-C unit tests for the following reasons:

- When an equality assert fails, the error messages reads as if the value we are testing is the first argument and the value we expect is the second argument. To improve the readability of test messages, I made sure all `XCTAssertEqual` and `XCTAssertNotEqual` have the arguments in the correct order.

- Because failing equality asserts already comes with a detailed message including the value tested and the expected value, I rewrote several truth asserts on `CGSizeEqual` to two equality asserts on the width and height: when those fail, the error message are clearer.
Closes https://github.com/facebook/yoga/pull/351

Reviewed By: emilsjolander

Differential Revision: D4454484

Pulled By: dshahidehpour

fbshipit-source-id: 0c1295a4a7e8477eacfb3f4ef6648984fd102a51
2017-01-24 10:09:32 -08:00
Dustin Shahidehpour
a4bab68802 Make YogaKit tests pass whether they are run in Xcode or BUCK.
Summary: Currently, some YogaKit tests fail when they are run in Xcode, but pass in BUCK. This cleans up the tests so that they more definitively test what they say they are testing, and the results are not affected by the enviroment they are run in.

Reviewed By: emilsjolander

Differential Revision: D4453745

fbshipit-source-id: 238e41960afe63d31e9f6efdcd947cfac39f2dc4
2017-01-23 19:39:37 -08:00
Dustin Shahidehpour
e3cfacf0cb Upgrade Travis to Xcode 8.2
Summary:
Doing this externally to trigger a Travis build. This will put our Travis infra on the newest Xcode.
Closes https://github.com/facebook/yoga/pull/353

Reviewed By: emilsjolander

Differential Revision: D4453795

Pulled By: dshahidehpour

fbshipit-source-id: 23416405fdd43486c934bea0b720c217fafd7f30
2017-01-23 19:39:37 -08:00
Ahmed El-Helw
8d74e01f41 Fix typo in generated Yoga classes
Reviewed By: emilsjolander

Differential Revision: D4416273

fbshipit-source-id: fa3f87b86560121e1186cdc0ee295eb052fb3a97
2017-01-19 16:24:33 -08:00
David Hart
5404bb13d4 Fix bugs introduced with YogaKit improvements
Summary:
I'm trying to fix some bugs I introduced in my latest PR, but while writing the Unit Tests for them, I saw a really weird behaviour. The following exact piece of code WORKS inside a Yoga C++ unit test, but fails from a Objective-C unit test. I had me completely confused and blocked me in my progression. Any ideas?

```
TEST(YogaTest, stupid_test) {
  const YGNodeRef node = YGNodeNew();
  YGNodeStyleSetPosition(node, YGEdgeLeft, 1);

  ASSERT_FLOAT_EQ(1, YGNodeStyleGetPosition(node, YGEdgeLeft).value);
  ASSERT_EQ(YGUnitPixel, YGNodeStyleGetPosition(node, YGEdgeLeft).unit);

  YGNodeFree(node);
}

```

```
- (void)testPositionalPropertiesWork
{
  YGNodeRef node = YGNodeNew();
  YGNodeStyleSetPosition(node, YGEdgeLeft, 1);

  XCTAssertEqual(1, YGNodeStyleGetPosition(node, YGEdgeLeft).value);
  XCTAssertEqual(YGUnitPixel, YGNodeStyleGetPosition(node, YGEdgeLeft).unit);

  YGNodeFree(node);
}
```
Closes https://github.com/facebook/yoga/pull/328

Reviewed By: dshahidehpour

Differential Revision: D4421504

Pulled By: emilsjolander

fbshipit-source-id: f59379edf70aee87a77cd1ad2986313cdfe71b94
2017-01-18 09:24:35 -08:00
Lukas Woehrl
be8773fee0 Fix wraping calculation if min-size constraint exists
Summary:
Fixes #261
Closes https://github.com/facebook/css-layout/pull/262

Reviewed By: splhack

Differential Revision: D4245200

Pulled By: emilsjolander

fbshipit-source-id: 77d802d71010ed426511d6a01e6de1e7c9194179
2017-01-16 16:24:35 -08:00
Emil Sjolander
0bcec80dfe BREAKING - Fix sizing of container with child overflowing parent
Summary:
Fixes issue brought up in https://github.com/facebook/react-native/issues/10603

The gist of the problem is that in css it is fine for a child to overflow a parent if it feels the need to, we were not respecting this.

Reviewed By: mmmulani

Differential Revision: D4182141

fbshipit-source-id: c73fd15d2577ab846fc8a202d529d0e6e1207b75
2017-01-16 11:09:32 -08:00
Thanabodee Charoenpiriyakij
2c8c2bffda Edit README.md in Benchmarks section
Summary:
Benchmarks are not located in folder benchmark. So rename folder
and buck target from 'benchmarks' to 'benchmark'.
Closes https://github.com/facebook/yoga/pull/339

Reviewed By: gkassabli

Differential Revision: D4420355

Pulled By: emilsjolander

fbshipit-source-id: 7a1bc6ece7f4b64c7cac506357e265c1b4790a4f
2017-01-16 10:39:37 -08:00
Maël Nison
d70f289e73 Add YGLayoutGetMargin
Summary:
Fix #326. I'll open another PR once this one gets accepted to add support for `YGLayoutGetBorder` 👌
Closes https://github.com/facebook/yoga/pull/335

Reviewed By: gkassabli

Differential Revision: D4409399

Pulled By: emilsjolander

fbshipit-source-id: 8153f6701cab60b55a485f6d2e0b9f7767481090
2017-01-15 15:24:30 -08:00
Rui Marinho
498a5980e8 Add YogaKit Shared and iOS version
Summary:
Using shared code for reuse in other platforms based on iOS native implementation.

Adds YogaKit sample.

Adds YogaKit tests (same as objc).

```
YogaKitTest : 80 ms
Facebook.YogaKit.iOS.Tests.exe : 81 ms
Tests run: 11 Passed: 8 Inconclusive: 0 Failed: 3 Ignored: 1
```

Since we don't have extension properties we need to go with a extension method to get access to the YogaLayout .

I m also not sure this is leak free yet, would love some help with testing and feedback about view/node lifecycle
Closes https://github.com/facebook/yoga/pull/336

Reviewed By: splhack

Differential Revision: D4415027

Pulled By: emilsjolander

fbshipit-source-id: c88328212426c3200e6f0c48cda594cd2c432065
2017-01-15 14:54:29 -08:00
Rui Marinho
8021c5d968 Fix test bug
Summary:
Simple fix on a possible copy paste error. The test actually passes the same way by coincidence.
Closes https://github.com/facebook/yoga/pull/338

Reviewed By: dshahidehpour

Differential Revision: D4415019

Pulled By: emilsjolander

fbshipit-source-id: 823c3efc821db14b70d9dfe99ef87d1d7ebb75d0
2017-01-15 14:54:29 -08:00
Kazuki Sakamoto
c536ab214d Update buck build in Visual Studio
Summary:
- Always launch buck build for Build, but copy native library when it was changed
- Rename Facebook.Yoga.Mac.Test to Facebook.Yoga.Mac.Sample
- Add Facebook.Yoga.Mac.Tests for NUnit test.
  - "Run Unit Tests" menu item was activated for the target, but Mono still can't find libyoga.dylib
Closes https://github.com/facebook/yoga/pull/332

Reviewed By: emilsjolander

Differential Revision: D4408799

Pulled By: splhack

fbshipit-source-id: b3f5f9ebd8265cc152ca859176afbf54efa8f170
2017-01-12 10:24:54 -08:00
Dustin Shahidehpour
adb81e2a1e Update docs to show new API.
Summary: Need API needs some new docs. I also removed the repo's `.hgignore` and added everything to fbobjc `.hgignore` via `./Tools/generate_hgignore.py` which uses Yoga's `.gitignore`.

Reviewed By: emilsjolander

Differential Revision: D4403967

fbshipit-source-id: f2158e4feb27953d1d9e21c775926e6207220c4a
2017-01-12 10:24:53 -08:00
Kazuki Sakamoto
c4a3e12add Launch buck from Visual Studio (Xamarin Studio) for Mac and iOS
Summary:
Launch buck from Visual Studio before `CopyInNativeLib` in `CompileDependsOn`
- Mac `buck build //csharp:yoganet#default,shared`
- iOS `buck build //csharp:yoganet-ios`

Reviewed By: emilsjolander

Differential Revision: D4403163

fbshipit-source-id: 2e5fd3fd154ef53574129ac9cb834ae3a58f2466
2017-01-11 07:54:35 -08:00
Rui Marinho
a3d7d72421 Xamarin iOS Support
Summary:
Since there's a couple of changes after last month pr of #280 , here's a new pr for Xamarin support #276 , the idea is to add Xamarin iOS, Mac and Android support.

- Add Xamarin iOS support for Yoga, by providing a wrapper for the native lib.
- Add Xamarin iOS Unit testing project
~~- Adds a YogaKit shared implementation in c#.~~
~~- Adds a YogaKIt iOS implementation.~~
~~- Adds Yoga/YogaKit iOS sample application~~

Facebook.Yoga.iOS.Tests.exe : 169 ms
Tests run: 114 Passed: 114 Inconclusive: 0 Failed: 0 Ignored: 0

![simulator screen shot 6 jan 2017 02 05 15](https://cloud.githubusercontent.com/assets/1235097/21705017/f851e9d8-d3b4-11e6-9c44-646dab559643.png)
Closes https://github.com/facebook/yoga/pull/324

Reviewed By: emilsjolander

Differential Revision: D4401408

Pulled By: splhack

fbshipit-source-id: ecdae7967060361bef2bc25a5ef759cb9a957322
2017-01-11 07:54:35 -08:00
Emil Sjolander
47266b9ae8 Add percentage support to react native
Summary:
@public

Adds support for percentage value in react native.

syntax: property: 100 | property | '100%'

supported properties:
padding
margin
width
height
minWidth
minHeight
maxWidth
maxHeight
flexBasis

```
class Playground extends React.Component {
  render() {
    return (
      <View style={{backgroundColor: 'white', padding: 10, paddingTop: 30, height: '100%'}}>
        <Text>
          If you want to quickly test out something,
          open the Playground.js file and start coding.
        </Text>
        <View style={{backgroundColor: 'red', height: 50, width: 50}}/>
        <View style={{backgroundColor: 'blue', height: '50%', width: '50%'}}/>
      </View>
    );
  }
}
```

Reviewed By: astreet

Differential Revision: D4376549

fbshipit-source-id: c41d68a7555396f95d063a7527ee081773ac56dc
2017-01-11 04:09:34 -08:00
Emil Sjolander
e39f13a8ea Allow aspect ratio to expand beyond bounds of parent
Summary: Allow aspect ratio to expand beyond bounds of parent as is generally accepted in css

Reviewed By: passy

Differential Revision: D4397547

fbshipit-source-id: d2b1ca7b096f2f17b3efbd8f47a50678bfe7bb5f
2017-01-10 08:39:36 -08:00
Emil Sjolander
c04604dbc0 Implement java bindings for custom baseline function
Summary: Implement java bindings for custom baseline function

Differential Revision: D4392516

fbshipit-source-id: 39cf6066f8e5982268becd87e54c9ab51fbf7a90
2017-01-10 07:09:33 -08:00
Emil Sjolander
1782646723 Update aspect ratio documentation to match changes recently made
Summary: Fixes #313 https://github.com/facebook/yoga/issues/313

Reviewed By: gkassabli

Differential Revision: D4397691

fbshipit-source-id: 29daabe9a4bbde3f330e952ca5e644c7cfdbcccf
2017-01-10 06:39:41 -08:00
Kazuki Sakamoto
78e64e3d5b Add Copy Constructor for C# YogaNode
Summary:
Add Copy Constructor for convenience.

    YogaNode defaultStyle = new YogaNode
    {
      Width = 100,
      Height = 100,
    };

    YogaNode node0 = new YogaNode(defaultStyle)
    {
        FlexDirection = YogaFlexDirection.Row,
        JustifyContent = YogaJustify.FlexEnd,
    };

    YogaNode node1 = new YogaNode(defaultStyle)
    {
        AlignItems = YogaAlign.Center,
    };

Reviewed By: emilsjolander

Differential Revision: D4393234

fbshipit-source-id: b4b73071aab4dc1b3ae422969de659380bd0e3ad
2017-01-09 11:24:37 -08:00
Emil Sjolander
0acb620159 Use int instead of NSInteger for ABI compatibility
Summary:
@public

Cannot use NSInteger as NSInteger has a different size than int (which is the default type of a enum). Therefor when linking the Yoga C library into obj-c the header is a missmatch for the Yoga ABI.

Reviewed By: cwdick

Differential Revision: D4392272

fbshipit-source-id: 22b92ac8f3eb7114e81dbd9b0bec9044c3d43da5
2017-01-09 08:39:36 -08:00
David Hart
9982295e10 Improved the objective-c and swift api
Summary:
Compared to what was planned, I added the `overflow` value which seemed missing. I had to modify the implementation a bit for all values which are backed by a `YGValue`, but we should probably enable the pixel dimensions in Objective-C and Swift somehow later.
Closes https://github.com/facebook/yoga/pull/322

Reviewed By: cosmin1123

Differential Revision: D4391434

Pulled By: emilsjolander

fbshipit-source-id: e33f6f7b2bbaad29553100b7a5bb424496372110
2017-01-08 11:54:32 -08:00
Kazuki Sakamoto
8ed71b2777 Add spacing properties
Summary:
Align C# implementation with YogaKit #322
Closes https://github.com/facebook/yoga/pull/327

Reviewed By: emilsjolander

Differential Revision: D4390687

Pulled By: splhack

fbshipit-source-id: 28c87a45898fcd958a422d5e254ead0ec00d3562
2017-01-08 08:09:34 -08:00
Chris Hamons
969b3709db Add basic Xamarin.Mac support
Summary:
- Does not contain "magic" found in YogaKit yet, but enough to get started
- Simple test project showing use
- YGInteropSetLogger and YGNodeInit(IntPtr) were missing from native lib built by buck
Closes https://github.com/facebook/yoga/pull/278

Reviewed By: emilsjolander

Differential Revision: D4388480

Pulled By: splhack

fbshipit-source-id: a7387bb5b5554b6fce80d08c23e4fa18a4611cce
2017-01-08 08:09:34 -08:00
Ben Holcomb
e2a7938b26 Revert D4386906: [YogaKit] Improved the objective-c and swift api
Summary: This reverts commit 05ac0e571ef3a8ff0be31469e449a7b23f102218

Differential Revision: D4386906

fbshipit-source-id: adac0d8e71ce9f3442f3bfd14b5157f88367c998
2017-01-07 10:24:37 -08:00
Kazuki Sakamoto
70a4221b9e C# Baseline function
Summary:
same as Measure function, based on #317
Closes https://github.com/facebook/yoga/pull/321

Reviewed By: emilsjolander

Differential Revision: D4385336

Pulled By: splhack

fbshipit-source-id: b583ec79861d2e9abba31a72503e2f706bfda8e8
2017-01-07 09:09:35 -08:00
David Hart
8d320ceac2 Improved the objective-c and swift api
Summary:
Compared to what was planned, I added the `overflow` value which seemed missing. I had to modify the implementation a bit for all values which are backed by a `YGValue`, but we should probably enable the pixel dimensions in Objective-C and Swift somehow later.
Closes https://github.com/facebook/yoga/pull/322

Reviewed By: dshahidehpour

Differential Revision: D4386906

Pulled By: emilsjolander

fbshipit-source-id: 05ac0e571ef3a8ff0be31469e449a7b23f102218
2017-01-07 08:24:52 -08:00
Lukas Woehrl
c169a98be6 Baseline support
Summary:
Added baseline support (see #132)

You have the ability for a custom baseline function (```float(*YGBaselineFunc)(YGNodeRef node);```) to return whatever baseline you want.
Closes https://github.com/facebook/yoga/pull/317

Reviewed By: splhack

Differential Revision: D4385061

Pulled By: emilsjolander

fbshipit-source-id: cb8a59a09237c840fa3e21753ab68239997dab0c
2017-01-06 06:54:41 -08:00
Emil Sjolander
6d48307c8d Expose layout paddding in csharp api
Summary: Expose layout padding api from D4376572

Reviewed By: splhack

Differential Revision: D4377070

fbshipit-source-id: 501628612675e3fdce9a8e77f929cb9c6eddc209
2017-01-05 12:54:45 -08:00
Emil Sjolander
e539ecc9aa Expose layout paddding in java api
Summary: Expose layout padding api from D4376572

Reviewed By: passy

Differential Revision: D4377069

fbshipit-source-id: 2e0c04104560e1be586562b27b3457576590dc18
2017-01-05 12:54:45 -08:00
Emil Sjolander
bf5eeaf61e Add api for retrieving computed padding
Summary: Add API for retrieving the computed final padding of a node. Many frameworks such as React Native retrieve padding via `YGNodeStyleGetPadding` but given that we now support percentage values this is not correct anymore.

Differential Revision: D4376572

fbshipit-source-id: 3ffb66e77090fc1257511bec5c933f9b0c304b9f
2017-01-05 12:54:45 -08:00
Kazuki Sakamoto
a36faf89e3 Fix dll path in Unity build script
Summary: sync with vcproj

Reviewed By: emilsjolander

Differential Revision: D4384510

fbshipit-source-id: 964c5b84c063a5241b3aab0f276b2b5a080677aa
2017-01-05 12:10:03 -08:00
David Hart
29c44e281c Set nodes dirty when sizeThatFits changes
Summary:
In YogaKit, nodes are not dirtied when `sizeThatFits` of leaf nodes change. This makes it difficult to reuse views like `UILabel` when their content (text) changes. I wrote a failing test to prove it and wrote a fix by caching the latest value of `sizeThatFits` in `YGNodeBridge` and checking for changes in `YGAttachNodesFromViewHierachy` (renamed to `YGUpdateNodesFromViewHierachy` to make it clear it's not simply reattaching nodes anymore). When a new size is detected, I call `YGNodeMarkDirty` on the leaf node.

**Unfortunately**, this makes another test fail for no logical reason (`testThatViewNotIncludedInFirstLayoutPassAreIncludedInSecond`). Either there's something I don't understand or I've un-advertedly unearthed a bug in the C implementation, but in what case would setting a node dirty make the layout return a different size?
Closes https://github.com/facebook/yoga/pull/308

Reviewed By: emilsjolander

Differential Revision: D4378826

Pulled By: dshahidehpour

fbshipit-source-id: cd0640bc863debb9e434370739416e3e33e57a08
2017-01-05 08:39:36 -08:00
David Hart
1877a97898 Fix crash when a non-leaf node becomes a leaf node
Summary:
When a non-leaf node becomes a leaf node, `YGAttachNodesFromViewHierachy` calls `YGNodeSetMeasureFunc` before `YGRemoveAllChildren`, which causes a crash because that node has children. Fixed by swapping the order of the calls and have a unit-test to make sure it works.
Closes https://github.com/facebook/yoga/pull/320

Differential Revision: D4383905

Pulled By: dshahidehpour

fbshipit-source-id: 4872b1e819f178adaaa66b1f1c233390d3ec3be9
2017-01-05 08:24:39 -08:00
Andrew Forster
bf6602ebff Update C# wrapper to support both desktop and UWP projects
Summary:
The C# wrapper project has been changed to a NETStandard (1.1) PCL allowing it
to be consumed by any project targeting .NET4.5 or greater including .NETCore
and UWP projects... The C# wrapper uses P/Invoke to call into the Native Yoga
DLL...

The "Yoga" C++ project has been updated to support ARM builds...

Added the ability to generate nuget packages for the C# wrapper that supports
copying the native DLLs to the target output directory.

Closes: https://github.com/facebook/yoga/pull/283

Reviewed By: splhack, emilsjolander

Differential Revision: D4381455

Pulled By: JoelMarcey

fbshipit-source-id: e6dc4190caa824ac63d5d5ee2eb4c7914efbb00f
2017-01-05 07:09:41 -08:00
Kazuki Sakamoto
6bcf0e3a50 Fix Unity build
Summary:
YogaValue.cs(20,30): error CS1644: Feature `expression bodied members' cannot be used because it is not part of the C# 4.0 language specification
    YogaValue.cs(21,28): error CS1644: Feature `expression bodied members' cannot be used because it is not part of the C# 4.0 language specification
Closes https://github.com/facebook/yoga/pull/316

Reviewed By: emilsjolander

Differential Revision: D4381190

Pulled By: splhack

fbshipit-source-id: fea157ac03944260d87b9f137bf966605c01a10e
2017-01-05 06:39:38 -08:00
Lukas Woehrl
d0aeabb8f0 Optimized memory alignment
Summary:
It's not much, but still 4 bytes saved here by moving the ```bool```s together. (on compilers where ```bool``` is a single byte)
Closes https://github.com/facebook/yoga/pull/319

Reviewed By: gkassabli, passy

Differential Revision: D4383686

Pulled By: emilsjolander

fbshipit-source-id: 9a48eccbb69382850c016aa6ee730526704a15f2
2017-01-05 06:24:31 -08:00
Lukas Woehrl
956df20c64 Use float instead of double for test values
Summary:
Use explicit float values to remove warning.
Closes https://github.com/facebook/yoga/pull/318

Reviewed By: gkassabli

Differential Revision: D4383687

Pulled By: emilsjolander

fbshipit-source-id: a820bf829f74a7bdaefc39e783d03b42e27d0b3b
2017-01-05 04:54:36 -08:00
Maël Nison
7108454455 Improve JS bindings
Summary:
- Fix a few things related to how npm should publish the package (sources were in the gitignore file, so I think it would have break the build during install - I fixed this by adding a npmignore that should override the gitignore rules)

- The enumerations values are now generated directly from `enums.py`

- I added percent unit support (#258) to the bindings (`.setWidthPercent` is currently exposed, but I've also added a very very little parsing to also support `.setWidth("100%")` and `.setWidth(.getWidth())`), added the missing tests, and fixed Travis.
Closes https://github.com/facebook/yoga/pull/314

Reviewed By: mikearmstrong001

Differential Revision: D4377198

Pulled By: emilsjolander

fbshipit-source-id: 774dfafd416f5421f3be59a1d181eb7056487abe
2017-01-04 04:39:40 -08:00
Dustin Shahidehpour
663a93912b Add Overflow API.
Summary: We need this for scrollviews, bring on the overflow!

Reviewed By: emilsjolander

Differential Revision: D4376759

fbshipit-source-id: a427432da5e8679dbf9fdbfe4250707e727368f4
2017-01-03 06:39:40 -08:00
Lukas Woehrl
a85bd4ad2a Add feature to use percentage as value unit
Summary:
Adds the feature to use percentage as a value unit.

You can use the function ```YGPx(float)``` and ```YGPercent(float)``` for convenience.

I did some benchmarks:

```
Without Percentage Feature - Release x86:

Stack with flex: median: 0.000000 ms, stddev: 0.146683 ms
Align stretch in undefined axis: median: 0.000000 ms, stddev: 0.136525 ms
Nested flex: median: 0.000000 ms, stddev: 0.490101 ms
Huge nested layout: median: 23.000000 ms, stddev: 0.928291 ms

Stack with flex: median: 0.000000 ms, stddev: 0.170587 ms
Align stretch in undefined axis: median: 0.000000 ms, stddev: 0.143384 ms
Nested flex: median: 0.000000 ms, stddev: 0.477791 ms
Huge nested layout: median: 22.000000 ms, stddev: 2.129779 ms

With Percentage Feature - Release x86:

Stack with flex: median: 0.000000 ms, stddev: 0.132951 ms
Align stretch in undefined axis: median: 0.000000 ms, stddev: 0.136525 ms
Nested flex: median: 0.000000 ms, stddev: 0.489570 ms
Huge nested layout: median: 21.000000 ms, stddev: 1.390476 ms
Closes https://github.com/facebook/yoga/pull/258

Reviewed By: dshahidehpour

Differential Revision: D4361945

Pulled By: emilsjolander

fbshipit-source-id: a8f5bc63ad352eb9410d792729e56664468cd76a
2017-01-02 05:24:35 -08:00
Maël Nison
6f462a72bf Adds Javascript Support
Summary:
- As mentioned in the title, this PR adds Javascript support to Yoga. Two different builds are included in this PR thanks to [nbind](https://github.com/charto/nbind), which conveniently allow to target both Node.js' native addons and browser environments via asmjs with approximately the same codebase. That should solve #215.

- All tests successfully pass on both codepaths. You can run `yarn test:all` inside the `javascript` directory to test it.

- Because of a bug in nbind, the [following PR](https://github.com/charto/nbind/pull/57) needs to be merged and a new version released before this one can be safely merged as well.

- I had to use `double` types instead of `float` in the C++ bindings because of an Emscripten [bug](https://github.com/kripken/emscripten/issues/3592) where symbols aren't correctly exported when using floats.

- There's some tweaks to do before this PR is 100% ready to merge, but I wanted to have your opinion first. What do you think of this?

 ---

To do:

- [x] Ensure th
Closes https://github.com/facebook/yoga/pull/304

Reviewed By: mikearmstrong001

Differential Revision: D4375187

Pulled By: emilsjolander

fbshipit-source-id: 47248558a9506b7c512b5ef281cd12fe1a60cab7
2017-01-02 02:24:38 -08:00
Emil Sjolander
352f592767 Allow decimal measurements on java
Summary: Preserve floating point values when passing them across the JNI bridge.

Differential Revision: D4366605

fbshipit-source-id: 0b94ee87a03a6ed918360dd9998930e780fc865d
2016-12-29 04:55:56 -08:00
Emil Sjolander
f2080e520f Move yoga docs into docs folder on master branch
Summary: Move yoga docs into master branch so that pull requests are able to include doc updates as part of other changes.

Reviewed By: JoelMarcey

Differential Revision: D4365700

fbshipit-source-id: 2f46a88974104c454c00bcdf1257abb5c4075a68
2016-12-28 04:09:48 -08:00
Lukas Woehrl
cd78291de5 C# use YogaSize throughout the measure call chain
Summary:
Java still has the same problem (see #296)

Also there is no need to have double in the method signature as we only use float internally, which could confuse some.
Closes https://github.com/facebook/yoga/pull/300

Reviewed By: splhack

Differential Revision: D4365993

Pulled By: emilsjolander

fbshipit-source-id: 681f8b1725e63eddcfb9a6c756f2ae215a44425a
2016-12-24 02:54:38 -08:00
Emil Sjolander
ab595d1875 ignore .buckversion
Summary: ignore .buckversion file from source control

Reviewed By: vjeux

Differential Revision: D4366002

fbshipit-source-id: 910173bab5f3235673a8686ae6b606624380df09
2016-12-24 02:54:38 -08:00
Emil Sjolander
597544e30a Add note about gtest submodule to readme
Summary: Add note about gtest submodule to readme

Reviewed By: vjeux

Differential Revision: D4366004

fbshipit-source-id: 13ddc040faa251d52aa4c253caff9f5478e12ca6
2016-12-24 02:54:38 -08:00
Kazuki Sakamoto
9f59a13836 Remove unused P/Invoke interface
Summary:
- Remove YGNodeGetContext and YGNodeSetContext from Native.cs
- https://github.com/facebook/yoga/pull/297#discussion_r93789907

Reviewed By: emilsjolander

Differential Revision: D4365845

fbshipit-source-id: 89b41ec773baa1b4901f637f5e83427c9fba4aed
2016-12-23 12:09:40 -08:00
Kazuki Sakamoto
12017e49bd Update .git/hgignore
Summary: Fix paths

Reviewed By: emilsjolander

Differential Revision: D4365853

fbshipit-source-id: 1eb5b1046f4bb7a18b8f29d2876c0d560c3fad49
2016-12-23 12:09:40 -08:00
Kazuki Sakamoto
abad796c44 Fix BUCK
Summary: Remove internal arg

Reviewed By: emilsjolander

Differential Revision: D4365827

fbshipit-source-id: 705855732146e03da65f21cbaa746277719b72f4
2016-12-23 11:24:37 -08:00
desmondyao
92137273a2 Not re-calculate value in Step1.
Summary:
Not re-calculate `paddingAndBorderAxisMain`/`paddingAndBorderAxisCross`/`paddingAndBorderAxisRow`/`paddingAndBorderAxisColumn` in Step1 of `YGNodelayoutImpl`.

They can be figure out by values calculated before.
Closes https://github.com/facebook/yoga/pull/298

Reviewed By: dshahidehpour

Differential Revision: D4365533

Pulled By: emilsjolander

fbshipit-source-id: 6caf60bc6ef3addd49915b39b48f01a8b4926e9c
2016-12-23 10:24:32 -08:00
Kazuki Sakamoto
f1ab289022 Run unit tests before building Unity package
Summary:
- Enable destructor unit tests in Unity Editor
- Exit pack.sh immediately if a command exits with a non-zero status
- Run unit tests before building Unity package

Reviewed By: emilsjolander

Differential Revision: D4365773

fbshipit-source-id: 20d0a51f4cef791154c17d329ac36598dc333a60
2016-12-23 09:54:32 -08:00
David Hart
a302b76d59 Added gitignore rule for Xcode xcuserdata
Summary: Closes https://github.com/facebook/yoga/pull/294

Reviewed By: dshahidehpour

Differential Revision: D4365534

Pulled By: emilsjolander

fbshipit-source-id: ff899d3526156ce9bbe8cba07418ca77b2f38ac8
2016-12-23 08:54:37 -08:00
Filip Frącz
4717594e93 Switched to using SafeHandle for native code interrupt
Summary:
This PR fixes issue #295

- Created a new internal YGNodeHandle class extending SafeHandle.
- YogaNode now stores a reference to YGNodeHandle.
- Removed finalizer from YogaNode.
- Pulling in System.Runtime.Handles 4.3.0.
Closes https://github.com/facebook/yoga/pull/297

Reviewed By: emilsjolander

Differential Revision: D4365462

Pulled By: splhack

fbshipit-source-id: 73293b105962cbedb71f4e3d8d1244251db1ea79
2016-12-23 08:39:33 -08:00
Hannes Verlinde
df0f76bba5 Run unit tests on Sandcastle
Summary:
- Change the CI config so it runs the tests for Editor on Sandcastle
- Don't run tests for effects-framework and yoga libraries when building for Mac (triggers code signing issues that I don't want to deal with right now)
- Add target for unit tests (aka EditorTests)
- Make the existing unit tests build and pass. These include both Objective-C and Swift (we should probably get rid of some of these though). I will convert these to Swift 3 before landing (after the migration is complete).
- Exclude the EditorUITests target for now. It only contains a single dummy test and it causes a code signing failure on Sandcastle. I did not manage to work around that yet but there is a separate task for it.

Reviewed By: Perspx

Differential Revision: D4352670

fbshipit-source-id: 0295004a72953bd8e7ae83895b2e5712bab7bd32
2016-12-23 02:09:35 -08:00
Kazuki Sakamoto
e43c9f66ff Add script to build Unity package
Summary:
Added Bash script and bat file to build a package of Yoga in order to import Yoga for Unity easily.
Closes https://github.com/facebook/yoga/pull/288

Reviewed By: emilsjolander

Differential Revision: D4344198

Pulled By: splhack

fbshipit-source-id: 49ae27dbc513b4a2d161840ca5c5f4c9df2ab227
2016-12-22 08:39:35 -08:00
Emil Sjolander
0df58d8aa2 Declaratively initialize default values of nodes
Summary: Improve performance of allocations and reseting by writing fewer bits. Also just looks nicer imho.

Reviewed By: passy

Differential Revision: D4356994

fbshipit-source-id: ebbe52163e0c86230bfa4131b657941afe16fbf1
2016-12-22 03:10:06 -08:00
David Hart
ff1a0e1eb8 Transform the Count enum values into private constants
Summary:
Hides implementation details for the C, Objective-C and Swift APIs.
Closes https://github.com/facebook/yoga/pull/292

Differential Revision: D4351523

Pulled By: emilsjolander

fbshipit-source-id: 18a1149d169f0d52bd078714295000b5d07434dd
2016-12-22 03:10:06 -08:00
Emil Sjolander
ed765fe508 Convert max cache count into a define
Summary: This should not be an enum. A define makes a whole lot more sense

Differential Revision: D4346529

fbshipit-source-id: 8641c4c5017d915d64e5884cae09ac8f01861337
2016-12-22 03:10:06 -08:00
Emil Sjolander
1b5eb7da5e BREAKING - Increase priority of AspectRatio to override flex, align stretch, and fixed sizes if specified.
Summary:
@public
AspectRatio is a new addition and soon after introduction we noticed use cases which is did not support. Specifically we wanted to support a node being as large as possible within a container while maintaining an arbitrary aspect ratio. This was not possible due to the low priority of AspectRatio, by increasing the priority of AspectRatio this is now possible as FlexGrow will grow an item to fit its parent unless the AspectRatio makes it too big in the cross axis, the AspectRatio will now override the FlexGrow in the main axis in that case.

Differential Revision: D4346720

fbshipit-source-id: 1f15613604190e3ad5ff4a467ba57db4bcfd2741
2016-12-22 03:10:06 -08:00
Emil Sjolander
071f576db9 BREAKING - Change aspect ratio to always be width/height
Summary:
@public

Aspect ratio being defined as width/height or height/width depending on the situation it was used in turned out to be very confusing. This diff makes aspect ratio always be defined as width/height irregardless of the usage.

Differential Revision: D4339132

fbshipit-source-id: e5da32750b55ddaf6acaf1cbd7662d86f2b480c3
2016-12-22 03:10:06 -08:00
Emil Sjolander
3d10ba5f72 Correctly check if child is flex by also accounting for undefined
Summary: We were incorrectly returning true for children which had no flex as the flex was nan and not 0.

Differential Revision: D4346712

fbshipit-source-id: 69ef0bb3fe5b4fcd3b3e2fe5aa348529be40252a
2016-12-22 03:10:05 -08:00
Georgiy Kassabli
85b8386ba1 Test for minHeight with flexing
Summary: This test creates a repro case for Yoga to emulate UFI layout failure

Reviewed By: emilsjolander

Differential Revision: D4313632

fbshipit-source-id: 35be7d86b50a9ae08c81891a889a74e4b61f2d27
2016-12-21 11:39:34 -08:00
Dustin Shahidehpour
7ec3607446 Fix diffing algorithm for reattaching views.
Summary:
There is a bug currently where we don't traverse the entire tree to detect view hierarchy changes.

Currently, if you had a hierachy like this:
```
container = UIView
container.subviews = @[subview1, subview2];

subview1.subviews = @[sub11, sub12, sub13];
subview2.subviews = @[sub21, sub22, sub23];
```

and then modified via:
```
subview2.subviews = @[newView1, newView2, newView3];
```

our algorithm wouldn't identify that we had new views that needed their layout calculated, and would cause a crash later on.

Reviewed By: emilsjolander

Differential Revision: D4357662

fbshipit-source-id: 2f61f213c5f1a62948a653f3b1fa3d874c5075f7
2016-12-21 11:09:38 -08:00
Dustin Shahidehpour
835bb1cd9c Add isLeaf flag to Views.
Summary: While building some views with YogaKit, I found an interesting problem. If you are apply `yg_` properties to a view which is constructed of subclassed views (that don't use Yoga.) we still treat view (and it's subviews) like they are using YogaKit. This fixes that behavior.

Reviewed By: emilsjolander

Differential Revision: D4348344

fbshipit-source-id: 37b8648918529f55afea1d1883a03af398aac849
2016-12-20 11:39:36 -08:00
yiminghe
9d35dce63e explicit default justifyContent value
Summary:
make default justifyContent value explicit like alignItems

https://developer.mozilla.org/en-US/docs/Web/CSS/justify-content

https://developer.mozilla.org/en-US/docs/Web/CSS/align-items

https://developer.mozilla.org/en-US/docs/Web/CSS/align-content
Closes https://github.com/facebook/yoga/pull/293

Differential Revision: D4351597

Pulled By: emilsjolander

fbshipit-source-id: b65ff2284ede4d75f1cc5e22d4106042ab0b0d02
2016-12-20 03:24:40 -08:00
Emil Sjolander
74fb205083 Rename test files to match other test file names
Summary: Rename test files to match other test file names

Differential Revision: D4335198

fbshipit-source-id: b8f38162c3094231476059eb1f54326d8ba84848
2016-12-16 09:09:37 -08:00
Kazuki Sakamoto
ba0bb10366 Build iOS fat static library for Unity and Xamarin
Summary:
$ buck build //csharp:yoganet-ios
    $ buck targets --show-output //csharp:yoganet-ios
    //csharp:yoganet-ios buck-out/gen/csharp/yoganet-ios/libyoga.a

    $ lipo -info buck-out/gen/csharp/yoganet-ios/libyoga.a
    Architectures in the fat file: buck-out/gen/csharp/yoganet-ios/libyoga.a are: armv7 x86_64 arm64

    $ nm buck-out/gen/csharp/yoganet-ios/libyoga.a|grep -e 'T _YGNodeNew' -e 'ygNode' -e 'T _YGInteropSetLogger'
    0000000000000000 T _YGNodeNew
    0000000000001070 t -[UIView(Yoga) ygNode]
    0000000000000000 T _YGInteropSetLogger
Closes https://github.com/facebook/yoga/pull/286

Reviewed By: emilsjolander

Differential Revision: D4338919

Pulled By: splhack

fbshipit-source-id: 7acfdfa0dc4d152d7bfe92161efdeb9f161f70e6
2016-12-16 06:54:35 -08:00
Emil Sjolander
0296511f2c YGNodeChildCount -> YGNodeGetChildCount for consistency
Summary: I kept wrongly typing this function which is a good sign that the name is inconsistent.

Reviewed By: gkassabli

Differential Revision: D4333480

fbshipit-source-id: 17058f18fa9e26b3e02f7a1651f7295cae59acad
2016-12-16 04:39:41 -08:00
Kazuki Sakamoto
04fe81f88f YGNodeInit is no longer exported
Summary:
- Problem: Can't link yoga static libraries with Unity and Xamarin.iOS since YGNodeInit is undefined in the libraries.
- Solution: Remove the reference in Native.cs

Reviewed By: emilsjolander

Differential Revision: D4338485

fbshipit-source-id: 9dc95aec8f1fd50f3f9d66e1623afe2fb1992210
2016-12-16 00:09:40 -08:00
Kazuki Sakamoto
98bbc15435 Support Xamarin.iOS
Summary:
- `__Internal`

https://developer.xamarin.com/guides/ios/advanced_topics/native_interop/#Static_Libraries

 > Since you can only use static libraries on iOS, there is no external shared library to link with, so the path parameter in the DllImport attribute needs to use the special name __Internal (note the double underscore characters at the start of the name) as opposed to the path name.

- `__IOS__`

https://developer.xamarin.com/guides/cross-platform/application_fundamentals/building_cross_platform_applications/part_4_-_platform_divergence_abstraction_divergent_implementation/#iOS

 > Xamarin.iOS defines __IOS__ which you can use to detect iOS devices.
Closes https://github.com/facebook/yoga/pull/277

Reviewed By: emilsjolander

Differential Revision: D4338420

Pulled By: splhack

fbshipit-source-id: 375efecbaf88fffbba544073c6d6b30fb1f4c8ba
2016-12-16 00:09:40 -08:00
Kazuki Sakamoto
25b206ac53 Build native library with BUCK for .NET (Mono, Xamarin)
Summary:
Examples:

- macOS on macOS (Mono, Xamarin.Mac, Unity)
  - `buck build //csharp:yoganet#shared,default` -> `libyoga.dylib`
- Android (Xamarin.Android, Unity)
  - `buck build //csharp:yoganet#shared,android-armv7` -> `libyoga.so`
- iOS (Xamarin.iOS, Unity)
  - `buck build //:yoga#static,iphoneos-arm64` -> `libyoga.a`
  - `buck build //csharp:yoganet#static,iphoneos-arm64` -> `libyoganet.a`
Closes https://github.com/facebook/yoga/pull/282

Reviewed By: emilsjolander

Differential Revision: D4333811

Pulled By: splhack

fbshipit-source-id: 54f4364d93b2419d7504392eb558296a5d06772f
2016-12-15 13:54:34 -08:00
Emil Sjolander
88a4e44fd4 Add YGNodeGetParent api
Summary: Fixes https://github.com/facebook/css-layout/issues/248

Reviewed By: gkassabli

Differential Revision: D4333456

fbshipit-source-id: 388afd0a01c19a6db73c175bf24c566278832cb9
2016-12-15 09:54:35 -08:00
Kazuki Sakamoto
642ea07d6f Update unmanaged dll name
Summary: - Update unmanaged dll name from `Yoga.dll` to `yoga.dll` since Native.cs `DllName` referes lowercase `yoga`

Reviewed By: emilsjolander

Differential Revision: D4295954

fbshipit-source-id: 16b91c407506685b84902102cf4380cb149b5b2c
2016-12-15 07:24:46 -08:00
Kazuki Sakamoto
e85c5ce39d lowercase argument
Summary: - Fix arguments of YogaNode.Create

Reviewed By: emilsjolander

Differential Revision: D4296488

fbshipit-source-id: f6eb5074b1b1462f2251d330929f7b8082ad72eb
2016-12-15 07:24:46 -08:00
Jatin Pandey
cf753af247 Make documentation clearer
Summary:
Fixing a typo :)
Closes https://github.com/facebook/yoga/pull/270

Reviewed By: dshahidehpour

Differential Revision: D4333129

Pulled By: emilsjolander

fbshipit-source-id: 28215de8fcd571fb889fe145ff303f231a50c598
2016-12-15 07:24:46 -08:00
Emil Sjolander
12efe604bb Fix YogaKit tests on travis
Summary: Fix include path

Reviewed By: dshahidehpour

Differential Revision: D4333185

fbshipit-source-id: 27638324e093260aa1b23134fab5140a0c703bc9
2016-12-15 07:24:46 -08:00
Emil Sjolander
f36f545d75 Add an anchor to the android platform regex
Summary: This prevents android from matching in the middle of a platform.

Reviewed By: gkassabli

Differential Revision: D4306164

fbshipit-source-id: 7f62a6a017724f8f6741d3e53b5fbe0650c8c88e
2016-12-10 17:37:12 -08:00
Joel Marcey
8fcd544c81 A bit more syncing after the name change 2016-12-10 17:31:11 -08:00
Emil Sjolander
73662ebf83 example license 2016-12-07 17:41:50 +00:00
Emil Sjolander
47a8ec06a1 Add sample project for YogaKit 2016-12-07 17:27:25 +00:00
Emil Sjolander
b611fac20b update naming and fix test 2016-12-07 16:18:13 +00:00
Emil Sjolander
b11155423c Rename directories
Reviewed By: gkassabli

Differential Revision: D4284681

Summary: Rename csslayout directories to yoga

fbshipit-source-id: f0c6855c2c6e4389b7867f48f72cbb697830fc5a
2016-12-07 05:22:52 -08:00
Emil Sjolander
40371cbf2d Remove init from api
Summary: Both New and Reset already call init internally. No reason to expose this function

Reviewed By: gkassabli

Differential Revision: D4276177

fbshipit-source-id: c4404d0534f381dfacee0625b2847d38de58e038
2016-12-06 14:52:34 -08:00
Emil Sjolander
613590b0d8 Ignore csharp test dependencies which are downloaded on the fly
Summary: Running csharp tests should not result in uncommited files.

Reviewed By: splhack

Differential Revision: D4271411

fbshipit-source-id: abf6c69555ed657356a9426ca37864f8c2eaa78f
2016-12-05 12:37:36 -08:00
Emil Sjolander
4710a65f7a Fix an error initializing needsCrossTrailingPos
Summary: https://github.com/facebook/css-layout/pull/259

Reviewed By: gkassabli

Differential Revision: D4271422

fbshipit-source-id: e8d72af742d96829684958780eb56e2c375df20c
2016-12-05 09:37:38 -08:00
Emil Sjolander
901f65ca05 Fix prefix typo in YogaKit
Summary: Forgot to update this in rename.

Reviewed By: dshahidehpour, gkassabli

Differential Revision: D4271399

fbshipit-source-id: cf354928a8839a864e9961e091d9f48840a5d4d4
2016-12-05 08:07:41 -08:00
Emil Sjolander
72cf6806de Add #pragma once and extern C to YGEnums.h
Summary: Makes YGEnums.h header looks like other Yoga headers

Reviewed By: gkassabli

Differential Revision: D4274156

fbshipit-source-id: 9fa0ae146bb9e5bd40d93fa3c56f83424ebd2bf9
2016-12-05 05:07:37 -08:00
Emil Sjolander
1b7ae2ed3d Update java package name to yoga
Summary: Update package name of java code to refer to yoga instead of csslayout. Still need to change the name of the folder where this code resides but that requires update github sync scripts etc so it is safer and easier to split these diffs apart.

Differential Revision: D4271420

fbshipit-source-id: b3cf150569a2331868410339cd19e5c694f2059e
2016-12-05 03:07:33 -08:00
Emil Sjolander
c6100d0771 Rename java API
Summary: Rename java api to new use yoga naming

Reviewed By: IanChilds

Differential Revision: D4265345

fbshipit-source-id: 69ecfd8fac214f86b8b70647b9b909acd83d78b5
2016-12-03 04:53:39 -08:00
Emil Sjolander
6339467b6d Rename tests
Summary: Rename test files to use new name

Reviewed By: gkassabli

Differential Revision: D4265235

fbshipit-source-id: 0090d3949828058baf7435f33d4068de92756bad
2016-12-03 04:53:39 -08:00
Emil Sjolander
dda24b1e23 Rename C api
Summary: This renames the core C api to use the new Yoga branding.

Differential Revision: D4259190

fbshipit-source-id: 26c8b356ca464d4304f5f9dc4192bff10cea2dc9
2016-12-03 04:53:38 -08:00
Emil Sjolander
f7cc614d67 rename csharp code
Summary: new name

Reviewed By: splhack

Differential Revision: D4247106

fbshipit-source-id: 6e1097de104f3a011c78ae65b33e57865b007711
2016-12-02 11:23:20 -08:00
Emil Sjolander
4bbf35832e Rename CSSLayoutKit
Summary: new name

Reviewed By: dshahidehpour

Differential Revision: D4245987

fbshipit-source-id: 880f558c694bd041abbedadeb91225a3ca6c14f9
2016-12-02 11:23:20 -08:00
Emil Sjolander
b9feb10420 Rename benchmarks
Summary: new name

Reviewed By: splhack

Differential Revision: D4245765

fbshipit-source-id: c524183ead279ad1d9159a1da2f18fc1b96c2b51
2016-12-02 11:23:20 -08:00
Emil Sjolander
42b6f6b6e5 Rename enums
Summary: new name, start by renaming enums

Differential Revision: D4244360

fbshipit-source-id: c9fcbdd231098c9ff230a6055676bbc7cbd11001
2016-12-02 05:52:59 -08:00
Emil Sjolander
07cf47baad Remove force_static
Summary: static linking is dangerous here as more than one library could be including the same symbols. The used to only be used by the jni target previously but that is no longer true

Reviewed By: gkassabli

Differential Revision: D4258293

fbshipit-source-id: 053f9e607503707830e3766b1f268ab31d3081ff
2016-12-02 05:22:49 -08:00
Emil Sjolander
686289814d Rename defs file
Summary: new name

Reviewed By: gkassabli

Differential Revision: D4258291

fbshipit-source-id: 4b9ad8773c68aed25afba57fcfa92721e6acc1a6
2016-12-02 05:22:49 -08:00
Emil Sjolander
bb37e65ab1 Fix error from refactor of setMeasuredDimensionsIfEmptyOrFixedSize
Summary: D4213339 refactored some code and some logic was missed where negative values should only be ignored for at most measurements.

Reviewed By: gkassabli

Differential Revision: D4258254

fbshipit-source-id: e22e36e67260114081e483527fc7ce378f7f0df9
2016-12-01 07:37:31 -08:00
Emil Sjolander
31b961d8b3 Revert D4245638: [yoga] Rename defs file
Summary: This reverts commit 14050d02c4298014a5fcadd75c4f364537ec2396

Differential Revision: D4245638

fbshipit-source-id: 5eba4f87cbf5a64e235dd16e038326e916cdda77
2016-11-30 12:37:49 -08:00
Emil Sjolander
4a578284a5 Revert D4248487: [yoga] Remove force_static
Summary: This reverts commit e5127a02561b145745cf5393a0188661469ec79b

Differential Revision: D4248487

fbshipit-source-id: c826eb6543ff6b8d512bf688fbd395e9766df2fb
2016-11-30 12:22:31 -08:00
Emil Sjolander
c5bbcd78ae Fix usage of weak references to check for null
Summary: In case the java object has been GCed during layout calculation we will crash if we try to call a method on the now invalid weak pointer. Use fbjni weak_ref to skip calling to java when the java object does not exist any more.

Reviewed By: lexs

Differential Revision: D4251133

fbshipit-source-id: 2d8949252b31447ce54bc16a35cb25fabe72230b
2016-11-30 10:14:15 -08:00
Emil Sjolander
4fbe0495b4 Remove force_static
Summary: static linking is dangerous here as more than one library could be including the same symbols. The used to only be used by the jni target previously but that is no longer true

Reviewed By: gkassabli

Differential Revision: D4248487

fbshipit-source-id: e5127a02561b145745cf5393a0188661469ec79b
2016-11-30 08:22:32 -08:00
Emil Sjolander
ff3d2e1691 Rename defs file
Summary: new name

Reviewed By: gkassabli

Differential Revision: D4245638

fbshipit-source-id: 14050d02c4298014a5fcadd75c4f364537ec2396
2016-11-30 08:07:44 -08:00
Emil Sjolander
684a36d6cf Add -fPIC to jni target
Summary: Add compile flag from CSSLayout to jni target as well

Reviewed By: passy

Differential Revision: D4248473

fbshipit-source-id: 18a163a3daedc56e98c7bdc38e10fc8626999f94
2016-11-30 03:22:35 -08:00
Emil Sjolander
7d74e1cb66 Add test case covering padding on child
Summary: Add coverage exposed by https://github.com/facebook/css-layout/pull/262

Reviewed By: splhack

Differential Revision: D4247282

fbshipit-source-id: 25500bcfced58a8095665b73eeebca8d1c266a17
2016-11-29 16:22:32 -08:00
Emil Sjolander
b32b6029de Remove deprecated java code
Summary: Remove deprecated java code and make use of CSSEdge instead of the now removed Spacing class.

Reviewed By: AaaChiuuu

Differential Revision: D4233198

fbshipit-source-id: 736d79be266e1b9f2d62e5fe6d901de47123cdc1
2016-11-29 12:37:47 -08:00
Emil Sjolander
5fa42cd1b0 Remove Style prefix in java and cs apis
Summary: The Style prefix does not make sense in the java and c# api and only a few methods had it. This diff removes the last of those.

Reviewed By: splhack

Differential Revision: D4232920

fbshipit-source-id: 6e2ff21bbb7e0e441892023c14df579d1bc7aa49
2016-11-29 09:07:34 -08:00
Emil Sjolander
6318801470 Always use soloader. Catching exception and re-trying hides errors
Summary: Soloader is safer than System load library, retrying with System load library just hides errors

Reviewed By: lexs

Differential Revision: D4243906

fbshipit-source-id: e4d691c9c49f3b9316f67e39b9f277657d78fb3c
2016-11-29 04:37:32 -08:00
Emil Sjolander
97d524fa96 Add notice in readme about ongoing API changes
Summary: Add notice in readme to prepare open source for large renaming diffs.

Reviewed By: splhack

Differential Revision: D4240761

fbshipit-source-id: 4c8070a06c3ac009b67eb7bef5de11ce3ab3e4d8
2016-11-28 15:52:33 -08:00
Emil Sjolander
c31df519e0 Dont strip class names referenced from native
Summary: Ensure we don't strip classes used from native

Reviewed By: lexs

Differential Revision: D4237790

fbshipit-source-id: 1bd0780d965efbb8334917011ffd65896670ece1
2016-11-28 09:22:41 -08:00
Pascal Hartig
0240d09949 Enable -fPIC for C library
Summary:
At least or x86_64 linux, it appears that you need position-independent
code is required in order to link against it. Otherwise you see errors
like this:

```
/usr/bin/ld: lib_sys.rlib(CSSLayout.c.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: lib_sys.rlib(CSSNodeList.c.o): relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
```

If I understand it correctly, you don't strictly need PIC for static libraries, but as soon as you want to link *other* dynamically linked library into it, it is required - which makes logical sense to me. Let me know if you want to enable this by default or leave it up to the developers to enable this if needed.
Closes https://github.com/facebook/css-layout/pull/263

Reviewed By: passy

Differential Revision: D4237009

Pulled By: emilsjolander

fbshipit-source-id: e73ea0ea22520758ec958a031d6e2ca62fdcda15
2016-11-28 09:22:41 -08:00
Emil Sjolander
22b0fdb3e6 Add experiment support to gentest
Summary:
This diff does two things
- Clean up some of the generated code making the files smaller.
- Add experiment support to generated tests allowing us to use gentest for things still being experimented with such as more compliant flex-basis behavior.

Reviewed By: gkassabli

Differential Revision: D4226734

fbshipit-source-id: 2cc1471c21883e8e326f16e7a8bb1a3657acd84b
2016-11-23 11:22:36 -08:00
Emil Sjolander
a0d560a24b Fixup recent fix to flex basis and put it behind an experimental flag
Summary: D4207106 previously fixed an issue where the computed flex basis was cached in between layout calculations, potentially caching wrong values. After landing we noticed that some product were implicitly relying on this behavior so this diff instead puts that behind a feature flag.

Reviewed By: gkassabli

Differential Revision: D4222910

fbshipit-source-id: d693482441fcc4d37a288e2e3529057a04f60541
2016-11-23 05:37:32 -08:00
Dustin Shahidehpour
dc10fdd958 Fix bug where swapping views in hierarchy throws an assert.
Summary: I found that if you move a subview to a different index, it would cause a crash in subsequent layout passes because the `CSSNodeRef` representing it was being re-inserted into the list. I spent a lot of time figuring out the best way to "diff" the view hierarchy from before and after, and I found the easiest implementation is also the most reliable. We can continue to optimize, but this is a great start.

Reviewed By: emilsjolander

Differential Revision: D4218623

fbshipit-source-id: 06253089492ac37ae4b94b7c30140ce6ed680ed2
2016-11-22 08:37:38 -08:00
Lukas Woehrl
b90f6e21bd Added feature to use rounded values
Summary:
Added an experimental feature to allow to use only rounded values. See #184. It's not a perfect solution and definitely  can be further improved. I'm looking forward to your ideas.
Closes https://github.com/facebook/css-layout/pull/256

Reviewed By: splhack

Differential Revision: D4214168

Pulled By: emilsjolander

fbshipit-source-id: 6293352d479b7b4dad258eb3f9e0afaa11cf7236
2016-11-22 05:37:34 -08:00
Lukas Woehrl
d54f09e32b Use ASSERT_FLOAT_EQ instead of ASSERT_EQ
Summary:
Changes the unit test comparsion to use ```ASSERT_FLOAT_EQ``` instead of ```ASSERT_EQ``` as they check float values.
Closes https://github.com/facebook/css-layout/pull/257

Reviewed By: splhack

Differential Revision: D4213809

Pulled By: emilsjolander

fbshipit-source-id: a79d310840814f26a122e1a0f6db47383b17d7e2
2016-11-22 02:52:30 -08:00
Dustin Shahidehpour
49a21e657b Fix bug where we insert nodes at wrong index in view hierarchy.
Summary:
We currently have a bug in `UIView+CSSLayout.m` that you can repro in a scenario like this:

```
UIView *container = [[UIView alloc] initWithFrame:CGRectZero];
  [container css_setUsesFlexbox:YES];
  [container css_setFlexDirection:CSSFlexDirectionRow];

  UIView *subview1 = [[UIView alloc] initWithFrame:CGRectZero];
  [subview1 css_setUsesFlexbox:YES];
  [subview1 css_setIncludeInLayout:NO];
  [container addSubview:subview1];

  UIView *subview2 = [[UIView alloc] initWithFrame:CGRectZero];
  [subview2 css_setUsesFlexbox:YES];
  [subview2 css_setIncludeInLayout:NO];
  [container addSubview:subview2];

  UIView *subview3 = [[UIView alloc] initWithFrame:CGRectZero];
  [subview3 css_setUsesFlexbox:YES];
  [subview3 css_setIncludeInLayout:YES];
  [container addSubview:subview3];

  [container css_applyLayout];
```

`subview3` (which is the only view whose is going to be included in layout calculation) is inserted at child index 2, instead of 0. This eventually can cause crash in CSSLayout.c because it will attempt access a child in the list which is null.

Reviewed By: emilsjolander

Differential Revision: D4215659

fbshipit-source-id: a615f50e51f85b15d3bdb437e55958865898b183
2016-11-21 18:07:36 -08:00
Emil Sjolander
2d58a36619 Move measure code for known dimensions out of main layout function
Summary: Try to move more code out of the main measure function

Reviewed By: gkassabli

Differential Revision: D4213339

fbshipit-source-id: 5ca35ca307594f3419fd0dee81321d3c2e06710f
2016-11-21 11:07:45 -08:00
Emil Sjolander
f56e8a5163 Move measure code for empty containers out of main layout function
Summary: Try to move more code out of the main measure function

Reviewed By: gkassabli

Differential Revision: D4213313

fbshipit-source-id: 2061a809202f7f948bff1b3ee8dc4c230692a223
2016-11-21 11:07:45 -08:00
Emil Sjolander
e78cf02a30 Move custom measure code out of main layout function
Summary: Try to move more code out of the main measure function

Reviewed By: gkassabli

Differential Revision: D4213302

fbshipit-source-id: df4bc43848325e99ad338a2fa6d5c9404315b0e6
2016-11-21 11:07:45 -08:00
Emil Sjolander
55fc795686 Add aspectRatio style property
Summary: Implement aspect ratio as part of Yoga. Aspect ratio allows users of the library to specify the size of the undefined dimension in terms of an aspect ratio. See test cases for examples.

Reviewed By: gkassabli

Differential Revision: D4211458

fbshipit-source-id: f8d0d318369c7b529ee29e61a52b17d0cf3b396d
2016-11-21 10:22:32 -08:00
577 changed files with 64071 additions and 24727 deletions

17
.github/ISSUE_TEMPLATE.md vendored Normal file
View File

@@ -0,0 +1,17 @@
# Report
- [ ] I have searched [existing issues](https://github.com/facebook/yoga/issues) and this is not a duplicate
# Issues and Steps to Reproduce
***Replaces this with steps to repro your issue.***
# Expected Behavior
***Describe what you expected would happen.***
# Actual Behavior
***Describe what actually happened.***
# Link to Code
***If you have some code that maintainers can clone/test for themselves, bugs can be resolved much faster. Please paste a link here.***
***When applicable, use this [fiddle](https://jsfiddle.net/emilsjolander/jckmwztt/) to post a web repro.***

52
.gitignore vendored
View File

@@ -5,6 +5,58 @@
/.buckconfig.local
/.buckd
/gentest/test.html
.buckversion
# Jekyll
/.sass-cache/
/_site/
# Visual studio code
.vscode
*.pdb
*.tlog
*.obj
*.pch
*.log
*.orig
# Xcode
## Build generated
build/
DerivedData/
## Various settings
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata/
## Other
*.moved-aside
*.xcuserstate
## Obj-C/Swift specific
*.hmap
*.ipa
*.dSYM.zip
*.dSYM
# CocoaPods
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
#
Pods/
# Carthage
#
# Add this line if you want to avoid checking in source code from Carthage dependencies.
# Carthage/Checkouts
Carthage/Build

View File

@@ -1,10 +0,0 @@
.DS_STORE
/buck-cache/
/buck-out/
/.buckconfig.local
/.buckd
/gentest/test.html
# Visual studio code
.vscode

1
.swift-version Normal file
View File

@@ -0,0 +1 @@
3.0

View File

@@ -6,7 +6,7 @@
# of patent rights can be found in the PATENTS file in the same directory.
os: osx
osx_image: xcode7.3
osx_image: xcode8.2
language: cpp
compiler: clang
@@ -17,14 +17,26 @@ before_install:
- brew cask install java
- brew outdated xctool || brew upgrade xctool
- brew install mono
- export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)
- export PATH=$JAVA_HOME/bin:$PATH
install:
- cd javascript
- npm install
- cd $TRAVIS_BUILD_DIR
script:
- buck test //:CSSLayout
- buck test //:yoga
- buck test //java:java
- buck test //CSSLayoutKit:CSSLayoutKit --config cxx.default_platform=iphonesimulator-x86_64 --config cxx.cflags=-DTRAVIS_CI
- sh csharp/tests/Facebook.CSSLayout/test_macos.sh
- buck test //YogaKit:YogaKitTests --config cxx.default_platform=iphonesimulator-x86_64
- sh csharp/tests/Facebook.Yoga/test_macos.sh
- cd javascript
- npm run test:all
- npm run bench
- cd $TRAVIS_BUILD_DIR
- buck run //benchmark:benchmark
- git checkout HEAD^
- buck run //benchmark:benchmark

30
BUCK
View File

@@ -5,43 +5,37 @@
# 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_defs('//CSSLAYOUT_DEFS')
BASE_COMPILER_FLAGS = [
'-fno-omit-frame-pointer',
'-fexceptions',
'-Wall',
'-Werror',
'-O3',
]
include_defs('//YOGA_DEFS')
GMOCK_OVERRIDE_FLAGS = [
# gmock does not mark mocked methods as override, ignore the warnings in tests
'-Wno-inconsistent-missing-override',
]
COMPILER_FLAGS = BASE_COMPILER_FLAGS + ['-std=c11']
COMPILER_FLAGS = BASE_COMPILER_FLAGS + ['-std=c11', '-fPIC']
TEST_COMPILER_FLAGS = BASE_COMPILER_FLAGS + GMOCK_OVERRIDE_FLAGS + ['-std=c++11']
cxx_library(
name = 'CSSLayout',
srcs = glob(['CSSLayout/*.c']),
tests=[':tests'],
exported_headers = subdir_glob([('', 'CSSLayout/*.h')]),
name = 'yoga',
soname = 'libyogacore.$(ext)',
srcs = glob(['yoga/*.c']),
tests=[':YogaTests'],
exported_headers = subdir_glob([('', 'yoga/*.h')]),
header_namespace = '',
force_static = True,
compiler_flags = COMPILER_FLAGS,
deps = [],
deps = [] if THIS_IS_FBOBJC else [
yoga_dep('lib/fb:ndklog'),
],
visibility = ['PUBLIC'],
)
cxx_test(
name = 'tests',
name = 'YogaTests',
contacts = ['emilsj@fb.com'],
srcs = glob(['tests/*.cpp']),
compiler_flags = TEST_COMPILER_FLAGS,
deps = [
':CSSLayout',
':yoga',
GTEST_TARGET,
],
visibility = ['PUBLIC'],

View File

@@ -1,10 +1,7 @@
# Contributing to css-layout
# Contributing to yoga
We want to make contributing to this project as easy and transparent as
possible.
## Our Development Process
All the development is happening on GitHub first and we have internal tools to sync down to Facebook codebase.
## Pull Requests
We actively welcome your pull requests.
1. Fork the repo and create your branch from `master`.
@@ -32,5 +29,5 @@ outlined on that page and do not file a public issue.
* format.sh
## License
By contributing to css-layout, you agree that your contributions will be licensed
By contributing to yoga, you agree that your contributions will be licensed
under its BSD license.

View File

@@ -1,106 +0,0 @@
/**
* 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.
*/
typedef enum CSSOverflow {
CSSOverflowVisible,
CSSOverflowHidden,
CSSOverflowScroll,
CSSOverflowCount,
} CSSOverflow;
typedef enum CSSJustify {
CSSJustifyFlexStart,
CSSJustifyCenter,
CSSJustifyFlexEnd,
CSSJustifySpaceBetween,
CSSJustifySpaceAround,
CSSJustifyCount,
} CSSJustify;
typedef enum CSSFlexDirection {
CSSFlexDirectionColumn,
CSSFlexDirectionColumnReverse,
CSSFlexDirectionRow,
CSSFlexDirectionRowReverse,
CSSFlexDirectionCount,
} CSSFlexDirection;
typedef enum CSSAlign {
CSSAlignAuto,
CSSAlignFlexStart,
CSSAlignCenter,
CSSAlignFlexEnd,
CSSAlignStretch,
CSSAlignCount,
} CSSAlign;
typedef enum CSSEdge {
CSSEdgeLeft,
CSSEdgeTop,
CSSEdgeRight,
CSSEdgeBottom,
CSSEdgeStart,
CSSEdgeEnd,
CSSEdgeHorizontal,
CSSEdgeVertical,
CSSEdgeAll,
CSSEdgeCount,
} CSSEdge;
typedef enum CSSWrap {
CSSWrapNoWrap,
CSSWrapWrap,
CSSWrapCount,
} CSSWrap;
typedef enum CSSDirection {
CSSDirectionInherit,
CSSDirectionLTR,
CSSDirectionRTL,
CSSDirectionCount,
} CSSDirection;
typedef enum CSSExperimentalFeature {
CSSExperimentalFeatureCount,
} CSSExperimentalFeature;
typedef enum CSSLogLevel {
CSSLogLevelError,
CSSLogLevelWarn,
CSSLogLevelInfo,
CSSLogLevelDebug,
CSSLogLevelVerbose,
CSSLogLevelCount,
} CSSLogLevel;
typedef enum CSSDimension {
CSSDimensionWidth,
CSSDimensionHeight,
CSSDimensionCount,
} CSSDimension;
typedef enum CSSMeasureMode {
CSSMeasureModeUndefined,
CSSMeasureModeExactly,
CSSMeasureModeAtMost,
CSSMeasureModeCount,
} CSSMeasureMode;
typedef enum CSSPositionType {
CSSPositionTypeRelative,
CSSPositionTypeAbsolute,
CSSPositionTypeCount,
} CSSPositionType;
typedef enum CSSPrintOptions {
CSSPrintOptionsLayout = 1,
CSSPrintOptionsStyle = 2,
CSSPrintOptionsChildren = 4,
CSSPrintOptionsCount,
} CSSPrintOptions;

File diff suppressed because it is too large Load Diff

View File

@@ -1,172 +0,0 @@
/**
* 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.
*/
#pragma once
#include <assert.h>
#include <math.h>
#include <stdarg.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#ifndef __cplusplus
#include <stdbool.h>
#endif
// Not defined in MSVC++
#ifndef NAN
static const unsigned long __nan[2] = {0xffffffff, 0x7fffffff};
#define NAN (*(const float *) __nan)
#endif
#define CSSUndefined NAN
#include "CSSEnums.h"
#include "CSSMacros.h"
CSS_EXTERN_C_BEGIN
typedef struct CSSSize {
float width;
float height;
} CSSSize;
typedef struct CSSNode *CSSNodeRef;
typedef CSSSize (*CSSMeasureFunc)(CSSNodeRef node,
float width,
CSSMeasureMode widthMode,
float height,
CSSMeasureMode heightMode);
typedef void (*CSSPrintFunc)(CSSNodeRef node);
typedef int (*CSSLogger)(CSSLogLevel level, const char *format, va_list args);
typedef void *(*CSSMalloc)(size_t size);
typedef void *(*CSSCalloc)(size_t count, size_t size);
typedef void *(*CSSRealloc)(void *ptr, size_t size);
typedef void (*CSSFree)(void *ptr);
// CSSNode
WIN_EXPORT CSSNodeRef CSSNodeNew(void);
WIN_EXPORT void CSSNodeInit(const CSSNodeRef node);
WIN_EXPORT void CSSNodeFree(const CSSNodeRef node);
WIN_EXPORT void CSSNodeFreeRecursive(const CSSNodeRef node);
WIN_EXPORT void CSSNodeReset(const CSSNodeRef node);
WIN_EXPORT int32_t CSSNodeGetInstanceCount(void);
WIN_EXPORT void CSSNodeInsertChild(const CSSNodeRef node,
const CSSNodeRef child,
const uint32_t index);
WIN_EXPORT void CSSNodeRemoveChild(const CSSNodeRef node, const CSSNodeRef child);
WIN_EXPORT CSSNodeRef CSSNodeGetChild(const CSSNodeRef node, const uint32_t index);
WIN_EXPORT uint32_t CSSNodeChildCount(const CSSNodeRef node);
WIN_EXPORT void CSSNodeCalculateLayout(const CSSNodeRef node,
const float availableWidth,
const float availableHeight,
const CSSDirection parentDirection);
// Mark a node as dirty. Only valid for nodes with a custom measure function
// set.
// CSSLayout knows when to mark all other nodes as dirty but because nodes with
// measure functions
// depends on information not known to CSSLayout they must perform this dirty
// marking manually.
WIN_EXPORT void CSSNodeMarkDirty(const CSSNodeRef node);
WIN_EXPORT bool CSSNodeIsDirty(const CSSNodeRef node);
WIN_EXPORT void CSSNodePrint(const CSSNodeRef node, const CSSPrintOptions options);
WIN_EXPORT bool CSSValueIsUndefined(const float value);
WIN_EXPORT bool CSSNodeCanUseCachedMeasurement(const CSSMeasureMode widthMode,
const float width,
const CSSMeasureMode heightMode,
const float height,
const CSSMeasureMode lastWidthMode,
const float lastWidth,
const CSSMeasureMode lastHeightMode,
const float lastHeight,
const float lastComputedWidth,
const float lastComputedHeight,
const float marginRow,
const float marginColumn);
WIN_EXPORT void CSSNodeCopyStyle(const CSSNodeRef dstNode, const CSSNodeRef srcNode);
#define CSS_NODE_PROPERTY(type, name, paramName) \
WIN_EXPORT void CSSNodeSet##name(const CSSNodeRef node, type paramName); \
WIN_EXPORT type CSSNodeGet##name(const CSSNodeRef node);
#define CSS_NODE_STYLE_PROPERTY(type, name, paramName) \
WIN_EXPORT void CSSNodeStyleSet##name(const CSSNodeRef node, const type paramName); \
WIN_EXPORT type CSSNodeStyleGet##name(const CSSNodeRef node);
#define CSS_NODE_STYLE_EDGE_PROPERTY(type, name, paramName) \
WIN_EXPORT void CSSNodeStyleSet##name(const CSSNodeRef node, \
const CSSEdge edge, \
const type paramName); \
WIN_EXPORT type CSSNodeStyleGet##name(const CSSNodeRef node, const CSSEdge edge);
#define CSS_NODE_LAYOUT_PROPERTY(type, name) \
WIN_EXPORT type CSSNodeLayoutGet##name(const CSSNodeRef node);
CSS_NODE_PROPERTY(void *, Context, context);
CSS_NODE_PROPERTY(CSSMeasureFunc, MeasureFunc, measureFunc);
CSS_NODE_PROPERTY(CSSPrintFunc, PrintFunc, printFunc);
CSS_NODE_PROPERTY(bool, HasNewLayout, hasNewLayout);
CSS_NODE_STYLE_PROPERTY(CSSDirection, Direction, direction);
CSS_NODE_STYLE_PROPERTY(CSSFlexDirection, FlexDirection, flexDirection);
CSS_NODE_STYLE_PROPERTY(CSSJustify, JustifyContent, justifyContent);
CSS_NODE_STYLE_PROPERTY(CSSAlign, AlignContent, alignContent);
CSS_NODE_STYLE_PROPERTY(CSSAlign, AlignItems, alignItems);
CSS_NODE_STYLE_PROPERTY(CSSAlign, AlignSelf, alignSelf);
CSS_NODE_STYLE_PROPERTY(CSSPositionType, PositionType, positionType);
CSS_NODE_STYLE_PROPERTY(CSSWrap, FlexWrap, flexWrap);
CSS_NODE_STYLE_PROPERTY(CSSOverflow, Overflow, overflow);
WIN_EXPORT void CSSNodeStyleSetFlex(const CSSNodeRef node, const float flex);
CSS_NODE_STYLE_PROPERTY(float, FlexGrow, flexGrow);
CSS_NODE_STYLE_PROPERTY(float, FlexShrink, flexShrink);
CSS_NODE_STYLE_PROPERTY(float, FlexBasis, flexBasis);
CSS_NODE_STYLE_EDGE_PROPERTY(float, Position, position);
CSS_NODE_STYLE_EDGE_PROPERTY(float, Margin, margin);
CSS_NODE_STYLE_EDGE_PROPERTY(float, Padding, padding);
CSS_NODE_STYLE_EDGE_PROPERTY(float, Border, border);
CSS_NODE_STYLE_PROPERTY(float, Width, width);
CSS_NODE_STYLE_PROPERTY(float, Height, height);
CSS_NODE_STYLE_PROPERTY(float, MinWidth, minWidth);
CSS_NODE_STYLE_PROPERTY(float, MinHeight, minHeight);
CSS_NODE_STYLE_PROPERTY(float, MaxWidth, maxWidth);
CSS_NODE_STYLE_PROPERTY(float, MaxHeight, maxHeight);
CSS_NODE_LAYOUT_PROPERTY(float, Left);
CSS_NODE_LAYOUT_PROPERTY(float, Top);
CSS_NODE_LAYOUT_PROPERTY(float, Right);
CSS_NODE_LAYOUT_PROPERTY(float, Bottom);
CSS_NODE_LAYOUT_PROPERTY(float, Width);
CSS_NODE_LAYOUT_PROPERTY(float, Height);
CSS_NODE_LAYOUT_PROPERTY(CSSDirection, Direction);
WIN_EXPORT void CSSLayoutSetLogger(CSSLogger logger);
WIN_EXPORT void CSSLog(CSSLogLevel level, const char *message, ...);
WIN_EXPORT void CSSLayoutSetExperimentalFeatureEnabled(CSSExperimentalFeature feature,
bool enabled);
WIN_EXPORT bool CSSLayoutIsExperimentalFeatureEnabled(CSSExperimentalFeature feature);
WIN_EXPORT void CSSLayoutSetMemoryFuncs(CSSMalloc cssMalloc,
CSSCalloc cssCalloc,
CSSRealloc cssRealloc,
CSSFree cssFree);
CSS_EXTERN_C_END

View File

@@ -1,42 +0,0 @@
/**
* 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.
*/
#pragma once
#ifdef __cplusplus
#define CSS_EXTERN_C_BEGIN extern "C" {
#define CSS_EXTERN_C_END }
#else
#define CSS_EXTERN_C_BEGIN
#define CSS_EXTERN_C_END
#endif
#ifdef _WINDLL
#define WIN_EXPORT __declspec(dllexport)
#else
#define WIN_EXPORT
#endif
#ifndef FB_ASSERTIONS_ENABLED
#define FB_ASSERTIONS_ENABLED 1
#endif
#if FB_ASSERTIONS_ENABLED
#define CSS_ABORT() abort()
#else
#define CSS_ABORT()
#endif
#ifndef CSS_ASSERT
#define CSS_ASSERT(X, message) \
if (!(X)) { \
CSSLog(CSSLogLevelError, "%s", message); \
CSS_ABORT(); \
}
#endif

View File

@@ -1,104 +0,0 @@
/**
* 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 "CSSNodeList.h"
extern CSSMalloc gCSSMalloc;
extern CSSRealloc gCSSRealloc;
extern CSSFree gCSSFree;
struct CSSNodeList {
uint32_t capacity;
uint32_t count;
CSSNodeRef *items;
};
CSSNodeListRef CSSNodeListNew(const uint32_t initialCapacity) {
const CSSNodeListRef list = gCSSMalloc(sizeof(struct CSSNodeList));
CSS_ASSERT(list != NULL, "Could not allocate memory for list");
list->capacity = initialCapacity;
list->count = 0;
list->items = gCSSMalloc(sizeof(CSSNodeRef) * list->capacity);
CSS_ASSERT(list->items != NULL, "Could not allocate memory for items");
return list;
}
void CSSNodeListFree(const CSSNodeListRef list) {
if (list) {
gCSSFree(list->items);
gCSSFree(list);
}
}
uint32_t CSSNodeListCount(const CSSNodeListRef list) {
if (list) {
return list->count;
}
return 0;
}
void CSSNodeListAdd(CSSNodeListRef *listp, const CSSNodeRef node) {
if (!*listp) {
*listp = CSSNodeListNew(4);
}
CSSNodeListInsert(listp, node, (*listp)->count);
}
void CSSNodeListInsert(CSSNodeListRef *listp, const CSSNodeRef node, const uint32_t index) {
if (!*listp) {
*listp = CSSNodeListNew(4);
}
CSSNodeListRef list = *listp;
if (list->count == list->capacity) {
list->capacity *= 2;
list->items = gCSSRealloc(list->items, sizeof(CSSNodeRef) * list->capacity);
CSS_ASSERT(list->items != NULL, "Could not extend allocation for items");
}
for (uint32_t i = list->count; i > index; i--) {
list->items[i] = list->items[i - 1];
}
list->count++;
list->items[index] = node;
}
CSSNodeRef CSSNodeListRemove(const CSSNodeListRef list, const uint32_t index) {
const CSSNodeRef removed = list->items[index];
list->items[index] = NULL;
for (uint32_t i = index; i < list->count - 1; i++) {
list->items[i] = list->items[i + 1];
list->items[i + 1] = NULL;
}
list->count--;
return removed;
}
CSSNodeRef CSSNodeListDelete(const CSSNodeListRef list, const CSSNodeRef node) {
for (uint32_t i = 0; i < list->count; i++) {
if (list->items[i] == node) {
return CSSNodeListRemove(list, i);
}
}
return NULL;
}
CSSNodeRef CSSNodeListGet(const CSSNodeListRef list, const uint32_t index) {
if (CSSNodeListCount(list) > 0) {
return list->items[index];
}
return NULL;
}

View File

@@ -1,33 +0,0 @@
/**
* 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.
*/
#pragma once
#include <assert.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "CSSLayout.h"
#include "CSSMacros.h"
CSS_EXTERN_C_BEGIN
typedef struct CSSNodeList *CSSNodeListRef;
CSSNodeListRef CSSNodeListNew(const uint32_t initialCapacity);
void CSSNodeListFree(const CSSNodeListRef list);
uint32_t CSSNodeListCount(const CSSNodeListRef list);
void CSSNodeListAdd(CSSNodeListRef *listp, const CSSNodeRef node);
void CSSNodeListInsert(CSSNodeListRef *listp, const CSSNodeRef node, const uint32_t index);
CSSNodeRef CSSNodeListRemove(const CSSNodeListRef list, const uint32_t index);
CSSNodeRef CSSNodeListDelete(const CSSNodeListRef list, const CSSNodeRef node);
CSSNodeRef CSSNodeListGet(const CSSNodeListRef list, const uint32_t index);
CSS_EXTERN_C_END

View File

@@ -1,202 +0,0 @@
/**
* 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.
*/
#import <XCTest/XCTest.h>
#import "UIView+CSSLayout.h"
@interface CSSLayoutKitTests : XCTestCase
@end
@implementation CSSLayoutKitTests
#ifndef TRAVIS_CI
- (void)testNodesAreDeallocedWithSingleView
{
XCTAssertEqual(0, CSSNodeGetInstanceCount());
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
[view css_setFlexBasis:1];
XCTAssertEqual(1, CSSNodeGetInstanceCount());
view = nil;
XCTAssertEqual(0, CSSNodeGetInstanceCount());
}
- (void)testNodesAreDeallocedCascade
{
XCTAssertEqual(0, CSSNodeGetInstanceCount());
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
[view css_setFlexBasis:1];
for (int i=0; i<10; i++) {
UIView *subview = [[UIView alloc] initWithFrame:CGRectZero];
[subview css_setFlexBasis:1];
[view addSubview:subview];
}
XCTAssertEqual(11, CSSNodeGetInstanceCount());
view = nil;
XCTAssertEqual(0, CSSNodeGetInstanceCount());
}
#endif
- (void)testUsesFlexbox
{
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
XCTAssertFalse([view css_usesFlexbox]);
[view css_setUsesFlexbox:YES];
XCTAssertTrue([view css_usesFlexbox]);
[view css_setUsesFlexbox:NO];
XCTAssertFalse([view css_usesFlexbox]);
}
- (void)testSizeThatFitsAsserts
{
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
dispatch_sync(dispatch_queue_create("com.facebook.CSSLayout.testing", DISPATCH_QUEUE_SERIAL), ^(void){
XCTAssertThrows([view css_intrinsicSize]);
});
}
- (void)testSizeThatFitsSmoke
{
UIView *container = [[UIView alloc] initWithFrame:CGRectZero];
[container css_setUsesFlexbox:YES];
[container css_setFlexDirection:CSSFlexDirectionRow];
[container css_setAlignItems:CSSAlignFlexStart];
UILabel *longTextLabel = [[UILabel alloc] initWithFrame:CGRectZero];
longTextLabel.text = @"This is a very very very very very very very very long piece of text.";
longTextLabel.lineBreakMode = NSLineBreakByTruncatingTail;
longTextLabel.numberOfLines = 1;
[longTextLabel css_setUsesFlexbox:YES];
[longTextLabel css_setFlexShrink:1];
[container addSubview:longTextLabel];
UIView *textBadgeView = [[UIView alloc] initWithFrame:CGRectZero];
[textBadgeView css_setUsesFlexbox:YES];
[textBadgeView css_setMargin:3.0 forEdge:CSSEdgeLeft];
[textBadgeView css_setWidth:10];
[textBadgeView css_setHeight:10];
[container addSubview:textBadgeView];
const CGSize containerSize = [container css_intrinsicSize];
XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(514,21), containerSize), @"Size is actually %@", NSStringFromCGSize(containerSize));
}
- (void)testFrameAndOriginPlacement
{
const CGSize containerSize = CGSizeMake(320, 50);
UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, containerSize.width, containerSize.height)];
[container css_setUsesFlexbox:YES];
[container css_setFlexDirection:CSSFlexDirectionRow];
for (int i = 0; i < 3; i++) {
UIView *subview = [[UIView alloc] initWithFrame:CGRectZero];
[subview css_setUsesFlexbox:YES];
[subview css_setFlexGrow:1];
[container addSubview:subview];
}
[container css_applyLayout];
XCTAssertFalse(CGRectIntersectsRect([container.subviews objectAtIndex:0].frame, [container.subviews objectAtIndex:1].frame));
XCTAssertFalse(CGRectIntersectsRect([container.subviews objectAtIndex:1].frame, [container.subviews objectAtIndex:2].frame));
XCTAssertFalse(CGRectIntersectsRect([container.subviews objectAtIndex:0].frame, [container.subviews objectAtIndex:2].frame));
CGFloat totalWidth = 0;
for (UIView *view in container.subviews) {
totalWidth += view.bounds.size.width;
}
XCTAssertEqual(containerSize.width, totalWidth, @"The container's width is %.6f, the subviews take up %.6f", containerSize.width, totalWidth);
}
- (void)testThatWeRespectIncludeInLayoutFlag
{
const CGSize containerSize = CGSizeMake(300, 50);
UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, containerSize.width, containerSize.height)];
[container css_setUsesFlexbox:YES];
[container css_setFlexDirection:CSSFlexDirectionRow];
UIView *subview1 = [[UIView alloc] initWithFrame:CGRectZero];
[subview1 css_setUsesFlexbox:YES];
[subview1 css_setFlexGrow:1];
[container addSubview:subview1];
UIView *subview2 = [[UIView alloc] initWithFrame:CGRectZero];
[subview2 css_setUsesFlexbox:YES];
[subview2 css_setFlexGrow:1];
[container addSubview:subview2];
UIView *subview3 = [[UIView alloc] initWithFrame:CGRectZero];
[subview3 css_setUsesFlexbox:YES];
[subview3 css_setFlexGrow:1];
[container addSubview:subview3];
[container css_applyLayout];
for (UIView *view in container.subviews) {
XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(100, 50), subview1.bounds.size), @"Actual size is %@", NSStringFromCGSize(view.bounds.size));
}
[subview3 css_setIncludeInLayout:NO];
[container css_applyLayout];
XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(150, 50), subview1.bounds.size), @"Actual size is %@", NSStringFromCGSize(subview1.bounds.size));
XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(150, 50), subview2.bounds.size), @"Actual size is %@", NSStringFromCGSize(subview2.bounds.size));
// We don't set the frame to zero, so, it should be set to what it was previously at.
XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(100, 50), subview3.bounds.size), @"Actual size is %@", NSStringFromCGSize(subview3.bounds.size));
}
- (void)testThatViewNotIncludedInFirstLayoutPassAreIncludedInSecond
{
UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 50)];
[container css_setUsesFlexbox:YES];
[container css_setFlexDirection:CSSFlexDirectionRow];
UIView *subview1 = [[UIView alloc] initWithFrame:CGRectZero];
[subview1 css_setUsesFlexbox:YES];
[subview1 css_setFlexGrow:1];
[container addSubview:subview1];
UIView *subview2 = [[UIView alloc] initWithFrame:CGRectZero];
[subview2 css_setUsesFlexbox:YES];
[subview2 css_setFlexGrow:1];
[container addSubview:subview2];
UIView *subview3 = [[UIView alloc] initWithFrame:CGRectZero];
[subview3 css_setUsesFlexbox:YES];
[subview3 css_setFlexGrow:1];
[subview3 css_setIncludeInLayout:NO];
[container addSubview:subview3];
[container css_applyLayout];
XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(150, 50), subview1.bounds.size), @"Actual size is %@", NSStringFromCGSize(subview1.bounds.size));
XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(150, 50), subview2.bounds.size), @"Actual size is %@", NSStringFromCGSize(subview2.bounds.size));
XCTAssertTrue(CGSizeEqualToSize(CGSizeZero, subview3.bounds.size), @"Actual size %@", NSStringFromCGSize(subview3.bounds.size));
[subview3 css_setIncludeInLayout:YES];
[container css_applyLayout];
for (UIView *view in container.subviews) {
XCTAssertTrue(CGSizeEqualToSize(CGSizeMake(100, 50), subview1.bounds.size), @"Actual size is %@", NSStringFromCGSize(view.bounds.size));
}
}
@end

View File

@@ -1,64 +0,0 @@
/**
* 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.
*/
#import <UIKit/UIKit.h>
#import <CSSLayout/CSSLayout.h>
@interface UIView (CSSLayout)
/**
The property that decides if we should include this view when calculating layout. Defaults to YES.
*/
@property (nonatomic, readwrite, assign, setter=css_setIncludeInLayout:) BOOL css_includeInLayout;
/**
The property that decides during layout/sizing whether or not css_* properties should be applied. Defaults to NO.
*/
@property (nonatomic, readwrite, assign, setter=css_setUsesFlexbox:) BOOL css_usesFlexbox;
- (void)css_setDirection:(CSSDirection)direction;
- (void)css_setFlexDirection:(CSSFlexDirection)flexDirection;
- (void)css_setJustifyContent:(CSSJustify)justifyContent;
- (void)css_setAlignContent:(CSSAlign)alignContent;
- (void)css_setAlignItems:(CSSAlign)alignItems;
- (void)css_setAlignSelf:(CSSAlign)alignSelf;
- (void)css_setPositionType:(CSSPositionType)positionType;
- (void)css_setFlexWrap:(CSSWrap)flexWrap;
- (void)css_setFlexGrow:(CGFloat)flexGrow;
- (void)css_setFlexShrink:(CGFloat)flexShrink;
- (void)css_setFlexBasis:(CGFloat)flexBasis;
- (void)css_setPosition:(CGFloat)position forEdge:(CSSEdge)edge;
- (void)css_setMargin:(CGFloat)margin forEdge:(CSSEdge)edge;
- (void)css_setPadding:(CGFloat)padding forEdge:(CSSEdge)edge;
- (void)css_setWidth:(CGFloat)width;
- (void)css_setHeight:(CGFloat)height;
- (void)css_setMinWidth:(CGFloat)minWidth;
- (void)css_setMinHeight:(CGFloat)minHeight;
- (void)css_setMaxWidth:(CGFloat)maxWidth;
- (void)css_setMaxHeight:(CGFloat)maxHeight;
/**
Get the resolved direction of this node. This won't be CSSDirectionInherit
*/
- (CSSDirection)css_resolvedDirection;
/**
Perform a layout calculation and update the frames of the views in the hierarchy with th results
*/
- (void)css_applyLayout;
/**
Returns the size of the view if no constraints were given. This could equivalent to calling [self sizeThatFits:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)];
*/
- (CGSize)css_intrinsicSize;
@end

View File

@@ -1,349 +0,0 @@
/**
* 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.
*/
#import "UIView+CSSLayout.h"
#import <objc/runtime.h>
@interface CSSNodeBridge : NSObject
@property (nonatomic, assign, readonly) CSSNodeRef cnode;
@end
@implementation CSSNodeBridge
- (instancetype)init
{
if ([super init]) {
_cnode = CSSNodeNew();
}
return self;
}
- (void)dealloc
{
CSSNodeFree(_cnode);
}
@end
@implementation UIView (CSSLayout)
- (BOOL)css_usesFlexbox
{
NSNumber *usesFlexbox = objc_getAssociatedObject(self, @selector(css_usesFlexbox));
return [usesFlexbox boolValue];
}
- (BOOL)css_includeInLayout
{
NSNumber *includeInLayout = objc_getAssociatedObject(self, @selector(css_includeInLayout));
return (includeInLayout != nil) ? [includeInLayout boolValue] : YES;
}
#pragma mark - Setters
- (void)css_setIncludeInLayout:(BOOL)includeInLayout
{
objc_setAssociatedObject(
self,
@selector(css_includeInLayout),
@(includeInLayout),
OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
- (void)css_setUsesFlexbox:(BOOL)enabled
{
objc_setAssociatedObject(
self,
@selector(css_usesFlexbox),
@(enabled),
OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
- (void)css_setDirection:(CSSDirection)direction
{
CSSNodeStyleSetDirection([self cssNode], direction);
}
- (void)css_setFlexDirection:(CSSFlexDirection)flexDirection
{
CSSNodeStyleSetFlexDirection([self cssNode], flexDirection);
}
- (void)css_setJustifyContent:(CSSJustify)justifyContent
{
CSSNodeStyleSetJustifyContent([self cssNode], justifyContent);
}
- (void)css_setAlignContent:(CSSAlign)alignContent
{
CSSNodeStyleSetAlignContent([self cssNode], alignContent);
}
- (void)css_setAlignItems:(CSSAlign)alignItems
{
CSSNodeStyleSetAlignItems([self cssNode], alignItems);
}
- (void)css_setAlignSelf:(CSSAlign)alignSelf
{
CSSNodeStyleSetAlignSelf([self cssNode], alignSelf);
}
- (void)css_setPositionType:(CSSPositionType)positionType
{
CSSNodeStyleSetPositionType([self cssNode], positionType);
}
- (void)css_setFlexWrap:(CSSWrap)flexWrap
{
CSSNodeStyleSetFlexWrap([self cssNode], flexWrap);
}
- (void)css_setFlexGrow:(CGFloat)flexGrow
{
CSSNodeStyleSetFlexGrow([self cssNode], flexGrow);
}
- (void)css_setFlexShrink:(CGFloat)flexShrink
{
CSSNodeStyleSetFlexShrink([self cssNode], flexShrink);
}
- (void)css_setFlexBasis:(CGFloat)flexBasis
{
CSSNodeStyleSetFlexBasis([self cssNode], flexBasis);
}
- (void)css_setPosition:(CGFloat)position forEdge:(CSSEdge)edge
{
CSSNodeStyleSetPosition([self cssNode], edge, position);
}
- (void)css_setMargin:(CGFloat)margin forEdge:(CSSEdge)edge
{
CSSNodeStyleSetMargin([self cssNode], edge, margin);
}
- (void)css_setPadding:(CGFloat)padding forEdge:(CSSEdge)edge
{
CSSNodeStyleSetPadding([self cssNode], edge, padding);
}
- (void)css_setWidth:(CGFloat)width
{
CSSNodeStyleSetWidth([self cssNode], width);
}
- (void)css_setHeight:(CGFloat)height
{
CSSNodeStyleSetHeight([self cssNode], height);
}
- (void)css_setMinWidth:(CGFloat)minWidth
{
CSSNodeStyleSetMinWidth([self cssNode], minWidth);
}
- (void)css_setMinHeight:(CGFloat)minHeight
{
CSSNodeStyleSetMinHeight([self cssNode], minHeight);
}
- (void)css_setMaxWidth:(CGFloat)maxWidth
{
CSSNodeStyleSetMaxWidth([self cssNode], maxWidth);
}
- (void)css_setMaxHeight:(CGFloat)maxHeight
{
CSSNodeStyleSetMaxHeight([self cssNode], maxHeight);
}
#pragma mark - Layout and Sizing
- (CSSDirection)css_resolvedDirection
{
return CSSNodeLayoutGetDirection([self cssNode]);
}
- (void)css_applyLayout
{
[self calculateLayoutWithSize:self.bounds.size];
CSSApplyLayoutToViewHierarchy(self);
}
- (CGSize)css_intrinsicSize
{
const CGSize constrainedSize = {
.width = CSSUndefined,
.height = CSSUndefined,
};
return [self calculateLayoutWithSize:constrainedSize];
}
#pragma mark - Private
- (CSSNodeRef)cssNode
{
CSSNodeBridge *node = objc_getAssociatedObject(self, @selector(cssNode));
if (!node) {
node = [CSSNodeBridge new];
CSSNodeSetContext(node.cnode, (__bridge void *) self);
objc_setAssociatedObject(self, @selector(cssNode), node, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
return node.cnode;
}
- (CGSize)calculateLayoutWithSize:(CGSize)size
{
NSAssert([NSThread isMainThread], @"CSS Layout calculation must be done on main.");
NSAssert([self css_usesFlexbox], @"CSS Layout is not enabled for this view.");
CSSAttachNodesFromViewHierachy(self);
const CSSNodeRef node = [self cssNode];
CSSNodeCalculateLayout(
node,
size.width,
size.height,
CSSNodeStyleGetDirection(node));
return (CGSize) {
.width = CSSNodeLayoutGetWidth(node),
.height = CSSNodeLayoutGetHeight(node),
};
}
static CSSSize CSSMeasureView(
CSSNodeRef node,
float width,
CSSMeasureMode widthMode,
float height,
CSSMeasureMode heightMode)
{
const CGFloat constrainedWidth = (widthMode == CSSMeasureModeUndefined) ? CGFLOAT_MAX : width;
const CGFloat constrainedHeight = (heightMode == CSSMeasureModeUndefined) ? CGFLOAT_MAX: height;
UIView *view = (__bridge UIView*) CSSNodeGetContext(node);
const CGSize sizeThatFits = [view sizeThatFits:(CGSize) {
.width = constrainedWidth,
.height = constrainedHeight,
}];
return (CSSSize) {
.width = CSSSanitizeMeasurement(constrainedWidth, sizeThatFits.width, widthMode),
.height = CSSSanitizeMeasurement(constrainedHeight, sizeThatFits.height, heightMode),
};
}
static CGFloat CSSSanitizeMeasurement(
CGFloat constrainedSize,
CGFloat measuredSize,
CSSMeasureMode measureMode)
{
CGFloat result;
if (measureMode == CSSMeasureModeExactly) {
result = constrainedSize;
} else if (measureMode == CSSMeasureModeAtMost) {
result = MIN(constrainedSize, measuredSize);
} else {
result = measuredSize;
}
return result;
}
static void CSSAttachNodesFromViewHierachy(UIView *view) {
CSSNodeRef node = [view cssNode];
const BOOL usesFlexbox = [view css_usesFlexbox];
const BOOL isLeaf = !usesFlexbox || view.subviews.count == 0;
// Only leaf nodes should have a measure function
if (isLeaf) {
CSSNodeSetMeasureFunc(node, CSSMeasureView);
// Clear any children
while (CSSNodeChildCount(node) > 0) {
CSSNodeRemoveChild(node, CSSNodeGetChild(node, 0));
}
} else {
CSSNodeSetMeasureFunc(node, NULL);
NSUInteger numSubviewsInLayout = 0;
// Add any children which were added since the last call to css_applyLayout
for (NSUInteger i = 0; i < view.subviews.count; i++) {
UIView *const subview = view.subviews[i];
if (![subview css_includeInLayout]) {
continue;
}
numSubviewsInLayout++;
CSSNodeRef childNode = [subview cssNode];
if (CSSNodeChildCount(node) < i + 1 || CSSNodeGetChild(node, i) != childNode) {
CSSNodeInsertChild(node, childNode, i);
}
CSSAttachNodesFromViewHierachy(subview);
}
// Remove any children which were removed since the last call to css_applyLayout
while (numSubviewsInLayout < CSSNodeChildCount(node)) {
CSSNodeRemoveChild(node, CSSNodeGetChild(node, CSSNodeChildCount(node) - 1));
}
}
}
static CGFloat CSSRoundPixelValue(CGFloat value)
{
static CGFloat scale;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^(){
scale = [UIScreen mainScreen].scale;
});
return round(value * scale) / scale;
}
static void CSSApplyLayoutToViewHierarchy(UIView *view) {
NSCAssert([NSThread isMainThread], @"Framesetting should only be done on the main thread.");
if (![view css_includeInLayout]) {
return;
}
CSSNodeRef node = [view cssNode];
const CGPoint topLeft = {
CSSNodeLayoutGetLeft(node),
CSSNodeLayoutGetTop(node),
};
const CGPoint bottomRight = {
topLeft.x + CSSNodeLayoutGetWidth(node),
topLeft.y + CSSNodeLayoutGetHeight(node),
};
view.frame = (CGRect) {
.origin = {
.x = CSSRoundPixelValue(topLeft.x),
.y = CSSRoundPixelValue(topLeft.y),
},
.size = {
.width = CSSRoundPixelValue(bottomRight.x) - CSSRoundPixelValue(topLeft.x),
.height = CSSRoundPixelValue(bottomRight.y) - CSSRoundPixelValue(topLeft.y),
},
};
const BOOL isLeaf = ![view css_usesFlexbox] || view.subviews.count == 0;
if (!isLeaf) {
for (NSUInteger i = 0; i < view.subviews.count; i++) {
CSSApplyLayoutToViewHierarchy(view.subviews[i]);
}
}
}
@end

View File

@@ -1,6 +1,6 @@
BSD License
For css-layout software
For yoga software
Copyright (c) 2014-present, Facebook, Inc. All rights reserved.

9
LICENSE-examples Normal file
View File

@@ -0,0 +1,9 @@
The examples provided by Facebook are for non-commercial testing and evaluation
purposes only. Facebook reserves all rights not expressly granted.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@@ -1,6 +1,6 @@
Additional Grant of Patent Rights Version 2
"Software" means the CSS Layout software distributed by Facebook, Inc.
"Software" means the yoga software distributed by Facebook, Inc.
Facebook, Inc. (“Facebook”) hereby grants to each recipient of the Software
(“you”) a perpetual, worldwide, royalty-free, non-exclusive, irrevocable

161
README.md
View File

@@ -1,159 +1,30 @@
# CSSLayout [![Build Status](https://travis-ci.org/facebook/css-layout.svg?branch=master)](https://travis-ci.org/facebook/css-layout)
# Yoga [![Build Status](https://travis-ci.org/facebook/yoga.svg?branch=master)](https://travis-ci.org/facebook/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)
## Goals
CSSLayout is a cross-platform implementation of flexbox. The goal of CSSLayout is allow native developers to have the same expressive layout system as developers developing for the modern web are used to. CSSLayout allows developers for web, android, iOS, and windows to use the same layout primitives across platforms. This saves time, increases collaboration between platform teams, and makes it easier for developers to work on multiple platforms.
## 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.
The goal of CSSLayout is not to re-implement all of css. CSSLayout only targets flexbox, and does not have any plans on implementing support for tables, floats, or any other css concepts. CSSLayout also does not plan on supporting styling properties which do not affect layout such as color or background properties.
## Testing
For testing we rely on [gtest](https://github.com/google/googletest) as a submodule. After cloning Yoga run `git submodule init` followed by `git submodule update`.
For any changes you make you should ensure that all the tests are passing. In case you make any fixes or additions to the library please also add tests for that change to ensure we don't break anything in the future. Tests are located in the `tests` directory. Run the tests by executing `buck test //:yoga`.
## Differences from web
CSSLayout tries to stay as close as possible to the web implementation of flexbox. There are however certain cases where CSSLayout differs from the web implementation.
### Default values
CSSLayout has chosen to make changes to the default values of certain properties. These default values were chosen based on our usage of the library. When testing layout with tools such as JSFiddle you can apply the following css style to ensure the defaults match those of CSSLayout. Or fork the [following JSFiddle](http://jsfiddle.net/vjeux/y11txxv9/).
```css
div, span {
box-sizing: border-box;
position: relative;
display: flex;
flex-direction: column;
align-items: stretch;
flex-shrink: 0;
align-content: flex-start;
border: 0 solid black;
margin: 0;
padding: 0;
min-width: 0;
}
```
- `box-sizing: border-box` is the most convenient way to express the relation between `width` and `borderWidth`.
- Everything is `display: flex` by default. All the behaviors of `block` and `inline-block` can be expressed in term of `flex` but not the opposite.
- All the flex elements are oriented from top to bottom, left to right and do not shrink. This is how things are laid out using the default CSS settings and what you'd expect.
- Everything is `position: relative`. This makes `position: absolute` target the direct parent and not some parent which is either `relative` or `absolute`. If you want to position an element relative to something else, you should move it in the DOM instead of relying of CSS. It also makes `top, left, right, bottom` do something when not specifying `position: absolute`.
### Size units
CSSLayout currently only supports pixel sizes. The reason being that we have not seen the need for any other units. We would like to support percentage units sometime in the future.
### -start and -end properties
We think supporting RTL locales is very important. Therefor CSSLayout supports non-standards -start and -end suffixed versions of margin, padding, border, and position.
## Usage
### C
The full API can be found in `CSSLayout/CSSLayout.h`.
```c
CSSNodeRef root = CSSNodeNew();
CSSNodeStyleSetWidth(root, 100);
CSSNodeStyleSetHeight(root, 100);
for (uint32_t i = 0; i < 10; i++) {
CSSNodeRef child = CSSNodeNew();
CSSNodeStyleSetHeight(child, 10);
CSSNodeInsertChild(root, child, 0);
}
CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR);
// Get for resulting layout
CSSNodeLayoutGetLeft(root);
CSSNodeLayoutGetTop(root);
CSSNodeLayoutGetWidth(root);
CSSNodeLayoutGetHeight(root);
```
### Java
The full API can be found in `java/com/facebook/csslayout/CSSNode.java`.
```java
CSSNode root = new CSSNode();
root.setStyleWidth(100);
root.setStyleHeight(100);
for (int i = 0; i < 10; i++) {
CSSNode child = new CSSNode();
child.setStyleHeight(10);
root.addChildAt(child, 0);
}
root.calculateLayout(new CSSLayoutContext());
// Get for resulting layout
root.getLayoutX();
root.getLayoutY();
root.getLayoutWidth();
root.getLayoutHeight();
```
### UIKit
The full API can be found in `CSSLayoutKit/UIView+CSSLayout.h`.
```objective-c
UIView *root = [UIView new];
[root css_setUsesFlexbox:YES];
[root css_setWidth:100];
[root css_setHeight:100];
for (NSUInteger i = 0; i < 10; i++) {
UIView *child = [UIView new];
[child css_setUsesFlexbox:YES];
[child css_setHeight:10];
[root addSubview:child];
}
// Resulting layout will be set on the UIView hierarchy frames.
[root css_applyLayout];
```
### .NET
The full API can be found in `csharp/Facebook.CSSLayout/CSSNode.cs`.
```csharp
var root = new CSSNode();
root.StyleWidth = 100;
root.StyleHeight = 100;
for (var i = 0; i < 10; i++)
{
var child = new CSSNode();
child.StyleHeight = 10;
root.Insert(0, child);
}
// Get for resulting layout
root.LayoutX;
root.LayoutY;
root.LayoutWidth;
root.LayoutHeight;
```
## Contributing
To contribute to CSSLayout you need to first install [buck](https://buckbuild.com) which is the build system used by CSSLayout. CSSLayout is implemented in C with language bindings for Java, Objective-C, and .NET. When making changes to `CSSLayout/CSSLayout.h` please ensure to update `java/jni/CSSJNI.h`, `java/com/facebook/csslayout/CSSNode.java`, `uikit/CSSLayout/UIView+CSSLayout.m`, and `csharp/Facebook.CSSLayout/CSSNode.cs` to reflect the API change. Before submitting any code please run `format.sh` to ensure the code matches the project's code style.
Before making any larger changes to CSSLayout please open an issue with a RFC so the changes can be discussed first. Generally we are very open to changes and improvements that will benefit the community.
### Testing
For any changes you make you should ensure that all the tests are passing. In case you make any fixes or additions to the library please also add at least one test to ensure we don't break anything in the future. Tests are located in `tests/CSSLayoutTest.cpp`. Run the tests by executing `buck test //:CSSLayout`.
Instead of manually writing a test which ensures parity with web implementations of flexbox you can run `gentest/gentest.rb` to generated a test for you. You can write html which you want to verify in CSSLayout, in `gentest/fixtures` folder, such as the following.
Instead of manually writing a test which ensures parity with web implementations of Flexbox you can run `gentest/gentest.rb` to generated a test for you. You can write html which you want to verify in Yoga, in `gentest/fixtures` folder, such as the following.
```html
<div style="width: 100px; height: 100px; align-items: center;">
<div id="my_test" style="width: 100px; height: 100px; align-items: center;">
<div style="width: 50px; height: 50px;"></div>
</div>
```
Run `gentest/gentest.rb` to generate test code and re-run `buck test //:CSSLayout` to validate the behavior. One test case will be generated for every root `div` in the input html.
Run `gentest/gentest.rb` to generate test code and re-run `buck test //:yoga` to validate the behavior. One test case will be generated for every root `div` in the input html.
You may need to install the latest watir-webdriver gem (`gem install watir-webdriver`) and [ChromeDriver](https://sites.google.com/a/chromium.org/chromedriver/) to run `gentest/gentest.rb` Ruby script.
#### .NET
.NET testing is not integrated in buck yet, you might need to set up .NET testing environment. We have a script which to launch C# test on macOS, `csharp/tests/Facebook.CSSLayout/test_macos.sh`.
### .NET
.NET testing is not integrated in buck yet, you might need to set up .NET testing environment. We have a script which to launch C# test on macOS, `csharp/tests/Facebook.Yoga/test_macos.sh`.
### Benchmarks
Benchmarks are located in `benchmarks/CSSBenchmark.c` and can be run with `buck run //benchmarks:benchmarks`. If you think your change has affected performance please run this before and after your change to validate that nothing has regressed.
## Code style
For the main C implementation of Yoga clang-format is used to ensure a consistent code style. Please run `bash format.sh` before submitting a pull request. For other languages just try to follow the current code style.
## Benchmarks
Benchmarks are located in `benchmark/YGBenchmark.c` and can be run with `buck run //benchmark:benchmark`. If you think your change has affected performance please run this before and after your change to validate that nothing has regressed. Benchmarks are run on every commit in CI.

View File

@@ -1,5 +1,5 @@
CSSLAYOUT_ROOT = '//...'
YOGA_ROOT = '//...'
INFER_ANNOTATIONS_TARGET = '//lib/infer-annotations:infer-annotations'
JSR_305_TARGET = '//lib/jsr-305:jsr-305'
JUNIT_TARGET = '//lib/junit:junit'
@@ -9,12 +9,23 @@ GTEST_TARGET = '//lib/gtest:gtest'
JNI_TARGET = '//lib/jni:jni'
FBJNI_TARGET = '//lib/fb:fbjni'
THIS_IS_FBOBJC = False
CXX_LIBRARY_WHITELIST = [
'//:yoga',
'//lib/fb:fbjni',
'//java:jni',
]
def csslayout_dep(dep):
BASE_COMPILER_FLAGS = [
'-fno-omit-frame-pointer',
'-fexceptions',
'-Wall',
'-Werror',
'-O3',
]
def yoga_dep(dep):
return '//' + dep
class allow_unsafe_import:

28
Yoga.podspec Normal file
View File

@@ -0,0 +1,28 @@
Pod::Spec.new do |spec|
spec.name = 'Yoga'
spec.version = '1.0.2'
spec.license = { :type => 'BSD', :file => "LICENSE" }
spec.homepage = 'https://facebook.github.io/yoga/'
spec.documentation_url = 'https://facebook.github.io/yoga/docs/api/c/'
spec.summary = 'Yoga is a cross-platform layout engine which implements Flexbox.'
spec.description = 'Yoga is a cross-platform layout engine enabling maximum collaboration within your team by implementing an API many designers are familiar with, and opening it up to developers across different platforms.'
spec.authors = 'Facebook'
spec.source = {
:git => 'https://github.com/facebook/yoga.git',
:tag => 'v2017.01.27.00',
}
spec.module_name = 'yoga'
spec.requires_arc = false
spec.compiler_flags = [
'-fno-omit-frame-pointer',
'-fexceptions',
'-Wall',
'-Werror',
'-std=c11',
'-fPIC'
]
spec.source_files = 'yoga/**/*.{c,h}'
end

29
YogaKit.podspec Normal file
View File

@@ -0,0 +1,29 @@
podspec = Pod::Spec.new do |spec|
spec.name = 'YogaKit'
spec.version = '1.0.3'
spec.license = { :type => 'BSD', :file => "LICENSE" }
spec.homepage = 'https://facebook.github.io/yoga/'
spec.documentation_url = 'https://facebook.github.io/yoga/docs/api/yogakit/'
spec.summary = 'Yoga is a cross-platform layout engine which implements Flexbox.'
spec.description = 'Yoga is a cross-platform layout engine enabling maximum collaboration within your team by implementing an API many designers are familiar with, and opening it up to developers across different platforms.'
spec.authors = 'Facebook'
spec.source = {
:git => 'https://github.com/facebook/yoga.git',
:tag => 'v2017.01.27.00',
}
spec.platform = :ios
spec.ios.deployment_target = '8.0'
spec.ios.frameworks = 'UIKit'
spec.dependency 'Yoga', '~> 1.0'
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'
end
# See https://github.com/facebook/yoga/pull/366
podspec.attributes_hash["readme"] = "YogaKit/README.md"
podspec

1
YogaKit/.swift-version Normal file
View File

@@ -0,0 +1 @@
3.0.2

View File

@@ -5,9 +5,9 @@
# 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_defs('//CSSLAYOUT_DEFS')
include_defs('//YOGA_DEFS')
UIKIT_CSSLAYOUT_COMPILER_FLAGS = [
COMPILER_FLAGS = [
'-fobjc-arc',
'-Wconditional-uninitialized',
'-Wdangling-else',
@@ -28,24 +28,23 @@ UIKIT_CSSLAYOUT_COMPILER_FLAGS = [
]
apple_library(
name = 'CSSLayoutKit',
compiler_flags = UIKIT_CSSLAYOUT_COMPILER_FLAGS,
tests = [':CSSLayoutKitTests'],
srcs = glob(['*.m']),
exported_headers = glob(['*.h']),
name = 'YogaKit',
compiler_flags = COMPILER_FLAGS,
srcs = glob(['Source/**/*.m']),
exported_headers = glob(['Source/**/*.h']),
frameworks = [
'$SDKROOT/System/Library/Frameworks/Foundation.framework',
'$SDKROOT/System/Library/Frameworks/UIKit.framework',
],
deps = [
csslayout_dep(':CSSLayout'),
yoga_dep(':yoga'),
],
visibility = ['PUBLIC'],
)
apple_test(
name = 'CSSLayoutKitTests',
compiler_flags = UIKIT_CSSLAYOUT_COMPILER_FLAGS,
name = 'YogaKitTests',
compiler_flags = COMPILER_FLAGS,
info_plist = 'Tests/Info.plist',
srcs = glob(['Tests/**/*.m']),
frameworks = [
@@ -53,7 +52,7 @@ apple_test(
'$PLATFORM_DIR/Developer/Library/Frameworks/XCTest.framework',
],
deps = [
':CSSLayoutKit',
':YogaKit',
],
visibility = ['PUBLIC'],
)

22
YogaKit/README.md Normal file
View File

@@ -0,0 +1,22 @@
# YogaKit
[![CocoaPods](https://img.shields.io/cocoapods/v/YogaKit.svg?style=flat)](https://cocoapods.org/pods/YogaKit)
[![Platform](https://img.shields.io/badge/platforms-iOS-orange.svg)](https://facebook.github.io/yoga/docs/api/yogakit/)
[![Languages](https://img.shields.io/badge/languages-ObjC%20%7C%20Swift-orange.svg)](https://facebook.github.io/yoga/docs/api/yogakit/)
## Installation
YogaKit is available to install via [CocoaPods](https://cocoapods.org/).
```
pod 'YogaKit', '~> 1.0.2'
```
## Getting Started
Checkout the docs [here](https://facebook.github.io/yoga/docs/api/yogakit/).
We also have a sample project. To try it out, clone this repo and open `YogaKitSample.xcodeproj` in the [YogaKitSample](https://github.com/facebook/yoga/tree/master/YogaKit/YogaKitSample) directory.
## 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.

View File

@@ -0,0 +1,17 @@
/**
* 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.
*/
#import "YGLayout.h"
#import <UIKit/UIKit.h>
@interface UIView (Yoga)
@property (nonatomic, readonly, strong) YGLayout *yoga;
@end

View File

@@ -0,0 +1,30 @@
/**
* 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.
*/
#import "UIView+Yoga.h"
#import "YGLayout+Private.h"
#import <objc/runtime.h>
static const void *kYGYogaAssociatedKey = &kYGYogaAssociatedKey;
@implementation UIView (YogaKit)
- (YGLayout *)yoga
{
YGLayout *yoga = objc_getAssociatedObject(self, kYGYogaAssociatedKey);
if (!yoga) {
yoga = [[YGLayout alloc] initWithView:self];
objc_setAssociatedObject(self, kYGYogaAssociatedKey, yoga, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
return yoga;
}
@end

View File

@@ -0,0 +1,19 @@
/**
* 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.
*/
#import "YGLayout.h"
#import <yoga/Yoga.h>
@interface YGLayout ()
@property (nonatomic, assign, readonly) YGNodeRef node;
- (instancetype)initWithView:(UIView *)view;
@end

118
YogaKit/Source/YGLayout.h Normal file
View File

@@ -0,0 +1,118 @@
/**
* 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.
*/
#import <UIKit/UIKit.h>
#import <yoga/YGEnums.h>
@interface YGLayout : NSObject
/**
The property that decides if we should include this view when calculating layout. Defaults to YES.
*/
@property (nonatomic, readwrite, assign, setter=setIncludedInLayout:) BOOL isIncludedInLayout;
/**
The property that decides during layout/sizing whether or not styling properties should be applied.
Defaults to NO.
*/
@property (nonatomic, readwrite, assign, setter=setEnabled:) BOOL isEnabled;
@property (nonatomic, readwrite, assign) YGDirection direction;
@property (nonatomic, readwrite, assign) YGFlexDirection flexDirection;
@property (nonatomic, readwrite, assign) YGJustify justifyContent;
@property (nonatomic, readwrite, assign) YGAlign alignContent;
@property (nonatomic, readwrite, assign) YGAlign alignItems;
@property (nonatomic, readwrite, assign) YGAlign alignSelf;
@property (nonatomic, readwrite, assign) YGPositionType position;
@property (nonatomic, readwrite, assign) YGWrap flexWrap;
@property (nonatomic, readwrite, assign) YGOverflow overflow;
@property (nonatomic, readwrite, assign) YGDisplay display;
@property (nonatomic, readwrite, assign) CGFloat flexGrow;
@property (nonatomic, readwrite, assign) CGFloat flexShrink;
@property (nonatomic, readwrite, assign) CGFloat flexBasis;
@property (nonatomic, readwrite, assign) CGFloat left;
@property (nonatomic, readwrite, assign) CGFloat top;
@property (nonatomic, readwrite, assign) CGFloat right;
@property (nonatomic, readwrite, assign) CGFloat bottom;
@property (nonatomic, readwrite, assign) CGFloat start;
@property (nonatomic, readwrite, assign) CGFloat end;
@property (nonatomic, readwrite, assign) CGFloat marginLeft;
@property (nonatomic, readwrite, assign) CGFloat marginTop;
@property (nonatomic, readwrite, assign) CGFloat marginRight;
@property (nonatomic, readwrite, assign) CGFloat marginBottom;
@property (nonatomic, readwrite, assign) CGFloat marginStart;
@property (nonatomic, readwrite, assign) CGFloat marginEnd;
@property (nonatomic, readwrite, assign) CGFloat marginHorizontal;
@property (nonatomic, readwrite, assign) CGFloat marginVertical;
@property (nonatomic, readwrite, assign) CGFloat margin;
@property (nonatomic, readwrite, assign) CGFloat paddingLeft;
@property (nonatomic, readwrite, assign) CGFloat paddingTop;
@property (nonatomic, readwrite, assign) CGFloat paddingRight;
@property (nonatomic, readwrite, assign) CGFloat paddingBottom;
@property (nonatomic, readwrite, assign) CGFloat paddingStart;
@property (nonatomic, readwrite, assign) CGFloat paddingEnd;
@property (nonatomic, readwrite, assign) CGFloat paddingHorizontal;
@property (nonatomic, readwrite, assign) CGFloat paddingVertical;
@property (nonatomic, readwrite, assign) CGFloat padding;
@property (nonatomic, readwrite, assign) CGFloat borderLeftWidth;
@property (nonatomic, readwrite, assign) CGFloat borderTopWidth;
@property (nonatomic, readwrite, assign) CGFloat borderRightWidth;
@property (nonatomic, readwrite, assign) CGFloat borderBottomWidth;
@property (nonatomic, readwrite, assign) CGFloat borderStartWidth;
@property (nonatomic, readwrite, assign) CGFloat borderEndWidth;
@property (nonatomic, readwrite, assign) CGFloat borderWidth;
@property (nonatomic, readwrite, assign) CGFloat width;
@property (nonatomic, readwrite, assign) CGFloat height;
@property (nonatomic, readwrite, assign) CGFloat minWidth;
@property (nonatomic, readwrite, assign) CGFloat minHeight;
@property (nonatomic, readwrite, assign) CGFloat maxWidth;
@property (nonatomic, readwrite, assign) CGFloat maxHeight;
// Yoga specific properties, not compatible with flexbox specification
@property (nonatomic, readwrite, assign) CGFloat aspectRatio;
/**
Get the resolved direction of this node. This won't be YGDirectionInherit
*/
@property (nonatomic, readonly, assign) YGDirection resolvedDirection;
/**
Perform a layout calculation and update the frames of the views in the hierarchy with the results
*/
- (void)applyLayout NS_SWIFT_NAME(applyLayout());
/**
Returns the size of the view if no constraints were given. This could equivalent to calling [self
sizeThatFits:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)];
*/
@property (nonatomic, readonly, assign) CGSize intrinsicSize;
/**
Returns the number of children that are using Flexbox.
*/
@property (nonatomic, readonly, assign) NSUInteger numberOfChildren;
/**
Return a BOOL indiciating whether or not we this node contains any subviews that are included in
Yoga's layout.
*/
@property (nonatomic, readonly, assign) BOOL isLeaf;
/**
Mark that a view's layout needs to be recalculated. Only works for leaf views.
*/
- (void)markDirty;
@end

406
YogaKit/Source/YGLayout.m Normal file
View File

@@ -0,0 +1,406 @@
/**
* 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.
*/
#import "YGLayout+Private.h"
#import "UIView+Yoga.h"
#define YG_PROPERTY(type, lowercased_name, capitalized_name) \
- (type)lowercased_name \
{ \
return YGNodeStyleGet##capitalized_name(self.node); \
} \
\
- (void)set##capitalized_name:(type)lowercased_name \
{ \
YGNodeStyleSet##capitalized_name(self.node, lowercased_name); \
}
#define YG_VALUE_PROPERTY(lowercased_name, capitalized_name) \
- (CGFloat)lowercased_name \
{ \
YGValue value = YGNodeStyleGet##capitalized_name(self.node); \
if (value.unit == YGUnitPixel) { \
return value.value; \
} else { \
return YGUndefined; \
} \
} \
\
- (void)set##capitalized_name:(CGFloat)lowercased_name \
{ \
YGNodeStyleSet##capitalized_name(self.node, lowercased_name); \
}
#define YG_EDGE_PROPERTY_GETTER(lowercased_name, capitalized_name, property, edge) \
- (CGFloat)lowercased_name \
{ \
return YGNodeStyleGet##property(self.node, edge); \
}
#define YG_SHORTHAND_EDGE_PROPERTY_GETTER(lowercased_name) \
- (CGFloat)lowercased_name \
{ \
return YGUndefined; \
}
#define YG_EDGE_PROPERTY_SETTER(lowercased_name, capitalized_name, property, edge) \
- (void)set##capitalized_name:(CGFloat)lowercased_name \
{ \
YGNodeStyleSet##property(self.node, edge, lowercased_name); \
}
#define YG_EDGE_PROPERTY(lowercased_name, capitalized_name, property, edge) \
YG_EDGE_PROPERTY_GETTER(lowercased_name, capitalized_name, property, edge) \
YG_EDGE_PROPERTY_SETTER(lowercased_name, capitalized_name, property, edge)
#define YG_SHORTHAND_EDGE_PROPERTY(lowercased_name, capitalized_name, property, edge) \
YG_SHORTHAND_EDGE_PROPERTY_GETTER(lowercased_name) \
YG_EDGE_PROPERTY_SETTER(lowercased_name, capitalized_name, property, edge)
#define YG_VALUE_EDGE_PROPERTY_GETTER(objc_lowercased_name, objc_capitalized_name, c_name, edge) \
- (CGFloat)objc_lowercased_name \
{ \
YGValue value = YGNodeStyleGet##c_name(self.node, edge); \
if (value.unit == YGUnitPixel) { \
return value.value; \
} else { \
return YGUndefined; \
} \
}
#define YG_VALUE_EDGE_PROPERTY_SETTER(objc_lowercased_name, objc_capitalized_name, c_name, edge) \
- (void)set##objc_capitalized_name:(CGFloat)objc_lowercased_name \
{ \
YGNodeStyleSet##c_name(self.node, edge, objc_lowercased_name); \
}
#define YG_VALUE_EDGE_PROPERTY(lowercased_name, capitalized_name, property, edge) \
YG_VALUE_EDGE_PROPERTY_GETTER(lowercased_name, capitalized_name, property, edge) \
YG_VALUE_EDGE_PROPERTY_SETTER(lowercased_name, capitalized_name, property, edge)
#define YG_VALUE_SHORTHAND_EDGE_PROPERTY(lowercased_name, capitalized_name, property, edge) \
YG_SHORTHAND_EDGE_PROPERTY_GETTER(lowercased_name) \
YG_VALUE_EDGE_PROPERTY_SETTER(lowercased_name, capitalized_name, property, edge)
#define YG_VALUE_EDGES_PROPERTIES(lowercased_name, capitalized_name) \
YG_VALUE_EDGE_PROPERTY(lowercased_name##Left, capitalized_name##Left, capitalized_name, YGEdgeLeft) \
YG_VALUE_EDGE_PROPERTY(lowercased_name##Top, capitalized_name##Top, capitalized_name, YGEdgeTop) \
YG_VALUE_EDGE_PROPERTY(lowercased_name##Right, capitalized_name##Right, capitalized_name, YGEdgeRight) \
YG_VALUE_EDGE_PROPERTY(lowercased_name##Bottom, capitalized_name##Bottom, capitalized_name, YGEdgeBottom) \
YG_VALUE_EDGE_PROPERTY(lowercased_name##Start, capitalized_name##Start, capitalized_name, YGEdgeStart) \
YG_VALUE_EDGE_PROPERTY(lowercased_name##End, capitalized_name##End, capitalized_name, YGEdgeEnd) \
YG_VALUE_SHORTHAND_EDGE_PROPERTY(lowercased_name##Horizontal, capitalized_name##Horizontal, capitalized_name, YGEdgeHorizontal) \
YG_VALUE_SHORTHAND_EDGE_PROPERTY(lowercased_name##Vertical, capitalized_name##Vertical, capitalized_name, YGEdgeVertical) \
YG_VALUE_SHORTHAND_EDGE_PROPERTY(lowercased_name, capitalized_name, capitalized_name, YGEdgeAll)
@interface YGLayout ()
@property (nonatomic, weak, readonly) UIView *view;
@end
@implementation YGLayout
@synthesize isEnabled=_isEnabled;
@synthesize isIncludedInLayout=_isIncludedInLayout;
@synthesize node=_node;
+ (void)initialize
{
YGSetExperimentalFeatureEnabled(YGExperimentalFeatureWebFlexBasis, true);
}
- (instancetype)initWithView:(UIView*)view
{
if (self = [super init]) {
_view = view;
_node = YGNodeNew();
YGNodeSetContext(_node, (__bridge void *) view);
_isEnabled = NO;
_isIncludedInLayout = YES;
}
return self;
}
- (void)dealloc
{
YGNodeFree(self.node);
}
- (void)markDirty
{
if (self.isLeaf) {
YGNodeMarkDirty(self.node);
}
}
- (NSUInteger)numberOfChildren
{
return YGNodeGetChildCount(self.node);
}
- (BOOL)isLeaf
{
NSAssert([NSThread isMainThread], @"This method must be called on the main thread.");
if (self.isEnabled) {
for (UIView *subview in self.view.subviews) {
YGLayout *const yoga = subview.yoga;
if (yoga.isEnabled && yoga.isIncludedInLayout) {
return NO;
}
}
}
return YES;
}
#pragma mark - Style
- (YGPositionType)position
{
return YGNodeStyleGetPositionType(self.node);
}
- (void)setPosition:(YGPositionType)position
{
YGNodeStyleSetPositionType(self.node, position);
}
YG_PROPERTY(YGDirection, direction, Direction)
YG_PROPERTY(YGFlexDirection, flexDirection, FlexDirection)
YG_PROPERTY(YGJustify, justifyContent, JustifyContent)
YG_PROPERTY(YGAlign, alignContent, AlignContent)
YG_PROPERTY(YGAlign, alignItems, AlignItems)
YG_PROPERTY(YGAlign, alignSelf, AlignSelf)
YG_PROPERTY(YGWrap, flexWrap, FlexWrap)
YG_PROPERTY(YGOverflow, overflow, Overflow)
YG_PROPERTY(YGDisplay, display, Display)
YG_PROPERTY(CGFloat, flexGrow, FlexGrow)
YG_PROPERTY(CGFloat, flexShrink, FlexShrink)
YG_VALUE_PROPERTY(flexBasis, FlexBasis)
YG_VALUE_EDGE_PROPERTY(left, Left, Position, YGEdgeLeft)
YG_VALUE_EDGE_PROPERTY(top, Top, Position, YGEdgeTop)
YG_VALUE_EDGE_PROPERTY(right, Right, Position, YGEdgeRight)
YG_VALUE_EDGE_PROPERTY(bottom, Bottom, Position, YGEdgeBottom)
YG_VALUE_EDGE_PROPERTY(start, Start, Position, YGEdgeStart)
YG_VALUE_EDGE_PROPERTY(end, End, Position, YGEdgeEnd)
YG_VALUE_EDGES_PROPERTIES(margin, Margin)
YG_VALUE_EDGES_PROPERTIES(padding, Padding)
YG_EDGE_PROPERTY(borderLeftWidth, BorderLeftWidth, Border, YGEdgeLeft)
YG_EDGE_PROPERTY(borderTopWidth, BorderTopWidth, Border, YGEdgeTop)
YG_EDGE_PROPERTY(borderRightWidth, BorderRightWidth, Border, YGEdgeRight)
YG_EDGE_PROPERTY(borderBottomWidth, BorderBottomWidth, Border, YGEdgeBottom)
YG_EDGE_PROPERTY(borderStartWidth, BorderStartWidth, Border, YGEdgeStart)
YG_EDGE_PROPERTY(borderEndWidth, BorderEndWidth, Border, YGEdgeEnd)
YG_SHORTHAND_EDGE_PROPERTY(borderWidth, BorderWidth, Border, YGEdgeAll)
YG_VALUE_PROPERTY(width, Width)
YG_VALUE_PROPERTY(height, Height)
YG_VALUE_PROPERTY(minWidth, MinWidth)
YG_VALUE_PROPERTY(minHeight, MinHeight)
YG_VALUE_PROPERTY(maxWidth, MaxWidth)
YG_VALUE_PROPERTY(maxHeight, MaxHeight)
YG_PROPERTY(CGFloat, aspectRatio, AspectRatio)
#pragma mark - Layout and Sizing
- (YGDirection)resolvedDirection
{
return YGNodeLayoutGetDirection(self.node);
}
- (void)applyLayout
{
[self calculateLayoutWithSize:self.view.bounds.size];
YGApplyLayoutToViewHierarchy(self.view);
}
- (CGSize)intrinsicSize
{
const CGSize constrainedSize = {
.width = YGUndefined,
.height = YGUndefined,
};
return [self calculateLayoutWithSize:constrainedSize];
}
#pragma mark - Private
- (CGSize)calculateLayoutWithSize:(CGSize)size
{
NSAssert([NSThread isMainThread], @"Yoga calculation must be done on main.");
NSAssert(self.isEnabled, @"Yoga is not enabled for this view.");
YGAttachNodesFromViewHierachy(self.view);
const YGNodeRef node = self.node;
YGNodeCalculateLayout(
node,
size.width,
size.height,
YGNodeStyleGetDirection(node));
return (CGSize) {
.width = YGNodeLayoutGetWidth(node),
.height = YGNodeLayoutGetHeight(node),
};
}
static YGSize YGMeasureView(
YGNodeRef node,
float width,
YGMeasureMode widthMode,
float height,
YGMeasureMode heightMode)
{
const CGFloat constrainedWidth = (widthMode == YGMeasureModeUndefined) ? CGFLOAT_MAX : width;
const CGFloat constrainedHeight = (heightMode == YGMeasureModeUndefined) ? CGFLOAT_MAX: height;
UIView *view = (__bridge UIView*) YGNodeGetContext(node);
const CGSize sizeThatFits = [view sizeThatFits:(CGSize) {
.width = constrainedWidth,
.height = constrainedHeight,
}];
return (YGSize) {
.width = YGSanitizeMeasurement(constrainedWidth, sizeThatFits.width, widthMode),
.height = YGSanitizeMeasurement(constrainedHeight, sizeThatFits.height, heightMode),
};
}
static CGFloat YGSanitizeMeasurement(
CGFloat constrainedSize,
CGFloat measuredSize,
YGMeasureMode measureMode)
{
CGFloat result;
if (measureMode == YGMeasureModeExactly) {
result = constrainedSize;
} else if (measureMode == YGMeasureModeAtMost) {
result = MIN(constrainedSize, measuredSize);
} else {
result = measuredSize;
}
return result;
}
static BOOL YGNodeHasExactSameChildren(const YGNodeRef node, NSArray<UIView *> *subviews)
{
if (YGNodeGetChildCount(node) != subviews.count) {
return NO;
}
for (int i=0; i<subviews.count; i++) {
if (YGNodeGetChild(node, i) != subviews[i].yoga.node) {
return NO;
}
}
return YES;
}
static void YGAttachNodesFromViewHierachy(UIView *const view)
{
YGLayout *const yoga = view.yoga;
const YGNodeRef node = yoga.node;
// Only leaf nodes should have a measure function
if (yoga.isLeaf) {
YGRemoveAllChildren(node);
YGNodeSetMeasureFunc(node, YGMeasureView);
} else {
YGNodeSetMeasureFunc(node, NULL);
NSMutableArray<UIView *> *subviewsToInclude = [[NSMutableArray alloc] initWithCapacity:view.subviews.count];
for (UIView *subview in view.subviews) {
if (subview.yoga.isIncludedInLayout) {
[subviewsToInclude addObject:subview];
}
}
if (!YGNodeHasExactSameChildren(node, subviewsToInclude)) {
YGRemoveAllChildren(node);
for (int i=0; i<subviewsToInclude.count; i++) {
YGNodeInsertChild(node, subviewsToInclude[i].yoga.node, i);
}
}
for (UIView *const subview in subviewsToInclude) {
YGAttachNodesFromViewHierachy(subview);
}
}
}
static void YGRemoveAllChildren(const YGNodeRef node)
{
if (node == NULL) {
return;
}
while (YGNodeGetChildCount(node) > 0) {
YGNodeRemoveChild(node, YGNodeGetChild(node, YGNodeGetChildCount(node) - 1));
}
}
static CGFloat YGRoundPixelValue(CGFloat value)
{
static CGFloat scale;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^(){
scale = [UIScreen mainScreen].scale;
});
return round(value * scale) / scale;
}
static void YGApplyLayoutToViewHierarchy(UIView *view)
{
NSCAssert([NSThread isMainThread], @"Framesetting should only be done on the main thread.");
const YGLayout *yoga = view.yoga;
if (!yoga.isIncludedInLayout) {
return;
}
YGNodeRef node = yoga.node;
const CGPoint topLeft = {
YGNodeLayoutGetLeft(node),
YGNodeLayoutGetTop(node),
};
const CGPoint bottomRight = {
topLeft.x + YGNodeLayoutGetWidth(node),
topLeft.y + YGNodeLayoutGetHeight(node),
};
view.frame = (CGRect) {
.origin = {
.x = YGRoundPixelValue(topLeft.x),
.y = YGRoundPixelValue(topLeft.y),
},
.size = {
.width = YGRoundPixelValue(bottomRight.x) - YGRoundPixelValue(topLeft.x),
.height = YGRoundPixelValue(bottomRight.y) - YGRoundPixelValue(topLeft.y),
},
};
if (!yoga.isLeaf) {
for (NSUInteger i=0; i<view.subviews.count; i++) {
YGApplyLayoutToViewHierarchy(view.subviews[i]);
}
}
}
@end

View File

@@ -0,0 +1,621 @@
/**
* 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.
*/
#import <XCTest/XCTest.h>
#import <YogaKit/UIView+Yoga.h>
#import <YogaKit/YGLayout+Private.h>
#import <yoga/Yoga.h>
@interface YogaKitTests : XCTestCase
@end
@implementation YogaKitTests
- (void)testNodesAreDeallocedWithSingleView
{
__weak YGLayout *layoutRef = nil;
@autoreleasepool {
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
view.yoga.flexBasis = 1;
layoutRef = view.yoga;
XCTAssertNotNil(layoutRef);
view = nil;
}
XCTAssertNil(layoutRef);
}
- (void)testNodesAreDeallocedCascade
{
__weak YGLayout *topLayout = nil;
__weak YGLayout *subviewLayout = nil;
@autoreleasepool {
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
topLayout = view.yoga;
topLayout.flexBasis = 1;
UIView *subview = [[UIView alloc] initWithFrame:CGRectZero];
subviewLayout = subview.yoga;
subviewLayout.flexBasis = 1;
view = nil;
}
XCTAssertNil(topLayout);
XCTAssertNil(subviewLayout);
}
- (void)testIsEnabled
{
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
XCTAssertFalse(view.yoga.isEnabled);
view.yoga.isEnabled = YES;
XCTAssertTrue(view.yoga.isEnabled);
view.yoga.isEnabled = NO;
XCTAssertFalse(view.yoga.isEnabled);
}
- (void)testSizeThatFitsAsserts
{
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
dispatch_sync(dispatch_queue_create("com.facebook.Yoga.testing", DISPATCH_QUEUE_SERIAL), ^(void){
XCTAssertThrows(view.yoga.intrinsicSize);
});
}
- (void)testSizeThatFitsSmoke
{
UIView *container = [[UIView alloc] initWithFrame:CGRectZero];
container.yoga.isEnabled = YES;
container.yoga.flexDirection = YGFlexDirectionRow;
container.yoga.alignItems = YGAlignFlexStart;
UILabel *longTextLabel = [[UILabel alloc] initWithFrame:CGRectZero];
longTextLabel.text = @"This is a very very very very very very very very long piece of text.";
longTextLabel.lineBreakMode = NSLineBreakByTruncatingTail;
longTextLabel.numberOfLines = 1;
longTextLabel.yoga.isEnabled = YES;
longTextLabel.yoga.flexShrink = 1;
[container addSubview:longTextLabel];
UIView *textBadgeView = [[UIView alloc] initWithFrame:CGRectZero];
textBadgeView.yoga.isEnabled = YES;
textBadgeView.yoga.margin = 0;
textBadgeView.yoga.width = 10;
textBadgeView.yoga.height = 10;
[container addSubview:textBadgeView];
const CGSize textBadgeViewSize = textBadgeView.yoga.intrinsicSize;
XCTAssertEqual(textBadgeViewSize.height, 10);
XCTAssertEqual(textBadgeViewSize.width, 10);
const CGSize containerSize = container.yoga.intrinsicSize;
const CGSize longTextLabelSize = longTextLabel.yoga.intrinsicSize;
XCTAssertEqual(longTextLabelSize.height, containerSize.height);
XCTAssertEqual(longTextLabelSize.width + textBadgeView.yoga.intrinsicSize.width, containerSize.width);
}
- (void)testThatMarkingLeafsAsDirtyWillTriggerASizeRecalculation
{
UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 50)];
container.yoga.isEnabled = YES;
container.yoga.flexDirection = YGFlexDirectionRow;
container.yoga.alignItems = YGAlignFlexStart;
UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero];
label.text = @"This is a short text.";
label.numberOfLines = 1;
label.yoga.isEnabled = YES;
[container addSubview:label];
[container.yoga applyLayout];
CGSize const labelSizeAfterFirstPass = label.frame.size;
label.text = @"This is a slightly longer text.";
XCTAssertTrue(CGSizeEqualToSize(label.frame.size, labelSizeAfterFirstPass));
[label.yoga markDirty];
[container.yoga applyLayout];
XCTAssertFalse(CGSizeEqualToSize(label.frame.size, labelSizeAfterFirstPass));
}
- (void)testFrameAndOriginPlacement
{
const CGSize containerSize = CGSizeMake(320, 50);
UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, containerSize.width, containerSize.height)];
container.yoga.isEnabled = YES;
container.yoga.flexDirection = YGFlexDirectionRow;
UIView *subview1 = [[UIView alloc] initWithFrame:CGRectZero];
subview1.yoga.isEnabled = YES;
subview1.yoga.flexGrow = 1;
[container addSubview:subview1];
UIView *subview2 = [[UIView alloc] initWithFrame:CGRectZero];
subview2.yoga.isEnabled = YES;
subview2.yoga.flexGrow = 1;
[container addSubview:subview2];
UIView *subview3 = [[UIView alloc] initWithFrame:CGRectZero];
subview3.yoga.isEnabled = YES;
subview3.yoga.flexGrow = 1;
[container addSubview:subview3];
[container.yoga applyLayout];
XCTAssertEqualWithAccuracy(subview2.frame.origin.x, CGRectGetMaxX(subview1.frame), FLT_EPSILON);
XCTAssertEqualWithAccuracy(subview3.frame.origin.x, CGRectGetMaxX(subview2.frame), FLT_EPSILON);
CGFloat totalWidth = 0;
for (UIView *view in container.subviews) {
totalWidth += view.bounds.size.width;
}
XCTAssertEqual(containerSize.width, totalWidth, @"The container's width is %.6f, the subviews take up %.6f", containerSize.width, totalWidth);
}
- (void)testThatLayoutIsCorrectWhenWeSwapViewOrder
{
const CGSize containerSize = CGSizeMake(300, 50);
UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, containerSize.width, containerSize.height)];
container.yoga.isEnabled = YES;
container.yoga.flexDirection = YGFlexDirectionRow;
UIView *subview1 = [[UIView alloc] initWithFrame:CGRectZero];
subview1.yoga.isEnabled = YES;
subview1.yoga.flexGrow = 1;
[container addSubview:subview1];
UIView *subview2 = [[UIView alloc] initWithFrame:CGRectZero];
subview2.yoga.isEnabled = YES;
subview2.yoga.flexGrow = 1;
[container addSubview:subview2];
UIView *subview3 = [[UIView alloc] initWithFrame:CGRectZero];
subview3.yoga.isEnabled = YES;
subview3.yoga.flexGrow = 1;
[container addSubview:subview3];
[container.yoga applyLayout];
XCTAssertTrue(CGRectEqualToRect(subview1.frame, CGRectMake(0, 0, 100, 50)));
XCTAssertTrue(CGRectEqualToRect(subview2.frame, CGRectMake(100, 0, 100, 50)));
XCTAssertTrue(CGRectEqualToRect(subview3.frame, CGRectMake(200, 0, 100, 50)));
[container exchangeSubviewAtIndex:2 withSubviewAtIndex:0];
subview2.yoga.isIncludedInLayout = NO;
[container.yoga applyLayout];
XCTAssertTrue(CGRectEqualToRect(subview3.frame, CGRectMake(0, 0, 150, 50)));
XCTAssertTrue(CGRectEqualToRect(subview1.frame, CGRectMake(150, 0, 150, 50)));
// this frame shouldn't have been modified since last time.
XCTAssertTrue(CGRectEqualToRect(subview2.frame, CGRectMake(100, 0, 100, 50)));
}
- (void)testThatWeRespectIncludeInLayoutFlag
{
const CGSize containerSize = CGSizeMake(300, 50);
UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, containerSize.width, containerSize.height)];
container.yoga.isEnabled = YES;
container.yoga.flexDirection = YGFlexDirectionRow;
UIView *subview1 = [[UIView alloc] initWithFrame:CGRectZero];
subview1.yoga.isEnabled = YES;
subview1.yoga.flexGrow = 1;
[container addSubview:subview1];
UIView *subview2 = [[UIView alloc] initWithFrame:CGRectZero];
subview2.yoga.isEnabled = YES;
subview2.yoga.flexGrow = 1;
[container addSubview:subview2];
UIView *subview3 = [[UIView alloc] initWithFrame:CGRectZero];
subview3.yoga.isEnabled = YES;
subview3.yoga.flexGrow = 1;
[container addSubview:subview3];
[container.yoga applyLayout];
for (UIView *subview in container.subviews) {
XCTAssertEqual(subview.bounds.size.width, 100);
}
subview3.yoga.isIncludedInLayout = NO;
[container.yoga applyLayout];
XCTAssertEqual(subview1.bounds.size.width, 150);
XCTAssertEqual(subview2.bounds.size.width, 150);
// We don't set the frame to zero, so, it should be set to what it was previously at.
XCTAssertEqual(subview3.bounds.size.width, 100);
}
- (void)testThatNumberOfChildrenIsCorrectWhenWeIgnoreSubviews
{
UIView *container = [[UIView alloc] initWithFrame:CGRectZero];
container.yoga.isEnabled = YES;
container.yoga.flexDirection = YGFlexDirectionRow;
UIView *subview1 = [[UIView alloc] initWithFrame:CGRectZero];
subview1.yoga.isEnabled = YES;
subview1.yoga.isIncludedInLayout = NO;
[container addSubview:subview1];
UIView *subview2 = [[UIView alloc] initWithFrame:CGRectZero];
subview2.yoga.isEnabled = YES;
subview2.yoga.isIncludedInLayout = NO;
[container addSubview:subview2];
UIView *subview3 = [[UIView alloc] initWithFrame:CGRectZero];
subview3.yoga.isEnabled = YES;
subview3.yoga.isIncludedInLayout = YES;
[container addSubview:subview3];
[container.yoga applyLayout];
XCTAssertEqual(container.yoga.numberOfChildren, 1);
subview2.yoga.isIncludedInLayout = YES;
[container.yoga applyLayout];
XCTAssertEqual(container.yoga.numberOfChildren, 2);
}
- (void)testThatViewNotIncludedInFirstLayoutPassAreIncludedInSecond
{
UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 50)];
container.yoga.isEnabled = YES;
container.yoga.flexDirection = YGFlexDirectionRow;
UIView *subview1 = [[UIView alloc] initWithFrame:CGRectZero];
subview1.yoga.isEnabled = YES;
subview1.yoga.flexGrow = 1;
[container addSubview:subview1];
UIView *subview2 = [[UIView alloc] initWithFrame:CGRectZero];
subview2.yoga.isEnabled = YES;
subview2.yoga.flexGrow = 1;
[container addSubview:subview2];
UIView *subview3 = [[UIView alloc] initWithFrame:CGRectZero];
subview3.yoga.isEnabled = YES;
subview3.yoga.flexGrow = 1;
subview3.yoga.isIncludedInLayout = NO;
[container addSubview:subview3];
[container.yoga applyLayout];
XCTAssertEqual(subview1.bounds.size.width, 150);
XCTAssertEqual(subview2.bounds.size.width, 150);
XCTAssertEqual(subview3.bounds.size.width, 0);
subview3.yoga.isIncludedInLayout = YES;
[container.yoga applyLayout];
XCTAssertEqual(subview1.bounds.size.width, 100);
XCTAssertEqual(subview2.bounds.size.width, 100);
XCTAssertEqual(subview3.bounds.size.width, 100);
}
- (void)testIsLeafFlag
{
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
XCTAssertTrue(view.yoga.isLeaf);
for (int i=0; i<10; i++) {
UIView *subview = [[UIView alloc] initWithFrame:CGRectZero];
[view addSubview:subview];
}
XCTAssertTrue(view.yoga.isLeaf);
view.yoga.isEnabled = YES;
view.yoga.width = 50.0;
XCTAssertTrue(view.yoga.isLeaf);
UIView *const subview = view.subviews[0];
subview.yoga.isEnabled = YES;
subview.yoga.width = 50.0;
XCTAssertFalse(view.yoga.isLeaf);
}
- (void)testThatWeCorrectlyAttachNestedViews
{
UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 50)];
container.yoga.isEnabled = YES;
container.yoga.flexDirection = YGFlexDirectionColumn;
UIView *subview1 = [[UIView alloc] initWithFrame:CGRectZero];
subview1.yoga.isEnabled = YES;
subview1.yoga.width = 100;
subview1.yoga.flexGrow = 1;
subview1.yoga.flexDirection = YGFlexDirectionColumn;
[container addSubview:subview1];
UIView *subview2 = [[UIView alloc] initWithFrame:CGRectZero];
subview2.yoga.isEnabled = YES;
subview2.yoga.width = 150;
subview2.yoga.flexGrow = 1;
subview2.yoga.flexDirection = YGFlexDirectionColumn;
[container addSubview:subview2];
for (UIView *view in @[subview1, subview2]) {
UIView *someView = [[UIView alloc] initWithFrame:CGRectZero];
someView.yoga.isEnabled = YES;
someView.yoga.flexGrow = 1;
[view addSubview:someView];
}
[container.yoga applyLayout];
// Add the same amount of new views, reapply layout.
for (UIView *view in @[subview1, subview2]) {
UIView *someView = [[UIView alloc] initWithFrame:CGRectZero];
someView.yoga.isEnabled = YES;
someView.yoga.flexGrow = 1;
[view addSubview:someView];
}
[container.yoga applyLayout];
XCTAssertEqual(subview1.bounds.size.width, 100);
XCTAssertEqual(subview1.bounds.size.height, 25);
for (UIView *subview in subview1.subviews) {
const CGSize subviewSize = subview.bounds.size;
XCTAssertNotEqual(subviewSize.width, 0);
XCTAssertNotEqual(subviewSize.height, 0);
XCTAssertFalse(isnan(subviewSize.height));
XCTAssertFalse(isnan(subviewSize.width));
}
XCTAssertEqual(subview2.bounds.size.width, 150);
XCTAssertEqual(subview2.bounds.size.height, 25);
for (UIView *subview in subview2.subviews) {
const CGSize subviewSize = subview.bounds.size;
XCTAssertNotEqual(subviewSize.width, 0);
XCTAssertNotEqual(subviewSize.height, 0);
XCTAssertFalse(isnan(subviewSize.height));
XCTAssertFalse(isnan(subviewSize.width));
}
}
- (void)testThatANonLeafNodeCanBecomeALeafNode
{
UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 50)];
container.yoga.isEnabled = YES;
UIView *subview1 = [[UIView alloc] initWithFrame:CGRectZero];
subview1.yoga.isEnabled = YES;
[container addSubview:subview1];
UIView *subview2 = [[UIView alloc] initWithFrame:CGRectZero];
subview2.yoga.isEnabled = YES;
[subview1 addSubview:subview2];
[container.yoga applyLayout];
[subview2 removeFromSuperview];
[container.yoga applyLayout];
}
- (void)testPositionalPropertiesWork
{
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
view.yoga.left = 1;
XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeLeft).value, 1);
XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeLeft).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.left, 1);
view.yoga.right = 2;
XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeRight).value, 2);
XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeRight).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.right, 2);
view.yoga.top = 3;
XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeTop).value, 3);
XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeTop).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.top, 3);
view.yoga.bottom = 4;
XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeBottom).value, 4);
XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeBottom).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.bottom, 4);
view.yoga.start = 5;
XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeStart).value, 5);
XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeStart).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.start, 5);
view.yoga.end = 6;
XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeEnd).value, 6);
XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeEnd).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.end, 6);
}
- (void)testMarginPropertiesWork
{
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
view.yoga.margin = 1;
XCTAssertEqual(view.yoga.marginLeft, 1);
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeLeft).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.marginRight, 1);
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeRight).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.marginStart, 1);
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeStart).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.marginEnd, 1);
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeEnd).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.marginTop, 1);
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeTop).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.marginBottom, 1);
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeBottom).unit, YGUnitPixel);
XCTAssertTrue(isnan(view.yoga.marginHorizontal));
XCTAssertTrue(isnan(view.yoga.marginVertical));
XCTAssertTrue(isnan(view.yoga.margin));
view.yoga.marginHorizontal = 2;
XCTAssertEqual(view.yoga.marginLeft, 2);
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeLeft).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.marginRight, 2);
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeRight).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.marginStart, 2);
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeStart).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.marginEnd, 2);
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeEnd).unit, YGUnitPixel);
XCTAssertTrue(isnan(view.yoga.marginHorizontal));
view.yoga.marginVertical = 3;
XCTAssertEqual(view.yoga.marginTop, 3);
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeTop).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.marginBottom, 3);
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeBottom).unit, YGUnitPixel);
XCTAssertTrue(isnan(view.yoga.marginVertical));
view.yoga.marginLeft = 4;
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeLeft).value, 4);
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeLeft).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.marginLeft, 4);
view.yoga.marginRight = 5;
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeRight).value, 5);
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeRight).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.marginRight, 5);
view.yoga.marginTop = 6;
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeTop).value, 6);
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeTop).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.marginTop, 6);
view.yoga.marginBottom = 7;
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeBottom).value, 7);
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeBottom).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.marginBottom, 7);
view.yoga.marginStart = 8;
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeStart).value, 8);
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeStart).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.marginStart, 8);
view.yoga.marginEnd = 9;
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeEnd).value, 9);
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeEnd).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.marginEnd, 9);
}
- (void)testPaddingPropertiesWork
{
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
view.yoga.padding = 1;
XCTAssertEqual(view.yoga.paddingLeft, 1);
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeLeft).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.paddingRight, 1);
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeRight).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.paddingStart, 1);
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeStart).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.paddingEnd, 1);
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeEnd).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.paddingTop, 1);
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeTop).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.paddingBottom, 1);
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeBottom).unit, YGUnitPixel);
XCTAssertTrue(isnan(view.yoga.paddingHorizontal));
XCTAssertTrue(isnan(view.yoga.paddingVertical));
XCTAssertTrue(isnan(view.yoga.padding));
view.yoga.paddingHorizontal = 2;
XCTAssertEqual(view.yoga.paddingLeft, 2);
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeLeft).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.paddingRight, 2);
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeRight).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.paddingStart, 2);
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeStart).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.paddingEnd, 2);
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeEnd).unit, YGUnitPixel);
XCTAssertTrue(isnan(view.yoga.paddingHorizontal));
view.yoga.paddingVertical = 3;
XCTAssertEqual(view.yoga.paddingTop, 3);
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeTop).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.paddingBottom, 3);
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeBottom).unit, YGUnitPixel);
XCTAssertTrue(isnan(view.yoga.paddingVertical));
view.yoga.paddingLeft = 4;
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeLeft).value, 4);
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeLeft).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.paddingLeft, 4);
view.yoga.paddingRight = 5;
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeRight).value, 5);
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeRight).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.paddingRight, 5);
view.yoga.paddingTop = 6;
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeTop).value, 6);
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeTop).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.paddingTop, 6);
view.yoga.paddingBottom = 7;
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeBottom).value, 7);
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeBottom).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.paddingBottom, 7);
view.yoga.paddingStart = 8;
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeStart).value, 8);
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeStart).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.paddingStart, 8);
view.yoga.paddingEnd = 9;
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeEnd).value, 9);
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeEnd).unit, YGUnitPixel);
XCTAssertEqual(view.yoga.paddingEnd, 9);
}
- (void)testBorderWidthPropertiesWork
{
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
view.yoga.borderWidth = 1;
XCTAssertEqual(view.yoga.borderLeftWidth, 1);
XCTAssertEqual(view.yoga.borderRightWidth, 1);
XCTAssertEqual(view.yoga.borderStartWidth, 1);
XCTAssertEqual(view.yoga.borderEndWidth, 1);
XCTAssertEqual(view.yoga.borderTopWidth, 1);
XCTAssertEqual(view.yoga.borderBottomWidth, 1);
XCTAssertTrue(isnan(view.yoga.borderWidth));
view.yoga.borderLeftWidth = 2;
XCTAssertEqual(view.yoga.borderLeftWidth, 2);
view.yoga.borderRightWidth = 3;
XCTAssertEqual(view.yoga.borderRightWidth, 3);
view.yoga.borderTopWidth = 4;
XCTAssertEqual(view.yoga.borderTopWidth, 4);
view.yoga.borderBottomWidth = 5;
XCTAssertEqual(view.yoga.borderBottomWidth, 5);
view.yoga.borderStartWidth = 6;
XCTAssertEqual(view.yoga.borderStartWidth, 6);
view.yoga.borderEndWidth = 7;
XCTAssertEqual(view.yoga.borderEndWidth, 7);
}
@end

View File

@@ -0,0 +1,5 @@
use_frameworks!
target 'YogaKitSample' do
pod 'YogaKit', :path => '../../YogaKit.podspec'
end

View File

@@ -0,0 +1,19 @@
PODS:
- Yoga (1.0.2)
- YogaKit (1.0.3):
- Yoga (~> 1.0)
DEPENDENCIES:
- YogaKit (from `../../YogaKit.podspec`)
EXTERNAL SOURCES:
YogaKit:
:path: "../../YogaKit.podspec"
SPEC CHECKSUMS:
Yoga: ef42f88b9bcbd7daf7267c0f19d8636ce3a50618
YogaKit: 6d9826a015c029b13731a33bf96fe6c1e33748a6
PODFILE CHECKSUM: 9db3bdea7f1b4b715ad859a449b2dc87fb6226cc
COCOAPODS: 1.2.0

View File

@@ -0,0 +1,514 @@
// !$*UTF8*$!
{
archiveVersion = 1;
classes = {
};
objectVersion = 46;
objects = {
/* Begin PBXBuildFile section */
13687D481DF8748400E7C260 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13687D471DF8748400E7C260 /* main.m */; };
13687D4B1DF8748400E7C260 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 13687D4A1DF8748400E7C260 /* AppDelegate.m */; };
13687D4E1DF8748400E7C260 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 13687D4D1DF8748400E7C260 /* ViewController.m */; };
13687D531DF8748400E7C260 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13687D521DF8748400E7C260 /* Assets.xcassets */; };
13687D851DF87D1E00E7C260 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 13687D841DF87D1E00E7C260 /* UIKit.framework */; };
13687D871DF87D2400E7C260 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 13687D861DF87D2400E7C260 /* Foundation.framework */; };
15A7CB5995C9DAB1C8803834 /* Pods_YogaKitSample.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C80A931E90C7F3088CB86822 /* Pods_YogaKitSample.framework */; };
638A94481E1F06D100A726AD /* SwiftViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 638A94471E1F06D100A726AD /* SwiftViewController.swift */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
638A94541E215CC800A726AD /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 13687D3B1DF8748300E7C260 /* Project object */;
proxyType = 1;
remoteGlobalIDString = 13687D421DF8748300E7C260;
remoteInfo = YogaKitSample;
};
/* End PBXContainerItemProxy section */
/* Begin PBXCopyFilesBuildPhase section */
13687D771DF878A000E7C260 /* yoga */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = include/yoga;
dstSubfolderSpec = 16;
files = (
);
name = yoga;
runOnlyForDeploymentPostprocessing = 0;
};
13687D7B1DF878CE00E7C260 /* YogaKit */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = include/YogaKit;
dstSubfolderSpec = 16;
files = (
);
name = YogaKit;
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
13687D431DF8748400E7C260 /* YogaKitSample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = YogaKitSample.app; sourceTree = BUILT_PRODUCTS_DIR; };
13687D471DF8748400E7C260 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
13687D491DF8748400E7C260 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
13687D4A1DF8748400E7C260 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
13687D4C1DF8748400E7C260 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = "<group>"; };
13687D4D1DF8748400E7C260 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = "<group>"; };
13687D521DF8748400E7C260 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
13687D571DF8748400E7C260 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
13687D841DF87D1E00E7C260 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
13687D861DF87D2400E7C260 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
1D2FF4D5FCA6A8C54A4074A3 /* Pods-YogaKitSample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-YogaKitSample.debug.xcconfig"; path = "Pods/Target Support Files/Pods-YogaKitSample/Pods-YogaKitSample.debug.xcconfig"; sourceTree = "<group>"; };
638A94471E1F06D100A726AD /* SwiftViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftViewController.swift; sourceTree = "<group>"; };
638A944F1E215CC800A726AD /* YogaKitSampleTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = YogaKitSampleTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
82F0896A88112E957EF37C7F /* Pods-YogaKitSample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-YogaKitSample.release.xcconfig"; path = "Pods/Target Support Files/Pods-YogaKitSample/Pods-YogaKitSample.release.xcconfig"; sourceTree = "<group>"; };
C80A931E90C7F3088CB86822 /* Pods_YogaKitSample.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_YogaKitSample.framework; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
13687D401DF8748300E7C260 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
13687D871DF87D2400E7C260 /* Foundation.framework in Frameworks */,
13687D851DF87D1E00E7C260 /* UIKit.framework in Frameworks */,
15A7CB5995C9DAB1C8803834 /* Pods_YogaKitSample.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
638A944C1E215CC800A726AD /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
13687D3A1DF8748300E7C260 = {
isa = PBXGroup;
children = (
13687D451DF8748400E7C260 /* YogaKitSample */,
13687D441DF8748400E7C260 /* Products */,
13687D831DF87D1E00E7C260 /* Frameworks */,
E1C759E3C8E84821213ECE8D /* Pods */,
);
sourceTree = "<group>";
};
13687D441DF8748400E7C260 /* Products */ = {
isa = PBXGroup;
children = (
13687D431DF8748400E7C260 /* YogaKitSample.app */,
638A944F1E215CC800A726AD /* YogaKitSampleTests.xctest */,
);
name = Products;
sourceTree = "<group>";
};
13687D451DF8748400E7C260 /* YogaKitSample */ = {
isa = PBXGroup;
children = (
13687D491DF8748400E7C260 /* AppDelegate.h */,
13687D4A1DF8748400E7C260 /* AppDelegate.m */,
13687D4C1DF8748400E7C260 /* ViewController.h */,
13687D4D1DF8748400E7C260 /* ViewController.m */,
638A94471E1F06D100A726AD /* SwiftViewController.swift */,
13687D521DF8748400E7C260 /* Assets.xcassets */,
13687D571DF8748400E7C260 /* Info.plist */,
13687D461DF8748400E7C260 /* Supporting Files */,
);
path = YogaKitSample;
sourceTree = "<group>";
};
13687D461DF8748400E7C260 /* Supporting Files */ = {
isa = PBXGroup;
children = (
13687D471DF8748400E7C260 /* main.m */,
);
name = "Supporting Files";
sourceTree = "<group>";
};
13687D831DF87D1E00E7C260 /* Frameworks */ = {
isa = PBXGroup;
children = (
13687D861DF87D2400E7C260 /* Foundation.framework */,
13687D841DF87D1E00E7C260 /* UIKit.framework */,
C80A931E90C7F3088CB86822 /* Pods_YogaKitSample.framework */,
);
name = Frameworks;
sourceTree = "<group>";
};
E1C759E3C8E84821213ECE8D /* Pods */ = {
isa = PBXGroup;
children = (
1D2FF4D5FCA6A8C54A4074A3 /* Pods-YogaKitSample.debug.xcconfig */,
82F0896A88112E957EF37C7F /* Pods-YogaKitSample.release.xcconfig */,
);
name = Pods;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
13687D421DF8748300E7C260 /* YogaKitSample */ = {
isa = PBXNativeTarget;
buildConfigurationList = 13687D5A1DF8748400E7C260 /* Build configuration list for PBXNativeTarget "YogaKitSample" */;
buildPhases = (
513B543F92B2E4F4D1EE1CE7 /* [CP] Check Pods Manifest.lock */,
13687D771DF878A000E7C260 /* yoga */,
13687D7B1DF878CE00E7C260 /* YogaKit */,
13687D3F1DF8748300E7C260 /* Sources */,
13687D401DF8748300E7C260 /* Frameworks */,
13687D411DF8748300E7C260 /* Resources */,
FA2FB9DD6471BDD3FBCE503B /* [CP] Embed Pods Frameworks */,
6E01EB987F1564F3D71EBE5A /* [CP] Copy Pods Resources */,
);
buildRules = (
);
dependencies = (
);
name = YogaKitSample;
productName = YogaKitSample;
productReference = 13687D431DF8748400E7C260 /* YogaKitSample.app */;
productType = "com.apple.product-type.application";
};
638A944E1E215CC800A726AD /* YogaKitSampleTests */ = {
isa = PBXNativeTarget;
buildConfigurationList = 638A94561E215CC800A726AD /* Build configuration list for PBXNativeTarget "YogaKitSampleTests" */;
buildPhases = (
638A944B1E215CC800A726AD /* Sources */,
638A944C1E215CC800A726AD /* Frameworks */,
638A944D1E215CC800A726AD /* Resources */,
);
buildRules = (
);
dependencies = (
638A94551E215CC800A726AD /* PBXTargetDependency */,
);
name = YogaKitSampleTests;
productName = YogaKitSampleTests;
productReference = 638A944F1E215CC800A726AD /* YogaKitSampleTests.xctest */;
productType = "com.apple.product-type.bundle.unit-test";
};
/* End PBXNativeTarget section */
/* Begin PBXProject section */
13687D3B1DF8748300E7C260 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0820;
ORGANIZATIONNAME = facebook;
TargetAttributes = {
13687D421DF8748300E7C260 = {
CreatedOnToolsVersion = 8.1;
LastSwiftMigration = 0820;
ProvisioningStyle = Automatic;
};
638A944E1E215CC800A726AD = {
CreatedOnToolsVersion = 8.2.1;
ProvisioningStyle = Automatic;
TestTargetID = 13687D421DF8748300E7C260;
};
};
};
buildConfigurationList = 13687D3E1DF8748300E7C260 /* Build configuration list for PBXProject "YogaKitSample" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
en,
Base,
);
mainGroup = 13687D3A1DF8748300E7C260;
productRefGroup = 13687D441DF8748400E7C260 /* Products */;
projectDirPath = "";
projectRoot = "";
targets = (
13687D421DF8748300E7C260 /* YogaKitSample */,
638A944E1E215CC800A726AD /* YogaKitSampleTests */,
);
};
/* End PBXProject section */
/* Begin PBXResourcesBuildPhase section */
13687D411DF8748300E7C260 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
13687D531DF8748400E7C260 /* Assets.xcassets in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
638A944D1E215CC800A726AD /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXResourcesBuildPhase section */
/* Begin PBXShellScriptBuildPhase section */
513B543F92B2E4F4D1EE1CE7 /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "[CP] Check Pods Manifest.lock";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
showEnvVarsInLog = 0;
};
6E01EB987F1564F3D71EBE5A /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "[CP] Copy Pods Resources";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-YogaKitSample/Pods-YogaKitSample-resources.sh\"\n";
showEnvVarsInLog = 0;
};
FA2FB9DD6471BDD3FBCE503B /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-YogaKitSample/Pods-YogaKitSample-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
/* End PBXShellScriptBuildPhase section */
/* Begin PBXSourcesBuildPhase section */
13687D3F1DF8748300E7C260 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
638A94481E1F06D100A726AD /* SwiftViewController.swift in Sources */,
13687D4E1DF8748400E7C260 /* ViewController.m in Sources */,
13687D4B1DF8748400E7C260 /* AppDelegate.m in Sources */,
13687D481DF8748400E7C260 /* main.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
638A944B1E215CC800A726AD /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
/* Begin PBXTargetDependency section */
638A94551E215CC800A726AD /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = 13687D421DF8748300E7C260 /* YogaKitSample */;
targetProxy = 638A94541E215CC800A726AD /* PBXContainerItemProxy */;
};
/* End PBXTargetDependency section */
/* Begin XCBuildConfiguration section */
13687D581DF8748400E7C260 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_SUSPICIOUS_MOVES = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 10.1;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
};
name = Debug;
};
13687D591DF8748400E7C260 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_SUSPICIOUS_MOVES = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 10.1;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
VALIDATE_PRODUCT = YES;
};
name = Release;
};
13687D5B1DF8748400E7C260 /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 1D2FF4D5FCA6A8C54A4074A3 /* Pods-YogaKitSample.debug.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
INFOPLIST_FILE = YogaKitSample/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.facebook.YogaKitSample;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_INSTALL_OBJC_HEADER = NO;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
13687D5C1DF8748400E7C260 /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 82F0896A88112E957EF37C7F /* Pods-YogaKitSample.release.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
INFOPLIST_FILE = YogaKitSample/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.facebook.YogaKitSample;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_INSTALL_OBJC_HEADER = NO;
SWIFT_VERSION = 3.0;
};
name = Release;
};
638A94571E215CC800A726AD /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
BUNDLE_LOADER = "$(TEST_HOST)";
INFOPLIST_FILE = YogaKitSampleTests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 10.2;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.facebook.YogaKitSampleTests;
PRODUCT_NAME = "$(TARGET_NAME)";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/YogaKitSample.app/YogaKitSample";
};
name = Debug;
};
638A94581E215CC800A726AD /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
BUNDLE_LOADER = "$(TEST_HOST)";
INFOPLIST_FILE = YogaKitSampleTests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 10.2;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.facebook.YogaKitSampleTests;
PRODUCT_NAME = "$(TARGET_NAME)";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/YogaKitSample.app/YogaKitSample";
};
name = Release;
};
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
13687D3E1DF8748300E7C260 /* Build configuration list for PBXProject "YogaKitSample" */ = {
isa = XCConfigurationList;
buildConfigurations = (
13687D581DF8748400E7C260 /* Debug */,
13687D591DF8748400E7C260 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
13687D5A1DF8748400E7C260 /* Build configuration list for PBXNativeTarget "YogaKitSample" */ = {
isa = XCConfigurationList;
buildConfigurations = (
13687D5B1DF8748400E7C260 /* Debug */,
13687D5C1DF8748400E7C260 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
638A94561E215CC800A726AD /* Build configuration list for PBXNativeTarget "YogaKitSampleTests" */ = {
isa = XCConfigurationList;
buildConfigurations = (
638A94571E215CC800A726AD /* Debug */,
638A94581E215CC800A726AD /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
rootObject = 13687D3B1DF8748300E7C260 /* Project object */;
}

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "self:YogaKitSample.xcodeproj">
</FileRef>
</Workspace>

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "group:YogaKitSample.xcodeproj">
</FileRef>
<FileRef
location = "group:Pods/Pods.xcodeproj">
</FileRef>
</Workspace>

View File

@@ -0,0 +1,15 @@
/**
* 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.
*/
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end

View File

@@ -0,0 +1,27 @@
/**
* 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.
*/
#import "AppDelegate.h"
#import "ViewController.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = [ViewController new];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
@end

View File

@@ -0,0 +1,74 @@
{
"images" : [
{
"size" : "20x20",
"idiom" : "iphone",
"filename" : "Yoga-20x20@2x.png",
"scale" : "2x"
},
{
"size" : "20x20",
"idiom" : "iphone",
"filename" : "Yoga-20x20@3x.png",
"scale" : "3x"
},
{
"size" : "29x29",
"idiom" : "iphone",
"filename" : "Yoga-29x29@1x.png",
"scale" : "1x"
},
{
"size" : "29x29",
"idiom" : "iphone",
"filename" : "Yoga-29x29@2x.png",
"scale" : "2x"
},
{
"size" : "29x29",
"idiom" : "iphone",
"filename" : "Yoga-29x29@3x.png",
"scale" : "3x"
},
{
"size" : "40x40",
"idiom" : "iphone",
"filename" : "Yoga-40x40@2x.png",
"scale" : "2x"
},
{
"size" : "40x40",
"idiom" : "iphone",
"filename" : "Yoga-40x40@3x.png",
"scale" : "3x"
},
{
"size" : "57x57",
"idiom" : "iphone",
"filename" : "Yoga-57x57@1x.png",
"scale" : "1x"
},
{
"size" : "57x57",
"idiom" : "iphone",
"filename" : "Yoga-57x57@2x.png",
"scale" : "2x"
},
{
"size" : "60x60",
"idiom" : "iphone",
"filename" : "Yoga-60x60@2x.png",
"scale" : "2x"
},
{
"size" : "60x60",
"idiom" : "iphone",
"filename" : "Yoga-60x60@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 868 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB

View File

@@ -0,0 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}

View File

@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>
<string></string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>

View File

@@ -0,0 +1,41 @@
/**
* 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.
*/
import UIKit
import YogaKit
class SwiftViewController: UIViewController {
override func viewDidLoad() {
let root = self.view!
root.backgroundColor = .red
root.yoga.isEnabled = true
root.yoga.width = self.view.bounds.size.width
root.yoga.height = self.view.bounds.size.height
root.yoga.alignItems = .center
root.yoga.justifyContent = .center
let child1 = UIView()
child1.backgroundColor = .blue
child1.yoga.isEnabled = true
child1.yoga.width = 100
child1.yoga.height = 10
let child2 = UIView()
child2.backgroundColor = .green
child2.frame = CGRect(x: 0, y: 0, width: 200, height: 100)
let child3 = UIView()
child3.backgroundColor = .yellow
child3.frame = CGRect(x: 0, y: 0, width: 100, height: 100)
child2.addSubview(child3)
root.addSubview(child1)
root.addSubview(child2)
root.yoga.applyLayout()
}
}

View File

@@ -0,0 +1,13 @@
/**
* 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.
*/
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@end

View File

@@ -0,0 +1,60 @@
/**
* 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.
*/
#import "ViewController.h"
#import <YogaKit/UIView+Yoga.h>
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
UIView *root = self.view;
root.backgroundColor = [UIColor redColor];
root.yoga.isEnabled = YES;
root.yoga.width = self.view.bounds.size.width;
root.yoga.height = self.view.bounds.size.height;
root.yoga.alignItems = YGAlignCenter;
root.yoga.justifyContent = YGJustifyCenter;
UIView *child1 = [UIView new];
child1.backgroundColor = [UIColor blueColor];
child1.yoga.isEnabled = YES;
child1.yoga.width = 100;
child1.yoga.height = 100;
UIView *child2 = [UIView new];
child2.backgroundColor = [UIColor greenColor];
child2.frame = (CGRect) {
.size = {
.width = 200,
.height = 100,
}
};
UIView *child3 = [UIView new];
child3.backgroundColor = [UIColor yellowColor];
child3.frame = (CGRect) {
.size = {
.width = 100,
.height = 100,
}
};
[child2 addSubview:child3];
[root addSubview:child1];
[root addSubview:child2];
[root.yoga applyLayout];
}
@end

View File

@@ -0,0 +1,16 @@
/**
* 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.
*/
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
int main(int argc, char * argv[]) {
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}

View File

@@ -5,7 +5,7 @@
# 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_defs('//CSSLAYOUT_DEFS')
include_defs('//YOGA_DEFS')
cxx_binary(
name = 'benchmark',
@@ -21,7 +21,7 @@ cxx_binary(
'-std=c11',
],
deps = [
csslayout_dep(':CSSLayout'),
yoga_dep(':yoga'),
],
visibility = ['PUBLIC'],
)

View File

@@ -1,118 +0,0 @@
/**
* 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 "CSSBenchmark.h"
#include <CSSLayout/CSSLayout.h>
static CSSSize _measure(CSSNodeRef node,
float width,
CSSMeasureMode widthMode,
float height,
CSSMeasureMode heightMode) {
return (CSSSize){
.width = widthMode == CSSMeasureModeUndefined ? 10 : width,
.height = heightMode == CSSMeasureModeUndefined ? 10 : width,
};
}
CSS_BENCHMARKS({
CSS_BENCHMARK("Stack with flex", {
const CSSNodeRef root = CSSNodeNew();
CSSNodeStyleSetWidth(root, 100);
CSSNodeStyleSetHeight(root, 100);
for (uint32_t i = 0; i < 10; i++) {
const CSSNodeRef child = CSSNodeNew();
CSSNodeSetMeasureFunc(child, _measure);
CSSNodeStyleSetFlex(child, 1);
CSSNodeInsertChild(root, child, 0);
}
CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR);
CSSNodeFreeRecursive(root);
});
CSS_BENCHMARK("Align stretch in undefined axis", {
const CSSNodeRef root = CSSNodeNew();
for (uint32_t i = 0; i < 10; i++) {
const CSSNodeRef child = CSSNodeNew();
CSSNodeStyleSetHeight(child, 20);
CSSNodeSetMeasureFunc(child, _measure);
CSSNodeInsertChild(root, child, 0);
}
CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR);
CSSNodeFreeRecursive(root);
});
CSS_BENCHMARK("Nested flex", {
const CSSNodeRef root = CSSNodeNew();
for (uint32_t i = 0; i < 10; i++) {
const CSSNodeRef child = CSSNodeNew();
CSSNodeStyleSetFlex(child, 1);
CSSNodeInsertChild(root, child, 0);
for (uint32_t ii = 0; ii < 10; ii++) {
const CSSNodeRef grandChild = CSSNodeNew();
CSSNodeSetMeasureFunc(grandChild, _measure);
CSSNodeStyleSetFlex(grandChild, 1);
CSSNodeInsertChild(child, grandChild, 0);
}
}
CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR);
CSSNodeFreeRecursive(root);
});
CSS_BENCHMARK("Huge nested layout", {
const CSSNodeRef root = CSSNodeNew();
for (uint32_t i = 0; i < 10; i++) {
const CSSNodeRef child = CSSNodeNew();
CSSNodeStyleSetFlexGrow(child, 1);
CSSNodeStyleSetWidth(child, 10);
CSSNodeStyleSetHeight(child, 10);
CSSNodeInsertChild(root, child, 0);
for (uint32_t ii = 0; ii < 10; ii++) {
const CSSNodeRef grandChild = CSSNodeNew();
CSSNodeStyleSetFlexDirection(grandChild, CSSFlexDirectionRow);
CSSNodeStyleSetFlexGrow(grandChild, 1);
CSSNodeStyleSetWidth(grandChild, 10);
CSSNodeStyleSetHeight(grandChild, 10);
CSSNodeInsertChild(child, grandChild, 0);
for (uint32_t iii = 0; iii < 10; iii++) {
const CSSNodeRef grandGrandChild = CSSNodeNew();
CSSNodeStyleSetFlexGrow(grandGrandChild, 1);
CSSNodeStyleSetWidth(grandGrandChild, 10);
CSSNodeStyleSetHeight(grandGrandChild, 10);
CSSNodeInsertChild(grandChild, grandGrandChild, 0);
for (uint32_t iii = 0; iii < 10; iii++) {
const CSSNodeRef grandGrandGrandChild = CSSNodeNew();
CSSNodeStyleSetFlexDirection(grandGrandGrandChild, CSSFlexDirectionRow);
CSSNodeStyleSetFlexGrow(grandGrandGrandChild, 1);
CSSNodeStyleSetWidth(grandGrandGrandChild, 10);
CSSNodeStyleSetHeight(grandGrandGrandChild, 10);
CSSNodeInsertChild(grandGrandChild, grandGrandGrandChild, 0);
}
}
}
}
CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR);
CSSNodeFreeRecursive(root);
});
});

118
benchmark/YGBenchmark.c Normal file
View File

@@ -0,0 +1,118 @@
/**
* 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 "YGBenchmark.h"
#include <yoga/Yoga.h>
static YGSize _measure(YGNodeRef node,
float width,
YGMeasureMode widthMode,
float height,
YGMeasureMode heightMode) {
return (YGSize){
.width = widthMode == YGMeasureModeUndefined ? 10 : width,
.height = heightMode == YGMeasureModeUndefined ? 10 : width,
};
}
YGBENCHMARKS({
YGBENCHMARK("Stack with flex", {
const YGNodeRef root = YGNodeNew();
YGNodeStyleSetWidth(root, 100);
YGNodeStyleSetHeight(root, 100);
for (uint32_t i = 0; i < 10; i++) {
const YGNodeRef child = YGNodeNew();
YGNodeSetMeasureFunc(child, _measure);
YGNodeStyleSetFlex(child, 1);
YGNodeInsertChild(root, child, 0);
}
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
YGNodeFreeRecursive(root);
});
YGBENCHMARK("Align stretch in undefined axis", {
const YGNodeRef root = YGNodeNew();
for (uint32_t i = 0; i < 10; i++) {
const YGNodeRef child = YGNodeNew();
YGNodeStyleSetHeight(child, 20);
YGNodeSetMeasureFunc(child, _measure);
YGNodeInsertChild(root, child, 0);
}
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
YGNodeFreeRecursive(root);
});
YGBENCHMARK("Nested flex", {
const YGNodeRef root = YGNodeNew();
for (uint32_t i = 0; i < 10; i++) {
const YGNodeRef child = YGNodeNew();
YGNodeStyleSetFlex(child, 1);
YGNodeInsertChild(root, child, 0);
for (uint32_t ii = 0; ii < 10; ii++) {
const YGNodeRef grandChild = YGNodeNew();
YGNodeSetMeasureFunc(grandChild, _measure);
YGNodeStyleSetFlex(grandChild, 1);
YGNodeInsertChild(child, grandChild, 0);
}
}
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
YGNodeFreeRecursive(root);
});
YGBENCHMARK("Huge nested layout", {
const YGNodeRef root = YGNodeNew();
for (uint32_t i = 0; i < 10; i++) {
const YGNodeRef child = YGNodeNew();
YGNodeStyleSetFlexGrow(child, 1);
YGNodeStyleSetWidth(child, 10);
YGNodeStyleSetHeight(child, 10);
YGNodeInsertChild(root, child, 0);
for (uint32_t ii = 0; ii < 10; ii++) {
const YGNodeRef grandChild = YGNodeNew();
YGNodeStyleSetFlexDirection(grandChild, YGFlexDirectionRow);
YGNodeStyleSetFlexGrow(grandChild, 1);
YGNodeStyleSetWidth(grandChild, 10);
YGNodeStyleSetHeight(grandChild, 10);
YGNodeInsertChild(child, grandChild, 0);
for (uint32_t iii = 0; iii < 10; iii++) {
const YGNodeRef grandGrandChild = YGNodeNew();
YGNodeStyleSetFlexGrow(grandGrandChild, 1);
YGNodeStyleSetWidth(grandGrandChild, 10);
YGNodeStyleSetHeight(grandGrandChild, 10);
YGNodeInsertChild(grandChild, grandGrandChild, 0);
for (uint32_t iii = 0; iii < 10; iii++) {
const YGNodeRef grandGrandGrandChild = YGNodeNew();
YGNodeStyleSetFlexDirection(grandGrandGrandChild, YGFlexDirectionRow);
YGNodeStyleSetFlexGrow(grandGrandGrandChild, 1);
YGNodeStyleSetWidth(grandGrandGrandChild, 10);
YGNodeStyleSetHeight(grandGrandGrandChild, 10);
YGNodeInsertChild(grandGrandChild, grandGrandGrandChild, 0);
}
}
}
}
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
YGNodeFreeRecursive(root);
});
});

View File

@@ -17,7 +17,7 @@
#define NUM_REPETITIONS 1000
#define CSS_BENCHMARKS(BLOCK) \
#define YGBENCHMARKS(BLOCK) \
int main(int argc, char const *argv[]) { \
clock_t __start; \
clock_t __endTimes[NUM_REPETITIONS]; \
@@ -25,7 +25,7 @@
return 0; \
}
#define CSS_BENCHMARK(NAME, BLOCK) \
#define YGBENCHMARK(NAME, BLOCK) \
__start = clock(); \
for (uint32_t __i = 0; __i < NUM_REPETITIONS; __i++) { \
{ BLOCK } \

6
csharp/.gitignore vendored
View File

@@ -34,6 +34,10 @@ bld/
# NUNIT
*.VisualState.xml
TestResult.xml
tests/Facebook.Yoga/NUnit-[0-9\.]*/
tests/Facebook.Yoga/YogaTest.dll
tests/Facebook.Yoga/YogaTest.dll.mdb
tests/Facebook.Yoga/libyoga.dylib
# Build Results of an ATL Project
[Dd]ebugPS/
@@ -262,4 +266,4 @@ paket-files/
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
*.pyc

View File

@@ -34,6 +34,10 @@ bld/
# NUNIT
*.VisualState.xml
TestResult.xml
tests/Facebook.Yoga/NUnit-[0-9\.]*/
tests/Facebook.Yoga/YogaTest.dll
tests/Facebook.Yoga/YogaTest.dll.mdb
tests/Facebook.Yoga/libyoga.dylib
# Build Results of an ATL Project
[Dd]ebugPS/
@@ -262,4 +266,4 @@ paket-files/
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
*.pyc

1
csharp/Android/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
lib/

View File

@@ -0,0 +1,62 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{2021459E-8FB1-44A4-89F1-E291769CD2C6}</ProjectGuid>
<ProjectTypeGuids>{EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<RootNamespace>Facebook.Yoga.Android.Tests</RootNamespace>
<AssemblyName>Facebook.Yoga.Android.Tests</AssemblyName>
<TargetFrameworkVersion>v7.0</TargetFrameworkVersion>
<AndroidApplication>True</AndroidApplication>
<AndroidResgenFile>Resources\Resource.designer.cs</AndroidResgenFile>
<AndroidResgenClass>Resource</AndroidResgenClass>
<MonoAndroidResourcePrefix>Resources</MonoAndroidResourcePrefix>
<MonoAndroidAssetsPrefix>Assets</MonoAndroidAssetsPrefix>
<AndroidUseLatestPlatformSdk>true</AndroidUseLatestPlatformSdk>
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AndroidLinkMode>None</AndroidLinkMode>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AndroidManagedSymbols>true</AndroidManagedSymbols>
<AndroidUseSharedRuntime>false</AndroidUseSharedRuntime>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Xml" />
<Reference Include="System.Core" />
<Reference Include="Mono.Android" />
<Reference Include="Xamarin.Android.NUnitLite" />
</ItemGroup>
<ItemGroup>
<Compile Include="MainActivity.cs" />
<Compile Include="Resources\Resource.designer.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Properties\AndroidManifest.xml" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Facebook.Yoga.Android\Facebook.Yoga.Android.csproj">
<Project>{EDF7CF8B-5640-4E1D-A2C7-E4BC8BE44363}</Project>
<Name>Facebook.Yoga.Android</Name>
</ProjectReference>
</ItemGroup>
<Import Project="..\..\tests\Facebook.Yoga\Facebook.Yoga.Shared.Tests.projitems" Label="Shared" Condition="Exists('..\..\tests\Facebook.Yoga\Facebook.Yoga.Shared.Tests.projitems')" />
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
</Project>

View File

@@ -0,0 +1,25 @@
/**
* 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.
*/
using System.Reflection;
using Android.App;
using Android.OS;
using Xamarin.Android.NUnitLite;
namespace Facebook.Yoga.Android.Tests
{
[Activity(Label = "Facebook.Yoga.Android.Tests", MainLauncher = true)]
public class MainActivity : TestSuiteActivity
{
protected override void OnCreate(Bundle bundle)
{
AddTest(Assembly.GetExecutingAssembly());
base.OnCreate(bundle);
}
}
}

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="1"
android:versionName="1.0"
package="Facebook.Yoga.Android.Tests">
<uses-sdk
android:minSdkVersion="19" />
<application
android:label="Facebook.Yoga.Android.Tests">
</application>
</manifest>

View File

@@ -0,0 +1,33 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Facebook.Yoga.Android.Tests", "Facebook.Yoga.Android.Tests\Facebook.Yoga.Android.Tests.csproj", "{2021459E-8FB1-44A4-89F1-E291769CD2C6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Facebook.Yoga.Android", "Facebook.Yoga.Android\Facebook.Yoga.Android.csproj", "{EDF7CF8B-5640-4E1D-A2C7-E4BC8BE44363}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Shared", "Shared", "{4804A8E6-E7B7-4F9E-A446-3DE8E73DB38A}"
EndProject
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Facebook.Yoga.Shared", "..\Facebook.Yoga\Facebook.Yoga.Shared.shproj", "{91C42D32-291D-4B72-90B4-551663D60B8B}"
EndProject
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Facebook.Yoga.Shared.Tests", "..\tests\Facebook.Yoga\Facebook.Yoga.Shared.Tests.shproj", "{4EDC82D9-A201-4831-8FE0-98F468F8E4AE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2021459E-8FB1-44A4-89F1-E291769CD2C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2021459E-8FB1-44A4-89F1-E291769CD2C6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2021459E-8FB1-44A4-89F1-E291769CD2C6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2021459E-8FB1-44A4-89F1-E291769CD2C6}.Release|Any CPU.Build.0 = Release|Any CPU
{EDF7CF8B-5640-4E1D-A2C7-E4BC8BE44363}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EDF7CF8B-5640-4E1D-A2C7-E4BC8BE44363}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EDF7CF8B-5640-4E1D-A2C7-E4BC8BE44363}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EDF7CF8B-5640-4E1D-A2C7-E4BC8BE44363}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{91C42D32-291D-4B72-90B4-551663D60B8B} = {4804A8E6-E7B7-4F9E-A446-3DE8E73DB38A}
{4EDC82D9-A201-4831-8FE0-98F468F8E4AE} = {4804A8E6-E7B7-4F9E-A446-3DE8E73DB38A}
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<BuildDependsOn>NativeLibraryARMV7;NativeLibraryX86;$(BuildDependsOn)</BuildDependsOn>
</PropertyGroup>
<Target Name="NativeLibraryARMV7" Outputs="$(ProjectDir)/lib/armeabi-v7a/libyoga.so">
<Exec WorkingDirectory="$(ProjectDir)" Command="$(ProjectDir)../../Mac/buck-build.sh //csharp:yoganet#android-armv7,shared" />
<Copy SourceFiles="$(ProjectDir)../../../buck-out/gen/csharp/yoganet#android-armv7,shared/libyoga.so" DestinationFiles="$(ProjectDir)/lib/armeabi-v7a/libyoga.so" SkipUnchangedFiles="true" />
</Target>
<!--
<Target Name="NativeLibraryARM64" Outputs="$(ProjectDir)/lib/arm64-v8a/libyoga.so">
<Exec WorkingDirectory="$(ProjectDir)" Command="$(ProjectDir)../../Mac/buck-build.sh //csharp:yoganet#android-arm64,shared" />
<Copy SourceFiles="$(ProjectDir)../../../buck-out/gen/csharp/yoganet#android-arm64,shared/libyoga.so" DestinationFiles="$(ProjectDir)/lib/arm64-v8/libyoga.so" SkipUnchangedFiles="true" />
</Target>
-->
<Target Name="NativeLibraryX86" Outputs="$(ProjectDir)/lib/x86/libyoga.so">
<Exec WorkingDirectory="$(ProjectDir)" Command="$(ProjectDir)../../Mac/buck-build.sh //csharp:yoganet#android-x86,shared" />
<Copy SourceFiles="$(ProjectDir)../../../buck-out/gen/csharp/yoganet#android-x86,shared/libyoga.so" DestinationFiles="$(ProjectDir)/lib/x86/libyoga.so" SkipUnchangedFiles="true" />
</Target>
</Project>

View File

@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{EDF7CF8B-5640-4E1D-A2C7-E4BC8BE44363}</ProjectGuid>
<ProjectTypeGuids>{EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<RootNamespace>Facebook.Yoga.Android</RootNamespace>
<AssemblyName>Facebook.Yoga.Android</AssemblyName>
<TargetFrameworkVersion>v7.0</TargetFrameworkVersion>
<AndroidResgenFile>Resources\Resource.designer.cs</AndroidResgenFile>
<AndroidResgenClass>Resource</AndroidResgenClass>
<MonoAndroidResourcePrefix>Resources</MonoAndroidResourcePrefix>
<MonoAndroidAssetsPrefix>Assets</MonoAndroidAssetsPrefix>
<AndroidUseLatestPlatformSdk>true</AndroidUseLatestPlatformSdk>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AndroidLinkMode>None</AndroidLinkMode>
<AndroidSupportedAbis>arm64-v8a;armeabi;armeabi-v7a;x86</AndroidSupportedAbis>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AndroidManagedSymbols>true</AndroidManagedSymbols>
<AndroidUseSharedRuntime>false</AndroidUseSharedRuntime>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Xml" />
<Reference Include="System.Core" />
<Reference Include="Mono.Android" />
</ItemGroup>
<ItemGroup>
<None Include="CustomBuildAction.targets" />
</ItemGroup>
<ItemGroup>
<Folder Include="lib\x86\" />
<Folder Include="lib\armeabi-v7a\" />
</ItemGroup>
<ItemGroup>
<EmbeddedNativeLibrary Include="lib\x86\libyoga.so">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedNativeLibrary>
<EmbeddedNativeLibrary Include="lib\armeabi-v7a\libyoga.so">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedNativeLibrary>
</ItemGroup>
<Import Project="..\..\Facebook.Yoga\Facebook.Yoga.Shared.projitems" Label="Shared" Condition="Exists('..\..\Facebook.Yoga\Facebook.Yoga.Shared.projitems')" />
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
<Import Project="CustomBuildAction.targets" />
</Project>

View File

@@ -5,16 +5,59 @@
# 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_defs('//YOGA_DEFS')
COMPILER_FLAGS = BASE_COMPILER_FLAGS + ['-std=c++11']
csharp_library(
name = 'csslibnet46',
dll_name = 'Facebook.CSSLayout.dll',
name = 'yogalibnet46',
dll_name = 'Facebook.Yoga.dll',
framework_ver = 'net46',
srcs = glob(['**/*.cs']),
)
csharp_library(
name = 'csslibnet45',
dll_name = 'Facebook.CSSLayout.dll',
name = 'yogalibnet45',
dll_name = 'Facebook.Yoga.dll',
framework_ver = 'net45',
srcs = glob(['**/*.cs']),
)
cxx_library(
name = 'yoganet',
soname = 'libyoga.$(ext)',
srcs = glob(['Yoga/YGInterop.cpp']),
compiler_flags = COMPILER_FLAGS,
link_style = 'static',
link_whole = True,
deps = [yoga_dep(':yoga')],
visibility = ['PUBLIC'],
)
with allow_unsafe_import():
import os
if os.path.isdir('/Applications/Xcode.app'):
yoganet_ios_srcs = []
for arch in ['iphonesimulator-x86_64', 'iphoneos-arm64', 'iphoneos-armv7']:
name = 'yoganet-' + arch
yoganet_ios_srcs.append(':' + name)
genrule(
name = name,
srcs = [
yoga_dep(':yoga#%s,static' % arch),
yoga_dep('YogaKit:YogaKit#%s,static' % arch),
yoga_dep('csharp:yoganet#%s,static' % arch),
],
out = 'libyoga-%s.a' % arch,
cmd = 'libtool -static -o $OUT $SRCS',
visibility = [yoga_dep('csharp:yoganet-ios')],
)
genrule(
name = 'yoganet-ios',
srcs = yoganet_ios_srcs,
out = 'libyoga.a',
cmd = 'lipo $SRCS -create -output $OUT',
visibility = ['PUBLIC'],
)

View File

@@ -1,46 +0,0 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CSSLayout", "CSSLayout\CSSLayout.vcxproj", "{0446C86B-F47B-4C46-B673-C7AE0CFF35D5}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Facebook.CSSLayout", "Facebook.CSSLayout\Facebook.CSSLayout.xproj", "{75BB7605-E54B-4EDE-8F5A-FF1F24464236}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{0446C86B-F47B-4C46-B673-C7AE0CFF35D5}.Debug|Any CPU.ActiveCfg = Debug|Win32
{0446C86B-F47B-4C46-B673-C7AE0CFF35D5}.Debug|x64.ActiveCfg = Debug|x64
{0446C86B-F47B-4C46-B673-C7AE0CFF35D5}.Debug|x64.Build.0 = Debug|x64
{0446C86B-F47B-4C46-B673-C7AE0CFF35D5}.Debug|x86.ActiveCfg = Debug|Win32
{0446C86B-F47B-4C46-B673-C7AE0CFF35D5}.Debug|x86.Build.0 = Debug|Win32
{0446C86B-F47B-4C46-B673-C7AE0CFF35D5}.Release|Any CPU.ActiveCfg = Release|Win32
{0446C86B-F47B-4C46-B673-C7AE0CFF35D5}.Release|x64.ActiveCfg = Release|x64
{0446C86B-F47B-4C46-B673-C7AE0CFF35D5}.Release|x64.Build.0 = Release|x64
{0446C86B-F47B-4C46-B673-C7AE0CFF35D5}.Release|x86.ActiveCfg = Release|Win32
{0446C86B-F47B-4C46-B673-C7AE0CFF35D5}.Release|x86.Build.0 = Release|Win32
{75BB7605-E54B-4EDE-8F5A-FF1F24464236}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{75BB7605-E54B-4EDE-8F5A-FF1F24464236}.Debug|Any CPU.Build.0 = Debug|Any CPU
{75BB7605-E54B-4EDE-8F5A-FF1F24464236}.Debug|x64.ActiveCfg = Debug|Any CPU
{75BB7605-E54B-4EDE-8F5A-FF1F24464236}.Debug|x64.Build.0 = Debug|Any CPU
{75BB7605-E54B-4EDE-8F5A-FF1F24464236}.Debug|x86.ActiveCfg = Debug|Any CPU
{75BB7605-E54B-4EDE-8F5A-FF1F24464236}.Debug|x86.Build.0 = Debug|Any CPU
{75BB7605-E54B-4EDE-8F5A-FF1F24464236}.Release|Any CPU.ActiveCfg = Release|Any CPU
{75BB7605-E54B-4EDE-8F5A-FF1F24464236}.Release|Any CPU.Build.0 = Release|Any CPU
{75BB7605-E54B-4EDE-8F5A-FF1F24464236}.Release|x64.ActiveCfg = Release|Any CPU
{75BB7605-E54B-4EDE-8F5A-FF1F24464236}.Release|x64.Build.0 = Release|Any CPU
{75BB7605-E54B-4EDE-8F5A-FF1F24464236}.Release|x86.ActiveCfg = Release|Any CPU
{75BB7605-E54B-4EDE-8F5A-FF1F24464236}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@@ -1,234 +0,0 @@
/**
* 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.CSSLayout
{
public partial class CSSNode
{
public static CSSNode Create(
CSSDirection? styleDirection = null,
CSSFlexDirection? flexDirection = null,
CSSJustify? justifyContent = null,
CSSAlign? alignContent = null,
CSSAlign? alignItems = null,
CSSAlign? alignSelf = null,
CSSPositionType? positionType = null,
CSSWrap? wrap = null,
CSSOverflow? 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? styleWidth = null,
float? styleHeight = null,
float? styleMaxWidth = null,
float? styleMaxHeight = null,
float? styleMinWidth = null,
float? styleMinHeight = null)
{
CSSNode node = new CSSNode();
if (styleDirection.HasValue)
{
node.StyleDirection = styleDirection.Value;
}
if (flexDirection.HasValue)
{
node.FlexDirection = flexDirection.Value;
}
if (justifyContent.HasValue)
{
node.JustifyContent = justifyContent.Value;
}
if (alignContent.HasValue)
{
node.AlignContent = alignContent.Value;
}
if (alignItems.HasValue)
{
node.AlignItems = alignItems.Value;
}
if (alignSelf.HasValue)
{
node.AlignSelf = alignSelf.Value;
}
if (positionType.HasValue)
{
node.PositionType = positionType.Value;
}
if (wrap.HasValue)
{
node.Wrap = wrap.Value;
}
if (overflow.HasValue)
{
node.Overflow = overflow.Value;
}
if (flex.HasValue)
{
node.Flex = flex.Value;
}
if (flexGrow.HasValue)
{
node.FlexGrow = flexGrow.Value;
}
if (flexShrink.HasValue)
{
node.FlexShrink = flexShrink.Value;
}
if (flexBasis.HasValue)
{
node.FlexBasis = flexBasis.Value;
}
if (position != null)
{
if (position.Top.HasValue)
{
node.SetPosition(CSSEdge.Top, position.Top.Value);
}
if (position.Bottom.HasValue)
{
node.SetPosition(CSSEdge.Bottom, position.Bottom.Value);
}
if (position.Left.HasValue)
{
node.SetPosition(CSSEdge.Left, position.Left.Value);
}
if (position.Right.HasValue)
{
node.SetPosition(CSSEdge.Right, position.Right.Value);
}
}
if (margin != null)
{
if (margin.Top.HasValue)
{
node.SetMargin(CSSEdge.Top, margin.Top.Value);
}
if (margin.Bottom.HasValue)
{
node.SetMargin(CSSEdge.Bottom, margin.Bottom.Value);
}
if (margin.Left.HasValue)
{
node.SetMargin(CSSEdge.Left, margin.Left.Value);
}
if (margin.Right.HasValue)
{
node.SetMargin(CSSEdge.Right, margin.Right.Value);
}
}
if (padding != null)
{
if (padding.Top.HasValue)
{
node.SetPadding(CSSEdge.Top, padding.Top.Value);
}
if (padding.Bottom.HasValue)
{
node.SetPadding(CSSEdge.Bottom, padding.Bottom.Value);
}
if (padding.Left.HasValue)
{
node.SetPadding(CSSEdge.Left, padding.Left.Value);
}
if (padding.Right.HasValue)
{
node.SetPadding(CSSEdge.Right, padding.Right.Value);
}
}
if (border != null)
{
if (border.Top.HasValue)
{
node.SetBorder(CSSEdge.Top, border.Top.Value);
}
if (border.Bottom.HasValue)
{
node.SetBorder(CSSEdge.Bottom, border.Bottom.Value);
}
if (border.Left.HasValue)
{
node.SetBorder(CSSEdge.Left, border.Left.Value);
}
if (border.Right.HasValue)
{
node.SetBorder(CSSEdge.Right, border.Right.Value);
}
}
if (styleWidth.HasValue)
{
node.StyleWidth = styleWidth.Value;
}
if (styleHeight.HasValue)
{
node.StyleHeight = styleHeight.Value;
}
if (styleMinWidth.HasValue)
{
node.StyleMinWidth = styleMinWidth.Value;
}
if (styleMinHeight.HasValue)
{
node.StyleMinHeight = styleMinHeight.Value;
}
if (styleMaxWidth.HasValue)
{
node.StyleMaxWidth = styleMaxWidth.Value;
}
if (styleMaxHeight.HasValue)
{
node.StyleMaxHeight = styleMaxHeight.Value;
}
return node;
}
}
}

View File

@@ -1,571 +0,0 @@
/**
* 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;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
namespace Facebook.CSSLayout
{
public partial class CSSNode : IEnumerable<CSSNode>
{
private IntPtr _cssNode;
private WeakReference _parent;
private List<CSSNode> _children;
private MeasureFunction _measureFunction;
private CSSMeasureFunc _cssMeasureFunc;
private object _data;
public CSSNode()
{
CSSLogger.Initialize();
_cssNode = Native.CSSNodeNew();
if (_cssNode == IntPtr.Zero)
{
throw new InvalidOperationException("Failed to allocate native memory");
}
}
~CSSNode()
{
Native.CSSNodeFree(_cssNode);
}
public void Reset()
{
_measureFunction = null;
_data = null;
Native.CSSNodeReset(_cssNode);
}
public bool IsDirty
{
get
{
return Native.CSSNodeIsDirty(_cssNode);
}
}
public virtual void MarkDirty()
{
Native.CSSNodeMarkDirty(_cssNode);
}
public bool HasNewLayout
{
get
{
return Native.CSSNodeGetHasNewLayout(_cssNode);
}
}
public void MarkHasNewLayout()
{
Native.CSSNodeSetHasNewLayout(_cssNode, true);
}
public CSSNode Parent
{
get
{
return _parent != null ? _parent.Target as CSSNode : null;
}
}
public bool IsMeasureDefined
{
get
{
return _measureFunction != null;
}
}
public void CopyStyle(CSSNode srcNode)
{
Native.CSSNodeCopyStyle(_cssNode, srcNode._cssNode);
}
public CSSDirection StyleDirection
{
get
{
return Native.CSSNodeStyleGetDirection(_cssNode);
}
set
{
Native.CSSNodeStyleSetDirection(_cssNode, value);
}
}
public CSSFlexDirection FlexDirection
{
get
{
return Native.CSSNodeStyleGetFlexDirection(_cssNode);
}
set
{
Native.CSSNodeStyleSetFlexDirection(_cssNode, value);
}
}
public CSSJustify JustifyContent
{
get
{
return Native.CSSNodeStyleGetJustifyContent(_cssNode);
}
set
{
Native.CSSNodeStyleSetJustifyContent(_cssNode, value);
}
}
public CSSAlign AlignItems
{
get
{
return Native.CSSNodeStyleGetAlignItems(_cssNode);
}
set
{
Native.CSSNodeStyleSetAlignItems(_cssNode, value);
}
}
public CSSAlign AlignSelf
{
get
{
return Native.CSSNodeStyleGetAlignSelf(_cssNode);
}
set
{
Native.CSSNodeStyleSetAlignSelf(_cssNode, value);
}
}
public CSSAlign AlignContent
{
get
{
return Native.CSSNodeStyleGetAlignContent(_cssNode);
}
set
{
Native.CSSNodeStyleSetAlignContent(_cssNode, value);
}
}
public CSSPositionType PositionType
{
get
{
return Native.CSSNodeStyleGetPositionType(_cssNode);
}
set
{
Native.CSSNodeStyleSetPositionType(_cssNode, value);
}
}
public CSSWrap Wrap
{
get
{
return Native.CSSNodeStyleGetFlexWrap(_cssNode);
}
set
{
Native.CSSNodeStyleSetFlexWrap(_cssNode, value);
}
}
public float Flex
{
set
{
Native.CSSNodeStyleSetFlex(_cssNode, value);
}
}
public float FlexGrow
{
get
{
return Native.CSSNodeStyleGetFlexGrow(_cssNode);
}
set
{
Native.CSSNodeStyleSetFlexGrow(_cssNode, value);
}
}
public float FlexShrink
{
get
{
return Native.CSSNodeStyleGetFlexShrink(_cssNode);
}
set
{
Native.CSSNodeStyleSetFlexShrink(_cssNode, value);
}
}
public float FlexBasis
{
get
{
return Native.CSSNodeStyleGetFlexBasis(_cssNode);
}
set
{
Native.CSSNodeStyleSetFlexBasis(_cssNode, value);
}
}
public float GetMargin(CSSEdge edge)
{
return Native.CSSNodeStyleGetMargin(_cssNode, edge);
}
public void SetMargin(CSSEdge edge, float value)
{
Native.CSSNodeStyleSetMargin(_cssNode, edge, value);
}
public float GetPadding(CSSEdge edge)
{
return Native.CSSNodeStyleGetPadding(_cssNode, edge);
}
public void SetPadding(CSSEdge edge, float padding)
{
Native.CSSNodeStyleSetPadding(_cssNode, edge, padding);
}
public float GetBorder(CSSEdge edge)
{
return Native.CSSNodeStyleGetBorder(_cssNode, edge);
}
public void SetBorder(CSSEdge edge, float border)
{
Native.CSSNodeStyleSetBorder(_cssNode, edge, border);
}
public float GetPosition(CSSEdge edge)
{
return Native.CSSNodeStyleGetPosition(_cssNode, edge);
}
public void SetPosition(CSSEdge edge, float position)
{
Native.CSSNodeStyleSetPosition(_cssNode, edge, position);
}
public float StyleWidth
{
get
{
return Native.CSSNodeStyleGetWidth(_cssNode);
}
set
{
Native.CSSNodeStyleSetWidth(_cssNode, value);
}
}
public float StyleHeight
{
get
{
return Native.CSSNodeStyleGetHeight(_cssNode);
}
set
{
Native.CSSNodeStyleSetHeight(_cssNode, value);
}
}
public float StyleMaxWidth
{
get
{
return Native.CSSNodeStyleGetMaxWidth(_cssNode);
}
set
{
Native.CSSNodeStyleSetMaxWidth(_cssNode, value);
}
}
public float StyleMaxHeight
{
get
{
return Native.CSSNodeStyleGetMaxHeight(_cssNode);
}
set
{
Native.CSSNodeStyleSetMaxHeight(_cssNode, value);
}
}
public float StyleMinWidth
{
get
{
return Native.CSSNodeStyleGetMinWidth(_cssNode);
}
set
{
Native.CSSNodeStyleSetMinWidth(_cssNode, value);
}
}
public float StyleMinHeight
{
get
{
return Native.CSSNodeStyleGetMinHeight(_cssNode);
}
set
{
Native.CSSNodeStyleSetMinHeight(_cssNode, value);
}
}
public float LayoutX
{
get
{
return Native.CSSNodeLayoutGetLeft(_cssNode);
}
}
public float LayoutY
{
get
{
return Native.CSSNodeLayoutGetTop(_cssNode);
}
}
public float LayoutWidth
{
get
{
return Native.CSSNodeLayoutGetWidth(_cssNode);
}
}
public float LayoutHeight
{
get
{
return Native.CSSNodeLayoutGetHeight(_cssNode);
}
}
public CSSDirection LayoutDirection
{
get
{
return Native.CSSNodeLayoutGetDirection(_cssNode);
}
}
public CSSOverflow Overflow
{
get
{
return Native.CSSNodeStyleGetOverflow(_cssNode);
}
set
{
Native.CSSNodeStyleSetOverflow(_cssNode, value);
}
}
public object Data
{
get
{
return _data;
}
set
{
_data = value;
}
}
public CSSNode this[int index]
{
get
{
return _children[index];
}
}
public int Count
{
get
{
return _children != null ? _children.Count : 0;
}
}
public void MarkLayoutSeen()
{
Native.CSSNodeSetHasNewLayout(_cssNode, false);
}
public bool ValuesEqual(float f1, float f2)
{
if (float.IsNaN(f1) || float.IsNaN(f2))
{
return float.IsNaN(f1) && float.IsNaN(f2);
}
return Math.Abs(f2 - f1) < float.Epsilon;
}
public void Insert(int index, CSSNode node)
{
if (_children == null)
{
_children = new List<CSSNode>(4);
}
_children.Insert(index, node);
node._parent = new WeakReference(this);
Native.CSSNodeInsertChild(_cssNode, node._cssNode, (uint)index);
}
public void RemoveAt(int index)
{
var child = _children[index];
child._parent = null;
_children.RemoveAt(index);
Native.CSSNodeRemoveChild(_cssNode, child._cssNode);
}
public void Clear()
{
if (_children != null)
{
while (_children.Count > 0)
{
RemoveAt(_children.Count-1);
}
}
}
public int IndexOf(CSSNode node)
{
return _children != null ? _children.IndexOf(node) : -1;
}
public void SetMeasureFunction(MeasureFunction measureFunction)
{
_measureFunction = measureFunction;
_cssMeasureFunc = measureFunction != null ? MeasureInternal : (CSSMeasureFunc)null;
Native.CSSNodeSetMeasureFunc(_cssNode, _cssMeasureFunc);
}
public void CalculateLayout()
{
Native.CSSNodeCalculateLayout(
_cssNode,
CSSConstants.Undefined,
CSSConstants.Undefined,
Native.CSSNodeStyleGetDirection(_cssNode));
}
private CSSSize MeasureInternal(
IntPtr node,
float width,
CSSMeasureMode widthMode,
float height,
CSSMeasureMode heightMode)
{
if (_measureFunction == null)
{
throw new InvalidOperationException("Measure function is not defined.");
}
long output = _measureFunction(this, width, widthMode, height, heightMode);
return new CSSSize { width = MeasureOutput.GetWidth(output), height = MeasureOutput.GetHeight(output) };
}
public string Print(CSSPrintOptions options =
CSSPrintOptions.Layout|CSSPrintOptions.Style|CSSPrintOptions.Children)
{
StringBuilder sb = new StringBuilder();
CSSLogger.Func orig = CSSLogger.Logger;
CSSLogger.Logger = (level, message) => {sb.Append(message);};
Native.CSSNodePrint(_cssNode, options);
CSSLogger.Logger = orig;
return sb.ToString();
}
public IEnumerator<CSSNode> GetEnumerator()
{
return _children != null ? ((IEnumerable<CSSNode>)_children).GetEnumerator() :
System.Linq.Enumerable.Empty<CSSNode>().GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return _children != null ? ((IEnumerable<CSSNode>)_children).GetEnumerator() :
System.Linq.Enumerable.Empty<CSSNode>().GetEnumerator();
}
public static int GetInstanceCount()
{
return Native.CSSNodeGetInstanceCount();
}
public static void setExperimentalFeatureEnabled(
CSSExperimentalFeature feature,
bool enabled)
{
Native.CSSLayoutSetExperimentalFeatureEnabled(feature, enabled);
}
public static bool isExperimentalFeatureEnabled(CSSExperimentalFeature feature)
{
return Native.CSSLayoutIsExperimentalFeatureEnabled(feature);
}
}
}

View File

@@ -1,21 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>75bb7605-e54b-4ede-8f5a-ff1f24464236</ProjectGuid>
<RootNamespace>Facebook.CSSLayout</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>

View File

@@ -1,34 +0,0 @@
/**
* 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.
*/
namespace Facebook.CSSLayout
{
public class MeasureOutput
{
public static long Make(double width, double height)
{
return Make((int) width, (int) height);
}
public static long Make(int width, int height)
{
return (long)(((ulong) width) << 32 | ((uint) height));
}
public static int GetWidth(long measureOutput)
{
return (int) (0xFFFFFFFF & (measureOutput >> 32));
}
public static int GetHeight(long measureOutput)
{
return (int) (0xFFFFFFFF & measureOutput);
}
}
}

View File

@@ -1,280 +0,0 @@
/**
* 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;
using System.Runtime.InteropServices;
namespace Facebook.CSSLayout
{
internal static class Native
{
#if UNITY_IOS && !UNITY_EDITOR
private const string DllName = "__Internal";
#else
private const string DllName = "CSSLayout";
#endif
[DllImport(DllName)]
public static extern void CSSInteropSetLogger(
[MarshalAs(UnmanagedType.FunctionPtr)] CSSLogger.Func func);
[DllImport(DllName)]
public static extern IntPtr CSSNodeNew();
[DllImport(DllName)]
public static extern void CSSNodeInit(IntPtr cssNode);
[DllImport(DllName)]
public static extern void CSSNodeFree(IntPtr cssNode);
[DllImport(DllName)]
public static extern void CSSNodeReset(IntPtr cssNode);
[DllImport(DllName)]
public static extern int CSSNodeGetInstanceCount();
[DllImport(DllName)]
public static extern void CSSLayoutSetExperimentalFeatureEnabled(
CSSExperimentalFeature feature,
bool enabled);
[DllImport(DllName)]
public static extern bool CSSLayoutIsExperimentalFeatureEnabled(
CSSExperimentalFeature feature);
[DllImport(DllName)]
public static extern void CSSNodeInsertChild(IntPtr node, IntPtr child, uint index);
[DllImport(DllName)]
public static extern void CSSNodeRemoveChild(IntPtr node, IntPtr child);
[DllImport(DllName)]
public static extern IntPtr CSSNodeGetChild(IntPtr node, uint index);
[DllImport(DllName)]
public static extern uint CSSNodeChildCount(IntPtr node);
[DllImport(DllName)]
public static extern void CSSNodeCalculateLayout(IntPtr node,
float availableWidth,
float availableHeight,
CSSDirection parentDirection);
[DllImport(DllName)]
public static extern void CSSNodeMarkDirty(IntPtr node);
[DllImport(DllName)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool CSSNodeIsDirty(IntPtr node);
[DllImport(DllName)]
public static extern void CSSNodePrint(IntPtr node, CSSPrintOptions options);
[DllImport(DllName)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool CSSValueIsUndefined(float value);
[DllImport(DllName)]
public static extern void CSSNodeCopyStyle(IntPtr dstNode, IntPtr srcNode);
#region CSS_NODE_PROPERTY
[DllImport(DllName)]
public static extern void CSSNodeSetContext(IntPtr node, IntPtr context);
[DllImport(DllName)]
public static extern IntPtr CSSNodeGetContext(IntPtr node);
[DllImport(DllName)]
public static extern void CSSNodeSetMeasureFunc(
IntPtr node,
[MarshalAs(UnmanagedType.FunctionPtr)] CSSMeasureFunc measureFunc);
[DllImport(DllName)]
[return: MarshalAs(UnmanagedType.FunctionPtr)]
public static extern CSSMeasureFunc CSSNodeGetMeasureFunc(IntPtr node);
[DllImport(DllName)]
public static extern void CSSNodeSetHasNewLayout(IntPtr node, [MarshalAs(UnmanagedType.I1)] bool hasNewLayout);
[DllImport(DllName)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool CSSNodeGetHasNewLayout(IntPtr node);
#endregion
#region CSS_NODE_STYLE_PROPERTY
[DllImport(DllName)]
public static extern void CSSNodeStyleSetDirection(IntPtr node, CSSDirection direction);
[DllImport(DllName)]
public static extern CSSDirection CSSNodeStyleGetDirection(IntPtr node);
[DllImport(DllName)]
public static extern void CSSNodeStyleSetFlexDirection(IntPtr node, CSSFlexDirection flexDirection);
[DllImport(DllName)]
public static extern CSSFlexDirection CSSNodeStyleGetFlexDirection(IntPtr node);
[DllImport(DllName)]
public static extern void CSSNodeStyleSetJustifyContent(IntPtr node, CSSJustify justifyContent);
[DllImport(DllName)]
public static extern CSSJustify CSSNodeStyleGetJustifyContent(IntPtr node);
[DllImport(DllName)]
public static extern void CSSNodeStyleSetAlignContent(IntPtr node, CSSAlign alignContent);
[DllImport(DllName)]
public static extern CSSAlign CSSNodeStyleGetAlignContent(IntPtr node);
[DllImport(DllName)]
public static extern void CSSNodeStyleSetAlignItems(IntPtr node, CSSAlign alignItems);
[DllImport(DllName)]
public static extern CSSAlign CSSNodeStyleGetAlignItems(IntPtr node);
[DllImport(DllName)]
public static extern void CSSNodeStyleSetAlignSelf(IntPtr node, CSSAlign alignSelf);
[DllImport(DllName)]
public static extern CSSAlign CSSNodeStyleGetAlignSelf(IntPtr node);
[DllImport(DllName)]
public static extern void CSSNodeStyleSetPositionType(IntPtr node, CSSPositionType positionType);
[DllImport(DllName)]
public static extern CSSPositionType CSSNodeStyleGetPositionType(IntPtr node);
[DllImport(DllName)]
public static extern void CSSNodeStyleSetFlexWrap(IntPtr node, CSSWrap flexWrap);
[DllImport(DllName)]
public static extern CSSWrap CSSNodeStyleGetFlexWrap(IntPtr node);
[DllImport(DllName)]
public static extern void CSSNodeStyleSetOverflow(IntPtr node, CSSOverflow flexWrap);
[DllImport(DllName)]
public static extern CSSOverflow CSSNodeStyleGetOverflow(IntPtr node);
[DllImport(DllName)]
public static extern void CSSNodeStyleSetFlex(IntPtr node, float flex);
[DllImport(DllName)]
public static extern void CSSNodeStyleSetFlexGrow(IntPtr node, float flexGrow);
[DllImport(DllName)]
public static extern float CSSNodeStyleGetFlexGrow(IntPtr node);
[DllImport(DllName)]
public static extern void CSSNodeStyleSetFlexShrink(IntPtr node, float flexShrink);
[DllImport(DllName)]
public static extern float CSSNodeStyleGetFlexShrink(IntPtr node);
[DllImport(DllName)]
public static extern void CSSNodeStyleSetFlexBasis(IntPtr node, float flexBasis);
[DllImport(DllName)]
public static extern float CSSNodeStyleGetFlexBasis(IntPtr node);
[DllImport(DllName)]
public static extern void CSSNodeStyleSetWidth(IntPtr node, float width);
[DllImport(DllName)]
public static extern float CSSNodeStyleGetWidth(IntPtr node);
[DllImport(DllName)]
public static extern void CSSNodeStyleSetHeight(IntPtr node, float height);
[DllImport(DllName)]
public static extern float CSSNodeStyleGetHeight(IntPtr node);
[DllImport(DllName)]
public static extern void CSSNodeStyleSetMinWidth(IntPtr node, float minWidth);
[DllImport(DllName)]
public static extern float CSSNodeStyleGetMinWidth(IntPtr node);
[DllImport(DllName)]
public static extern void CSSNodeStyleSetMinHeight(IntPtr node, float minHeight);
[DllImport(DllName)]
public static extern float CSSNodeStyleGetMinHeight(IntPtr node);
[DllImport(DllName)]
public static extern void CSSNodeStyleSetMaxWidth(IntPtr node, float maxWidth);
[DllImport(DllName)]
public static extern float CSSNodeStyleGetMaxWidth(IntPtr node);
[DllImport(DllName)]
public static extern void CSSNodeStyleSetMaxHeight(IntPtr node, float maxHeight);
[DllImport(DllName)]
public static extern float CSSNodeStyleGetMaxHeight(IntPtr node);
#endregion
#region CSS_NODE_STYLE_EDGE_PROPERTY
[DllImport(DllName)]
public static extern void CSSNodeStyleSetPosition(IntPtr node, CSSEdge edge, float position);
[DllImport(DllName)]
public static extern float CSSNodeStyleGetPosition(IntPtr node, CSSEdge edge);
[DllImport(DllName)]
public static extern void CSSNodeStyleSetMargin(IntPtr node, CSSEdge edge, float margin);
[DllImport(DllName)]
public static extern float CSSNodeStyleGetMargin(IntPtr node, CSSEdge edge);
[DllImport(DllName)]
public static extern void CSSNodeStyleSetPadding(IntPtr node, CSSEdge edge, float padding);
[DllImport(DllName)]
public static extern float CSSNodeStyleGetPadding(IntPtr node, CSSEdge edge);
[DllImport(DllName)]
public static extern void CSSNodeStyleSetBorder(IntPtr node, CSSEdge edge, float border);
[DllImport(DllName)]
public static extern float CSSNodeStyleGetBorder(IntPtr node, CSSEdge edge);
#endregion
#region CSS_NODE_LAYOUT_PROPERTY
[DllImport(DllName)]
public static extern float CSSNodeLayoutGetLeft(IntPtr node);
[DllImport(DllName)]
public static extern float CSSNodeLayoutGetTop(IntPtr node);
[DllImport(DllName)]
public static extern float CSSNodeLayoutGetRight(IntPtr node);
[DllImport(DllName)]
public static extern float CSSNodeLayoutGetBottom(IntPtr node);
[DllImport(DllName)]
public static extern float CSSNodeLayoutGetWidth(IntPtr node);
[DllImport(DllName)]
public static extern float CSSNodeLayoutGetHeight(IntPtr node);
[DllImport(DllName)]
public static extern CSSDirection CSSNodeLayoutGetDirection(IntPtr node);
#endregion
}
}

View File

@@ -1,32 +0,0 @@
/**
* 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.Reflection;
using System.Resources;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Facebook, Inc.")]
[assembly: AssemblyProduct("Facebook.CSSLayout")]
[assembly: AssemblyTrademark("Copyright (c) 2014-present, Facebook, Inc.")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("75bb7605-e54b-4ede-8f5a-ff1f24464236")]
[assembly: NeutralResourcesLanguage("en")]
[assembly: AssemblyVersion("3.0.0.0")]

View File

@@ -1,31 +0,0 @@
/**
* 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.
*/
namespace Facebook.CSSLayout
{
public class Spacing
{
public float? Top;
public float? Bottom;
public float? Left;
public float? Right;
public Spacing(
float? top = null,
float? bottom = null,
float? left = null,
float? right = null)
{
Top = top;
Bottom = bottom;
Left = left;
Right = right;
}
}
}

View File

@@ -0,0 +1,13 @@
/**
* 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.
*/
namespace Facebook.Yoga
{
public delegate float BaselineFunction(YogaNode node, float width, float height);
}

View File

@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
<HasSharedItems>true</HasSharedItems>
<SharedGUID>91c42d32-291d-4b72-90b4-551663d60b8b</SharedGUID>
</PropertyGroup>
<PropertyGroup Label="Configuration">
<Import_RootNamespace>Facebook.Yoga.Shared</Import_RootNamespace>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)BaselineFunction.cs" />
<Compile Include="$(MSBuildThisFileDirectory)MeasureFunction.cs" />
<Compile Include="$(MSBuildThisFileDirectory)MeasureOutput.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Native.cs" />
<Compile Include="$(MSBuildThisFileDirectory)YogaAlign.cs" />
<Compile Include="$(MSBuildThisFileDirectory)YogaBaselineFunc.cs" />
<Compile Include="$(MSBuildThisFileDirectory)YogaConstants.cs" />
<Compile Include="$(MSBuildThisFileDirectory)YogaDimension.cs" />
<Compile Include="$(MSBuildThisFileDirectory)YogaDirection.cs" />
<Compile Include="$(MSBuildThisFileDirectory)YogaEdge.cs" />
<Compile Include="$(MSBuildThisFileDirectory)YogaExperimentalFeature.cs" />
<Compile Include="$(MSBuildThisFileDirectory)YogaFlexDirection.cs" />
<Compile Include="$(MSBuildThisFileDirectory)YogaJustify.cs" />
<Compile Include="$(MSBuildThisFileDirectory)YogaLogger.cs" />
<Compile Include="$(MSBuildThisFileDirectory)YogaLogLevel.cs" />
<Compile Include="$(MSBuildThisFileDirectory)YogaMeasureFunc.cs" />
<Compile Include="$(MSBuildThisFileDirectory)YogaMeasureMode.cs" />
<Compile Include="$(MSBuildThisFileDirectory)YogaNode.Spacing.cs" />
<Compile Include="$(MSBuildThisFileDirectory)YogaNode.cs" />
<Compile Include="$(MSBuildThisFileDirectory)YogaOverflow.cs" />
<Compile Include="$(MSBuildThisFileDirectory)YogaPositionType.cs" />
<Compile Include="$(MSBuildThisFileDirectory)YogaPrintOptions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)YogaSize.cs" />
<Compile Include="$(MSBuildThisFileDirectory)YogaUnit.cs" />
<Compile Include="$(MSBuildThisFileDirectory)YogaValue.cs" />
<Compile Include="$(MSBuildThisFileDirectory)YogaValueExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)YogaWrap.cs" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Label="Globals">
<ProjectGuid>91c42d32-291d-4b72-90b4-551663d60b8b</ProjectGuid>
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props" />
<PropertyGroup />
<Import Project="Facebook.Yoga.Shared.projitems" Label="Shared" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets" />
</Project>

View File

@@ -7,12 +7,12 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/
namespace Facebook.CSSLayout
namespace Facebook.Yoga
{
public delegate long MeasureFunction(
CSSNode node,
public delegate YogaSize MeasureFunction(
YogaNode node,
float width,
CSSMeasureMode widthMode,
YogaMeasureMode widthMode,
float height,
CSSMeasureMode heightMode);
YogaMeasureMode heightMode);
}

View File

@@ -0,0 +1,19 @@
/**
* 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.
*/
namespace Facebook.Yoga
{
public class MeasureOutput
{
public static YogaSize Make(float width, float height)
{
return new YogaSize { width = width, height = height};
}
}
}

View File

@@ -0,0 +1,332 @@
/**
* 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;
using System.Runtime.InteropServices;
namespace Facebook.Yoga
{
internal static class Native
{
#if (UNITY_IOS && !UNITY_EDITOR) || __IOS__
private const string DllName = "__Internal";
#else
private const string DllName = "yoga";
#endif
internal class YGNodeHandle : SafeHandle
{
private YGNodeHandle() : base(IntPtr.Zero, true)
{
}
public override bool IsInvalid
{
get
{
return this.handle == IntPtr.Zero;
}
}
protected override bool ReleaseHandle()
{
Native.YGNodeFree(this.handle);
GC.KeepAlive(this);
return true;
}
}
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern void YGInteropSetLogger(
[MarshalAs(UnmanagedType.FunctionPtr)] YogaLogger.Func func);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern YGNodeHandle YGNodeNew();
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern void YGNodeFree(IntPtr node);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern void YGNodeReset(YGNodeHandle node);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern int YGNodeGetInstanceCount();
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern void YGSetExperimentalFeatureEnabled(
YogaExperimentalFeature feature,
bool enabled);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern bool YGIsExperimentalFeatureEnabled(
YogaExperimentalFeature feature);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern void YGNodeInsertChild(YGNodeHandle node, YGNodeHandle child, uint index);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern void YGNodeRemoveChild(YGNodeHandle node, YGNodeHandle child);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern void YGNodeCalculateLayout(YGNodeHandle node,
float availableWidth,
float availableHeight,
YogaDirection parentDirection);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern void YGNodeMarkDirty(YGNodeHandle node);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool YGNodeIsDirty(YGNodeHandle node);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern void YGNodePrint(YGNodeHandle node, YogaPrintOptions options);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern void YGNodeCopyStyle(YGNodeHandle dstNode, YGNodeHandle srcNode);
#region YG_NODE_PROPERTY
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern void YGNodeSetMeasureFunc(
YGNodeHandle node,
[MarshalAs(UnmanagedType.FunctionPtr)] YogaMeasureFunc measureFunc);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern void YGNodeSetBaselineFunc(
YGNodeHandle node,
[MarshalAs(UnmanagedType.FunctionPtr)] YogaBaselineFunc baselineFunc);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern void YGNodeSetHasNewLayout(YGNodeHandle node, [MarshalAs(UnmanagedType.I1)] bool hasNewLayout);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool YGNodeGetHasNewLayout(YGNodeHandle node);
#endregion
#region YG_NODE_STYLE_PROPERTY
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern void YGNodeStyleSetDirection(YGNodeHandle node, YogaDirection direction);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern YogaDirection YGNodeStyleGetDirection(YGNodeHandle node);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern void YGNodeStyleSetFlexDirection(YGNodeHandle node, YogaFlexDirection flexDirection);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern YogaFlexDirection YGNodeStyleGetFlexDirection(YGNodeHandle node);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern void YGNodeStyleSetJustifyContent(YGNodeHandle node, YogaJustify justifyContent);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern YogaJustify YGNodeStyleGetJustifyContent(YGNodeHandle node);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern void YGNodeStyleSetAlignContent(YGNodeHandle node, YogaAlign alignContent);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern YogaAlign YGNodeStyleGetAlignContent(YGNodeHandle node);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern void YGNodeStyleSetAlignItems(YGNodeHandle node, YogaAlign alignItems);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern YogaAlign YGNodeStyleGetAlignItems(YGNodeHandle node);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern void YGNodeStyleSetAlignSelf(YGNodeHandle node, YogaAlign alignSelf);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern YogaAlign YGNodeStyleGetAlignSelf(YGNodeHandle node);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern void YGNodeStyleSetPositionType(YGNodeHandle node, YogaPositionType positionType);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern YogaPositionType YGNodeStyleGetPositionType(YGNodeHandle node);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern void YGNodeStyleSetFlexWrap(YGNodeHandle node, YogaWrap flexWrap);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern YogaWrap YGNodeStyleGetFlexWrap(YGNodeHandle node);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern void YGNodeStyleSetOverflow(YGNodeHandle node, YogaOverflow flexWrap);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern YogaOverflow YGNodeStyleGetOverflow(YGNodeHandle node);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern void YGNodeStyleSetDisplay(YGNodeHandle node, YogaDisplay display);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern YogaDisplay YGNodeStyleGetDisplay(YGNodeHandle node);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern void YGNodeStyleSetFlex(YGNodeHandle node, float flex);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern void YGNodeStyleSetFlexGrow(YGNodeHandle node, float flexGrow);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern float YGNodeStyleGetFlexGrow(YGNodeHandle node);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern void YGNodeStyleSetFlexShrink(YGNodeHandle node, float flexShrink);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern float YGNodeStyleGetFlexShrink(YGNodeHandle node);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern void YGNodeStyleSetFlexBasis(YGNodeHandle node, float flexBasis);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern void YGNodeStyleSetFlexBasisPercent(YGNodeHandle node, float flexBasis);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern YogaValue YGNodeStyleGetFlexBasis(YGNodeHandle node);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern void YGNodeStyleSetWidth(YGNodeHandle node, float width);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern void YGNodeStyleSetWidthPercent(YGNodeHandle node, float width);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern YogaValue YGNodeStyleGetWidth(YGNodeHandle node);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern void YGNodeStyleSetHeight(YGNodeHandle node, float height);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern void YGNodeStyleSetHeightPercent(YGNodeHandle node, float height);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern YogaValue YGNodeStyleGetHeight(YGNodeHandle node);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern void YGNodeStyleSetMinWidth(YGNodeHandle node, float minWidth);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern void YGNodeStyleSetMinWidthPercent(YGNodeHandle node, float minWidth);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern YogaValue YGNodeStyleGetMinWidth(YGNodeHandle node);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern void YGNodeStyleSetMinHeight(YGNodeHandle node, float minHeight);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern void YGNodeStyleSetMinHeightPercent(YGNodeHandle node, float minHeight);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern YogaValue YGNodeStyleGetMinHeight(YGNodeHandle node);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern void YGNodeStyleSetMaxWidth(YGNodeHandle node, float maxWidth);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern void YGNodeStyleSetMaxWidthPercent(YGNodeHandle node, float maxWidth);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern YogaValue YGNodeStyleGetMaxWidth(YGNodeHandle node);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern void YGNodeStyleSetMaxHeight(YGNodeHandle node, float maxHeight);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern void YGNodeStyleSetMaxHeightPercent(YGNodeHandle node, float maxHeight);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern YogaValue YGNodeStyleGetMaxHeight(YGNodeHandle node);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern void YGNodeStyleSetAspectRatio(YGNodeHandle node, float aspectRatio);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern float YGNodeStyleGetAspectRatio(YGNodeHandle node);
#endregion
#region YG_NODE_STYLE_EDGE_PROPERTY
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern void YGNodeStyleSetPosition(YGNodeHandle node, YogaEdge edge, float position);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern void YGNodeStyleSetPositionPercent(YGNodeHandle node, YogaEdge edge, float position);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern YogaValue YGNodeStyleGetPosition(YGNodeHandle node, YogaEdge edge);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern void YGNodeStyleSetMargin(YGNodeHandle node, YogaEdge edge, float margin);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern void YGNodeStyleSetMarginPercent(YGNodeHandle node, YogaEdge edge, float margin);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern YogaValue YGNodeStyleGetMargin(YGNodeHandle node, YogaEdge edge);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern void YGNodeStyleSetPadding(YGNodeHandle node, YogaEdge edge, float padding);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern void YGNodeStyleSetPaddingPercent(YGNodeHandle node, YogaEdge edge, float padding);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern YogaValue YGNodeStyleGetPadding(YGNodeHandle node, YogaEdge edge);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern void YGNodeStyleSetBorder(YGNodeHandle node, YogaEdge edge, float border);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern float YGNodeStyleGetBorder(YGNodeHandle node, YogaEdge edge);
#endregion
#region YG_NODE_LAYOUT_PROPERTY
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern float YGNodeLayoutGetLeft(YGNodeHandle node);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern float YGNodeLayoutGetTop(YGNodeHandle node);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern float YGNodeLayoutGetRight(YGNodeHandle node);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern float YGNodeLayoutGetBottom(YGNodeHandle node);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern float YGNodeLayoutGetWidth(YGNodeHandle node);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern float YGNodeLayoutGetHeight(YGNodeHandle node);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern float YGNodeLayoutGetMargin(YGNodeHandle node, YogaEdge edge);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern float YGNodeLayoutGetPadding(YGNodeHandle node, YogaEdge edge);
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
public static extern YogaDirection YGNodeLayoutGetDirection(YGNodeHandle node);
#endregion
}
}

View File

@@ -7,14 +7,15 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/
namespace Facebook.CSSLayout
namespace Facebook.Yoga
{
public enum CSSAlign
public enum YogaAlign
{
Auto,
FlexStart,
Center,
FlexEnd,
Stretch,
Baseline,
}
}

View File

@@ -0,0 +1,17 @@
/**
* 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;
using System.Runtime.InteropServices;
namespace Facebook.Yoga
{
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate float YogaBaselineFunc(IntPtr node, float width, float height);
}

View File

@@ -7,9 +7,9 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/
namespace Facebook.CSSLayout
namespace Facebook.Yoga
{
public static class CSSConstants
public static class YogaConstants
{
public const float Undefined = float.NaN;
@@ -17,5 +17,10 @@ namespace Facebook.CSSLayout
{
return float.IsNaN(value);
}
public static bool IsUndefined(YogaValue value)
{
return value.Unit == YogaUnit.Undefined;
}
}
}

View File

@@ -7,9 +7,9 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/
namespace Facebook.CSSLayout
namespace Facebook.Yoga
{
public enum CSSDimension
public enum YogaDimension
{
Width,
Height,

View File

@@ -0,0 +1,18 @@
/**
* 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.
*/
namespace Facebook.Yoga
{
public enum YogaDirection
{
Inherit,
LTR,
RTL,
}
}

View File

@@ -7,9 +7,11 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/
namespace Facebook.CSSLayout
namespace Facebook.Yoga
{
public enum CSSExperimentalFeature
public enum YogaDisplay
{
Flex,
None,
}
}

View File

@@ -7,9 +7,9 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/
namespace Facebook.CSSLayout
namespace Facebook.Yoga
{
public enum CSSEdge
public enum YogaEdge
{
Left,
Top,

View File

@@ -0,0 +1,17 @@
/**
* 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.
*/
namespace Facebook.Yoga
{
public enum YogaExperimentalFeature
{
Rounding,
WebFlexBasis,
}
}

View File

@@ -7,9 +7,9 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/
namespace Facebook.CSSLayout
namespace Facebook.Yoga
{
public enum CSSFlexDirection
public enum YogaFlexDirection
{
Column,
ColumnReverse,

View File

@@ -7,9 +7,9 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/
namespace Facebook.CSSLayout
namespace Facebook.Yoga
{
public enum CSSJustify
public enum YogaJustify
{
FlexStart,
Center,

View File

@@ -7,9 +7,9 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/
namespace Facebook.CSSLayout
namespace Facebook.Yoga
{
public enum CSSLogLevel
public enum YogaLogLevel
{
Error,
Warn,

View File

@@ -10,12 +10,12 @@
using System;
using System.Runtime.InteropServices;
namespace Facebook.CSSLayout
namespace Facebook.Yoga
{
internal static class CSSLogger
internal static class YogaLogger
{
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void Func(CSSLogLevel level, string message);
public delegate void Func(YogaLogLevel level, string message);
private static bool _initialized;
private static Func _managedLogger = null;
@@ -32,12 +32,12 @@ namespace Facebook.CSSLayout
Logger(level, message);
}
if (level == CSSLogLevel.Error)
if (level == YogaLogLevel.Error)
{
throw new InvalidOperationException(message);
}
};
Native.CSSInteropSetLogger(_managedLogger);
Native.YGInteropSetLogger(_managedLogger);
_initialized = true;
}
}

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