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
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
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
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
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
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
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
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
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
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
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
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
Summary: Ensure that `format.sh` can be run from anywhere with the same results.
Reviewed By: emilsjolander
Differential Revision: D4494367
fbshipit-source-id: cbd2cc36476a0a54a77a732cbe1b79388f7e0c46
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
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
Summary: Make the two podspecs more consistent with each other.
Reviewed By: dshahidehpour
Differential Revision: D4481945
fbshipit-source-id: ab782abecd709c763b4e931b6839a5cae6346281
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
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
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
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!

```
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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

Closes https://github.com/facebook/yoga/pull/324
Reviewed By: emilsjolander
Differential Revision: D4401408
Pulled By: splhack
fbshipit-source-id: ecdae7967060361bef2bc25a5ef759cb9a957322
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
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
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
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
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
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
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
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
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
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
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
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
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
Summary: We need this for scrollviews, bring on the overflow!
Reviewed By: emilsjolander
Differential Revision: D4376759
fbshipit-source-id: a427432da5e8679dbf9fdbfe4250707e727368f4
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
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
Summary: Preserve floating point values when passing them across the JNI bridge.
Differential Revision: D4366605
fbshipit-source-id: 0b94ee87a03a6ed918360dd9998930e780fc865d
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
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
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
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
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
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
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
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
Summary: This should not be an enum. A define makes a whole lot more sense
Differential Revision: D4346529
fbshipit-source-id: 8641c4c5017d915d64e5884cae09ac8f01861337
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
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
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
Summary: This test creates a repro case for Yoga to emulate UFI layout failure
Reviewed By: emilsjolander
Differential Revision: D4313632
fbshipit-source-id: 35be7d86b50a9ae08c81891a889a74e4b61f2d27
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
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
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
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
Summary: This prevents android from matching in the middle of a platform.
Reviewed By: gkassabli
Differential Revision: D4306164
fbshipit-source-id: 7f62a6a017724f8f6741d3e53b5fbe0650c8c88e
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
Summary: Running csharp tests should not result in uncommited files.
Reviewed By: splhack
Differential Revision: D4271411
fbshipit-source-id: abf6c69555ed657356a9426ca37864f8c2eaa78f
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
Summary: Rename java api to new use yoga naming
Reviewed By: IanChilds
Differential Revision: D4265345
fbshipit-source-id: 69ecfd8fac214f86b8b70647b9b909acd83d78b5
Summary: Rename test files to use new name
Reviewed By: gkassabli
Differential Revision: D4265235
fbshipit-source-id: 0090d3949828058baf7435f33d4068de92756bad
Summary: This renames the core C api to use the new Yoga branding.
Differential Revision: D4259190
fbshipit-source-id: 26c8b356ca464d4304f5f9dc4192bff10cea2dc9
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
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
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
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
Summary: Add compile flag from CSSLayout to jni target as well
Reviewed By: passy
Differential Revision: D4248473
fbshipit-source-id: 18a163a3daedc56e98c7bdc38e10fc8626999f94
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
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
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
Summary: Add notice in readme to prepare open source for large renaming diffs.
Reviewed By: splhack
Differential Revision: D4240761
fbshipit-source-id: 4c8070a06c3ac009b67eb7bef5de11ce3ab3e4d8
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
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
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
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
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
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
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
Summary: Try to move more code out of the main measure function
Reviewed By: gkassabli
Differential Revision: D4213339
fbshipit-source-id: 5ca35ca307594f3419fd0dee81321d3c2e06710f
Summary: Try to move more code out of the main measure function
Reviewed By: gkassabli
Differential Revision: D4213313
fbshipit-source-id: 2061a809202f7f948bff1b3ee8dc4c230692a223
Summary: Try to move more code out of the main measure function
Reviewed By: gkassabli
Differential Revision: D4213302
fbshipit-source-id: df4bc43848325e99ad338a2fa6d5c9404315b0e6
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
Summary:
computed flex basis was incorrectly being reused in some circumstances between calls to caluclateLayout
also run format script.
Reviewed By: dshahidehpour
Differential Revision: D4207106
fbshipit-source-id: fc1063ca79ecf75f6101aadded53bca96cb0585d
Summary:
```isnan``` is already defined in ```math.h``` (at least when using VS13) so there is no need to redefine it. it also is a nan for float and not for double opposed to ```_isnan```
Closes https://github.com/facebook/css-layout/pull/253
Reviewed By: emilsjolander
Differential Revision: D4199331
Pulled By: splhack
fbshipit-source-id: 139fb0efd68dd5df79bbaef863a8e8b9246c795d
Summary:
Use ```size_t```instead of ```unsinged long``` as this is the "offical" return type of ```strlen```. Is VS13 ```size_t``` is defined as ```unsigned long long``` which leads to a compiler warning.
Closes https://github.com/facebook/css-layout/pull/254
Reviewed By: emilsjolander
Differential Revision: D4199327
Pulled By: splhack
fbshipit-source-id: 5e1a91f282bf776e4d9f5806e6467dfe36c7a633
Summary:
- Add a convenience function to copy all style from one node to another.
- CSSNodeIsDirty will return true after this function if any style was changed in the destination node.
Reviewed By: emilsjolander
Differential Revision: D4188514
fbshipit-source-id: af8d7fb5e8688c64aea05ce7ad23fff9233fb441
Summary:
- Problem: Build error in Visual Studio since an array cannot have zero size.
- e6702e1168 (commitcomment-19839659)
- Solution: Add 1 until we'll have actual CSSExperimentalFeature value.
Reviewed By: emilsjolander
Differential Revision: D4191268
fbshipit-source-id: 53fdcc388292e76c2b97ad071f0d7c27d0613ecf
Summary:
When dealing with manual sizing in UIView's (or UIKit in general) we see a common pattern like so:
Below we have an example implementation of a view with two Labels that want to be stacked horizontally. If we don't pass a second string, we hide the second label and give up the available space to the first label. See below:
```
interface TitleSubtitleView : UIView
- (void)configureWithTitle:(NSString *)title subtitle:(NSString *)subtitle;
end
implementation {
UILabel *_titleLabel;
UILabel *_subtitleLabel;
}
....
- (void)configureWithTitle:(NSString *)title subtitle:(NSString *)subtitle {
_titleLabel.text = title;
if (subtitle.length > 0) {
_subtitleLabel.hidden = NO;
_subtitleLabel.text = subtitle;
} else {
_subtitleLabel.hidden = YES;
}
}
- (CGSize)sizeThatFits:(CGSize)size {
const CGSize titleSize = [_titleLabel sizeThatFits:size];
CGSize subtitleSize = CGSizeZero;
if (!_subtitleLabel.isHidden) {
subtitleSize = [_subtitleSize sizeThatFits:CGSizeMake(size.width - titleSize.width, size.height - titleSize.height)];
}
}
- (void)layoutSubviews {
[super layoutSubviews];
const CGSize titleSize = [_titleLabel sizeThatFits:size];
_titleLabel.frame = CGRectMake(0, 0, titleSize.width, titleSize.height);
if (!_subtitleLabel.isHidden) {
subtitleSize = [_subtitleSize sizeThatFits:CGSizeMake(size.width - titleSize.width, size.height - titleSize.height)];
_subtitleLabel.frame = CGRectMake(CGRectGetMaxX(_titleLabel.frame), 0, subtitleSize.width, subtitleSize.height);
}
}
```
The problem is with the CSSLayout framework, as long as your view is in hierarchy, it's going to be allocated space during layout calculation. The only way to fix the view above would be to completely remove it from view hierarchy if it isn't being used. The problem is that adding/removing views from hierarchy is much less performant than hiding.
As a result, we need a way to tell the CSSLayoutKit library that even though a view is in hierarchy, we don't want to include it in layout. With this diff, we could change the class to look like this:
```
interface TitleSubtitleView : UIView
- (void)configureWithTitle:(NSString *)title subtitle:(NSString *)subtitle;
end
implementation {
UILabel *_titleLabel;
UILabel *_subtitleLabel;
}
....
- (void)configureWithTitle:(NSString *)title subtitle:(NSString *)subtitle {
_titleLabel.text = title;
_subtitleLabel.text = subtitle;
const BOOL subtitleHasText = subtitle.length > 0;
_subtitleLabel.hidden = !subtitleHasText;
[_subtitleLabel css_includeInLayout:!subtitleHasText];
}
- (CGSize)sizeThatFits:(CGSize)size {
const intrinsicSize = [self css_intrinsicSize];
return CGSizeMake(MIN(size.width, intrinsicSize.width), MIN(size.height, intrinsicSize.height)));
}
- (void)layoutSubviews {
[super layoutSubviews];
[self css_applyLayout];
}
```
Reviewed By: emilsjolander
Differential Revision: D4189897
fbshipit-source-id: 403d11d84d47691e3ce0b5ac18a180b0e4c104c4
Summary: When I try to use this in practice, I have come to realize that css_sizeThatFits will 99% return to you the constrainedSize that you pass it, thus making it useless. Instead, we replace it with a new API that will tell you the optimal size of the resolved layout. From this we can choose to use that size, or scale it down.
Reviewed By: emilsjolander
Differential Revision: D4191873
fbshipit-source-id: d36a2850448d9d82f97e5ef4c7397778c2a14094
Summary: Remove infra for dynamically downloading gtest as this fails like 50% of the time on travis. I'll manually push gtest as a submodule instead.
Reviewed By: gkassabli
Differential Revision: D4183033
fbshipit-source-id: 09a121b8ede7a5974a29b6692edc63bff79aece7
Summary: For some reason these tests don't pass when running in travis. They are still running internally so we should catch any regressions. We can remove this if we figure out what is causing travis to fail here but until now I would rather get travis to pass.
Reviewed By: dshahidehpour
Differential Revision: D4189251
fbshipit-source-id: a27d3390f6b6fdcac6a3312d02581bb64969fd4b
Summary:
- Add CSSLayoutSetMemoryFuncs function which allows application to replace malloc, calloc, realloc and free with application's functions, like zalloc and zfree of zlib.
- Fixed memory leaks in tests.
- Close#247
For example, to use dlmalloc with USE_DL_PREFIX
CSSLayoutSetMemoryFuncs(&dlmalloc, &dlcalloc, &dlrealloc, &dlfree);
Reviewed By: emilsjolander
Differential Revision: D4178386
fbshipit-source-id: a79dbdaf82a512f42cc43f99dbc49faba296903b
Summary: Keeping enums in sync between all the different bindings is tedious and error prone. Getting one of the values in the incorrect order could lead to many hours of debugging as they are passed as ints to C. This diff adds a simple python script to generate these enums for all languages. This also makes it much easier to add support for more languages in the future
Reviewed By: gkassabli
Differential Revision: D4174263
fbshipit-source-id: 478961a8f683e196704d3c6ea1505a05c85fcb10
Summary: If some test previous to this test fails to de-allocate a node we don't want this test to fail.
Reviewed By: dshahidehpour
Differential Revision: D4182179
fbshipit-source-id: 229dd5736d6d7b9c1b22b181e022c788584b9c17
Summary: Talked with emilsjolander offline, and we want to keep the prefixes standardized in this lib. Changing CLK prefixes to CSS.
Reviewed By: emilsjolander
Differential Revision: D4175634
fbshipit-source-id: 7152268b9312df3fdb8eaee7ce3f6baabc5de937
Summary: We want to start experimenting with changes to the library in a more controlled and easier to measure manner. This diff adds the basics of an experiment layer to csslayout.
Reviewed By: gkassabli
Differential Revision: D4174260
fbshipit-source-id: ad3667183810c02833fba9a1276f89286e848fcd
Summary: Java and csharp already use CSSWrap and not CSSWrapType. Let's consolidate and stick with the shorter of the two.
Reviewed By: gkassabli
Differential Revision: D4174257
fbshipit-source-id: ba0bfab996ba158b07863d8c72cf2a41262c9592
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: gkassabli
Differential Revision: D4157971
fbshipit-source-id: 3cfae15ac8b65b70f01789444099ee684e1b099a
Summary: There is a little bit of tidying that was needed for this class. The documentation was inconsistent in the header, the static functions were prefixed with underscores (discouraged by apple). Cleaned it all up.
Reviewed By: rnystrom
Differential Revision: D4167936
fbshipit-source-id: 6e9a6e7fb78e3cff290b867a1ac0d5dd5cc9de5b
Summary: Just firming up some stuff with more compiler flags.
Reviewed By: rnystrom
Differential Revision: D4168081
fbshipit-source-id: fced407f03944081bdd70cc28c57e3dc842ff7f0
Summary: Previous fix for flex in max size constraint was not entirely correct and was missing a test case for the time when the max constraint is not applied. This diff addresses that.
Reviewed By: gkassabli
Differential Revision: D4162104
fbshipit-source-id: 08feba6cb4e789c9aa12179e2cdeadc66b011841
Summary:
When trying to integrate this into an Xcode project that already included CSSLayout.[c|h], we were getting a linker error.
Upon digging in, I found out that Xcode was becoming confused because the imports of the uikit library and the c library are both `#import <CSSLayout/CSSLayout.h>`. So, it needed a new name.
Reviewed By: emilsjolander
Differential Revision: D4162621
fbshipit-source-id: b5f7624eb29f1b9eaebbed5104ec9ea8a12ad2e5
Summary: Currently travis logs indicate it is building with the wrong cxx platform. Explicitly set this to and ios simulator for ios tests
Reviewed By: dshahidehpour
Differential Revision: D4162159
fbshipit-source-id: 50f563132456ee4ba4e5b3b4b1f50b636cb94306
Summary: Same as Java, it allows to use float and double values in Make arguments.
Reviewed By: emilsjolander
Differential Revision: D4163347
fbshipit-source-id: f373247b3f37e7940a66044000cca2935068decf
Summary: Pointed out by the Xcode analyzer
Reviewed By: emilsjolander
Differential Revision: D4159938
fbshipit-source-id: 8b9ff3896c0e222e8e89546881129214bc6ba566
Summary: It was always a mistake to have a measure function here but the recent addition of an assertion made us notice it.
Reviewed By: splhack
Differential Revision: D4156754
fbshipit-source-id: 98fcea6e233cb4f5706ebca37028c8d67edb4c09
Summary: Add tests for checking C side asserts in managed
Reviewed By: emilsjolander
Differential Revision: D4154869
fbshipit-source-id: 5203db27eff963d46f188de448f607a24ed63fab
Summary: Travis builds have been broken for a while. This diff fixes some of the issues surrounding bad buck file configuration as well as missing jni.h file.
Reviewed By: astreet
Differential Revision: D4148724
fbshipit-source-id: 1e284db61280326a4bcbb9337e804a4804348aa6
Summary:
If there is a single child which is flex grow and flex shrink then instead of measuring and then shrinking we can just set the flex basis to zero as we know the final result will be that the child take up all remaining space.
This is a re-land of D4147298. I have updated the diff to check explicitly for exact measure mode to also handle at_most case correctly.
Reviewed By: gkassabli
Differential Revision: D4153133
fbshipit-source-id: 2333150a83857cc30078cc8d52761cbd00652830
Summary:
@public
The goal of this diff is to have assertion failures show up as error logs on Android. To do this, I updated the logging API to take calls with log levels. We now have to pass around va_list unfortunately since you can't re-expand or pass along var-args to a subcall.
Reviewed By: emilsjolander
Differential Revision: D4140898
fbshipit-source-id: e0eb9a1f0b08a7d90a8233f66bb857d5b871b6ad
Summary: Default value for positions should be undefined not 0px. Fixing this leads to more correct tests.
Reviewed By: gkassabli
Differential Revision: D4153329
fbshipit-source-id: d0f194f9c47eac93d3815ec7e55568a1016bc7fe
Summary: Within `UIView+CSSLayout`, we often nil out the measure function of a node because view hierarchy can often change. Unfortunately, this causes us to hit an assert which crashes the app. Instead, lets the measure func to be set to NULL, regardless of how many children a node might have.
Reviewed By: emilsjolander
Differential Revision: D4148727
fbshipit-source-id: 79a0f3ef1bf7b1dce9a14de96f870e35c042b78b
Summary: If there is a single child which is flex grow and flex shrink then instead of measuring and then shrinking we can just set the flex basis to zero as we know the final result will be that the child take up all remaining space.
Reviewed By: gkassabli
Differential Revision: D4147298
fbshipit-source-id: 8416508a31e8d317bf59d956abdbe5760b55bb6d
Summary: If there is a single child which is flex grow and flex shrink then instead of measuring and then shrinking we can just set the flex basis to zero as we know the final result will be that the child take up all remaining space.
Reviewed By: gkassabli
Differential Revision: D4147298
fbshipit-source-id: 51152e57eff8e322a833a6d698c30f8c5e2dcc35
Summary:
Max dimension constraints were not correctly passed down to children.
see https://github.com/facebook/css-layout/issues/230 for more info
fixes#230
Reviewed By: gkassabli
Differential Revision: D4147199
fbshipit-source-id: feb335eb8687a1b7939ee8cd8649e455e0c069a9
Summary: Scrolling through feed and logging when this optimization is hit leads to... 0 logs. If anything this just adds to confusion. It was initially added due to instinct and not data, which was a mistake. I am happy to add some similar optimization in the future if we have data that it is useful in real world situations, currently it just leads to bugs and confusion though.
Reviewed By: astreet
Differential Revision: D4146785
fbshipit-source-id: e20d780fbd5759b8f38b809e8cadf29cedee82a8
Summary: Not sure why this didn't catch during my testing, but, this causes a build error. #accept2ship
Reviewed By: emilsjolander
Differential Revision: D4143108
fbshipit-source-id: 01c35c5b91767c95485d615eb06e836b023e125a
Summary: For some reason I didn't get a signal of this breakage. Fixing unit tests.
Reviewed By: emilsjolander
Differential Revision: D4140327
fbshipit-source-id: 95049b510a8869b6f68cc841e7f8731364417af9
Summary: css-layout will only call measure which it is unsure of the size of a node so it will never call measure with both modes equal to exact.
Reviewed By: dshahidehpour
Differential Revision: D4142193
fbshipit-source-id: fb8423cf0d45852ecb9df8fed042b25d1a443eea
Summary:
Not all platforms have gtest death tests. There is a define to check for that.
Bracketed the relevant tests with the define.
Reviewed By: youerkang
Differential Revision: D4141823
fbshipit-source-id: 1396657f3ee83853fcda85d5a51708d4e77642cb
Summary: We don't want to expose this in our first usage. Lets kill it.
Reviewed By: emilsjolander
Differential Revision: D4140377
fbshipit-source-id: 0c53845ec65466692b847a5ce40c3b9823dd9557
Summary: You can lose a lot of performance on UIView's if they are not pixel-aligned. This protects it from happening in views which use css-layout.
Reviewed By: emilsjolander
Differential Revision: D4140306
fbshipit-source-id: 53493c08c084a7e3dcd4e05f6a665a99340ea5a6
Summary:
The inline keyword is available only in C++. The __inline and __forceinline keywords are available in both C and C++. For compatibility with previous versions, _inline is a synonym for __inline.
https://msdn.microsoft.com/en-us/library/z8y1yy88(v=vs.120).aspx
Closes https://github.com/facebook/css-layout/pull/239
Reviewed By: astreet
Differential Revision: D4138941
Pulled By: emilsjolander
fbshipit-source-id: cb59dc91ef285e5378036c4912217fd4ec8d9f79
Summary: As I've begun to integrate this into the codebase, I've found that sometimes our layouts are affected by bad implementations of sizeThatFits:. For example, in certain configurations of UILabel it won't take clipping into account and return a size that is much larger than the max size we requested. This adds some checks to make sure we never return a size that is larger than the one specified by `_measure`. This also fixes the bug where `CSSMeasureModeExactly` won't be applied if the measure mode for other parameter is node `CSSMeasureModeExactly`.
Reviewed By: emilsjolander
Differential Revision: D4131195
fbshipit-source-id: 4659fd83892a2c149b3b70733b06b19217507bf9
Summary:
@public
In the JNI portion of CSSLayout, there's a subtle bug where we were caching the jmethodid of the 'measure' of the first object that had measure called on it. However, if that class had overriden measure, then the jmethodid would be specific to that subclass's implementation and would not work for other classes. Conversely, if a regular CSSNode had been called first, then the super method would be called on the subclass instead of the proper overriden method.
Since there's not really a reason to overriden measure anyway (since you can just provide a different measure function), it's safest to just mark it final and explicitly cache the appropriate methodid
Reviewed By: emilsjolander
Differential Revision: D4132428
fbshipit-source-id: 6fb51597d80f1c03681e6611153b52b73b392245
Summary:
@public
We don't need to allocate a list for every node since leaf nodes don't have children.
Reviewed By: emilsjolander
Differential Revision: D4130818
fbshipit-source-id: 80d3e98fce9d2daa0676fd1cbed0e81edcf7adb3
Summary:
@public
Instead of silently ignorning non-leaf nodes with measure functions, we should assert that we don't create those kinds of trees.
Reviewed By: emilsjolander
Differential Revision: D4130770
fbshipit-source-id: a3ef10a2e63bbc12b5aa07977e4b84c8d59e3ffe
Summary: flex is just shorthand for flexBasis, flexGrow and flexShrink, and I don't want to expose overflow yet, so, removing them from the API.
Reviewed By: ryanolsonk
Differential Revision: D4126773
fbshipit-source-id: e3b9ef714832cb5665bd20d7fa92f97a266c9210
Summary: Currently, when we try to remove a child from a node, that node is mark dirty //regardless of whether or not anything was actually removed//. This fixes it.
Reviewed By: gkassabli
Differential Revision: D4125453
fbshipit-source-id: 745cfc55269415fea106a80c72401eb3074f2d31
Summary: This exposes an API so people can find out the resulting size of a layout calculation without changing the frame of the view.
Reviewed By: emilsjolander
Differential Revision: D4124630
fbshipit-source-id: f2b28d8a5474857cb1c92e021a1f161806826cda
Summary: We need to expose CSSLayout caching check to CKFlexboxComponent to enable performant bridging to CKComponentKit
Reviewed By: emilsjolander
Differential Revision: D4124705
fbshipit-source-id: 23284967900585fa20dcb51c9cc1bee829b32975
Summary: With the current implementation, as long as you had set a value on usesFlexbox (YES or NO), it would return YES. This fixes it.
Reviewed By: amonshiz
Differential Revision: D4124485
fbshipit-source-id: 32fe4ec0109b5c8678a112f9d4295bd17a6f6dc2
Summary: We don't want people to somehow change the underlying cnode on our CSSNodeBridge. Making it readonly.
Reviewed By: rnystrom
Differential Revision: D4124496
fbshipit-source-id: f88ed82c1df17d401aeca6f6341e429c95e55624
Summary:
Even so the problem of #236 has been fixed via ced779b there is still a case where you have a out of bound array access of undefined behaviour. This PR prevents the out of bound access of the underlying c array. The out of bound access happens if you already have 4 subViews and add another one. Then you will access CSSNodeGetChild with 4 which points into uninitialized memory.
Closes https://github.com/facebook/css-layout/pull/237
Reviewed By: dshahidehpour
Differential Revision: D4107743
Pulled By: emilsjolander
fbshipit-source-id: 0f21397f3a77308369acfea7327733f74eb72e00
Summary: Previously, we would preallocate Node's with a child list of 4. We recently removed that logic (see diff below), and as a result, if you tried to access a Node's list of children before it had been allocated, you would crash. I added a simple check to protect from crashes, the operation of the check is O(1) so we shouldn't see a perf hit.
Reviewed By: emilsjolander
Differential Revision: D4104093
fbshipit-source-id: cd7b09818759aa76415b97e241f1a6746a2bc50c
Summary: Simplify logic for what value to return in smaller functions with a preference for ternary operator where possible.
Reviewed By: gkassabli
Differential Revision: D4101772
fbshipit-source-id: 626df10c0fc76278c330c86be4dc82fdda5f5156
Summary: This list can only contain CSSNodeRefs so don't use void*
Reviewed By: gkassabli
Differential Revision: D4101773
fbshipit-source-id: 8a5c9066da796967bd02ce6b1fc74ff40e15dfe1
Summary: Add a more complex benchmark which actually take a couple milliseconds to perform. This makes it easier to see if optimizations have any effect. More styles should be added later to make sure the benchmarks covers most of the csslayout code.
Reviewed By: gkassabli
Differential Revision: D4101780
fbshipit-source-id: 6bdf703edfbe64c47c77e04ef1ca946f4b75d093
Summary: Since these functions are private and only used in the implementation file, we don't need to declare them beforehand.
Reviewed By: emilsjolander
Differential Revision: D4088488
fbshipit-source-id: 738175a4aae27d88d32f8c2cf6b47a4f6ae32aab
Summary:
- bit operation with long
- Clean up _measureOutput which is no longer needed
- Fix unittests (SetMeasureFunction, unused error)
Reviewed By: emilsjolander
Differential Revision: D4082401
fbshipit-source-id: b3b2dd002d108c5b43f36a4a73ce8e5233281b45
Summary: Set layout outputs on CSSNode from C after layout calculation finishes instead of relying on calling jni gettings from java code. This should be much more efficient as it avoids a lot of jni overhead and also allows for calling getLayoutWidth() etc multiple times without incurring a penalty.
Reviewed By: lexs
Differential Revision: D4077968
fbshipit-source-id: bce86ba610cd5ae36cfb45d78b2609c63a14cfa3
Summary: To perform some JNI optimizations for java we need a reference to the node in the measure function. This updates the API to provide the whole node as input instead of just the context.
Reviewed By: javache
Differential Revision: D4081544
fbshipit-source-id: d49679025cea027cf7b8482898de0a01fe0f9d40
Summary: This is an API breaking change done to allow us to avoid an allocation during measurement. Instead we do the same trick as is done when passing measure results to C, we path them into a long.
Reviewed By: splhack
Differential Revision: D4081037
fbshipit-source-id: 28adbcdd160cbd3f59a0fdd4b9f1200ae18678f1
Summary: This state was never reset when we switched to doing reset in C instead of re-allocating.
Differential Revision: D4081049
fbshipit-source-id: 0b9ad70339ad906ad5219ad2679329cfe2fd7abc
Summary:
- Prevent the GC from collecting MeasureInternal in order to call managed MeasureFunction properly from unmanaged
- TestMeasureFuncWithDestructor will fail without the fix
- Avoid new as C implementation
Reviewed By: emilsjolander
Differential Revision: D4080765
fbshipit-source-id: d58fa18f6f74012aeda5dd15dfa7ceb0b64584d0
Summary: Many layout systems query the padding after calculation to as it is needs to be propagated to the underlying view system on the platform. However most nodes have no padding set on them so going 4-6 times through JNI layer to figure this out is a waste of time.
Differential Revision: D4080909
fbshipit-source-id: 7eb1885c615191055aa21e3435c6fbc652b883ae
Summary: There is no reason to malloc a list of 4 child pointers for every CSS node eagerly. Instead, we malloc the list (preserving the default size of 4) when we try to put stuff in it.
Reviewed By: emilsjolander
Differential Revision: D4078012
fbshipit-source-id: 7cdcab03ec4067550a5fee5e1baea14344f3a8f9
Summary: sleeping in the measure function was done to ensure we were not regressing in double measure calls. This was before we have CSSLayoutMeasureCacheTest though. Let's switch over benchmark to purely benchmark the algorithm and not simulate measure time.
Reviewed By: swolchok
Differential Revision: D4078186
fbshipit-source-id: e1c16806b3c8714e223e1cfcb6c43846f8f6bbb2
Summary:
This PR leads to removing the children from the end. [So we don't have the overhead of copying them to the front](dcaef7ecb0/CSSLayout/CSSNodeList.c (L62)).
Closes https://github.com/facebook/css-layout/pull/233
Reviewed By: emilsjolander
Differential Revision: D4075905
Pulled By: splhack
fbshipit-source-id: d8b460badb01bfc6ea647004c799395b9cab9e7c
Summary:
- Update CSSNodeFree to unlink parent and children for C#, Java and Objective-C bindings finalizer.
- [C#] Fix build (Fix#232)
- [C#] Add Clear API for convenience as CSSNodeFreeRecursive.
- [C#] Revise and add unit tests
Reviewed By: emilsjolander
Differential Revision: D4069655
fbshipit-source-id: 1fd764059784d7968af38b6aaf7fb6f70fdee8ee
Summary: canUseCachedMeasurement function was not handling CSSMeasureModeAtMost correctly so a bunch of measurements that could have been reused were not. When a previous measurement used AtMost and the new one as an AtMost with a smaller constraint but still bigger than the previous computed size it should be OK to re-use the previously computed size.
Reviewed By: gkassabli
Differential Revision: D4071621
fbshipit-source-id: 19d87d939051ddf8ee2e1c6e60efee22d173bbb9
Summary: Remove duplicate functions calls. Using instruments I could see a 5% perf increase from this change.
Reviewed By: gkassabli
Differential Revision: D4068140
fbshipit-source-id: 91261afb73e1c5e23c2cfc84df6ecc5c844a4e78
Summary: The current implementation was made out of simplicity and to keep the same API as before. Now that the java version of csslayout is deprecated it is time to change the API to make the calls more efficient for the JNI version. This diff with reduce allocations as well as reduce the number of JNI calls done.
Differential Revision: D4050773
fbshipit-source-id: 3fd04c27f887a36875e455b5404a17154ac18f91
Summary: Instead of having different lifetimes for java and c memory we can can tie them together and make them much easier to manage. This also leads to automatically pooling native memory if pooling java memory.
Differential Revision: D4051454
fbshipit-source-id: 8f5d010be520b3d1c981a7f85e5e6d95773ea6c1
Summary: It doesn't make sense to have a getter for the shorthand as it is the computed flexGrow and flexShrink values that you should care about.
Reviewed By: gkassabli
Differential Revision: D4064674
fbshipit-source-id: 69935b85042020b4e8c61a393c1be8f4d42a6674
Summary: when setting both flex and flexGrow then flexGrow should override flex even though flex was setter after.
Reviewed By: gkassabli
Differential Revision: D4064696
fbshipit-source-id: db2d4b8e60209f0a9eed6794a167b85e453be41c
Summary:
- Update README for gentest
- Fix gentest.rb for the right working dir
Reviewed By: emilsjolander
Differential Revision: D4065863
fbshipit-source-id: 5c6bd9d18779c05c1de24c06a83b148889facb6b
Summary:
- Revise scripts to generate Java and C# unittests using the same HTML fixtures as well as C for code coverage.
- Add wrap_column test workaround in gentest.js.
- Add checkDefaultValues for sanity check of the CSSLayout default values by test-template.html
- Add `align-content: flex-start;` in default div to align with CSSLayout default
$ cd csharp/gentest
$ ruby gentest.rb
- macOS example for C#
$ cd csharp/tests/Facebook.CSSLayout
$ clang -DCSS_ASSERT_FAIL_ENABLED -Wall -Wextra -dynamiclib -o libCSSLayout.dylib -g -I../../.. ../../../CSSLayout/*.c ../../CSSLayout/CSSInterop.cpp
$ mcs -debug -t:library -r:nunit.framework.dll -out:CSSLayoutTest.dll *.cs ../../../csharp/Facebook.CSSLayout/*cs
$ mono64 --debug nunit-console.exe CSSLayoutTest.dll
Reviewed By: emilsjolander
Differential Revision: D4053777
fbshipit-source-id: 84450208015e65baf604987bd56c6a268598b545
Summary:
When using CSS-Layout in a C# UWP project in x86, by default the MSVC compiler defaults the delegate calling convention to cdecl, while .NET assumes that all delegates are declared using stdcall. This causes a problem when invoking such as this error:
```
Run-Time Check Failure #0 - The value of ESP was not properly saved across
a function call. This is usually a result of calling a function declared with one
calling convention with a function pointer declared with a different calling
convention.
```
This PR changes the calling convention in the C# code to reflect cdecl by using the `UnmanagedFunctionPointer` attribute and setting the calling convention to `CallingConvention.Cdecl`.
```csharp
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate CSSSize CSSMeasureFunc(
IntPtr context,
float width,
CSSMeasureMode widthMode,
float height,
CSSMeasureMode heightMode);
```
I have updated all calls as well to other functions. I
Closes https://github.com/facebook/css-layout/pull/231
Reviewed By: emilsjolander
Differential Revision: D4063437
Pulled By: splhack
fbshipit-source-id: b1069a1b9f675d2623a64a1c5f3189292a18a646
Summary: ryandm pointed out that `use_cxx_library` is necessary for fbcode overrides. And that's also true for fbandroid now.
Reviewed By: ryandm
Differential Revision: D4053192
fbshipit-source-id: 453e77df6f31b9bf6b2d221d7def8361e2966ff2
Summary:
Originally, we thought that skipping the measurement of views that were hidden would be a nice optimiatzion. Upon further review, we saw that according to Apple's `UIView` documentation:
> A hidden view disappears from its window and does not receive input events. It remains in its superview’s list of subviews, however, and participates in autoresizing as usual.
So, to keep parity with common iOS layout APIs, we are going to size and layout views, even if they are hidden.
Reviewed By: emilsjolander
Differential Revision: D4051225
fbshipit-source-id: 0794cbad293a7de83d109dad2b3983d83845d145
Summary: Fixup format file for hopefully the last time in a while and re-format code
Reviewed By: gkassabli
Differential Revision: D4044545
fbshipit-source-id: 60ebb73cfdd9dbc9b5fae62ddebf37e9b1e6eecf
Summary:
- CSSLayoutSetLogger
- Problem: Unity or other logging system can't use printf output
- Solution: Add CSSLogger to pass CSSNodePrint result to UnityEngine.Debug.Log or other logging system via CSSLogger function for debugging purpose
Reviewed By: emilsjolander
Differential Revision: D4027044
fbshipit-source-id: 90e2e449260888770f71fa7ea790ca9764d91c44
Summary: Flex basis should override height/width. Not the other way around.
Reviewed By: gkassabli
Differential Revision: D4029374
fbshipit-source-id: bc3c72879f3937a50bf8a636b547adc7b9a4f5a7
Summary: Use typedefs from header for print and measure functions
Reviewed By: gkassabli
Differential Revision: D4036421
fbshipit-source-id: 01f15cb840363850970e6a60e661af06fd6ec9e0
Summary:
The flag to use in fbandroid is `-Duses_native_libraries` passed in via `vm_args`
In `fbandroid/third-party/build-tools/java/java.sh` looks for this flag to override the default java with the fbcode runtime java.
Reviewed By: ryandm
Differential Revision: D4024857
fbshipit-source-id: 0ace0ee94fea32376a24004582556fa1d7d2e222
Summary: If we ever add more cases to an enum the compiler would not complain if we used default.
Reviewed By: gkassabli
Differential Revision: D4036440
fbshipit-source-id: f5ef4c8afff0f353de50681ad304878f90255fef
Summary: Prefer inline style to computed style as inline style should be the source of truth and computed style may differ
Reviewed By: gkassabli
Differential Revision: D4029373
fbshipit-source-id: 39ce9d577f295c2361dc384212d7467418c63c33
Summary: Min dimension was not respected when calculating justify content. This diff ensures that the min dimension is taken into account when at most measure spec is used.
Reviewed By: gkassabli, lucasr
Differential Revision: D4021443
fbshipit-source-id: 00f58c6078ac3076221e1148aacc34712786deb5
Summary: using `IS_THIS_FBOBJC` will break the tests in the open-source repo. This fixes Facebook builds and open source builds.
Reviewed By: WaseemTheDream, mzlee
Differential Revision: D4025580
fbshipit-source-id: 8280520a63134744fd24518aa6f45423aa0ecd03
Summary: Now that we have some tests, lets run them.
Reviewed By: emilsjolander
Differential Revision: D4023765
fbshipit-source-id: 9f2fa723dc9a33f12c0470b782d6329b432546fa
Summary: Gate it with `THIS_IS_FBOBJC` for now - the better solution is gating with fb_xplat_cxx_library and fb_xplat_cxx_test
Reviewed By: dshahidehpour
Differential Revision: D4024973
fbshipit-source-id: 2ce744fd67630b39b0498d0479a034d0b05c68ed
Summary: Wrote some tests to make sure the associated objects we use for layout live and die with the objects. This was worthwhile because it made me realize UIView+CSSLayout wasn't enabled to ARC. As a result, my tests were failing because they weren't explicitly deallocing nodes.
Reviewed By: rnystrom
Differential Revision: D4023324
fbshipit-source-id: 5356cf4f0522582d75f83b5eb2193d9bc8d63aee
Summary: `sizeThatFits:` can be expensive, this optimizes our measuring function so that we do not call it if we know that we are going to use the exact height and width that were passed-in.
Reviewed By: rnystrom
Differential Revision: D4023715
fbshipit-source-id: dc02703b50bafd168ffab62ed98a7f6342100cc9
Summary: If views are hidden on screen, we don't want to bother including them in layout calculations.
Reviewed By: rnystrom
Differential Revision: D4022992
fbshipit-source-id: 2e93eb911f26223f305ef7ce788f86d050b83e4a
Summary: I'm going to make some changes, but first, I want to get testing setup.
Reviewed By: rnystrom
Differential Revision: D4022585
fbshipit-source-id: a48516faad0bcb1a9cf5610ab21da5ee099c6f16
Summary: Don't assume a node with a measure function is a leaf node
Reviewed By: gkassabli
Differential Revision: D4021096
fbshipit-source-id: 7e039239b1697a0ac42dce9f4b7e252a931bad7e
Summary: Rename C test target to match pattern of other test targets
Reviewed By: gkassabli
Differential Revision: D4014931
fbshipit-source-id: 2b4b831d6073214e8162a1d27b7478f3665a795f
Summary: This diff adds compatibility with Apple TVOS Buck build for CSSLayout library. Warning fixes are needed to ensure correct build
Reviewed By: emilsjolander
Differential Revision: D4001901
fbshipit-source-id: f095b4ac0ba91addb28d877b411ec27ecff4aad6
Summary: Update readme adding UIKit and fixing things that have changed
Differential Revision: D4015068
fbshipit-source-id: 213a60bea6f16ca01a4e613c8e3563f7c354ca8e
Summary:
The changed functions tripped -Wmissing-prototypes. (e.g.,
`void Foo();` doesn't count as a prototype in C. you need `void
Foo(void);`)
Reviewed By: mzlee
Differential Revision: D4012611
fbshipit-source-id: f56949d464e0ce602138b60f4abfd45b211be3b2
Summary: Add flexbox support to UIViews via a category
Reviewed By: dshahidehpour
Differential Revision: D4002873
fbshipit-source-id: f89de3acdf8fd89c7801918dcad34ba9011dd025
Summary: Move java buck rules out of the root buck file and into the java subfolder. This matches how buck should be used. Having one huge buck file is not best practice.
Reviewed By: lucasr
Differential Revision: D4008408
fbshipit-source-id: 5895c62cc8806d6a849e1b2cc6ea95c36b9d99b6
Summary: Remove tests for CSSNodeDEPRECATED. Java tests will be replaced by jni binding tests in upcoming diff.
Reviewed By: lucasr
Differential Revision: D3992821
fbshipit-source-id: d4877674c96f667f5acf92aab58af02aa27da4c2
Summary: Rename init() -> reinit() to be more in line with what it now does as the initiall init is done when constructing the object.
Reviewed By: lucasr
Differential Revision: D3992811
fbshipit-source-id: 61a10acc873ec028b2789007a400d89e62cf31d6
Summary: Rename reset() -> free() to be more in line with what it now does as the default implementation is JNI
Reviewed By: lucasr
Differential Revision: D3992808
fbshipit-source-id: 8428ae33268d1417ce8642b741e47150a17bf077
Summary: Don't require calling init() to used an allocated object. This makes more sense and is more in line with how jni in java is generally managed.
Reviewed By: lucasr
Differential Revision: D3992802
fbshipit-source-id: 06d65821f1802ed8f2b2db651cef69f6851803f2
Summary: JNI version is the default, its name should reflect that
Reviewed By: lucasr
Differential Revision: D3992777
fbshipit-source-id: cdd4cc58f3c15b5db1158f6f794394eb5c44a44d
Summary: Remove internal xcode_public_headers_symlinks flag from open source in hope to fix travis builds.
Reviewed By: lucasr
Differential Revision: D3992698
fbshipit-source-id: 1bd19bdd18d1bdfff595c19475bb2adc23d95335
Summary: Clearly mark java CSSNode as deprecated. It will go away very soon.
Reviewed By: lucasr
Differential Revision: D3992775
fbshipit-source-id: b3ceca277e5c7426eb51f8cbeacf5e2fe451c6ec
Summary: Move csharp tests into csharp/tests instead of tests. I feel like it makes more sense to have tests next to source. This is similar to how the C version has it as well.
Reviewed By: splhack
Differential Revision: D3993002
fbshipit-source-id: d9241f8ce7707c17a49c17fea2cce9959d52697d
Summary: buck rules are not meant to be in the root buck file but instead next to source files. This diff moves benchmark rule into benchmark folder.
Reviewed By: lucasr
Differential Revision: D3992992
fbshipit-source-id: 34782ff73bbd5b799d83d0f01b553bfab928f1df
Summary: Ensure all native memory is released once gc deallocates the java object reference.
Reviewed By: lucasr
Differential Revision: D3992759
fbshipit-source-id: f648b72ead5bdb7257a5197496b19795f71f3788
Summary: Add some dependencies to enable running the native version of csslayout within robolectric internally.
Reviewed By: lucasr
Differential Revision: D3960840
fbshipit-source-id: 08a45f7299b04f70f643b0c9b95da13f90690dd8
Summary:
- Define CSS_ASSERT_FAIL_ENABLED for P/Invoke (Visual Studio project already has it)
- Pass managed delegate pointer to unmanaged side via P/Invoke.
- CSSAssertFail will call the managed delegate when assert failed.
- The delegate will throw managed exception.
Reviewed By: emilsjolander
Differential Revision: D3982084
fbshipit-source-id: 058a87c10ca89238362be4d8759cc00dd0c9b376
Summary: - Use WeakReference for parent to avoid circular reference although GC will treat it
Reviewed By: emilsjolander
Differential Revision: D3982520
fbshipit-source-id: b0f6764aa4df3da53be51f6cb4fe2994d989afdf
Summary:
- Add CSSNodeGetInstanceCount API to get the number of native instances.
- It makes testing easy.
Reviewed By: emilsjolander
Differential Revision: D3981990
fbshipit-source-id: 98005ae1fc21d4c8802f24030fff9ffb00bd292d
Summary:
- Unused _context GCHandle prevent calling CSSNode destructor.
- CSSNode C# impl will retain children node when calling CSSNodeInsertChild, so the lifetime of C# object is the same as the lifetime of native instance.
Reviewed By: emilsjolander
Differential Revision: D3981697
fbshipit-source-id: 71f0f7be97fd694d27934d7d07deb64ee08b2840
Summary: This diff resolves some differences in behaviour between jni and java css nodes. This ensures certain test cases pass with both implementations.
Reviewed By: lucasr
Differential Revision: D3960755
fbshipit-source-id: 3e13a9435208851a96a619c07625ef2a5402f5ec
Summary: In the libraries where headers symlinks are required, we enable them.
Reviewed By: skotchvail
Differential Revision: D3943274
fbshipit-source-id: c7ec741af020a60bb7c39b10773cea58a33adc3e
Summary: Its very usefull to be able to run valgrind on the tests and benchmarks. We were previously not freeing test memory so valgrind output was very messy.
Reviewed By: javache
Differential Revision: D3937493
fbshipit-source-id: 23c6970d7769b081575d39de583ba954fc65a397
Summary:
This PR adds the C# version of the `CSSNode` API calls where it currently has only Java and C versions.
Closes https://github.com/facebook/css-layout/pull/225
Reviewed By: lucasr
Differential Revision: D3936431
Pulled By: emilsjolander
fbshipit-source-id: 689cb359c204c6c52e04e031c66615fb04c001af
Summary: I accidentally turned the logic around when cleaning up some code. This was subtle and only caught a week later by a RN product engineer. This fixes the bug without reverting the rest of the code cleanup.
Reviewed By: lucasr
Differential Revision: D3923635
fbshipit-source-id: bfeb175bb40393be63cafb6a995b22701b87ffec
Summary: Oops, when regexing start->left/right end->left/right I did not take into account flex-start and flex-end. Easiest solution is to regex back flex-left and flex-right into their correct values.
Reviewed By: lucasr
Differential Revision: D3930244
fbshipit-source-id: 20742cbc8e5f23af694e14584c7c3df89526876e
Summary:
Closes#222 for the `csharp` implementation which does not use the `CSSLayoutContext` parameter in the `CalculateLayout` method call.
Closes https://github.com/facebook/css-layout/pull/223
Reviewed By: lucasr
Differential Revision: D3918948
Pulled By: emilsjolander
fbshipit-source-id: 8708e08b226500727e33d131ed880bb7e077c08e
Summary:
@public
This fixes measuring of items in the main axis of a container. Previously items were in a lot of cases measured with UNSPECIFIED instead of AT_MOST. This was to support scrolling containers. The correct way to handle scrolling containers is to instead provide them with their own overflow value to activate this behavior. This is also similar to how the web works.
This is a breaking change. Most of your layouts will continue to function as before however some of them might not. Typically this is due to having a `flex: 1` style where it is currently a no-op due to being measured with an undefined size but after this change it may collapse your component to take zero size due to the implicit `flexBasis: 0` now being correctly treated. Removing the bad `flex: 1` style or changing it to `flexGrow: 1` should solve most if not all layout issues your see after this diff.
Reviewed By: majak
Differential Revision: D3876927
fbshipit-source-id: 81ea1c9d6574dd4564a3333f1b3617cf84b4022f
Summary:
This version of the css-layout project includes support for .NET projects. Up in the air is how many configurations of .NET projects we allow for, such as Portable Class Libraries, Universal Windows Platform, .NET Core, etc. Still needs integration with Buck.
Closes https://github.com/facebook/css-layout/pull/220
Reviewed By: lucasr
Differential Revision: D3909367
Pulled By: emilsjolander
fbshipit-source-id: aaaa9c4ff2d3452649f256c3268cf873cf33a0b9
Summary: Add tests to check that measure modes are set correctly.
Reviewed By: lucasr
Differential Revision: D3856585
fbshipit-source-id: 421b368d2d2cbca1d2ba4d58d850836cb22128ac
Summary:
@public
Introduce `overflow:scroll` so that scrolling can be implemented without the current overflow:visible hackiness. Currently we use AT_MOST to measure in the cross axis but not in the main axis. This was done to enable scrolling containers where children are not constraint in the main axis by their parent. This caused problems for non-scrolling containers though as it meant that their children cannot be measured correctly in the main axis. Introducing `overflow:scroll` fixes this.
Reviewed By: astreet
Differential Revision: D3855801
fbshipit-source-id: 3c365f9e6ef612fd9d9caaaa8c650e9702176e77
Summary: Add tests to check that measure modes are set correctly.
Reviewed By: lucasr
Differential Revision: D3856585
fbshipit-source-id: 5fa407f149b1c081503b4ad7aa5f0203ec5b1cc0
Summary:
@public
Introduce `overflow:scroll` so that scrolling can be implemented without the current overflow:visible hackiness. Currently we use AT_MOST to measure in the cross axis but not in the main axis. This was done to enable scrolling containers where children are not constraint in the main axis by their parent. This caused problems for non-scrolling containers though as it meant that their children cannot be measured correctly in the main axis. Introducing `overflow:scroll` fixes this.
Reviewed By: astreet
Differential Revision: D3855801
fbshipit-source-id: 6077b0bcb68fe5ddd4aa22926acab40ff4d83949
Summary: Now that gentest has been used to cover all flexbox properties as well as some internal behavior I thought it was time to remove the old CSSLayoutTest.cpp. This removes a huge amount of previously regex transpiled code in favor of the new test suite which does more fine grained assertions and uses the public api. Given that RTL support was added to gentest now I feel confident that the new test suite covers all and more cases than the old one.
Reviewed By: lucasr
Differential Revision: D3863095
fbshipit-source-id: a2c4f87cd2263b4cc1fcdec4f2a0964f0696472f
Summary: previously when copying in a test inout into an editor the user of gentest needed to remove the ` * ` prefix. This was annoying so this diff fixes that by removing that from gentest.
Reviewed By: lucasr
Differential Revision: D3862943
fbshipit-source-id: 06bd3ee3fa3f85cc44b6ea1d67cf3e91ed368791
Summary: Make input html easier to read by indenting it and adding a space between children. The code to do this could very well be improved but it works for the current set of inputs.
Reviewed By: lucasr
Differential Revision: D3798087
fbshipit-source-id: 0d50ff276000f14ed078cf5ce2e7560ace285a6a
Summary:
When an absolutely positioned node appeared inside an overflow:hidden
parent, we were limiting its height. This is inconsistent with how
layout behaves on the web.
Closes https://github.com/facebook/css-layout/pull/218
Reviewed By: lucasr
Differential Revision: D3797285
Pulled By: emilsjolander
fbshipit-source-id: 98f98e77aa26edce86b9882c1cac284799b69a27
Summary: Generate tests for border. This required modifying gentest to add the parent clientLeft and clientTop so that border width are accounted for in output.
Reviewed By: lucasr
Differential Revision: D3791286
fbshipit-source-id: 698cc2332a3f4118e1afdfbfd745ba824e8ec3f4
Summary: While adding tests for CSSEdge I found that when setting both horizontal/vertical/all + left/right then left/right were not correctly overriding the others. This is now fixed and validated through added tests
Reviewed By: lucasr
Differential Revision: D3791106
fbshipit-source-id: 3e0c943f94218848a1fbf36e5ae48dbc720ea923
Summary: Previous test for dirty propagation (last test in CSSLayoutTest.cpp) only tested one specific case. This tests much more of the bahavior to ensure that a vital optimization in css-layout is applied correctly.
Reviewed By: lucasr
Differential Revision: D3790968
fbshipit-source-id: af11a5924640cd1d497920cd97549603a9f147cc
Summary: Use fbjni for safer and easier jni bridging. This diff includes all of fbjni as it currently does not live as its own open source project. The code was copied from the react-native open source distribution.
Reviewed By: ritzau
Differential Revision: D3764065
fbshipit-source-id: 7ff566af314dcb5279460c322c476ef6f6ed8131
Summary: Measure caching is a crucial optimization to css-layout which re-uses the output of the measure function if possible. This logic was never covered by tests.
Reviewed By: lucasr
Differential Revision: D3790915
fbshipit-source-id: 7fe6d5ebb1303d3186d24d15e401901bc7c8ecdb
Summary: don't hardcode .so extension. Different platforms use different extensions such as .dll, .so, .dylib
Reviewed By: lucasr
Differential Revision: D3785675
fbshipit-source-id: c326e330741e65a7f5d3cb4e4105894c582a2a12
Summary: Don't want to autoformat tests as they are autogenerated. Also they contain html which we don't want to get limited by line length.
Reviewed By: lucasr
Differential Revision: D3785246
fbshipit-source-id: 3e07b300ad16a1f0de53840e399eea25f4672b58
Summary: Allow adding test name within html through the id of the root element. This makes it much easier to re-generate test files.
Differential Revision: D3771966
fbshipit-source-id: 313e1648dcf4521e7c649f54c4ced2aa3297bf06
Summary: So that it can be reset when Spacing is used outside CSSNode.
Differential Revision: D3763593
fbshipit-source-id: 27436c0dbd292b38cfc98f4cfb8e2d12787b85d6
Summary: Revert changes to flex-basis as it broke some specific layouts. Will update later with a more comprehensive set of tests
Differential Revision: D3776987
fbshipit-source-id: 06bd154a36f895782f45511cd8cf49cc6d7cbe7d
Summary: Generate tests for flex-properties and fix bug where flex basis was not taken into account when parent main dimension was undefined.
Differential Revision: D3771513
fbshipit-source-id: 1b5edc7a28bb26217e8a6d10d1829d9031c3ae2e
Summary: Generate tests for flex wrap. The behavior for how the parents cross dimension is sized based on the children differs between browsers but looking at the spec this is the correct implementation.
Differential Revision: D3771140
fbshipit-source-id: bf144d506834e1d4217222bc2422150884a0be1c
Summary: These props were never tested so I didn't notice the typo until now.
Differential Revision: D3771132
fbshipit-source-id: 9d7c2037195f29b3cac5d21599035edf3b7830ff
Summary: generate absolute layout tests. Also make sure default value for position is relative (#default div is absolutely positioned)
Reviewed By: IanChilds
Differential Revision: D3770947
fbshipit-source-id: 0327b071c0dc1aa4574ded759dcc667768b28f55
Summary: Remove output properties from computed styles as they will be computed to their output values before we can read them. Only include them if they are explicitly set by the user.
Reviewed By: IanChilds
Differential Revision: D3770917
fbshipit-source-id: e55996cf8744073496debea19c36a188d2e5086c
Summary: Make the test cases absolute to ensure left/top are both zero for each layout in the test case.
Reviewed By: IanChilds
Differential Revision: D3770913
fbshipit-source-id: c3085c2f8709b52fde0af7f47e1417252997b610
Summary: Implement flexShrink flexGrow and flexBasis in java as well because it will take a bit until the java code is removed
Reviewed By: lucasr
Differential Revision: D3753231
fbshipit-source-id: ea41d887cd99d1f03d2bc876a2fd7141dbe48320
Summary: Benchmarks were broken by const diff leaving in some code which should not have changed. This was not caught earlier due to benchmarks only being run on travis.
Reviewed By: IanChilds
Differential Revision: D3751151
fbshipit-source-id: 08207ce7ad584d4681a27ec0727bbfdbc1198d05
Summary: Use const where possible. This does not use const for all variables as that would require too much refactoring for one diff. It does however use const where currently possible as well as does some small refactoring to enable const usage in more locations. Striving for 100% const usage leads to code with is easier to reason about as a reference will always reference the same value. The compiler will also assist if you accidentally override a reference.
Reviewed By: IanChilds
Differential Revision: D3741999
fbshipit-source-id: 1ba7da5784c3047f2d4c03746890192f724aa65e
Summary: Remove unnecessary function calls which just caused indirection and thus confusion. These were an artifact of the regex transpilation.
Reviewed By: IanChilds
Differential Revision: D3741988
fbshipit-source-id: fdb31dc45a478508b41c522f0e1b3ef842971b50
Summary: The concept of default padding was confusing and only used by react-native android. Makes more sense to let them manage this themselve.
Reviewed By: foghina
Differential Revision: D3709574
fbshipit-source-id: 6e0277bd97407a5c642d742f93ca2ac70d7307da
Summary: When moving over java code to JNI we must make sure things like spacing behave the same. This introduces the same concepts to the C code.
Reviewed By: lexs
Differential Revision: D3728742
fbshipit-source-id: aa19400880afa49664f7bde72b1df45314e699bb
Summary: When adding CSSEdge I kinda forgot we had CSSPosition. I should have just refactor renamed CSSPosition and added some fields. Well this cleans that up.
Reviewed By: IanChilds
Differential Revision: D3728740
fbshipit-source-id: 19dc817a637b80d1f6df8d76982feb2e1fb2705a
Summary: Pointers are 64 bit on 64 bit platforms so using an int might truncate the pointer. Using longs supports 32 bit platforms as well.
Reviewed By: davidaurelio
Differential Revision: D3722479
fbshipit-source-id: c132f24c92c8476b328713861ad30670a43040c4
Summary: JNI code isn't covered by tests yet so I accidentally passed the spacing constant as a pointer value. oops.
Differential Revision: D3722391
fbshipit-source-id: 9adaf7b80d7bad93887a122c10eb06159a5189c2
Summary: We don't run this file internally so this was not caught earlier. Must of course include the function before using it.
Reviewed By: lucasr
Differential Revision: D3717080
fbshipit-source-id: 15c070b6b18bfa4fdd495e8c3b1b5ae62cb09824
Summary:
marginLeft(node, margin) -> margin(node, CSSEdgeLeft, margin)
This reduces the api surface of CSSLayout as well as puts the api more in line with the java version. This also adds support for CSSEdgeAll which java has had support for for a while. This also open up the possibility of doing margin(node, CSSEdgeLeft | CSSEdgeTop, margin) in the future.
Reviewed By: lucasr
Differential Revision: D3715201
fbshipit-source-id: ea81ed426f0f7853bb542355c01fc16ae4360238
Summary: We don't want to format files in lib/ for example. For some reason java/jni and tests/CSSLayoutTestUtils folders were previously ignored. This change formats those folders as well.
Reviewed By: lucasr
Differential Revision: D3715203
fbshipit-source-id: 37bcbd36bcf8535cfca73d6a806ab0f1d097dde7
Summary: Previously format script had to be run from the root directory. With this change it can be run from anywhere
Reviewed By: lucasr
Differential Revision: D3715186
fbshipit-source-id: a46bc0b49aa32f0860bb3e3097ae7b08bdccbf2e
Summary: Add header to generated code so that code can easily be re-generated in case test generation is improved in the future.
Reviewed By: lucasr
Differential Revision: D3715181
fbshipit-source-id: 593baa691c2d7c7f171c6673898fb8a2ecf0e008
Summary: Modify test generation script to be able to generate multiple test cases
Reviewed By: lucasr
Differential Revision: D3714577
fbshipit-source-id: d2bc2155712f946c5a24231a9532d2acc097524c
Summary: Add support for flex-grow, flex-shrink, and flex-basis properties. The flex property behavior is preserved for backwards compatibility.
Reviewed By: lucasr
Differential Revision: D3714520
fbshipit-source-id: 80d3a9a1e2b6f74b863bbe22357f2c9865fa290e
Summary: Spent a couple hours customizing the clang-format rules to better match the desired code style.
Reviewed By: IanChilds
Differential Revision: D3714510
fbshipit-source-id: f6d0436346416aab023aacbedd70ea189e583e8d
Summary: allow_unsafe_import was added to internal builds. add no-op version for open source
Reviewed By: IanChilds
Differential Revision: D3714497
fbshipit-source-id: fac9710726fd981d442c84c5b5879a94b955d102
Summary:
Enable build file sandboxing in fbandroid.
Importing modules in build files that are not whitelisted will be blocked, this can be overriden by using
with allow_unsafe_import():
import foo
`import os` and `import os.path` will not be blocked and will import a safe version of `os` module instead (functions not accessing the file system like `os.path.join()` will be accessible), full `os` module can be imported using `allow_unsafe_import()`
Reviewed By: plamenko
Differential Revision: D3649817
fbshipit-source-id: 3e6a3ab9c4c6a56a99ca7adf599323143a5844f4
Summary: Mean was previously printed just because it was the quickest. Median is a better measurement and we need to include stddev for the sake of comparison against previous diff.
Differential Revision: D3709165
fbshipit-source-id: 67aff0877192143df82a9c24cbedb1f49616eec7
Summary: A .so file is only needed for the JNI target. The main library can be static.
Differential Revision: D3703897
fbshipit-source-id: b2efb98a6ae4488e6107c736c263cad35ef7c4fe
Summary:
Add first version of test generation script. Currently works for most layouts and styles. Probably has a bunch of broken edge-case.
Usage:
$ gentest/gentest.sh
<Enter HTML with inline styles> e.g. <div style="width: 100px; height: 100px;"></div>
Open chrome dev tools console tab.
Copy code from console into file and save.
Run buck test //:CSSLayout
Differential Revision: D3697812
fbshipit-source-id: e6809f95bf6782e7e2cc47b9cdd3a25a13163c5c
Summary: Modern C allows us to document this kind of thing using C and not comments.
Reviewed By: adamjernst
Differential Revision: D3698569
fbshipit-source-id: c92b18540140662979cf001aeedaa76504c6a3ac
Summary: The previous repetition count did not scale to many benchmarks. Also add more benchmarks
Reviewed By: adamjernst
Differential Revision: D3697280
fbshipit-source-id: 56fe424f36936445f31d6e9fa080abbdd816d32d
Summary: Building on osx machines makes things a lot easier.
Differential Revision: D3693987
fbshipit-source-id: f6e2599f99a3fd4ac6fb2a6efd5563074da707d0
Summary: .buckversion is not needed in open source and we have no good way to keep it updated.
Differential Revision: D3696643
fbshipit-source-id: 3ce47a605730935e40f3cd3256a8ec3bd1f7b396
Summary: This means we don't need to use buck fetch. soloader ships as an aar and does not get updated often.
Differential Revision: D3696638
fbshipit-source-id: 57fc7c24067ee833f47ed7c34b927a0d84e20200
Summary: Use spacing for position in public api. This was already the case internally
Differential Revision: D3690235
fbshipit-source-id: 4c04952e6ded32fd5fbfdccf63736cf025ae470e
Summary:
As they're were not available yet.
Emil, I'm going to wait for your diffs to land before pushing this to
avoid disruptions on your side.
Differential Revision: D3669177
fbshipit-source-id: b06f382cb89546e817a2475298cf2cad17d95a2c
Summary:
Consistently namespace all of css-layout's public C API with "CSS". The only function that needed to be renamed was isUndefined, which I renamed to CSSValueIsUndefined.
Fixes#210.
Closes https://github.com/facebook/css-layout/pull/211
Reviewed By: lucasr
Differential Revision: D3674922
Pulled By: emilsjolander
fbshipit-source-id: 1752f477bde45586db112fe2654d0404cc52e1d1
Summary: This code used to be auto generated. Let's let clang-format clean up some stuff for us.
Reviewed By: lucasr
Differential Revision: D3662225
fbshipit-source-id: ddd4064cbf9be21ca6a97001ace1b56b4314c86f
Summary: The C version already has this ability via the same name 'context'. This can be used to attach arbitrary data about your view hierarchy to a CSSNode. Previously this could only be done in java via subclassing CSSNode.
Reviewed By: lucasr
Differential Revision: D3662065
fbshipit-source-id: 560a768092f17381e99b349d08bd4a8b365541be
Summary: To make the library easier to get started with we don't want to force people to use SoLoader. If SoLoader is not initialized we will fall back to the standard System.loadLibrary() method.
Reviewed By: lucasr
Differential Revision: D3661990
fbshipit-source-id: f2003577aa3d2f89ec579b6f889fdfb684110b60
Summary: This caches the class and method id references between calls. The class lookup is done once per method still but I think that is ok for now as the code becomes somewhat cleaner and more self contained.
Reviewed By: lucasr
Differential Revision: D3661989
fbshipit-source-id: 68d4557364bb8957400aefb2603c2e46424ccec3
Summary: Add jni bindings for csslayout. First step in many of removing LayoutEngine.java and performing all layout in native.
Reviewed By: lucasr
Differential Revision: D3648793
fbshipit-source-id: d0e696e196fa7c63109c9117a65645ca3d6c9c00
Summary: Anyone importing this header would have abort() redefined to nothing. That's not good. Fix mistake by defining a CSS_ABORT() macro instead.
Differential Revision: D3661871
fbshipit-source-id: 14a9d076299b4f21d17a2bed68aa30b796c438a5
Summary: assert.h assertion gets stripped from builds. I don't want these assertions to be stripped so implement a custom assert macro. This also allows the assertion to be documented with a message.
Reviewed By: javache
Differential Revision: D3648805
fbshipit-source-id: a6bf1bb55e1e0ee37284647ab76d66f3956a66c0
Summary: #pragma once is widely supported and is a lot harder to get wrong than #ifdef include guards.
Reviewed By: lucasr
Differential Revision: D3648895
fbshipit-source-id: faf42cda82764adaf41cf3f3f9109d48aea203fe
Summary: Java instructions were missing from the readme. Add a quick note about how to run tests in java.
Reviewed By: lucasr
Differential Revision: D3648981
fbshipit-source-id: d9009a60bb1bb0837722f914981ef4e31f0adb68
Summary: stdint.h defines the modern standard c types which have a fixed memory size. This makes the program run more predictably as well as removing the need to ugly double work types such as `unsigned int` or `long long`.
Reviewed By: lucasr
Differential Revision: D3649096
fbshipit-source-id: dc9fc8861c3106494c5d00d6ac337da50a4c945b
Summary: Implement some very basic benchmarking infra. We need benchmarks in css-layout and I want to add something now so that others have the option to follow an example when implementing a benchmark.
Reviewed By: lucasr
Differential Revision: D3648889
fbshipit-source-id: 60b93c6e5ed027a37195a9a5d86e681e3e79a5b9
Summary: This moves the api in line with the java api. hasNewLayout makes for sense than shouldUpdate because the API is not telling css layout to update but is instead just a marker for the user of the API to know if there has been a new layout since last time it checked.
Reviewed By: majak
Differential Revision: D3613695
fbshipit-source-id: 4e16e8d4de90660a09d6e1d3a43c6c5e89349993
Summary:
@public The make current RCTShadowView support RTL layout.
1 Change all left/right to start/end for margin, padding, boarder and position
2 Calculate position in the same way as margin, padding and boarder
Reviewed By: fkgozali
Differential Revision: D3619292
fbshipit-source-id: eaaa6faeee93c964d59bb6f498d89effc09ed567
Summary: @public The new CSSLayout have a wrong calculate for the getRelativePosition. So use the getLeadingPosition will get 0 instead of return undefined. Fix it with using isLeadingPosDefined.
Reviewed By: fkgozali
Differential Revision: D3640799
fbshipit-source-id: 50d3bd2ea4c0d8bf96ba34297425ba269b0535cd
Summary: The test case CSSLayoutTest/test_layout_node_with_bottom has some problem. I can't find a way to fix it without get the screen size. I decided to remove it first. If we could find a better way to right this test case. We can add it again.
Reviewed By: fkgozali
Differential Revision: D3629662
fbshipit-source-id: 303f81a74919e5d3bf037e2809e1345a554a7009
Summary:
@public The current CSSLayout can't support RTL because wrong calculation for absolute position.
This change is mainly to fix the issue: https://github.com/facebook/css-layout/issues/197
Three main problems I fixed:
1. Calculate the position in the same way as margin, boarder, and padding. So that to fix the absolute problem.
2. Fix one wrong calculation for leading value when we only know the trailing value. It was hard code for the LTR situation. Now I changed it to depends on the main Axis.
3. Expose getter and setter function for RN to read layout direction and start/end position value.
Reviewed By: fkgozali
Differential Revision: D3616949
fbshipit-source-id: ae7a47cc0a5d02b42b95f87232be51ab144056d9
Summary: The test case CSSLayoutTest/test_layout_node_with_bottom has some problem. I can't find a way to fix it without get the screen size. I decided to remove it first. If we could find a better way to right this test case. We can add it again.
Reviewed By: fkgozali
Differential Revision: D3629662
fbshipit-source-id: 62d6cd3827d20ae670af55d1c072bd9645a701b9
Summary: Update readme with info about building and github markdown syntax
Differential Revision: D3613284
fbshipit-source-id: 1f57009ccf02a48fe100f675ce08503e15cb6c22
We already did this optimization when there wasn't any
available horizontal space. Now we're covering the
vertical space case as well.
This optimization assumes that, for a node with a
measure function, if there isn't any available
horizontal or vertical space, then we don't need to
measure the node and can assume that the node is 0x0.
Introduced heuristics that enable css-layout to avoid
calling measure functions under a number of conditions.
This enables us to save time by skipping unnecessary
measurements.
We found a case where a flexible item with a max width that was supposed
to be centered was positioned in the wrong location.
The problem was with our 2 pass approach for sizing flexible items with
a min/max width/height. Items sized in the first pass were being double
counted when calculating the remainingFreeSpace. Specifically, their
sizes were being subtracted from remainingFreeSpace in both the first
and second passes.
I also noticed a second unrelated bug. We weren't correctly calculating
deltaFreeSpace in the first pass. When calculating deltaFreeSpace, we
need to take into account the flex basis like we do in the second pass.
Consequently, in the first pass I changed this:
deltaFreeSpace -= boundMainSize;
To this:
deltaFreeSpace -= boundMainSize - childFlexBasis;
The problem there was that we'd end up double counting childFlexBasis
in the remainingFreeSpace.
The primary goals of this change are:
- Better conformance to the W3C flexbox standard (https://www.w3.org/TR/css-flexbox-1/)
and a clear articulation of the areas where it deviates from the spec.
- Support for flex-shrink.
- Conformance with layout effects of "overflow: hidden".
Specifically, here are the limitations of this implementation as compared to the W3C
flexbox standard (this is also documented in Layout.js):
- Display property is always assumed to be 'flex' except for Text nodes, which
are assumed to be 'inline-flex'.
- The 'zIndex' property (or any form of z ordering) is not supported. Nodes are
stacked in document order.
- The 'order' property is not supported. The order of flex items is always defined
by document order.
- The 'visibility' property is always assumed to be 'visible'. Values of 'collapse'
and 'hidden' are not supported.
- The 'wrap' property supports only 'nowrap' (which is the default) or 'wrap'. The
rarely-used 'wrap-reverse' is not supported.
- Rather than allowing arbitrary combinations of flexGrow, flexShrink and
flexBasis, this algorithm supports only the three most common combinations:
- flex: 0 is equiavlent to flex: 0 0 auto
- flex: n (where n is a positive value) is equivalent to flex: n 0 0
- flex: -1 (or any negative value) is equivalent to flex: 0 1 auto
- Margins cannot be specified as 'auto'. They must be specified in terms of pixel
values, and the default value is 0.
- The 'baseline' value is not supported for alignItems and alignSelf properties.
- Values of width, maxWidth, minWidth, height, maxHeight and minHeight must be
specified as pixel values, not as percentages.
- There is no support for calculation of dimensions based on intrinsic aspect ratios
(e.g. images).
- There is no support for forced breaks.
- It does not support vertical inline directions (top-to-bottom or bottom-to-top text).
And here is how the implementation deviates from the standard (this is also documented in
Layout.js):
- Section 4.5 of the spec indicates that all flex items have a default minimum
main size. For text blocks, for example, this is the width of the widest word.
Calculating the minimum width is expensive, so we forego it and assume a default
minimum main size of 0.
- Min/Max sizes in the main axis are not honored when resolving flexible lengths.
- The spec indicates that the default value for 'flexDirection' is 'row', but
the algorithm below assumes a default of 'column'.
This diff:
* adds height as another parameter passed to the measure function, computed the same way width is
* adds tests for this extension, which has involved adding a new measure function to all of js, c, java and c# tests
also, on line 134, I could be wrong, but be wary of this sentence: "No C implementation of this function is provided in provided..." Perhaps this is a mistake.
thanks for all the awesome code!
8f6a96adbc added a test in isDimDefined that checks if `value > 0.0`, but unfortunately, it did not faithfully port the JavaScript version which is `value >= 0.0`. Sadly, no test covered this so it went unnoticed.
It turns the spacing resolution in Java is fairly expensive right now
because it doesn't a bunch of unnecessary checks in the array,
especially when the Spacing instance doesn't have any values set on it.
This diff changes Spacing to store the state of the defined values in a
bitwise flag so that padding/border/margin queries are a lot faster
during layout calculations. This gives us as extra 20% performance win
in my local benchmarks on Android
Unfortunately, Java doesn't have any build-time inlining solution and
method invocations do have a big performance impact on Android. This
changes Java's transpiler to inline almost all internal methods at build
time. This gives us a 30% performance win in my local benchmarks.
There's a drawback from moving code to the transpiler but I think this
is worth it (given the massive perf wins here) and the inlined methods
are fairly simple.
Change the initial line loop to opportunistically position children in
the in container with simple stacking params i.e. vertical/horizontal
stacking on non-flexible STRETCH/FLEX_START aligned. This allows us to
skip the main and cross axis loops (Loop C and D, respectively)
partially and even completely in many common scenarios.
In my benchamrks, this gives us about ~15% performance win in many
setups.
We were traversing all children to only perform calculations/changes to
flexible children in order to avoid new allocations during layout. This
diff ensures we only visit flexible children during layout calculations
if any are present. We accomplish this by keeping a private linked list
of flexible children.
There's no need to go through all absolute children at the end of the
layout calculation if the node at hand doesn't have any. This also
ensures only absolutely positioned children are traversed in the final
loop.
There's no need to go through all children before starting the main line loop
as we'll visit all children in the former loop anyway. This diff merges the
pre-fill loop into the main line one to avoid an extraneous traversal on the
node's children.
There's no need to set the trailing position on left-to-right layouts
as the nodes will already have what we need (x, y, width, and height).
This means we still have an extra cost for reversed layout directions
but they are not as common as LTR ones.
Store immutable values from the node being laid out to avoid unnecessary
method invocations during layout calculation. This gives us a 3%-5%
performance boost in my benchmarks on Android.
Method invocations are not entirely free on Android. Change the
generated Java code to use the same array-based approach used in
JS and C to compute dimensions, positions, etc instead of relying
too heavily on method invovations. As a bonus, the Java transpiler
becomes a lot simpler because the code is more analogous to the C
counterpart.
In my local benchmarks this change gives us a major performance
boost on Android (between 15% and 30%) depending on the device
and the runtime (Dalvik|Art).
2015-09-08 15:15:46 +01:00
614 changed files with 77265 additions and 27065 deletions
This project implements a subset of CSS including flexbox and the box model using pure JavaScript, then transpiled to C and Java. The goal is to have a small standalone library to layout elements. It doesn't rely on the DOM at all.
## 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 Java, C and JavaScript version of the code is available via [npm](https://www.npmjs.com/package/css-layout) or directly from the `dist` folder of this repo. The JavaScript version is also available via [cdnjs](https://cdnjs.com/libraries/css-layout).
## 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`.
In order to make sure that the code is correct, it is developed in JavaScript using TDD where each commit adds a unit test and the associated code to make it work. All the unit tests are tested against Chrome's implementation of CSS.
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`.
The JavaScript version has been implemented in a way that can be easily transpiled to C and Java via regexes. The layout function doesn't do any allocation nor uses any of the dynamic aspect of JavaScript. The tests are also transpiled to make sure that the implementations are correct everywhere.
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.
- takes a tree of nodes: `{ style: { ... }, children: [ nodes ] }`
- computes the layout and writes it back to the node tree.
For example,
```javascript
// create an initial tree of nodes
varnodeTree={
"style":{
"padding":50
},
"children":[
{
"style":{
"padding":10,
"alignSelf":"stretch"
}
}
]
};
// compute the layout
computeLayout(nodeTree);
// the layout information is written back to the node tree, with
// each node now having a layout property:
// JSON.stringify(nodeTree, null, 2);
{
"style":{
"padding":50
},
"children":[
{
"style":{
"padding":10,
"alignSelf":"stretch"
},
"layout":{
"width":20,
"height":20,
"top":50,
"left":50,
"right":50,
"bottom":50,
"direction":"ltr"
},
"children":[],
"lineIndex":0
}
],
"layout":{
"width":120,
"height":120,
"top":0,
"left":0,
"right":0,
"bottom":0,
"direction":"ltr"
}
}
```
```
Supported Attributes
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.
--------------------
Name | Value
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.
----:|------
width, height | positive number
minWidth, minHeight | positive number
maxWidth, maxHeight | positive number
left, right, top, bottom | number
margin, marginLeft, marginRight, marginTop, marginBottom | number
padding, paddingLeft, paddingRight, paddingTop, paddingBottom | positive number
borderWidth, borderLeftWidth, borderRightWidth, borderTopWidth, borderBottomWidth | positive number
-`inherit` value is not implemented because it's a way to disambiguate between multiple colliding rules. This should be done in a pre-processing step, not in the actual layout algorithm.
### .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`.
## 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
Default values
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.
--------------
Since we are only using flexbox, we can use defaults that are much more sensible. This is the configuration to use in order to get the same behavior using the DOM and CSS. You can try those default settings with 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:0solidblack;
margin:0;
padding: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`.
Development
-----------
The core logic resides with `Layout.js`, which is transpiled into equivalent C and Java implementations.
The JavaScript build process is managed via Grunt. The build performs linting, runs the tests against Chrome, transpiles and packages the code (JavaScript and Java) into the `dist` folder. For JavaScript, the build output uses the Universal Module Format (UMD) so that it can be used via AMD / RequireJS, CommonJS or included directly into an HTML page.
While developing you can just run the lint / Chrome-based tests a follows:
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.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.'
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.
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";
Some files were not shown because too many files have changed in this diff
Show More
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.