Compare commits

...

1081 Commits

Author SHA1 Message Date
Pascal Hartig
adb1b11055 1.8.0
Summary: New release.

Reviewed By: marco-cova

Differential Revision: D7550852

fbshipit-source-id: eac5662179daa88d9d62c55566b3a31428c4117a
2018-04-09 02:41:21 -07:00
David Vacca
2e234473ca [yoga re-add assertion to check for owner reference before adding child.
Summary: this diff re-add the assertion to check for owner reference before adding child that was removed by mistake in previous diff

Reviewed By: emilsjolander

Differential Revision: D7495417

fbshipit-source-id: b81174aeea3f2796d76ccdae4a8eddd0beace0aa
2018-04-04 10:57:52 -07:00
Lukas Wöhrl
6b08db68bb Fix compilation on MSVC by moving YGConfig to C++
Summary:
This PR fixes the compilation on MSVC. I moved the `YGConfig` creation to a C++ constructor.

Addionally it removes the "dot" notation on `YGValue`, I didn't want to change that type to a C++ constructor, because I think this will break the ABI.
Closes https://github.com/facebook/yoga/pull/746

Differential Revision: D7498141

Pulled By: emilsjolander

fbshipit-source-id: 5f5308ff838dcd803065785ddc08b2404524acb9
2018-04-04 09:55:45 -07:00
Pritesh Nandgaonkar
9550126f76 clean up experimental setup and keep using ffast-math flag
Summary: Remove experimental setup of fast-math and add `-ffast-math` as a compiler flag for yoga.

Reviewed By: emilsjolander

Differential Revision: D7414228

fbshipit-source-id: 320e1b1953f6af867b13e617af7872eb8999160e
2018-04-04 08:29:43 -07:00
Pritesh Nandgaonkar
bad262b961 Change the return type of getMarginForAxis to YGFloatOptional
Summary: Change the return type of getMarginForAxis to YGFloatOptional

Reviewed By: emilsjolander

Differential Revision: D7350337

fbshipit-source-id: dd1ee2fcd295ccd14f7d414ab0c24090b24e91e0
2018-04-04 08:29:43 -07:00
Pritesh Nandgaonkar
3c6c10075a Change the return type of getTrailingMargin to YGFloatOptional
Summary: Change the return type of getTrailingMargin to YGFloatOptional

Reviewed By: emilsjolander

Differential Revision: D7350221

fbshipit-source-id: 61a67364c1975ec6dd1883bc2cb4968b830c73df
2018-04-04 08:29:43 -07:00
Pritesh Nandgaonkar
6a77a6939e Changed the return type of getLeadingMargin to YGFloatOptional
Summary: Changed the return type of getLeadingMargin to YGFloatOptional

Reviewed By: emilsjolander

Differential Revision: D7349907

fbshipit-source-id: b20894fbc33fd5b29a28f3c9174d1b5f406774ab
2018-04-04 08:29:43 -07:00
Pritesh Nandgaonkar
b725a4a140 Refactored relativePosition private method to YGFloatOptional return type
Summary: Refactored relativePosition private method to YGFloatOptional return type

Reviewed By: emilsjolander

Differential Revision: D7344939

fbshipit-source-id: 72443d38426a211d3e84be814e6a61baf4d26703
2018-04-04 08:29:43 -07:00
Pritesh Nandgaonkar
2b714a5b5d Change the type of getTrailingPosition to YGFloatOptional
Summary: Change the type of getTrailingPosition to YGFloatOptional

Reviewed By: emilsjolander

Differential Revision: D7344710

fbshipit-source-id: eb4c422b6e0f55d90b083221aa8ff1ab797d58a8
2018-04-04 08:29:43 -07:00
Pritesh Nandgaonkar
572546088f Changed the type of return value of getLeadingPosition to YGFloatOptional
Summary: Changed the type of return value of getLeadingPosition to YGFloatOptional

Reviewed By: emilsjolander

Differential Revision: D7344367

fbshipit-source-id: 0f5a667ca357b2ce056c86763aa3e9e4c54b82f0
2018-04-04 08:29:43 -07:00
Pritesh Nandgaonkar
5b109578d3 Changed the type of computedFlexBasis to YGFloatOptional in YGLayout
Summary: Changed the type of computedFlexBasis to YGFloatOptional in YGLayout

Reviewed By: emilsjolander

Differential Revision: D7340413

fbshipit-source-id: 39247b2b582a682e602f49f58b4bbd2bf0c995af
2018-04-04 08:29:43 -07:00
Pritesh Nandgaonkar
77b720f9a5 Fixed types of getLeadingPaddingAndBorder and getTrailingPaddingAndBorder to YGFloatOptional
Summary: Fixed types of getLeadingPaddingAndBorder and getTrailingPaddingAndBorder to YGFloatOptional

Reviewed By: emilsjolander

Differential Revision: D7339998

fbshipit-source-id: aa24335c2db1cd895b9711214b72195add718c32
2018-04-04 08:29:43 -07:00
Pritesh Nandgaonkar
de954eb9cc Changed the return type of trailing padding to YGFloatOptional
Summary: Changed the return type of trailing padding to YGFloatOptional

Reviewed By: emilsjolander

Differential Revision: D7339712

fbshipit-source-id: 483c5886838c14b17cb731c81abb9fc80f519956
2018-04-04 08:29:42 -07:00
Pritesh Nandgaonkar
3e322e60e4 Updated the implementation of leading padding
Summary: Changed the arguments for the getter of leading padding to avoid copies. Added an assetion in getter of leading padding, as padding would always be defined even in the case when the user has not explicitly defined the value. In these cases it would take the default value of 0. So changing the type of `getLayoutPadding` to `YGFloatOptional`, doesn't make sense.

Reviewed By: emilsjolander

Differential Revision: D7336690

fbshipit-source-id: b2a2f010026f26fc2cc9fb35ad921da8f7017c9f
2018-04-04 08:29:42 -07:00
Pritesh Nandgaonkar
a3642541d0 Make the return type of YGNodeBoundAxisWithinMinAndMax to YGFloatOptional
Summary: Make the return type of YGNodeBoundAxisWithinMinAndMax to YGFloatOptional

Reviewed By: emilsjolander

Differential Revision: D7323382

fbshipit-source-id: 8e3eb4f3744b5f3f9e2b353f56184905f7557191
2018-04-04 08:29:42 -07:00
Pritesh Nandgaonkar
bb139d3f91 Remove the use of YGUnwrapOptional from YGConstrainedMaxSizeForMode
Summary: Remove the use of YGUnwrapOptional from YGConstrainedMaxSizeForMode

Reviewed By: emilsjolander

Differential Revision: D7322743

fbshipit-source-id: d825c60bcdc9ecdc0c784a215dc6b1b8a7a7860e
2018-04-04 08:29:42 -07:00
Pritesh Nandgaonkar
08743a42e2 Made the acccessors method to return const references
Summary: Made the acccessors method to return const references

Reviewed By: emilsjolander

Differential Revision: D7321801

fbshipit-source-id: 9fc4da724bc2f58a0d95824ca3c0b5bf1690bccf
2018-04-04 08:29:42 -07:00
Lukas Wöhrl
cb6e76973d Fix float type mismatch on endOfLineIndex and inside rounding
Summary:
This PR fixes a type mismatch on `endOfLineIndex` where it should be of type `uint32_t` while it is of type `float`

Additonally it fixes some `double` casting in the rounding methods.
Closes https://github.com/facebook/yoga/pull/745

Differential Revision: D7494519

Pulled By: emilsjolander

fbshipit-source-id: 30a86574ce163458a6888f61a902d0640c1874fb
2018-04-04 07:04:23 -07:00
Pritesh Nandgaonkar
4b760fa9bc Changed the return type of YGResolveValueMargin to YGFloatOptional
Summary: Changed the return type of YGResolveValueMargin to YGFloatOptional

Reviewed By: emilsjolander

Differential Revision: D7304090

fbshipit-source-id: cbec03a9367cf34976d083ad475d4da0b736e6d2
2018-04-03 15:12:07 -07:00
Pritesh Nandgaonkar
5730be093e Move equaltiy function from utils to an operator on YGFloatOptional
Summary: Move equaltiy function from utils to an operator on YGFloatOptional

Reviewed By: emilsjolander

Differential Revision: D7303460

fbshipit-source-id: 41ec0076ace621ec1a5bdbab00b72eea57780fff
2018-04-03 15:12:05 -07:00
Pritesh Nandgaonkar
d85e2ee9c3 Change the type of aspect Ratio to YGFloatOptional
Summary: Change the type of aspect Ratio to YGFloatOptional

Reviewed By: emilsjolander

Differential Revision: D7302651

fbshipit-source-id: 53e3b4c9627207a379f927b1f3485e36a9c70601
2018-04-03 15:12:02 -07:00
Pritesh Nandgaonkar
fe433b012f Remove the usage of YGUndefined for kYGValueAuto and fix setter and getter of dimensions
Summary: Removes the use of YGUndefined from kYGValueAuto. Also fixed the setter and getter of dimensions. This diff also fixes a typo

Reviewed By: emilsjolander

Differential Revision: D7302453

fbshipit-source-id: e002a1ddd75bfc6fe142a7275e7913c064972e16
2018-04-03 15:11:58 -07:00
David Vacca
5e3ffb39a2 Extend Yoga to be able clone Yoga Node with new children
Summary:
This diff includes the following changes:

1 ) I extended the Java implementation of YogaNode to be able to get a full copy of a YogaNode object without copying the List of children of the original YogaNode. In other words, the new copy of the YogaNode will have the same data of the original YogaNode, but with an empty list of children.

2 ) We created a new method in Yoga.cpp called YGNodeInsertSharedChild. This new method is going to be used by Fabric in order to temporarily share a YogaNode between two "Yoga Trees" (the "current Yoga" tree and a partial "clone of the current Yoga tree"). We exposed this new functionality in the java implementation of Yoga (method addSharedChildAt)

I'm including sebmarkbage for more context.

Reviewed By: emilsjolander

Differential Revision: D7245421

fbshipit-source-id: 72578c8261f29e4a12fc6c72a91f2f891cd58d48
2018-04-01 18:35:13 -07:00
David Vacca
f0edefdbb7 Rename YogaNode.parent -> YogaNode.owner
Summary:
In the persistent version of Yoga, a YogaNode can be shared between two YogaTrees, that means that a YogaNode could have more than one Parent at one point in time. That's why the concept of Parent of a YogaNode is not a 1-1 relationship anymore.
This diff changes the semantic of Parent of a YogaNode to Owner of a Yoga Node. CC sebmarkbage and priteshrnandgaonkar for more context.

Technically this diff renames the field YogaNode.parent to YogaNode.owner (and every internal field, Getter and Setter that is related to parent)

Note that as part of this diff I also modified the CSSLayoutDEPRECATED version of Yoga in order to keep compatibility with the C++ implementation.

Reviewed By: priteshrnandgaonkar

Differential Revision: D7352778

fbshipit-source-id: dcf1af5e72bfc3063b5c4bda197d7952a9194768
2018-04-01 18:35:13 -07:00
David Vacca
17901ea5c2 Refactor cloning of YogaNode
Summary: see Test Plan

Reviewed By: priteshrnandgaonkar

Differential Revision: D7339832

fbshipit-source-id: 2de6f47ae7601ac083d3b9fbe10ffaf6307ae760
2018-04-01 18:35:13 -07:00
Jonathan Dann
187fc54596 Add YGNodeSetChildren(), YGNodeTraversePreOrder()
Summary:
We had functions for inserting/removing a specific child, but not for simply replacing the child set with another list.

`YGNodeSetChildren()` will unhook child nodes from the parent that don't appear in the new set. We set the disconnected child node layouts to `YGLayout()` b/c that's what the rest of the code does.

`YGTraversePreOrder()` walks the tree and calls a labmda for each node. We could very easily add a post-order traversal and the ability to stop traversal if we ever want, but for now this is an MVP.

Reviewed By: Woody17

Differential Revision: D7360203

fbshipit-source-id: 32df8e1213ead03bc0a026ec4bf453bc799bb9ce
2018-03-25 13:59:44 -07:00
Pritesh Nandgaonkar
c951ad7c7b Push Yoga 1.8.0 to cocoapods
Summary:
Podspec to push yoga 1.8.0 to cocoapods. There is an issue with cocoapods and it fails to lint those projects with C++ in its header, which is the case with yoga too.

Follow this thread https://github.com/CocoaPods/CocoaPods/issues/5152. To make the lint pass, one would have to change `app_target_helper.rb` cocoapod source file in the local machine. Follow my [gist](https://gist.github.com/priteshrnandgaonkar/dcca9639a3bc0a3b9adecae3a2b3b0c4).

I am able to pass the lint, but not able to push the pod in cocoapods as I am not the admin. @[759512522:emilsj], please push it on Cocoapods or give me permission.

Podspec now also exposes public header explicitly.

Reviewed By: gkassabli

Differential Revision: D7375018

fbshipit-source-id: 4e82e1c0b6340c3f8d3b8a96ecadbcb711d4bcd8
2018-03-23 05:33:59 -07:00
Daniel Büchele
9785975f77 add documentation about JS library usage. fixes #733
Summary: Adds an example of how to use yoga from JavaScript to the documentation pages.

Reviewed By: priteshrnandgaonkar

Differential Revision: D7354390

fbshipit-source-id: 0dbc08e5341c06b621acd99bfb9ce7e789b67a45
2018-03-22 04:53:24 -07:00
Jonathan Dann
79281049f2 Mark more member functions as const
Summary: These don't mutate internal state.

Reviewed By: priteshrnandgaonkar

Differential Revision: D7291364

fbshipit-source-id: 2e7d96cfe0345692ffa411bb21a80eb7a859880b
2018-03-21 16:14:21 -07:00
Jonathan Dann
7d2b84aab6 Pass some constructor argumetns by const-reference
Summary: These don't need to be copied twice.

Reviewed By: priteshrnandgaonkar

Differential Revision: D7291363

fbshipit-source-id: 22e606d0b3fa1133d7e0334c8cf9f5f1f32fe64b
2018-03-21 16:14:21 -07:00
Jonathan Dann
cda328fa7e Pass-by-reference in YGNode::setStyle() ::setChildren() ::setLayout()
Summary: These shouldn't be copying the arguments when they pass by value. Instead these only get copied when assigning the value to the member.

Reviewed By: priteshrnandgaonkar

Differential Revision: D7291096

fbshipit-source-id: 7a4025831811d622050adbb5f86608855b94d68e
2018-03-21 16:14:20 -07:00
Pritesh Nandgaonkar
5d7b75a47a Moved YGFloatOptional from C struct to C++ struct
Summary:
Earlier `YGfloatOptional` was plain struct with no privacy around the variables. This diff adds privacy and also enforces checks when one tries to access value of an undefined `YGFloatOptional`

This diff also adds a behaviour in which when a value of an undefined YGFloatOptional is accessed, it will normally terminate(Several cleanup steps are performed).

Reviewed By: emilsjolander

Differential Revision: D7288555

fbshipit-source-id: f61cc92c8fd0d48d2fc1f4d0e6fcef155f19ff8a
2018-03-15 13:04:51 -07:00
Pritesh Nandgaonkar
ae86824636 Fixed a typo and added a test case
Summary: Fixed a typo of flexshrink and added a test case

Reviewed By: emilsjolander

Differential Revision: D7289221

fbshipit-source-id: 48ee9ccfac4adee51d515a366b5a11790f7236fc
2018-03-15 13:04:51 -07:00
Pritesh Nandgaonkar
0dde40ce0b Fix getters and setters if min and max Dimension
Summary: Fix getters and setters of min and max Dimension to behave exactly the same way as it was before fast math changes

Reviewed By: emilsjolander

Differential Revision: D7274807

fbshipit-source-id: 7c1a4c19e8d0552b089a410c3330392cb26a6a47
2018-03-15 07:27:55 -07:00
Pritesh Nandgaonkar
369c9ad12a Fix setter and getter of margin, position, border and padding
Summary:
This diff fixes the setter and getter of margin, position, border and padding to the previous behaviour of yoga, before floatoptional change

This diff also removes the unrequired `#define`

Reviewed By: emilsjolander

Differential Revision: D7274115

fbshipit-source-id: 942a91e6562ef789ae79102a828f397889468fa7
2018-03-15 07:27:55 -07:00
Pritesh Nandgaonkar
cfb9eeca20 Fix failing float max test
Summary:
Earlier YGUndefined was NAN, but recently it was replaced with 10E20 and the check for `isUndefined` is as follows

```
  public static boolean isUndefined(float value) {
    return (Float.compare(value, (float) 10E8) >= 0 || Float.compare(value, (float) -10E8) <= 0);
}
```

If the number is in (-inf, -10E8] and [10E8, inf) then it is considered as undefined. Failing test passed values in this range, so thats why the test was failing. Current diff fixes this issue, and passes a big number which is outside the range as the result of measure function.

Reviewed By: emilsjolander

Differential Revision: D7272325

fbshipit-source-id: 81a77117c65c5dc0cec920f50f0735ec0a7433d1
2018-03-14 09:21:15 -07:00
Pritesh Nandgaonkar
3dfb68887d Expose layout diffing flag to java
Summary:
This diff exposes `shouldDiffLayoutWithoutLegacyStretchBehaviour` from YGConfig and `doesLegacyStretchFlagAffectsLayout` from YGLayout to YogaConfig and YogaNode respectively

Also added a positive test case. Didn't find the negative test case example. @[508947467:ianc] or @[759512522:emilsj], can you suggest a negative test case example.

Reviewed By: emilsjolander

Differential Revision: D7272067

fbshipit-source-id: e67e82eb057e4c7124904c715f9dca4dcfea21ea
2018-03-14 08:43:01 -07:00
Pritesh Nandgaonkar
d567885070 Remove the use of YGUndefined for flex-basis
Summary: Remove the use of YGUndefined for default flex-basis value

Reviewed By: emilsjolander

Differential Revision: D7243924

fbshipit-source-id: 2bfaca1a5e3da40d5292a273cabf705f59c9d666
2018-03-14 04:36:53 -07:00
Pritesh Nandgaonkar
877c275a13 Change the type of flexShrink to YGFloatOptional
Summary: Change the type of flexShrink to YGFloatOptional

Reviewed By: emilsjolander

Differential Revision: D7232171

fbshipit-source-id: 3111119d3d74a7035c01132bff61b30cf44e120a
2018-03-14 04:36:53 -07:00
Pritesh Nandgaonkar
8aadae8ce4 Change the type of flexGrow to YGFloatOptional
Summary: Change the type of flexGrow to YGFloatOptional

Reviewed By: emilsjolander

Differential Revision: D7215355

fbshipit-source-id: 1298ee332551d44e4d070169a1e4103d005c4f43
2018-03-14 04:36:53 -07:00
Pritesh Nandgaonkar
2232d7603a Change the type of flex to YGFloatOptional
Summary: Change the type of flex to YGFloatOptional internally, but keeping the public facing API the same as before

Reviewed By: emilsjolander

Differential Revision: D7211327

fbshipit-source-id: 0d979b6ba00317317b98bbc6e63979c7f1feb2da
2018-03-14 04:36:52 -07:00
Pritesh Nandgaonkar
b3f8851bc2 Changed the return type of YGResolveValue
Summary: Changed the return type of YGResolveValue

Reviewed By: emilsjolander

Differential Revision: D7195099

fbshipit-source-id: 72c4163cd08691cf6e40df05394cc52e83b0de14
2018-03-14 04:36:52 -07:00
Pritesh Nandgaonkar
47ad3f63cf Remove the usage of YGUndefined in the default values of Border in YGStyle
Summary: Remove the usage of YGUndefined in the default values of Border in YGStyle. In the getter of Border function, YGUndefined is used just to keep it logically consistent. The proper solution would be to change the api in `Yoga.h` to accept `YGFloatOptional`, but that would require to change lot of the code in client of this library. Will make a separate diff for that.

Reviewed By: emilsjolander

Differential Revision: D7195115

fbshipit-source-id: e635cf55ac94d8a90caef6cafce281579da2cbfc
2018-03-14 04:36:52 -07:00
Tomer Shalev
c75adb0671 solves the Android pixel bug
Summary:
emilsjolander hi,
this PR solves the following common and probable layout pixel scenario:
the older code is presented for reference:

```java
view.measure(
    View.MeasureSpec.makeMeasureSpec(
        Math.round(node.getLayoutWidth()),
        View.MeasureSpec.EXACTLY),
    View.MeasureSpec.makeMeasureSpec(
        Math.round(node.getLayoutHeight()),
        View.MeasureSpec.EXACTLY));
view.layout(
    Math.round(xOffset + node.getLayoutX()),
    Math.round(yOffset + node.getLayoutY()),
    Math.round(xOffset + node.getLayoutX() + node.getLayoutWidth()),
    Math.round(yOffset + node.getLayoutY() + node.getLayoutHeight()));

```

suppose now the following:
- `xOffset + node.getLayoutX() = 2.2`
- `node.getLayoutWidth() = 0.4` ==> `Math.round(node.getLayoutWidth()) = 0`
- `Math.round(xOffset + node.getLayoutX() + node.getLayoutWidth()) = Math.round(2.2 + 0.4) = 3`

this induces, the following measurements:
```java
view.measure(
    View.MeasureSpec.makeMeasureSpec(
        0,
        View.MeasureSpec.EXACTLY),
    View.MeasureSpec.makeMeasureSpec(
        Math.round(node.getLayoutHeight()),
        View.MeasureSpec.EXACTLY));
view.layout(
    2,
    Math.round(yOffset + node.getLayoutY()),
    3,
    Math.round(yOffset + node.getLayoutY() + node.getLayoutHeight()));

```

the width measurement of the view is 0, while the layout is `(3 - 2 = 1)`.
my proposed solution is to measure the view the way it is now, but when layouting
I use the `#getMeasuredWidth/Height()` methods, this will stop this problem
from happening.

I also want to note that this bug happens with high probability.
Closes https://github.com/facebook/yoga/pull/712

Reviewed By: emilsjolander

Differential Revision: D7231798

Pulled By: priteshrnandgaonkar

fbshipit-source-id: 171da519639dbecd75416a574bccc4456aa22f31
2018-03-13 03:13:00 -07:00
Héctor Ramos
178b8f5f64 Update config files to use LICENSE-examples
Summary: Use examples license in config files.

Reviewed By: sophiebits

Differential Revision: D7174444

fbshipit-source-id: 50c2369b18abd9d7fff9b4a66788fd67a5b40a0c
2018-03-08 10:21:51 -08:00
Michael Lee
a874992e7c Set missing header_namespace
Summary: When we don't explicitly set header_namespace, we can get differing behavior between Android and iOS. Even when it is not explicitly necessary, we are going to try to enforce this properly.

Reviewed By: scottrice

Differential Revision: D7141155

fbshipit-source-id: 74d1488c3909f89ad9d6d0ee0de335b789dc2ccd
2018-03-02 17:05:25 -08:00
Héctor Ramos
31fc287d35 Check PATENTS does not creep into files
Summary:
Some files have crept into the repo with the old license header. These are usually from PRs that were opened prior to the re-licensing of the project.

Let the script run, prior to fixing the errant files. The script outputs the following:

```
PATENTS crept into some new files?
 --- /dev/fd/63	2018-03-01 01:42:48.250153746 +0000
+++ /dev/fd/62	2018-03-01 01:42:48.250153746 +0000
@@ -1 +1,9 @@
+Libraries/NativeAnimation/Nodes/RCTTrackingAnimatedNode.h
+Libraries/NativeAnimation/Nodes/RCTTrackingAnimatedNode.m
+ReactAndroid/src/main/java/com/facebook/react/animated/TrackingAnimatedNode.java
+ReactAndroid/src/main/java/com/facebook/react/views/text/CustomLetterSpacingSpan.java
+ReactCommon/yoga/yoga/YGLayout.cpp
+ReactCommon/yoga/yoga/YGLayout.h
+ReactCommon/yoga/yoga/YGStyle.cpp
+ReactCommon/yoga/yoga/YGStyle.h
 scripts/circleci/check_license.sh
Exited with code 1
```

Fix the headers in these files and run the script again. No output, exit code 0.
Closes https://github.com/facebook/react-native/pull/18143

Reviewed By: sophiebits

Differential Revision: D7119356

Pulled By: hramos

fbshipit-source-id: d238e4d4a3ae320a2c8e625c2fa29690057a4814
2018-03-01 08:35:23 -08:00
Daniel Büchele
892913a69d Google analytics tracking
Summary:
Adds tracking for:
- short URL created
- value in interactive documentation changed

Reviewed By: priteshrnandgaonkar

Differential Revision: D7123493

fbshipit-source-id: 2fc19fa6c9b5614043af508a82e898b3ccefcbaa
2018-03-01 06:42:01 -08:00
Marcus Wu
99026e42a9 Fixed min-max docs typo
Summary:
Fixed `Max / Min Width and Height` docs typo.
Closes https://github.com/facebook/yoga/pull/720

Reviewed By: emilsjolander

Differential Revision: D7110855

Pulled By: priteshrnandgaonkar

fbshipit-source-id: 253d96e5d1208b94b6248ffab5f59caaef6ada2b
2018-03-01 06:19:41 -08:00
Pritesh Nandgaonkar
3a82d2b1a8 Change NaN with large number
Summary:
Changed NaN with large number to support `-ffast-math` compiler flag.For  `-ffast-math` to work, all floating point numbers should be finite. Reason for not going with `FLT_MAX`, is that, it may cause number overflow during math operations. So thats why I opted for big number smaller than `FLT_MAX`.  Earlier we used NaN, while NaN is involved in comparision the comparision operator behaves differently, it always returns false. Also operators like, fmaxf,fminf etc. have wierd beahviours. This diff takes care of those things as far as possible, and all tests are passing.

Running ./instrumentation_tests/run instrumentation_tests/com/facebook/feed/ctacoalescing:ctacoalescing --class AttachmentCallToActionSelectorBenchmarkTest --benchmark --extra-arg iterations=100 shows the perf gain of 13-15%

Reviewed By: emilsjolander

Differential Revision: D6969537

fbshipit-source-id: bdc09eaf703e0d313ca65c25a4fb44c99203d9bf
2018-03-01 04:03:19 -08:00
Pritesh Nandgaonkar
b28292e454 Make two separate yoga targets for QE
Summary: Setup QE for yoga perf changes

Reviewed By: emilsjolander

Differential Revision: D7059278

fbshipit-source-id: dd11b018edc8ea930d5eba09c6c01e349bb8b63c
2018-03-01 04:03:18 -08:00
Daniel Büchele
2ff18bc948 remove old docs folder
Summary: removing the old `docs` folder as we are switching to `gh-pages` branch.

Reviewed By: emilsjolander

Differential Revision: D7110147

fbshipit-source-id: a27e6fc3a115f2f62b8a0dd5833d872e24698021
2018-02-28 03:43:27 -08:00
Daniel Büchele
d0bee487e0 add tracking for code generators
Summary: Tracks a Google Analytics event once the code generator is opened.

Reviewed By: emilsjolander

Differential Revision: D7097182

fbshipit-source-id: 637a96db981f5e90c9f7ce155ba8669b8dac98fa
2018-02-27 07:13:53 -08:00
Daniel Büchele
419e29c5a6 adding --ignore-scripts flag to yarn
Summary: Travis builds for the website were failing. The problem was due to `yoga-layout` not compiling. However, we don't need to compile `yoga-layout` at all, because we are only using the asm.js version. This adds the `--ignore-scripts` flag to the `yarn` command, to ignore the post-install script which tries to compile yoga.

Reviewed By: emilsjolander

Differential Revision: D7097154

fbshipit-source-id: 3bf9efda0e2ae6166181dad66621cf6fc9586e88
2018-02-27 06:11:55 -08:00
Daniel Büchele
295d111f0e travis node version
Summary: Travis defaults to node version 0.10 (!). Explicitly setting the node version to 8.

Reviewed By: emilsjolander

Differential Revision: D7056888

fbshipit-source-id: f6e31cc75009dc4f322c1750c2ce540afdd641ce
2018-02-23 02:27:00 -08:00
Daniel Büchele
da5eb2db67 Remove travis builds
Summary: Removes travis build as they were currently not in use and prevented website from being deployed.

Reviewed By: emilsjolander

Differential Revision: D7055369

fbshipit-source-id: f227b1da1fea748c526b9faeedef063f9eeff61f
2018-02-22 08:19:56 -08:00
Daniel Büchele
3408e4d4fa adding travis deploy
Summary: Adds a deploy step to travis.yml file to depoly the docs to github pages.

Reviewed By: emilsjolander

Differential Revision: D7028804

fbshipit-source-id: bb91c6b1ad2a306a6957a48679f164128c5b1be1
2018-02-21 09:47:08 -08:00
Pascal Hartig
6d7eca8e42 Fix typo in docs
Summary:
"feature" should be "features" but it's already used twice in that paragraph so
I replaced it with "showcases" instead.

Reviewed By: emilsjolander

Differential Revision: D7042770

fbshipit-source-id: 0287f8746feca5c9f651950c8e9c24d2e86d55e9
2018-02-21 09:13:31 -08:00
Michael Lee
5726a71b62 Specify a platform argument for //yoga/java:jni
Summary: Specify that the jni rule is really for android

Reviewed By: emilsjolander

Differential Revision: D7015911

fbshipit-source-id: 5fbff4bb15d2d1256261b13417653b68bb6dc5aa
2018-02-20 15:02:21 -08:00
Kazuki Sakamoto
f73b5057ac Fix native build
Summary:
- Fix OSS build regarding is_apple_platform
- Update buck
- Drop 32bit build for Apple target

Reviewed By: ttsugriy

Differential Revision: D7032331

fbshipit-source-id: bb6a24bd404a107729a30b5ac4b419c238f7d42e
2018-02-20 14:13:39 -08:00
Pritesh Nandgaonkar
51051aad7f Added default constructor for YGCachedMeasurement
Summary: Added default constructor for YGCachedMeasurement. This diff uses the default initialiser to get rid off the older designated initializer syntax. This diff also addresses https://github.com/facebook/yoga/pull/700

Reviewed By: emilsjolander

Differential Revision: D7020337

fbshipit-source-id: e084e234bf6a2ae22e53e739959683abca169b88
2018-02-20 06:22:21 -08:00
Pritesh Nandgaonkar
91d3c08248 Add constructor in YGLayout
Summary: Add default constructor in YGLayout and moved to separate file. This diff also addresses https://github.com/facebook/yoga/pull/700

Reviewed By: emilsjolander

Differential Revision: D7019653

fbshipit-source-id: 5a2655626db0915fcebe7d4517e2d0b2e2484460
2018-02-20 06:22:21 -08:00
Pritesh Nandgaonkar
52f2cf319a Move YGStyle to seperate file and add constructors
Summary: Moved YGStyle to separate file and added default constructor to it. This diff also gets rid off of the default values, which were earlier declared in Yoga-interna.h and instead uses default constructor. This diff also addresses https://github.com/facebook/yoga/pull/700

Reviewed By: emilsjolander

Differential Revision: D7016575

fbshipit-source-id: eb28df0ffb4cc813b23edaff80d7d4ebc56ce6af
2018-02-20 06:22:17 -08:00
Emil Sjölander
bbdb62e654 Use absolute paths in links
Summary: allow-large-files

Reviewed By: danielbuechele

Differential Revision: D7023260

fbshipit-source-id: a797d09b61530b13da10e02c21acef13c508470c
2018-02-19 02:57:52 -08:00
Daniel Büchele
e024943c4b bugfixes
Summary:
- adds favicon
- adds page titles
- fixes bug in react native code gen

allow-large-files

Reviewed By: emilsjolander

Differential Revision: D7013492

fbshipit-source-id: d29a56a7caddf0da4fb19a0ba443c6906ccfff56
2018-02-19 02:38:16 -08:00
Sophie Alpert
7f44ec512e Update to MIT license
Summary: Manual changes.

Reviewed By: TheSavior, yungsters

Differential Revision: D7012152

fbshipit-source-id: de7459be3db13c687868b45059856f125c4f2eb1
2018-02-16 18:27:33 -08:00
Sophie Alpert
a2b6ddb7b1 Update license headers for MIT license
Summary:
Includes React Native and its dependencies Fresco, Metro, and Yoga. Excludes samples/examples/docs.

find: ^(?:( *)|( *(?:[\*~#]|::))( )? *)?Copyright (?:\(c\) )?(\d{4})\b.+Facebook[\s\S]+?BSD[\s\S]+?(?:this source tree|the same directory)\.$
replace: $1$2$3Copyright (c) $4-present, Facebook, Inc.\n$2\n$1$2$3This source code is licensed under the MIT license found in the\n$1$2$3LICENSE file in the root directory of this source tree.

Reviewed By: TheSavior, yungsters

Differential Revision: D7007050

fbshipit-source-id: 37dd6bf0ffec0923bfc99c260bb330683f35553e
2018-02-16 18:27:33 -08:00
Emil Sjölander
bdc37b0797 shipit
Reviewed By: danielbuechele

Differential Revision: D7010371

fbshipit-source-id: 9a111010755ee134bded7500c461342b944b4d62
2018-02-16 09:58:06 -08:00
Joel Marcey
82aaebfea2 Delete CNAME 2018-02-16 09:48:03 -08:00
Pritesh Nandgaonkar
48d82224ee Add redirect documentation
Summary: Add redirect documentation

Reviewed By: emilsjolander

Differential Revision: D7010032

fbshipit-source-id: fc370bc84e3afa0508ad38f910cf2bc20e991d84
2018-02-16 08:02:53 -08:00
Daniel Büchele
100afcfdb0 Add Yoga logo
Summary: Yoga logo was hotlinked from the old pages. This adds the logo to the sources

Reviewed By: emilsjolander

Differential Revision: D7009804

fbshipit-source-id: d913223e042b1bd9cf2ddab7c74d864e482d94b3
2018-02-16 07:22:06 -08:00
Daniel Büchele
b3436d5eba Default position to NaN
Summary: The position record defaulted to 0, which was wrong. No it defaults to NaN, which is the same as not having a value at all.

Reviewed By: emilsjolander

Differential Revision: D7009783

fbshipit-source-id: 83810da87e983f8d4d3e428f1f5fab0928bce58d
2018-02-16 07:22:06 -08:00
Daniel Büchele
c5371aca64 select value on focus
Summary: select the value of any input element once the field gets focus.

Reviewed By: emilsjolander

Differential Revision: D7009723

fbshipit-source-id: e1bc0f4b219958d8bdb79ef1a583cad86157b050
2018-02-16 07:22:06 -08:00
Pritesh Nandgaonkar
269619a419 Fixed Playground References for examples
Summary: Fixed Playground References for examples

Reviewed By: emilsjolander

Differential Revision: D7009922

fbshipit-source-id: 3025aebb383fb8e2be81e8ff59c0a071ce0860cb
2018-02-16 07:22:06 -08:00
Emil Sjölander
9b3104577c Tweak playground on landing page
Reviewed By: danielbuechele

Differential Revision: D7009909

fbshipit-source-id: a2734466efed6b9dc21f047be011b427bf67f830
2018-02-16 07:22:05 -08:00
Emil Sjölander
a1697d2307 Tweak landing page text
Reviewed By: danielbuechele

Differential Revision: D7009832

fbshipit-source-id: 69f7f68cc8d4f435f27c121bef4899c92f98a7a8
2018-02-16 07:22:05 -08:00
Emil Sjölander
056b75858c Tweak documentation
Reviewed By: danielbuechele

Differential Revision: D7009695

fbshipit-source-id: 145eca292e5cf95413caf5bc81b033419adb67a1
2018-02-16 07:22:05 -08:00
Emil Sjölander
c84ed90272 Allow playground on lg screens not just xl
Summary: This is now possible with the changes to centering the content

Reviewed By: danielbuechele

Differential Revision: D7009506

fbshipit-source-id: e2ff11d25dd6c388c82983d615e2a4c50b992583
2018-02-16 07:22:05 -08:00
Emil Sjölander
b21dd9891a Final tweaks
Reviewed By: danielbuechele

Differential Revision: D7009456

fbshipit-source-id: 65304f648141407bc15484840647050e712e89df
2018-02-16 07:22:05 -08:00
Emil Sjölander
bba81781af Copy review
Reviewed By: danielbuechele

Differential Revision: D7009457

fbshipit-source-id: d5053751a2bde369a65a740c03ace5bbd2eec02f
2018-02-16 07:22:05 -08:00
Pritesh Nandgaonkar
0c74a72fac Fix playground references
Summary: Fix playground references

Reviewed By: emilsjolander

Differential Revision: D7009698

fbshipit-source-id: 276fa1e5b98f05db281e101c90d6f19a1af77752
2018-02-16 06:42:02 -08:00
Daniel Büchele
1822bc5eaf Copy generated code to clipboard
Summary: Generated code modal now has a copy to clipboard button

Reviewed By: emilsjolander

Differential Revision: D7009716

fbshipit-source-id: 7a9b083d7067aa66ffa5b9d9c23741321547c4f6
2018-02-16 06:12:21 -08:00
Daniel Büchele
01ffe10c2f display NaN values as undefined
Summary: NaN values now display a placeholder saying undefined.

Reviewed By: emilsjolander

Differential Revision: D7009509

fbshipit-source-id: a3af360cc5c9d93e95a9e10368270f053a9b2c08
2018-02-16 05:51:22 -08:00
Daniel Büchele
7f99a547f5 hover on nodes
Summary: Adds a hover background color to nodes.

Reviewed By: emilsjolander

Differential Revision: D7009467

fbshipit-source-id: 1e1fb4d00086a6664ad8a53a0e8dbec075987a19
2018-02-16 05:51:22 -08:00
Daniel Büchele
0e5651fb80 Relative values in code generators
Summary: Code generators now can handle percentage and auto values as well as numeric values (DIP)

Reviewed By: emilsjolander

Differential Revision: D7009344

fbshipit-source-id: 64ddcb61a2dce01e68e38a16e4d5865d8e4c6d5b
2018-02-16 03:58:39 -08:00
Emil Sjölander
0ca44f3001 Document layout direction
Reviewed By: priteshrnandgaonkar

Differential Revision: D7000393

fbshipit-source-id: 2e5ae6a3fb69386920655bdfeee71a11f1775c2a
2018-02-16 03:49:48 -08:00
Pritesh Nandgaonkar
3f85763797 Documentation for Writing documentation
Summary: Documentation for "Writing documentation"

Reviewed By: emilsjolander

Differential Revision: D7000294

fbshipit-source-id: 633389a5e32ddd54be8f09b0945db5b9198d9552
2018-02-16 03:18:58 -08:00
Daniel Büchele
b318c4c5c9 upgrade yoga-layout
Summary:
- upgraded to yoga-layout@1.9.3
- set default values correctly
- catch errors

Reviewed By: emilsjolander

Differential Revision: D7001154

fbshipit-source-id: 49527576c61ce109ba0af0f50c981cf5c2c7d41a
2018-02-15 17:10:33 -08:00
Daniel Büchele
ae9703712a v1.9.3
Summary:
- fixes a but where `auto` was passed to properties that don't support auto as a value
- fixes errors in flow typing
- Re-adds accidentally removed scripts to package.json

Reviewed By: emilsjolander, arcanis

Differential Revision: D6999447

fbshipit-source-id: df66976c74c4af082a1ca0527e3e1ce54bdeb732
2018-02-15 09:48:39 -08:00
Emil Sjölander
d617ab6662 Tweak footer styling
Reviewed By: priteshrnandgaonkar

Differential Revision: D6999652

fbshipit-source-id: 93f4e43894388bb607112691a0b97e2e12a7df23
2018-02-15 09:12:34 -08:00
Daniel Büchele
4c3eebd3e5 Remove standalone playground
Summary: This is an older version of the standalone playground which is outdated and not used anymore

Reviewed By: emilsjolander

Differential Revision: D6998970

fbshipit-source-id: a27bee81b6f85f70c35a8d3e7ea7b06486c52626
2018-02-15 08:36:40 -08:00
Daniel Büchele
10061af491 enum title display
Summary: lower case and centerd

Reviewed By: emilsjolander

Differential Revision: D6998485

fbshipit-source-id: c06472afa4ccaa25ebf7c3c791d697b1fdc7732c
2018-02-15 08:36:40 -08:00
Daniel Büchele
91621641e6 visually center root node
Summary: root node is now centerwed between edge and editor

Reviewed By: emilsjolander

Differential Revision: D6989159

fbshipit-source-id: ce2621402d380843125fabc43452c64ea3b563dd
2018-02-15 08:36:40 -08:00
Pritesh Nandgaonkar
35c6931ade Remove unwanted footer items
Summary: Remove unwanted footer items

Reviewed By: emilsjolander

Differential Revision: D6999348

fbshipit-source-id: e1ff13b8a5a497bfc54e04294994eddef48bbf94
2018-02-15 08:13:40 -08:00
Yuichi ONO
44622912a2 Fix main size calculation from the aspect ratio
Summary:
When the following conditions are met, the main size become smaller by the margins in the main axis.
* The aspect ratio is defined
* The main size is not defined
* The cross size is defined
* The main margin is defined

This is because the main margin size is not included when calculating the main size from the aspect ratio.
Closes https://github.com/facebook/yoga/pull/715

Reviewed By: emilsjolander

Differential Revision: D6998988

Pulled By: priteshrnandgaonkar

fbshipit-source-id: f6f69c47ece17bd7c5e41517b96032bf0c149356
2018-02-15 07:40:34 -08:00
Pritesh Nandgaonkar
aac40cf89b Footer implementation
Summary: Footer Implementation

Reviewed By: emilsjolander

Differential Revision: D6998645

fbshipit-source-id: db637f2d9fe1cdbcaa8366e0cc03f2bf67e2543a
2018-02-15 06:21:01 -08:00
Pritesh Nandgaonkar
d4b20f5793 Documentation for absolute/relative layout
Summary: Documentation for absolute/relative layout

Reviewed By: emilsjolander

Differential Revision: D6998594

fbshipit-source-id: 25dacbb87e067ab8abd555fd24611776b0332047
2018-02-15 06:21:01 -08:00
Pritesh Nandgaonkar
89df2d9475 Google Analytics added
Summary: Google analytics added

Reviewed By: emilsjolander

Differential Revision: D6998583

fbshipit-source-id: 3886964407ec32454da4770b0fe80185e8e18881
2018-02-15 06:21:01 -08:00
Pritesh Nandgaonkar
79fa6f8d58 Documentation for min/max
Summary: Documentation for min/max

Reviewed By: emilsjolander

Differential Revision: D6998539

fbshipit-source-id: 65a0c1713fb5a01e41e0afcfbefa1b0280c82ed5
2018-02-15 06:21:01 -08:00
Pritesh Nandgaonkar
69242938f7 Add min/max in YogaRecord
Summary: Add min/max in YogaRecord

Reviewed By: emilsjolander

Differential Revision: D6998533

fbshipit-source-id: 4613c99bd3a4cb3b8fbe577909157b25f3bef9c7
2018-02-15 06:21:00 -08:00
Pritesh Nandgaonkar
1b66b5d941 Documentation added for width and height
Summary: Width and height documentation

Reviewed By: emilsjolander

Differential Revision: D6978015

fbshipit-source-id: f62972acaf70be2b6df5056b5deed2a893c10b4c
2018-02-15 06:21:00 -08:00
Emil Sjölander
fb30f7ddcb Responsify
Reviewed By: danielbuechele

Differential Revision: D6998697

fbshipit-source-id: ea15f1b1ce3f518c194dc66169413a92e0d870bc
2018-02-15 06:21:00 -08:00
David Vacca
747c2a4208 Make Java YogaNode cloneable
Summary:
This diff exposes the YogaNode clone operation to JNI in order to be able to clone Java YogaNode objects.

The clone method performs a shallow copy of the java YogaNode.

I made YogaNode to implement Cloneable, I know that this might not be a good idea but in this case it simplifies the cloning mechanism. I am open to suggestions.

IMPORTANT NOTES:
- The current implementation IS NOT making a deep copy of the mData instance variable.
- The mParent Java instance variable will reference the parent of the original Java YogaNode, is that ok sebmarkbage?

Reviewed By: priteshrnandgaonkar

Differential Revision: D6935971

fbshipit-source-id: a2008f1eb849b5074585b48699b7de56d5ac90d4
2018-02-14 18:12:34 -08:00
Daniel Büchele
43fda26275 add share and code buttons
Summary: Adds code and share buttons to the editor

Reviewed By: emilsjolander

Differential Revision: D6989097

fbshipit-source-id: 67478fe0810a0af43524f24458c520acf2999219
2018-02-14 11:03:59 -08:00
David Vacca
b1222bf83e Expose methods of persistent yoga for Java
Summary: This diff extends the JNI version of yoga in order to allow Java instances of the YogaConfig class to receive a callback when a Yoga node is cloned.

Reviewed By: priteshrnandgaonkar

Differential Revision: D6918605

fbshipit-source-id: e424c78680c04e21154ebe21405671c4e90f6529
2018-02-14 09:41:52 -08:00
Emil Sjölander
3ec41b656f Markdown redirect frontmatter
Reviewed By: danielbuechele

Differential Revision: D6987631

fbshipit-source-id: 8b3431fa885fb94d4a87119b5a5199db0b36b20c
2018-02-14 08:49:37 -08:00
Daniel Büchele
740ef6cd9e flexWrap, alignContent, initialPlayground
Summary: Adds `initialPlayground` to the markdown header. Adds contents fro alignContent and flexWrap.

Reviewed By: emilsjolander

Differential Revision: D6987513

fbshipit-source-id: 41de309d427a9f42e09477170fb8512ce1e7a816
2018-02-14 08:17:21 -08:00
Daniel Büchele
8c5cbf698b Inline controls for docs
Summary:
Adding inline controls in markdown using:
```
<controls prop="flexWrap"></controls>
```

Reviewed By: emilsjolander

Differential Revision: D6987150

fbshipit-source-id: 28def12df702ba5d5d5b6a83dd1cb907716d1b1c
2018-02-14 08:17:21 -08:00
Emil Sjölander
5f2cf6623f Bump size of documentation sidebar
Reviewed By: danielbuechele

Differential Revision: D6978450

fbshipit-source-id: c82da40e2ef44b360cb98e1cc0a28b516aa2e573
2018-02-13 11:43:04 -08:00
Emil Sjölander
4b7efb73d7 Change some default playground styling
Reviewed By: danielbuechele

Differential Revision: D6977989

fbshipit-source-id: 64975685490b8a2230d4effc8791c028b680d2b7
2018-02-13 11:43:04 -08:00
Emil Sjölander
a6b7e34187 Go over property descriptions and add documentation links
Reviewed By: danielbuechele

Differential Revision: D6977090

fbshipit-source-id: cc8a6acda8b9b7f007ad0a2f83249d4e6037bb0f
2018-02-13 11:43:04 -08:00
Emil Sjölander
e50308e823 Tweak styling of list and code in docs
Reviewed By: danielbuechele

Differential Revision: D6976762

fbshipit-source-id: 6decc7af180773193e3811253ada7f8d543c6cc8
2018-02-13 11:43:04 -08:00
Emil Sjölander
b6a13ce43a Mark selected page in toolbar
Reviewed By: danielbuechele

Differential Revision: D6976597

fbshipit-source-id: 280623b4dbf18eb008da846077fc8f5277eccc09
2018-02-13 11:43:03 -08:00
Daniel Büchele
96a87a811d Shorten playground URL
Summary: Shorten URL using Google's URL shortner and display URL for copying.

Reviewed By: emilsjolander

Differential Revision: D6976973

fbshipit-source-id: cc791ffbf9e01a8dc2e0a40d05bce5022a3957bc
2018-02-13 09:45:06 -08:00
Emil Sjölander
025ee03cb1 Add copywrite headers to css files
Reviewed By: danielbuechele

Differential Revision: D6976529

fbshipit-source-id: 7f0c3fdd70105cbe055fa49f10eac3bdaf84b5c2
2018-02-13 09:16:03 -08:00
Emil Sjölander
c06ee92251 Add standalone docs
Reviewed By: danielbuechele

Differential Revision: D6976384

fbshipit-source-id: 329dd6b5997ab83d408fb330421624cf85e3f09e
2018-02-13 07:42:41 -08:00
Emil Sjölander
3aca5965dc Fix sizing of playground in landing page
Reviewed By: danielbuechele

Differential Revision: D6976272

fbshipit-source-id: e9cf8582aa4f8d97190b40d5b7cf219ff1ef8ae5
2018-02-13 07:42:41 -08:00
Emil Sjölander
cac77e5ffa Add contributing docs
Reviewed By: danielbuechele

Differential Revision: D6976258

fbshipit-source-id: 71b3d0ab4a071ce0c4a9c1241cd6295aa6d52b8e
2018-02-13 07:31:58 -08:00
Emil Sjölander
49f1d7b5f6 Add external doc links for Litho, ComponentKit, and React Native
Reviewed By: danielbuechele

Differential Revision: D6976131

fbshipit-source-id: 83f5f59cb839d0c2f291621f9f88678261077082
2018-02-13 06:55:33 -08:00
Emil Sjölander
82e44dbf04 Handle external doc links
Reviewed By: danielbuechele

Differential Revision: D6976132

fbshipit-source-id: 56bd33816a312af12ba9a0f088c9f49a42ef9913
2018-02-13 06:55:33 -08:00
Emil Sjölander
9b501dd9eb Scroll doc sidebar not whole page
Reviewed By: danielbuechele

Differential Revision: D6976133

fbshipit-source-id: 7807aa4e2ab0ed013fbd1f4bbef2ee1b8098dff6
2018-02-13 06:55:33 -08:00
Emil Sjölander
8ba663f6f4 Document margins, paddings, and borders
Reviewed By: danielbuechele

Differential Revision: D6976134

fbshipit-source-id: dcf870d9a88478ed1aef68e9840e7b17467b87bb
2018-02-13 06:55:32 -08:00
Emil Sjölander
8f35484262 Document flexing
Reviewed By: danielbuechele

Differential Revision: D6976135

fbshipit-source-id: e9051b1e583d909aefe76f7aa9505467890a0d4c
2018-02-13 06:55:32 -08:00
Emil Sjölander
1e3143656d Document aspect ratio
Reviewed By: danielbuechele

Differential Revision: D6976130

fbshipit-source-id: caf3cc1d1d1c00fee03ca26966fb57d1796e1604
2018-02-13 06:55:32 -08:00
Daniel Büchele
699b1f5012 Fixing playground editing
Summary: editing numerical values didn't work. this fixes it and cleans up the API of the playground

Reviewed By: emilsjolander

Differential Revision: D6976128

fbshipit-source-id: 9b1ace9d93ba8e597bdfb4842ed6adcaf8b77fd9
2018-02-13 06:16:12 -08:00
Daniel Büchele
9c877a621e fix inserting/deleting children
Summary: Inserting or deleting nodes threw an error, due to some changes I made earlier. This fixes the error.

Reviewed By: emilsjolander

Differential Revision: D6975950

fbshipit-source-id: d04df08260ab8ab248726809329e69f4d264decd
2018-02-13 06:16:12 -08:00
Daniel Büchele
a3144150e0 fix Yoga imports for build script
Summary: The bundling of gatsby is done in node. This caused the node-libs from yoga being loaded. This directly imports the browser version.

Reviewed By: emilsjolander

Differential Revision: D6975779

fbshipit-source-id: 0257a86733c5552259b171309e59cc676786621e
2018-02-13 06:16:12 -08:00
Daniel Büchele
c830083df3 Website readme
Summary: Updating readme

Reviewed By: emilsjolander

Differential Revision: D6975778

fbshipit-source-id: c27a074c8d512e72de63ffa1d2f06f18a4f8e2c5
2018-02-13 06:16:12 -08:00
Emil Sjölander
9eb03b1bcd playground doc page first draft
Reviewed By: danielbuechele

Differential Revision: D6968725

fbshipit-source-id: 588018a347a723b32e4dcab407c4da2db0d85130
2018-02-13 04:01:04 -08:00
Emil Sjölander
7e3136c347 non-playground doc page first draft
Reviewed By: danielbuechele

Differential Revision: D6968540

fbshipit-source-id: c5d408adb1d11c429d72a0f180ce3154ae0922a6
2018-02-13 04:01:04 -08:00
Emil Sjölander
c3de8016c0 Move footer to only landing page
Reviewed By: danielbuechele

Differential Revision: D6968277

fbshipit-source-id: ec01d6e0de6a76ab9235378a1c1a29dcf7903ae3
2018-02-13 04:01:04 -08:00
Emil Sjölander
af45863f8e Docs page first draft
Reviewed By: danielbuechele

Differential Revision: D6968201

fbshipit-source-id: f08104428188b8b3225b2803c9f2165ee653a0b6
2018-02-13 04:01:04 -08:00
Emil Sjölander
08d7d1673e Add documentation placeholders
Reviewed By: danielbuechele

Differential Revision: D6968199

fbshipit-source-id: 433d81b6367d1376224e0b3516be65132c091a34
2018-02-13 04:01:03 -08:00
Emil Sjölander
e7c56ccd1e Landing page first draft
Reviewed By: danielbuechele

Differential Revision: D6964899

fbshipit-source-id: ea9fed66ba0376a5cd2efda4d631cc14e591e666
2018-02-12 10:46:04 -08:00
Emil Sjölander
de8cab8e60 Footer design
Reviewed By: danielbuechele

Differential Revision: D6964900

fbshipit-source-id: 68831f101ef2112613cd170cb90bdd9235441c9d
2018-02-12 10:46:04 -08:00
Emil Sjölander
9e0f751464 Toolbar design
Reviewed By: danielbuechele

Differential Revision: D6964901

fbshipit-source-id: c052449d0ae3da91bec64c8f9da867244022ccf1
2018-02-12 10:46:03 -08:00
Daniel Büchele
951a429ac5 Template for docs pages
Summary:
- Dynamic loading of documentation pages
- code highlighting for markdown files
- editing playground from sidebar

Reviewed By: emilsjolander

Differential Revision: D6964951

fbshipit-source-id: 1c7f36afa8d23215471d5b9a9c01bd2241c2008e
2018-02-12 10:46:03 -08:00
Daniel Büchele
e43bb9da19 website v2 skeleton
Summary:
Sets up a skeleton for the new yoga website using gatsby static site generator

allow-large-files

Reviewed By: emilsjolander

Differential Revision: D6952326

fbshipit-source-id: 7579bc80bec21552689da5b78f3d960910ff13bb
2018-02-12 09:39:22 -08:00
Pritesh Nandgaonkar
b08bd572ef Add flag in YGConfig for running experiments
Summary: Add flag in YGConfig for running experiments

Reviewed By: emilsjolander

Differential Revision: D6948702

fbshipit-source-id: 009fe2d64b6098f8c3a0289f0e6939dea5ce0d37
2018-02-09 06:45:11 -08:00
Pritesh Nandgaonkar
402ee11273 Fix memory leak by not duplicating the YGConfig
Summary:
YGConfig isn't owned by the YGNode, and thus isn't freed when freeing the node (`YGNodeFreeRecursive`)

This fixes a memory leak caused by D6856812

Reviewed By: emilsjolander

Differential Revision: D6945022

fbshipit-source-id: 5fd3c3e2ac1cd94d459d5aa06e0daa8f107779ac
2018-02-09 05:00:13 -08:00
Pritesh Nandgaonkar
6e38a26f32 Expose a function which marks all descendants dirty
Summary: Expose a function which marks all descendants dirty

Reviewed By: emilsjolander

Differential Revision: D6911869

fbshipit-source-id: e0a3abcf5653f921297edfdca473d83b947cc627
2018-02-08 05:23:46 -08:00
Pritesh Nandgaonkar
d66239bea8 call margin method on child instead of node
Summary: While moving a function as a method in YGNode, there was an error in which I mistakenly called a method on node, whereas I had to call it on child.

Reviewed By: emilsjolander

Differential Revision: D6918367

fbshipit-source-id: cee90e015f9e45a717a7307f59fd3b9ef6f399b6
2018-02-07 17:27:22 -08:00
Pritesh Nandgaonkar
7eb8df2777 Fix screenshot test due main axis justification refactor
Summary: There was a slight error in main axis justification which caused the regression

Reviewed By: emilsjolander

Differential Revision: D6923178

fbshipit-source-id: d8f81b06d9127c75daecffb73b5e6c5abbad8ade
2018-02-07 08:53:08 -08:00
Joel Marcey
75473fd924 Create CNAME 2018-02-06 09:32:58 -08:00
Joel Marcey
c94ade8ffd Update config for yogalayout.com
Summary: Closes https://github.com/facebook/yoga/pull/710

Reviewed By: emilsjolander

Differential Revision: D6912211

Pulled By: JoelMarcey

fbshipit-source-id: 8ccadc1a4845fb8a6fdc756077bfad01f0de7aac
2018-02-06 09:31:34 -08:00
Pritesh Nandgaonkar
61afbd43c9 Moved margin axis function as a method in YGNode
Summary: Moved margin axis function as a method in YGNode

Reviewed By: emilsjolander

Differential Revision: D6900003

fbshipit-source-id: a42da3bcd3126bf8c432c6740987b5ec0b572172
2018-02-06 08:44:46 -08:00
Pritesh Nandgaonkar
64f6ea37bd Moved trailing padding and border function as a method on YGNode
Summary: Moved trailing padding and border function as a method on YGNode

Reviewed By: emilsjolander

Differential Revision: D6899571

fbshipit-source-id: 7f686e8771d5a94aae502191516557b20c557d7c
2018-02-06 08:44:46 -08:00
Pritesh Nandgaonkar
dc0609d153 Moved out main axis justification logic to seperate function
Summary: Moved out main axis justification logic to seperate function

Reviewed By: emilsjolander

Differential Revision: D6845997

fbshipit-source-id: fdb64e00de39427ce1d66d4fbfd06c23c0d32bcf
2018-02-06 08:44:45 -08:00
Daniel Büchele
bd46344a4e Fix ComponentKit code generation
Summary: Fixes ComponentKit code generation to outpput valid code.

Reviewed By: emilsjolander

Differential Revision: D6902924

fbshipit-source-id: f03a69268d22084f30aea46297b59aec28ba68d2
2018-02-06 08:27:42 -08:00
Joel Marcey
7199902316 Delete CNAME 2018-02-06 08:16:40 -08:00
Joel Marcey
250873abf2 Create CNAME 2018-02-06 08:12:21 -08:00
Pritesh Nandgaonkar
1e775ecb83 Fixed failing snapshot test
Summary: Fixed failing snapshot test

Reviewed By: emilsjolander

Differential Revision: D6901242

fbshipit-source-id: 7391d6a34fa28e9f92f4ff834755a89dd876fdad
2018-02-06 07:23:56 -08:00
Daniel Büchele
9718c517d9 add playground
Summary:
This adds a web-based playground to try out Yoga. The playground uses yogas javascript bindings to use yoga within the browser. The layout tree can be modified and shared. Code generators for litho, ComponentKit and React Native allow the layout to be copied into any app.

allow-large-files

Reviewed By: emilsjolander

Differential Revision: D6871601

fbshipit-source-id: 3b97c87e91d6bafe8e1c38b8b7eca8d372324c0b
2018-02-05 07:11:57 -08:00
Pritesh Nandgaonkar
afc215aa66 Made a separate function for resolving flexible length
Summary: Made a separate function for resolving flexible length

Reviewed By: emilsjolander

Differential Revision: D6834269

fbshipit-source-id: 954bc7fe8eb9256d353cdda27e5c64c076808e25
2018-02-05 06:42:52 -08:00
Pritesh Nandgaonkar
5df8157863 Seperate function for second pass
Summary: Added a separate function which does the second pass to distribute the free space amongst the views which can be flexed.

Reviewed By: emilsjolander

Differential Revision: D6833635

fbshipit-source-id: 7680a67db8bfe22f8fb86407159888882f3a3353
2018-02-05 06:42:52 -08:00
Pritesh Nandgaonkar
802fe6bb29 Replaced first pass with a function
Summary: Added a function which does the first pass to determine the free space based on flex items whose min and max constraints are triggered

Reviewed By: emilsjolander

Differential Revision: D6819719

fbshipit-source-id: e5e77c21d1dca2255433da3388887d9db3f7b642
2018-02-05 06:42:51 -08:00
Pritesh Nandgaonkar
27d2ad198e Moved out logic to calculate size consumed on a line into seperate function
Summary: Moved out logic to calculate size consumed on a line into seperate function

Reviewed By: emilsjolander

Differential Revision: D6797640

fbshipit-source-id: ad9757e7d603c0ce57f452b1e5c404037605bed9
2018-02-05 06:42:51 -08:00
Pritesh Nandgaonkar
63be3ff84c Remove the use of legacy flag and log the diff if its used
Summary: Check if the layout tree is different if we do not use legacy flags. If they are different then report to the client

Reviewed By: emilsjolander

Differential Revision: D6856812

fbshipit-source-id: e4724d80702cc75c1894e348e137b24e663573d2
2018-02-02 07:43:26 -08:00
Mark Wang
66045bd13d Use delete instead of free
Summary: Since a `YGNodeRef` is created with `new`, it needs to be deleted using `delete` instead of `free`.

Reviewed By: richardjrossiii

Differential Revision: D6866064

fbshipit-source-id: a44828cedb5045b6c97179fb30ffd8c8dafcbfbe
2018-01-31 18:12:55 -08:00
Pritesh Nandgaonkar
f5f8105b57 Made logging logic dynamic to log string length
Summary: Previously the logging logic assumed fixed number of characters in the string to be logged. With this diff the logging logic is made dynamic, catering to variable length of the string to be logged

Reviewed By: emilsjolander

Differential Revision: D6784491

fbshipit-source-id: 26e4520a84be355ff992b808297ce7a95b3d09e3
2018-01-23 06:41:41 -08:00
Pritesh Nandgaonkar
4f92ae46ef Yoga android news feed benchmark tests
Summary: Added a benchmark tests along with the usual gentest in yoga for a complex yoga android news feed view.

Reviewed By: emilsjolander

Differential Revision: D6753544

fbshipit-source-id: 23b8da9785990a86248ff4708ac61e12411eb489
2018-01-22 04:30:26 -08:00
Pascal Hartig
80f8aa3c7e Mark model fields final
Summary: These are already considered immutable, but not marked in their class.

Reviewed By: emilsjolander

Differential Revision: D6759564

fbshipit-source-id: 810dc8a9730fb330760d2aedecafcea81cf25cb1
2018-01-22 02:56:53 -08:00
Daniel Büchele
42778f687b Release version 1.9.0
Summary:
- Fixes bindings
- Fixes benchmarks and test calls
- version 1.9.0

Reviewed By: arcanis, priteshrnandgaonkar

Differential Revision: D6759438

fbshipit-source-id: 0ea58e607e0b518aaa907cbfa82d2baea7bc1ed5
2018-01-19 11:28:44 -08:00
Daniel Büchele
7b27a58b97 NPM release v1.8.1
Summary: Package is already published via NPM. This is just the version bump.

Reviewed By: emilsjolander

Differential Revision: D6750224

fbshipit-source-id: 6add1ce71714e58e4afacd095265b3e770bc558e
2018-01-19 11:28:44 -08:00
Daniel Büchele
a40ba9d350 update JavaScript bindings
Summary:
- adds flow types
- transpiles bundle using babel
- cleans and formats code

Reviewed By: emilsjolander

Differential Revision: D6748362

fbshipit-source-id: fcb5fdde73df6e0062eff1e5038bb5fe0532f997
2018-01-18 08:27:03 -08:00
Pritesh Nandgaonkar
9ecdff14fa Use vector instead of linked list
Summary: Currently in the flexbox algorithm we were using linked list for maintaining the nodes which had relative/absolute position types, this diff uses STL vector instead of linked list.

Reviewed By: emilsjolander

Differential Revision: D6722959

fbshipit-source-id: 4e81176802b9a9319bc5f385c824a06be14a83a2
2018-01-16 09:42:13 -08:00
Pritesh Nandgaonkar
288adc49c9 Fix for failing screenshot tests
Summary: Fixes failing screenshot tests

Reviewed By: emilsjolander

Differential Revision: D6726745

fbshipit-source-id: 99f91aabe2337b23953724545f97695238f2124e
2018-01-16 09:20:09 -08:00
Valentin Shergin
b8c2428b31 Exposing setDirtiedFunc as plain C function YGNodeSetDirtiedFunc
Summary:
@public
Trivial. Those lines were lost during rebasing of the original commit.

Reviewed By: priteshrnandgaonkar

Differential Revision: D6717696

fbshipit-source-id: a5dce25427c8977352b3ae7ea01e546a540e0c13
2018-01-15 15:52:29 -08:00
Pritesh Nandgaonkar
92bfcbafc0 Moved leadingpaddingnandborder function as a method on YGNode
Summary: Moved leadingpaddingnandborder function as a method on YGNode

Reviewed By: emilsjolander

Differential Revision: D6711991

fbshipit-source-id: 41ad7191bf8df6fe3131106436dc0c87e9dee297
2018-01-15 10:15:14 -08:00
Pritesh Nandgaonkar
130b5beca2 Move trailing padding function as a method on YGNode
Summary: Move trailing padding function as a method on YGNode

Reviewed By: emilsjolander

Differential Revision: D6711897

fbshipit-source-id: fa2e1a8e31242358a6e94aef51368e2c2c58b79d
2018-01-15 10:15:13 -08:00
Pritesh Nandgaonkar
adb2e0fdd6 Moved leading padding function as a method on YGNode
Summary: Moved leading padding function as a method on YGNode

Reviewed By: emilsjolander

Differential Revision: D6711830

fbshipit-source-id: d2f6f55ec23b007bb51f8a91385e02236f46dc7b
2018-01-15 10:15:13 -08:00
Pritesh Nandgaonkar
0a04bd7f2f Resolve direction function is now as a method on YGNode
Summary: Resolve direction function is now as a method on YGNode

Reviewed By: emilsjolander

Differential Revision: D6711755

fbshipit-source-id: a0e80596e10f0c7fb7a31b75377da4db846c4bbb
2018-01-15 10:15:13 -08:00
Pritesh Nandgaonkar
9d6af5b314 Move trailing border function as a method on YGNode
Summary: Move trailing border function as a method on YGNode

Reviewed By: emilsjolander

Differential Revision: D6711666

fbshipit-source-id: fe4fdfc2db59d03beb763317e1a6f9de52f851d4
2018-01-15 10:15:13 -08:00
Pritesh Nandgaonkar
6efb4b90d4 Move leading border function as a method on YGNode
Summary: Move leading border function as a method on YGNode

Reviewed By: emilsjolander

Differential Revision: D6711523

fbshipit-source-id: 76e90083a9dd0728dc9557cc3b0a1f431f3afd5d
2018-01-15 10:15:13 -08:00
Pritesh Nandgaonkar
5806f1728c Moved YGNodeIsFlex as a method on YGNode
Summary: Moved YGNodeIsFlex as a method on YGNode

Reviewed By: emilsjolander

Differential Revision: D6711536

fbshipit-source-id: e60be7da55e3e8d254eb253c141d219a37a76087
2018-01-15 10:15:13 -08:00
Pritesh Nandgaonkar
a9dd527748 Refactored step3 of flexbox algorithm
Summary: Previously flexbasis calculation was doing more than one task of accumulating absolutelypositioned child and flexbasis calculation. So this diff refactors the logic and moves out absolutely positioned child calculation to our step 1(which is calculating the variables which are required for rest of the algorithm). This diff also moves the flexbasis logic into separate function

Reviewed By: emilsjolander

Differential Revision: D6702749

fbshipit-source-id: 15dcc94ae30ac185e4d1c7d6e3744a40cfa47317
2018-01-15 10:15:12 -08:00
Pritesh Nandgaonkar
db3d20b7b7 Refactored the flexbox step to determine available space in main and cross dim
Summary: Refactored the logic to calculate available main and cross dimensions

Reviewed By: emilsjolander

Differential Revision: D6693777

fbshipit-source-id: d6c87670e74bdc22b32916c2d77fe423d831b378
2018-01-15 05:41:56 -08:00
Semen Zhydenko
acd4e01aaf Typos in comments and log messages
Summary:
No code changes, no testing required.

alligned -> aligned
allignment -> alignment
completly -> completely
conseptually -> conceptually
decendents -> descendants
indefinetly -> indefinitely
dimention -> dimension
doesnt -> doesn't
safegaurd -> safeguard
intialization -> initialization
hierachy -> hierarchy
happend -> happened
gaurd -> guard
programatically -> programmatically
initalized -> initialized
immidiately -> immediately
occured -> occurred
unkown -> unknown
neccessary -> necessary
neccesarily -> necessarily
occuring -> occurring
comoponent -> component
propogate -> propagate
recieved -> received
referece -> reference
perfomance -> performance
recieving -> receiving
subsquently -> subsequently
scoll -> scroll
suprisingly -> surprisingly
targetting -> targeting
tranform -> transform
symetrical -> symmetrical
wtih -> with
Closes https://github.com/facebook/react-native/pull/17578

Differential Revision: D6718791

Pulled By: shergin

fbshipit-source-id: 4ab79c1131ec5971d35a0c7199eba7ec0a0918ad
2018-01-12 22:16:32 -08:00
Attila Jakabfi
b217f23ba5 Spacing
Summary: Add spacing type to Yoga Config

Differential Revision: D6683074

fbshipit-source-id: a76bc5028962d738bb931a997752f6ba194bd8ed
2018-01-12 05:13:40 -08:00
Pritesh Nandgaonkar
76875af207 Moved setPosition as a method on YGNode
Summary: Moved setPosition as a method on YGNode

Reviewed By: emilsjolander

Differential Revision: D6683387

fbshipit-source-id: 83f64101faa700933771c69b222056ec2a6b8d1e
2018-01-11 04:59:02 -08:00
Pritesh Nandgaonkar
f2ba14c309 Moved trailingmargin function as a method on YGNode
Summary: Moved trailingmargin function as a method on YGNode

Reviewed By: emilsjolander

Differential Revision: D6683313

fbshipit-source-id: 5ee458c2f4698768724901df0e3f5d8805c7c8f5
2018-01-11 04:59:02 -08:00
Pritesh Nandgaonkar
a65b79a944 Moved getLeadingMargin as a function on YGNode
Summary: Moved getLeadingMargin as a function on YGNode

Reviewed By: emilsjolander

Differential Revision: D6683270

fbshipit-source-id: a26663006419e13cb783e9849183e3c665f59b3c
2018-01-11 04:59:01 -08:00
Pritesh Nandgaonkar
681b580fd8 Moved getTrailingPosition function as a method on YGNode
Summary: Moved getTrailingPosition function as a method on YGNode

Reviewed By: emilsjolander

Differential Revision: D6683205

fbshipit-source-id: d30003d90d634c644d92c833e58165b073d4d13e
2018-01-11 04:59:01 -08:00
Pritesh Nandgaonkar
b985b6c377 Moved is isTrailingPos defined as a method on YGNode
Summary: Moved is isTrailingPos defined as a method on YGNode

Reviewed By: emilsjolander

Differential Revision: D6683190

fbshipit-source-id: c37e57d02cc4475eb8181a2bb003c555bdb0aaea
2018-01-11 04:59:01 -08:00
Pritesh Nandgaonkar
92eda21e78 Moved isLeadingPos defined as a method on YGNode
Summary: Moved isLeadingPos defined as a method on YGNode

Reviewed By: emilsjolander

Differential Revision: D6682956

fbshipit-source-id: 31c60e0eae906e1434a6969f3cd786fcaf9097a5
2018-01-11 04:59:01 -08:00
Pritesh Nandgaonkar
0cfdb50477 Moved YGNodeLeading position as a method on YGNode
Summary: Moved YGNodeLeading position as a method on YGNode

Reviewed By: emilsjolander

Differential Revision: D6682929

fbshipit-source-id: 3607aab1544b62b1126c5d75b2f6fb8f5ca2d45f
2018-01-11 04:59:01 -08:00
Valentin Shergin
1eb9a5edd9 Tests for YGNodeSetDirtiedFunc
Summary: testallthethings

Reviewed By: gkassabli

Differential Revision: D6687460

fbshipit-source-id: bebae3604212cb10e7ac43d10cfebd4978834d69
2018-01-10 10:09:38 -08:00
Valentin Shergin
383b881748 Introducing on-dirty handler (aka YGNodeSetDirtiedFunc)
Summary:
@public
Currently, we can dirty leaf nodes with `measure` function, we also can get `dirty` status for any node, but we cannot handle a moment when this change happen. This diff introduces a new call-back-manner handler for it.
We need this to plug Yoga inside and outside other layout systems without maintaining own dirty propagation infrastructure.
Consider using Yoga for flex-box layout in React Native where we can have deeply nested layout like `<View><Text><View><Text/></View></Text></View>` where all content of all <Text> nodes are laid out using native text/inline (not flex-box!) layout system. In this case, when some change dirties some deeply nested Yoga node, we have to propagate the dirty state down to outer one. Having this handler makes possible to wire up `on-dirty` handler on the root node and `setDirtied` for the leaf node.
Removing custom dirting mechanism from React Native should drastically simplify rendering layer and bring a huge performance win.

Reviewed By: emilsjolander

Differential Revision: D6597856

fbshipit-source-id: 6588cd712f9c1dede4af32f3d326f90103e48ff0
2018-01-10 10:09:38 -08:00
Pritesh Nandgaonkar
47543c8fba Move utility functions to utils file
Summary: Move utility functions to utils file

Reviewed By: emilsjolander

Differential Revision: D6682933

fbshipit-source-id: 0fd90fdaf5ca4f9b7a11cbd15d8c54c7d0ce8a03
2018-01-10 05:03:52 -08:00
Pritesh Nandgaonkar
dc6ed89bfa Fix warnings of casting and null pointer handling
Summary: There were warnings of castings and null pointer handling in yoga.cpp. This diff fixes the warnings. The issue was brought up here https://github.com/facebook/react-native/issues/17274

Reviewed By: emilsjolander

Differential Revision: D6675111

fbshipit-source-id: 884659fabb05033b4d43d3aa6629e22481d39b7e
2018-01-09 04:27:01 -08:00
Pritesh Nandgaonkar
348dd368b5 Move YGNodeResolveFlexShrink to a method on YGNode
Summary: Move YGNodeResolveFlexShrink to a method on YGNode

Reviewed By: emilsjolander

Differential Revision: D6611418

fbshipit-source-id: 6e5ba39b555d313a967800589891027920112c15
2018-01-08 03:00:46 -08:00
Pritesh Nandgaonkar
40eeefd4f7 Moved YGResolveFlexGrow as a method on YGNode
Summary: Moved YGResolveFlexGrow as a method on YGNode

Reviewed By: emilsjolander

Differential Revision: D6611385

fbshipit-source-id: 71660946c469fac77c5ffa0284c793e6adc9db7b
2018-01-08 03:00:46 -08:00
Pritesh Nandgaonkar
47892c17ce Move markDirtyInternal as a method in YGNode
Summary: Moved YGNodeMarkDirtyInternal as a method in YGNode

Reviewed By: emilsjolander

Differential Revision: D6611287

fbshipit-source-id: 54402145d51ea717553ea136be739b9880a79817
2018-01-08 03:00:46 -08:00
Pritesh Nandgaonkar
f2a369fb73 Move YGCloneChildrenIfNeeded as a method on YGNode
Summary:
- Removed the default() static method, instead of this, its zero argument initialiser is used
  - Moved `YGCloneChildrenIfNeeded` to `cloneChildrenIfNeeded` as a method on `YGNode`.

Reviewed By: emilsjolander

Differential Revision: D6611155

fbshipit-source-id: 463723a363e0fbd2c7686f65226eca73236bd07e
2018-01-08 03:00:46 -08:00
Pritesh Nandgaonkar
61dc10ef66 Optimize the performance of Origami
Summary: With this flag the the workflow successfully passed.

Reviewed By: emilsjolander

Differential Revision: D6619293

fbshipit-source-id: c1632efd97f47696b7f8bb1b3e763de92c707287
2017-12-22 06:55:20 -08:00
Pritesh Nandgaonkar
7d01f4d8b1 Do not set FB_ASSERTION_ENABLED
Summary: Currently whenever `Yoga.h` is imported by someone we set `FB_ASSERTION_ENABLED`. The use case of this flag is to use assert calls of `FBAssert.h`, since we do not use it anymore, there is no need to set this flag.

Reviewed By: emilsjolander

Differential Revision: D6611904

fbshipit-source-id: f01ac144159c1b333d8deb8cbb5ba0288e4bf7a4
2017-12-21 04:56:09 -08:00
Pritesh Nandgaonkar
c7a5e1e290 Fix typo in YogaKit's YGDimensionFlexibility
Summary: Fix typo in `YGDimensionFlexibility` enum

Reviewed By: emilsjolander

Differential Revision: D6601679

fbshipit-source-id: 3a7d98322de3383de65ff5164d4c7a632ac6916f
2017-12-20 03:11:46 -08:00
Pritesh Nandgaonkar
fbd332dee8 Make YGNode as c++ struct with properties exposed through accessors
Summary: Moved c implementation of `YGNode` to C++ struct. Not moving to C++ class as the React Classes dependent on `Yoga.h` assume it to be C. Thats why keeping `Yoga.h` C compatible. Sorry for the long diff, didn't thought that it will turn out to be this much big.Will keep an eye on number of lines next time 😉

Reviewed By: emilsjolander

Differential Revision: D6592257

fbshipit-source-id: 641e8b9462ad00731a094511f9f5608b23a6bb21
2017-12-19 11:33:07 -08:00
Pritesh Nandgaonkar
dbf6a12134 Hide init of YGLayout
Summary:
Make default init unavailable, as it will not initialise `YGNode` which is required for the setters
 and getters of YGLayout's properties to work properly. In setters and getters we call the corresponding `YGNode`'s setters and getters. Thus the following code will crash

```
let layout = YGLayout()
layout.flexDirection = .row
```

Reviewed By: emilsjolander

Differential Revision: D6597796

fbshipit-source-id: 653d275d7314bfdd7a1106884fa3fbc0a13e1be7
2017-12-19 07:48:35 -08:00
Amir Shalem
dbc47ae383 Disable assert code in release builds (define DNDEBUG)
Summary:
Disable assert code in release builds (define DNDEBUG).
This disables assertions in Facebook JNI library - which checks that our references to Yoga JNI objects are correct.
This saves CPU time, since those checks are costly.

Reviewed By: emilsjolander

Differential Revision: D6592023

fbshipit-source-id: eaf869c7990cab3a72ae2bbdc67e709153f5020c
2017-12-18 11:32:36 -08:00
Amir Shalem
f22cfd52e0 Add buck mode/opt compile file to support release compilation mode
Summary:
Currently we have `-O3` hardcoded inside our BUCK target files, this will allow us afterwards to remove that.
Follow up commit will also add `-DNDEBUG` which will disable `assert` in release builds.

Reviewed By: emilsjolander

Differential Revision: D6592024

fbshipit-source-id: f541ee8728ff44db8e31885f2085dc036a400f70
2017-12-18 11:32:36 -08:00
Jonathan Kim
2a10337344 Consolidate mobile yoga into top-level xplat
Reviewed By: emilsjolander

Differential Revision: D6494379

fbshipit-source-id: f6b78d8a1b3d4bcdeef350ad7bd097cdbe5d15b1
2017-12-13 15:08:03 -08:00
Greg McGary
836eaa62df Explicitly #define isnan __builtin_isnan for Android clang-5 to mimic gcc's default behavior
Summary:
GCC internally aliases isnan and a dozen other math.h primitives to their `__builtin_` counterparts, which compile straight to assembler. Clang does not do this, so calls to `isnan` compile to a function call. The Android libc does not define `isnan` because it assumes all application code compiled `__builtin_isnan` and has no need for the function `isnan`.

This is a temporary kludge: Starting with NDK r16, the math.h header has appropriate `#defines` to alias primitives to their `__builtin_` counterparts. Upon upgrade to NDK r16, this can be reverted.

Reviewed By: passy

Differential Revision: D6527499

fbshipit-source-id: 65d9e43c7e7d973a6c92e9863ebe469b35a24ac8
2017-12-12 16:56:48 -08:00
Taras Tsugrii
a01c7adcfb Skylarkify default_platform_defs macros.
Reviewed By: adamjernst

Differential Revision: D6527119

fbshipit-source-id: 1e31b9491d2cf501f348d544482c025096fd81b1
2017-12-09 10:28:47 -08:00
Ben Nham
5133faa1ad Revert D6155682: Use clang-5.0 -Oz
Summary:
This reverts commit 2f64e742f4dc44be171274c2ad0a41fb1e7079d7

bypass-lint

Differential Revision: D6155682

fbshipit-source-id: 9139ed14e0d24784bf25b2783e364a511173ab83
2017-12-08 09:42:21 -08:00
Emil Sjölander
6a8c2960ad New javascript release
Summary: https://www.npmjs.com/package/yoga-layout

Reviewed By: arcanis

Differential Revision: D6496634

fbshipit-source-id: 2d834edcfce6c1e3d3f481822b3ccd22b39e1a13
2017-12-07 19:02:32 -08:00
Greg McGary
0c98e89fdb Use clang-5.0 -Oz
Summary:
Use clang-5.0 -Oz as default NDK compiler for android.
It does 3 good things:
* brings us into compliance with deprecation of gcc for android NDKs since r13
* yields slightly smaller native code, on the order of many-10s-to-small-100s of KB
* slight improvement in startup performance, on the order of 10s of ms

Reviewed By: mzlee

Differential Revision: D6155682

fbshipit-source-id: 2f64e742f4dc44be171274c2ad0a41fb1e7079d7
2017-12-07 13:27:20 -08:00
Yaroslav Pavlov
5f78181911 Round size geometry for Button and RichText components.
Summary:
ComponentKit requires all size geometry provided to be rounded to pixel grid. This ensures
that layout will not truncate provided sizes.

Reviewed By: cuva

Differential Revision: D6466875

fbshipit-source-id: 62a480411e7d2354a6879917c42bbf0ee96cdadd
2017-12-06 16:27:45 -08:00
Pritesh Nandgaonkar
03dd1d23fa vector instead of YGNodeList
Summary: Replaced YGNodeList with std::vector

Reviewed By: jonathandann, emilsjolander

Differential Revision: D6442379

fbshipit-source-id: d2d48ef0676351d2eeaa2d427dcd72e082cd15a1
2017-12-05 08:28:54 -08:00
Luc Dion
91683be798 YogaKit: Changes so we are able to reset properties to their initial value
Summary:
Changes so we are able to reset properties to their initial value.
This is required to reset these properties.

Add the support of YGUnitUndefined to many properties:
* minWidth
* maxWidth
* minHeight
* maxHeight

Also, these properties must be reset to YGUnitAuto.
* width
* height
* flexBasis

This now matches completely how these properties are initialized in Yoga.cpp
Closes https://github.com/facebook/yoga/pull/672

Reviewed By: dshahidehpour

Differential Revision: D6407908

Pulled By: emilsjolander

fbshipit-source-id: ac20c7b2c06349115aea7d31240204d17e2f1b44
2017-12-04 04:26:46 -08:00
Cory Reed
109cb1a562 Fix Android comment and docblock typos
Summary:
👋 Hello! Thanks for react-native, it’s a great project.

I was digging into the Android implementation in _ReactAndroid_ and noticed a couple typos in the documentation. I went through and tried to fix all the typos I could find using [aspell](http://aspell.net).

Not applicable: these changes are only to comments, and CI should be skipped.

[ANDROID][ENHANCEMENT][*] - Correct comment and docblock typos
Closes https://github.com/facebook/react-native/pull/17049

Differential Revision: D6472182

Pulled By: shergin

fbshipit-source-id: 7e62cab118609596b483d1cf16c3abf651d6753b
2017-12-03 20:15:49 -08:00
Lukas Wöhrl
ad1240e276 Fix min/max percentage constraints on measured nodes
Summary:
Fix min/max percentage constraints on measured nodes. Currently we passed in the available size instead of the parent size.
Fixes #611
Closes https://github.com/facebook/yoga/pull/649

Reviewed By: priteshrnandgaonkar

Differential Revision: D6408019

Pulled By: emilsjolander

fbshipit-source-id: 18be5056dbc0dc179970ec231ab8b4e2cdba65c5
2017-11-30 08:02:05 -08:00
Emil Sjölander
2e468d9c8c Update watir
Summary: We were using a very out-dated version of watir which did not run with latest ruby

Reviewed By: priteshrnandgaonkar

Differential Revision: D6447029

fbshipit-source-id: ff4ccb8c96947811ff09f7e87cb504e3e7cb834e
2017-11-30 07:01:32 -08:00
Huge Rocker
6caa94b779 Fix can not find source files in CMakeLists.txt
Summary:
Because the source files are *.cpp, not *.c. This fixes building issue with gradle.
Closes https://github.com/facebook/yoga/pull/676

Reviewed By: emilsjolander

Differential Revision: D6446545

Pulled By: priteshrnandgaonkar

fbshipit-source-id: 809229057db26665b2d97b3002ade73632dd9117
2017-11-30 07:01:31 -08:00
Lukas Wöhrl
429a7eeee3 Suppress unused warnings on YGDefaultLog
Summary:
Suppresses the unused warnings on ```YGDefaultLog```. It uses a more generic macro which simply casts the variable to ```(void)```. This is the simples approach to make mutiple different compilers happy. Fixes #650
Closes https://github.com/facebook/yoga/pull/651

Differential Revision: D6407999

Pulled By: emilsjolander

fbshipit-source-id: 19fd78dd8b84eafdbb48875dd003d506a98c4807
2017-11-28 10:26:07 -08:00
Taras Tsugrii
dec1172f38 Migrate yoga defs to Skylark syntax.
Summary: https://our.intern.facebook.com/intern/dex/buck/python-to-skylark/

Reviewed By: adamjernst

Differential Revision: D6411822

fbshipit-source-id: 2abe2c183d1b1a28349d0c7bd765754688ec4441
2017-11-27 14:00:52 -08:00
Lukas Wöhrl
afaafb4126 Measure nodes which have margin: auto and align-item: stretch
Summary:
If you have a measurable node and set ```marign-left: auto``` + ```align-item:stretch``` on it, it won't get measured and they get a width/height of ```-(nan)```. This change fixes that behaviour. Fixes #644.
Closes https://github.com/facebook/yoga/pull/645

Differential Revision: D6413512

Pulled By: emilsjolander

fbshipit-source-id: 755febeb33bb0d4520ca6b3c28d56ac333e4a14d
2017-11-27 05:36:48 -08:00
Jake Larson
e566fcca08 Fix invalid value check for entry-common.js
Summary:
`!Object.prototype.hasOwnProperty.call(methods, unit))` doesn't correctly return `true` when an unsupported value is passed into `setMaxWidth` within an Automator (macOS) javascript/cocoascript environment.

This PR fixes the issue and also adds the `value` information to the returned error to help with debugging
Closes https://github.com/facebook/yoga/pull/643

Differential Revision: D6413569

Pulled By: emilsjolander

fbshipit-source-id: a42a66710a3ca578b5c25ecef8722f9c3f082b73
2017-11-27 05:12:37 -08:00
vincentriemer
c7f7ba250c Add Config::setPointScaleFactor to JavaScript binding
Summary:
Needed for a project I'm working on to properly render on high dpi screens. I've manually tested against my project to confirm it works.
Closes https://github.com/facebook/yoga/pull/612

Differential Revision: D6413517

Pulled By: emilsjolander

fbshipit-source-id: c298d7f6b58dc45aaaede2bb995df8615911a4a9
2017-11-27 04:59:53 -08:00
Lukas Wöhrl
7e3be21811 Add justify-content: space-evenly
Summary:
Adds new ```space-evenly``` for ```justify-content```.

Also adds a typofix in one of the other justify-content tests.

Fixes #657
Closes https://github.com/facebook/yoga/pull/658

Differential Revision: D6407996

Pulled By: emilsjolander

fbshipit-source-id: cc837409e1345624b4bd72c31e25fe68dcb0f6a3
2017-11-27 03:47:23 -08:00
Lukas Wöhrl
5e39f1a57c Fix shrinking in non strech alignments while retaining legacy behaviour
Summary:
This fixes shrinking of elements which are in a non stretch alignment, but keeps the legacy stretch behaviour in place. Additionally this adds a testcase for ```useLegacyStretchBehaviour```

Fixes #633
Closes https://github.com/facebook/yoga/pull/635

Differential Revision: D6408037

Pulled By: emilsjolander

fbshipit-source-id: 377ab0308dd3a75a148a0af31ab5eb3ffb5b5d83
2017-11-27 03:14:59 -08:00
Lukas Wöhrl
5aa0f44a9b Do not mark node as dirty if, new and old values are undefined
Summary:
If we have a values already set to undefined and set it to undefined again, we invalidate the layout. This change takes this case into account and keeps the layout valid.
Fixes #630
Closes https://github.com/facebook/yoga/pull/648

Differential Revision: D6408013

Pulled By: emilsjolander

fbshipit-source-id: dc2a848d84d3de9f4650fac9e41d7c8169446406
2017-11-27 03:14:54 -08:00
Jake Teton-Landis
55c767ba7f Fix assertion preventing YGNodeLayoutGet* with YGEdgeEnd
Summary:
Expected to be able to call `YGNodeLayoutGetMargin(node, YGEdgeEnd)`, but instead, the program aborts with `"Cannot get layout properties of multi-edge shorthands"`.

This bug seems to incorrectly prevent properties from YGEdgeEnd for all Layout properties.
Closes https://github.com/facebook/yoga/pull/632

Differential Revision: D6408060

Pulled By: emilsjolander

fbshipit-source-id: 4ab3b2ffb2f1bb6fd3a27f780caf0123abcdb230
2017-11-27 03:00:05 -08:00
Taras Tsugrii
5502a97f7f Replace include_defs with load.
Summary: https://our.intern.facebook.com/intern/dex/buck/python-to-skylark/

Reviewed By: adamjernst

Differential Revision: D6411777

fbshipit-source-id: 5553d75a650d906a280a61b38492e20d7bc7081a
2017-11-26 21:30:14 -08:00
Taras Tsugrii
8ab1d81917 Do not use isdir in build files.
Summary: This leads to slow, non-reproducible builds.

Reviewed By: adamjernst

Differential Revision: D6411750

fbshipit-source-id: 566424fa813edd20813da15101e6640d6c8fff19
2017-11-26 21:05:54 -08:00
Alexander Sarkisov
942543f6a5 Add default block attribute.
Summary:
It is very inconvenient to enter block attribute name for each view in Objective-C.
Closes https://github.com/facebook/yoga/pull/618

Differential Revision: D6408138

Pulled By: emilsjolander

fbshipit-source-id: 71fe8eadda7233e5055560667d0fc3840ab7259b
2017-11-24 08:12:33 -08:00
Lukas Wöhrl
a69545a6ae Fix justify content with min/max constraint parent
Summary:
The min/max inner width shouldn't take the margins into account.
Adds a test for both cases.

Fixes #664
Closes https://github.com/facebook/yoga/pull/665

Differential Revision: D6407982

Pulled By: emilsjolander

fbshipit-source-id: ffa549a06f802263e3b8488e90756aa3f722d52d
2017-11-24 07:24:51 -08:00
Lukas Wöhrl
0b13a0c168 Fix generation of license header for java
Summary:
If you run ```enums.py``` it will revert the changes from 835b2bb . This changes the license header for java to  not be a javadocs comment.
Closes https://github.com/facebook/yoga/pull/660

Differential Revision: D6407985

Pulled By: emilsjolander

fbshipit-source-id: 49efe555fecb8d740675c6b4631dce2a64f10417
2017-11-24 06:57:23 -08:00
Yury Zholobov
d8341ca3b0 Fix horizontally to vertically in FlexDirection=Column doc
Summary: Closes https://github.com/facebook/yoga/pull/663

Differential Revision: D6407915

Pulled By: emilsjolander

fbshipit-source-id: 03e2896b9b98cf476a92e7c87fd8dc3f7cef9047
2017-11-24 06:26:37 -08:00
Pritesh Nandgaonkar
34ac314101 Refactor and move YGNodeToString implementation to different file
Summary: Refactored the `YGNodeToString` function from c to c++.

Reviewed By: emilsjolander

Differential Revision: D6397372

fbshipit-source-id: 79e701efe7f19db6dac1aea6328ebf0ac84a7ac3
2017-11-23 09:42:21 -08:00
Pritesh Nandgaonkar
02c00f2711 Change c files to cpp
Summary: Changed the extensions of c files to cpp and made the project build successfully

Reviewed By: gkassabli

Differential Revision: D6271299

fbshipit-source-id: 66c0e54ccf019d72d1fd0b4d117826e4e84fdc89
2017-11-21 10:28:51 -08:00
Flarnie Marchan
15231c3304 Add Code of Conduct
Summary:
**what is the change?:**
Adding a document linking to the Facebook Open Source Code of Conduct,
for visibility and to meet Github community standards.

**why make this change?:**
Facebook Open Source provides a Code of Conduct statement for all
projects to follow.

Exposing the COC via a separate markdown file is a standard being
promoted by Github via the Community Profile in order to meet their Open
Source Guide's recommended community standards.

As you can see, adding this file will complete [Yoga's Community Profile](https://github.com/facebook/yoga/community)
checklist and increase the visibility of our COC.

We also added a link to the COC in the CONTRIBUTING doc because folks may miss the separate CODE_OF_CONDUCT document.

**test plan:**
Viewing it on my branch -
![screen shot 2017-11-20 at 6 02 25 pm](https://user-images.githubusercontent.com/1114467/33051133-4dc293e6-ce1d-11e7-9b0a-776cad6211f5.png)
![screen shot 2017-11-20 at 6 02 33 pm](https://user-images.githubusercontent.com/1114467/33051135-4dee35fa-ce1d-11e7-9077-a2d6d6f2ed3e.png)

**issue:**
internal task t23481323
Closes https://github.com/facebook/yoga/pull/670

Reviewed By: emilsjolander

Differential Revision: D6384655

Pulled By: flarnie

fbshipit-source-id: 6c5557094719cc8f1b08deb4d477ab56603caf39
2017-11-21 05:27:53 -08:00
Pritesh Nandgaonkar
d98e5aef97 Deleted YGSetMemoryFucs as it is unused
Summary: Removed YGSetMemoryFuncs, as it is not used internally and barely externally.

Reviewed By: emilsjolander

Differential Revision: D6374147

fbshipit-source-id: 8c896dce23571268a1a52df5cc72486af9d66df7
2017-11-21 03:43:23 -08:00
Pritesh Nandgaonkar
5b0dfa471f Use internal clang format settings
Summary: Use internal linting rules instead of the custom once.

Differential Revision: D6284667

fbshipit-source-id: 65aae336f1d7f14dfefed7391b0f5b89b333495e
2017-11-20 03:17:53 -08:00
Pritesh Nandgaonkar
26481a6553 Replace printf with YGLog calls
Summary: Replace printf calls with YGLog

Reviewed By: gkassabli

Differential Revision: D6297015

fbshipit-source-id: 6a67bdf33ef121785ac14938f5d3ed6e9d6f2656
2017-11-16 05:43:23 -08:00
Pascal Hartig
64e08aa98b v1.7.1-SNAPSHOT
Summary: Back to snapshot releases.

Reviewed By: emilsjolander

Differential Revision: D6284123

fbshipit-source-id: 30ec356d0da63e7bf6c33cbc20d446aea7be5a05
2017-11-16 03:15:52 -08:00
Pascal Hartig
0c3168f150 v1.7.0
Summary: Version bumps.

Reviewed By: emilsjolander

Differential Revision: D6284124

fbshipit-source-id: 08f6116bb0237791210847976533206055376f1a
2017-11-16 03:15:52 -08:00
Pascal Hartig
40861c699e Modernize Android build system, bump dependencies
Summary:
- Build against Android SDK 26
- Upgrade to Gradle 4
- Upgrade to Android Plugin 3.0, adjust dependency management accordingly
- Upgrade Maven deployment plugin

Reviewed By: emilsjolander

Differential Revision: D6272007

fbshipit-source-id: b198b4c8e1a94e2ee031ad26193fdfdf5b52adf1
2017-11-08 09:47:26 -08:00
Daniel Tsuan
d8fee24778 Set link_whole true for YogaKit and IGListKit
Summary: For our -objc efforts we'll be excluding vendorlibs from these changes for now and then working on getting them to not have to be fully linked as a second effort. The way -objc flag works is its an all or nothing flag for the app and thus for any library we still want to link completely we'll have to add a link_whole = True to the BUCK file. (Otherwise we'll have crashes in these libraries :P).

Reviewed By: kastiglione

Differential Revision: D6252740

fbshipit-source-id: fe074977a11b70c4aa63a4c69cb7518906c98eb9
2017-11-07 14:36:48 -08:00
Richard Ross
5c617a5947 Mirror AsyncExecutor, yoga, and nanosvg to fbcode.
Summary: We'll need these libraries for rainbow, and none of them exist in fbcode.

Reviewed By: mzlee

Differential Revision: D5897801

fbshipit-source-id: c379b76fef2ab204555ceded0834efc6ba932f90
2017-11-01 16:42:21 -07:00
Chandra Patni
ff0a3f39d9 use > || YGFloatsEqual instead of >= for computing round value to pixel grid
Summary: YGRoundValueToPixelGrid does not handle float point values correctly. It causes layout bugs in arm 32 devices. The way values are rounded to pixel grid is the following: if value is close to the left pixel - discard error and set it equal to left pixel. If value is close to right pixel - set it equal to the right pixel. Otherwise if value is closer to the left - set it equal to the left, closer to the right - set it equal to the right. The problem is when values are close to the middle. Old implementation could produce either left or right boundaries. This patch moves all values that are close to the middle to right boundary. This way results are consistent.

Reviewed By: emilsjolander

Differential Revision: D6202484

fbshipit-source-id: bb80235452208caec388775574cc4f07bfd649c4
2017-11-01 15:52:49 -07:00
Georgiy Kassabli
bfb4dabf0c Fixing the edge case in Yoga with percentage absolute position and infinite constraint
Summary: Yoga has an edge case that cause layout to return NaN. This happened when we used absolute position with percentage and infinite constraint in that dimension. This diff fixes that case to default to border+padding

Reviewed By: emilsjolander

Differential Revision: D6199731

fbshipit-source-id: f40ddf00614b2f507848fb35f348a9dfef14b323
2017-11-01 06:40:10 -07:00
Pritesh Nandgaonkar
58d14ee557 Reverting the dirty child optimization
Summary: Reverting D6134754

Reviewed By: emilsjolander

Differential Revision: D6203290

fbshipit-source-id: 8e42abb70e55f0fac90faaa21ecdbe0fbb76ce6b
2017-10-31 23:23:01 -07:00
Pritesh Nandgaonkar
c5182c4bf5 Used hasDirtyChildren tag for the optimization
Summary:
More fine grained dirty marking

Currently a node's dirty flag propagates to the root of the tree ensuring that when any node is invalidated its whole subtree will be re-calculated. This is often times not needed. There are many properties which only effects a node's children and would not need to propagate all the way to the root such as align-items. Also in cases where the style does change layout it may not need to propagate all the way to the root but can often stop at the nearest position: absolute parent.

This change has the potential of greatly improving performance of re-calculating a tree.

This might require adding a second dirty flag named hasDirtyDescendants ensuring that traversal still works even though a parent is not marked as dirty.

Reviewed By: emilsjolander

Differential Revision: D6134754

fbshipit-source-id: bbcfee14058140b946401de756a3f130de0f51cd
2017-10-31 08:22:29 -07:00
Jonathan Keljo
132b016bae Automated fixups for Instagram
Summary:
Source-only ABIs are a new feature of Buck that allows massive parallelism
by generating ABI jars from just the source code (without looking at most
dependencies). Because dependencies are not available, the generator
makes assumptions about how we write Java code. This commit updates
Instagram's code to conform to those assumptions.

These changes were generated by Buck's automatic migration script.

Reviewed By: dreiss

Differential Revision: D6168048

fbshipit-source-id: 0e51319d93fd697db01ea3933f48cd06a6ffac12
2017-10-27 01:14:24 -07:00
Sebastian Markbage
4785e95a0c Persistent Yoga
Summary:
This is meant to show a possible route format for a persistent form of Yoga. Where previous layouts can remain intact while still taking advantage of incremental layout by reusing previous subtrees.

```c
YGNodeRef YGNodeClone(const YGNodeRef node);
```

The core of this functionality is a new API to clone an existing node. This makes a new detached node with all the same values as the previous one. Conceptually this makes the original node "frozen" from that point on. It's now immutable. (This is not yet enforced at runtime in this PR but something we should add.)

Since the original is frozen, we reuse the children set from the original node. Their parent pointers still point back to the original tree though.

The cloned node is still mutable. It can have its styles updated, and nodes can be inserted or deleted. If an insertion/deletion happens on a cloned node whose children were reused, it'll first shallow clone its children automatically.

As a convenience I also added an API to clear all children:

```c
void YGNodeRemoveAllChildren(const YGNodeRef node);
```

During insert/delete, or as a result of layout a set of reused children may need to be first cloned. A kind of copy-on-write. When that happens, the host may want to respond. E.g. by updating the `context` such as by cloning any wrapper objects and attaching them to the new node.

```c
typedef void (*YGNodeClonedFunc)(YGNodeRef oldNode,
                                 YGNodeRef newNode,
                                 YGNodeRef parent,
                                 int childIndex);

void YGConfigSetNodeClonedFunc(YGConfigRef config,
                               YGNodeClonedFunc callback);
```

This PR doesn't change any existing semantics for trees that are not first cloned.

It's possible for a single node to exist in two trees at once and be used by multiple threads. Therefore it's not safe to recursively free a whole tree when you use persistence. To solve this, any user of the library has to manually manage ref counting or tracing GC. E.g. by replicating the tree structure in a wrapper.

In a follow up we could consider moving ref counting into Yoga.
Closes https://github.com/facebook/yoga/pull/636

Reviewed By: emilsjolander

Differential Revision: D5941921

Pulled By: sebmarkbage

fbshipit-source-id: c8e93421824c112d09c4773bed4e3141b6491ccf
2017-10-17 01:11:11 -07:00
Pascal Hartig
be94a5ef8d Fix NDK download in Travis
Summary:
After about 500MB, Travis seems to kill the TLS connection. Could be a traffic
limit, could be a timeout. I've only seen this for their MacOS boxes. We're now
retrying a few times with curl, which seems to work.

Reviewed By: emilsjolander

Differential Revision: D6051024

fbshipit-source-id: feb73bfb9fd81b2a8b9b4d33d4e9f230a9899a66
2017-10-13 06:56:18 -07:00
Pascal Hartig
208b70a93c Fix license check
Summary: This seems to have changed upstream.

Reviewed By: emilsjolander

Differential Revision: D6050471

fbshipit-source-id: b453831c1d5a5974572265a78da40b0612b1d1f2
2017-10-13 03:56:35 -07:00
Pascal Hartig
6c3155ae3b Download right NDK for Travis
Summary:
I'm a big dummy.

https://travis-ci.org/facebook/yoga/jobs/257605319

Reviewed By: emilsjolander

Differential Revision: D6040274

fbshipit-source-id: e73225e6e2e1e899c25326030ac522d5a7aa06a5
2017-10-12 08:41:55 -07:00
Pascal Hartig
32f071c2ad Fix NDK download
Summary: Fix NDK download for Travis.

Reviewed By: emilsjolander

Differential Revision: D6020352

fbshipit-source-id: c7523c0afb18d675fc2443e133d5ab63109fec7b
2017-10-11 08:19:51 -07:00
Pascal Hartig
fdd1dbe3a9 Update buildScript deps
Summary:
The native-dependencies plugin seems unused. Upgrade to the latest
gradle-bintray-plugin version that's supported for the current Gradle version.

I'll hold back the upgrade to Gradle 4 until the Gradle Android Plugin for the
version hits stable.

Reviewed By: IanChilds

Differential Revision: D5986549

fbshipit-source-id: d26aa19e9eba40a2b30b20d5ffa9d2b006450f95
2017-10-06 02:26:15 -07:00
Pascal Hartig
1ca5bb694d Use NDK 15c
Summary: To match internal config.

Reviewed By: emilsjolander

Differential Revision: D5986514

fbshipit-source-id: b0e7dbc060c106f17f8e1c5e54e5b951d9e3e350
2017-10-06 02:26:15 -07:00
Marko Novakovic
b4cfaa916c Un-inline-ing a method declared as export
Reviewed By: compnerd

Differential Revision: D5909847

fbshipit-source-id: 7108dd88271e640e1881b20c0cbf1ad28bbf63c9
2017-09-26 19:12:42 -07:00
Michael Lee
fc6c85996e Reformat BUCK files
Summary: Reformat BUCK files to better conform with style.

Reviewed By: zertosh

Differential Revision: D5901515

fbshipit-source-id: 93e8c56450f65b691af9017d880e6cf2a2cdb7af
2017-09-25 10:16:22 -07:00
Andrew Gallagher
969f055f47 Deprecate older API uses of prebuilt_cxx_library
Summary:
Use the `deprecated_prebuilt_cxx_library` wrapper instead of the deprecated
API of `prebuilt_cxx_library`.

Reviewed By: ttsugriy

Differential Revision: D5878523

fbshipit-source-id: 2c8c1fd1d19597ff7459bbd527c89573520db74b
2017-09-22 13:27:32 -07:00
Bin Yu
58328d01ef Add 'useYoga' property to indicate whether UIView uses Yoga for layout or not
Summary: Now developer could check whether UIView uses Yoga for layout.

Reviewed By: emilsjolander

Differential Revision: D5881242

fbshipit-source-id: 4d1cf0b489b759ff0b9c5091cc51534fd12dcf60
2017-09-21 10:18:52 -07:00
Mingwei Pan
d90914f3dc Improve formatting of YogaNode.print() on Android
Summary:
The Android logger adds newline automatically, which makes the log ugly on Android.
To avoid that, wrap the android logger, print to a memory buffer.  Call __android_log_write() when '\n' is detected.

Reviewed By: emilsjolander

Differential Revision: D5842889

fbshipit-source-id: 8ecc829dc43614934c47fd3a68317259e403325a
2017-09-21 07:41:37 -07:00
Emil Sjolander
3a0a86788e Revert D5874862: [yoga][PR] Fix shrinking in non strech alignments
Summary:
This reverts commit 1426aa6b60f6ba42c2be702e6f24cea935ab7acb

bypass-lint

Differential Revision: D5874862

fbshipit-source-id: 24517d26b18c11fb9f75c6d3b5faae360711ea9e
2017-09-21 03:41:19 -07:00
Lukas Wöhrl
a77aa9a41e Fix shrinking in non strech alignments
Summary:
This fixes shrinking of elements which are in a non stretch alignment

Fixes #633
Closes https://github.com/facebook/yoga/pull/634

Differential Revision: D5874862

Pulled By: emilsjolander

fbshipit-source-id: 1426aa6b60f6ba42c2be702e6f24cea935ab7acb
2017-09-20 13:30:39 -07:00
Shaddix
7217471427 fix build, correctly size UIScrollViews
Summary: Closes https://github.com/facebook/yoga/pull/626

Reviewed By: emilsjolander

Differential Revision: D5824425

Pulled By: splhack

fbshipit-source-id: e1a8dda5e86e2705afa7f6630a6757491a94c6d6
2017-09-19 09:41:41 -07:00
Mingwei Pan
bcc36cc1b2 Zero out all fields in YGZeroOutLayoutRecursivly using memset
Summary:
Add a new test named YGZeroOutLayoutRecursivlyTest, which verifies that padding and margin of a child node should be set to 0 when the display is set to none.
Modify YGZeroOutLayoutRecursivly function, use memset to clear the layout struct of the node.

Reviewed By: emilsjolander

Differential Revision: D5842351

fbshipit-source-id: d2c2b6f829588a200525b7ccbdb63003cb4dcc4e
2017-09-15 08:32:36 -07:00
Amir Shalem
16052085d0 Fix YogaLogger leakage when removing it from YogaConfig
Summary: -

Reviewed By: emilsjolander

Differential Revision: D5802035

fbshipit-source-id: 79c1f8c3cc5ddf3abd51206f23e076f2410cfc0c
2017-09-11 03:14:11 -07:00
Lukas Wöhrl
c20f2864ab Only add UIView nodes to Yoga where they are enabled
Summary:
Only add UIView nodes to Yoga where they are enabled.

We check for it in `isLeaf` but I think we should also check for them in the check for sub views.
Closes https://github.com/facebook/yoga/pull/609

Reviewed By: emilsjolander

Differential Revision: D5643387

Pulled By: dshahidehpour

fbshipit-source-id: a85c62b6b2e0120b2913e7f2df8b094d43ca49a6
2017-08-23 15:46:51 -07:00
Lukas Wöhrl
4185a44393 Fix const declaration mismatch and double/float mix
Summary:
This PR fixes a declaration mismatch for `YGNodeCanUseCachedMeasurement` where the last argument is declared non `const` in `.h` and `const` in `.c`.

Additionally it uses explicit `float` for fraction calculation do avoid usage of `double` assignment.
Closes https://github.com/facebook/yoga/pull/607

Differential Revision: D5677931

Pulled By: emilsjolander

fbshipit-source-id: 502da957089e4439ed956987ff8dec10bd033ba3
2017-08-23 03:02:16 -07:00
Scott Wolchok
c79c5e3c9d Make gYGNodeDefaults const
Summary: At least one compiler seems to care about it.

Reviewed By: emilsjolander

Differential Revision: D5675518

fbshipit-source-id: 72a6e208263dde0b6bb46a78fedb2796d0e0a600
2017-08-22 11:56:21 -07:00
Emil Sjolander
35a9f33abb BREAKING: Change aspect ratio behavior
Summary:
@public

== Before ==
- Aspect ratio would do its best to fit within it's parent constraints
- Aspect ratio would prioritize `alignItems: stretch` over other sizing properties.

== After ==
- Aspect ratio is allowed to make a node grow past its parent constraints. This matches many other aspects of flexbox where parent constraints are not treated as hard constraints but rather as suggestions.
- Aspect ratio only takes `alignItems: stretch` into account if no other size definition is defined. This matches the interaction of other properties with `alignItems: stretch`.

== Updating your code ==

**You probably don't need to do anything** but in case something does break in your product it should be as easy as  adding `{width: '100%', height: '100%', flexShrink: 1}` to the style declaring the `aspectRatio`.

Reviewed By: gkassabli

Differential Revision: D5639187

fbshipit-source-id: 603e8fcc3373f0b7f2461da2dad1625ab59dcb19
2017-08-21 03:12:00 -07:00
Hoa Dinh
32f128640b Revert D5643382: [yoga][PR] Fix a typo in YogaKit,
Summary:
This reverts commit 127b0c11dbfd76d298db823e65fd2f6e365642e7

bypass-lint

Differential Revision: D5643382

fbshipit-source-id: f25b04680428bcd4515c44741ed72a004be43ef1
2017-08-17 15:48:47 -07:00
Luc Dion
18d19af7ec Fix a typo in YogaKit,
Summary:
`YGDimensionFlexibilityFlexibleHeight` it was wrongly spelled `YGDimensionFlexibilityFlexibleHeigth`.

[X] Test suite passes
[X] Contributor License Agreement
Closes https://github.com/facebook/yoga/pull/605

Reviewed By: amonshiz

Differential Revision: D5643382

Pulled By: dshahidehpour

fbshipit-source-id: 127b0c11dbfd76d298db823e65fd2f6e365642e7
2017-08-17 14:42:03 -07:00
Levi McCallum
2ee2dd439f Fix link to YGLayout header in docs
Summary: Closes https://github.com/facebook/yoga/pull/595

Reviewed By: amonshiz

Differential Revision: D5643379

Pulled By: dshahidehpour

fbshipit-source-id: ae972f270ee26fe7755ba5dee4d357d150a27c2a
2017-08-17 13:56:37 -07:00
Lior Tubi
5edfb679e7 Add a java binary buck target
Summary: .

Reviewed By: amir-shalem

Differential Revision: D5619667

fbshipit-source-id: e956190be0c6a7ea573e5511231de28aab5586fe
2017-08-13 07:32:11 -07:00
Georgiy Kassabli
f45059e1e6 Fixing edge case issue in Yoga where text node was unnecessary rounded down
Summary: There was an uncovered edge case where number close to the whole was forced to round down because it was considered non-whole and had forced flooring. This diff covers that + adds a bunch of test cases to cover rounding function

Reviewed By: emilsjolander

Differential Revision: D5465632

fbshipit-source-id: 57e11092a97eba5dd76daad15fa8619535ff9c1b
2017-07-26 19:38:31 -07:00
Pascal Hartig
c9384762ee Fix NDK build, Take II
Summary:
There was one incorrect path and some caching problems. I hope this will take
care of it for good.

Reviewed By: emilsjolander

Differential Revision: D5470120

fbshipit-source-id: 17c9e783c952c92fa5c2ccfb18107a59d8a80e3d
2017-07-21 08:29:43 -07:00
Pascal Hartig
7ea50439ce Fix travis NDK setup
Summary:
Phew, this took a while. Buck had some changes in how it picks up SDK/NDK
configs.

In order to satisfy the new demands, I'm now installing the NDK manually and no
longer through the SDK manager. I'm also trying to cache as much as possible to
reduce the flakiness here.

Reviewed By: emilsjolander

Differential Revision: D5465206

fbshipit-source-id: 61a4b9006fe96fc9a99fb9d75b822589064a9d1a
2017-07-21 03:14:21 -07:00
Pascal Hartig
154e67adbc Bump to 1.6.1-SNAPSHOT
Summary:
Set to the next snapshot version so automatic snapshot publishing is reenabled.
We need those to keep in sync with the Litho snapshots.

Reviewed By: emilsjolander

Differential Revision: D5442493

fbshipit-source-id: ecb92071ec8edb9c3c6b625c08f5aad20368d0a3
2017-07-18 11:46:10 -07:00
Lukas Wöhrl
570a193b7e Update c# docs to use object initializer
Summary:
Updates the C# docs to use the object initializer instead of `Create` which doesn't exist anymore.

Fixes facebook/yoga#550.
Closes https://github.com/facebook/yoga/pull/601

Reviewed By: emilsjolander

Differential Revision: D5427217

Pulled By: splhack

fbshipit-source-id: 9a2f036335e5ab475d5c1ee8308701ccb5a3b4e4
2017-07-14 16:13:07 -07:00
Emil Sjolander
79e294c927 1.6.0 version bumps
Reviewed By: passy

Differential Revision: D5415450

fbshipit-source-id: cf3c42303c4a63adf114199618d42dabdb123c42
2017-07-13 08:27:10 -07:00
Georgiy Kassabli
5d75c7c4c8 Fixing the issue with node dimensions rounding in Yoga
Summary: Yoga had a bug in Rounding calculation that caused text nodes dimensions to be rounded up even when the dimensions didn't need rounding

Reviewed By: emilsjolander

Differential Revision: D5406211

fbshipit-source-id: df1d54ed0805dfc3abbd8f0ceae30f6d8c26d61a
2017-07-12 09:33:51 -07:00
vincentriemer
7c688cea68 Add babel processing to browser build to remove references to node builtins
Summary:
Currently the nbind asm.js output generates boilerplate code which can conditionally load node's `fs` and `path` modules. If this output is run directly in the browser there are no issues but if you run it through a bundler the build step will fail trying to resolve the node builtins.

Workarounds currently exist for bundlers like webpack (mentioned in #444) but this is not a safe assumption to make (for example such workarounds don't exist for `metro-bundler`).

I am by no means suggesting that this is the perfect solution but this might provide a stop-gap fix for people who are currently blocked by this issue (like I am).
Closes https://github.com/facebook/yoga/pull/585

Differential Revision: D5388660

Pulled By: emilsjolander

fbshipit-source-id: d3a51eb852df35e3d0610158fe7d9f5754e4e684
2017-07-10 12:00:37 -07:00
Lukas Wöhrl
7640cd667f Reset the hadOverflow flag at the beginning of the algorithm
Summary:
This fixes the case where we change the layout, so that it doesn't overflow anymore.

This also improves the readability by using `|=` instead of referencing the value twice.
Closes https://github.com/facebook/yoga/pull/587

Differential Revision: D5388657

Pulled By: emilsjolander

fbshipit-source-id: ce1b1ded1feed7314a2c16bf695f62b866c19ea0
2017-07-10 12:00:37 -07:00
Lukas Wöhrl
24e2fc95dd Fix text node rounding with fractional dimensions matching the rounding factor
Summary:
If we have a fractional measure output which matches the subpixel rounding factor, we still should round both dimension into the same direction.

Fixes facebook/yoga#580.
Closes https://github.com/facebook/yoga/pull/583

Reviewed By: marco-cova

Differential Revision: D5274212

Pulled By: emilsjolander

fbshipit-source-id: 1febf9194210437ab77f91319d10d4da9b284b79
2017-07-04 06:27:24 -07:00
Andrey Mishanin
ce3f99939f Overflow detection in Yoga
Summary:
We need to provide Yoga clients with means of detecting overflow in flexbox layout. This information can be used later to identify a non-overflowing layout variant among others.

Flexbox layout considered overflown if (this is *not* an exhaustive list):

- if any child node overflows
- [no-wrap] total flex basis of all child nodes is greater than available space in parent and there are no flexible children
- [no-wrap] after flexing there is still not enough space to layout all child nodes

Reviewed By: gkassabli

Differential Revision: D5336645

fbshipit-source-id: c4f87d1754d7bac848e8d347b31d619393b94d2c
2017-06-30 09:26:57 -07:00
Lior Tubi
11bc97b16c Don't load fb native library
Summary: We don't bundle this library with the yoga source, and it isn't needed.

Reviewed By: emilsjolander

Differential Revision: D5274172

fbshipit-source-id: fec47d2700da86498410fe445d2980f31a563551
2017-06-19 05:42:52 -07:00
Matthew Jarjoura
4804bcd594 make sure YGPointValue works in Obj-C++
Summary:
This is an easy diff to wrap YGPointValue() in an extern "C" block to make sure it compiles
when we are using inside of Objective-C++ classes.

Reviewed By: emilsjolander

Differential Revision: D5242366

fbshipit-source-id: 772aaac056b3a20041926d5f35128716848a271a
2017-06-16 11:12:31 -07:00
Lukas Wöhrl
ca2c607f90 The total flex factores need to be a minimum of 1 if any
Summary:
The only thing I found in the spec for this change is the following. Not exactly sure if this is the thing this PR is about:

> For each flex item, subtract its outer flex base size from its max-content contribution size. If that result is not zero, divide it by (if the result was positive) its **flex grow factor floored at 1** or (if the result was negative) by its scaled flex shrink factor, having **floored the flex shrink factor at 1**. This is the item’s max-content flex fraction.

But at least it seems a required change.

Fixes facebook/yoga#566
Closes https://github.com/facebook/yoga/pull/572

Differential Revision: D5264388

Pulled By: emilsjolander

fbshipit-source-id: 0004d1c3b9bad070a98cd6766c1adc06a54475f8
2017-06-16 07:46:06 -07:00
sospartan
6c67684fa6 Change android minimum SDK version to 14
Summary:
The library(yoga) has no dependency on android framework. As a matter of
fact this version can change to a lower number which will make yoga
support more old systems.

According to I/O 17, support library has change its minimum SDK version
 to 14, so I think 14 is a reasonable min support version for yoga as well.

See
https://developer.android.com/topic/libraries/support-library/revisions.html
Closes https://github.com/facebook/yoga/pull/573

Differential Revision: D5264385

Pulled By: emilsjolander

fbshipit-source-id: cb813a3b643a3f4e2034c6c0ab8b488f94d6a7d0
2017-06-16 06:43:28 -07:00
Pascal Hartig
835b2bbae8 Fix license headers
Summary:
They were set up as javadocs (double-asterisk at the start) but should be normal
block headers.

Reviewed By: IanChilds

Differential Revision: D5255424

fbshipit-source-id: 23439ac035f74f2fd1c756b8185e39199e748e33
2017-06-15 07:41:44 -07:00
Pascal Hartig
47edd2586c Bump gradle plugin version
Summary:
Same as litho, just for compat with Android Studio. Shouldn't affect the
project.

Reviewed By: emilsjolander

Differential Revision: D5217956

fbshipit-source-id: 32cfec0bf4ab4e51f5e4116149ee091cf1245e95
2017-06-10 08:28:58 -07:00
Marco Cova
ca483cae00 Rounding error in width/height fixed
Summary: If the width has an exact dimension, while the left and right edges have a decimal part, that means the decimal part is equal and we can round both down instead of rounding left down and right up. Same for top and bottom.

Reviewed By: emilsjolander

Differential Revision:
D5209073

Tags: accept2ship

fbshipit-source-id: a3a6a43767aa707ebfa5eee62a83adcdd88d7ce6
2017-06-10 05:45:35 -07:00
Lukas Wöhrl
a20bde8444 Fix absolute position if wrap-reverse and align-items: flex-end
Summary:
This is a fix on top of 56b10fc. It takes the case into account were you have `wrap-reverse` and `align-items: flex-end` set.
Closes https://github.com/facebook/yoga/pull/568

Differential Revision: D5155521

Pulled By: emilsjolander

fbshipit-source-id: 7e5fcfa2fbb48b6c6279da46cc648a071ff2b079
2017-06-01 05:41:25 -07:00
Christian Oliff
ac885626b3 Correct capitalization of JavaScript
Summary:
Correct capitalization of JavaScript
Closes https://github.com/facebook/yoga/pull/569

Differential Revision: D5155524

Pulled By: emilsjolander

fbshipit-source-id: 48d9a28a61bb96af42241aa2ed6ac3d070adeaf9
2017-05-31 10:27:00 -07:00
Emil Sjolander
976ecc6816 Version bump
Summary: Version bump

Reviewed By: passy

Differential Revision: D5155064

fbshipit-source-id: a6d896b6b8741ea947cb5cc36c2a2f9333edfb2a
2017-05-31 08:27:41 -07:00
Emil Sjolander
d2f22283bb Fix confusing variable name
Summary: Variable name suggest it does not constrain to min dimension but it did indeed. Changing that to match variable name. This required updating code to use fully constraint value again. gkassabli this seems wrong, do you know what is going on?

Reviewed By: gkassabli

Differential Revision: D5144146

fbshipit-source-id: a5d711f8ad7049b0d96ee0f0f3eef1165ab3b4e8
2017-05-29 07:57:00 -07:00
Emil Sjolander
56b10fc35b Fix absolute positioning in reverse wrapping container
Summary: aligning with odd web behaviour

Reviewed By: gkassabli

Differential Revision: D5144145

fbshipit-source-id: da6ef999ec0aabacf499017d1cfa81fc8f66e4bd
2017-05-29 07:57:00 -07:00
Eduardo Gonzalez
5a3ceffba1 Add .editorconfig
Summary:
Just add .editorconfig into yoga 😄
Closes https://github.com/facebook/yoga/pull/562

Differential Revision: D5144025

Pulled By: emilsjolander

fbshipit-source-id: 9f28caaff276b266ac2aa514097fda6972b85f7c
2017-05-27 09:12:22 -07:00
Georgiy Kassabli
b378a685a4 Changed pointScaleFactor usage to avoid accumulating error
Summary: Previously pointScaleFactor was stored as a divider that opened way to accumulating difference. For instance in ScreenScale=3, pointScaleFactor = 0.3333343 (0.000001 error). When used for width = 300 that error was multiplied by the number of times pointScale contained in width (300 *3 = 900) and we had almost 0.001 error accumulated. With this change Yoga will avoid such issue

Reviewed By: shergin

Differential Revision: D5137923

fbshipit-source-id: 652b59bc3da3f35ee93ffa3695936f623298a023
2017-05-26 10:57:12 -07:00
Pascal Hartig
fa50f048f1 Only decrypt if keys are present
Summary:
Travis doesn't set encrypted variables in pull requests (for very good reasons),
but openssl fails rather loudly if it doesn't get them. Our artifact publishing
script happily skips PRs anyway, so we don't need these variables in that case.

Reviewed By: emilsjolander

Differential Revision:
D5137092

Tags: accept2ship

fbshipit-source-id: b14d61feba0bb98a1705b2f8232f52ba59a2c734
2017-05-26 04:13:01 -07:00
Emil Sjolander
f68b50bb4b Parse YogaValue from string. inverse of toString()
Summary: Implement the inverse of toString. This allows us to parse a YogaValue from a string inputted from the user in debugging tools.

Reviewed By: kittens

Differential Revision: D5120456

fbshipit-source-id: 6ac7cff2a040778e63a953070e1bd7e768fedaa7
2017-05-24 07:56:49 -07:00
Brian Cooke
aad1c3055c Move sdks = out to YOGA_DEFS
Summary: To fix builds where `sdks =` is not supported.

Reviewed By: splhack

Differential Revision: D5113020

fbshipit-source-id: b716acd6fb88ccb55c72b24f9fcdf20a2ea3693e
2017-05-23 12:12:45 -07:00
Georgiy Kassabli
cd1dbc3f0f Fixing potential measure call with negative size value
Summary: There is a case when measure() function will be called with negative width/height because of margin/padding. This diff fixes that scenario

Reviewed By: emilsjolander

Differential Revision: D5111534

fbshipit-source-id: 99f09b85f0c6a0e5dec89a26baba8f9d560100da
2017-05-23 11:12:10 -07:00
Pascal Hartig
bf4ff0769d Use 'dumb' terminal for Gradle
Summary: This makes the output less messy.

Reviewed By: emilsjolander

Differential Revision: D5111279

fbshipit-source-id: c65c7f275e57312fb56c2edfec429cc3d2373e3f
2017-05-23 03:57:34 -07:00
Pascal Hartig
a141ebfb50 Run Android tests with Gradle
Summary:
Make sure that the gradle tests pass before publishing the snapshot. Also makes
sure that we don't break the gradle build.

Reviewed By: emilsjolander

Differential Revision: D5020044

fbshipit-source-id: dfebd829701717eac3ed078a807cd10f489f4348
2017-05-23 03:57:33 -07:00
Jernej Strasner
2fb01daf70 Expose calculateLayoutWithSize in YogaKit
Summary:
calculateLayoutWithSize: can be useful when calculating table/collection view sizes before the views are fully laid out by UIKit.
Closes https://github.com/facebook/yoga/pull/558

Differential Revision: D5104863

Pulled By: emilsjolander

fbshipit-source-id: e0e0c6d502f6745be8d84de8c1b6e24cc25a0352
2017-05-22 11:41:55 -07:00
Pascal Hartig
e9e1e084da Enable unit tests with Gradle
Summary:
This adds the same logic that we have in place with Litho for Yoga, allowing
unit tests to run with Gradle for Yoga. It'll still shell out to Buck to build
the native library, but that's hopefully only until we have found a way to reuse
the NDK build. For CI this shouldn't matter as we want to run `buck build`
anyway and the build step should be a no-op.

FB-Only:
This should unlock D5020044.

Reviewed By: emilsjolander

Differential Revision: D5104154

fbshipit-source-id: 48732fff6c1d100a155452f675de343aaf06427b
2017-05-22 10:11:49 -07:00
yihuang
629e401deb Fix right/bottom in absolute layout.
Summary:
1, Change bottom to be based� on height of parent.
2, Respect margin value when layout with right/bottom.
Closes https://github.com/facebook/yoga/pull/552

Differential Revision: D5102090

Pulled By: emilsjolander

fbshipit-source-id: dca291413ffc2027d7628f4c8b8eeeb0b4823bc2
2017-05-22 02:56:41 -07:00
Chiamaka Nwolisa
f4c2b6ae63 Fix Typo
Summary: Closes https://github.com/facebook/yoga/pull/556

Differential Revision: D5102089

Pulled By: emilsjolander

fbshipit-source-id: 340cab34189628318c08ec45fe8c50a5c1970a17
2017-05-22 02:33:05 -07:00
yihuang
4487862227 fix print edge value.
Summary: Closes https://github.com/facebook/yoga/pull/551

Differential Revision: D5069358

Pulled By: emilsjolander

fbshipit-source-id: 8a8f07043d43f9f2d846a645217a52913cffe31b
2017-05-21 07:00:25 -07:00
Brian Cooke
927eca6604 Enable YogaKit for tvOS
Summary:
This is used in a stack where I'm using YogaKit on tvOS. fb_apple_library needs `sdks = ` to get buck to do its thing for tvOS.

This seems like it should be OK since apple_library is a nop on non apple platforms (which makes sense since this is ObjC only) - I think that makes sense anyway?

Reviewed By: emilsjolander

Differential Revision: D5080261

fbshipit-source-id: f08d7e6d2599b9af25fb964ade485aef552f306b
2017-05-18 06:03:25 -07:00
Georgiy Kassabli
f2612192c5 Fixing using flex in root node
Summary: We should always try to make root node as small as possible, while previously this wasn't functioning this way

Reviewed By: emilsjolander

Differential Revision: D5071164

fbshipit-source-id: b8afef42477d0ed87d0c9fcfd26349e0a0babd6e
2017-05-17 07:28:30 -07:00
Rui Marinho
49bccf47fa Fix windows and osx builds
Summary: Closes https://github.com/facebook/yoga/pull/555

Reviewed By: emilsjolander

Differential Revision: D5071045

Pulled By: splhack

fbshipit-source-id: f9e387242055e0a4a7c330c7bf99ed4a4b4057be
2017-05-16 12:42:08 -07:00
cregnier
fa54167a20 fixes #411 - add npm config platform env var in order to set which js…
Summary:
… platform will be built
Closes https://github.com/facebook/yoga/pull/537

Differential Revision: D5069356

Pulled By: emilsjolander

fbshipit-source-id: eaa67d17fe9d5ed9d0959781ed12a238cb3d95f2
2017-05-16 10:57:03 -07:00
Rui Marinho
50feb21cb3 Centralize native dependencies build script
Summary: Closes https://github.com/facebook/yoga/pull/554

Differential Revision: D5069362

Pulled By: emilsjolander

fbshipit-source-id: 7cf65233928c11010337ee21c633173ea919cc94
2017-05-16 09:59:13 -07:00
Kazuki Sakamoto
52ce5828c9 Use buck release for csharp/build-native.sh
Summary: Closes https://github.com/facebook/yoga/pull/553

Differential Revision: D5069363

Pulled By: emilsjolander

fbshipit-source-id: 2a88f0f53147b5abf1d4eb26f05108c2c001a8f5
2017-05-16 08:11:46 -07:00
Georgiy Kassabli
9cdaedfcb5 Correct YGNodeCanUseCachedMeasurement to account for non-existent scale factor
Summary: When config was added to YGNodeCanUseCachedMeasurement we didn't account for default 0 scale factor. This diff fixes that

Reviewed By: emilsjolander

Differential Revision: D5061016

fbshipit-source-id: 907ef987bd0ead29cf02f6945a3f03d4ffb58a2e
2017-05-15 08:41:30 -07:00
Georgiy Kassabli
adad054cad Adding ability to account for rounding in YGNodeCanUseCachedMeasurement
Summary: We want to be able to use YGConfig to account for possible rounding of width/height

Reviewed By: emilsjolander

Differential Revision: D5059560

fbshipit-source-id: d729e991758a8c668a4b373105b71337961875cd
2017-05-15 06:28:39 -07:00
Emil Sjolander
b2b0c7ee37 Fix typo causing wrapped children to be sized by wrong axis margin
Summary: Fixes https://github.com/facebook/yoga/issues/548

Reviewed By: passy

Differential Revision: D5044470

fbshipit-source-id: 7d203dd48b258a5fe5c4b3c493099092a1d334db
2017-05-12 09:12:51 -07:00
Emil Sjolander
488a7c1fe0 Include margin when calculating if children overflow
Summary: Include margin when calculating if children overflow

Reviewed By: passy

Differential Revision: D5044471

fbshipit-source-id: e7c1eb694445ffb898bcf375d9deefc558c49f11
2017-05-12 09:12:51 -07:00
Emil Sjolander
85c2e406e4 Fix flex basis not accounting for max size constraint
Summary: Fix flex basis not being constraint to the max size in the main direction. Previously this caused the added test to fail due to NaN in child dimensions.

Reviewed By: gkassabli

Differential Revision: D5044314

fbshipit-source-id: d9f9db832e4943a57a89c9d162ff6077b709795a
2017-05-12 09:12:51 -07:00
Emil Sjolander
dcf57d2f7e Big refactor moving most logic into DebugComponent
Summary: This adds very little (no?) new features and mostly just refactors code to live in a singular place. Instead of users having to worry about DebugComponent as well as the DebugInfo object and attaching it correctly to a tree now user's of the DebugComponent API only need to worry about a single class, greatly simplifying its usage.

Reviewed By: passy

Differential Revision: D5027780

fbshipit-source-id: 95a95b3572747aa2088f8f9b35a160257eb59269
2017-05-12 03:57:10 -07:00
Georgiy Kassabli
3fefe9fc49 Adding node type and moving rounding dependency to rely on that type
Summary: This diff adds node type definition to Yoga and moves rounding to rely on the node type. If the node has measure function we consider that node to be text node, otherwise we have default behavior.

Reviewed By: emilsjolander

Differential Revision: D5025107

fbshipit-source-id: a8d66e2f9c5d02ab080784cc474be583a09b92e2
2017-05-11 08:15:46 -07:00
Pascal Hartig
626a05fb6f Update docs for SNAPSHOTs
Summary: Also bumped the version number for the existing dependency examples.

Reviewed By: emilsjolander

Differential Revision: D5044190

fbshipit-source-id: 4199ab114450a256efaa30a811822923beafb378
2017-05-11 05:27:02 -07:00
Pascal Hartig
ffcd2cfc8a Fix android build and enable snapshots
Summary:
Fix some long-standing issues with the android build on Travis (and elsewhere)
and enable automatic publishing of snapshots.

Reviewed By: emilsjolander

Differential Revision: D5044001

fbshipit-source-id: f00be07f33c8018573af0b98233068ebd93360b4
2017-05-11 03:47:16 -07:00
Pascal Hartig
181101c92d Bump snapshot version
Summary: Per title

Reviewed By: emilsjolander

Differential Revision: D5044000

fbshipit-source-id: f1058700daff115bdff52ff62b859b4b3f2e469e
2017-05-11 03:47:16 -07:00
Pascal Hartig
3db6804202 Fix sample app oss build
Summary: The appcompat library was way outdated and failed CI: https://travis-ci.org/facebook/yoga/builds/231065300

Reviewed By: emilsjolander

Differential Revision: D5043967

fbshipit-source-id: a5bb02110cf016972d983f511cf8c31dd9d667e1
2017-05-11 03:47:15 -07:00
Emil Sjolander
3fb135829d Release 1.5.0
Summary: Bump version and fix small issues blocking release

Reviewed By: passy

Differential Revision: D5036755

fbshipit-source-id: 65fa2cd09dad8108bdd21067fb44107b059732e8
2017-05-10 09:32:26 -07:00
Pieter De Baets
2c91e1e7d2 Mark ByteBuffer methods as const
Summary: So I can use them from JSBigString whose methods are marked const.

Reviewed By: emilsjolander

Differential Revision: D5020648

fbshipit-source-id: 6e60b80cb3d4718bab25dd6ca9627aee862117db
2017-05-10 04:26:22 -07:00
Pascal Hartig
c3982b6c1e Set up for automatic snapshot publishing
Summary:
Gets all the pieces in place to automatically publish snapshot artifacts after
successful travis build.

I'll test the actual publishing in a separate branch and then flip the switch in
a separate diff when it's ready.

Reviewed By: emilsjolander

Differential Revision: D5028239

fbshipit-source-id: c57d02a1dee41c84001bd17821b050c8c9aa4134
2017-05-09 08:52:36 -07:00
Pascal Hartig
ae33c6c19c Update Maven release scripts
Summary:
Reuse the gradle setup we've built for Litho which allows for parallel publishing to Bintray and Maven Central in addition to Sonatype Snapshots.

This appears not to break the existing jcenter deploy script which is pretty great.

Reviewed By: emilsjolander

Differential Revision: D5020576

fbshipit-source-id: 3ef163ccbfe91c6858b051d39dcf237ca388e18d
2017-05-09 03:41:51 -07:00
Pascal Hartig
bcd68b997f Add missing fbjni deps
Summary:
fbjni was previously dependency-free but now requires some annotations and
soloader. This unbreaks the gradle build.

Reviewed By: emilsjolander

Differential Revision: D5020069

fbshipit-source-id: b8bde83ce6a70b06e04491f1d70c2a6b568bc99c
2017-05-09 01:56:44 -07:00
Emil Sjolander
fcfa1b9f01 Update pod lock
Summary: run pod install

Reviewed By: gkassabli

Differential Revision: D5019525

fbshipit-source-id: 9cf5d22d8542560e377ab5c3be80ba3ea7ec3de2
2017-05-08 04:48:49 -07:00
Emil Sjolander
d9a0822517 Update formula location for android-sdk
Summary: follow brews instructions on changed location of android sdk

Reviewed By: passy

Differential Revision: D5010781

fbshipit-source-id: 8c39116c821befadb8a153870f365cd0d3a1140d
2017-05-05 10:16:08 -07:00
Emil Sjolander
097e99b699 Always use latest buck
Summary: Always use latest buck

Reviewed By: aiked

Differential Revision: D5010762

fbshipit-source-id: d0c7d36665fab0c58ea5e05d9880b849b3ccf745
2017-05-05 09:19:22 -07:00
Kazuki Sakamoto
ff7bec703b Fix build and test
Summary: Closes https://github.com/facebook/yoga/pull/543

Reviewed By: emilsjolander

Differential Revision: D4997389

Pulled By: splhack

fbshipit-source-id: b4b3aa4cba29063df93fd2a57f96031a8fa393de
2017-05-04 09:19:40 -07:00
Maël Nison
c7ab004922 Fixes Travis error reporting
Summary:
Just cherry-picked my commit from #508
Closes https://github.com/facebook/yoga/pull/542

Differential Revision: D5002335

Pulled By: emilsjolander

fbshipit-source-id: 3f61a235c41627e9cfb90dce150323f11892e65f
2017-05-04 07:45:28 -07:00
Lukas Wöhrl
91230ae177 Move YGLogger into YGConfig and associate YGNodeRef with log events
Summary:
Moves the `YGLogger` into `YGConfig` and pass the `YGNodeRef` into the logger to be able to associate the log messages and assertions with the specific node.

Tackles facebook/yoga#530 and facebook/yoga#446
Closes https://github.com/facebook/yoga/pull/531

Reviewed By: astreet

Differential Revision: D4970149

Pulled By: emilsjolander

fbshipit-source-id: b7fcdaa273143ea2fa35861620b2e4d79f04f0af
2017-05-03 09:30:25 -07:00
Aurimas
40eba60cf5 Move from ActionBarActivity to AppCompatActivity
Summary:
ActionBarActivity has been deprecated for 2+ years now.
Closes https://github.com/facebook/yoga/pull/538

Differential Revision: D4985973

Pulled By: emilsjolander

fbshipit-source-id: 09f2a8a12943c9b3ccdaee9cac684276b42ff843
2017-05-02 09:27:18 -07:00
Aurimas
fb4cfed20d Move from ActionBarActivity to AppCompatActivity
Summary:
ActionBarActivity has been deprecated for 2+ years now.
Closes https://github.com/facebook/yoga/pull/539

Differential Revision: D4985970

Pulled By: emilsjolander

fbshipit-source-id: 2e2fcc5188c08ef1cd78f7e1be71917f0395ff2c
2017-05-02 09:27:18 -07:00
Emil Sjolander
d3a9a84ac4 use java_library instead of android_library
Summary: fbjni doesn't have android deps anyways.

Reviewed By: passy

Differential Revision: D4985285

fbshipit-source-id: 95a5942d89210568b74caa9f3c976a8ae6e9601c
2017-05-02 04:17:14 -07:00
cregnier
accad5366f fixes #535 - changes unneeded js require expression to a static strin…
Summary:
fixes #535 - changes unneeded js require expression to a static string to clean up webpack warnings
Closes https://github.com/facebook/yoga/pull/536

Differential Revision: D4977993

Pulled By: emilsjolander

fbshipit-source-id: 92fe3a278391f37e44ac816d662885df6b4ea11f
2017-05-01 05:21:32 -07:00
Emil Sjolander
8eca67e257 Fix useLegacyStretchBehaviour flag by simplifying its usage
Summary: See blame revision. we are still passing all the added tests from that pull request but with much simpler logic.

Reviewed By: gkassabli

Differential Revision: D4977923

fbshipit-source-id: cb488e63c7c2e15e4c0f0133a16df36580c646fd
2017-05-01 04:32:40 -07:00
Emil Sjolander
40e1bf6ce3 Treat measured nodes size as a minimun contraint when rounding
Summary: We need to treat measurements from nodes with measure functions as minimum values as to not truncate text.

Reviewed By: shergin

Differential Revision: D4972290

fbshipit-source-id: 0a7bcc7f47b3e5acb8745da5286abcb9c4e44a38
2017-04-30 03:11:58 -07:00
David Hart
7b89a1dd48 Implemented percentage values in YogaKit
Summary:
We still need to wait for the `YGUnitPoint` PR to be merged :) But please let me know what you think. One caveat: because of a limitation of Swift, a literal value can be automatically understood as a point-based `YGValue`, but variables have to be explicitly cast. I haven't found a way around it yet:

```
view.yoga.width = 10 // value == 10, unit == YGUnitPixel

let a: CGFloat = 100
view.yoga.height = a // Compiler error
view.yoga.height = YGValue(a) // works, not great
```
Closes https://github.com/facebook/yoga/pull/390

Reviewed By: emilsjolander

Differential Revision: D4954021

Pulled By: maxoll

fbshipit-source-id: 5eff6aeb6dd969d0d5dc557b149bb5819b0e31de
2017-04-28 10:51:31 -07:00
Lukas Wöhrl
203577724e Fix sizing of non strech items
Summary:
Fixes the sizing of items so that under most scenarios it calcultes its height by it's content for non exact measurings. This introduces a new useLegacyStretchBehaviour flag on the config to opt out of this change as it is breaking.

See facebook/yoga#505
Closes https://github.com/facebook/yoga/pull/506

Reviewed By: astreet

Differential Revision: D4954016

Pulled By: emilsjolander

fbshipit-source-id: d28bd5d174cd76951fb94df85e3b0cfab7f81ff7
2017-04-28 06:27:14 -07:00
Emil Sjolander
e3dbef7cbd Revert D4957570: [yoga] Consolidate measure cache for layout nodes and leaf nodes
Summary: This reverts commit 5c5f39b67bd3f72d92b939ecee2d9a46c80b583f

Differential Revision: D4957570

fbshipit-source-id: 4d30de37c6911aac2dc1243a54914515aabfb229
2017-04-28 04:19:33 -07:00
Ivan Persidskiy
0ee3303791 Configure YogaKit with main screen scale factor
Summary:
Hi! After merging 3db38f2a80 the rounding algorithm become broken in YogaKit because it doesn't configure scale factor.
Closes https://github.com/facebook/yoga/pull/534

Differential Revision: D4969481

Pulled By: emilsjolander

fbshipit-source-id: 57ea42a3b1f37007b2392cda724d509e0b28c4cb
2017-04-28 03:12:12 -07:00
Emil Sjolander
83fddd8af6 Expose print function to java
Summary: Allow printing a node from java

Reviewed By: astreet

Differential Revision: D4962456

fbshipit-source-id: 8f62ed6724490e621fbc11573b2a9b25c56e51f1
2017-04-27 16:28:34 -07:00
Emil Sjolander
77c05b5ff6 Consolidate measure cache for layout nodes and leaf nodes
Summary: Re-use advanced changing logic of leaf nodes in layout nodes. //benchmark:benchmark nested flex test shows a ~15% improvement in layout performance!

Reviewed By: astreet

Differential Revision: D4957570

fbshipit-source-id: 5c5f39b67bd3f72d92b939ecee2d9a46c80b583f
2017-04-27 13:11:50 -07:00
Kazuki Sakamoto
7c324f058c Fix C# MeasureFunc test
Summary: Closes https://github.com/facebook/yoga/pull/533

Reviewed By: emilsjolander

Differential Revision: D4962771

Pulled By: splhack

fbshipit-source-id: 96919da73f0f35c027097259fa189b5658fb11b7
2017-04-27 09:30:20 -07:00
Emil Sjolander
3db38f2a80 Remove rounding from experimental features
Summary: Rounding has been successfully adopted by multiple products and frameworks. Time to move it out of experimental mode. Rounding can still be turned of by setting the point scale factor to 0 on the config.

Reviewed By: gkassabli

Differential Revision: D4953838

fbshipit-source-id: 3ee5f27d92f95b3ed4a01c98bc35e9157f2e91c5
2017-04-27 07:14:29 -07:00
Lukas Wöhrl
f6b17183c5 Let measure behave more like on the web
Summary:
Nodes with a measure function needs to be measured even so it seems there is no available space. So it behaves more like on the web. Fix facebook/yoga#488
Closes https://github.com/facebook/yoga/pull/499

Reviewed By: astreet

Differential Revision: D4954008

Pulled By: emilsjolander

fbshipit-source-id: 5b6d9afae0cdebe33f8b82b67620b3b4527d1efc
2017-04-27 07:14:29 -07:00
Emil Sjolander
8f9d7e243e Expose setPointScaleFactor to java
Summary: Expose setPointScaleFactor to java

Reviewed By: gkassabli

Differential Revision: D4953835

fbshipit-source-id: b1f97d9ec1bb78ccf7f53131fce87955fe66eb02
2017-04-26 12:35:00 -07:00
Cheng Zhao
fde4db9383 Add YGConfigCopy
Summary: Closes https://github.com/facebook/yoga/pull/525

Differential Revision: D4953723

Pulled By: emilsjolander

fbshipit-source-id: 1c54f40dfae5054822a440edf9d0aafb22a465d9
2017-04-26 11:57:01 -07:00
Lukas Wöhrl
3178e3bf15 Fix flex-wrap with max constraint
Summary:
Fixes `flex-wrap` with a max constraint and `justify-content`. Fixes facebook/yoga#514.
Closes https://github.com/facebook/yoga/pull/519

Differential Revision: D4953727

Pulled By: emilsjolander

fbshipit-source-id: 32dec48220be1392ea8dac5f34871d407eb8d49b
2017-04-26 11:46:23 -07:00
ChengWei
cdfd05c742 Fix the parameter error
Summary: Closes https://github.com/facebook/yoga/pull/528

Differential Revision: D4953974

Pulled By: emilsjolander

fbshipit-source-id: eda4770d4eb6cf52304d40a1b7ac17c2f0e17148
2017-04-26 11:27:52 -07:00
Emil Sjolander
76f6a54327 Update fbjni
Summary: Update yoga's copy of fbjni to include some missing java files.

Reviewed By: IanChilds

Differential Revision: D4953841

fbshipit-source-id: 74d5c617a6fcd11e82c86f03e61448b14a34b86b
2017-04-26 07:42:40 -07:00
Robert Spencer
c91e4b3566 Correct android attribute link in docs
Summary:
Addresses issue #523
Closes https://github.com/facebook/yoga/pull/529

Differential Revision: D4953973

Pulled By: emilsjolander

fbshipit-source-id: b6e64f30ad615ba65152f19e775bd6c890e6c6b6
2017-04-26 06:27:17 -07:00
Robert Spencer
e24561bcef Update Android XML attribute names in docs
Summary:
Fixes #507 .  The attribute name format got changed and the docs were left behind.
Closes https://github.com/facebook/yoga/pull/510

Differential Revision: D4953733

Pulled By: emilsjolander

fbshipit-source-id: 6eb02d6745d08fdd8cce669c691794351bd6fbc7
2017-04-26 03:12:51 -07:00
Uldéric KIBONGUI
363e941867 Fixed doc mismatch with the implementation
Summary: Closes https://github.com/facebook/yoga/pull/518

Differential Revision: D4953729

Pulled By: emilsjolander

fbshipit-source-id: 6693a0e44e8f12f07af5c3fe7c0475f8553a1df2
2017-04-26 03:12:51 -07:00
Ivan Persidskiy
3fb2c1888c Downgrade deployment target to ios 7
Summary:
Hey there, lets downgrade deployment target of YogaKit pod to iOS7. This days there is a lot of apps that still have support of ios7 (and  i'm working on one of them :)). And I didnt't find any reason why it couldn't be done.

Thanks
Closes https://github.com/facebook/yoga/pull/524

Differential Revision: D4953726

Pulled By: emilsjolander

fbshipit-source-id: 9e17a40caaa0a3ae26779c0d08acb59f71df2b23
2017-04-26 03:12:51 -07:00
Valentin Shergin
aa5b296ac7 New round-to-pixel-grid algorithm that fixes possible subpixel gaps between sibling nodes
Summary:
This diff introduces new, little bit sophisticated round-to-pixel-grid algorithm.

**Motivation:**

Previous simple and straightforward solution works in most cases but sometimes produce the not-so-great result. A while ago Nick Lockwood described this problem and proposed the solution in RN's RCTShadowView class:

For example, say you have the following structure:

  // +--------+---------+--------+
  // |        |+-------+|        |
  // |        ||       ||        |
  // |        |+-------+|        |
  // +--------+---------+--------+

Say the screen width is 320 pts so the three big views will get the following x bounds from our layout system:
{0, 106.667}, {106.667, 213.333}, {213.333, 320}
Assuming screen scale is 2, these numbers must be rounded to the nearest 0.5 to fit the pixel grid:
{0, 106.5}, {106.5, 213.5}, {213.5, 320}
You'll notice that the three widths are 106.5, 107, 106.5.

This is great for the parent views but it gets trickier when we consider rounding for the subview. When we go to round the bounds for the subview in the middle, it's relative bounds are {0, 106.667} which gets rounded to {0, 106.5}. This will cause the subview to be one pixel smaller than it should be. This is why we need to pass in the absolute position in order to do the rounding relative to the screen's grid rather than the view's grid. After passing in the absolutePosition of {106.667, y}, we do the following calculations:
absoluteLeft = round(absolutePosition.x + viewPosition.left) = round(106.667 + 0) = 106.5
absoluteRight = round(absolutePosition.x + viewPosition.left + viewSize.width) + round(106.667 + 0 + 106.667) = 213.5
width = 213.5 - 106.5 = 107

You'll notice that this is the same width we calculated for the parent view because we've taken its position into account.

I believe this is awesome. I also believe that we have to decouple this logic from RN and put it into awesome Yoga. So I did it in this diff.

**Fun fact:**
The original implementation of this algorithm in RN had (and still have) a bug, which was found by Dustin dshahidehpour and fixed in D4133643. Therefore that diff was unlanded because it broke something unrelated inside RN text engine. I will fix that problem in RN later.

**Why do we need to change test methodology?**
Because the way we receive layout metrics from Chrome browser actually directly related to rounding problem. Previously we used `offsetHeight` and `offsetWidth` properties of the DOM node, which contain naively rounded values from `computedStyle` or `getBoundingClientRect`. (Which is we are trying to fix!) So, I added the new function that computes node size using two-step-rounding approach, conceptually similar to one that implemented in Yoga. Note: Chrome browser performs rounding layout as part of rendering process and actual values that can ve computed by counting actual pixel are different from these natively rounded ones.

**Why do some tests now have different desired values?**
These changes actually prove that my approach is correct and more useful for actual view rendering goals. So, let's take a look at test with changed values `rounding_fractial_input_3`:
Previously: 64+25+24=114 (Incorrect!)
Now: 65+24+25=114 (Correct!)
Previously: 64+25+24=114 (Incorrect!)
Now: 65+24+25=114 (Correct!)

Reviewed By: emilsjolander

Differential Revision: D4941266

fbshipit-source-id: 07500f5cc93c628219500e9e07291438e9d5d36c
2017-04-25 17:43:13 -07:00
Lukas Wöhrl
f2b5d0fef7 Mark some fields as readonly and reuse index value in RemoveChild
Summary:
Mark some fields as readonly and reuse index value in RemoveChild.
Closes https://github.com/facebook/yoga/pull/516

Reviewed By: emilsjolander

Differential Revision: D4921809

Pulled By: splhack

fbshipit-source-id: 261a7910675d93be165c16ee53a83c02b15925f1
2017-04-25 11:27:55 -07:00
Lukas Wöhrl
0684795a89 Mark enum with [Flags] where they are used as flags
Summary:
Marks enum with ```[Flags]``` attribute, where they are used as flags.
Closes https://github.com/facebook/yoga/pull/515

Reviewed By: emilsjolander

Differential Revision: D4921807

Pulled By: splhack

fbshipit-source-id: f056189b76ee6e6c042417a7998bfd20a610c27f
2017-04-25 10:28:06 -07:00
Daniel Wagner-Hall
2ffc23f400 Remove project_config rules
Summary:
These only exist to support a deprecated form of project generation which is
about to be removed.

Reviewed By: marcinkosiba

Differential Revision: D4945841

fbshipit-source-id: 3d35b8f8cd902572995ee4f55f9b5930efa186ec
2017-04-25 08:04:02 -07:00
Emil Sjolander
dc4d16401f Move reset into yoga node and dont set overflow as it has no effect
Summary: We don't need to set overflow from litho any more because overflow hidden / visible no longer effects layout.

Reviewed By: marco-cova

Differential Revision: D4938759

fbshipit-source-id: 4cd6bc478dd1f56340f23e8bfe95fe7bb1b5db2d
2017-04-25 03:27:27 -07:00
Martin Kralik
849de89a58 support flexible top container
Summary:
The main container that gets called `applyLayoutPreservingOrigin:` is using its size as a fixed bounding box.
In some cases it's preferrable to let it accomodate its contents.

This diffs extends `applyLayoutPreservingOrigin:` by adding an additional parameter which can be used to sepecify whether width and/or height are fixed or flexible.

Feel free to suggest better names than `YGDimensionFlexibility` & co.
Let me know if you prefet to kill the API without flexiblity specifier - I'll codemod everything then.

Reviewed By: dshahidehpour

Differential Revision: D4929702

fbshipit-source-id: f128f244140b4a54d8ce3b3f4edddbb9756f8fdf
2017-04-23 17:26:50 -07:00
Martin Kralik
f8a2903d02 fixed invalid test
Summary: The `block` paramenter is marked as nonnull, so we can't pass `nil` directly in.

Reviewed By: dshahidehpour

Differential Revision: D4929692

fbshipit-source-id: a35ef2940d6986f4ff55444d8a99ba17eb7c677e
2017-04-22 10:02:50 -07:00
Emil Sjolander
60977de242 Manual resync of moved fbjni files 2017-04-20 12:43:17 -07:00
Georgiy Kassabli
cb612bcfbe Correcting Flex fix within Experimental feature
Summary: This diff corrects the fix to be limited only to cases when either element itself or all of it's children can't be flexed

Reviewed By: emilsjolander

Differential Revision: D4915189

fbshipit-source-id: efccee2fe39ed0f474a41dc3250d24c546f3f5d9
2017-04-19 13:27:52 -07:00
Pascal Hartig
6be1c2cdb4 Begone buckBuildAndCopy!
Summary:
I'm actually quite excited about this one!

No more buck shelling out for building the Yoga AARs/JARs via Gradle. It's now
all done via Gradle.

This commit is the only one that should actually change anything about the entry
points to the gradle builds and release process. **So if anything goes wrong
with the next release, reverting this one here should be enough!**

Reviewed By: emilsjolander

Differential Revision: D4913600

fbshipit-source-id: 4a54562ad5be69f62a7781d43fddad211f99ab25
2017-04-19 12:27:32 -07:00
Pascal Hartig
034ab0b3b1 Set up Gradle build for yogacore
Summary:
I put the CMake file in the root directory to avoid moving the actual `yoga/`
dir around, but created a directory for the Android library manifest nonsense
so it works as its own module you can depend on.

Reviewed By: emilsjolander

Differential Revision: D4913601

fbshipit-source-id: 582064264cf0b6b69c03d0e72ed9dd22d217dd16
2017-04-19 12:27:32 -07:00
Pascal Hartig
8c50347f3c Add NDK build for libfb
Summary:
This enables using gradle for building libfb using the NDK. This is 1/3 of what
we need to do. We also need to build yoga itself (which is the easiest as it's
just a static library without external dependencies) and yogajni which relies on
the other two.

Hopefully, this should also make it more obvious why the previous moves were
necessary.

Reviewed By: emilsjolander

Differential Revision: D4913360

fbshipit-source-id: 47658328532fd1ec15f10f8e31ea04691c481011
2017-04-19 12:27:32 -07:00
Pascal Hartig
9f76fb6980 Move libfb to src/main/cpp
Summary:
This way we can more easily build it with Gradle. The CMake build for this comes
with the next Diff.

Reviewed By: emilsjolander

Differential Revision: D4913361

fbshipit-source-id: b7958e204a8a4a97a1f60043788d826dd2a4c080
2017-04-19 11:42:38 -07:00
Lukas Wöhrl
8b0ff0a25c Add methods for easy adding/removing children
Summary:
Adds two methods ```AddChild``` and ```RemoveChild``` to be able to add/remove children without the need to know there position.
Closes https://github.com/facebook/yoga/pull/513

Reviewed By: emilsjolander

Differential Revision: D4914242

Pulled By: splhack

fbshipit-source-id: df187ba71a1bae0b3b0649624f3c29401d5f8804
2017-04-19 11:30:41 -07:00
Lukas Wöhrl
8891ea1a7a Rename StyleAspectRatio to AspectRatio to be more consistent
Summary:
Rename ```StyleAspectRatio``` to ```AspectRatio``` to be consistent with the other getters and setters.
Closes https://github.com/facebook/yoga/pull/512

Reviewed By: emilsjolander

Differential Revision: D4914236

Pulled By: splhack

fbshipit-source-id: 7b9ebdbf8945c4a8570c61de16d71c8d9d96bf9f
2017-04-19 11:30:41 -07:00
Lukas Wöhrl
ede2ad94bc Add YGEnums to visual studio solutions
Summary:
As stated in 152074935 by rmarinho the Visual Studio solution didn't compile as ```YGEnums.c/YGEnums.h``` hasn't been added to them. This fixes this problem.
Closes https://github.com/facebook/yoga/pull/511

Reviewed By: emilsjolander

Differential Revision: D4914234

Pulled By: splhack

fbshipit-source-id: 473b6169bfb6576ca8848d4a5079f81692766897
2017-04-19 11:30:41 -07:00
Pascal Hartig
eacf3cdbb4 Bump gradle and android dependencies
Summary:
We need to use the most recent Android SDK to leverage the cmake-based NDK build
system. Also, since everything seems to be still working - why not?

I also changed the dependency of `yoga-layout` to be the project, not the
pre-published artifact as it no longer compiled due to the changed measure API
signature. I'm not sure if there was a reason to keep the two separate.

By relying on Maven-published artifacts, we generate better POMs when publishing
and people can override dependencies and see them more easily.

A few more cleanups based on what we did with Litho.

Reviewed By: emilsjolander

Differential Revision: D4913208

fbshipit-source-id: 053deb444ce91106afb3b66c3be28d6fcbdea450
2017-04-19 10:56:48 -07:00
Pascal Hartig
3569a13b74 Make bintray parameters optional
Summary:
By declaring the properties first, before using them in the scripts, you no
longer get an exception if you fail to specify them.

You can now build artifacts or run tests without specifying your bintray
password, which is probably what you want.

Reviewed By: emilsjolander

Differential Revision: D4913103

fbshipit-source-id: 8787af8973cebb84cd59e18c63a3a9f28e0ec348
2017-04-19 10:56:48 -07:00
Pascal Hartig
b2a96ec744 Bundle gradle wrapper
Summary:
I'm trying to get an NDK build set up for Yoga and clean up some of the Gradle
things along the way.

Having a wrapper is not only the preferred way of setting up Android
repositories and more convenient than asking users to install Gradle on their
machines themselves, but also allows for version pinning, which is important
when dealing with Android plugins which usually expect one very specific version
of Gradle.

Reviewed By: emilsjolander

Differential Revision: D4913104

fbshipit-source-id: b14964025271cd16c3c5c05a2fb6dab213227346
2017-04-19 10:56:48 -07:00
Pascal Hartig
a505adb2b7 Bump Android target SDK
Summary: Can we just bump this here?

Reviewed By: emilsjolander

Differential Revision: D4905930

fbshipit-source-id: ea0bd51e32700556ecd1527d2b7fad67d4645366
2017-04-18 12:11:15 -07:00
Pascal Hartig
906b6e52f8 Bump java artifact
Summary: Distribute a new java binary after removing YogaNodeAPI

Reviewed By: lucasr

Differential Revision: D4895449

fbshipit-source-id: c911d3ab69ad01967c76527da22d7c9be7f5f049
2017-04-15 00:45:15 -07:00
George Xu
3292337754 Revert D4875343: Correct fix for flexing grandchildren
Summary: This reverts commit 634e961f9798dff43eae2c6564b28c6629b816e0

Differential Revision: D4875343

fbshipit-source-id: 2949762bf47e151c8c0ff923d501859b3e0a567a
2017-04-13 18:15:40 -07:00
Emil Sjolander
eb4af86e3c Revert D4850458: [yoga][PR] Let measure behave more like on the web
Summary: This reverts commit be5e35a670ddcbf3cd426fc3c2a0c9b60a874cdc

Differential Revision: D4850458

fbshipit-source-id: 2ecb6c8627a84b52ade968fd18331a7473369ebe
2017-04-13 15:41:55 -07:00
Emil Sjolander
1b3e971549 Remove references to CSSLayoutDEPRECATED
Summary: Remove references to CSSLayoutDEPRECATED from litho

Reviewed By: marco-cova

Differential Revision: D4859822

fbshipit-source-id: 2588c1b3334f28332ae43e6c0bdec65934ca84c4
2017-04-13 12:45:23 -07:00
Emil Sjolander
4615eee2d8 Revert D4878875: [yoga][PR] Fix sizing of non strech items
Summary: This reverts commit ab1174ac7a76dcf20aae7b29a3bc396e11077c4d

Differential Revision: D4878875

fbshipit-source-id: 8927438e7a1969deb617434369af53f71f625638
2017-04-13 10:04:15 -07:00
Lukas Wöhrl
7c57245943 Let measure behave more like on the web
Summary:
Nodes with a measure function needs to be measured even so it seems there is no available space. So it behaves more like on the web. Fix facebook/yoga#488
Closes https://github.com/facebook/yoga/pull/499

Differential Revision: D4850458

Pulled By: emilsjolander

fbshipit-source-id: be5e35a670ddcbf3cd426fc3c2a0c9b60a874cdc
2017-04-13 08:46:20 -07:00
Georgiy Kassabli
0d100ad7e9 Correct fix for flexing grandchildren
Summary: This diff adds correct fix for non-flexible child with flexible grandchildren

Reviewed By: emilsjolander

Differential Revision: D4875343

fbshipit-source-id: 634e961f9798dff43eae2c6564b28c6629b816e0
2017-04-13 08:46:20 -07:00
Lukas Wöhrl
0235789863 Fix sizing of non strech items
Summary:
Fixes the sizing of items so that under most scenarios it calcultes its height by it's content for non exact measurings. See facebook/yoga#505
Closes https://github.com/facebook/yoga/pull/506

Differential Revision: D4878875

Pulled By: emilsjolander

fbshipit-source-id: ab1174ac7a76dcf20aae7b29a3bc396e11077c4d
2017-04-13 07:41:52 -07:00
Emil Sjolander
c080a46571 Fix some issues with the deploy script and deploy a new version for android
Summary: Fix some issues with the deploy script and deploy a new version for android

Reviewed By: passy

Differential Revision: D4876006

fbshipit-source-id: ddafb8349e1c77ab5afd9a823103fb6a1dfabb1d
2017-04-12 09:56:42 -07:00
Emil Sjolander
5f050cb590 Bump version of android stuff
Summary: Bump version of android things

Reviewed By: passy

Differential Revision: D4875213

fbshipit-source-id: 2b229a0dade521ef745852c0096545e7e9fe2c1e
2017-04-12 03:43:45 -07:00
Lukas Wöhrl
25f14a1917 Fix min constraint incorrectly reducing available space
Summary:
If a min constraint exists. It incorrectly reduces the available space by that amount. This adds a test and fix for this.
Closes https://github.com/facebook/yoga/pull/501

Differential Revision: D4867146

Pulled By: emilsjolander

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

Differential Revision: D4867144

Pulled By: emilsjolander

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

Reviewed By: emilsjolander

Differential Revision: D4796199

Pulled By: splhack

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

Reviewed By: emilsjolander

Differential Revision: D4796190

Pulled By: splhack

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

Reviewed By: emilsjolander

Differential Revision: D4796178

Pulled By: splhack

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

Differential Revision: D4850451

Pulled By: emilsjolander

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

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

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

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

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

Differential Revision: D4834356

Pulled By: emilsjolander

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

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

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

Reviewed By: gkassabli

Differential Revision: D4802184

Pulled By: emilsjolander

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

Reviewed By: astreet

Differential Revision: D4802966

Pulled By: emilsjolander

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

Reviewed By: emilsjolander

Differential Revision: D4802918

Pulled By: rspencer01

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

Reviewed By: astreet

Differential Revision: D4786961

Pulled By: emilsjolander

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

Reviewed By: emilsjolander

Differential Revision: D4794861

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

Reviewed By: emilsjolander

Differential Revision: D4794772

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

Reviewed By: astreet

Differential Revision: D4779742

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

Reviewed By: astreet

Differential Revision: D4779743

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

Reviewed By: astreet

Differential Revision: D4786615

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

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

Reviewed By: emilsjolander

Differential Revision: D4778870

Pulled By: astreet

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

Reviewed By: astreet

Differential Revision: D4765683

Pulled By: splhack

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

Reviewed By: astreet

Differential Revision: D4739149

Pulled By: splhack

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

Differential Revision: D4716024

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

Reviewed By: emilsjolander

Differential Revision: D4714782

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

Reviewed By: astreet

Differential Revision: D4716024

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

Reviewed By: astreet

Differential Revision: D4716022

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

Reviewed By: rspencer01

Differential Revision: D4721745

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

Reviewed By: emilsjolander

Differential Revision: D4565531

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

Differential Revision: D4713645

Pulled By: emilsjolander

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

Differential Revision: D4697833

Pulled By: emilsjolander

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

Reviewed By: emilsjolander

Differential Revision: D4698936

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

Differential Revision: D4698444

Pulled By: dshahidehpour

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

Differential Revision: D4689718

Pulled By: emilsjolander

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

Reviewed By: emilsjolander

Differential Revision: D4687978

Pulled By: splhack

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

Differential Revision: D4688997

Pulled By: emilsjolander

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

Differential Revision: D4688993

Pulled By: emilsjolander

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

Reviewed By: emilsjolander

Differential Revision: D4676753

Pulled By: splhack

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

Differential Revision: D4675088

Pulled By: emilsjolander

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

Reviewed By: emilsjolander

Differential Revision: D4681514

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

Differential Revision: D4681342

Pulled By: emilsjolander

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

Differential Revision: D4681340

Pulled By: emilsjolander

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

Reviewed By: emilsjolander

Differential Revision: D4674049

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

Differential Revision: D4674103

Pulled By: emilsjolander

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

Added badges for build and nuget for more exposure.

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

Reviewed By: emilsjolander

Differential Revision: D4670392

Pulled By: splhack

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

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

Differential Revision: D4673746

Pulled By: emilsjolander

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

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

Reviewed By: emilsjolander

Differential Revision: D4666572

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

Reviewed By: emilsjolander

Differential Revision: D4666500

Pulled By: splhack

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

Reviewed By: emilsjolander

Differential Revision: D4666641

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

Reviewed By: emilsjolander

Differential Revision: D4666314

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

Reviewed By: emilsjolander

Differential Revision: D4666239

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

Reviewed By: dshahidehpour

Differential Revision: D4666248

fbshipit-source-id: 924aea76db5d68acbae7048d8542cab71122cbc2
2017-03-07 06:28:47 -08:00
Robert Spencer
17be6718ee Nicer formatting of gists in docs
Summary: The gists in the docs have large margins to fit with the front page.  This diff specialises that margin setting and sets it to something smaller for other gists.

Reviewed By: emilsjolander

Differential Revision: D4666016

fbshipit-source-id: 5121849a153e78d523b33e10b96641426e794f8d
2017-03-07 05:26:24 -08:00
Robert Spencer
abf912b729 Gradle version bump and POM details
Summary: This improves the quality of the published POM files, adding dependencies and marking the object as an 'aar'.  It also bumps the version to 1.2.0 for JCenter.

Reviewed By: emilsjolander

Differential Revision: D4620150

fbshipit-source-id: 968f1cea21af4b2f19aeff3f32ad575b185fa1bb
2017-03-07 03:56:46 -08:00
Eric Rozell
5bc0197c78 Workaround for P/Invoke AccessViolationException
Summary:
The issue is on ARM builds for Windows UWP. For the C# P/Invoke API wrapper, any native method that returns the YogaValue struct throws the AccessViolationException. The issue is not with structs in general, as returning the YogaSize / YGSize struct works fine. The issue seems to be limited to structs that have an enum member.

I tried a number of things to resolve the issue without changing the underlying native API for Windows. I read the ARM documentation and saw reference to variable enum sizes based on the number of enum members, so I tried to use a number of different UnmanagedType values in a [MarsalAs()] attribute on the enum member of the C# struct declaration.

What ultimately worked was to return a pointer to the location of the struct, and use the System.Runtime.InteropServices.PtrToStructure API to read the struct data from that pointer. I added a few new macros that will return the struct address on Windows only, other builds are not affected.

Note, I have not tested the impact of this ch
Closes https://github.com/facebook/yoga/pull/459

Reviewed By: emilsjolander

Differential Revision: D4652278

Pulled By: splhack

fbshipit-source-id: bf7ada4da1781e3f813b3ba331974b7bded476d9
2017-03-06 11:42:40 -08:00
Lukas Wöhrl
62f47190fb Added bool config to YGConfig to configure using web defaults
Summary:
Added bool config to YGConfig to configure using web defaults. See #445.
Closes https://github.com/facebook/yoga/pull/449

Reviewed By: astreet

Differential Revision: D4642272

Pulled By: emilsjolander

fbshipit-source-id: 4f35bd17b7f764f42295052a4a8b4ae46c192d7e
2017-03-03 10:55:59 -08:00
Lukas Wöhrl
a706f4c97c Mark all children as dirty if display changes
Summary:
If we set ```display:none``` all children are set with layout sizes/values of 0. We need do mark all those children as dirty to force a relayout if we toggle the display on a higher parent node. This fixes #443
Closes https://github.com/facebook/yoga/pull/448

Reviewed By: astreet

Differential Revision: D4642273

Pulled By: emilsjolander

fbshipit-source-id: dfdb920e2049952bd6c7f48cfa53b1448e1f3e8f
2017-03-03 10:45:19 -08:00
Lukas Wöhrl
feb365a77b Explicitly set new experimental and a small other improvement
Summary:
This sets the new ```YGExperimentalFeatureMinFlexFix``` explicitly to false in the config.

It also a changes a stretch reason to reflect that it is the strech in a multiline.
Closes https://github.com/facebook/yoga/pull/447

Reviewed By: astreet

Differential Revision: D4642275

Pulled By: emilsjolander

fbshipit-source-id: 26777db7008ff6ee86da72ca9ea19e979b916cc9
2017-03-03 10:26:41 -08:00
Lukas Wöhrl
b2a4e67fee Use floats to prevent double calculation + float casting on scale
Summary:
Use ```float``` for calculation, as we would calculate with ```double``` and cast to float afterwards otherwise. So this removes the warning.
Closes https://github.com/facebook/yoga/pull/450

Reviewed By: astreet

Differential Revision: D4642267

Pulled By: emilsjolander

fbshipit-source-id: 184ef24474f2b8a42654a71a8e98839296648b2b
2017-03-03 10:26:40 -08:00
Emil Sjolander
e7d2792009 Add another nested percentage test
Summary: Add test covering a nested percentage container inside of a unconstraint container. This is something we ran into recently and want to make sure to cover in tests.

Reviewed By: astreet

Differential Revision: D4637519

fbshipit-source-id: a8fe3c7702c2ea0ad954cce80fbdf953bb23c997
2017-03-03 10:26:40 -08:00
Emil Sjolander
0fde1424f0 re-generate tests. Something was missed when rebasing
Summary: Some of the tests were not generated correctly. most likely due to a rebase.

Reviewed By: astreet

Differential Revision: D4637539

fbshipit-source-id: 196478d7e5197519af9ab05e5134e6fb7d22b992
2017-03-03 10:26:40 -08:00
Robert Spencer
29fd447f0c Margin percent values should be floats
Summary: Percentages should be floats

Reviewed By: emilsjolander

Differential Revision: D4642511

fbshipit-source-id: f1ef78259cf967acec9b82d77e43d7b9ad263e5b
2017-03-03 06:48:10 -08:00
Robert Spencer
7047d96087 Add yg prefix to attributes
Summary: To avoid clashes in the `app:` namespace, we prefix all yoga attributes with `yg_`.

Reviewed By: emilsjolander

Differential Revision: D4643080

fbshipit-source-id: 3e9265fd57e56a1df2f687a5d17c5bc66b8befa3
2017-03-03 00:41:04 -08:00
Robert Spencer
6336e641f4 Add ability to invalidate views
Summary: When some drawing attributes of a view changes how it measures, we need to be able to relayout it correctly.  This adds method `invalidate(View)` to `YogaLayout` which will flag the corresponding node as dirty and requiring layout again.

Reviewed By: emilsjolander

Differential Revision: D4634563

fbshipit-source-id: af7f47dce00a31414d0987a58307c5d44c1bcf20
2017-03-02 02:58:52 -08:00
Scott Wolchok
ecabe757a2 BUCK file renaming round 2 (13/13)
Summary: Ran the autoformat linter on our BUCK files.

Reviewed By: dinhviethoa

Differential Revision: D4641344

fbshipit-source-id: 25b42543ddf5cc60c72e4228cec1c5175f60eaca
2017-03-01 20:42:23 -08:00
Lukas Wöhrl
37c48257ae Move configuration to new YGConfig and pass them down to CalculateLayout
Summary:
Move configuration to new ```YGConfig``` and pass them down to CalculateLayout. See #418 .

Adds ```YGConfigNew()``` + ```YGConfigFree```, and changed ```YGSetExperimentalFeatureEnabled``` to use the config.

New function for calculation is ```YGNodeCalculateLayoutWithConfig```.
Closes https://github.com/facebook/yoga/pull/432

Reviewed By: astreet

Differential Revision: D4611359

Pulled By: emilsjolander

fbshipit-source-id: a1332f0e1b21cec02129dd021ee57408449e10b0
2017-03-01 09:27:53 -08:00
Emil Sjolander
8668e43f6d Fix margin auto for start and end values
Summary: Margin auto was not handling start/end margins correctly

Reviewed By: astreet

Differential Revision: D4627339

fbshipit-source-id: eebf64e79a34331e79cffcfa3662d4938fbd6c13
2017-03-01 09:27:52 -08:00
Emil Sjolander
785713c9c0 default root node to size of parent contraints
Summary: This is a follow up on a recent change which made the constraints passed into conculateLayout describe the parent constraints and not the root node constraints. This broke some assumptions and was not very inuitive if no size was set on the root. Therefor this diff ensure that if the root node does not have any size set then it will adopt the size of the parent constraints.

Reviewed By: dshahidehpour

Differential Revision: D4634616

fbshipit-source-id: 089eb4313c5bb810a6ff56f158cd19cec71808ec
2017-03-01 07:11:25 -08:00
Robert Spencer
b523402eda Update NDK version to 12
Summary: This diff updates the NDK version from 10 to 12

Reviewed By: emilsjolander

Differential Revision: D4634938

fbshipit-source-id: 6a9cbc48dbcbda4674d6460120c7a0d8abd626ab
2017-03-01 06:27:17 -08:00
Emil Sjolander
3790635af1 Re-generate wrap tests
Summary: Seems someone forgot to run the generation script

Reviewed By: astreet

Differential Revision: D4627337

fbshipit-source-id: 17dd1e1fed938a049ae820a9a4ac913667073d09
2017-03-01 06:27:16 -08:00
Robert Spencer
b940fadb7e Add android bindings to margin:auto
Summary: [This commit](1146013e9e) (or diff D4501142) adds an `auto` option for margins.  This diff allows you to leverage that in android via attribute `yoga:margin_all="auto"` (and as expected for the other edges).

Reviewed By: emilsjolander

Differential Revision: D4634684

fbshipit-source-id: 158f70ec975b5bb3a666e590b76eb52daeb38f49
2017-03-01 05:57:03 -08:00
Georgiy Kassabli
3ef2970032 Yoga test failure for flexing with min stack dimension
Summary: Test fails when we have flexible child and min/max layout dimension. Yoga should flex the child to minimal size, while in reality Yoga flexes it to maximal size

Reviewed By: emilsjolander

Differential Revision: D4558653

fbshipit-source-id: 06b38d7ed43aee063cc881f38b84558641f043f3
2017-02-28 16:28:54 -08:00
Robert Spencer
4372aa16d3 Enable RTL on sample app
Summary: The manifest didn't acknowledge that the sample app supports RTL.  Thus `TextView`s didn't render properly.

Reviewed By: emilsjolander

Differential Revision: D4628867

fbshipit-source-id: 72e57f48f7d68a8d2d6dd091b44b9452a3fe281a
2017-02-28 12:27:15 -08:00
Lukas Wöhrl
3346f9511a Change flex getters to return the set values
Summary:
Changed the flex getters to return the values they were actually set. See #421 .
Closes https://github.com/facebook/yoga/pull/431

Reviewed By: astreet

Differential Revision: D4604744

Pulled By: emilsjolander

fbshipit-source-id: 02d79100ef22be866db1c3bd9d53e4447186811f
2017-02-28 09:26:32 -08:00
Emil Sjolander
1cd7363bea Pass the parent size to YGNodeCalculateLayout instead of the node size
Summary: The size of the node is already set on the node however there was no way to set the size of the parent to the root so that the root could use percentages. This change fixes this by making the width and height passed to calculate layout be the width and height of the hypothetical parent.

Reviewed By: astreet

Differential Revision: D4611417

fbshipit-source-id: 2fb0eedffa17f0ec89b601722a1717a72e216b9e
2017-02-28 08:11:58 -08:00
Lukas Wöhrl
17e3dca9f9 Fix percentage in flexing parent
Summary:
If we don't measure exactly, percentage values aren't exactly either. Fix for #414.
Closes https://github.com/facebook/yoga/pull/416
Closes https://github.com/facebook/yoga/pull/414

Reviewed By: astreet

Differential Revision: D4604729

Pulled By: emilsjolander

fbshipit-source-id: 66880230073209cbe89668b838c2a82e7f9b34df
2017-02-28 07:12:05 -08:00
Robert Spencer
533f560ce0 Android bindings for display property
Summary: Diff D4501141 added display attributes for Yoga.  This exposes them in the android library.

Reviewed By: emilsjolander

Differential Revision: D4605574

fbshipit-source-id: dbad3d6fe924682c6b81f65bbba9727085de2d81
2017-02-28 00:26:27 -08:00
Robert Spencer
6a60d4893e Add travis_wait to installing Android SDK in travis builds
Summary: The android sdk and api installation seems to be timing out on Travis.  This should extend the 10 minute limit to 20 minutes.  Hopefully this will be enough to download it all.  If not, we must just extend the timeout.

Reviewed By: emilsjolander

Differential Revision: D4588245

fbshipit-source-id: fef25c54b081ba4d96d1e0435c6c1f643ff49b66
2017-02-28 00:26:27 -08:00
Emil Sjolander
51dd082682 bump javascript version
Summary: https://www.npmjs.com/package/yoga-layout

Reviewed By: arcanis

Differential Revision: D4611991

fbshipit-source-id: 4f75a85f8664e6d5bec609f6feb668a59f0fdde8
2017-02-27 01:13:08 -08:00
Michael Bolin
47d8d9d22b Apply auto-formatter for BUCK files in fbandroid.
Summary:
For more background, see:

https://fb.facebook.com/groups/303159406399348/permalink/1334977403217538/
https://fburl.com/auto-format-build-files
D4527873

fbshipit-source-id: 278ce6f67f5df830b2218e3aca69be103d3c56a6
2017-02-24 21:44:02 -08:00
Dustin Shahidehpour
d6d4dcb141 Update YogaKitSample Podfile.lock
Summary: #accept2ship

Reviewed By: amonshiz

Differential Revision: D4614473

fbshipit-source-id: d46fc54c53280fca1607dc75b59e730f340eb4e7
2017-02-24 14:26:55 -08:00
Georgiy Kassabli
37ec1774a7 Add rounding to the pixel grid to Yoga
Summary: This diff adds rounding to the pixel grid feature to Yoga and appropriate property

Reviewed By: emilsjolander

Differential Revision: D4565980

fbshipit-source-id: 9700f6d6ed147f82b19f230fbff2e9ccbd625b25
2017-02-24 09:57:00 -08:00
birfincankafein
3ad4d7dd6e Solve build target error while building Android with Buck.
Summary:
SoLoader library targets Android API 21 but main manifest targets 19. This will block buck android build.
Closes https://github.com/facebook/yoga/pull/437

Reviewed By: astreet

Differential Revision: D4611364

Pulled By: emilsjolander

fbshipit-source-id: 113bcfce751e98b8a42e46e0101b6a4b1327b9c3
2017-02-24 03:26:46 -08:00
Emil Sjolander
e596091fa2 Bump podspec versions
Summary: podspec version bump

Reviewed By: dshahidehpour

Differential Revision: D4606652

fbshipit-source-id: a9a7d4512f174182301a0b7ac2ae13303b659a3f
2017-02-23 11:57:06 -08:00
Lukas Wöhrl
4f5c7ed6af Fix align-content:strech overriding align-item
Summary:
Fix for #413. This was a hangover from a previous attept to fix other align-content problems.
Closes https://github.com/facebook/yoga/pull/417

Reviewed By: astreet

Differential Revision: D4604727

Pulled By: emilsjolander

fbshipit-source-id: 92fd31a385d8182c6b201c891d5ae478372d525d
2017-02-23 08:31:05 -08:00
Robert Spencer
60ffa1953b Gradle for android library
Summary: Adds a buildscript for gradle as well as bintray upload capabilities for the YogaLayout library

Reviewed By: emilsjolander

Differential Revision: D4604712

fbshipit-source-id: bacbcc20b7ed6ee8689130287a48bd5d3826298c
2017-02-23 05:07:20 -08:00
Robert Spencer
5519a73087 Gradle for java library
Summary: This builds the java bindings with gradle, and adds a script for Facebook employees to upload the generated artifacts to JCenter.

Reviewed By: emilsjolander

Differential Revision: D4597335

fbshipit-source-id: 4c01695a8638000a417bfb49deba4b9b9b4e114b
2017-02-23 05:07:20 -08:00
Lukas Wöhrl
67717a7872 Force scalefactor=1 for gentest to fix issues with test generation on hdpi devices
Summary:
Since my new main work maschine is a hdpi device, all the gentests with rounding are producing different outputs.

This PR force the scalefactor=1 for gentest to fix issues with generation on hdpi devices.
Closes https://github.com/facebook/yoga/pull/434

Differential Revision: D4604724

Pulled By: emilsjolander

fbshipit-source-id: ce4036ae71a45775280e0504f20c06a4622ccceb
2017-02-23 01:26:55 -08:00
Aljoscha Meyer
4522d4b8aa Fix a typo in C API documentation
Summary:
Change "Certain nodes need *to* ability to measure themselves" to "Certain nodes need *the* ability to measure themselves".
Closes https://github.com/facebook/yoga/pull/430

Differential Revision: D4600091

Pulled By: emilsjolander

fbshipit-source-id: d20693b47291e79bd8c5f76e57d6dff2444333d2
2017-02-22 12:57:21 -08:00
Robert Spencer
d7ca339c27 Fix android height attribute
Summary: The attribute for height was incorrectly assumed to be type `float` which led to it not being explicitly defined.  It is actually a dimension.

Reviewed By: emilsjolander

Differential Revision: D4588629

fbshipit-source-id: 56c7e460d27528823944852d682e7f26bf908292
2017-02-21 00:12:09 -08:00
Emil Sjolander
6b39165801 Fix behaviour of wrapping container within align-items: not stretch
Summary: When a container's children wrap the container should match the parent size and not wrap to the new size of the children. This is confirmed behavior in chrome.

Reviewed By: astreet

Differential Revision: D4578614

fbshipit-source-id: 5d22a3a673735587384d775189158a87bb1d457d
2017-02-20 07:28:42 -08:00
Maël Nison
78ade6cfb5 Improve JS Travis testing
Summary:
Build emscripten js file on travis
Closes https://github.com/facebook/yoga/pull/397

Reviewed By: arcanis

Differential Revision: D4579563

Pulled By: emilsjolander

fbshipit-source-id: fa5f92fd26f758fb617e428c07aabf2dccd63b37
2017-02-20 05:41:38 -08:00
Robert Spencer
3f68b4f76b Travis install android sdk and api for build
Summary:
Travis android build is failing with

    BUILD FAILED: Google APIs not found in /usr/local/opt/android-sdk/add-ons/addon-google_apis-google-19/libs.
    Please run '/usr/local/opt/android-sdk/tools/android sdk' and select both 'SDK Platform' and 'Google APIs' under Android (API 19)

This should fix that error

Reviewed By: emilsjolander

Differential Revision: D4588053

fbshipit-source-id: e57d635141e8aede5803b919ee5a28a60c5e667c
2017-02-20 02:26:16 -08:00
Robert Spencer
521aab5fcc Omptimisation on layout and measure children of YogaLayout
Summary:
You must measure children before you lay them out, and YogaLayout didn't do this.  This fixes that.

We also only recompute the yoga tree if the YogaLayout is laid out with a different size to what it's been measured as.

Reviewed By: emilsjolander

Differential Revision: D4572237

fbshipit-source-id: 6e86dbf939b06338c1dc2a37b7dafafd548dd390
2017-02-19 23:58:09 -08:00
Rui Marinho
42492596b3 Changes for nuget and CI support
Summary:
For now i setup the CI using VSTS (Visual Studio Team Services) , i m using my own account, but i want to move this to a Travis setup so it would be easy ported to Facebook own build system. We can also take a look on how buck can help with this.

Here's a overview of my dashboard for the build and release process on VSTS:

<img width="1084" alt="screen shot 2017-02-16 at 23 52 07" src="https://cloud.githubusercontent.com/assets/1235097/23046869/ff4dcada-f4a3-11e6-8d09-fb8974fb58d4.png">

The all process is pretty simple, there's a few tricks here and there, but the basic steps are:

<img width="1036" alt="builds" src="https://cloud.githubusercontent.com/assets/1235097/23046874/0cb95fc2-f4a4-11e6-8fd8-3048be7ffd9d.png">

These run for every commit and publish the artifacts, then the release lane takes that artifacts and builds a nuget, after that (and it's not implemented yet) we run UI Tests on devices Android , iOS for the nuget created and run tests on UWP and .net45 on both windows and OS X so
Closes https://github.com/facebook/yoga/pull/408

Reviewed By: emilsjolander

Differential Revision: D4576542

Pulled By: splhack

fbshipit-source-id: 66e0e4c1cb3721ed7aa7118e4e226b6ec575fea8
2017-02-17 10:41:47 -08:00
Eric Rozell
b24e728666 Adds UWP build for yoga.dll
Summary:
The existing Yoga.vcxproj works great for Desktop apps, but breaks when you try to use the resulting DLL on mobile, Xbox, etc. This change compiles the DLL for the UWP and the Windows Store.
Closes https://github.com/facebook/yoga/pull/401

Reviewed By: emilsjolander

Differential Revision: D4561354

Pulled By: splhack

fbshipit-source-id: 643ad4ed1ffc73719d35974e2d357c37d5b1d1c4
2017-02-16 11:42:30 -08:00
Kazuki Sakamoto
4fe0b810e1 Fix callbacks on AOT
Summary:
Based on the idea of #386 by rmarinho
Closes https://github.com/facebook/yoga/pull/388

Reviewed By: emilsjolander

Differential Revision: D4570778

Pulled By: splhack

fbshipit-source-id: 362983deaf6f040c42b3db8205b711e7e5e60eaf
2017-02-16 11:15:36 -08:00
Rui Marinho
8deed174f5 Fix callbacks on AOT
Summary:
When using AOT mode on Mono one can't use instance methods for callbacks, the compiler needs the MonoPInvokeCallback attribute on a static method to know how to get back to the managed world.
This worked fine without the change in JIT mode.

I not sure if we should use a __MONO__ flag for this stuff as this could be needed for other usage that not only on iOS.

~~The adicional change is that one should as good practice call Dispose on the YogaNode when using callbacks to make sure we remove the handler from our dictionary, i was trying to write a test for this.. but i saw TestMeasureFuncWithDestructor was already there, but it doesn't seem correct to me, can you check splhack.~~
Closes https://github.com/facebook/yoga/pull/386

Reviewed By: emilsjolander

Differential Revision: D4546030

Pulled By: splhack

fbshipit-source-id: 121d44a2ecd14d754b9614493db6ac15fca02da2
2017-02-16 11:15:36 -08:00
Kazuki Sakamoto
2184547094 Fix unit test for flexBasis
Summary: Fix unit test for flexBasis

Reviewed By: emilsjolander

Differential Revision: D4572394

fbshipit-source-id: ce0b3cd28b5c8a9910106308c561c95d1b3866e9
2017-02-16 10:26:33 -08:00
Lukas Wöhrl
8eda4dc040 Removed duplicate code by calculating with mainSize/crossSize
Summary:
This PR removes some duplicate code by calculating with ```mainSize```/```crossSize``` and converting that to ```width``` or ```height``` at the end. See #395 .
Closes https://github.com/facebook/yoga/pull/396

Reviewed By: astreet

Differential Revision: D4564713

Pulled By: emilsjolander

fbshipit-source-id: 0b24e69cc9dc75cdf93deeb6c076dcacf134c6d8
2017-02-16 07:41:32 -08:00
Kazuki Sakamoto
4d4db92a46 Fix unit test
Summary: Fix #406 #407

Reviewed By: emilsjolander

Differential Revision: D4569680

fbshipit-source-id: a7b78674ed483d8619bd4aaa6e463203ef619c9b
2017-02-16 07:41:32 -08:00
Emil Sjolander
ea8b7e0c91 Fix up some small issues with YGUnitAuto
Summary: There are still some pieces of RN which does not handle YGUnitAuto and makes use of either the value being nan or the unit being undefined. This diff makes this more robust to those kinds of situations.

Reviewed By: wwjholmes

Differential Revision: D4567045

fbshipit-source-id: ace5fd89bd534a6bb5ec7dba0c3afbf13d62d7c9
2017-02-16 06:58:47 -08:00
Robert Spencer
6928957096 Set ANDROID_SDK and ANDROID_HOME for Travis build
Summary: Travis builds are failing due to ANDROID_SDK not being set.  So we set both it and ANDROID_HOME to where homebrew should have created a link to the installation.

Reviewed By: emilsjolander

Differential Revision: D4571703

fbshipit-source-id: a6dc4eb07006dc8baefb6ca938111ff256c6f018
2017-02-16 02:58:45 -08:00
Robert Spencer
b680b726d1 Add Android Travis badge to README.md
Summary: Adds the Travis build badge for the android target to the README.md

Reviewed By: emilsjolander

Differential Revision: D4571693

fbshipit-source-id: a5110dac7d86989cc4a14b858c63d59332072869
2017-02-16 02:44:53 -08:00
Robert Spencer
fbd692c449 Remove splash screen activity from sample app
Summary: The yoga splash screen that runs at the beginning of the app is unnecessary and can be removed for simplicty.

Reviewed By: emilsjolander

Differential Revision: D4571624

fbshipit-source-id: 3eb12f7c3447805f4546bd192df9670c5427572a
2017-02-16 02:44:50 -08:00
Kazuki Sakamoto
2199a7908d Fix BUCK
Summary:
- Deleted a non-existent include
- Fix #404

Reviewed By: bolinfest

Differential Revision: D4569377

fbshipit-source-id: 34161b28be8bab476b30442596314899463814ef
2017-02-15 16:58:04 -08:00
Dustin Shahidehpour
59704f1508 Backed out changeset 762168ced81e
Summary: Acting weird with Xcode 8.2.1

Differential Revision: D4567880

fbshipit-source-id: e5a200b59780ac3dd8f75b6152054778b9fc786c
2017-02-15 14:35:46 -08:00
Lukas Wöhrl
20536923d6 flex-wrap: wrap-reverse support
Summary:
I couldn't resist to do this 😄 #394

This adds ```flex-wrap: wrap-reverse```

I think we hit a edge case here:
https://stackoverflow.com/questions/33891709/when-flexbox-items-wrap-in-column-mode-container-does-not-grow-its-width

as is differs here from chrome, but I think that yoga is here more correct.

So I haven't added this test yet as this would fail against chrome, as chrome outputs a width of 30 for root, whereas yoga gets a width of 60 here, which I think is correct. Strangely the output of ```flex-wrap:wrap``` is in jsfiddle also only with a (visual) width of 30 on chrome, while the tests gets generated with 60.

```html
<div id="wrap_reverse_column" style="height: 100px; flex-wrap: wrap-reverse">
  <div style="height: 30px; width: 30px;"></div>
  <div style="height: 30px; width: 30px;"></div>
  <div style="height: 30px; width: 30px;"></div>
  <div style="height: 30px; width: 30px;"></div>
</div>
```

Looking forward what you think here emilsjolander
Closes https://github.com/facebook/yoga/pull/398

Reviewed By: astreet

Differential Revision: D4564711

Pulled By: emilsjolander

fbshipit-source-id: 33dc055abd8444b2aa7796ef90bd7ec99e961bb8
2017-02-15 13:42:47 -08:00
Lukas Wöhrl
bba7289537 Remove no longer valid limitiation hints
Summary:
Remove no longer valid limitiation hints, according to percentag, auto margins and flex values.
Closes https://github.com/facebook/yoga/pull/402

Reviewed By: astreet

Differential Revision: D4564709

Pulled By: emilsjolander

fbshipit-source-id: ef7f37921644b4d315c7a84552861713061b33e1
2017-02-15 08:26:56 -08:00
Dustin Shahidehpour
04d1ccc085 Create Xcode project so it's much easier to run tests.
Summary:
I don't even know how people have been running tests (unless they install BUCK). This creates a workspace to make it much easier to run tests.
Closes https://github.com/facebook/yoga/pull/400

Differential Revision: D4565290

Pulled By: dshahidehpour

fbshipit-source-id: 762168ced81e517126ac05c92bb27ccad0d9d305
2017-02-15 08:11:36 -08:00
Joel Marcey
a7e7c5eb52 Add actual Google Analytics ID
Summary:
We still had the default one from the template.
Closes https://github.com/facebook/yoga/pull/403

Reviewed By: astreet

Differential Revision: D4564708

Pulled By: emilsjolander

fbshipit-source-id: ec76325e0dca34f89e5a920627ced7fa812827de
2017-02-15 07:47:25 -08:00
David Hart
9d2839f8ca Rename YGUnitPixel to YGPoint...
Summary:
...to reflect the modern world we live in with dynamic DPI platforms :)
Closes https://github.com/facebook/yoga/pull/375

Reviewed By: dshahidehpour

Differential Revision: D4528518

Pulled By: emilsjolander

fbshipit-source-id: e422bd4ae148e02c598a7b484a6adfa8c0e1e0c9
2017-02-14 14:27:48 -08:00
Lukas Wöhrl
1146013e9e Feature auto margin
Summary:
Even so I know there are some opinions against ```margin: 0 auto``` it's still part of the spec: https://www.w3.org/TR/css-flexbox-1/#auto-margins and pretty usefull if you have to position via ```justify-content```.

This PR adds an implementation for that.

It adds an additonal ```YGUnitAuto``` and margins got ```YGNodeStyleSetMarginAuto``` functions as well.
Closes https://github.com/facebook/yoga/pull/357

Reviewed By: astreet

Differential Revision: D4501142

Pulled By: emilsjolander

fbshipit-source-id: 86519f8632496f46e78a7c9dbc5b21e212e3e0c7
2017-02-14 14:27:48 -08:00
Michael Bolin
8a91c0a0e5 Attempt to fix open source Yoga build.
Reviewed By: emilsjolander

Differential Revision: D4557733

fbshipit-source-id: b99701e9c1ec56fb147aa4cc738549df90aa7016
2017-02-14 10:45:02 -08:00
Emil Sjolander
a1c75454e9 Fix align-content strech with multiple lines
Summary: This is an update of facebook/yoga#368 which was reverted. It fixes support for align-content: strech with multiple lines. The problem with the last attempt at solving this was that align-items:stretch was interfering. We handle this now by detecting when the flex basis of the children hints at them overflowing. This is not 100% correct as the size of the items could change when remeasuring but it will work in 99% of cases.

Reviewed By: astreet

Differential Revision: D4551234

fbshipit-source-id: 2964f19cf415991dc55dfa2caa4868cb00c56bd0
2017-02-14 09:26:10 -08:00
Robert Spencer
ad3963daa6 Travis build of sample app
Summary: Build the sample app in travis

Reviewed By: emilsjolander

Differential Revision: D4558310

fbshipit-source-id: b730a7bc9036054a17c6204a93c63ea2064e0943
2017-02-14 08:41:42 -08:00
Robert Spencer
a66339d63c Separate YogaLayout library from sample app
Summary: The sample app has library-like elements (i.e. the `YogaLayout` and associated files).  This separates them out into a separate tree.

Reviewed By: emilsjolander

Differential Revision: D4558263

fbshipit-source-id: 33f8cec99661ef20e0e882663b554c12ae33c12f
2017-02-14 08:13:22 -08:00
Robert Spencer
d0bdd4dc91 Adds Android docs to landing page
Summary: Adds a simple "photo with poster and comment" layout to the landing page as an example for Android, along with the XML.

Reviewed By: emilsjolander

Differential Revision: D4558478

fbshipit-source-id: c7302321a67e99f5853358e711ff538d192f06e9
2017-02-14 08:13:22 -08:00
Robert Spencer
d24078be31 Move res files to be more gradle-esque
Summary: Resources don't usually live under the package name.  We want to gradle build this soon, so making the directory structure as traditional as possible is best.

Reviewed By: emilsjolander

Differential Revision: D4557978

fbshipit-source-id: 7f80599201fe007a895e52bc5141425f9a83eb51
2017-02-14 03:14:59 -08:00
Robert Spencer
f251648726 Add android docs
Summary: Adds docs for how to build the Android sample app and use the `YogaLayout`.

Reviewed By: emilsjolander

Differential Revision: D4557955

fbshipit-source-id: 49a3b8fde20de81a895244ffcecbd5bf392455b0
2017-02-14 02:48:14 -08:00
Emil Sjolander
b587ecb30f Fix travis builds
Summary: && instead of ; and only update xctools if needed

Reviewed By: passy

Differential Revision: D4558044

fbshipit-source-id: 90d55bf0147026e527b238365835d803a4bee7fb
2017-02-14 02:28:49 -08:00
Robert Spencer
a580712b2f Move in yoga sample android app
Summary: The sample app is simply moved into the repo.  A few libraries are included and the buck targets rearranged.

Reviewed By: emilsjolander

Differential Revision: D4528129

fbshipit-source-id: 3e9e779857cd9219711a939876c9275d75e09929
2017-02-14 00:11:38 -08:00
Michael Bolin
ce5d52b54e Update a number of build files in fbandroid/xplat to use the py_sdk build defs.
Summary:
I'm cleaning up these files in their own revision because I want to trigger
dirsync sandcastle separately from my other cleanup.

Reviewed By: mzlee

Differential Revision: D4549131

fbshipit-source-id: 1d45118256d8b517dea7a2b6c9e50bca1ccc1b0c
2017-02-13 22:26:31 -08:00
Dustin Shahidehpour
55fe6f0bc9 Add isDirty property and make markDirty less crashy/more performant.
Summary: For some internal Instagram diffs, and some external ones (auto-detection of dirty nodes). We need to give the dirty properties a little love. This adds a getter to find out if your node is dirty, and makes sure that the leaf node is properly setup before it is marked dirty to prevent a crash.

Reviewed By: emilsjolander

Differential Revision: D4549241

fbshipit-source-id: 36eda6fdb4ea7f968d126aab6da67896f4a01d40
2017-02-13 10:26:58 -08:00
Emil Sjolander
abf142ea3f Fix more travis file errors
Summary: and add badges to readme

Reviewed By: passy

Differential Revision: D4551571

fbshipit-source-id: c6eafe480e3667252eadc96c548c3b3c85046389
2017-02-13 09:41:35 -08:00
Dustin Shahidehpour
ae9f89b5d1 Add helper function for bulk updates.
Summary:
Currently, our configuration of Views looks like this:

```objc
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
view.yoga.isEnabled = YES;
view.yoga.height = 50;
view.yoga.width = 50;
```

Every time that we access `view.yoga` we have to access the associated object on `UIView` to get the `YGLayout`. This adds an extra `objc_msgSend` which increases binary size, and is slight perf impact.

This diff creates a way to modify the `YGLayout` with only a single `objc_msgSend`. Here's the new syntax:

```objc
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
[view configureLayoutWithBlock:^void(YGLayout *layout){
  layout.isEnabled = YES
  layout.height = 50;
  layout.width = 50;
}];
```

Here's the Swift version:
```swift
let view = UIView(frame: .zero)
view.configureLayout { (layout) in
  layout.isEnabled = true
  layout.height = 50
  layout.width = 50
}
```
Closes https://github.com/facebook/yoga/pull/393

Reviewed By: emilsjolander

Differential Revision: D4550382

Pulled By: dshahidehpour

fbshipit-source-id: 76d797d1e0de8e5dc767e02180a7fc440a70212e
2017-02-13 09:28:12 -08:00
Dustin Shahidehpour
058761e16e Give YogaKitSample some love, Convert it to a Swift Project
Summary:
To date, our sample project was lacking. There is still a lot of work that can be done to improve, but, this is a step in the right direction.

Here are the changes in this commit:
1. The project is written in Swift.
2. Created new CollectionView (via [IGListKit](https://github.com/instagram/iglistkit)), making it very easy to add new examples.
3. New examples for basic layouts, and including/excluding layouts on the fly.

Here's a video!

![](https://media.giphy.com/media/l0ExcvTLa0ADdawRa/giphy.gif)
Closes https://github.com/facebook/yoga/pull/392

Reviewed By: emilsjolander

Differential Revision: D4550379

Pulled By: dshahidehpour

fbshipit-source-id: 64a07acf96c1887f1d2ad0c54971fcedb64334a0
2017-02-13 09:13:43 -08:00
Kazuki Sakamoto
ad8c6225fd Build i386 for iOS and macOS
Summary: Closes https://github.com/facebook/yoga/pull/391

Reviewed By: emilsjolander

Differential Revision: D4549469

Pulled By: splhack

fbshipit-source-id: 7500b7235218f9a4f564adb36044303dff520fd6
2017-02-13 08:26:20 -08:00
Emil Sjolander
1cbadf5f54 Fix mistakes in travis file
Summary: Fix yaml errors

Reviewed By: passy

Differential Revision: D4551330

fbshipit-source-id: d17087cf51f9556c7015ea0fc4ab11fec44917f2
2017-02-13 06:56:27 -08:00
Emil Sjolander
e7021715b8 Split travis builds into multiple runs
Summary: Split travis into one run per language. This should improve build speed as well as improve signal as to what is failing.

Reviewed By: dshahidehpour

Differential Revision: D4551194

fbshipit-source-id: 36bc60193b4b287352073ab62a7bd053b15eaedf
2017-02-13 05:27:03 -08:00
Emil Sjolander
0d2749a3fd Revert D4528559: [yoga][PR] Fix align-content strech with multiple lines
Summary: This reverts commit 019e6f85fa452d0c3412f711e3886f0c4452da47

Differential Revision: D4528559

fbshipit-source-id: 4bd82b399cb36acb348f2c6fedcae6b360513424
2017-02-13 01:11:16 -08:00
Dustin Shahidehpour
76fbd628e1 Use correct rounding function when rounding pixels.
Summary: While debugging something at Instagram, I kept seeing a UILabel be truncated when it clearly had enough room to display all its' text. What I realized is that during our pixel rounding, we were losing precision because we were using the incorrect rounding function for floats. Changing from `round()` (which is for doubles) to `roundf()` fixed it.

Reviewed By: amonshiz

Differential Revision: D4549069

fbshipit-source-id: 78a1bb33e315e7c066b7fb625b1f5a28def76515
2017-02-11 19:56:08 -08:00
Dustin Shahidehpour
15309d2bdd Update README.md
Summary: Closes https://github.com/facebook/yoga/pull/389

Differential Revision: D4549243

Pulled By: dshahidehpour

fbshipit-source-id: 2c8d6d78af9f98994ad2f5f028494ae743c354b4
2017-02-11 14:12:51 -08:00
Dustin Shahidehpour
4f6924a0c1 BREAKING CHANGE: rename applyLayout to applyLayoutPreservingOrigin.
Summary: Will update on Monday

Reviewed By: emilsjolander

Differential Revision: D4545786

fbshipit-source-id: f8189d82f1c64cd1eac532fd2dfaa9aea35d6004
2017-02-11 11:26:07 -08:00
Lukas Wöhrl
063f65d065 Fix align-content strech with multiple lines
Summary:
Fixes ```align-content:strech``` on nodes without specified cross dimension, if there are multiple lines. Currently it uses the full height of the parent, but it has to use the line height. As we don't know the number of lines until here, we need to realign the relevant children.
Closes https://github.com/facebook/yoga/pull/368

Reviewed By: gkassabli

Differential Revision: D4528559

Pulled By: emilsjolander

fbshipit-source-id: 019e6f85fa452d0c3412f711e3886f0c4452da47
2017-02-11 08:41:45 -08:00
Lukas Wöhrl
adf8691093 Fix resolving bug on changing layout and optimized memory usage
Summary:
Due to the changes in 46817a38. We have a bug if the layout changes.

This PR fixes this bug and adds a test for it.

Additionally it correctly marks negative percentage values as undefined dim.

It also changes the ```resolvedDimensions``` to use a reference instead of the full value in order to minimize the memory requirement of a ```YGNode``` and reduces the copying of the ```YGValue```.
Closes https://github.com/facebook/yoga/pull/379

Reviewed By: gkassabli

Differential Revision: D4528552

Pulled By: emilsjolander

fbshipit-source-id: c024fe3a009c3788af319b689858ea3374c46477
2017-02-11 08:41:45 -08:00
Lukas Wöhrl
6a7ad2125d Add support for space-between and space-around on align-content
Summary:
Adds the two missing alignments ```space-between``` and ```space-around``` for ```align-content``` . Those values are a noop on ```align-items``` in order to prevent a breaking changes for an additional enum.

Fix #229
Closes https://github.com/facebook/yoga/pull/364

Reviewed By: gkassabli

Differential Revision: D4528561

Pulled By: emilsjolander

fbshipit-source-id: ea6291b6dd22cef05d9eec03893250d50371236e
2017-02-11 08:41:45 -08:00
Lukas Wöhrl
247aa26d3e Make enums.py c header output resistent to format.sh
Summary:
This PR changes the enums.py to create the header the same as format.sh would layout it. Reduces the clutter due to missed format.sh calls after enums.py generation.
Closes https://github.com/facebook/yoga/pull/380

Reviewed By: gkassabli

Differential Revision: D4529593

Pulled By: emilsjolander

fbshipit-source-id: 7281e0d500f79459c19cc8fe6dbc8fd77f0a537c
2017-02-11 08:41:45 -08:00
Dustin Shahidehpour
3c9f620c77 BREAKING CHANGE: Computed edge values are no longer returned on concrete properties, fix tests.
Summary:
Now that the Yoga library supports percentage values, the results returned from it's API were changed.

`YGNodeStyleGetPadding` returns the explicit value that you set, whereas `YGNodeLayoutGetPadding` returns the computed value. Since we are planning to build support for percentages, I'm modifying our API so that it strictly returns the value that was set. As a result:

```
view.yoga.margin = 10;

// view.yoga.margin == 10
// view.yoga.marginLeftWidth == 0
// view.yoga.marginRightWidth == 0
// etc.
```

Reviewed By: emilsjolander

Differential Revision: D4543471

fbshipit-source-id: a731025cd4b47e9f1a559c766494fc5a259291ae
2017-02-11 08:28:50 -08:00
Emil Sjolander
e0e2a61dfc Use Float.compare in java equals
Summary: Handles nans. Also if the unit is undefined there is no need to check the value.

Reviewed By: astreet

Differential Revision: D4531805

fbshipit-source-id: 723e15381e9fa39837a4c99f726501eda26af11b
2017-02-11 06:27:15 -08:00
Emil Sjolander
168ae4099d Always return undefined value if nothing is set
Summary: This reflects a check to native code where style values will always return the value that was set on them and default to undefined.

Reviewed By: astreet

Differential Revision: D4531779

fbshipit-source-id: 97a789e70dcf0fb5174e2039991e7a2b27f45f01
2017-02-11 06:27:12 -08:00
Emil Sjolander
6ceb4af2d4 Expose layout border to java
Summary: Expose layout border to java

Reviewed By: astreet

Differential Revision: D4543284

fbshipit-source-id: 6030915fc6f758e785a688f94c8ffbec7fbac8b8
2017-02-11 06:27:04 -08:00
Emil Sjolander
240c2dd657 Fix min/max not overriding width/height
Summary:
Two bugs:
1. Min/Max width/height should have higher priority than width/height
2. custom measure nodes percentages should be based in parent size like everything else.

Differential Revision: D4537576

fbshipit-source-id: c003f723f424afbca63170d41e54fd5ff837926d
2017-02-11 05:28:10 -08:00
Rui Marinho
a5b94ebd0c Add YogaDisplay to shared project
Summary: Closes https://github.com/facebook/yoga/pull/383

Reviewed By: emilsjolander

Differential Revision: D4537332

Pulled By: splhack

fbshipit-source-id: d3068fc09e567c9f175bdcc8974c8069575ef5f7
2017-02-10 11:13:24 -08:00
Dustin Shahidehpour
5037c2f365 Preserve the origin of the root view.
Summary: Currently, we have an issue in YogaKit where it ignores the preexisting bounds a root view. There are multiple fixes for this, but the easiest one for developer experience is to apply the preexisting bounds of the root view to it's frame after layout calculation.

Reviewed By: emilsjolander

Differential Revision: D4537173

fbshipit-source-id: ccef8b1c1398ea299b4e5710abe597378347a48d
2017-02-09 13:10:59 -08:00
Dustin Shahidehpour
ef05404bee Bump YogaKit podspec.
Summary: See commit message. #accept2ship

Reviewed By: emilsjolander

Differential Revision: D4536585

fbshipit-source-id: 808e39e7a38f470c67459a42686e095d8b5e5fc6
2017-02-09 08:46:30 -08:00
Dustin Shahidehpour
3db493665e Bump podspec version.
Summary: See commit message. #accept2ship

Reviewed By: emilsjolander

Differential Revision: D4536570

fbshipit-source-id: 4fc72bd4d9418ea06d24a6ca0cdd6845def30465
2017-02-09 08:26:17 -08:00
Emil Sjolander
737f1cc67c Remove now not needed definition of allow_unsafe_import
Summary: not needed any more

Reviewed By: bolinfest

Differential Revision: D4532533

fbshipit-source-id: 43b4db9a21ae774f7d41187e4e4598e171b7a59c
2017-02-09 03:27:11 -08:00
Georgiy Kassabli
b5c2b09780 Revert D4456312: Fix for Yoga test failure for flexing with min stack dimension
Summary: This reverts commit 82a39bc93cf3bf2374b968e9f7403397e752908e

Differential Revision: D4456312

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

Reviewed By: emilsjolander

Differential Revision: D4492395

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

Reviewed By: emilsjolander

Differential Revision: D4456312

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

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

Reviewed By: astreet

Differential Revision: D4501141

Pulled By: emilsjolander

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

Differential Revision: D4515193

Pulled By: dshahidehpour

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

Reviewed By: amonshiz

Differential Revision: D4508624

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

Reviewed By: astreet

Differential Revision: D4501016

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

Reviewed By: astreet

Differential Revision: D4500892

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

Reviewed By: emilsjolander

Differential Revision: D4507887

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

Reviewed By: gkassabli

Differential Revision: D4494265

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

Reviewed By: gkassabli

Differential Revision: D4494263

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

Reviewed By: gkassabli

Differential Revision: D4494258

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

Reviewed By: gkassabli

Differential Revision: D4501140

Pulled By: emilsjolander

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

Reviewed By: pasqualeanatriello

Differential Revision: D4494371

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

Reviewed By: emilsjolander

Differential Revision: D4500973

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

Reviewed By: emilsjolander

Differential Revision: D4494367

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

Reviewed By: emilsjolander

Differential Revision: D4481501

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

Differential Revision: D4482049

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

Differential Revision: D4482028

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

Reviewed By: emilsjolander

Differential Revision: D4481490

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

Reviewed By: dshahidehpour

Differential Revision: D4488099

Pulled By: emilsjolander

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

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

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

Reviewed By: emilsjolander

Differential Revision: D4488011

Pulled By: dshahidehpour

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

Reviewed By: emilsjolander

Differential Revision: D4482411

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

Reviewed By: dshahidehpour

Differential Revision: D4481945

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

Reviewed By: astreet

Differential Revision: D4476067

Pulled By: emilsjolander

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

Reviewed By: emilsjolander

Differential Revision: D4481713

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

Reviewed By: emilsjolander

Differential Revision: D4481772

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

Reviewed By: gkassabli

Differential Revision: D4480608

Pulled By: emilsjolander

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

Reviewed By: dshahidehpour

Differential Revision: D4479027

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

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

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

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

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

Reviewed By: emilsjolander

Differential Revision: D4475370

Pulled By: splhack

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

Reviewed By: dshahidehpour

Differential Revision: D4477027

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

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

**TODO**

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

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

Reviewed By: emilsjolander

Differential Revision: D4471950

Pulled By: dshahidehpour

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

Reviewed By: astreet

Differential Revision: D4473024

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

Reviewed By: emilsjolander

Differential Revision: D4474945

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

Differential Revision: D4471126

Pulled By: dshahidehpour

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

Reviewed By: dshahidehpour

Differential Revision: D4459455

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

Reviewed By: dshahidehpour

Differential Revision: D4459950

Pulled By: emilsjolander

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

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

Reviewed By: dshahidehpour

Differential Revision: D4458528

Pulled By: emilsjolander

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

Reviewed By: nlutsenko, emilsjolander

Differential Revision: D4466788

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

Reviewed By: dshahidehpour

Differential Revision: D4455438

Pulled By: emilsjolander

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

Reviewed By: gkassabli

Differential Revision: D4453612

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

Reviewed By: mhorowitz

Differential Revision: D4420352

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

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

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

Reviewed By: emilsjolander

Differential Revision: D4454484

Pulled By: dshahidehpour

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

Reviewed By: emilsjolander

Differential Revision: D4453745

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

Reviewed By: emilsjolander

Differential Revision: D4453795

Pulled By: dshahidehpour

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

Differential Revision: D4416273

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

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

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

  YGNodeFree(node);
}

```

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

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

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

Reviewed By: dshahidehpour

Differential Revision: D4421504

Pulled By: emilsjolander

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

Reviewed By: splhack

Differential Revision: D4245200

Pulled By: emilsjolander

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

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

Reviewed By: mmmulani

Differential Revision: D4182141

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

Reviewed By: gkassabli

Differential Revision: D4420355

Pulled By: emilsjolander

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

Reviewed By: gkassabli

Differential Revision: D4409399

Pulled By: emilsjolander

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

Adds YogaKit sample.

Adds YogaKit tests (same as objc).

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

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

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

Reviewed By: splhack

Differential Revision: D4415027

Pulled By: emilsjolander

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

Reviewed By: dshahidehpour

Differential Revision: D4415019

Pulled By: emilsjolander

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

Reviewed By: emilsjolander

Differential Revision: D4408799

Pulled By: splhack

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

Reviewed By: emilsjolander

Differential Revision: D4403967

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

Reviewed By: emilsjolander

Differential Revision: D4403163

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

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

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

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

Reviewed By: emilsjolander

Differential Revision: D4401408

Pulled By: splhack

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

Adds support for percentage value in react native.

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

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

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

Reviewed By: astreet

Differential Revision: D4376549

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

Reviewed By: passy

Differential Revision: D4397547

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

Differential Revision: D4392516

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

Reviewed By: gkassabli

Differential Revision: D4397691

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

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

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

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

Reviewed By: emilsjolander

Differential Revision: D4393234

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

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

Reviewed By: cwdick

Differential Revision: D4392272

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

Reviewed By: cosmin1123

Differential Revision: D4391434

Pulled By: emilsjolander

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

Reviewed By: emilsjolander

Differential Revision: D4390687

Pulled By: splhack

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

Reviewed By: emilsjolander

Differential Revision: D4388480

Pulled By: splhack

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

Differential Revision: D4386906

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

Reviewed By: emilsjolander

Differential Revision: D4385336

Pulled By: splhack

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

Reviewed By: dshahidehpour

Differential Revision: D4386906

Pulled By: emilsjolander

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

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

Reviewed By: splhack

Differential Revision: D4385061

Pulled By: emilsjolander

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

Reviewed By: splhack

Differential Revision: D4377070

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

Reviewed By: passy

Differential Revision: D4377069

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

Differential Revision: D4376572

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

Reviewed By: emilsjolander

Differential Revision: D4384510

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

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

Reviewed By: emilsjolander

Differential Revision: D4378826

Pulled By: dshahidehpour

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

Differential Revision: D4383905

Pulled By: dshahidehpour

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

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

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

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

Reviewed By: splhack, emilsjolander

Differential Revision: D4381455

Pulled By: JoelMarcey

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

Reviewed By: emilsjolander

Differential Revision: D4381190

Pulled By: splhack

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

Reviewed By: gkassabli, passy

Differential Revision: D4383686

Pulled By: emilsjolander

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

Reviewed By: gkassabli

Differential Revision: D4383687

Pulled By: emilsjolander

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

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

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

Reviewed By: mikearmstrong001

Differential Revision: D4377198

Pulled By: emilsjolander

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

Reviewed By: emilsjolander

Differential Revision: D4376759

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

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

I did some benchmarks:

```
Without Percentage Feature - Release x86:

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

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

With Percentage Feature - Release x86:

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

Reviewed By: dshahidehpour

Differential Revision: D4361945

Pulled By: emilsjolander

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

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

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

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

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

 ---

To do:

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

Reviewed By: mikearmstrong001

Differential Revision: D4375187

Pulled By: emilsjolander

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

Differential Revision: D4366605

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

Reviewed By: JoelMarcey

Differential Revision: D4365700

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

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

Reviewed By: splhack

Differential Revision: D4365993

Pulled By: emilsjolander

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

Reviewed By: vjeux

Differential Revision: D4366002

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

Reviewed By: vjeux

Differential Revision: D4366004

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

Reviewed By: emilsjolander

Differential Revision: D4365845

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

Reviewed By: emilsjolander

Differential Revision: D4365853

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

Reviewed By: emilsjolander

Differential Revision: D4365827

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

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

Reviewed By: dshahidehpour

Differential Revision: D4365533

Pulled By: emilsjolander

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

Reviewed By: emilsjolander

Differential Revision: D4365773

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

Reviewed By: dshahidehpour

Differential Revision: D4365534

Pulled By: emilsjolander

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

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

Reviewed By: emilsjolander

Differential Revision: D4365462

Pulled By: splhack

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

Reviewed By: Perspx

Differential Revision: D4352670

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

Reviewed By: emilsjolander

Differential Revision: D4344198

Pulled By: splhack

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

Reviewed By: passy

Differential Revision: D4356994

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

Differential Revision: D4351523

Pulled By: emilsjolander

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

Differential Revision: D4346529

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

Differential Revision: D4346720

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

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

Differential Revision: D4339132

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

Differential Revision: D4346712

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

Reviewed By: emilsjolander

Differential Revision: D4313632

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

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

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

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

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

Reviewed By: emilsjolander

Differential Revision: D4357662

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

Reviewed By: emilsjolander

Differential Revision: D4348344

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

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

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

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

Differential Revision: D4351597

Pulled By: emilsjolander

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

Differential Revision: D4335198

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

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

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

Reviewed By: emilsjolander

Differential Revision: D4338919

Pulled By: splhack

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

Reviewed By: gkassabli

Differential Revision: D4333480

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

Reviewed By: emilsjolander

Differential Revision: D4338485

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

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

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

- `__IOS__`

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

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

Reviewed By: emilsjolander

Differential Revision: D4338420

Pulled By: splhack

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

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

Reviewed By: emilsjolander

Differential Revision: D4333811

Pulled By: splhack

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

Reviewed By: gkassabli

Differential Revision: D4333456

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

Reviewed By: emilsjolander

Differential Revision: D4295954

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

Reviewed By: emilsjolander

Differential Revision: D4296488

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

Reviewed By: dshahidehpour

Differential Revision: D4333129

Pulled By: emilsjolander

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

Reviewed By: dshahidehpour

Differential Revision: D4333185

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

Reviewed By: gkassabli

Differential Revision: D4306164

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

Differential Revision: D4284681

Summary: Rename csslayout directories to yoga

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

Reviewed By: gkassabli

Differential Revision: D4276177

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

Reviewed By: splhack

Differential Revision: D4271411

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

Reviewed By: gkassabli

Differential Revision: D4271422

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

Reviewed By: dshahidehpour, gkassabli

Differential Revision: D4271399

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

Reviewed By: gkassabli

Differential Revision: D4274156

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

Differential Revision: D4271420

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

Reviewed By: IanChilds

Differential Revision: D4265345

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

Reviewed By: gkassabli

Differential Revision: D4265235

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

Differential Revision: D4259190

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

Reviewed By: splhack

Differential Revision: D4247106

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

Reviewed By: dshahidehpour

Differential Revision: D4245987

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

Reviewed By: splhack

Differential Revision: D4245765

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

Differential Revision: D4244360

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

Reviewed By: gkassabli

Differential Revision: D4258293

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

Reviewed By: gkassabli

Differential Revision: D4258291

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

Reviewed By: gkassabli

Differential Revision: D4258254

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

Differential Revision: D4245638

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

Differential Revision: D4248487

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

Reviewed By: lexs

Differential Revision: D4251133

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

Reviewed By: gkassabli

Differential Revision: D4248487

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

Reviewed By: gkassabli

Differential Revision: D4245638

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

Reviewed By: passy

Differential Revision: D4248473

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

Reviewed By: splhack

Differential Revision: D4247282

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

Reviewed By: AaaChiuuu

Differential Revision: D4233198

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

Reviewed By: splhack

Differential Revision: D4232920

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

Reviewed By: lexs

Differential Revision: D4243906

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

Reviewed By: splhack

Differential Revision: D4240761

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

Reviewed By: lexs

Differential Revision: D4237790

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

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

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

Reviewed By: passy

Differential Revision: D4237009

Pulled By: emilsjolander

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

Reviewed By: gkassabli

Differential Revision: D4226734

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

Reviewed By: gkassabli

Differential Revision: D4222910

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

Reviewed By: emilsjolander

Differential Revision: D4218623

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

Reviewed By: splhack

Differential Revision: D4214168

Pulled By: emilsjolander

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

Reviewed By: splhack

Differential Revision: D4213809

Pulled By: emilsjolander

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

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

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

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

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

  [container css_applyLayout];
```

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

Reviewed By: emilsjolander

Differential Revision: D4215659

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

Reviewed By: gkassabli

Differential Revision: D4213339

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

Reviewed By: gkassabli

Differential Revision: D4213313

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

Reviewed By: gkassabli

Differential Revision: D4213302

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

Reviewed By: gkassabli

Differential Revision: D4211458

fbshipit-source-id: f8d0d318369c7b529ee29e61a52b17d0cf3b396d
2016-11-21 10:22:32 -08:00
Emil Sjolander
b16c22a8f3 Only skip updating computed flex basis within the same generation
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
2016-11-20 05:07:33 -08:00
Lukas Wöhrl
56ec33a463 Fix CS0675 warning in c#
Summary:
Fix CS0675 warning in c#.
Closes https://github.com/facebook/css-layout/pull/255

Reviewed By: emilsjolander

Differential Revision: D4204765

Pulled By: splhack

fbshipit-source-id: bcf71796e1bf585a94b3549905cb6d6bc78a34b8
2016-11-18 09:37:33 -08:00
Lukas Wöhrl
367c3a28be use fmaxf to prevent casting from and to double
Summary:
Use ```fmaxf``` to prevent double casting.
Closes https://github.com/facebook/css-layout/pull/251

Reviewed By: emilsjolander

Differential Revision: D4199342

Pulled By: splhack

fbshipit-source-id: c04bc68a3c9c97b92e910e885457cf2fe00da28b
2016-11-17 20:52:54 -08:00
Lukas Wöhrl
653150a7c4 Change more method arguments to const
Summary:
Change more method arguments to ```const```
Closes https://github.com/facebook/css-layout/pull/252

Reviewed By: emilsjolander

Differential Revision: D4199335

Pulled By: splhack

fbshipit-source-id: f54fccaea8051a49c6cdf0fcaf1a68c025ba26da
2016-11-17 20:52:54 -08:00
Lukas Wöhrl
542fc50409 do not redefine isnan if already defined via math.h
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
2016-11-17 20:52:54 -08:00
Lukas Wöhrl
4f192481ee use size_t instead of unsigned long
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
2016-11-17 20:52:54 -08:00
Kazuki Sakamoto
0bb2955c5c CSSNodeCopyStyle API for Java and C#
Summary: Add CopyStyle API for Java and C#

Reviewed By: emilsjolander

Differential Revision: D4189954

fbshipit-source-id: 10759fdb27bf67350d3151614f7815aa09bf7e04
2016-11-17 09:22:37 -08:00
Kazuki Sakamoto
191ac98b89 Introduce CSSNodeCopyStyle
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
2016-11-17 09:22:37 -08:00
Kazuki Sakamoto
32c175ac55 Workaround fix for Visual Studio
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
2016-11-17 09:07:28 -08:00
Dustin Shahidehpour
4b61cdccea Add flag to not include view in layout.
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
2016-11-17 08:37:34 -08:00
Kazuki Sakamoto
b9c4c403a9 Fix memory func test
Summary: Reset gNodeInstanceCount before memory func test.

Reviewed By: emilsjolander

Differential Revision: D4193712

fbshipit-source-id: a4aba84d054d98a7baf438e213a90bd7ef34e979
2016-11-17 07:52:34 -08:00
Dustin Shahidehpour
56aa279fef BREAKING: remove css_sizeThatFits:, replace with new API.
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
2016-11-17 07:37:32 -08:00
Kazuki Sakamoto
7e4bb732ff Introduce CSSNode.Create API
Summary:
Add a convenience construction method for CSSNode.

    CSSNode node = CSSNode.Create(
        positionType: CSSPositionType.Absolute,
        wrap: CSSWrap.Wrap,
        position: new Spacing(top:6, right:4),
        margin: new Spacing(bottom:5, left:3));

Reviewed By: emilsjolander

Differential Revision: D4193380

fbshipit-source-id: 30b917f64e92997355a76e3b11799883b86fb9de
2016-11-17 07:07:32 -08:00
Emil Sjolander
32ba5ae647 Make gtest a submodule in open source
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
2016-11-17 04:52:31 -08:00
Emil Sjolander
2fa6f5087d Disable UIKit memory tests on travis
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
2016-11-17 04:37:34 -08:00
Emil Sjolander
c2aac9f46e Add googletest submodule 2016-11-16 16:36:36 +01:00
Kazuki Sakamoto
ef81d4b0c7 Introduce CSSLayoutSetMemoryFuncs
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
2016-11-15 20:22:51 -08:00
Kazuki Sakamoto
667858990c Fix build
Summary: Fix C# build

Reviewed By: emilsjolander

Differential Revision: D4183287

fbshipit-source-id: 7dda449a940589de1d37f4024964a6512ab123e3
2016-11-15 17:37:34 -08:00
Kazuki Sakamoto
d80bac4234 Use LTR and RTL instead obsolete enums
Summary: Use LTR and RTL instead obsolete LeftToRight and RightToLeft enums

Reviewed By: emilsjolander

Differential Revision: D4175897

fbshipit-source-id: d22af46d3292f9ad1754f571e95cb64b11722f7b
2016-11-15 09:22:45 -08:00
Emil Sjolander
d1c555fede Autogenerate enum defenitions for all languages
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
2016-11-15 08:52:59 -08:00
Emil Sjolander
ac4d0ab2a1 Count allocations relative to start of test
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
2016-11-15 07:22:34 -08:00
Emil Sjolander
603321e1ab Install and use java 8 on travis
Summary: Java tests need to run with java 8, ensure travis runs java 8

Reviewed By: gkassabli

Differential Revision: D4182384

fbshipit-source-id: 61ba77d3e0f008f50912d088d3e504cb96e46bdc
2016-11-15 06:40:51 -08:00
Dustin Shahidehpour
129437f49e Change CLK prefix on static functions to CSS.
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
2016-11-14 13:22:52 -08:00
Fred Liu
204aba80b9 Revert D4157971: [csslayout] BREAKING - Fix sizing of container with child overflowing parent
Summary: This reverts commit 3cfae15ac8b65b70f01789444099ee684e1b099a

Differential Revision: D4157971

fbshipit-source-id: be055cf018fd39b3cee9af0bc777831fcf757190
2016-11-14 12:22:58 -08:00
Emil Sjolander
e6702e1168 Implement standard interface for toggling experimental features
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
2016-11-14 03:37:45 -08:00
Emil Sjolander
b99172d28b rename CSSWrapType to shorter CSSWrap matching java and csharp
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
2016-11-14 03:37:45 -08:00
Emil Sjolander
7a3df9999b BREAKING - Fix sizing of container with child overflowing parent
Summary:
Fixes issue brought up in https://github.com/facebook/react-native/issues/10603

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

Reviewed By: gkassabli

Differential Revision: D4157971

fbshipit-source-id: 3cfae15ac8b65b70f01789444099ee684e1b099a
2016-11-14 02:22:44 -08:00
Dustin Shahidehpour
e0e88f97b6 Cleanup documentation, add pragma marks, and rename static functions in UIView+CSSLayout
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
2016-11-11 16:52:47 -08:00
Dustin Shahidehpour
b4d0e1a17c Add some more compiler flags to CSSLayoutKit.
Summary: Just firming up some stuff with more compiler flags.

Reviewed By: rnystrom

Differential Revision: D4168081

fbshipit-source-id: fced407f03944081bdd70cc28c57e3dc842ff7f0
2016-11-11 15:07:35 -08:00
Kazuki Sakamoto
e40af30fa5 Update .travis.yml for C# test
Summary: Closes https://github.com/facebook/css-layout/pull/246

Reviewed By: emilsjolander

Differential Revision: D4167133

Pulled By: splhack

fbshipit-source-id: d55c0ff5155311f4da859b12b6485b120dac480b
2016-11-11 09:07:44 -08:00
Emil Sjolander
cd054ecf26 Expose CSSLayoutSetLogger to java
Summary: Expose CSSLayoutSetLogger to java

Reviewed By: astreet

Differential Revision: D4153502

fbshipit-source-id: 630909d9d0d36d94d7cd3027476ddb52668b8cc0
2016-11-11 08:23:14 -08:00
Emil Sjolander
aaa977f645 Fix flex within max size if max size is not constraint to
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
2016-11-11 08:07:42 -08:00
Dustin Shahidehpour
70e01a4476 Rename uikit/CSSLayout to CSSLayoutKit.
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
2016-11-11 07:38:15 -08:00
Emil Sjolander
3e2c13f418 Fix running ios tests in travis
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
2016-11-10 19:52:56 -08:00
Kazuki Sakamoto
0dbbfc5910 Add convenient cast method for MeasureOutput.Make
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
2016-11-10 19:22:36 -08:00
Pieter De Baets
f222d22ba8 Remove useless store in CSSLayout.c
Summary: Pointed out by the Xcode analyzer

Reviewed By: emilsjolander

Differential Revision: D4159938

fbshipit-source-id: 8b9ff3896c0e222e8e89546881129214bc6ba566
2016-11-10 08:53:05 -08:00
Emil Sjolander
087d1f3a82 Fix benchmark
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
2016-11-09 20:22:41 -08:00
Kazuki Sakamoto
c382d513fb Remove CSSAssertSetFailFunc
Summary: Remove CSSAssertSetFailFunc and use CSSLogLevelError for throwing managed exception.

Reviewed By: emilsjolander

Differential Revision: D4155452

fbshipit-source-id: 5a19c79a212f204d13064527fd6e5843bab76e6b
2016-11-09 17:38:10 -08:00
Kazuki Sakamoto
8a7183f465 Add tests for SetMeasureFunction
Summary: Add tests for checking C side asserts in managed

Reviewed By: emilsjolander

Differential Revision: D4154869

fbshipit-source-id: 5203db27eff963d46f188de448f607a24ed63fab
2016-11-09 13:23:00 -08:00
Emil Sjolander
ff602d4606 Absolute positioned items should apear inside padding but outside border
Summary:
Absolute positioned elements were not correctly respecting border / padding.

https://github.com/facebook/css-layout/issues/245
fixes #245

Reviewed By: gkassabli

Differential Revision: D4153332

fbshipit-source-id: 251e29e02018a433f60349b78c03feb121512797
2016-11-09 11:52:54 -08:00
Emil Sjolander
f5912a97e4 Fix issues with running test in open source
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
2016-11-09 11:37:48 -08:00
Emil Sjolander
a253c6fbb7 Dont measure single flex grow+shrink child
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
2016-11-09 11:37:48 -08:00
Kazuki Sakamoto
863378d74e Sync Logger API
Summary: - Sync Logger API with C implementation

Reviewed By: emilsjolander

Differential Revision: D4143019

fbshipit-source-id: f20203320bad5b8f4b9cce01a5b2e7c615a4d923
2016-11-09 10:22:42 -08:00
Andy Street
f1fcd5e382 Update logging to support levels, print messages in Android logcat on assertion failures
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
2016-11-09 09:52:43 -08:00
Emil Sjolander
6a6efe0764 change default value of position styles
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
2016-11-09 09:22:40 -08:00
Dustin Shahidehpour
e54af5e854 Allow MeasureFunc to be set to NULL no matter how many children a node has.
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
2016-11-09 08:52:45 -08:00
Jing Chen
502f3c7010 Reverted commit D4147298
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
2016-11-09 00:07:45 -08:00
Emil Sjolander
12ebaa56b6 Dont measure single flex grow+shrink child
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
2016-11-08 15:37:48 -08:00
Emil Sjolander
3e567fdcae Fix flex within max width constraint
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
2016-11-08 09:53:00 -08:00
Emil Sjolander
1baa239389 Remove isTextNode optimization
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
2016-11-08 09:22:38 -08:00
Dustin Shahidehpour
b50090a04e NSAssert -> NSCAssert.
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
2016-11-08 07:22:48 -08:00
Kazuki Sakamoto
ba2905dd1d Add C# test script for macOS
Summary: - Updated README and added bash script for testing C# on macOS

Reviewed By: emilsjolander

Differential Revision: D4142507

fbshipit-source-id: c682778e42d10242e02f3fdafe8a23f906bfabc5
2016-11-07 19:37:57 -08:00
Dustin Shahidehpour
997088ffbb Fix broken unit tests.
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
2016-11-07 14:37:56 -08:00
Emil Sjolander
ffb90e6ff2 Remove check for both modes being exact as this will never happen
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
2016-11-07 14:37:55 -08:00
Rachit Siamwalla
1c22a1aa53 Fix xplat CSSLayoutTests to compile on platforms without death tests.
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
2016-11-07 14:07:49 -08:00
Dustin Shahidehpour
7082734c6b Kill border API.
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
2016-11-07 13:37:47 -08:00
Dustin Shahidehpour
366a61af8d Take care of pixel rounding for UIView.
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
2016-11-07 13:37:47 -08:00
安秋亮
18fe0959f0 Add inline definition for Microsoft Visual Studio
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
2016-11-07 13:07:40 -08:00
Dustin Shahidehpour
1ffce3edb1 Sanitize results from sizeThatFits:, fix bug where only one of the measure modes is CSSMeasureModeExactly.
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
2016-11-07 06:52:47 -08:00
Andy Street
6165d7a2be Make CSSNode#measure final, cache more correct methodid
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
2016-11-07 06:07:36 -08:00
Andy Street
01a3881426 Lazy create children list when first child is added
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
2016-11-07 05:52:41 -08:00
Andy Street
9c1896043d Assert that node can have measure function <==> node is a leaf node
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
2016-11-07 05:37:45 -08:00
Dustin Shahidehpour
0f822bbef2 Remove overflow and flex from API.
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
2016-11-04 13:37:40 -07:00
Dustin Shahidehpour
e00e30ca15 Only mark Nodes dirty if an actual node is removed.
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
2016-11-03 13:38:05 -07:00
Dustin Shahidehpour
b938017ccf Add Sizing API that doesn't change view's frame.
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
2016-11-03 13:07:37 -07:00
Georgiy Kassabli
630ae0972b Exposing layout cache check publicly
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
2016-11-03 10:52:43 -07:00
Dustin Shahidehpour
d8662805d5 Fix incorrect results from css_usesFlexbox
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
2016-11-03 09:37:41 -07:00
Dustin Shahidehpour
26e7490fc9 Make CSSNodeRef readonly.
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
2016-11-03 09:07:37 -07:00
Dustin Shahidehpour
d94363ea7e Cleanup Measure method.
Summary: We have redundant/dead code in UIKit's sizing method, lets clean it up.

Reviewed By: emilsjolander

Differential Revision: D4110939

fbshipit-source-id: 35e856aa6c60fd24316bc67cc564f7eec2d9d714
2016-11-02 17:07:47 -07:00
Lukas Wöhrl
af5e6771d7 Prevent array out of bound access
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
2016-11-01 20:54:00 -07:00
Dustin Shahidehpour
ced779b259 Prevent crash when accessing child count, but child list is NULL.
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
2016-10-31 12:52:52 -07:00
Emil Sjolander
a65e6930cf Some small simplifications for function return values
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
2016-10-31 11:08:05 -07:00
Emil Sjolander
267e17f23a void* -> CSSNodeRef in CSSNodeList
Summary: This list can only contain CSSNodeRefs so don't use void*

Reviewed By: gkassabli

Differential Revision: D4101773

fbshipit-source-id: 8a5c9066da796967bd02ce6b1fc74ff40e15dfe1
2016-10-31 11:08:02 -07:00
Emil Sjolander
df6368e048 Add complex layout to benchmark
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
2016-10-31 10:38:02 -07:00
Emil Sjolander
ba20d75992 Fix benchmark
Summary: Benchmark accidentally broke during a refactor

Reviewed By: gkassabli

Differential Revision: D4101776

fbshipit-source-id: 00094837b7856c06c0463c48929f960122c0c8ac
2016-10-31 10:38:02 -07:00
Dustin Shahidehpour
620cb3f507 Remove static method declarations.
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
2016-10-27 12:52:43 -07:00
Kazuki Sakamoto
3201e24780 Fix build and clean up
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
2016-10-27 11:53:11 -07:00
Emil Sjolander
2cac77eaa1 Set layout outputs on java object from C
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
2016-10-27 10:52:57 -07:00
Emil Sjolander
46823878a5 BREAKING - Make first parameter of measure and print functions CSSNodeRef instead of just context
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
2016-10-27 10:52:57 -07:00
Emil Sjolander
b59ce09109 BREAKING - Change measure() api to remove need for MeasureOutput allocation
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
2016-10-27 10:52:57 -07:00
Emil Sjolander
c34299edc9 Reset java state in jni reset method
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
2016-10-26 07:37:47 -07:00
Kazuki Sakamoto
1ba81d9ec7 Prevent GC and avoid new
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
2016-10-26 06:52:41 -07:00
Emil Sjolander
d6d817c142 Dont go down through JNI to figure out that no margin/padding/border/position was set
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
2016-10-26 03:07:42 -07:00
Scott Wolchok
01c2ac3369 Don't preallocate child lists
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
2016-10-25 17:22:47 -07:00
Emil Sjolander
0cc1b83569 Remove nanosleep from benchmark measure and increase loop count
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
2016-10-25 16:23:04 -07:00
Lukas Wöhrl
c8d77b2aae Remove children from the end to prevent copying over
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
2016-10-25 12:22:48 -07:00
Emil Sjolander
01507044b3 Suggest the compiler to inline smaller functions
Summary: Suggest the compiler inline some functions. Shows ~15% performance benefit on android compiling with gcc.

Reviewed By: gkassabli

Differential Revision: D4074580

fbshipit-source-id: 69b63fadf2011cb688af58f09d67c2cb711a0e20
2016-10-25 10:37:45 -07:00
Kazuki Sakamoto
2168d68007 Update CSSNodeFree for C#, Java and Objective-C
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
2016-10-25 07:52:39 -07:00
Emil Sjolander
4d0e657653 Fix bug in canUseCachedMeasurement causing unneeded double measure
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
2016-10-25 07:37:59 -07:00
Kazuki Sakamoto
4452c7be5c Remove no longer needed Spacing.cs
Summary: - Remove no longer needed Spacing.cs

Reviewed By: emilsjolander

Differential Revision: D4073539

fbshipit-source-id: 916cf85119c6bac3d516de5396ea3ba7b0af1475
2016-10-25 07:08:00 -07:00
Emil Sjolander
15f5c4cea5 Reduce duplicate function calls
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
2016-10-24 12:37:49 -07:00
Emil Sjolander
97fef59f96 Dont hold strong reference to java objects creating a cycle
Summary: Use weak reference to avoid cycle

Reviewed By: splhack

Differential Revision: D4064773

fbshipit-source-id: 4088fef5e088a8415747898ef17851e21ada5180
2016-10-24 12:37:49 -07:00
Emil Sjolander
e9b9973cae Dont create a spacing object for returning margin, padding, border, and position
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
2016-10-24 10:37:51 -07:00
Emil Sjolander
69c374e74e Simplify memory model between managed and unmanaged memory
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
2016-10-24 10:37:51 -07:00
Emil Sjolander
4c57029a28 Remove flex shorthand getter because it doesnt make a lot of sense
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
2016-10-24 03:37:49 -07:00
Emil Sjolander
c28429efc8 Dont override flexShrink, flexGrow, and flexBasis with shorthand flex
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
2016-10-24 03:37:48 -07:00
Emil Sjolander
ab4ce535b9 Forward gLogger output to adb on android platforms
Summary: use android/log on android platforms

Reviewed By: splhack

Differential Revision: D4064619

fbshipit-source-id: de23e72844e25106d0db756064f5699959f45ed2
2016-10-23 11:07:43 -07:00
Emil Sjolander
7fee10691c Add test to assert default values
Summary: assert default values in test

Reviewed By: splhack

Differential Revision: D4064659

fbshipit-source-id: f7bf06232ebbbaa72c0202c5d9f15dd0d8005e22
2016-10-23 10:52:40 -07:00
Kazuki Sakamoto
4d964bdbc3 Update README
Summary:
- Update README for gentest
- Fix gentest.rb for the right working dir

Reviewed By: emilsjolander

Differential Revision: D4065863

fbshipit-source-id: 5c6bd9d18779c05c1de24c06a83b148889facb6b
2016-10-23 10:37:40 -07:00
Kazuki Sakamoto
ef538a45cd Add generated tests
Summary: - Add Java and C# test code generated by gentest

Reviewed By: emilsjolander

Differential Revision: D4065904

fbshipit-source-id: c0d489f37ee0a3132185636812057dc95725d59a
2016-10-23 10:37:39 -07:00
Kazuki Sakamoto
dc5e613285 gentest for Java and C#
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
2016-10-23 10:37:39 -07:00
mattpodwysocki
1488f822c3 Fix C# delegate calling conventions
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
2016-10-22 09:52:42 -07:00
Michael Lee
7673de823f Clean up the vm_args override and use_cxx_libraries instead
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
2016-10-20 15:22:39 -07:00
Dustin Shahidehpour
26bcc1e072 Remove view.isHidden optimization from sizing/layout.
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
2016-10-20 09:37:39 -07:00
Emil Sjolander
2e090cb1c8 Fixup format file for hopefully the last time in a while and re-format code
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
2016-10-20 06:22:37 -07:00
Kazuki Sakamoto
daed6f5b8a Introduce CSSLayoutSetLogger to pass the print result to C# side
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
2016-10-19 11:08:08 -07:00
Emil Sjolander
e4ad7d3c12 Change flex basis to override main axis size
Summary: Flex basis should override height/width. Not the other way around.

Reviewed By: gkassabli

Differential Revision: D4029374

fbshipit-source-id: bc3c72879f3937a50bf8a636b547adc7b9a4f5a7
2016-10-19 06:52:43 -07:00
Emil Sjolander
fa2ffc72a4 Use typedefs from header
Summary: Use typedefs from header for print and measure functions

Reviewed By: gkassabli

Differential Revision: D4036421

fbshipit-source-id: 01f15cb840363850970e6a60e661af06fd6ec9e0
2016-10-18 10:29:22 -07:00
Emil Sjolander
d1d9326fa4 Use switch instead of ifelse chain
Summary: easier to read

Reviewed By: gkassabli

Differential Revision: D4036445

fbshipit-source-id: 2159946f53507ff3d7505795e5baa5f820cdb65c
2016-10-18 10:07:46 -07:00
Emil Sjolander
9c3970dd75 Fix flex-shrink when shrinking to zero size
Summary: Fix flex-shrink when shrinking to zero size

Reviewed By: gkassabli

Differential Revision: D4036345

fbshipit-source-id: f6848d7a316a694426f761d5e51d972bd379d90e
2016-10-18 09:22:42 -07:00
Michael Lee
6152ca46c8 Tell the java wrapper to use the fbcode java
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
2016-10-18 08:07:45 -07:00
Emil Sjolander
9fb1b29f14 Remove default: usage to ensure compiler can help with missing cases
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
2016-10-18 06:52:51 -07:00
Emil Sjolander
82dafa75cf Move absolute layout calculation out into seperate function
Summary: Move absolute layout calculation out into seperate function

Reviewed By: gkassabli

Differential Revision: D4028329

fbshipit-source-id: 2903f66b028063cec0a6b3037ca7cb4d6552176d
2016-10-17 12:22:49 -07:00
Emil Sjolander
eb4f1cdc96 Fix justify content + min dimension when children overflow
Summary: Fix justify content + min dimension when children overflow

Reviewed By: gkassabli

Differential Revision: D4029442

fbshipit-source-id: d28ebd269c452c3359e16ecc5749a415da6e4d75
2016-10-17 08:07:48 -07:00
Emil Sjolander
501ed57784 Only look at computed style if key was not set inline
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
2016-10-17 06:37:45 -07:00
Emil Sjolander
bfb9b926b3 Move flex basis calculation out into seperate function
Summary: Move flex basis calculation out into seperate function

Reviewed By: gkassabli

Differential Revision: D4028328

fbshipit-source-id: 6d5f3bf1321077675eaa65408a70c9dc92a675be
2016-10-17 05:37:44 -07:00
Emil Sjolander
b21efa45e6 Fix justify content + min dimension usage in root
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
2016-10-17 04:23:55 -07:00
Dustin Shahidehpour
c619c0be5a Proper fix for broken android builds.
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
2016-10-14 17:52:48 -07:00
Dustin Shahidehpour
63d3e8f3f3 Add uikit tests to Travis.
Summary: Now that we have some tests, lets run them.

Reviewed By: emilsjolander

Differential Revision: D4023765

fbshipit-source-id: 9f2fa723dc9a33f12c0470b782d6329b432546fa
2016-10-14 16:52:47 -07:00
Michael Lee
770fa6d254 Turn off the apple_test getting pulled into end-to-end tests
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
2016-10-14 16:22:55 -07:00
Dustin Shahidehpour
eedee80f25 Add Test to make sure associated objects live/die with lifetime of UIView.
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
2016-10-14 14:52:57 -07:00
Dustin Shahidehpour
0254e3e97f Don't call sizeThatFits: if measure modes are exact.
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
2016-10-14 14:52:57 -07:00
Dustin Shahidehpour
05ba3a2565 Do not measure the view if it is hidden.
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
2016-10-14 14:37:43 -07:00
Dustin Shahidehpour
89440f630f Add Testing to uikit.
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
2016-10-14 13:37:50 -07:00
Kazuki Sakamoto
832d07902e Modify unittest
Summary:
- Disable destructor tests in Unity Editor, seems GC is flaky.
- Use current native instance counts

Reviewed By: emilsjolander

Differential Revision: D4018951

fbshipit-source-id: a57f0e1fa5a46e7de0b88235124d437d20e4082b
2016-10-14 07:08:29 -07:00
Emil Sjolander
b45a7e3737 Don't assume a node with a measure function is a leaf node
Summary: Don't assume a node with a measure function is a leaf node

Reviewed By: gkassabli

Differential Revision: D4021096

fbshipit-source-id: 7e039239b1697a0ac42dce9f4b7e252a931bad7e
2016-10-14 04:37:53 -07:00
Emil Sjolander
14009ec470 Rename C test target to match pattern of other test targets
Summary: Rename C test target to match pattern of other test targets

Reviewed By: gkassabli

Differential Revision: D4014931

fbshipit-source-id: 2b4b831d6073214e8162a1d27b7478f3665a795f
2016-10-13 11:39:35 -07:00
Georgiy Kassabli
203e3dc9b8 Compatibility with Apple TVOS
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
2016-10-13 10:52:44 -07:00
Kazuki Sakamoto
7548164edb Clean up MeasureFunc and PrintFunc
Summary:
- Remove unneeded instance variables
- Simplify MeasureFunc call
- Add unittest

Reviewed By: emilsjolander

Differential Revision: D4013176

fbshipit-source-id: 4cdfa3ac3ad60a6bac5cda10644376ee9c46300b
2016-10-13 08:07:58 -07:00
Kazuki Sakamoto
722bfb9032 Align C# implementation with Java
Summary:
- Align C# implementation with Java JNI implementation
  - No need to call init(reinit)
  - Rename Initialize and Reset
- Add unittests

Reviewed By: emilsjolander

Differential Revision: D4009351

fbshipit-source-id: 191ddec30b0c8518eb0d76c0579afe909b673fac
2016-10-13 08:07:58 -07:00
Emil Sjolander
2a8a4e10c6 Update readme adding UIKit and fixing things that have changed
Summary: Update readme adding UIKit and fixing things that have changed

Differential Revision: D4015068

fbshipit-source-id: 213a60bea6f16ca01a4e613c8e3563f7c354ca8e
2016-10-13 06:22:53 -07:00
Scott Wolchok
8df9320f4c Fix build with -Wmissing-prototypes
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
2016-10-12 21:22:55 -07:00
Emil Sjolander
df6b4d3682 Add tests for java jni bindings
Summary: Add tests for java jni integration

Reviewed By: lucasr

Differential Revision: D4008411

fbshipit-source-id: c896a3925ff3f7fa368176a3d03c84eb7188ef60
2016-10-12 10:08:54 -07:00
Emil Sjolander
8939bcb96d UIView category
Summary: Add flexbox support to UIViews via a category

Reviewed By: dshahidehpour

Differential Revision: D4002873

fbshipit-source-id: f89de3acdf8fd89c7801918dcad34ba9011dd025
2016-10-12 09:37:42 -07:00
Kazuki Sakamoto
d3fc24e842 Implement SetPosition
Summary: Implement missing SetPosition method in CSSNode

Reviewed By: emilsjolander

Differential Revision: D4006153

fbshipit-source-id: 488263965c2b3b2bd46f3ac58575776a748e3eb9
2016-10-12 09:22:54 -07:00
Emil Sjolander
7f6b942146 Move java rules into java directory
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
2016-10-12 09:07:51 -07:00
Emil Sjolander
29fa232129 Remove tests for CSSNodeDEPRECATED
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
2016-10-12 06:07:42 -07:00
Emil Sjolander
41b64478c4 Rename init() -> reinit() to be more in line with what it now does
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
2016-10-12 03:53:04 -07:00
Emil Sjolander
23acf2156f Rename reset() -> free() to be more in line with what it now does
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
2016-10-12 03:53:04 -07:00
Emil Sjolander
1de914737a Automatically init native memory when allocating java wrapper
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
2016-10-12 03:53:04 -07:00
Emil Sjolander
033658196f JNI version is the default, its name should reflect that
Summary: JNI version is the default, its name should reflect that

Reviewed By: lucasr

Differential Revision: D3992777

fbshipit-source-id: cdd4cc58f3c15b5db1158f6f794394eb5c44a44d
2016-10-12 03:53:04 -07:00
Emil Sjolander
136ec25e8c Remove xcode_public_headers_symlinks from open source
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
2016-10-12 03:22:42 -07:00
Emil Sjolander
62dba4c741 Clearly mark java CSSNode as deprecated. It will go away very soon
Summary: Clearly mark java CSSNode as deprecated. It will go away very soon.

Reviewed By: lucasr

Differential Revision: D3992775

fbshipit-source-id: b3ceca277e5c7426eb51f8cbeacf5e2fe451c6ec
2016-10-12 02:52:56 -07:00
Emil Sjolander
871a7cf310 Move csharp tests into csharp folder
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
2016-10-11 07:08:10 -07:00
Emil Sjolander
cdf4ee1e59 Move benchmark buck file into benchmark directory
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
2016-10-11 05:52:50 -07:00
Emil Sjolander
588d2c91ba Remove unused buck rule
Summary: CSSLayoutTestUtils doesn't exist anymore

Reviewed By: lucasr

Differential Revision: D3992982

fbshipit-source-id: 427270e5a164974a8e964a4b23461b18d9b91066
2016-10-11 05:07:40 -07:00
Emil Sjolander
f61fbd269e Add finalizer to release any unreleased native memory
Summary: Ensure all native memory is released once gc deallocates the java object reference.

Reviewed By: lucasr

Differential Revision: D3992759

fbshipit-source-id: f648b72ead5bdb7257a5197496b19795f71f3788
2016-10-11 04:52:49 -07:00
Emil Sjolander
d506e6ab94 Enable running within robolectric
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
2016-10-08 06:22:50 -07:00
Kazuki Sakamoto
56f6efdecf Introduce CSSAssertSetFailFunc and CSSAsserFail to throw managed exception
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
2016-10-07 12:38:08 -07:00
Kazuki Sakamoto
90844d62c5 WeakReference for parent
Summary: - Use WeakReference for parent to avoid circular reference although GC will treat it

Reviewed By: emilsjolander

Differential Revision: D3982520

fbshipit-source-id: b0f6764aa4df3da53be51f6cb4fe2994d989afdf
2016-10-07 11:23:00 -07:00
Kazuki Sakamoto
c233bafeb2 Introduce CSSNodeGetInstanceCount API
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
2016-10-07 11:23:00 -07:00
Kazuki Sakamoto
b57abb2f60 Remove unused GCHandle
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
2016-10-07 11:22:59 -07:00
Emil Sjolander
56279110c0 Resolve some differences between CSSNode and CSSNodeJNI
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
2016-10-07 05:22:45 -07:00
Kazuki Sakamoto
01115b8bbd Add unittest
Summary: - Unittest for P/Invoke integration

Reviewed By: emilsjolander

Differential Revision: D3977114

fbshipit-source-id: 11f6bf747898433226c920997839e938734cbd77
2016-10-06 06:08:06 -07:00
Kazuki Sakamoto
47bd1bb943 Align C# implementation with Java and Dispose pattern
Summary:
- Align C# implementation with Java JNI implementation
  - AssertNativeInstance
    - is this instance disposed?
    - does this instance have native instance pointer?
- Align Dispose and destructor with Dispose pattern
  - https://msdn.microsoft.com/en-us/library/fs2xkftw(v=vs.110).aspx

    if (disposing)
    {
      Free maanged objects here
    }
    Free unmanaged objects here
    disposed = true;

Reviewed By: emilsjolander

Differential Revision: D3977015

fbshipit-source-id: 023cf5b15aacfada14a85c321576aa81d7f95125
2016-10-06 06:08:05 -07:00
Kazuki Sakamoto
2870d3ce4d Remove .dll from DllName for other platforms
Summary:
- Different platforms have different naming conventions
  - http://www.mono-project.com/docs/advanced/pinvoke/#library-names
- Unity iOS requires special name `__Internal`
  - https://docs.unity3d.com/Manual/PluginsForIOS.html

Reviewed By: emilsjolander

Differential Revision: D3976369

fbshipit-source-id: 4c1d7fe226c5c2a89531ee1c2ee8b47df847b3e4
2016-10-06 06:08:05 -07:00
mattpodwysocki
23f2878808 rocket: fix P/Invoke sig for bool
Summary:
Fixes the `bool` marshaling issue as describe on [MSDN](https://blogs.msdn.microsoft.com/jaredpar/2008/10/14/pinvoke-and-bool-or-should-i-say-bool/) so C# will now act properly.
Closes https://github.com/facebook/css-layout/pull/226

Reviewed By: IanChilds

Differential Revision: D3967349

Pulled By: emilsjolander

fbshipit-source-id: f61d3bb39eb1b0b6e749629825234615b425e930
2016-10-05 02:37:55 -07:00
Hoa Dinh
11f85ce91e create symlinks in xplat
Summary: In the libraries where headers symlinks are required, we enable them.

Reviewed By: skotchvail

Differential Revision: D3943274

fbshipit-source-id: c7ec741af020a60bb7c39b10773cea58a33adc3e
2016-09-29 10:23:33 -07:00
Emil Sjolander
1f300a58fb Free memory used in tests to enable use of valgrind
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
2016-09-29 04:22:47 -07:00
mattpodwysocki
dbf3b11946 Add C# example for css-layout CSSNode
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
2016-09-28 03:23:26 -07:00
Emil Sjolander
3b1515f2b7 Fix bug introduced by D3886866
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
2016-09-27 10:22:59 -07:00
Emil Sjolander
6b16dc4060 Fix flex-end/flex-start RTL transpilation
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
2016-09-27 08:52:44 -07:00
mattpodwysocki
9c93c7fc42 Removes unnecessary CSSLayoutContext param from CalculateLayout
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
2016-09-27 04:37:37 -07:00
Emil Sjolander
15d5cb0169 BREAKING - Fix unconstraint sizing in main axis
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
2016-09-26 06:22:39 -07:00
Christopher Chedeau
dba5faabb2 Syntax highlight C code in README
Summary: Closes https://github.com/facebook/css-layout/pull/221

Reviewed By: vjeux

Differential Revision: D3914024

Pulled By: emilsjolander

fbshipit-source-id: 4cb0741e526dfefbbb41e8afed1c2f52823df08a
2016-09-23 09:22:38 -07:00
mattpodwysocki
ff8f17ac99 Introducing .NET version of css-layout using P/Invoke
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
2016-09-22 16:37:46 -07:00
Emil Sjolander
017fb2c734 Cleanup some multiline code
Summary: some general cleanup

Reviewed By: lucasr

Differential Revision: D3886866

fbshipit-source-id: e19c1be4af58605933f90b5bf381008338be2236
2016-09-20 10:23:09 -07:00
Emil Sjolander
8fd14c710c Move justifyContent check into switch statement
Summary: some general cleanup

Reviewed By: lucasr

Differential Revision: D3886861

fbshipit-source-id: 17ba2962016af34b5add3ce6d8355c9c305a35c0
2016-09-20 10:23:09 -07:00
Emil Sjolander
1415a5d7fd Remove empty line in function call
Summary: some general cleanup

Reviewed By: lucasr

Differential Revision: D3886856

fbshipit-source-id: cf76ad9b6c85a62b9f2683618a6abe986d98acc2
2016-09-20 10:23:09 -07:00
Emil Sjolander
2592894d2d Remove use of snake_case
Summary: some general cleanup

Reviewed By: lucasr

Differential Revision: D3886849

fbshipit-source-id: eaf3f219fe1ccb717ba363dba0d2f475ffb204e3
2016-09-20 10:23:09 -07:00
Ben Hiller
dcaef7ecb0 Reverted commit D3856585
Summary: Add tests to check that measure modes are set correctly.

Reviewed By: lucasr

Differential Revision: D3856585

fbshipit-source-id: 421b368d2d2cbca1d2ba4d58d850836cb22128ac
2016-09-14 12:07:40 -07:00
Emil Sjolander
2dcd8b4074 Reverted commit D3855801
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
2016-09-14 11:37:51 -07:00
Emil Sjolander
1951242a52 Add tests for measure modes
Summary: Add tests to check that measure modes are set correctly.

Reviewed By: lucasr

Differential Revision: D3856585

fbshipit-source-id: 5fa407f149b1c081503b4ad7aa5f0203ec5b1cc0
2016-09-14 09:07:44 -07:00
Emil Sjolander
d4121401d7 BREAKING - Fix unconstraint sizing in main axis
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
2016-09-14 09:07:44 -07:00
Emil Sjolander
0be3b1013f Remove legacy test suite
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
2016-09-14 08:52:44 -07:00
Emil Sjolander
21a05417cd Generate RTL version of tests
Summary: Generate RTL versions of css-layout tests

Reviewed By: lucasr

Differential Revision: D3863081

fbshipit-source-id: df4debb3c1e371425d7c297f8d013b8042ad1e0e
2016-09-14 08:52:44 -07:00
Emil Sjolander
8fcb265830 Make generated test input more copy pastable
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
2016-09-14 08:52:44 -07:00
Emil Sjolander
64fffcb8f3 Remove flex section from readme as it now supports all web properties
Summary: Update readme to reflect new support.

Reviewed By: lucasr

Differential Revision: D3856292

fbshipit-source-id: 012f3d1171330cc93c34de300153ff4bb1326819
2016-09-14 08:22:37 -07:00
Emil Sjolander
059384f277 Improve formatting of generated test code input
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
2016-08-31 11:22:42 -07:00
Emil Sjolander
57725e849a Copy fbjni library from react-native 2016-08-31 16:15:15 +01:00
Adam Comella
b51e832e4e Fix sizing of absolutely positioned nodes inside overflow:hidden parent
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
2016-08-31 08:07:59 -07:00
Emil Sjolander
d9191431ff Generate test for border (and fix gentest to include border offset)
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
2016-08-31 08:07:59 -07:00
Emil Sjolander
251a499ba6 Generate tests for padding
Summary: Add generated tests for padding

Reviewed By: lucasr

Differential Revision: D3791211

fbshipit-source-id: 7fb4580c2ab8fba05532df746297c7a0ec6a734e
2016-08-31 08:07:59 -07:00
Emil Sjolander
3c33184dbb Add tests for margin
Summary: Generate tests for margins

Reviewed By: lucasr

Differential Revision: D3791131

fbshipit-source-id: e038ccd8b9314a8cc472e4f57d77c5f097228344
2016-08-31 08:07:59 -07:00
Emil Sjolander
583830b3df Fix and add tests for cssedge priority
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
2016-08-31 08:07:59 -07:00
Emil Sjolander
36eaae88e0 Add tests for dirty propagation
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
2016-08-31 08:07:59 -07:00
Emil Sjolander
284634c880 Remove unnecesarry imports for tests
Summary: Minimal imports

Reviewed By: lucasr

Differential Revision: D3790919

fbshipit-source-id: 496078d8132252307ef2b3cb45472917a19d7750
2016-08-31 06:22:46 -07:00
Emil Sjolander
94bbbde930 Make use of fbjni
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
2016-08-31 05:08:29 -07:00
Emil Sjolander
1051c39a59 Add tests for measure caching
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
2016-08-31 05:08:29 -07:00
Emil Sjolander
1abb2d1714 Change dynamic library extension depending on platform
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
2016-08-30 10:22:36 -07:00
Emil Sjolander
c28148caff Exclude tests from formatting as they are auto-generated and include html
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
2016-08-30 10:07:53 -07:00
Emil Sjolander
e3fa40e694 Allow specifying the test name in the input to gentest
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
2016-08-26 10:38:01 -07:00
Lucas Rocha
89c00a7a3b Make Spacing.release() public
Summary: So that it can be reset when Spacing is used outside CSSNode.

Differential Revision: D3763593

fbshipit-source-id: 27436c0dbd292b38cfc98f4cfb8e2d12787b85d6
2016-08-26 04:22:54 -07:00
Emil Sjolander
2808e547c6 Revert changes causing layout failures
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
2016-08-26 03:22:35 -07:00
Emil Sjolander
8b4a61df1a Generate tests for min/max height/width
Summary: Generate tests for min/max height/width

Differential Revision: D3771576

fbshipit-source-id: a114f79bdb3d36237d7ecc22f8cef69b6899fc3d
2016-08-25 15:38:14 -07:00
Emil Sjolander
43faff434a Generate tests for flex properties
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
2016-08-25 15:38:14 -07:00
Emil Sjolander
ea9a6ce06f Generate test for justify content
Summary: Generate tests for justify content

Differential Revision: D3771389

fbshipit-source-id: 2f6c5a38e6899b9ef05b7ad2da9b881c3b71e15c
2016-08-25 15:38:14 -07:00
Emil Sjolander
beb51fac1b Generate test for align content
Summary: Generate tests for align content

Differential Revision: D3771383

fbshipit-source-id: 4a0798486522bdfd7f10ca4db7086096494f03d8
2016-08-25 15:38:14 -07:00
Emil Sjolander
d33befeb98 Generate test for align self
Summary: Generate tests for align self

Differential Revision: D3771377

fbshipit-source-id: eaeec8a7ac5609bd8dd95d31500054510ab749d9
2016-08-25 15:38:14 -07:00
Emil Sjolander
2fc622adbd Generate test for flex wrap
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
2016-08-25 15:38:14 -07:00
Emil Sjolander
1fd3a16116 Fix naming of some style props in gentest
Summary: These props were never tested so I didn't notice the typo until now.

Differential Revision: D3771132

fbshipit-source-id: 9d7c2037195f29b3cac5d21599035edf3b7830ff
2016-08-25 15:38:14 -07:00
Emil Sjolander
aa70125f6c Generate tests for absolute layout
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
2016-08-25 15:38:14 -07:00
Emil Sjolander
9985e398b3 Generate test for align items
Summary: generate align-items tests

Reviewed By: IanChilds

Differential Revision: D3770946

fbshipit-source-id: 30ec043a8819d31a611f689bf89635f6a51c1628
2016-08-25 15:38:14 -07:00
Emil Sjolander
b629bcacab Generate test for flex direction
Summary: Generate flex-direction tests

Reviewed By: IanChilds

Differential Revision: D3770939

fbshipit-source-id: 7c02fe91bd50345c18653f70d1b572b643c44d26
2016-08-25 15:38:14 -07:00
Emil Sjolander
f65febb1af Remove certain computed values from output style
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
2016-08-25 15:38:14 -07:00
Emil Sjolander
ccbfee3841 Ensure multiple test cases all have the same origin
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
2016-08-25 15:38:14 -07:00
Emil Sjolander
9eb75e27cc Update gentest to new api
Summary: Update gentest to handle new CSSEdge api

Reviewed By: IanChilds

Differential Revision: D3770906

fbshipit-source-id: 1fa978354209fb8f4d0c5a2f892e1c79b062d4de
2016-08-25 15:38:14 -07:00
rh389
15afb4207c Use quote style for local includes
Summary:
This PR changes `#include <CSSLayout/*.h>` to  `#include "*.h"` within the `CSSLayout` directory.

Rationale: Quote includes are preferred for user (aka local/project) includes, whereas angle includes are preferred for standard libraries and external frameworks. In particular, XCode 7.1+ will not search user paths (even the current directory) when angle brackets are used unless "Always search user paths" is enabled - it is off by default and [Apple recommend](https://developer.apple.com/library/mac/documentation/DeveloperTools/Reference/XcodeBuildSettingRef/1-Build_Setting_Reference/build_setting_ref.html#//apple_ref/doc/uid/TP40003931-CH3-SW110) that it is only enabled for backwards compatibility.

I think this is the best fix for https://github.com/facebook/react-native/issues/9014, and seems like good practice in any case.
Closes https://github.com/facebook/css-layout/pull/217

Reviewed By: majak

Differential Revision: D3764132

Pulled By: emilsjolander

fbshipit-source-id: c8a6e8d19db71455922e3ba8f6c72bd66018fa84
2016-08-24 10:52:35 -07:00
Emil Sjolander
f1ae87cd73 Implement flex properties in java version as well
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
2016-08-23 04:37:46 -07:00
Emil Sjolander
e8465aee45 Fix benchmark build
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
2016-08-22 08:22:38 -07:00
Emil Sjolander
ca72b2b796 Use const where possible
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
2016-08-22 07:07:41 -07:00
Emil Sjolander
4bcefd8845 Remove unnecessary indirection
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
2016-08-22 07:07:41 -07:00
Emil Sjolander
0672f5572f Move default spacing out of csslayout
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
2016-08-18 03:37:37 -07:00
Emil Sjolander
9d34b4e110 Compute edge values similar to how Spacing.java does it
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
2016-08-17 10:38:40 -07:00
Emil Sjolander
dab03cb800 Remove CSSPosition in favor of CSSEdge
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
2016-08-17 10:38:38 -07:00
Emil Sjolander
dd2346f8ac Document format.sh
Summary: Mention format.sh script in README and CONTRIBUTING docs

Reviewed By: IanChilds

Differential Revision: D3728789

fbshipit-source-id: 1d5d99dc627b6cb87898d282aae8adfcaeec7c14
2016-08-17 06:37:43 -07:00
Emil Sjolander
dde2b349f2 Support 64 bit platforms
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
2016-08-16 08:52:38 -07:00
Emil Sjolander
7cd6305371 Fix parameter order
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
2016-08-16 06:07:42 -07:00
Emil Sjolander
f28dacf280 import function before using it
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
2016-08-16 03:52:43 -07:00
Emil Sjolander
a960203567 Use single function for margin, position, padding, and border
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
2016-08-15 09:23:28 -07:00
Emil Sjolander
48e5304276 Specify format folders more granularly
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
2016-08-15 09:23:28 -07:00
Emil Sjolander
53ff4f59ca Allow format script to be run from anywhere
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
2016-08-15 09:23:28 -07:00
Emil Sjolander
28bc42a988 Add generation script header to generated tests
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
2016-08-15 09:23:28 -07:00
Emil Sjolander
c373056d80 Add the ability to generate multiple test cases
Summary: Modify test generation script to be able to generate multiple test cases

Reviewed By: lucasr

Differential Revision: D3714577

fbshipit-source-id: d2bc2155712f946c5a24231a9532d2acc097524c
2016-08-15 09:23:28 -07:00
Emil Sjolander
f68521aa69 Add support for flex-grow, flex-shrink, and flex-basis
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
2016-08-15 09:23:28 -07:00
Emil Sjolander
fdd5c8ce82 Use library style imports
Summary: Use library style imports to avoid lint warning

Reviewed By: IanChilds

Differential Revision: D3714512

fbshipit-source-id: 4c42d52b3ab92903e9e9451df0ca1564e2d33f0f
2016-08-15 09:23:28 -07:00
Emil Sjolander
7a1e353404 Update clang-format rules
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
2016-08-15 09:23:27 -07:00
Emil Sjolander
6a44dbc43b Add no-op allow_unsafe_import for open source
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
2016-08-15 09:23:27 -07:00
Michal Lowicki
597354a43b Enable build file sandboxing in fbandroid
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
2016-08-12 09:38:05 -07:00
Emil Sjolander
1ce14cd097 Update readme
Summary: Docs!

Reviewed By: IanChilds

Differential Revision: D3709305

fbshipit-source-id: 1c8b7c1395bd78f073195eade1839ead4d9dacad
2016-08-12 08:52:41 -07:00
Emil Sjolander
d125911894 Print more detailed benchmark results including median and stddev
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
2016-08-12 06:22:38 -07:00
Emil Sjolander
e307dc22d1 Expose alignContent to java
Summary: Expose already existing alignContent property to java

Reviewed By: IanChilds

Differential Revision: D3709071

fbshipit-source-id: 421d75924ecc12d6d0975e342f3862cf5592f65f
2016-08-12 04:22:41 -07:00
Emil Sjolander
916170f6ac Dont generate so for main library
Summary: A .so file is only needed for the JNI target. The main library can be static.

Differential Revision: D3703897

fbshipit-source-id: b2efb98a6ae4488e6107c736c263cad35ef7c4fe
2016-08-12 03:53:52 -07:00
Emil Sjolander
57021eba9d Run benchmarks on previous revision as well
Summary: Checkout previous revision and re-run benchmark on travis

Differential Revision: D3697439

fbshipit-source-id: 260c5e379ae5caa667cf315e210ff4a7349b5868
2016-08-11 11:52:44 -07:00
Emil Sjolander
a43b813517 Add test generation scripts
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
2016-08-11 11:52:44 -07:00
Emil Sjolander
e5a3f7bf5b Turn on higher optimization level
Summary: quicker the better

Reviewed By: adamjernst

Differential Revision: D3697615

fbshipit-source-id: 822fb0927601849b364d3a649af934a0e82108e3
2016-08-11 03:07:51 -07:00
Emil Sjolander
af5b14335e Use modern initializer syntax instead of comments
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
2016-08-11 03:07:51 -07:00
Emil Sjolander
118f64f206 Add benchmarks and change repetition count
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
2016-08-11 02:37:38 -07:00
Emil Sjolander
450472766d Fix travis build
Summary: Building on osx machines makes things a lot easier.

Differential Revision: D3693987

fbshipit-source-id: f6e2599f99a3fd4ac6fb2a6efd5563074da707d0
2016-08-10 08:37:46 -07:00
Emil Sjolander
759cb707a4 Remove .buckversion
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
2016-08-10 08:37:46 -07:00
Emil Sjolander
328db9ca1c Include soloader as aar
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
2016-08-10 08:37:46 -07:00
Emil Sjolander
f15b563166 Use spacing for position
Summary: Use spacing for position in public api. This was already the case internally

Differential Revision: D3690235

fbshipit-source-id: 4c04952e6ded32fd5fbfdccf63736cf025ae470e
2016-08-10 05:22:32 -07:00
Emil Sjolander
7f27046cc5 Expose methods to set position Start|End
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
2016-08-09 04:37:45 -07:00
ymmuse
faad5cdf4d fix CSSNodeList memory leak
Summary:
CSSNodeListFree does not free the list->items memory
Closes https://github.com/facebook/css-layout/pull/214

Differential Revision: D3683643

Pulled By: emilsjolander

fbshipit-source-id: 7f9ef19f4603d5558cc2f8302756b3bcec2f6c12
2016-08-08 04:52:35 -07:00
James Ide
256d080fd2 Prefix isUndefined with "CSS"
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
2016-08-05 06:37:38 -07:00
Emil Sjolander
efe1595f0e Add and run clang format script
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
2016-08-04 08:23:02 -07:00
Emil Sjolander
9278ff462e Add the ability to attach data to a java CSSNode
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
2016-08-04 08:23:02 -07:00
Emil Sjolander
b32d384337 Fallback to System.loadLibrary if SoLoader has not been initialized
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
2016-08-04 08:23:02 -07:00
Emil Sjolander
f5caf93c6e Only perform class and method lookup once
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
2016-08-04 08:23:01 -07:00
Emil Sjolander
c74eae50ac Add jni bindings
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
2016-08-04 08:23:01 -07:00
Emil Sjolander
7af5e3d68d Dont redefine abort() as it may leak into other files
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
2016-08-03 02:07:39 -07:00
Emil Sjolander
9689062f6c Implement custom assert macro
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
2016-08-02 08:08:09 -07:00
Emil Sjolander
ac44d2ea6e use #pragma once
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
2016-08-02 08:08:09 -07:00
Emil Sjolander
9ab97af05d Re-enable travis
Summary: Add travis config file.

Reviewed By: lucasr

Differential Revision: D3649004

fbshipit-source-id: 27f257246965db473dc85ec6fed6b9a32bc8a621
2016-08-02 08:08:09 -07:00
Emil Sjolander
cdf18b9c2b Update readme with java instructions
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
2016-08-02 08:08:09 -07:00
Emil Sjolander
c7d02257e3 Make use of modern standard types
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
2016-08-02 08:08:09 -07:00
Emil Sjolander
c72321f8a9 Add first benchmark
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
2016-08-01 07:40:11 -07:00
Emil Sjolander
a0805d0b90 shouldUpdate -> hasNewLayout
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
2016-08-01 05:37:31 -07:00
Mengjue Wang
5207b90420 Provide RTL support for RCTShadowView according to new csslayout
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
2016-07-29 10:37:40 -07:00
Mengjue Wang
5e7d95b403 bottom styling isn't applied when a View is not absolute-positioned
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
2016-07-28 23:37:41 -07:00
Mengjue Wang
041960fcbc Reverted commit D3629662
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
2016-07-28 21:52:33 -07:00
Mengjue Wang
46c842c71a Fix CSSLayout to Support RTL
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
2016-07-28 14:52:40 -07:00
Mengjue Wang
b26794a375 Fix the test files according to new CSSLayout change
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
2016-07-28 11:07:38 -07:00
Emil Sjolander
8ffff2bfaf update readme
Summary: Update readme with info about building and github markdown syntax

Differential Revision: D3613284

fbshipit-source-id: 1f57009ccf02a48fe100f675ce08503e15cb6c22
2016-07-25 09:52:59 -07:00
FBShipIt
fdd8552c4e Import new C source of truth css-layout
fbshipit-source-id: e866918d6c62fc1cf3a04c269f782b94db9b875a
2016-07-25 15:53:07 +01:00
Emil Sjolander
93809b69c8 Restructure things to fit upcoming diff 2016-07-25 15:48:39 +01:00
Emil Sjölander
667106e423 Merge pull request #206 from facebook/revert-199-measure-fix
Revert "Correctly size cross axis when measuring flex basis"
2016-07-13 11:02:05 +01:00
Emil Sjölander
57874a1a9e Revert "Correctly size cross axis when measuring flex basis" 2016-07-13 10:42:03 +01:00
Emil Sjölander
8b7f353746 Merge pull request #199 from emilsjolander/measure-fix
Correctly size cross axis when measuring flex basis
2016-07-08 16:47:19 +01:00
Emil Sjolander
ca34ff4446 Correctly size cross axis when measuring flex basis 2016-07-08 16:05:21 +01:00
Emil Sjölander
d878091c4b Merge pull request #203 from emilsjolander/at-most-root-js
Add missing js implementation for PR #200
2016-07-08 15:52:19 +01:00
Emil Sjolander
c4fa32cfd3 Add missing js implementation for PR #200 2016-07-08 14:43:30 +01:00
Emil Sjölander
6e05325f08 Merge pull request #200 from emilsjolander/at-most-root
Use AT_MOST measurespec when onyl max dimension is defined
2016-07-04 23:25:04 +01:00
Emil Sjolander
a1f36b53f5 Use AT_MOST measurespec when onyl max dimension is defined 2016-07-02 11:22:57 +01:00
Emil Sjölander
383d8a6b3d Merge pull request #195 from emilsjolander/imrpove-cache-hit
Improve heuristic for cache re-use
2016-06-09 10:55:48 -04:00
Emil Sjolander
7b0c008300 Improve heuristic for cache re-use 2016-06-09 10:33:00 -04:00
Emil Sjölander
45e595e6ae Merge pull request #193 from emilsjolander/stretch-perf
Measure with exact measurement when stretch is defined
2016-06-09 10:21:04 -04:00
Emil Sjolander
2a816bf5a7 Measure with exact measurement when stretch is defined 2016-06-08 14:00:31 -04:00
Emil Sjölander
71eb25d1cc Merge pull request #196 from emilsjolander/styling
Remove whitespace on empty lines etc.
2016-06-03 22:19:53 +01:00
Emil Sjolander
c06752e052 Remove whitespace on empty lines etc. 2016-06-03 22:19:03 +01:00
Emil Sjölander
bd92550d57 Merge pull request #192 from rigdern/rigdern/expose-props
Expose getters and setters for some new properties
2016-06-02 17:20:30 +01:00
Adam Comella
9260363fef Expose getters and setters for some new properties
The properties include overflow and min/max height/width.
2016-06-01 12:56:35 -07:00
Emil Sjölander
9d62cee68b Merge pull request #185 from rigdern/rigdern/spec-conformance
Alter layout engine to conform closer to W3C spec
2016-05-31 11:04:41 +01:00
Adam Comella
16f43dac87 Skip measurement when there's no available vertical space
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.
2016-05-25 10:53:15 -07:00
Adam Comella
8177bfe702 Heuristics for skipping calls to the measure function
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.
2016-05-18 13:40:34 -07:00
Adam Comella
8779d942ea Fix positioning of items with min/max width/height
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.
2016-05-11 00:29:40 -07:00
Adam Comella
f3dd51ab97 Alter layout engine to conform closer to W3C spec
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'.
2016-04-26 19:45:58 -07:00
Emil Sjölander
b0d00ad338 Merge pull request #163 from emilsjolander/measuremode
Add support for measure mode
2016-04-06 18:07:37 +01:00
Emil Sjolander
7bd6b2b7dd Add support for measure mode 2016-04-01 11:01:16 +01:00
Pieter De Baets
68e0b0cc58 Merge pull request #182 from javache/skip-layout-correctly
Correct skipLayout condition in Layout.c
2016-03-30 15:22:43 +01:00
Pieter De Baets
5b56be412c Correct skipLayout condition in Layout.c
Fixes #155
2016-03-30 12:11:49 +01:00
Lucas Rocha
3454511947 Merge pull request #178 from javache/node-layout-reset 2016-03-29 11:15:53 +01:00
Pieter De Baets
b157ab4a00 Reset child position/sizes before calculating layout 2016-03-29 11:05:53 +01:00
Lucas Rocha
8d5cdd4e6c Merge pull request #145 from alebo/issue-127 2016-03-01 23:07:14 +00:00
Alex Bogomazov
425345aa8d Redo layout of 'stretch' aligned items for correct positioning of nested
items

Fixes facebook/css-layout#83, facebook/css-layout#100,
facebook/css-layout#127.
2016-02-26 00:43:58 +03:00
Christopher Chedeau
dd8e5cd65d Merge pull request #170 from casandrasilva/patch-1
fixes UMD url
2016-02-05 03:57:39 -08:00
Casandra Silva Zenteno
64704dd708 fixes UMD url 2016-02-04 23:31:16 -08:00
Christopher Chedeau
dc7059d340 Merge pull request #166 from RReverser/patch-1
Add C# to the supported language list
2016-01-13 06:26:40 -08:00
Ingvar Stepanyan
acd295e470 Add C# to the supported language list 2016-01-13 14:15:48 +00:00
Lucas Rocha
5d5630d3c8 Merge pull request #161 from emilsjolander/master 2016-01-07 12:17:49 +00:00
Emil Sjolander
c9094f94d0 Check layout instead of style before setting height and width to whatever is set in layout 2016-01-06 15:07:41 +00:00
Christopher Chedeau
f3b6fb3be0 Merge pull request #159 from CatalystCode/dirty
Need dirty() to be virtual to override in special cases.
2016-01-05 07:19:23 -08:00
Eric Rozell
3d7bc48fa6 Need dirty() to be virtual to override in special cases.
See, for example ReactShadowNode in the ReactAndroid code base, which overrides this virtual.
2016-01-05 08:55:32 -05:00
Lucas Rocha
219bdaed15 Merge pull request #154 from majak/width 2015-12-14 16:28:52 +00:00
Martin Kralik
f2aa5ba604 passing height to the measure function
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
2015-12-14 15:00:13 +00:00
Colin Eberhardt
53769ccbc5 Merge pull request #153 from casandrawith1s/patch-1
'package-all' tense consistency
2015-11-22 14:36:31 +00:00
Casandra Silva
2733ebf1d0 'package-all' tense consistency
Change 'package-all' comment to present tense and unfiform grammar for consistency
2015-11-21 21:51:50 -08:00
Colin Eberhardt
45227c0b9a Merge pull request #151 from pragmatrix/csharp-travis-pr
Configure travis to install mono and run the C# tests from within the…
2015-11-20 09:11:27 +00:00
Armin Sander
e848706911 Configure travis to install mono and run the C# tests from within the Gruntfile 2015-11-19 21:27:58 +01:00
Colin Eberhardt
79d7291906 1.1.1 2015-11-12 14:32:34 +00:00
Colin Eberhardt
bae4eb1830 Updated distribution build 2015-11-12 14:31:58 +00:00
Colin Eberhardt
609d4ae69d Do not delete release instructions! 2015-11-12 14:26:15 +00:00
Colin Eberhardt
99c3a88df4 Update release process to include a build step!
See #149
2015-11-12 11:52:07 +00:00
Colin Eberhardt
4364c6ebb2 Merge pull request #150 from wpcarro/patch-1
grammatical fix
2015-11-11 07:41:42 +00:00
Colin Eberhardt
73b1e63bd7 1.1.0 2015-11-11 07:27:17 +00:00
William Carroll
b7856ce26a grammatical fix
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!
2015-11-10 22:46:41 -08:00
Christopher Chedeau
f5eefe51f8 Merge pull request #148 from moneppo/master
Add C usage to documentation.
2015-11-07 08:39:01 -08:00
Michael
aac6694127 Add C usage to documentation.
Fixes #114.
2015-11-07 08:29:12 -08:00
Krzysztof Magiera
6e499300ff Merge pull request #146 from lucasr/style-getters
New style getters and cleanups in CSSNode
2015-10-21 16:42:46 +01:00
Lucas Rocha
d3b702e1ad Rename getStylePadding() to getPadding() for consistency
So that we're consistent with other style-only methods. Move existing
getters to be close to their matching setters in CSSNode.
2015-10-21 14:31:35 +01:00
Lucas Rocha
eb1d1726b9 Add getters for all style properties
For consistency and because now we have some use cases for it.
2015-10-21 10:37:09 +01:00
Christopher Chedeau
8f7632bc7f Merge pull request #144 from woehrl01/woehrl01-width
return correct value from Width property (C#)
2015-10-14 08:45:59 -07:00
Lukas Wöhrl
d2e66a8d82 return correct value from Width property 2015-10-14 08:50:49 +02:00
Lucas Rocha
4b4cd06be2 Merge pull request #140 from lucasr/fast-reset 2015-10-08 15:06:49 +01:00
Lucas Rocha
a821f6c555 Add reset() method to CSSNode
This allows users of css-layout in Java to perform faster resets on
CSSNode in cases when you want to recycle instances.
2015-10-08 14:49:28 +01:00
Colin Eberhardt
fbeef4542d Merge pull request #139 from ColinEberhardt/eslint
Eslint - enforces many more rules.
2015-10-07 22:26:04 +01:00
Colin Eberhardt
f02fbfc10c Changed from '"typeof foo === 'undefined'" to "foo === undefined" 2015-10-07 22:18:27 +01:00
Colin Eberhardt
e4c93e8c59 Updated to use eslint from fbjs-scripts 2015-10-07 21:52:22 +01:00
Krzysztof Magiera
35bd01e3f2 Merge pull request #141 from lucasr/enum-comparison
Faster enum comparisons in CSSNode
2015-10-07 13:19:56 +01:00
Colin Eberhardt
040f0f3e7c relaxed the eqeqeq rule to permit 'foo != null' 2015-10-07 06:40:17 +01:00
Lucas Rocha
af09213d1a Faster enum comparisons in CSSNode
Enums are singletons by design so it's safe (and faster) to compare by
reference. This also covers the null case.
2015-10-05 17:07:23 +01:00
Colin Eberhardt
538cb2e940 Fixed build
(I was using an older verson of eslint locally)
2015-10-05 13:30:59 +01:00
Colin Eberhardt
45f62c424c Widened scope of CI eslint to all JavaScript files 2015-10-05 13:21:19 +01:00
Colin Eberhardt
c33e255182 Enforced quote style and indentation 2015-10-05 13:18:27 +01:00
Colin Eberhardt
0f43977bb2 Enforced the eqeqeq rule 2015-10-05 12:50:54 +01:00
Colin Eberhardt
9b75493988 auto-configured eslint and fixed gruntfile linting failures 2015-10-05 08:08:57 +01:00
Christopher Chedeau
0faaabb78c Merge pull request #138 from devongovett/js-caching
Implement caching in the JS version
2015-10-04 16:07:45 -07:00
Devon Govett
e510c72111 Update based on feedback 2015-10-04 14:36:44 -07:00
Devon Govett
57d41f3e35 Add a shouldUpdate property to nodes whose layout changed 2015-10-04 14:19:02 -07:00
Devon Govett
e9d880a105 Add isDirty support 2015-10-04 14:11:55 -07:00
Devon Govett
221510cfcf Fix nits 2015-10-04 14:11:07 -07:00
Devon Govett
2636a4fbed Merge branch 'master' of github.com:facebook/css-layout into js-caching 2015-10-04 12:33:17 -07:00
Devon Govett
7b2140d7f9 Implement caching in the JS version 2015-10-04 11:45:54 -07:00
Christopher Chedeau
3042bac0bb Merge pull request #137 from devongovett/js-optimization
JS optimization
2015-10-04 07:24:43 -07:00
Devon Govett
5af85c5ef6 Inline some isUndefined calls 2015-10-03 23:14:04 -07:00
Devon Govett
0f5d3ae8f0 Don't use the in operator 2015-10-03 23:13:33 -07:00
Devon Govett
39b45c65c1 Speed up margin/padding/border lookups 2015-10-03 23:11:09 -07:00
Christopher Chedeau
948241b659 Merge pull request #136 from getsetbro/patch-1
Update README.md
2015-10-02 15:51:43 -07:00
Seth Broweleit
2cf795c118 Update README.md
"alignContent" is not supported - see image: https://raw.githubusercontent.com/getsetbro/images/gh-pages/screenshots/reactnative.no.flexbox.aligncontent.png
2015-10-02 16:36:29 -05:00
Christopher Chedeau
9eb00949ae Merge pull request #135 from pragmatrix/csharp5-pr
Don't use C#6 language features for the time being
2015-09-30 09:21:05 -07:00
Armin Sander
2e908bfdee don't use C#6 language features for the time being 2015-09-30 07:57:59 +02:00
Christopher Chedeau
cefd6ccb96 Merge pull request #134 from vjeux/fix_dim_0
Fix width being ignored when has a value of 0
2015-09-25 14:43:52 -07:00
Christopher Chedeau
e280a577ae Fix width being ignored when has a value of 0
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.
2015-09-25 13:10:21 -07:00
Christopher Chedeau
246005cc84 Update dist/ to be the latest version 2015-09-24 11:56:18 -07:00
Christopher Chedeau
4ca2ea3466 Merge pull request #129 from pragmatrix/csharp-fb-pr
C# Transpiler, API, and Tests
2015-09-23 09:08:15 -07:00
Armin Sander
4de0721a24 C# transpiler, API, and tests 2015-09-23 09:27:45 +02:00
Lucas Rocha
4ef24028be Merge pull request #126 from AaaChiuuu/master 2015-09-16 08:20:50 +01:00
Aaron Chiu
a353a11bf4 Merge pull request #1 from AaaChiuuu/publicConstants
Make CSSLayout constants public
2015-09-15 11:43:10 +01:00
Aaron Chiu
4a7936aa24 Make CSSLayout constants public 2015-09-15 11:42:30 +01:00
Aaron Chiu
f51c2d004d Merge pull request #123 from lucasr/omg-faster-flexbox
Even faster flexbox
2015-09-15 04:37:43 +01:00
Lucas Rocha
e43a8b28d6 Add 'package' comment in CSSNode for consistency 2015-09-14 18:23:36 +01:00
Lucas Rocha
cf94d35b51 Implement cascasing checks via bitwise flags
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
2015-09-14 18:23:36 +01:00
Lucas Rocha
ebc56fee59 Inline private methods at build time in Java
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.
2015-09-14 18:23:36 +01:00
Christopher Chedeau
2120285467 Merge pull request #122 from lucasr/even-faster-flexbox
Even faster flexbox
2015-09-10 14:25:41 -07:00
Lucas Rocha
765ff8463e Add fast path for simple stack layouts
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.
2015-09-10 11:19:28 +01:00
Lucas Rocha
2d869489ef More efficient resetResult() loop in LayoutEngine 2015-09-10 11:19:28 +01:00
Lucas Rocha
909c14117f Fix dimension check for STRETCH children
The correct check is on the layout state, no the style.
2015-09-10 11:19:28 +01:00
Lucas Rocha
9a149c83ff Avoid extra work when justifyContent is FLEX_START
Remaining space and between space only need to be updated when
justifyContent is not FLEX_START.
2015-09-10 11:19:28 +01:00
Lucas Rocha
2321165d53 Move condition to the non-redundant block
No need to check for RELATIVE position when position type is ABSOLUTE
and dimension is set.
2015-09-08 15:34:51 +01:00
Lucas Rocha
d1a49a4f0b Reduce search range of flexible children
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.
2015-09-08 15:34:51 +01:00
Lucas Rocha
793220faf8 Skip final loop on absolute children, if possible
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.
2015-09-08 15:34:51 +01:00
Lucas Rocha
996f2a03d5 Merge pre-fill loop into main line 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.
2015-09-08 15:34:27 +01:00
Lucas Rocha
877a2838a6 Skip trailing position loop, if possible
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.
2015-09-08 15:33:26 +01:00
Lucas Rocha
1ab785b7a3 Inline immutable values in layout algorithm
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.
2015-09-08 15:15:52 +01:00
Lucas Rocha
06c708053f Change Java to use array indexes instead of methods
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
Colin Eberhardt
486b9a84bf 1.0.0 2015-09-08 07:45:08 +01:00
Colin Eberhardt
00c8428015 Merge pull request #119 from ColinEberhardt/keywords
Keywords
2015-09-01 06:51:59 +01:00
Colin Eberhardt
ecb8f8e610 Added layout keyword 2015-09-01 06:10:34 +01:00
Colin Eberhardt
baf34484fe Updated repo to include cdnjs / npm instructions 2015-08-31 22:15:46 +01:00
Colin Eberhardt
5dd1482148 Minor build change
removed duplication of the step that creates the 'dist' folder
2015-08-31 22:09:30 +01:00
Colin Eberhardt
9d1abd8d51 added keywords 2015-08-31 22:05:14 +01:00
Christopher Chedeau
e6d3aea73d Merge pull request #117 from paramaggarwal/watch
Watch for changes and run tests during development using `grunt watch`.
2015-08-28 09:49:46 -07:00
Param Aggarwal
f9d308f923 Watch for changes and run tests during development using grunt watch. 2015-08-28 22:15:57 +05:30
Colin Eberhardt
68d45b4b9a 0.0.6 2015-08-21 11:05:20 +01:00
Colin Eberhardt
99f44302fe Giving up on travis!
OK, Travis you have defeated me! reverting to a more manual release process
2015-08-21 11:04:46 +01:00
731 changed files with 141380 additions and 27179 deletions

10
.buckconfig Normal file
View File

@@ -0,0 +1,10 @@
[cxx]
gtest_dep = //lib/gtest:gtest
[android]
target = android-25
build_tools_version = 26.0.2
[ndk]
ndk_version = 15.2.4203891
compiler = clang
app_platform = android-21
cpu_abis = arm64, armv7, x86, x86_64

11
.editorconfig Normal file
View File

@@ -0,0 +1,11 @@
root = true
[*]
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[*.md]
trim_trailing_whitespace = false

View File

@@ -1,24 +0,0 @@
{
"browser": true,
"shadow": true,
"globals": {
"jasmine": true,
"describe": true,
"beforeEach": true,
"afterEach": true,
"spyOn": true,
"it": true,
"xit": true,
"expect": true,
"require": true,
"global": true,
"__dirname": true,
"module": true,
"console": true,
"setTimeout": true,
"define": true
},
"rules": {
"quotes": [2, "single"]
}
}

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

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

74
.gitignore vendored
View File

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

3
.gitmodules vendored Normal file
View File

@@ -0,0 +1,3 @@
[submodule "lib/gtest/googletest"]
path = lib/gtest/googletest
url = https://github.com/google/googletest.git

1
.swift-version Normal file
View File

@@ -0,0 +1 @@
3.0

View File

@@ -1,22 +1,25 @@
language: node_js
node_js:
- "0.12"
- "8"
sudo: false
install:
- cd website
- yarn --ignore-scripts
- cd ..
before_install:
- npm install grunt-cli -g
addons:
apt:
packages:
- gcc
script:
- cd website
- yarn build
- cd ..
deploy:
provider: npm
email: ceberhardt@scottlogic.com
api_key:
secure: "Dk69FV717n91CRMv0UqzqZG6mrd4dSwd2PJDf1Fe0GOVPrVG9pmSTUmsk7JGli7EB57ovPGRhE/lcDGnlE+hEVw5DjZhGUUmZIFGg+FdcVomoiTRUYjRLwRUKEVxYw1TGCjJHm4rEx4qdkghahjf1YRYnivOn7ADhdH5THr7uQE="
provider: pages
skip-cleanup: true
github-token: $GITHUB_TOKEN
fqdn: yogalayout.com
local-dir: website/public
email: yogabot@fb.com
name: Yoga-bot
keep-history: true
on:
tags: true
branch: master
branch: master

45
BUCK Normal file
View File

@@ -0,0 +1,45 @@
# Copyright (c) 2014-present, Facebook, Inc.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
load("//:yoga_defs.bzl", "LIBRARY_COMPILER_FLAGS", "BASE_COMPILER_FLAGS", "GTEST_TARGET", "yoga_dep", "cxx_library", "cxx_test")
GMOCK_OVERRIDE_FLAGS = [
# gmock does not mark mocked methods as override, ignore the warnings in tests
"-Wno-inconsistent-missing-override",
]
COMPILER_FLAGS = LIBRARY_COMPILER_FLAGS + [
"-std=c++1y",
]
TEST_COMPILER_FLAGS = BASE_COMPILER_FLAGS + GMOCK_OVERRIDE_FLAGS + [
"-std=c++1y",
]
cxx_library(
name = "yoga",
srcs = glob(["yoga/*.cpp"]),
header_namespace = "",
exported_headers = subdir_glob([("", "yoga/*.h")]),
compiler_flags = COMPILER_FLAGS,
soname = "libyogacore.$(ext)",
tests = [":YogaTests"],
visibility = ["PUBLIC"],
deps = [
yoga_dep("lib/fb:ndklog"),
],
)
cxx_test(
name = "YogaTests",
srcs = glob(["tests/*.cpp"]),
compiler_flags = TEST_COMPILER_FLAGS,
contacts = ["emilsj@fb.com"],
visibility = ["PUBLIC"],
deps = [
":yoga",
GTEST_TARGET,
],
)

15
CMakeLists.txt Normal file
View File

@@ -0,0 +1,15 @@
#
# Copyright (c) 2014-present, Facebook, Inc.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
#
cmake_minimum_required(VERSION 3.4.1)
set(CMAKE_VERBOSE_MAKEFILE on)
file(GLOB yogacore_SRC yoga/*.cpp)
add_library(yogacore STATIC ${yogacore_SRC})
target_link_libraries(yogacore android log)

3
CODE_OF_CONDUCT.md Normal file
View File

@@ -0,0 +1,3 @@
# Code of Conduct
Facebook has adopted a Code of Conduct that we expect project participants to adhere to. Please [read the full text](https://code.facebook.com/pages/876921332402685/open-source-code-of-conduct) so that you can understand what actions will and will not be tolerated.

View File

@@ -1,9 +1,10 @@
# Contributing to css-layout
# Contributing to yoga
We want to make contributing to this project as easy and transparent as
possible.
## Our Development Process
All the development is happening on GitHub first and we have internal tools to sync down to Facebook codebase.
## Code of Conduct
Facebook has adopted a Code of Conduct that we expect project participants to adhere to. Please [read the full text](https://code.facebook.com/pages/876921332402685/open-source-code-of-conduct) so that you can understand what actions will and will not be tolerated.
## Pull Requests
We actively welcome your pull requests.
@@ -28,11 +29,6 @@ Facebook has a [bounty program](https://www.facebook.com/whitehat/) for the safe
disclosure of security bugs. In those cases, please go through the process
outlined on that page and do not file a public issue.
## Coding Style
* 2 spaces for indentation rather than tabs
* 80 character line length
* ...
## License
By contributing to css-layout, you agree that your contributions will be licensed
under its BSD license.
By contributing to yoga, you agree that your contributions will be licensed
under its MIT license.

View File

@@ -1,184 +0,0 @@
'use strict';
module.exports = function(grunt) {
var fs = require('fs');
var path = require('path');
var isWindows = /^win/.test(process.platform);
require('load-grunt-tasks')(grunt);
// config
var config = {
delimiter: path.delimiter,
libName: 'css-layout',
distFolder: 'dist',
srcFolder: 'src',
testFolder: 'src/__tests__',
javaLibFolder: 'src/java/lib',
javaSource: 'src/java/tests/com/facebook/csslayout/*.java',
javaTestFiles: 'org.junit.runner.JUnitCore com.facebook.csslayout.LayoutEngineTest com.facebook.csslayout.LayoutCachingTest com.facebook.csslayout.CSSNodeTest'
};
// C compilation configuration
if (isWindows) {
// Windows build, assumes cl is in the path (see https://msdn.microsoft.com/en-us/library/f2ccy3wt.aspx).
config.cTestOutput = 'c_test.exe';
config.cTestCompile = 'cl -nologo -Zi -Tpsrc/__tests__/Layout-test.c -Tpsrc/Layout.c -Tpsrc/Layout-test-utils.c -link -incremental:no -out:"<%= config.cTestOutput %>"';
config.cTestExecute = '<%= config.cTestOutput %>';
config.cTestClean = ['<%= config.cTestOutput %>','*.obj','*.pdb'];
}
else {
// GCC build (OSX, Linux, ...), assumes gcc is in the path.
config.cTestOutput = 'c_test';
config.cTestCompile = 'gcc -std=c99 -Werror -Wno-padded src/__tests__/Layout-test.c src/Layout.c src/Layout-test-utils.c -lm -o "./<%= config.cTestOutput %>"';
config.cTestExecute = './<%= config.cTestOutput %>';
config.cTestClean = ['<%= config.cTestOutput %>'];
}
grunt.initConfig({
config: config,
mkdir: {
dist: {
options: {
create: ['<%= config.distFolder %>']
},
},
},
clean: {
dist: ['<%= config.distFolder %>'],
cTest: config.cTestClean,
javaTest: ['**/*.class']
},
eslint: {
options: {
configFile: '.eslintrc'
},
target: ['<%= config.srcFolder %>/Layout.js']
},
includereplace: {
options: {
prefix: '// @@',
},
main: {
src: '<%= config.srcFolder %>/<%= config.libName %>.js',
dest: '<%= config.distFolder %>/<%= config.libName %>.js'
}
},
uglify: {
options: {
sourceMap: true,
sourceMapIncludeSources: true
},
main: {
files: {
'<%= config.distFolder %>/<%= config.libName %>.min.js':
['<%= config.distFolder %>/<%= config.libName %>.js']
}
}
},
karma: {
main: {
options: {
files: [
'<%= config.srcFolder %>/Layout.js',
'<%= config.srcFolder %>/Layout-test-utils.js',
'<%= config.testFolder %>/Layout-test.js',
'<%= config.testFolder %>/Layout-consts-test.js'
],
browsers: ['Chrome'],
frameworks: ['jasmine'],
singleRun: true
}
}
},
execute: {
transpile: {
src: ['<%= config.srcFolder %>/transpile.js']
}
},
concat: {
options: {
separator: '\n',
// Replace all 'use strict' statements in the code with a single one at the top
banner: [
'/*',
' * #define CSS_LAYOUT_IMPLEMENTATION',
' * before you include this file in *one* C or C++ file to create the implementation.',
' */\n'
].join('\n'),
process: function(src, filepath) {
if (path.extname(filepath) === '.c') {
return [
'#ifdef CSS_LAYOUT_IMPLEMENTATION',
src,
'#endif // CSS_LAYOUT_IMPLEMENTATION'
].join('\n')
}
else {
return src;
}
},
},
dist: {
src: ['<%= config.srcFolder %>/Layout.h', '<%= config.srcFolder %>/Layout.c'],
dest: '<%= config.distFolder %>/css-layout.h',
},
},
shell: {
cCompile: {
command: config.cTestCompile
},
cTestExecute: {
command: config.cTestExecute
},
javaCompile: {
command: 'javac -cp <%= config.javaLibFolder %>/junit4.jar<%= config.delimiter %><%= config.javaLibFolder %>/jsr305.jar<%= config.delimiter %><%= config.javaLibFolder %>/infer-annotations-1.4.jar' + ' -sourcepath ./src/java/src<%= config.delimiter %>./src/java/tests' + ' <%= config.javaSource %>'
},
javaTestExecute: {
command: 'java -cp ./src/java/src<%= config.delimiter %>./src/java/tests<%= config.delimiter %><%= config.javaLibFolder %>/junit4.jar<%= config.delimiter %><%= config.javaLibFolder %>/infer-annotations-1.4.jar <%= config.javaTestFiles %>'
},
javaPackage: {
command: 'jar cf <%= config.distFolder %>/<%= config.libName %>.jar <%= config.javaSource %>'
}
}
});
// Compiles and runs the Java tests
grunt.registerTask('test-java', ['shell:javaCompile', 'shell:javaTestExecute', 'clean:javaTest']);
// Compiles and runs the C tests
grunt.registerTask('test-c', ['shell:cCompile', 'shell:cTestExecute', 'clean:cTest']);
// Transpiles the JavaScript to C and Java, running tests
grunt.registerTask('transpile', ['execute:transpile', 'test-c', 'test-java']);
// Lints and tests the JavaScritp using Chrome
grunt.registerTask('test-javascript', ['eslint', 'karma']);
// Packages the JavaScript as a single UMD module and minifies
grunt.registerTask('package-javascript', ['mkdir:dist', 'includereplace', 'uglify']);
// Packages the Java as a JAR
grunt.registerTask('package-java', ['mkdir:dist', 'shell:javaPackage']);
// Packages the C code as a single header
grunt.registerTask('package-c', ['mkdir:dist', 'concat']);
// Default build, performs the full works!
grunt.registerTask('build', ['test-javascript', 'transpile', 'clean:dist', 'package-javascript', 'package-java', 'package-c']);
// The JavaScript unit tests require Chrome (they need a faithful flexbox implementation
// to test against), so under CI this step is skipped.
grunt.registerTask('ci', ['eslint', 'transpile', 'clean:dist', 'package-javascript', 'package-java', 'package-c']);
grunt.registerTask('default', ['build']);
};

43
LICENSE
View File

@@ -1,30 +1,21 @@
BSD License
MIT License
For css-layout software
Copyright (c) 2014-present, Facebook, Inc.
Copyright (c) 2014, Facebook, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name Facebook nor the names of its contributors may be used to
endorse or promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

9
LICENSE-examples Normal file
View File

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

33
PATENTS
View File

@@ -1,33 +0,0 @@
Additional Grant of Patent Rights Version 2
"Software" means the CSS Layout software distributed by Facebook, Inc.
Facebook, Inc. (“Facebook”) hereby grants to each recipient of the Software
(“you”) a perpetual, worldwide, royalty-free, non-exclusive, irrevocable
(subject to the termination provision below) license under any Necessary
Claims, to make, have made, use, sell, offer to sell, import, and otherwise
transfer the Software. For avoidance of doubt, no license is granted under
Facebook's rights in any patent claims that are infringed by (i) modifications
to the Software made by you or any third party or (ii) the Software in
combination with any software or other technology.
The license granted hereunder will terminate, automatically and without notice,
if you (or any of your subsidiaries, corporate affiliates or agents) initiate
directly or indirectly, or take a direct financial interest in, any Patent
Assertion: (i) against Facebook or any of its subsidiaries or corporate
affiliates, (ii) against any party if such Patent Assertion arises in whole or
in part from any software, technology, product or service of Facebook or any of
its subsidiaries or corporate affiliates, or (iii) against any party relating
to the Software. Notwithstanding the foregoing, if Facebook or any of its
subsidiaries or corporate affiliates files a lawsuit alleging patent
infringement against you in the first instance, and you respond by filing a
patent infringement counterclaim in that lawsuit against that party that is
unrelated to the Software, the license granted hereunder will not terminate
under section (i) of this paragraph due to such counterclaim.
A "Necessary Claim" is a claim of a patent owned by Facebook that is
necessarily infringed by the Software standing alone.
A "Patent Assertion" is any lawsuit or other action alleging direct, indirect,
or contributory infringement or inducement to infringe any patent, including a
cross-claim or counterclaim.

160
README.md
View File

@@ -1,138 +1,48 @@
css-layout [![Build Status](https://travis-ci.org/facebook/css-layout.svg?branch=master)](https://travis-ci.org/facebook/css-layout)
==========
# Yoga [![CocoaPods](https://img.shields.io/cocoapods/v/YogaKit.svg)](http://cocoapods.org/pods/YogaKit) [![npm](https://img.shields.io/npm/v/yoga-layout.svg)](https://www.npmjs.com/package/yoga-layout) [![bintray](https://img.shields.io/bintray/v/facebook/maven/com.facebook.yoga:yoga.svg)](https://bintray.com/facebook/maven/com.facebook.yoga%3Ayoga/_latestVersion) [![NuGet](https://img.shields.io/nuget/v/Facebook.Yoga.svg)](https://www.nuget.org/packages/Facebook.Yoga)
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.
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.
## 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`.
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.
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`.
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.
Usage
-----
A single function `computeLayout` is exposed that
- 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
var nodeTree = {
"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"
}
}
```html
<div id="my_test" style="width: 100px; height: 100px; align-items: center;">
<div style="width: 50px; height: 50px;"></div>
</div>
```
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
----:|------
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
flexDirection | 'column', 'row'
justifyContent | 'flex-start', 'center', 'flex-end', 'space-between', 'space-around'
alignItems, alignSelf, alignContent | 'flex-start', 'center', 'flex-end', 'stretch'
flex | positive number
flexWrap | 'wrap', 'nowrap'
position | 'relative', 'absolute'
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.
- `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`.
## Benchmarks
Benchmarks are located in `benchmark/YGBenchmark.c` and can be run with `buck run //benchmark:benchmark`. If you think your change has affected performance please run this before and after your change to validate that nothing has regressed. Benchmarks are run on every commit in CI.
Default values
--------------
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: 0 solid black;
margin: 0;
padding: 0;
}
### JavaScript
Installing through NPM
```sh
npm install yoga-layout
```
- `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:
```
grunt test-javascript
By default this will install the library and try to build for all platforms (node, browser asm, and standalone webpack). You may receive errors if you do not have the required platform development tools already installed. To preset the platform you'd like to build for you can set a .npmrc property first.
```sh
npm config set yoga-layout:platform standalone
```
This will now only run the standalone webpack build upon install.
## Build Platforms
| name | description |
|----------------|-------------------------------------------------|
| all (default) | Builds all of these platforms. |
| browser | Builds asm js browser version. |
| node | Builds node js version. |
| standalone | Runs webpack. |
| none | Does nothing. You can use the prepackaged libs. |

30
Yoga.podspec Normal file
View File

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

29
YogaKit.podspec Normal file
View File

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

1
YogaKit/.swift-version Normal file
View File

@@ -0,0 +1 @@
3.0.2

65
YogaKit/BUCK Normal file
View File

@@ -0,0 +1,65 @@
# Copyright (c) 2014-present, Facebook, Inc.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
load("//:yoga_defs.bzl", "yoga_dep", "apple_library", "apple_test")
COMPILER_FLAGS = [
"-fobjc-arc",
"-Wconditional-uninitialized",
"-Wdangling-else",
"-Wdeprecated-declarations",
"-Wimplicit-retain-self",
"-Wincomplete-implementation",
"-Wobjc-method-access",
"-Wobjc-missing-super-calls",
"-Wmismatched-return-types",
"-Wreturn-type",
"-Wno-global-constructors",
"-Wno-shadow",
"-Wunused-const-variable",
"-Wunused-function",
"-Wunused-property-ivar",
"-Wunused-result",
"-Wunused-value",
]
apple_library(
name = "YogaKit",
srcs = glob(["Source/**/*.m"]),
header_namespace = "",
exported_headers = subdir_glob(
[
("", "Source/**/*.h"),
("Source", "**/*.h"),
],
prefix = "YogaKit",
),
compiler_flags = COMPILER_FLAGS,
frameworks = [
"$SDKROOT/System/Library/Frameworks/Foundation.framework",
"$SDKROOT/System/Library/Frameworks/UIKit.framework",
],
header_path_prefix = "",
link_whole = True,
visibility = ["PUBLIC"],
deps = [
yoga_dep(":yoga"),
],
)
apple_test(
name = "YogaKitTests",
srcs = glob(["Tests/**/*.m"]),
compiler_flags = COMPILER_FLAGS,
frameworks = [
"$PLATFORM_DIR/Developer/Library/Frameworks/XCTest.framework",
"$SDKROOT/System/Library/Frameworks/CoreGraphics.framework",
],
info_plist = "Tests/Info.plist",
visibility = ["PUBLIC"],
deps = [
":YogaKit",
],
)

22
YogaKit/README.md Normal file
View File

@@ -0,0 +1,22 @@
# YogaKit
[![CocoaPods](https://img.shields.io/cocoapods/v/YogaKit.svg?style=flat)](https://cocoapods.org/pods/YogaKit)
[![Platform](https://img.shields.io/badge/platforms-iOS-orange.svg)](https://facebook.github.io/yoga/docs/api/yogakit/)
[![Languages](https://img.shields.io/badge/languages-ObjC%20%7C%20Swift-orange.svg)](https://facebook.github.io/yoga/docs/api/yogakit/)
## Installation
YogaKit is available to install via [CocoaPods](https://cocoapods.org/).
```
pod 'YogaKit', '~> 1.7'
```
## 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.md](https://github.com/facebook/yoga/blob/master/CONTRIBUTING.md) file for how to help out.

View File

@@ -0,0 +1,36 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "YGLayout.h"
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
typedef void (^YGLayoutConfigurationBlock)(YGLayout *layout);
@interface UIView (Yoga)
/**
The YGLayout that is attached to this view. It is lazily created.
*/
@property (nonatomic, readonly, strong) YGLayout *yoga;
/**
Indicates whether or not Yoga is enabled
*/
@property (nonatomic, readonly, assign) BOOL isYogaEnabled;
/**
In ObjC land, every time you access `view.yoga.*` you are adding another `objc_msgSend`
to your code. If you plan on making multiple changes to YGLayout, it's more performant
to use this method, which uses a single objc_msgSend call.
*/
- (void)configureLayoutWithBlock:(YGLayoutConfigurationBlock)block
NS_SWIFT_NAME(configureLayout(block:));
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,39 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "UIView+Yoga.h"
#import "YGLayout+Private.h"
#import <objc/runtime.h>
static const void *kYGYogaAssociatedKey = &kYGYogaAssociatedKey;
@implementation UIView (YogaKit)
- (YGLayout *)yoga
{
YGLayout *yoga = objc_getAssociatedObject(self, kYGYogaAssociatedKey);
if (!yoga) {
yoga = [[YGLayout alloc] initWithView:self];
objc_setAssociatedObject(self, kYGYogaAssociatedKey, yoga, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
return yoga;
}
- (BOOL)isYogaEnabled
{
return objc_getAssociatedObject(self, kYGYogaAssociatedKey) != nil;
}
- (void)configureLayoutWithBlock:(YGLayoutConfigurationBlock)block
{
if (block != nil) {
block(self.yoga);
}
}
@end

View File

@@ -0,0 +1,17 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "YGLayout.h"
#import <yoga/Yoga.h>
@interface YGLayout ()
@property (nonatomic, assign, readonly) YGNodeRef node;
- (instancetype)initWithView:(UIView *)view;
@end

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

@@ -0,0 +1,162 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <UIKit/UIKit.h>
#import <yoga/YGEnums.h>
#import <yoga/Yoga.h>
#import <yoga/YGMacros.h>
YG_EXTERN_C_BEGIN
extern YGValue YGPointValue(CGFloat value)
NS_SWIFT_UNAVAILABLE("Use the swift Int and FloatingPoint extensions instead");
extern YGValue YGPercentValue(CGFloat value)
NS_SWIFT_UNAVAILABLE("Use the swift Int and FloatingPoint extensions instead");
YG_EXTERN_C_END
typedef NS_OPTIONS(NSInteger, YGDimensionFlexibility) {
YGDimensionFlexibilityFlexibleWidth = 1 << 0,
YGDimensionFlexibilityFlexibleHeight = 1 << 1,
};
@interface YGLayout : NSObject
/**
Make default init unavailable, as it will not initialise YGNode which is
required for the setters and getters of YGLayout's properties to work properly.
*/
- (instancetype)init
__attribute__((unavailable("you are not meant to initialise YGLayout")));
/**
The property that decides if we should include this view when calculating
layout. Defaults to YES.
*/
@property (nonatomic, readwrite, assign, setter=setIncludedInLayout:) BOOL isIncludedInLayout;
/**
The property that decides during layout/sizing whether or not styling properties should be applied.
Defaults to NO.
*/
@property (nonatomic, readwrite, assign, setter=setEnabled:) BOOL isEnabled;
@property (nonatomic, readwrite, assign) YGDirection direction;
@property (nonatomic, readwrite, assign) YGFlexDirection flexDirection;
@property (nonatomic, readwrite, assign) YGJustify justifyContent;
@property (nonatomic, readwrite, assign) YGAlign alignContent;
@property (nonatomic, readwrite, assign) YGAlign alignItems;
@property (nonatomic, readwrite, assign) YGAlign alignSelf;
@property (nonatomic, readwrite, assign) YGPositionType position;
@property (nonatomic, readwrite, assign) YGWrap flexWrap;
@property (nonatomic, readwrite, assign) YGOverflow overflow;
@property (nonatomic, readwrite, assign) YGDisplay display;
@property (nonatomic, readwrite, assign) CGFloat flexGrow;
@property (nonatomic, readwrite, assign) CGFloat flexShrink;
@property (nonatomic, readwrite, assign) YGValue flexBasis;
@property (nonatomic, readwrite, assign) YGValue left;
@property (nonatomic, readwrite, assign) YGValue top;
@property (nonatomic, readwrite, assign) YGValue right;
@property (nonatomic, readwrite, assign) YGValue bottom;
@property (nonatomic, readwrite, assign) YGValue start;
@property (nonatomic, readwrite, assign) YGValue end;
@property (nonatomic, readwrite, assign) YGValue marginLeft;
@property (nonatomic, readwrite, assign) YGValue marginTop;
@property (nonatomic, readwrite, assign) YGValue marginRight;
@property (nonatomic, readwrite, assign) YGValue marginBottom;
@property (nonatomic, readwrite, assign) YGValue marginStart;
@property (nonatomic, readwrite, assign) YGValue marginEnd;
@property (nonatomic, readwrite, assign) YGValue marginHorizontal;
@property (nonatomic, readwrite, assign) YGValue marginVertical;
@property (nonatomic, readwrite, assign) YGValue margin;
@property (nonatomic, readwrite, assign) YGValue paddingLeft;
@property (nonatomic, readwrite, assign) YGValue paddingTop;
@property (nonatomic, readwrite, assign) YGValue paddingRight;
@property (nonatomic, readwrite, assign) YGValue paddingBottom;
@property (nonatomic, readwrite, assign) YGValue paddingStart;
@property (nonatomic, readwrite, assign) YGValue paddingEnd;
@property (nonatomic, readwrite, assign) YGValue paddingHorizontal;
@property (nonatomic, readwrite, assign) YGValue paddingVertical;
@property (nonatomic, readwrite, assign) YGValue padding;
@property (nonatomic, readwrite, assign) CGFloat borderLeftWidth;
@property (nonatomic, readwrite, assign) CGFloat borderTopWidth;
@property (nonatomic, readwrite, assign) CGFloat borderRightWidth;
@property (nonatomic, readwrite, assign) CGFloat borderBottomWidth;
@property (nonatomic, readwrite, assign) CGFloat borderStartWidth;
@property (nonatomic, readwrite, assign) CGFloat borderEndWidth;
@property (nonatomic, readwrite, assign) CGFloat borderWidth;
@property (nonatomic, readwrite, assign) YGValue width;
@property (nonatomic, readwrite, assign) YGValue height;
@property (nonatomic, readwrite, assign) YGValue minWidth;
@property (nonatomic, readwrite, assign) YGValue minHeight;
@property (nonatomic, readwrite, assign) YGValue maxWidth;
@property (nonatomic, readwrite, assign) YGValue maxHeight;
// Yoga specific properties, not compatible with flexbox specification
@property (nonatomic, readwrite, assign) CGFloat aspectRatio;
/**
Get the resolved direction of this node. This won't be YGDirectionInherit
*/
@property (nonatomic, readonly, assign) YGDirection resolvedDirection;
/**
Perform a layout calculation and update the frames of the views in the hierarchy with the results.
If the origin is not preserved, the root view's layout results will applied from {0,0}.
*/
- (void)applyLayoutPreservingOrigin:(BOOL)preserveOrigin
NS_SWIFT_NAME(applyLayout(preservingOrigin:));
/**
Perform a layout calculation and update the frames of the views in the hierarchy with the results.
If the origin is not preserved, the root view's layout results will applied from {0,0}.
*/
- (void)applyLayoutPreservingOrigin:(BOOL)preserveOrigin
dimensionFlexibility:(YGDimensionFlexibility)dimensionFlexibility
NS_SWIFT_NAME(applyLayout(preservingOrigin:dimensionFlexibility:));
/**
Returns the size of the view if no constraints were given. This could equivalent to calling [self
sizeThatFits:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)];
*/
@property (nonatomic, readonly, assign) CGSize intrinsicSize;
/**
Returns the size of the view based on provided constraints. Pass NaN for an unconstrained dimension.
*/
- (CGSize)calculateLayoutWithSize:(CGSize)size
NS_SWIFT_NAME(calculateLayout(with:));
/**
Returns the number of children that are using Flexbox.
*/
@property (nonatomic, readonly, assign) NSUInteger numberOfChildren;
/**
Return a BOOL indiciating whether or not we this node contains any subviews that are included in
Yoga's layout.
*/
@property (nonatomic, readonly, assign) BOOL isLeaf;
/**
Return's a BOOL indicating if a view is dirty. When a node is dirty
it usually indicates that it will be remeasured on the next layout pass.
*/
@property (nonatomic, readonly, assign) BOOL isDirty;
/**
Mark that a view's layout needs to be recalculated. Only works for leaf views.
*/
- (void)markDirty;
@end

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

@@ -0,0 +1,471 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "YGLayout+Private.h"
#import "UIView+Yoga.h"
#define YG_PROPERTY(type, lowercased_name, capitalized_name) \
- (type)lowercased_name \
{ \
return YGNodeStyleGet##capitalized_name(self.node); \
} \
\
- (void)set##capitalized_name:(type)lowercased_name \
{ \
YGNodeStyleSet##capitalized_name(self.node, lowercased_name); \
}
#define YG_VALUE_PROPERTY(lowercased_name, capitalized_name) \
- (YGValue)lowercased_name \
{ \
return YGNodeStyleGet##capitalized_name(self.node); \
} \
\
- (void)set##capitalized_name:(YGValue)lowercased_name \
{ \
switch (lowercased_name.unit) { \
case YGUnitUndefined: \
YGNodeStyleSet##capitalized_name(self.node, lowercased_name.value); \
break; \
case YGUnitPoint: \
YGNodeStyleSet##capitalized_name(self.node, lowercased_name.value); \
break; \
case YGUnitPercent: \
YGNodeStyleSet##capitalized_name##Percent(self.node, lowercased_name.value); \
break; \
default: \
NSAssert(NO, @"Not implemented"); \
} \
}
#define YG_AUTO_VALUE_PROPERTY(lowercased_name, capitalized_name) \
- (YGValue)lowercased_name \
{ \
return YGNodeStyleGet##capitalized_name(self.node); \
} \
\
- (void)set##capitalized_name:(YGValue)lowercased_name \
{ \
switch (lowercased_name.unit) { \
case YGUnitPoint: \
YGNodeStyleSet##capitalized_name(self.node, lowercased_name.value); \
break; \
case YGUnitPercent: \
YGNodeStyleSet##capitalized_name##Percent(self.node, lowercased_name.value); \
break; \
case YGUnitAuto: \
YGNodeStyleSet##capitalized_name##Auto(self.node); \
break; \
default: \
NSAssert(NO, @"Not implemented"); \
} \
}
#define YG_EDGE_PROPERTY_GETTER(type, lowercased_name, capitalized_name, property, edge) \
- (type)lowercased_name \
{ \
return YGNodeStyleGet##property(self.node, edge); \
}
#define YG_EDGE_PROPERTY_SETTER(lowercased_name, capitalized_name, property, edge) \
- (void)set##capitalized_name:(CGFloat)lowercased_name \
{ \
YGNodeStyleSet##property(self.node, edge, lowercased_name); \
}
#define YG_EDGE_PROPERTY(lowercased_name, capitalized_name, property, edge) \
YG_EDGE_PROPERTY_GETTER(CGFloat, lowercased_name, capitalized_name, property, edge) \
YG_EDGE_PROPERTY_SETTER(lowercased_name, capitalized_name, property, edge)
#define YG_VALUE_EDGE_PROPERTY_SETTER(objc_lowercased_name, objc_capitalized_name, c_name, edge) \
- (void)set##objc_capitalized_name:(YGValue)objc_lowercased_name \
{ \
switch (objc_lowercased_name.unit) { \
case YGUnitUndefined: \
YGNodeStyleSet##c_name(self.node, edge, objc_lowercased_name.value); \
break; \
case YGUnitPoint: \
YGNodeStyleSet##c_name(self.node, edge, objc_lowercased_name.value); \
break; \
case YGUnitPercent: \
YGNodeStyleSet##c_name##Percent(self.node, edge, objc_lowercased_name.value); \
break; \
default: \
NSAssert(NO, @"Not implemented"); \
} \
}
#define YG_VALUE_EDGE_PROPERTY(lowercased_name, capitalized_name, property, edge) \
YG_EDGE_PROPERTY_GETTER(YGValue, lowercased_name, capitalized_name, property, edge) \
YG_VALUE_EDGE_PROPERTY_SETTER(lowercased_name, capitalized_name, property, edge)
#define YG_VALUE_EDGES_PROPERTIES(lowercased_name, capitalized_name) \
YG_VALUE_EDGE_PROPERTY(lowercased_name##Left, capitalized_name##Left, capitalized_name, YGEdgeLeft) \
YG_VALUE_EDGE_PROPERTY(lowercased_name##Top, capitalized_name##Top, capitalized_name, YGEdgeTop) \
YG_VALUE_EDGE_PROPERTY(lowercased_name##Right, capitalized_name##Right, capitalized_name, YGEdgeRight) \
YG_VALUE_EDGE_PROPERTY(lowercased_name##Bottom, capitalized_name##Bottom, capitalized_name, YGEdgeBottom) \
YG_VALUE_EDGE_PROPERTY(lowercased_name##Start, capitalized_name##Start, capitalized_name, YGEdgeStart) \
YG_VALUE_EDGE_PROPERTY(lowercased_name##End, capitalized_name##End, capitalized_name, YGEdgeEnd) \
YG_VALUE_EDGE_PROPERTY(lowercased_name##Horizontal, capitalized_name##Horizontal, capitalized_name, YGEdgeHorizontal) \
YG_VALUE_EDGE_PROPERTY(lowercased_name##Vertical, capitalized_name##Vertical, capitalized_name, YGEdgeVertical) \
YG_VALUE_EDGE_PROPERTY(lowercased_name, capitalized_name, capitalized_name, YGEdgeAll)
YGValue YGPointValue(CGFloat value)
{
return (YGValue) { .value = value, .unit = YGUnitPoint };
}
YGValue YGPercentValue(CGFloat value)
{
return (YGValue) { .value = value, .unit = YGUnitPercent };
}
static YGConfigRef globalConfig;
@interface YGLayout ()
@property (nonatomic, weak, readonly) UIView *view;
@end
@implementation YGLayout
@synthesize isEnabled=_isEnabled;
@synthesize isIncludedInLayout=_isIncludedInLayout;
@synthesize node=_node;
+ (void)initialize
{
globalConfig = YGConfigNew();
YGConfigSetExperimentalFeatureEnabled(globalConfig, YGExperimentalFeatureWebFlexBasis, true);
YGConfigSetPointScaleFactor(globalConfig, [UIScreen mainScreen].scale);
}
- (instancetype)initWithView:(UIView*)view
{
if (self = [super init]) {
_view = view;
_node = YGNodeNewWithConfig(globalConfig);
YGNodeSetContext(_node, (__bridge void *) view);
_isEnabled = NO;
_isIncludedInLayout = YES;
}
return self;
}
- (void)dealloc
{
YGNodeFree(self.node);
}
- (BOOL)isDirty
{
return YGNodeIsDirty(self.node);
}
- (void)markDirty
{
if (self.isDirty || !self.isLeaf) {
return;
}
// Yoga is not happy if we try to mark a node as "dirty" before we have set
// the measure function. Since we already know that this is a leaf,
// this *should* be fine. Forgive me Hack Gods.
const YGNodeRef node = self.node;
if (YGNodeGetMeasureFunc(node) == NULL) {
YGNodeSetMeasureFunc(node, YGMeasureView);
}
YGNodeMarkDirty(node);
}
- (NSUInteger)numberOfChildren
{
return YGNodeGetChildCount(self.node);
}
- (BOOL)isLeaf
{
NSAssert([NSThread isMainThread], @"This method must be called on the main thread.");
if (self.isEnabled) {
for (UIView *subview in self.view.subviews) {
YGLayout *const yoga = subview.yoga;
if (yoga.isEnabled && yoga.isIncludedInLayout) {
return NO;
}
}
}
return YES;
}
#pragma mark - Style
- (YGPositionType)position
{
return YGNodeStyleGetPositionType(self.node);
}
- (void)setPosition:(YGPositionType)position
{
YGNodeStyleSetPositionType(self.node, position);
}
YG_PROPERTY(YGDirection, direction, Direction)
YG_PROPERTY(YGFlexDirection, flexDirection, FlexDirection)
YG_PROPERTY(YGJustify, justifyContent, JustifyContent)
YG_PROPERTY(YGAlign, alignContent, AlignContent)
YG_PROPERTY(YGAlign, alignItems, AlignItems)
YG_PROPERTY(YGAlign, alignSelf, AlignSelf)
YG_PROPERTY(YGWrap, flexWrap, FlexWrap)
YG_PROPERTY(YGOverflow, overflow, Overflow)
YG_PROPERTY(YGDisplay, display, Display)
YG_PROPERTY(CGFloat, flexGrow, FlexGrow)
YG_PROPERTY(CGFloat, flexShrink, FlexShrink)
YG_AUTO_VALUE_PROPERTY(flexBasis, FlexBasis)
YG_VALUE_EDGE_PROPERTY(left, Left, Position, YGEdgeLeft)
YG_VALUE_EDGE_PROPERTY(top, Top, Position, YGEdgeTop)
YG_VALUE_EDGE_PROPERTY(right, Right, Position, YGEdgeRight)
YG_VALUE_EDGE_PROPERTY(bottom, Bottom, Position, YGEdgeBottom)
YG_VALUE_EDGE_PROPERTY(start, Start, Position, YGEdgeStart)
YG_VALUE_EDGE_PROPERTY(end, End, Position, YGEdgeEnd)
YG_VALUE_EDGES_PROPERTIES(margin, Margin)
YG_VALUE_EDGES_PROPERTIES(padding, Padding)
YG_EDGE_PROPERTY(borderLeftWidth, BorderLeftWidth, Border, YGEdgeLeft)
YG_EDGE_PROPERTY(borderTopWidth, BorderTopWidth, Border, YGEdgeTop)
YG_EDGE_PROPERTY(borderRightWidth, BorderRightWidth, Border, YGEdgeRight)
YG_EDGE_PROPERTY(borderBottomWidth, BorderBottomWidth, Border, YGEdgeBottom)
YG_EDGE_PROPERTY(borderStartWidth, BorderStartWidth, Border, YGEdgeStart)
YG_EDGE_PROPERTY(borderEndWidth, BorderEndWidth, Border, YGEdgeEnd)
YG_EDGE_PROPERTY(borderWidth, BorderWidth, Border, YGEdgeAll)
YG_AUTO_VALUE_PROPERTY(width, Width)
YG_AUTO_VALUE_PROPERTY(height, Height)
YG_VALUE_PROPERTY(minWidth, MinWidth)
YG_VALUE_PROPERTY(minHeight, MinHeight)
YG_VALUE_PROPERTY(maxWidth, MaxWidth)
YG_VALUE_PROPERTY(maxHeight, MaxHeight)
YG_PROPERTY(CGFloat, aspectRatio, AspectRatio)
#pragma mark - Layout and Sizing
- (YGDirection)resolvedDirection
{
return YGNodeLayoutGetDirection(self.node);
}
- (void)applyLayout
{
[self calculateLayoutWithSize:self.view.bounds.size];
YGApplyLayoutToViewHierarchy(self.view, NO);
}
- (void)applyLayoutPreservingOrigin:(BOOL)preserveOrigin
{
[self calculateLayoutWithSize:self.view.bounds.size];
YGApplyLayoutToViewHierarchy(self.view, preserveOrigin);
}
- (void)applyLayoutPreservingOrigin:(BOOL)preserveOrigin dimensionFlexibility:(YGDimensionFlexibility)dimensionFlexibility
{
CGSize size = self.view.bounds.size;
if (dimensionFlexibility & YGDimensionFlexibilityFlexibleWidth) {
size.width = YGUndefined;
}
if (dimensionFlexibility & YGDimensionFlexibilityFlexibleHeight) {
size.height = YGUndefined;
}
[self calculateLayoutWithSize:size];
YGApplyLayoutToViewHierarchy(self.view, preserveOrigin);
}
- (CGSize)intrinsicSize
{
const CGSize constrainedSize = {
.width = YGUndefined,
.height = YGUndefined,
};
return [self calculateLayoutWithSize:constrainedSize];
}
- (CGSize)calculateLayoutWithSize:(CGSize)size
{
NSAssert([NSThread isMainThread], @"Yoga calculation must be done on main.");
NSAssert(self.isEnabled, @"Yoga is not enabled for this view.");
YGAttachNodesFromViewHierachy(self.view);
const YGNodeRef node = self.node;
YGNodeCalculateLayout(
node,
size.width,
size.height,
YGNodeStyleGetDirection(node));
return (CGSize) {
.width = YGNodeLayoutGetWidth(node),
.height = YGNodeLayoutGetHeight(node),
};
}
#pragma mark - Private
static YGSize YGMeasureView(
YGNodeRef node,
float width,
YGMeasureMode widthMode,
float height,
YGMeasureMode heightMode)
{
const CGFloat constrainedWidth = (widthMode == YGMeasureModeUndefined) ? CGFLOAT_MAX : width;
const CGFloat constrainedHeight = (heightMode == YGMeasureModeUndefined) ? CGFLOAT_MAX: height;
UIView *view = (__bridge UIView*) YGNodeGetContext(node);
const CGSize sizeThatFits = [view sizeThatFits:(CGSize) {
.width = constrainedWidth,
.height = constrainedHeight,
}];
return (YGSize) {
.width = YGSanitizeMeasurement(constrainedWidth, sizeThatFits.width, widthMode),
.height = YGSanitizeMeasurement(constrainedHeight, sizeThatFits.height, heightMode),
};
}
static CGFloat YGSanitizeMeasurement(
CGFloat constrainedSize,
CGFloat measuredSize,
YGMeasureMode measureMode)
{
CGFloat result;
if (measureMode == YGMeasureModeExactly) {
result = constrainedSize;
} else if (measureMode == YGMeasureModeAtMost) {
result = MIN(constrainedSize, measuredSize);
} else {
result = measuredSize;
}
return result;
}
static BOOL YGNodeHasExactSameChildren(const YGNodeRef node, NSArray<UIView *> *subviews)
{
if (YGNodeGetChildCount(node) != subviews.count) {
return NO;
}
for (int i=0; i<subviews.count; i++) {
if (YGNodeGetChild(node, i) != subviews[i].yoga.node) {
return NO;
}
}
return YES;
}
static void YGAttachNodesFromViewHierachy(UIView *const view)
{
YGLayout *const yoga = view.yoga;
const YGNodeRef node = yoga.node;
// Only leaf nodes should have a measure function
if (yoga.isLeaf) {
YGRemoveAllChildren(node);
YGNodeSetMeasureFunc(node, YGMeasureView);
} else {
YGNodeSetMeasureFunc(node, NULL);
NSMutableArray<UIView *> *subviewsToInclude = [[NSMutableArray alloc] initWithCapacity:view.subviews.count];
for (UIView *subview in view.subviews) {
if (subview.yoga.isEnabled && subview.yoga.isIncludedInLayout) {
[subviewsToInclude addObject:subview];
}
}
if (!YGNodeHasExactSameChildren(node, subviewsToInclude)) {
YGRemoveAllChildren(node);
for (int i=0; i<subviewsToInclude.count; i++) {
YGNodeInsertChild(node, subviewsToInclude[i].yoga.node, i);
}
}
for (UIView *const subview in subviewsToInclude) {
YGAttachNodesFromViewHierachy(subview);
}
}
}
static void YGRemoveAllChildren(const YGNodeRef node)
{
if (node == NULL) {
return;
}
while (YGNodeGetChildCount(node) > 0) {
YGNodeRemoveChild(node, YGNodeGetChild(node, YGNodeGetChildCount(node) - 1));
}
}
static CGFloat YGRoundPixelValue(CGFloat value)
{
static CGFloat scale;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^(){
scale = [UIScreen mainScreen].scale;
});
return roundf(value * scale) / scale;
}
static void YGApplyLayoutToViewHierarchy(UIView *view, BOOL preserveOrigin)
{
NSCAssert([NSThread isMainThread], @"Framesetting should only be done on the main thread.");
const YGLayout *yoga = view.yoga;
if (!yoga.isIncludedInLayout) {
return;
}
YGNodeRef node = yoga.node;
const CGPoint topLeft = {
YGNodeLayoutGetLeft(node),
YGNodeLayoutGetTop(node),
};
const CGPoint bottomRight = {
topLeft.x + YGNodeLayoutGetWidth(node),
topLeft.y + YGNodeLayoutGetHeight(node),
};
const CGPoint origin = preserveOrigin ? view.frame.origin : CGPointZero;
view.frame = (CGRect) {
.origin = {
.x = YGRoundPixelValue(topLeft.x + origin.x),
.y = YGRoundPixelValue(topLeft.y + origin.y),
},
.size = {
.width = YGRoundPixelValue(bottomRight.x) - YGRoundPixelValue(topLeft.x),
.height = YGRoundPixelValue(bottomRight.y) - YGRoundPixelValue(topLeft.y),
},
};
if (!yoga.isLeaf) {
for (NSUInteger i=0; i<view.subviews.count; i++) {
YGApplyLayoutToViewHierarchy(view.subviews[i], NO);
}
}
}
@end

View File

@@ -0,0 +1,44 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
postfix operator %
extension Int {
public static postfix func %(value: Int) -> YGValue {
return YGValue(value: Float(value), unit: .percent)
}
}
extension Float {
public static postfix func %(value: Float) -> YGValue {
return YGValue(value: value, unit: .percent)
}
}
extension CGFloat {
public static postfix func %(value: CGFloat) -> YGValue {
return YGValue(value: Float(value), unit: .percent)
}
}
extension YGValue : ExpressibleByIntegerLiteral, ExpressibleByFloatLiteral {
public init(integerLiteral value: Int) {
self = YGValue(value: Float(value), unit: .point)
}
public init(floatLiteral value: Float) {
self = YGValue(value: value, unit: .point)
}
public init(_ value: Float) {
self = YGValue(value: value, unit: .point)
}
public init(_ value: CGFloat) {
self = YGValue(value: Float(value), unit: .point)
}
}

22
YogaKit/Tests/Info.plist Normal file
View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIdentifier</key>
<string>com.facebook.${PRODUCT_NAME:rfc1034identifier}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>

View File

@@ -0,0 +1,745 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <XCTest/XCTest.h>
#import <YogaKit/UIView+Yoga.h>
#import <YogaKit/YGLayout+Private.h>
#import <yoga/Yoga.h>
@interface YogaKitTests : XCTestCase
@end
@implementation YogaKitTests
- (void)testConfigureLayoutIsNoOpWithNilBlock
{
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
id block = nil;
XCTAssertNoThrow([view configureLayoutWithBlock:block]);
}
- (void)testConfigureLayoutBlockWorksWithValidBlock
{
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
[view configureLayoutWithBlock:^(YGLayout *layout){
XCTAssertNotNil(layout);
layout.isEnabled = YES;
layout.width = YGPointValue(25);
}];
XCTAssertTrue(view.yoga.isEnabled);
XCTAssertEqual(view.yoga.width.value, 25);
}
- (void)testNodesAreDeallocedWithSingleView
{
__weak YGLayout *layoutRef = nil;
@autoreleasepool {
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
view.yoga.flexBasis = YGPointValue(1);
layoutRef = view.yoga;
XCTAssertNotNil(layoutRef);
view = nil;
}
XCTAssertNil(layoutRef);
}
- (void)testNodesAreDeallocedCascade
{
__weak YGLayout *topLayout = nil;
__weak YGLayout *subviewLayout = nil;
@autoreleasepool {
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
topLayout = view.yoga;
topLayout.flexBasis = YGPointValue(1);
UIView *subview = [[UIView alloc] initWithFrame:CGRectZero];
subviewLayout = subview.yoga;
subviewLayout.flexBasis = YGPointValue(1);
view = nil;
}
XCTAssertNil(topLayout);
XCTAssertNil(subviewLayout);
}
- (void)testIsEnabled
{
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
XCTAssertFalse(view.yoga.isEnabled);
view.yoga.isEnabled = YES;
XCTAssertTrue(view.yoga.isEnabled);
view.yoga.isEnabled = NO;
XCTAssertFalse(view.yoga.isEnabled);
}
- (void)testSizeThatFitsAsserts
{
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
dispatch_sync(dispatch_queue_create("com.facebook.Yoga.testing", DISPATCH_QUEUE_SERIAL), ^(void){
XCTAssertThrows(view.yoga.intrinsicSize);
});
}
- (void)testSizeThatFitsSmoke
{
UIView *container = [[UIView alloc] initWithFrame:CGRectZero];
container.yoga.isEnabled = YES;
container.yoga.flexDirection = YGFlexDirectionRow;
container.yoga.alignItems = YGAlignFlexStart;
UILabel *longTextLabel = [[UILabel alloc] initWithFrame:CGRectZero];
longTextLabel.text = @"This is a very very very very very very very very long piece of text.";
longTextLabel.lineBreakMode = NSLineBreakByTruncatingTail;
longTextLabel.numberOfLines = 1;
longTextLabel.yoga.isEnabled = YES;
longTextLabel.yoga.flexShrink = 1;
[container addSubview:longTextLabel];
UIView *textBadgeView = [[UIView alloc] initWithFrame:CGRectZero];
textBadgeView.yoga.isEnabled = YES;
textBadgeView.yoga.margin = YGPointValue(0);
textBadgeView.yoga.width = YGPointValue(10);
textBadgeView.yoga.height = YGPointValue(10);
[container addSubview:textBadgeView];
const CGSize textBadgeViewSize = textBadgeView.yoga.intrinsicSize;
XCTAssertEqual(textBadgeViewSize.height, 10);
XCTAssertEqual(textBadgeViewSize.width, 10);
const CGSize containerSize = container.yoga.intrinsicSize;
const CGSize longTextLabelSize = longTextLabel.yoga.intrinsicSize;
XCTAssertEqual(longTextLabelSize.height, containerSize.height);
XCTAssertEqual(longTextLabelSize.width + textBadgeView.yoga.intrinsicSize.width, containerSize.width);
}
- (void)testPreservingOrigin
{
UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0,0,50,75)];
container.yoga.isEnabled = YES;
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
view.yoga.isEnabled = YES;
view.yoga.flexBasis = YGPointValue(0);
view.yoga.flexGrow = 1;
[container addSubview:view];
UIView *view2 = [[UIView alloc] initWithFrame:CGRectZero];
view2.yoga.isEnabled = YES;
view2.yoga.marginTop = YGPointValue(25);
view2.yoga.flexBasis = YGPointValue(0);
view2.yoga.flexGrow = 1;
[container addSubview:view2];
[container.yoga applyLayoutPreservingOrigin:YES];
XCTAssertEqual(50, view2.frame.origin.y);
[view2.yoga applyLayoutPreservingOrigin:NO];
XCTAssertEqual(25, view2.frame.origin.y);
}
- (void)testContainerWithFlexibleWidthGetsCorrectlySized
{
UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0,0,200,200)];
container.yoga.isEnabled = YES;
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
view.yoga.isEnabled = YES;
view.yoga.width = YGPointValue(100);
view.yoga.height = YGPointValue(100);
[container addSubview:view];
[container.yoga applyLayoutPreservingOrigin:YES dimensionFlexibility:YGDimensionFlexibilityFlexibleWidth];
XCTAssertEqual(100, container.frame.size.width);
XCTAssertEqual(200, container.frame.size.height);
}
- (void)testContainerWithFlexibleHeightGetsCorrectlySized
{
UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0,0,200,200)];
container.yoga.isEnabled = YES;
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
view.yoga.isEnabled = YES;
view.yoga.width = YGPointValue(100);
view.yoga.height = YGPointValue(100);
[container addSubview:view];
[container.yoga
applyLayoutPreservingOrigin:YES
dimensionFlexibility:YGDimensionFlexibilityFlexibleHeight];
XCTAssertEqual(200, container.frame.size.width);
XCTAssertEqual(100, container.frame.size.height);
}
- (void)testContainerWithFlexibleWidthAndHeightGetsCorrectlySized
{
UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0,0,200,200)];
container.yoga.isEnabled = YES;
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
view.yoga.isEnabled = YES;
view.yoga.width = YGPointValue(100);
view.yoga.height = YGPointValue(100);
[container addSubview:view];
[container.yoga
applyLayoutPreservingOrigin:YES
dimensionFlexibility:YGDimensionFlexibilityFlexibleWidth |
YGDimensionFlexibilityFlexibleHeight];
XCTAssertEqual(100, container.frame.size.width);
XCTAssertEqual(100, container.frame.size.height);
}
- (void)testMarkingDirtyOnlyWorksOnLeafNodes
{
UIView *container = [[UIView alloc] initWithFrame:CGRectZero];
container.yoga.isEnabled = YES;
UIView *subview = [[UIView alloc] initWithFrame:CGRectZero];
subview.yoga.isEnabled = YES;
[container addSubview:subview];
XCTAssertFalse(container.yoga.isDirty);
[container.yoga markDirty];
XCTAssertFalse(container.yoga.isDirty);
XCTAssertFalse(subview.yoga.isDirty);
[subview.yoga markDirty];
XCTAssertTrue(subview.yoga.isDirty);
}
- (void)testThatMarkingLeafsAsDirtyWillTriggerASizeRecalculation
{
UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 50)];
container.yoga.isEnabled = YES;
container.yoga.flexDirection = YGFlexDirectionRow;
container.yoga.alignItems = YGAlignFlexStart;
UILabel *view = [[UILabel alloc] initWithFrame:CGRectZero];
view.text = @"This is a short text.";
view.numberOfLines = 1;
view.yoga.isEnabled = YES;
[container addSubview:view];
[container.yoga applyLayoutPreservingOrigin:YES];
CGSize const viewSizeAfterFirstPass = view.frame.size;
view.text = @"This is a slightly longer text.";
XCTAssertTrue(CGSizeEqualToSize(view.frame.size, viewSizeAfterFirstPass));
[view.yoga markDirty];
[container.yoga applyLayoutPreservingOrigin:YES];
XCTAssertFalse(CGSizeEqualToSize(view.frame.size, viewSizeAfterFirstPass));
}
- (void)testFrameAndOriginPlacement
{
const CGSize containerSize = CGSizeMake(320, 50);
UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, containerSize.width, containerSize.height)];
container.yoga.isEnabled = YES;
container.yoga.flexDirection = YGFlexDirectionRow;
UIView *subview1 = [[UIView alloc] initWithFrame:CGRectZero];
subview1.yoga.isEnabled = YES;
subview1.yoga.flexGrow = 1;
[container addSubview:subview1];
UIView *subview2 = [[UIView alloc] initWithFrame:CGRectZero];
subview2.yoga.isEnabled = YES;
subview2.yoga.flexGrow = 1;
[container addSubview:subview2];
UIView *subview3 = [[UIView alloc] initWithFrame:CGRectZero];
subview3.yoga.isEnabled = YES;
subview3.yoga.flexGrow = 1;
[container addSubview:subview3];
[container.yoga applyLayoutPreservingOrigin:YES];
XCTAssertEqualWithAccuracy(subview2.frame.origin.x, CGRectGetMaxX(subview1.frame), FLT_EPSILON);
XCTAssertEqualWithAccuracy(subview3.frame.origin.x, CGRectGetMaxX(subview2.frame), FLT_EPSILON);
CGFloat totalWidth = 0;
for (UIView *view in container.subviews) {
totalWidth += view.bounds.size.width;
}
XCTAssertEqual(containerSize.width, totalWidth, @"The container's width is %.6f, the subviews take up %.6f", containerSize.width, totalWidth);
}
- (void)testThatLayoutIsCorrectWhenWeSwapViewOrder
{
const CGSize containerSize = CGSizeMake(300, 50);
UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, containerSize.width, containerSize.height)];
container.yoga.isEnabled = YES;
container.yoga.flexDirection = YGFlexDirectionRow;
UIView *subview1 = [[UIView alloc] initWithFrame:CGRectZero];
subview1.yoga.isEnabled = YES;
subview1.yoga.flexGrow = 1;
[container addSubview:subview1];
UIView *subview2 = [[UIView alloc] initWithFrame:CGRectZero];
subview2.yoga.isEnabled = YES;
subview2.yoga.flexGrow = 1;
[container addSubview:subview2];
UIView *subview3 = [[UIView alloc] initWithFrame:CGRectZero];
subview3.yoga.isEnabled = YES;
subview3.yoga.flexGrow = 1;
[container addSubview:subview3];
[container.yoga applyLayoutPreservingOrigin:YES];
XCTAssertTrue(CGRectEqualToRect(subview1.frame, CGRectMake(0, 0, 100, 50)));
XCTAssertTrue(CGRectEqualToRect(subview2.frame, CGRectMake(100, 0, 100, 50)));
XCTAssertTrue(CGRectEqualToRect(subview3.frame, CGRectMake(200, 0, 100, 50)));
[container exchangeSubviewAtIndex:2 withSubviewAtIndex:0];
subview2.yoga.isIncludedInLayout = NO;
[container.yoga applyLayoutPreservingOrigin:YES];
XCTAssertTrue(CGRectEqualToRect(subview3.frame, CGRectMake(0, 0, 150, 50)));
XCTAssertTrue(CGRectEqualToRect(subview1.frame, CGRectMake(150, 0, 150, 50)));
// this frame shouldn't have been modified since last time.
XCTAssertTrue(CGRectEqualToRect(subview2.frame, CGRectMake(100, 0, 100, 50)));
}
- (void)testThatWeRespectIncludeInLayoutFlag
{
const CGSize containerSize = CGSizeMake(300, 50);
UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, containerSize.width, containerSize.height)];
container.yoga.isEnabled = YES;
container.yoga.flexDirection = YGFlexDirectionRow;
UIView *subview1 = [[UIView alloc] initWithFrame:CGRectZero];
subview1.yoga.isEnabled = YES;
subview1.yoga.flexGrow = 1;
[container addSubview:subview1];
UIView *subview2 = [[UIView alloc] initWithFrame:CGRectZero];
subview2.yoga.isEnabled = YES;
subview2.yoga.flexGrow = 1;
[container addSubview:subview2];
UIView *subview3 = [[UIView alloc] initWithFrame:CGRectZero];
subview3.yoga.isEnabled = YES;
subview3.yoga.flexGrow = 1;
[container addSubview:subview3];
[container.yoga applyLayoutPreservingOrigin:YES];
for (UIView *subview in container.subviews) {
XCTAssertEqual(subview.bounds.size.width, 100);
}
subview3.yoga.isIncludedInLayout = NO;
[container.yoga applyLayoutPreservingOrigin:YES];
XCTAssertEqual(subview1.bounds.size.width, 150);
XCTAssertEqual(subview2.bounds.size.width, 150);
// We don't set the frame to zero, so, it should be set to what it was previously at.
XCTAssertEqual(subview3.bounds.size.width, 100);
}
- (void)testThatNumberOfChildrenIsCorrectWhenWeIgnoreSubviews
{
UIView *container = [[UIView alloc] initWithFrame:CGRectZero];
container.yoga.isEnabled = YES;
container.yoga.flexDirection = YGFlexDirectionRow;
UIView *subview1 = [[UIView alloc] initWithFrame:CGRectZero];
subview1.yoga.isEnabled = YES;
subview1.yoga.isIncludedInLayout = NO;
[container addSubview:subview1];
UIView *subview2 = [[UIView alloc] initWithFrame:CGRectZero];
subview2.yoga.isEnabled = YES;
subview2.yoga.isIncludedInLayout = NO;
[container addSubview:subview2];
UIView *subview3 = [[UIView alloc] initWithFrame:CGRectZero];
subview3.yoga.isEnabled = YES;
subview3.yoga.isIncludedInLayout = YES;
[container addSubview:subview3];
[container.yoga applyLayoutPreservingOrigin:YES];
XCTAssertEqual(container.yoga.numberOfChildren, 1);
subview2.yoga.isIncludedInLayout = YES;
[container.yoga applyLayoutPreservingOrigin:YES];
XCTAssertEqual(container.yoga.numberOfChildren, 2);
}
- (void)testThatViewNotIncludedInFirstLayoutPassAreIncludedInSecond
{
UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 50)];
container.yoga.isEnabled = YES;
container.yoga.flexDirection = YGFlexDirectionRow;
UIView *subview1 = [[UIView alloc] initWithFrame:CGRectZero];
subview1.yoga.isEnabled = YES;
subview1.yoga.flexGrow = 1;
[container addSubview:subview1];
UIView *subview2 = [[UIView alloc] initWithFrame:CGRectZero];
subview2.yoga.isEnabled = YES;
subview2.yoga.flexGrow = 1;
[container addSubview:subview2];
UIView *subview3 = [[UIView alloc] initWithFrame:CGRectZero];
subview3.yoga.isEnabled = YES;
subview3.yoga.flexGrow = 1;
subview3.yoga.isIncludedInLayout = NO;
[container addSubview:subview3];
[container.yoga applyLayoutPreservingOrigin:YES];
XCTAssertEqual(subview1.bounds.size.width, 150);
XCTAssertEqual(subview2.bounds.size.width, 150);
XCTAssertEqual(subview3.bounds.size.width, 0);
subview3.yoga.isIncludedInLayout = YES;
[container.yoga applyLayoutPreservingOrigin:YES];
XCTAssertEqual(subview1.bounds.size.width, 100);
XCTAssertEqual(subview2.bounds.size.width, 100);
XCTAssertEqual(subview3.bounds.size.width, 100);
}
- (void)testIsLeafFlag
{
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
XCTAssertTrue(view.yoga.isLeaf);
for (int i=0; i<10; i++) {
UIView *subview = [[UIView alloc] initWithFrame:CGRectZero];
[view addSubview:subview];
}
XCTAssertTrue(view.yoga.isLeaf);
view.yoga.isEnabled = YES;
view.yoga.width = YGPointValue(50);
XCTAssertTrue(view.yoga.isLeaf);
UIView *const subview = view.subviews[0];
subview.yoga.isEnabled = YES;
subview.yoga.width = YGPointValue(50);
XCTAssertFalse(view.yoga.isLeaf);
}
- (void)testThatWeCorrectlyAttachNestedViews
{
UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 50)];
container.yoga.isEnabled = YES;
container.yoga.flexDirection = YGFlexDirectionColumn;
UIView *subview1 = [[UIView alloc] initWithFrame:CGRectZero];
subview1.yoga.isEnabled = YES;
subview1.yoga.width = YGPointValue(100);
subview1.yoga.flexGrow = 1;
subview1.yoga.flexDirection = YGFlexDirectionColumn;
[container addSubview:subview1];
UIView *subview2 = [[UIView alloc] initWithFrame:CGRectZero];
subview2.yoga.isEnabled = YES;
subview2.yoga.width = YGPointValue(150);
subview2.yoga.flexGrow = 1;
subview2.yoga.flexDirection = YGFlexDirectionColumn;
[container addSubview:subview2];
for (UIView *view in @[subview1, subview2]) {
UIView *someView = [[UIView alloc] initWithFrame:CGRectZero];
someView.yoga.isEnabled = YES;
someView.yoga.flexGrow = 1;
[view addSubview:someView];
}
[container.yoga applyLayoutPreservingOrigin:YES];
// Add the same amount of new views, reapply layout.
for (UIView *view in @[subview1, subview2]) {
UIView *someView = [[UIView alloc] initWithFrame:CGRectZero];
someView.yoga.isEnabled = YES;
someView.yoga.flexGrow = 1;
[view addSubview:someView];
}
[container.yoga applyLayoutPreservingOrigin:YES];
XCTAssertEqual(subview1.bounds.size.width, 100);
XCTAssertEqual(subview1.bounds.size.height, 25);
for (UIView *subview in subview1.subviews) {
const CGSize subviewSize = subview.bounds.size;
XCTAssertNotEqual(subviewSize.width, 0);
XCTAssertNotEqual(subviewSize.height, 0);
XCTAssertFalse(isnan(subviewSize.height));
XCTAssertFalse(isnan(subviewSize.width));
}
XCTAssertEqual(subview2.bounds.size.width, 150);
XCTAssertEqual(subview2.bounds.size.height, 25);
for (UIView *subview in subview2.subviews) {
const CGSize subviewSize = subview.bounds.size;
XCTAssertNotEqual(subviewSize.width, 0);
XCTAssertNotEqual(subviewSize.height, 0);
XCTAssertFalse(isnan(subviewSize.height));
XCTAssertFalse(isnan(subviewSize.width));
}
}
- (void)testThatANonLeafNodeCanBecomeALeafNode
{
UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 50)];
container.yoga.isEnabled = YES;
UIView *subview1 = [[UIView alloc] initWithFrame:CGRectZero];
subview1.yoga.isEnabled = YES;
[container addSubview:subview1];
UIView *subview2 = [[UIView alloc] initWithFrame:CGRectZero];
subview2.yoga.isEnabled = YES;
[subview1 addSubview:subview2];
[container.yoga applyLayoutPreservingOrigin:YES];
[subview2 removeFromSuperview];
[container.yoga applyLayoutPreservingOrigin:YES];
}
- (void)testPointPercent
{
XCTAssertEqual(YGPointValue(1).value, 1);
XCTAssertEqual(YGPointValue(1).unit, YGUnitPoint);
XCTAssertEqual(YGPercentValue(2).value, 2);
XCTAssertEqual(YGPercentValue(2).unit, YGUnitPercent);
}
- (void)testPositionalPropertiesWork
{
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
view.yoga.left = YGPointValue(1);
XCTAssertEqual(view.yoga.left.value, 1);
XCTAssertEqual(view.yoga.left.unit, YGUnitPoint);
view.yoga.left = YGPercentValue(2);
XCTAssertEqual(view.yoga.left.value, 2);
XCTAssertEqual(view.yoga.left.unit, YGUnitPercent);
view.yoga.right = YGPointValue(3);
XCTAssertEqual(view.yoga.right.value, 3);
XCTAssertEqual(view.yoga.right.unit, YGUnitPoint);
view.yoga.right = YGPercentValue(4);
XCTAssertEqual(view.yoga.right.value, 4);
XCTAssertEqual(view.yoga.right.unit, YGUnitPercent);
view.yoga.top = YGPointValue(5);
XCTAssertEqual(view.yoga.top.value, 5);
XCTAssertEqual(view.yoga.top.unit, YGUnitPoint);
view.yoga.top = YGPercentValue(6);
XCTAssertEqual(view.yoga.top.value, 6);
XCTAssertEqual(view.yoga.top.unit, YGUnitPercent);
view.yoga.bottom = YGPointValue(7);
XCTAssertEqual(view.yoga.bottom.value, 7);
XCTAssertEqual(view.yoga.bottom.unit, YGUnitPoint);
view.yoga.bottom = YGPercentValue(8);
XCTAssertEqual(view.yoga.bottom.value, 8);
XCTAssertEqual(view.yoga.bottom.unit, YGUnitPercent);
view.yoga.start = YGPointValue(9);
XCTAssertEqual(view.yoga.start.value, 9);
XCTAssertEqual(view.yoga.start.unit, YGUnitPoint);
view.yoga.start = YGPercentValue(10);
XCTAssertEqual(view.yoga.start.value, 10);
XCTAssertEqual(view.yoga.start.unit, YGUnitPercent);
view.yoga.end = YGPointValue(11);
XCTAssertEqual(view.yoga.end.value, 11);
XCTAssertEqual(view.yoga.end.unit, YGUnitPoint);
view.yoga.end = YGPercentValue(12);
XCTAssertEqual(view.yoga.end.value, 12);
XCTAssertEqual(view.yoga.end.unit, YGUnitPercent);
}
- (void)testMarginPropertiesWork
{
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
view.yoga.margin = YGPointValue(1);
XCTAssertEqual(view.yoga.margin.value, 1);
XCTAssertEqual(view.yoga.margin.unit, YGUnitPoint);
view.yoga.margin = YGPercentValue(2);
XCTAssertEqual(view.yoga.margin.value, 2);
XCTAssertEqual(view.yoga.margin.unit, YGUnitPercent);
view.yoga.marginHorizontal = YGPointValue(3);
XCTAssertEqual(view.yoga.marginHorizontal.value, 3);
XCTAssertEqual(view.yoga.marginHorizontal.unit, YGUnitPoint);
view.yoga.marginHorizontal = YGPercentValue(4);
XCTAssertEqual(view.yoga.marginHorizontal.value, 4);
XCTAssertEqual(view.yoga.marginHorizontal.unit, YGUnitPercent);
view.yoga.marginVertical = YGPointValue(5);
XCTAssertEqual(view.yoga.marginVertical.value, 5);
XCTAssertEqual(view.yoga.marginVertical.unit, YGUnitPoint);
view.yoga.marginVertical = YGPercentValue(6);
XCTAssertEqual(view.yoga.marginVertical.value, 6);
XCTAssertEqual(view.yoga.marginVertical.unit, YGUnitPercent);
view.yoga.marginLeft = YGPointValue(7);
XCTAssertEqual(view.yoga.marginLeft.value, 7);
XCTAssertEqual(view.yoga.marginLeft.unit, YGUnitPoint);
view.yoga.marginLeft = YGPercentValue(8);
XCTAssertEqual(view.yoga.marginLeft.value, 8);
XCTAssertEqual(view.yoga.marginLeft.unit, YGUnitPercent);
view.yoga.marginRight = YGPointValue(9);
XCTAssertEqual(view.yoga.marginRight.value, 9);
XCTAssertEqual(view.yoga.marginRight.unit, YGUnitPoint);
view.yoga.marginRight = YGPercentValue(10);
XCTAssertEqual(view.yoga.marginRight.value, 10);
XCTAssertEqual(view.yoga.marginRight.unit, YGUnitPercent);
view.yoga.marginTop = YGPointValue(11);
XCTAssertEqual(view.yoga.marginTop.value, 11);
XCTAssertEqual(view.yoga.marginTop.unit, YGUnitPoint);
view.yoga.marginTop = YGPercentValue(12);
XCTAssertEqual(view.yoga.marginTop.value, 12);
XCTAssertEqual(view.yoga.marginTop.unit, YGUnitPercent);
view.yoga.marginBottom = YGPointValue(13);
XCTAssertEqual(view.yoga.marginBottom.value, 13);
XCTAssertEqual(view.yoga.marginBottom.unit, YGUnitPoint);
view.yoga.marginBottom = YGPercentValue(14);
XCTAssertEqual(view.yoga.marginBottom.value, 14);
XCTAssertEqual(view.yoga.marginBottom.unit, YGUnitPercent);
view.yoga.marginStart = YGPointValue(15);
XCTAssertEqual(view.yoga.marginStart.value, 15);
XCTAssertEqual(view.yoga.marginStart.unit, YGUnitPoint);
view.yoga.marginStart = YGPercentValue(16);
XCTAssertEqual(view.yoga.marginStart.value, 16);
XCTAssertEqual(view.yoga.marginStart.unit, YGUnitPercent);
view.yoga.marginEnd = YGPointValue(17);
XCTAssertEqual(view.yoga.marginEnd.value, 17);
XCTAssertEqual(view.yoga.marginEnd.unit, YGUnitPoint);
view.yoga.marginEnd = YGPercentValue(18);
XCTAssertEqual(view.yoga.marginEnd.value, 18);
XCTAssertEqual(view.yoga.marginEnd.unit, YGUnitPercent);
}
- (void)testPaddingPropertiesWork
{
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
view.yoga.padding = YGPointValue(1);
XCTAssertEqual(view.yoga.padding.value, 1);
XCTAssertEqual(view.yoga.padding.unit, YGUnitPoint);
view.yoga.padding = YGPercentValue(2);
XCTAssertEqual(view.yoga.padding.value, 2);
XCTAssertEqual(view.yoga.padding.unit, YGUnitPercent);
view.yoga.paddingHorizontal = YGPointValue(3);
XCTAssertEqual(view.yoga.paddingHorizontal.value, 3);
XCTAssertEqual(view.yoga.paddingHorizontal.unit, YGUnitPoint);
view.yoga.paddingHorizontal = YGPercentValue(4);
XCTAssertEqual(view.yoga.paddingHorizontal.value, 4);
XCTAssertEqual(view.yoga.paddingHorizontal.unit, YGUnitPercent);
view.yoga.paddingVertical = YGPointValue(5);
XCTAssertEqual(view.yoga.paddingVertical.value, 5);
XCTAssertEqual(view.yoga.paddingVertical.unit, YGUnitPoint);
view.yoga.paddingVertical = YGPercentValue(6);
XCTAssertEqual(view.yoga.paddingVertical.value, 6);
XCTAssertEqual(view.yoga.paddingVertical.unit, YGUnitPercent);
view.yoga.paddingLeft = YGPointValue(7);
XCTAssertEqual(view.yoga.paddingLeft.value, 7);
XCTAssertEqual(view.yoga.paddingLeft.unit, YGUnitPoint);
view.yoga.paddingLeft = YGPercentValue(8);
XCTAssertEqual(view.yoga.paddingLeft.value, 8);
XCTAssertEqual(view.yoga.paddingLeft.unit, YGUnitPercent);
view.yoga.paddingRight = YGPointValue(9);
XCTAssertEqual(view.yoga.paddingRight.value, 9);
XCTAssertEqual(view.yoga.paddingRight.unit, YGUnitPoint);
view.yoga.paddingRight = YGPercentValue(10);
XCTAssertEqual(view.yoga.paddingRight.value, 10);
XCTAssertEqual(view.yoga.paddingRight.unit, YGUnitPercent);
view.yoga.paddingTop = YGPointValue(11);
XCTAssertEqual(view.yoga.paddingTop.value, 11);
XCTAssertEqual(view.yoga.paddingTop.unit, YGUnitPoint);
view.yoga.paddingTop = YGPercentValue(12);
XCTAssertEqual(view.yoga.paddingTop.value, 12);
XCTAssertEqual(view.yoga.paddingTop.unit, YGUnitPercent);
view.yoga.paddingBottom = YGPointValue(13);
XCTAssertEqual(view.yoga.paddingBottom.value, 13);
XCTAssertEqual(view.yoga.paddingBottom.unit, YGUnitPoint);
view.yoga.paddingBottom = YGPercentValue(14);
XCTAssertEqual(view.yoga.paddingBottom.value, 14);
XCTAssertEqual(view.yoga.paddingBottom.unit, YGUnitPercent);
view.yoga.paddingStart = YGPointValue(15);
XCTAssertEqual(view.yoga.paddingStart.value, 15);
XCTAssertEqual(view.yoga.paddingStart.unit, YGUnitPoint);
view.yoga.paddingStart = YGPercentValue(16);
XCTAssertEqual(view.yoga.paddingStart.value, 16);
XCTAssertEqual(view.yoga.paddingStart.unit, YGUnitPercent);
view.yoga.paddingEnd = YGPointValue(17);
XCTAssertEqual(view.yoga.paddingEnd.value, 17);
XCTAssertEqual(view.yoga.paddingEnd.unit, YGUnitPoint);
view.yoga.paddingEnd = YGPercentValue(18);
XCTAssertEqual(view.yoga.paddingEnd.value, 18);
XCTAssertEqual(view.yoga.paddingEnd.unit, YGUnitPercent);
}
- (void)testBorderWidthPropertiesWork
{
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
view.yoga.borderWidth = 1;
XCTAssertEqual(view.yoga.borderWidth, 1);
view.yoga.borderLeftWidth = 2;
XCTAssertEqual(view.yoga.borderLeftWidth, 2);
view.yoga.borderRightWidth = 3;
XCTAssertEqual(view.yoga.borderRightWidth, 3);
view.yoga.borderTopWidth = 4;
XCTAssertEqual(view.yoga.borderTopWidth, 4);
view.yoga.borderBottomWidth = 5;
XCTAssertEqual(view.yoga.borderBottomWidth, 5);
view.yoga.borderStartWidth = 6;
XCTAssertEqual(view.yoga.borderStartWidth, 6);
view.yoga.borderEndWidth = 7;
XCTAssertEqual(view.yoga.borderEndWidth, 7);
}
@end

View File

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

View File

@@ -0,0 +1,26 @@
PODS:
- IGListKit (2.1.0):
- IGListKit/Default (= 2.1.0)
- IGListKit/Default (2.1.0):
- IGListKit/Diffing
- IGListKit/Diffing (2.1.0)
- Yoga (1.7.0)
- YogaKit (1.7.0):
- Yoga (~> 1.7)
DEPENDENCIES:
- IGListKit (~> 2.1.0)
- YogaKit (from `../../YogaKit.podspec`)
EXTERNAL SOURCES:
YogaKit:
:path: ../../YogaKit.podspec
SPEC CHECKSUMS:
IGListKit: b826c68ef7a4ae1626c09d4d3e1ea7a169e6c36e
Yoga: 2ed1d7accfef3610a67f58c0cf101a0662137f2c
YogaKit: 31576530e8fcae3175469719ec3212397403330b
PODFILE CHECKSUM: 216f8e7127767709e0e43f3711208d238fa5c404
COCOAPODS: 1.1.1

View File

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

View File

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

View File

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

View File

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

View File

@@ -0,0 +1,27 @@
/**
* Copyright 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the license found in the
* LICENSE-examples file in the root directory of this source tree.
*/
import Foundation
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func applicationDidFinishLaunching(_ application: UIApplication) {
self.window = UIWindow(frame: UIScreen.main.bounds)
if let window = self.window {
let navigationController = UINavigationController(rootViewController: ExamplesViewController())
navigationController.navigationBar.isTranslucent = false
window.rootViewController = navigationController
window.backgroundColor = .white
window.makeKeyAndVisible()
}
}
}

View File

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 868 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB

View File

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

View File

@@ -0,0 +1,100 @@
/**
* Copyright 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the license found in the
* LICENSE-examples file in the root directory of this source tree.
*/
import UIKit
import IGListKit
private final class ExampleModel {
let title: String
let controllerClass: UIViewController.Type
init(title: String, controllerClass: UIViewController.Type) {
self.title = title
self.controllerClass = controllerClass
}
}
extension ExampleModel: IGListDiffable {
fileprivate func diffIdentifier() -> NSObjectProtocol {
return title as NSString
}
fileprivate func isEqual(toDiffableObject object: IGListDiffable?) -> Bool {
guard let otherObj = object as? ExampleModel else { return false }
return (title == otherObj.title) &&
(controllerClass == otherObj.controllerClass)
}
}
final class ExamplesViewController: UIViewController, IGListAdapterDataSource, IGListSingleSectionControllerDelegate {
private lazy var adapter: IGListAdapter = {
return IGListAdapter(updater: IGListAdapterUpdater(), viewController: self, workingRangeSize: 0)
}()
private let collectionView = IGListCollectionView(frame: .zero, collectionViewLayout: UICollectionViewFlowLayout())
// Update this to array to create more examples.
private let models: [ExampleModel] = [ExampleModel(title: "Basic Layout", controllerClass: BasicViewController.self),
ExampleModel(title: "Exclude Views in Layout", controllerClass: LayoutInclusionViewController.self)]
//MARK: UIViewController
override func viewDidLoad() {
super.viewDidLoad()
title = "Examples"
view.addSubview(collectionView)
adapter.collectionView = collectionView
adapter.dataSource = self
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
collectionView.frame = view.bounds
}
//MARK: IGListAdapterDataSource
func objects(for listAdapter: IGListAdapter) -> [IGListDiffable] {
return models as [IGListDiffable]
}
func listAdapter(_ listAdapter: IGListAdapter, sectionControllerFor object: Any) -> IGListSectionController {
let sizeBlock: IGListSingleSectionCellSizeBlock = { (model, context) in
return CGSize(width: (context?.containerSize.width)!, height: 75.0)
}
let configureBlock: IGListSingleSectionCellConfigureBlock = { (model, cell) in
guard let m = model as? ExampleModel, let c = cell as? SingleLabelCollectionCell else {
return
}
c.label.text = m.title
}
let sectionController = IGListSingleSectionController(cellClass: SingleLabelCollectionCell.self,
configureBlock: configureBlock,
sizeBlock: sizeBlock)
sectionController.selectionDelegate = self
return sectionController
}
func emptyView(for listAdapter: IGListAdapter) -> UIView? { return nil }
//MARK: IGListSingleSectionControllerDelegate
func didSelect(_ sectionController: IGListSingleSectionController) {
let section = adapter.section(for: sectionController)
let model = models[section]
let controller = model.controllerClass.init()
controller.title = model.title
self.navigationController?.pushViewController(controller, animated: true)
}
}

View File

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

View File

@@ -0,0 +1,71 @@
/**
* Copyright 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the license found in the
* LICENSE-examples file in the root directory of this source tree.
*/
import UIKit
import IGListKit
import YogaKit
struct DemoItem {
let name: String
root.backgroundColor = .red
root.yoga.isEnabled = true
root.yoga.width = YGValue(self.view.bounds.size.width)
root.yoga.height = YGValue(self.view.bounds.size.height)
root.yoga.alignItems = .center
}
final class SwiftViewController: UIViewController, IGListAdapterDataSource {
lazy var adapter: IGListAdapter = {
return IGListAdapter(updater: IGListAdapterUpdater(), viewController: self, workingRangeSize: 0)
}()
let collectionView = IGListCollectionView(frame: .zero, collectionViewLayout: UICollectionViewFlowLayout())
//MARK: UIViewController
override func viewDidLoad() {
super.viewDidLoad()
title = "YogaKit Examples"
view.addSubview(collectionView)
adapter.collectionView = collectionView
adapter.dataSource = self
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
collectionView.frame = view.bounds
}
//MARK: IGListAdapterDataSource
func objects(for listAdapter: IGListAdapter) -> [IGListDiffable] {
return ["Dustin" as IGListDiffable, "Ryan" as IGListDiffable]
}
func listAdapter(_ listAdapter: IGListAdapter, sectionControllerFor object: Any) -> IGListSectionController {
let sizeBlock: IGListSingleSectionCellSizeBlock = { (model, context) in
return CGSize(width: (context?.containerSize.width)!, height: 100.0)
}
let configureBlock: IGListSingleSectionCellConfigureBlock = { (model, cell) in
guard let m = model as? String else {
return
}
cell.backgroundColor = (m == "Dustin") ? .blue : .red
}
return IGListSingleSectionController(cellClass: UICollectionViewCell.self,
configureBlock: configureBlock,
sizeBlock: sizeBlock)
}
func emptyView(for listAdapter: IGListAdapter) -> UIView? {
return nil
}
}

View File

@@ -0,0 +1,56 @@
/**
* Copyright 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the license found in the
* LICENSE-examples file in the root directory of this source tree.
*/
#import "ViewController.h"
#import <YogaKit/UIView+Yoga.h>
@implementation ViewController
- (void)viewDidLoad
{
UIView *root = self.view;
root.backgroundColor = [UIColor redColor];
root.yoga.isEnabled = YES;
root.yoga.width = YGPointValue(self.view.bounds.size.width);
root.yoga.height = YGPointValue(self.view.bounds.size.height);
root.yoga.alignItems = YGAlignCenter;
root.yoga.justifyContent = YGJustifyCenter;
UIView *child1 = [UIView new];
child1.backgroundColor = [UIColor blueColor];
child1.yoga.isEnabled = YES;
child1.yoga.width = YGPointValue(100);
child1.yoga.height = YGPointValue(100);
UIView *child2 = [UIView new];
child2.backgroundColor = [UIColor greenColor];
child2.frame = (CGRect) {
.size = {
.width = 200,
.height = 100,
}
};
UIView *child3 = [UIView new];
child3.backgroundColor = [UIColor yellowColor];
child3.frame = (CGRect) {
.size = {
.width = 100,
.height = 100,
}
};
[child2 addSubview:child3];
[root addSubview:child1];
[root addSubview:child2];
[root.yoga applyLayoutPreservingOrigin:NO];
}
@end

View File

@@ -0,0 +1,54 @@
/**
* Copyright 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the license found in the
* LICENSE-examples file in the root directory of this source tree.
*/
import UIKit
import YogaKit
final class BasicViewController: UIViewController {
override func viewDidLoad() {
let containerSize = self.view.bounds.size
let root = self.view!
root.backgroundColor = .white
root.configureLayout { (layout) in
layout.isEnabled = true
layout.width = YGValue(containerSize.width)
layout.height = YGValue(containerSize.height)
layout.alignItems = .center
layout.justifyContent = .center
}
let child1 = UIView()
child1.backgroundColor = .blue
child1.configureLayout { (layout) in
layout.isEnabled = true
layout.width = 100
layout.height = 10
layout.marginBottom = 25
}
root.addSubview(child1)
let child2 = UIView(frame: CGRect(x: 0, y: 0, width: 200, height: 200))
child2.backgroundColor = .green
child2.configureLayout { (layout) in
layout.isEnabled = true
layout.alignSelf = .flexEnd
}
root.addSubview(child2)
let child3 = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
child3.backgroundColor = .yellow
child3.configureLayout { (layout) in
layout.isEnabled = true
layout.alignSelf = .flexStart
}
root.addSubview(child3)
root.yoga.applyLayout(preservingOrigin: true)
}
}

View File

@@ -0,0 +1,80 @@
/**
* Copyright 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the license found in the
* LICENSE-examples file in the root directory of this source tree.
*/
import UIKit
import YogaKit
final class LayoutInclusionViewController: UIViewController {
private let button: UIButton = UIButton(type: .system)
private let disappearingView: UIView = UIView(frame: .zero)
private let contentView: UIView = UIView(frame: .zero)
override func viewDidLoad() {
let root = self.view!
root.backgroundColor = .white
root.configureLayout { (layout) in
layout.isEnabled = true
layout.flexDirection = .column
layout.justifyContent = .spaceAround
}
contentView.backgroundColor = .clear
contentView.layer.borderColor = UIColor.lightGray.cgColor
contentView.layer.borderWidth = 1.0
contentView.configureLayout { (layout) in
layout.isEnabled = true
layout.height = 300
layout.width = YGValue(self.view.bounds.size.width)
layout.flexDirection = .row
layout.justifyContent = .center
layout.paddingHorizontal = 25
}
self.view.addSubview(contentView)
let redView = UIView(frame: .zero)
redView.backgroundColor = .red
redView.configureLayout { (layout) in
layout.isEnabled = true
layout.flexGrow = 1
layout.flexShrink = 1
}
contentView.addSubview(redView)
disappearingView.backgroundColor = .blue
disappearingView.configureLayout { (layout) in
layout.isEnabled = true
layout.flexGrow = 1
}
contentView.addSubview(disappearingView)
button.setTitle("Add Blue View", for: UIControlState.selected)
button.setTitle("Remove Blue View", for: UIControlState.normal)
button.addTarget(self, action: #selector(buttonWasTapped), for: UIControlEvents.touchUpInside)
button.configureLayout { (layout) in
layout.isEnabled = true
layout.height = 300
layout.width = 300
layout.alignSelf = .center
}
root.addSubview(button)
root.yoga.applyLayout(preservingOrigin: false)
}
// MARK - UIButton Action
func buttonWasTapped() {
button.isSelected = !button.isSelected
button.isUserInteractionEnabled = false
disappearingView.yoga.isIncludedInLayout = !disappearingView.yoga.isIncludedInLayout
disappearingView.isHidden = !disappearingView.isHidden
contentView.yoga.applyLayout(preservingOrigin: true)
button.isUserInteractionEnabled = true
}
}

View File

@@ -0,0 +1,49 @@
/**
* Copyright 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the license found in the
* LICENSE-examples file in the root directory of this source tree.
*/
import UIKit
import YogaKit
final class SingleLabelCollectionCell: UICollectionViewCell {
let label: UILabel = UILabel(frame: .zero)
override init(frame: CGRect) {
super.init(frame: frame)
contentView.configureLayout { (layout) in
layout.isEnabled = true
layout.flexDirection = .column
layout.justifyContent = .flexEnd
}
label.textAlignment = .center
label.numberOfLines = 1
label.yoga.isIncludedInLayout = false
contentView.addSubview(label)
let border = UIView(frame: .zero)
border.backgroundColor = .lightGray
border.configureLayout { (layout) in
layout.isEnabled = true
layout.height = 0.5
layout.marginHorizontal = 25
}
contentView.addSubview(border)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func layoutSubviews() {
super.layoutSubviews()
contentView.yoga.applyLayout(preservingOrigin: false)
label.frame = contentView.bounds
}
}

30
android/BUCK Normal file
View File

@@ -0,0 +1,30 @@
# Copyright (c) 2014-present, Facebook, Inc.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
load("//:yoga_defs.bzl", "ANDROID_JAVA_TARGET", "ANDROID_RES_TARGET", "INFER_ANNOTATIONS_TARGET", "JAVA_TARGET", "PROGRUARD_ANNOTATIONS_TARGET", "android_aar", "android_resource")
android_aar(
name = "android",
manifest_skeleton = "src/main/AndroidManifest.xml",
visibility = [
"PUBLIC",
],
deps = [
ANDROID_JAVA_TARGET,
ANDROID_RES_TARGET,
INFER_ANNOTATIONS_TARGET,
JAVA_TARGET,
PROGRUARD_ANNOTATIONS_TARGET,
],
)
android_resource(
name = "res",
package = "com.facebook.yoga.android",
res = "src/main/res",
visibility = [
"PUBLIC",
],
)

21
android/README.md Normal file
View File

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

45
android/build.gradle Normal file
View File

@@ -0,0 +1,45 @@
apply plugin: 'com.jfrog.bintray'
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'maven-publish'
version = VERSION_NAME
group = GROUP
android {
compileSdkVersion rootProject.compileSdkVersion
buildToolsVersion rootProject.buildToolsVersion
defaultConfig {
minSdkVersion rootProject.minSdkVersion
targetSdkVersion rootProject.targetSdkVersion
}
compileOptions {
targetCompatibility rootProject.targetCompatibilityVersion
sourceCompatibility rootProject.sourceCompatibilityVersion
}
}
dependencies {
api project(':yoga')
}
task sourcesJar(type: Jar) {
classifier = 'source'
from android.sourceSets.main.java.srcDirs
}
task javadoc(type: Javadoc) {
failOnError false
source = android.sourceSets.main.java.sourceFiles
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
classpath += configurations.compile
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
apply from: rootProject.file('gradle/release.gradle')

View File

@@ -0,0 +1,5 @@
GROUP=com.facebook.yoga.android
POM_NAME=YogaLayout
POM_DESCRIPTION=YogaLayout
POM_ARTIFACT_ID=yoga-layout
POM_PACKAGING=aar

View File

@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2014-present, Facebook, Inc.
All rights reserved.
This source code is licensed under the license found in the
LICENSE-examples file in the root directory of this source tree.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.facebook.samples.yoga"
android:versionCode="1"
android:versionName="1.0"
>
<variable name="applicationId" value="com.facebook.yoga"/>
<variable name="app_label" value="Yoga Sample App"/>
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="19"
/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:label="@string/app_name"
android:icon="@drawable/ic_launcher"
android:allowBackup="false"
android:theme="@style/NoTitleBarWhiteBG"
android:supportsRtl="true"
>
<activity
android:name=".MainActivity"
android:exported="true"
>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity
android:name=".BenchmarkActivity"
android:exported="false"
/>
</application>
</manifest>

35
android/sample/BUCK Normal file
View File

@@ -0,0 +1,35 @@
# Copyright 2014-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE-examples file in the root directory of this source tree.
load("//:yoga_defs.bzl", "ANDROID_SAMPLE_JAVA_TARGET", "ANDROID_SAMPLE_RES_TARGET", "ANDROID_RES_TARGET", "android_binary", "android_resource")
android_binary(
name = "sample",
keystore = ":debug_keystore",
manifest = "AndroidManifest.xml",
deps = [
ANDROID_SAMPLE_JAVA_TARGET,
ANDROID_SAMPLE_RES_TARGET,
],
)
android_resource(
name = "res",
package = "com.facebook.samples.yoga",
res = "res",
visibility = [
"PUBLIC",
],
deps = [
ANDROID_RES_TARGET,
],
)
keystore(
name = "debug_keystore",
properties = "debug.keystore.properties",
store = "debug.keystore",
)

Binary file not shown.

View File

@@ -0,0 +1,3 @@
key.alias=androiddebugkey
key.store.password=android
key.alias.password=android

View File

@@ -0,0 +1,21 @@
# Copyright (c) 2014-present, Facebook, Inc.
#
# This source code is licensed under the license found in the
# LICENSE-examples file in the root directory of this source tree.
load("//:yoga_defs.bzl", "ANDROID_JAVA_TARGET", "ANDROID_SAMPLE_RES_TARGET", "ANDROID_SUPPORT_TARGET", "APPCOMPAT_TARGET", "SOLOADER_TARGET", "android_library")
android_library(
name = "yoga",
srcs = glob(["**/*.java"]),
visibility = [
"PUBLIC",
],
deps = [
ANDROID_JAVA_TARGET,
ANDROID_SAMPLE_RES_TARGET,
ANDROID_SUPPORT_TARGET,
APPCOMPAT_TARGET,
SOLOADER_TARGET,
],
)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -0,0 +1,54 @@
/**
* Copyright 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the license found in the
* LICENSE-examples file in the root directory of this source tree.
*/
package com.facebook.samples.yoga;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.Menu;
import com.facebook.samples.yoga.R;
import com.facebook.soloader.SoLoader;
import com.facebook.yoga.android.YogaViewLayoutFactory;
/**
* An activity to show off Yoga in Android. This activity shows a simple layout (defined in
* {@code main_layout.xml}) that shows off the awesome functionality of the Yoga layout engine
* as well as some optimisations on layout systems that it facilitates.
*/
public class MainActivity extends AppCompatActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
LayoutInflater.from(this).setFactory(YogaViewLayoutFactory.getInstance());
super.onCreate(savedInstanceState);
SoLoader.init(this, false);
setContentView(R.layout.main_layout);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.action_bar_home, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// There is only one option
Intent intent = new Intent(this, BenchmarkActivity.class);
startActivity(intent);
this.finish();
return true;
}
}

View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--
Copyright 2014-present, Facebook, Inc.
All rights reserved.
This source code is licensed under the license found in the
LICENSE-examples file in the root directory of this source tree.
-->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
>
<solid
android:color="@color/yoga_grey"
/>
</shape>

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

View File

@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--
Copyright 2014-present, Facebook, Inc.
All rights reserved.
This source code is licensed under the license found in the
LICENSE-examples file in the root directory of this source tree.
-->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
>
<corners
android:radius="4dp"
/>
<stroke
android:width="1dp"
android:color="@color/children_stroke"
/>
<padding
android:top="6dp"
android:bottom="6dp"
android:left="8dp"
android:right="8dp"
/>
<solid
android:color="@color/children_background"
/>
</shape>

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -0,0 +1,137 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--
Copyright 2014-present, Facebook, Inc.
All rights reserved.
This source code is licensed under the license found in the
LICENSE-examples file in the root directory of this source tree.
-->
<YogaLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yoga="http://schemas.android.com/apk/res/com.facebook.samples.yoga"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<YogaLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/sample_children_background"
yoga:yg_marginHorizontal="10dp"
yoga:yg_marginTop="5dp"
yoga:yg_flexDirection="row"
yoga:yg_alignItems="center"
>
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:src="@drawable/ic_launcher"
yoga:yg_flex="0"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/child_1_text"
android:textColor="@color/children_text"
yoga:yg_flex="1"
yoga:yg_marginStart="8dp"
/>
</YogaLayout>
<YogaLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/sample_children_background"
yoga:yg_marginHorizontal="10dp"
yoga:yg_marginTop="5dp"
yoga:yg_flexDirection="row"
yoga:yg_alignItems="center"
>
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:src="@drawable/ic_launcher"
yoga:yg_flex="0"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/child_2_text"
android:textColor="@color/children_text"
yoga:yg_flex="1"
yoga:yg_marginStart="8dp"
/>
</YogaLayout>
<YogaLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/sample_children_background"
yoga:yg_marginHorizontal="10dp"
yoga:yg_marginTop="5dp"
yoga:yg_flexDirection="row"
yoga:yg_alignItems="center"
>
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:src="@drawable/ic_launcher"
yoga:yg_flex="0"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/child_3_text"
android:textColor="@color/children_text"
yoga:yg_flex="1"
yoga:yg_marginStart="8dp"
/>
</YogaLayout>
<YogaLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/sample_children_background"
yoga:yg_marginHorizontal="10dp"
yoga:yg_marginTop="5dp"
yoga:yg_flexDirection="row"
yoga:yg_alignItems="center"
>
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:src="@drawable/ic_launcher"
yoga:yg_flex="0"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/child_4_text"
android:textColor="@color/children_text"
yoga:yg_flex="1"
yoga:yg_marginStart="8dp"
/>
</YogaLayout>
<YogaLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/sample_children_background"
yoga:yg_marginHorizontal="10dp"
yoga:yg_marginTop="5dp"
yoga:yg_flexDirection="row"
yoga:yg_alignItems="center"
>
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:src="@drawable/ic_launcher"
yoga:yg_flex="0"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/child_5_text"
android:textColor="@color/children_text"
yoga:yg_flex="1"
yoga:yg_marginStart="10dp"
/>
</YogaLayout>
</YogaLayout>

View File

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

View File

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

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2014-present, Facebook, Inc.
All rights reserved.
This source code is licensed under the license found in the
LICENSE-examples file in the root directory of this source tree.
-->
<resources>
<color name="yoga_grey">#FF303846</color>
<color name="yoga_blue">#FF97DCCF</color>
<color name="children_background">#FFFFFFFF</color>
<color name="children_stroke">#665890ff</color>
<color name="children_text">#FF23355b</color>
</resources>

View File

@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2014-present, Facebook, Inc.
All rights reserved.
This source code is licensed under the license found in the
LICENSE-examples file in the root directory of this source tree.
-->
<resources>
<string name="app_name">Yoga</string>
<string
name="child_1_text"
description="Placeholder text for the first element in the layout"
>Hello. I am Yoga!</string>
<string
name="child_2_text"
description="Placeholder text for the second element in the layout"
>I am a layout engine!</string>
<string
name="child_3_text"
description="Placeholder text for the third element in the layout"
>I run natively.</string>
<string
name="child_4_text"
description="Placeholder text for the fourth element in the layout"
>So I\'m fast.</string>
<string
name="child_5_text"
description="Placeholder text for the fifth element in the layout"
>Who are you?</string>
</resources>

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2014-present, Facebook, Inc.
All rights reserved.
This source code is licensed under the license found in the
LICENSE-examples file in the root directory of this source tree.
-->
<resources>
<style name="NoTitleBarWhiteBG" parent="Theme.AppCompat.Light">
<item name="android:actionBarStyle">@style/MyActionBar</item>
<item name="android:textDirection">locale</item>
</style>
<style name="MyActionBar" parent="Widget.AppCompat.Light.ActionBar">
<item name="android:titleTextStyle">@style/MyTitleText</item>
<item name="android:background">@drawable/action_bar_background</item>
</style>
<style name="MyTitleText" parent="TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">@color/yoga_blue</item>
</style>
</resources>

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (c) 2014-present, Facebook, Inc.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.facebook.yoga.android"
android:versionCode="1"
android:versionName="1.0"
>
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="21"
/>
<application/>
</manifest>

View File

@@ -0,0 +1,21 @@
# Copyright (c) 2014-present, Facebook, Inc.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
load("//:yoga_defs.bzl", "ANDROID_RES_TARGET", "INFER_ANNOTATIONS_TARGET", "JAVA_TARGET", "JSR_305_TARGET", "SOLOADER_TARGET", "android_library")
android_library(
name = "android",
srcs = glob(["**/*.java"]),
visibility = [
"PUBLIC",
],
deps = [
ANDROID_RES_TARGET,
INFER_ANNOTATIONS_TARGET,
JAVA_TARGET,
JSR_305_TARGET,
SOLOADER_TARGET,
],
)

View File

@@ -0,0 +1,148 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
package com.facebook.yoga.android;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import com.facebook.yoga.YogaNode;
/**
* Much like a {@link YogaLayout}, except this class does not render itself (the container) to the
* screen. As a result, <i>do not use this if you wish the container to have a background or
* foreground</i>. However, all of its children will still render as expected.
*
* <p>
* In practice, this class never added to the View tree, and all its children become children of its
* parent. As a result, all the layout (such as the traversal of the tree) is performed by Yoga
* (and so natively) increasing performance.
*/
public class VirtualYogaLayout extends ViewGroup {
final private List<View> mChildren = new LinkedList<>();
final private Map<View, YogaNode> mYogaNodes = new HashMap<>();
final private YogaNode mYogaNode = new YogaNode();
public VirtualYogaLayout(Context context) {
super(context);
}
public VirtualYogaLayout(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public VirtualYogaLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
YogaLayout.LayoutParams lp = new YogaLayout.LayoutParams(context, attrs);
YogaLayout.applyLayoutParams(lp, mYogaNode, this);
}
public YogaNode getYogaNode() {
return mYogaNode;
}
/**
* Called to add a view, creating a new yoga node for it and adding that yoga node to the parent.
* If the child is a {@link VirtualYogaLayout}, we simply transfer all its children to this one
* in a manner that maintains the tree, and add its root to the tree.
*
* @param child the View to add
* @param index the position at which to add it (ignored)
* @param params the layout parameters to apply
*/
@Override
public void addView(View child, int index, ViewGroup.LayoutParams params) {
if (child instanceof VirtualYogaLayout) {
((VirtualYogaLayout) child).transferChildren(this);
final YogaNode childNode = ((VirtualYogaLayout) child).getYogaNode();
mYogaNode.addChildAt(childNode, mYogaNode.getChildCount());
return;
}
YogaNode node = new YogaNode();
YogaLayout.LayoutParams lp = new YogaLayout.LayoutParams(params);
YogaLayout.applyLayoutParams(lp, node, child);
node.setData(child);
node.setMeasureFunction(new YogaLayout.ViewMeasureFunction());
mYogaNode.addChildAt(node, mYogaNode.getChildCount());
addView(child, node);
}
/**
* Called to add a view with a corresponding node, but not to change the Yoga tree in any way.
*
* @param child the View to add
* @param node the corresponding yoga node
*/
public void addView(View child, YogaNode node) {
mChildren.add(child);
mYogaNodes.put(child, node);
}
/**
* Gives up children {@code View}s to the parent, maintaining the Yoga tree. This function calls
* {@link YogaLayout#addView(View, YogaNode)} or {@link VirtualYogaLayout#addView(View, YogaNode)}
* on the parent to add the {@code View} without generating new yoga nodes.
*
* @param parent the parent to pass children to (must be a YogaLayout or a VirtualYogaLayout)
*/
protected void transferChildren(ViewGroup parent) {
if (parent instanceof VirtualYogaLayout) {
for (View child : mChildren) {
((VirtualYogaLayout) parent).addView(child, mYogaNodes.get(child));
}
} else if (parent instanceof YogaLayout) {
for (View child : mChildren) {
((YogaLayout) parent).addView(child, mYogaNodes.get(child));
}
} else {
throw new RuntimeException("VirtualYogaLayout cannot transfer children to ViewGroup of type "
+parent.getClass().getCanonicalName()+". Must either be a VirtualYogaLayout or a " +
"YogaLayout.");
}
mChildren.clear();
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
throw new RuntimeException("Attempting to layout a VirtualYogaLayout");
}
@Override
public ViewGroup.LayoutParams generateLayoutParams(AttributeSet attrs) {
return new YogaLayout.LayoutParams(getContext(), attrs);
}
@Override
protected ViewGroup.LayoutParams generateDefaultLayoutParams() {
return new YogaLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT);
}
@Override
protected ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams p) {
return new YogaLayout.LayoutParams(p);
}
@Override
protected boolean checkLayoutParams(ViewGroup.LayoutParams p) {
return p instanceof YogaLayout.LayoutParams;
}
}

View File

@@ -0,0 +1,815 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
package com.facebook.yoga.android;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.TypedArray;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.util.AttributeSet;
import android.util.SparseArray;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
import com.facebook.yoga.YogaAlign;
import com.facebook.yoga.YogaConstants;
import com.facebook.yoga.YogaDirection;
import com.facebook.yoga.YogaDisplay;
import com.facebook.yoga.YogaEdge;
import com.facebook.yoga.YogaFlexDirection;
import com.facebook.yoga.YogaJustify;
import com.facebook.yoga.YogaMeasureFunction;
import com.facebook.yoga.YogaMeasureMode;
import com.facebook.yoga.YogaMeasureOutput;
import com.facebook.yoga.YogaNode;
import com.facebook.yoga.YogaOverflow;
import com.facebook.yoga.YogaPositionType;
import com.facebook.yoga.YogaWrap;
import java.util.HashMap;
import java.util.Map;
/**
* A {@code ViewGroup} based on the Yoga layout engine.
*
* <p>
* This class is designed to be as "plug and play" as possible. That is, you can use it in XML
* like this (note: to use {@code YogaLayout} you need to use the {@link YogaViewLayoutFactory}):
* <p>
* <pre>{@code
* <YogaLayout
* xmlns:android="http://schemas.android.com/apk/res/android"
* xmlns:yoga="http://schemas.android.com/apk/com.facebook.yoga.android"
* android:layout_width="match_owner"
* android:layout_height="match_owner"
* yoga:flex_direction="row"
* yoga:padding_all="10dp"
* >
* <TextView
* android:layout_width="match_owner"
* android:layout_height="match_owner"
* android:text="Hello, World!"
* yoga:flex="1"
* />
* </YogaLayout>
* }</pre>
*
* Under the hood, all views added to this {@code ViewGroup} are laid out using flexbox rules
* and the Yoga engine.
*/
public class YogaLayout extends ViewGroup {
private final Map<View, YogaNode> mYogaNodes;
private final YogaNode mYogaNode;
public YogaLayout(Context context) {
this(context, null, 0);
}
public YogaLayout(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public YogaLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
mYogaNode = new YogaNode();
mYogaNodes = new HashMap<>();
mYogaNode.setData(this);
mYogaNode.setMeasureFunction(new ViewMeasureFunction());
LayoutParams layoutParams = null;
if (attrs != null) {
layoutParams = new LayoutParams(context, attrs);
} else {
layoutParams = (LayoutParams) generateDefaultLayoutParams();
}
applyLayoutParams(layoutParams, mYogaNode, this);
}
public YogaNode getYogaNode() {
return mYogaNode;
}
public YogaNode getYogaNodeForView(View view) {
return mYogaNodes.get(view);
}
/**
* Adds a child view with the specified layout parameters.
*
* In the typical View is added, this constructs a {@code YogaNode} for this child and applies all
* the {@code yoga:*} attributes. The Yoga node is added to the Yoga tree and the child is added
* to this ViewGroup.
*
* If the child is a {@link YogaLayout} itself, we do not construct a new Yoga node for that
* child, but use its root node instead.
*
* If the child is a {@link VirtualYogaLayout}, we also use its Yoga node, but we also instruct it
* to transfer all of its children to this {@link YogaLayout} while preserving the Yoga tree (so
* that the layout of its children is correct). The {@link VirtualYogaLayout} is then not added
* to the View hierarchy.
*
* <p><strong>Note:</strong> do not invoke this method from
* {@code #draw(android.graphics.Canvas)}, {@code onDraw(android.graphics.Canvas)},
* {@code #dispatchDraw(android.graphics.Canvas)} or any related method.</p>
*
* @param child the child view to add
* @param index the position at which to add the child or -1 to add last
* @param params the layout parameters to set on the child
*/
@Override
public void addView(View child, int index, ViewGroup.LayoutParams params) {
// Internal nodes (which this is now) cannot have measure functions
mYogaNode.setMeasureFunction(null);
if (child instanceof VirtualYogaLayout) {
((VirtualYogaLayout) child).transferChildren(this);
final YogaNode childNode = ((VirtualYogaLayout) child).getYogaNode();
mYogaNode.addChildAt(childNode, mYogaNode.getChildCount());
return;
}
super.addView(child, index, params);
// It is possible that addView is being called as part of a transferal of children, in which
// case we already know about the YogaNode and only need the Android View tree to be aware
// that we now own this child. If so, we don't need to do anything further
if (mYogaNodes.containsKey(child)) {
return;
}
YogaNode childNode;
if (child instanceof YogaLayout) {
childNode = ((YogaLayout) child).getYogaNode();
} else {
if(mYogaNodes.containsKey(child)) {
childNode = mYogaNodes.get(child);
} else {
childNode = new YogaNode();
}
childNode.setData(child);
childNode.setMeasureFunction(new ViewMeasureFunction());
}
final LayoutParams lp = (LayoutParams) child.getLayoutParams();
applyLayoutParams(lp, childNode, child);
mYogaNodes.put(child, childNode);
mYogaNode.addChildAt(childNode, mYogaNode.getChildCount());
}
/**
* Adds a view to this {@code ViewGroup} with an already given {@code YogaNode}. Use
* this function if you already have a Yoga node (and perhaps tree) associated with the view you
* are adding, that you would like to preserve.
*
* @param child The view to add
* @param node The Yoga node belonging to the view
*/
public void addView(View child, YogaNode node) {
mYogaNodes.put(child, node);
addView(child);
}
@Override
public void removeView(View view) {
removeViewFromYogaTree(view, false);
super.removeView(view);
}
@Override
public void removeViewAt(int index) {
removeViewFromYogaTree(getChildAt(index), false);
super.removeViewAt(index);
}
@Override
public void removeViewInLayout(View view) {
removeViewFromYogaTree(view, true);
super.removeViewInLayout(view);
}
@Override
public void removeViews(int start, int count) {
for (int i = start; i < start + count; i++) {
removeViewFromYogaTree(getChildAt(i), false);
}
super.removeViews(start, count);
}
@Override
public void removeViewsInLayout(int start, int count) {
for (int i = start; i < start + count; i++) {
removeViewFromYogaTree(getChildAt(i), true);
}
super.removeViewsInLayout(start, count);
}
@Override
public void removeAllViews() {
final int childCount = getChildCount();
for (int i = 0; i < childCount; i++) {
removeViewFromYogaTree(getChildAt(i), false);
}
super.removeAllViews();
}
@Override
public void removeAllViewsInLayout() {
final int childCount = getChildCount();
for (int i = 0; i < childCount; i++) {
removeViewFromYogaTree(getChildAt(i), true);
}
super.removeAllViewsInLayout();
}
/**
* Marks a particular view as "dirty" and to be relaid out. If the view is not a child of this
* {@link YogaLayout}, the entire tree is traversed to find it.
*
* @param view the view to mark as dirty
*/
public void invalidate(View view) {
if (mYogaNodes.containsKey(view)) {
mYogaNodes.get(view).dirty();
return;
}
final int childCount = mYogaNode.getChildCount();
for (int i = 0; i < childCount; i++) {
final YogaNode yogaNode = mYogaNode.getChildAt(i);
if (yogaNode.getData() instanceof YogaLayout) {
((YogaLayout) yogaNode.getData()).invalidate(view);
}
}
invalidate();
}
private void removeViewFromYogaTree(View view, boolean inLayout) {
final YogaNode node = mYogaNodes.get(view);
if (node == null) {
return;
}
final YogaNode owner = node.getOwner();
for (int i = 0; i < owner.getChildCount(); i++) {
if (owner.getChildAt(i).equals(node)) {
owner.removeChildAt(i);
break;
}
}
node.setData(null);
mYogaNodes.remove(view);
if (inLayout) {
mYogaNode.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
}
}
private void applyLayoutRecursive(YogaNode node, float xOffset, float yOffset) {
View view = (View) node.getData();
if (view != null && view != this) {
if (view.getVisibility() == GONE) {
return;
}
int left = Math.round(xOffset + node.getLayoutX());
int top = Math.round(yOffset + node.getLayoutY());
view.measure(
View.MeasureSpec.makeMeasureSpec(
Math.round(node.getLayoutWidth()),
View.MeasureSpec.EXACTLY),
View.MeasureSpec.makeMeasureSpec(
Math.round(node.getLayoutHeight()),
View.MeasureSpec.EXACTLY));
view.layout(left, top, left + view.getMeasuredWidth(), top + view.getMeasuredHeight());
}
final int childrenCount = node.getChildCount();
for (int i = 0; i < childrenCount; i++) {
if (this.equals(view)) {
applyLayoutRecursive(node.getChildAt(i), xOffset, yOffset);
} else if (view instanceof YogaLayout) {
continue;
} else {
applyLayoutRecursive(
node.getChildAt(i),
xOffset + node.getLayoutX(),
yOffset + node.getLayoutY());
}
}
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
// Either we are a root of a tree, or this function is called by our owner's onLayout, in which
// case our r-l and b-t are the size of our node.
if (!(getParent() instanceof YogaLayout)) {
createLayout(
MeasureSpec.makeMeasureSpec(r - l, MeasureSpec.EXACTLY),
MeasureSpec.makeMeasureSpec(b - t, MeasureSpec.EXACTLY));
}
applyLayoutRecursive(mYogaNode, 0, 0);
}
/**
* This function is mostly unneeded, because Yoga is doing the measuring. Hence we only need to
* return accurate results if we are the root.
*
* @param widthMeasureSpec the suggested specification for the width
* @param heightMeasureSpec the suggested specification for the height
*/
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
if (!(getParent() instanceof YogaLayout)) {
createLayout(widthMeasureSpec, heightMeasureSpec);
}
setMeasuredDimension(
Math.round(mYogaNode.getLayoutWidth()),
Math.round(mYogaNode.getLayoutHeight()));
}
private void createLayout(int widthMeasureSpec, int heightMeasureSpec) {
final int widthSize = MeasureSpec.getSize(widthMeasureSpec);
final int heightSize = MeasureSpec.getSize(heightMeasureSpec);
final int widthMode = MeasureSpec.getMode(widthMeasureSpec);
final int heightMode = MeasureSpec.getMode(heightMeasureSpec);
if (heightMode == MeasureSpec.EXACTLY) {
mYogaNode.setHeight(heightSize);
}
if (widthMode == MeasureSpec.EXACTLY) {
mYogaNode.setWidth(widthSize);
}
if (heightMode == MeasureSpec.AT_MOST) {
mYogaNode.setMaxHeight(heightSize);
}
if (widthMode == MeasureSpec.AT_MOST) {
mYogaNode.setMaxWidth(widthSize);
}
mYogaNode.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
}
/**
* Applies the layout parameters to the YogaNode. That is, this function is a translator from
* {@code yoga:X="Y"} to {@code yogaNode.setX(Y);}, with some reasonable defaults.
*
* <p>
* If the SDK version is high enough, and the {@code yoga:direction} is not set on
* the component, the direction (LTR or RTL) is set according to the locale.
*
* <p>
* The attributes {@code padding_top}, {@code padding_right} etc. default to those of the view's
* drawable background, if it has one.
*
* @param layoutParameters The source set of params
* @param node The destination node
*/
protected static void applyLayoutParams(LayoutParams layoutParameters, YogaNode node, View view) {
// JELLY_BEAN_MR1 (17) is the first version supporting getLayoutDirection()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
Configuration configuration = view.getResources().getConfiguration();
if (configuration.getLayoutDirection() == LAYOUT_DIRECTION_RTL) {
node.setDirection(YogaDirection.RTL);
}
}
Drawable background = view.getBackground();
if (background != null) {
final Rect backgroundPadding = new Rect();
if (background.getPadding(backgroundPadding)) {
node.setPadding(YogaEdge.LEFT, backgroundPadding.left);
node.setPadding(YogaEdge.TOP, backgroundPadding.top);
node.setPadding(YogaEdge.RIGHT, backgroundPadding.right);
node.setPadding(YogaEdge.BOTTOM, backgroundPadding.bottom);
}
}
for (int i = 0; i < layoutParameters.numericAttributes.size(); i++) {
final int attribute = layoutParameters.numericAttributes.keyAt(i);
final float value = layoutParameters.numericAttributes.valueAt(i);
if (attribute == R.styleable.yoga_yg_alignContent) {
node.setAlignContent(YogaAlign.fromInt(Math.round(value)));
} else if (attribute == R.styleable.yoga_yg_alignItems) {
node.setAlignItems(YogaAlign.fromInt(Math.round(value)));
} else if (attribute == R.styleable.yoga_yg_alignSelf) {
node.setAlignSelf(YogaAlign.fromInt(Math.round(value)));
} else if (attribute == R.styleable.yoga_yg_aspectRatio) {
node.setAspectRatio(value);
} else if (attribute == R.styleable.yoga_yg_borderLeft) {
node.setBorder(YogaEdge.LEFT, value);
} else if (attribute == R.styleable.yoga_yg_borderTop) {
node.setBorder(YogaEdge.TOP, value);
} else if (attribute == R.styleable.yoga_yg_borderRight) {
node.setBorder(YogaEdge.RIGHT, value);
} else if (attribute == R.styleable.yoga_yg_borderBottom) {
node.setBorder(YogaEdge.BOTTOM, value);
} else if (attribute == R.styleable.yoga_yg_borderStart) {
node.setBorder(YogaEdge.START, value);
} else if (attribute == R.styleable.yoga_yg_borderEnd) {
node.setBorder(YogaEdge.END, value);
} else if (attribute == R.styleable.yoga_yg_borderHorizontal) {
node.setBorder(YogaEdge.HORIZONTAL, value);
} else if (attribute == R.styleable.yoga_yg_borderVertical) {
node.setBorder(YogaEdge.VERTICAL, value);
} else if (attribute == R.styleable.yoga_yg_borderAll) {
node.setBorder(YogaEdge.ALL, value);
} else if (attribute == R.styleable.yoga_yg_direction) {
node.setDirection(YogaDirection.fromInt(Math.round(value)));
} else if (attribute == R.styleable.yoga_yg_display) {
node.setDisplay(YogaDisplay.fromInt(Math.round(value)));
} else if (attribute == R.styleable.yoga_yg_flex) {
node.setFlex(value);
} else if (attribute == R.styleable.yoga_yg_flexBasis) {
node.setFlexBasis(value);
} else if (attribute == R.styleable.yoga_yg_flexDirection) {
node.setFlexDirection(YogaFlexDirection.fromInt(Math.round(value)));
} else if (attribute == R.styleable.yoga_yg_flexGrow) {
node.setFlexGrow(value);
} else if (attribute == R.styleable.yoga_yg_flexShrink) {
node.setFlexShrink(value);
} else if (attribute == R.styleable.yoga_yg_height) {
node.setHeight(value);
} else if (attribute == R.styleable.yoga_yg_marginLeft) {
node.setMargin(YogaEdge.LEFT, value);
} else if (attribute == R.styleable.yoga_yg_justifyContent) {
node.setJustifyContent(YogaJustify.fromInt(Math.round(value)));
} else if (attribute == R.styleable.yoga_yg_marginTop) {
node.setMargin(YogaEdge.TOP, value);
} else if (attribute == R.styleable.yoga_yg_marginRight) {
node.setMargin(YogaEdge.RIGHT, value);
} else if (attribute == R.styleable.yoga_yg_marginBottom) {
node.setMargin(YogaEdge.BOTTOM, value);
} else if (attribute == R.styleable.yoga_yg_marginStart) {
node.setMargin(YogaEdge.START, value);
} else if (attribute == R.styleable.yoga_yg_marginEnd) {
node.setMargin(YogaEdge.END, value);
} else if (attribute == R.styleable.yoga_yg_marginHorizontal) {
node.setMargin(YogaEdge.HORIZONTAL, value);
} else if (attribute == R.styleable.yoga_yg_marginVertical) {
node.setMargin(YogaEdge.VERTICAL, value);
} else if (attribute == R.styleable.yoga_yg_marginAll) {
node.setMargin(YogaEdge.ALL, value);
} else if (attribute == R.styleable.yoga_yg_maxHeight) {
node.setMaxHeight(value);
} else if (attribute == R.styleable.yoga_yg_maxWidth) {
node.setMaxWidth(value);
} else if (attribute == R.styleable.yoga_yg_minHeight) {
node.setMinHeight(value);
} else if (attribute == R.styleable.yoga_yg_minWidth) {
node.setMinWidth(value);
} else if (attribute == R.styleable.yoga_yg_overflow) {
node.setOverflow(YogaOverflow.fromInt(Math.round(value)));
} else if (attribute == R.styleable.yoga_yg_paddingLeft) {
node.setPadding(YogaEdge.LEFT, value);
} else if (attribute == R.styleable.yoga_yg_paddingTop) {
node.setPadding(YogaEdge.TOP, value);
} else if (attribute == R.styleable.yoga_yg_paddingRight) {
node.setPadding(YogaEdge.RIGHT, value);
} else if (attribute == R.styleable.yoga_yg_paddingBottom) {
node.setPadding(YogaEdge.BOTTOM, value);
} else if (attribute == R.styleable.yoga_yg_paddingStart) {
node.setPadding(YogaEdge.START, value);
} else if (attribute == R.styleable.yoga_yg_paddingEnd) {
node.setPadding(YogaEdge.END, value);
} else if (attribute == R.styleable.yoga_yg_paddingHorizontal) {
node.setPadding(YogaEdge.HORIZONTAL, value);
} else if (attribute == R.styleable.yoga_yg_paddingVertical) {
node.setPadding(YogaEdge.VERTICAL, value);
} else if (attribute == R.styleable.yoga_yg_paddingAll) {
node.setPadding(YogaEdge.ALL, value);
} else if (attribute == R.styleable.yoga_yg_positionLeft) {
node.setPosition(YogaEdge.LEFT, value);
} else if (attribute == R.styleable.yoga_yg_positionTop) {
node.setPosition(YogaEdge.TOP, value);
} else if (attribute == R.styleable.yoga_yg_positionRight) {
node.setPosition(YogaEdge.RIGHT, value);
} else if (attribute == R.styleable.yoga_yg_positionBottom) {
node.setPosition(YogaEdge.BOTTOM, value);
} else if (attribute == R.styleable.yoga_yg_positionStart) {
node.setPosition(YogaEdge.START, value);
} else if (attribute == R.styleable.yoga_yg_positionEnd) {
node.setPosition(YogaEdge.END, value);
} else if (attribute == R.styleable.yoga_yg_positionHorizontal) {
node.setPosition(YogaEdge.HORIZONTAL, value);
} else if (attribute == R.styleable.yoga_yg_positionVertical) {
node.setPosition(YogaEdge.VERTICAL, value);
} else if (attribute == R.styleable.yoga_yg_positionAll) {
node.setPosition(YogaEdge.ALL, value);
} else if (attribute == R.styleable.yoga_yg_positionType) {
node.setPositionType(YogaPositionType.fromInt(Math.round(value)));
} else if (attribute == R.styleable.yoga_yg_width) {
node.setWidth(value);
} else if (attribute == R.styleable.yoga_yg_wrap) {
node.setWrap(YogaWrap.fromInt(Math.round(value)));
}
}
for (int i = 0; i < layoutParameters.stringAttributes.size(); i++) {
final int attribute = layoutParameters.stringAttributes.keyAt(i);
final String value = layoutParameters.stringAttributes.valueAt(i);
if (value.equals("auto")) {
if (attribute == R.styleable.yoga_yg_marginLeft) {
node.setMarginAuto(YogaEdge.LEFT);
} else if (attribute == R.styleable.yoga_yg_marginTop) {
node.setMarginAuto(YogaEdge.TOP);
} else if (attribute == R.styleable.yoga_yg_marginRight) {
node.setMarginAuto(YogaEdge.RIGHT);
} else if (attribute == R.styleable.yoga_yg_marginBottom) {
node.setMarginAuto(YogaEdge.BOTTOM);
} else if (attribute == R.styleable.yoga_yg_marginStart) {
node.setMarginAuto(YogaEdge.START);
} else if (attribute == R.styleable.yoga_yg_marginEnd) {
node.setMarginAuto(YogaEdge.END);
} else if (attribute == R.styleable.yoga_yg_marginHorizontal) {
node.setMarginAuto(YogaEdge.HORIZONTAL);
} else if (attribute == R.styleable.yoga_yg_marginVertical) {
node.setMarginAuto(YogaEdge.VERTICAL);
} else if (attribute == R.styleable.yoga_yg_marginAll) {
node.setMarginAuto(YogaEdge.ALL);
}
}
if (value.endsWith("%")) {
final float numericValue = Float.parseFloat(value.substring(0, value.length()-1));
if (attribute == R.styleable.yoga_yg_flexBasis) {
node.setFlexBasisPercent(numericValue);
} else if (attribute == R.styleable.yoga_yg_height) {
node.setHeightPercent(numericValue);
} else if (attribute == R.styleable.yoga_yg_marginLeft) {
node.setMarginPercent(YogaEdge.LEFT, numericValue);
} else if (attribute == R.styleable.yoga_yg_marginTop) {
node.setMarginPercent(YogaEdge.TOP, numericValue);
} else if (attribute == R.styleable.yoga_yg_marginRight) {
node.setMarginPercent(YogaEdge.RIGHT, numericValue);
} else if (attribute == R.styleable.yoga_yg_marginBottom) {
node.setMarginPercent(YogaEdge.BOTTOM, numericValue);
} else if (attribute == R.styleable.yoga_yg_marginStart) {
node.setMarginPercent(YogaEdge.START, numericValue);
} else if (attribute == R.styleable.yoga_yg_marginEnd) {
node.setMarginPercent(YogaEdge.END, numericValue);
} else if (attribute == R.styleable.yoga_yg_marginHorizontal) {
node.setMarginPercent(YogaEdge.HORIZONTAL, numericValue);
} else if (attribute == R.styleable.yoga_yg_marginVertical) {
node.setMarginPercent(YogaEdge.VERTICAL, numericValue);
} else if (attribute == R.styleable.yoga_yg_marginAll) {
node.setMarginPercent(YogaEdge.ALL, numericValue);
} else if (attribute == R.styleable.yoga_yg_maxHeight) {
node.setMaxHeightPercent(numericValue);
} else if (attribute == R.styleable.yoga_yg_maxWidth) {
node.setMaxWidthPercent(numericValue);
} else if (attribute == R.styleable.yoga_yg_minHeight) {
node.setMinHeightPercent(numericValue);
} else if (attribute == R.styleable.yoga_yg_minWidth) {
node.setMinWidthPercent(numericValue);
} else if (attribute == R.styleable.yoga_yg_paddingLeft) {
node.setPaddingPercent(YogaEdge.LEFT, numericValue);
} else if (attribute == R.styleable.yoga_yg_paddingTop) {
node.setPaddingPercent(YogaEdge.TOP, numericValue);
} else if (attribute == R.styleable.yoga_yg_paddingRight) {
node.setPaddingPercent(YogaEdge.RIGHT, numericValue);
} else if (attribute == R.styleable.yoga_yg_paddingBottom) {
node.setPaddingPercent(YogaEdge.BOTTOM, numericValue);
} else if (attribute == R.styleable.yoga_yg_paddingStart) {
node.setPaddingPercent(YogaEdge.START, numericValue);
} else if (attribute == R.styleable.yoga_yg_paddingEnd) {
node.setPaddingPercent(YogaEdge.END, numericValue);
} else if (attribute == R.styleable.yoga_yg_paddingHorizontal) {
node.setPaddingPercent(YogaEdge.HORIZONTAL, numericValue);
} else if (attribute == R.styleable.yoga_yg_paddingVertical) {
node.setPaddingPercent(YogaEdge.VERTICAL, numericValue);
} else if (attribute == R.styleable.yoga_yg_paddingAll) {
node.setPaddingPercent(YogaEdge.ALL, numericValue);
} else if (attribute == R.styleable.yoga_yg_positionLeft) {
node.setPositionPercent(YogaEdge.LEFT, numericValue);
} else if (attribute == R.styleable.yoga_yg_positionTop) {
node.setPositionPercent(YogaEdge.TOP, numericValue);
} else if (attribute == R.styleable.yoga_yg_positionRight) {
node.setPositionPercent(YogaEdge.RIGHT, numericValue);
} else if (attribute == R.styleable.yoga_yg_positionBottom) {
node.setPositionPercent(YogaEdge.BOTTOM, numericValue);
} else if (attribute == R.styleable.yoga_yg_positionStart) {
node.setPositionPercent(YogaEdge.START, numericValue);
} else if (attribute == R.styleable.yoga_yg_positionEnd) {
node.setPositionPercent(YogaEdge.END, numericValue);
} else if (attribute == R.styleable.yoga_yg_positionHorizontal) {
node.setPositionPercent(YogaEdge.HORIZONTAL, numericValue);
} else if (attribute == R.styleable.yoga_yg_positionVertical) {
node.setPositionPercent(YogaEdge.VERTICAL, numericValue);
} else if (attribute == R.styleable.yoga_yg_positionAll) {
node.setPositionPercent(YogaEdge.ALL, numericValue);
} else if (attribute == R.styleable.yoga_yg_width) {
node.setWidthPercent(numericValue);
}
}
}
}
@Override
public ViewGroup.LayoutParams generateLayoutParams(AttributeSet attrs) {
return new YogaLayout.LayoutParams(getContext(), attrs);
}
@Override
protected ViewGroup.LayoutParams generateDefaultLayoutParams() {
return new YogaLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT);
}
@Override
protected ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams p) {
return new YogaLayout.LayoutParams(p);
}
@Override
protected boolean checkLayoutParams(ViewGroup.LayoutParams p) {
return p instanceof LayoutParams;
}
/**
* {@code YogaLayout.LayoutParams} are used by views to tell {@link YogaLayout} how they want to
* be laid out. More precisely, the specify the yoga parameters of the view.
*
* <p>
* This is actually mostly a wrapper around a {@code SparseArray} that holds a mapping between
* styleable id's ({@code R.styleable.yoga_yg_*}) and the float of their values. In cases where
* the value is an enum or an integer, they should first be cast to int (with rounding) before
* using.
*/
public static class LayoutParams extends ViewGroup.LayoutParams {
/**
* A mapping from attribute keys ({@code R.styleable.yoga_yg_*}) to the float of their values.
* For attributes like position_percent_left (float), this is the native type. For attributes
* like align_self (enums), the integer enum value is cast (rounding is used on the other side
* to prevent precision errors). Dimension attributes are stored as float pixels.
*/
SparseArray<Float> numericAttributes;
/**
* A mapping from attribute keys ({@code R.styleable.yoga_yg_*}) with string values to those
* strings. This is used for values such as "auto".
*/
SparseArray<String> stringAttributes;
/**
* Constructs a set of layout params from a source set. In the case that the source set is
* actually a {@link YogaLayout.LayoutParams}, we can copy all the yoga attributes. Otherwise
* we start with a blank slate.
*
* @param source The layout params to copy from
*/
public LayoutParams(ViewGroup.LayoutParams source) {
super(source);
if (source instanceof LayoutParams) {
numericAttributes = ((LayoutParams) source).numericAttributes.clone();
stringAttributes = ((LayoutParams) source).stringAttributes.clone();
} else {
numericAttributes = new SparseArray<>();
stringAttributes = new SparseArray<>();
// Negative values include MATCH_PARENT and WRAP_CONTENT
if (source.width >= 0) {
numericAttributes.put(R.styleable.yoga_yg_width, (float) width);
}
if (source.height >= 0) {
numericAttributes.put(R.styleable.yoga_yg_height, (float) height);
}
}
}
/**
* Constructs a set of layout params, given width and height specs. In this case, we can set
* the {@code yoga:width} and {@code yoga:height} if we are given them explicitly. If other
* options (such as {@code match_owner} or {@code wrap_content} are given, then the owner
* LayoutParams will store them, and we deal with them during layout. (see
* {@link YogaLayout#createLayout})
*
* @param width the requested width, either a pixel size, {@code WRAP_CONTENT} or
* {@code MATCH_PARENT}.
* @param height the requested height, either a pixel size, {@code WRAP_CONTENT} or
* {@code MATCH_PARENT}.
*/
public LayoutParams(int width, int height) {
super(width, height);
numericAttributes = new SparseArray<>();
stringAttributes = new SparseArray<>();
// Negative values include MATCH_PARENT and WRAP_CONTENT
if (width >= 0) {
numericAttributes.put(R.styleable.yoga_yg_width, (float) width);
}
if (height >= 0) {
numericAttributes.put(R.styleable.yoga_yg_height, (float) height);
}
}
/**
* Constructs a set of layout params, given attributes. Grabs all the {@code yoga:*}
* defined in {@code ALL_YOGA_ATTRIBUTES} and collects the ones that are set in {@code attrs}.
*
* @param context the application environment
* @param attrs the set of attributes from which to extract the yoga specific attributes
*/
public LayoutParams(Context context, AttributeSet attrs) {
super(context, attrs);
numericAttributes = new SparseArray<>();
stringAttributes = new SparseArray<>();
final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.yoga);
// Negative values include MATCH_PARENT and WRAP_CONTENT
if (width >= 0) {
numericAttributes.put(R.styleable.yoga_yg_width, (float) width);
}
if (height >= 0) {
numericAttributes.put(R.styleable.yoga_yg_height, (float) height);
}
final int attributeCount = a.getIndexCount();
for (int i = 0; i < attributeCount; i++) {
final int attribute = a.getIndex(i);
final TypedValue val = new TypedValue();
a.getValue(attribute, val);
if (val.type == TypedValue.TYPE_DIMENSION) {
numericAttributes.put(
attribute,
(float) a.getDimensionPixelSize(attribute, 0));
} else if (val.type == TypedValue.TYPE_STRING) {
stringAttributes.put(attribute, a.getString(attribute));
} else {
numericAttributes.put(attribute, a.getFloat(attribute, 0));
}
}
a.recycle();
}
}
/**
* Wrapper around measure function for yoga leaves.
*/
public static class ViewMeasureFunction implements YogaMeasureFunction {
/**
* A function to measure leaves of the Yoga tree. Yoga needs some way to know how large
* elements want to be. This function passes that question directly through to the relevant
* {@code View}'s measure function.
*
* @param node The yoga node to measure
* @param width The suggested width from the owner
* @param widthMode The type of suggestion for the width
* @param height The suggested height from the owner
* @param heightMode The type of suggestion for the height
* @return A measurement output ({@code YogaMeasureOutput}) for the node
*/
public long measure(
YogaNode node,
float width,
YogaMeasureMode widthMode,
float height,
YogaMeasureMode heightMode) {
final View view = (View) node.getData();
if (view == null || view instanceof YogaLayout) {
return YogaMeasureOutput.make(0, 0);
}
final int widthMeasureSpec = MeasureSpec.makeMeasureSpec(
(int) width,
viewMeasureSpecFromYogaMeasureMode(widthMode));
final int heightMeasureSpec = MeasureSpec.makeMeasureSpec(
(int) height,
viewMeasureSpecFromYogaMeasureMode(heightMode));
view.measure(widthMeasureSpec, heightMeasureSpec);
return YogaMeasureOutput.make(view.getMeasuredWidth(), view.getMeasuredHeight());
}
private int viewMeasureSpecFromYogaMeasureMode(YogaMeasureMode mode) {
if (mode == YogaMeasureMode.AT_MOST) {
return MeasureSpec.AT_MOST;
} else if (mode == YogaMeasureMode.EXACTLY) {
return MeasureSpec.EXACTLY;
} else {
return MeasureSpec.UNSPECIFIED;
}
}
}
}

View File

@@ -0,0 +1,57 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
package com.facebook.yoga.android;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
/**
* A layout inflater factory. This provides our custom {@link YogaViewLayoutFactory#onCreateView}
* to the XML inflation system, allowing us to replace XML tags.
*/
public class YogaViewLayoutFactory implements LayoutInflater.Factory {
private static YogaViewLayoutFactory sYogaViewLayoutFactory;
/**
* Obtains (and initialises if necessary) the singleton {@link YogaViewLayoutFactory}.
*
* @return The singleton instance
*/
public static YogaViewLayoutFactory getInstance() {
if (sYogaViewLayoutFactory == null) {
sYogaViewLayoutFactory = new YogaViewLayoutFactory();
}
return sYogaViewLayoutFactory;
}
YogaViewLayoutFactory() {}
/**
* Hook for inflating from a LayoutInflater. This hook replaces the cumbersome
* {@code com.facebook.etc.YogaLayout} with simply {@code YogaLayout} in your XML and the same
* with {@code VirtualYogaLayout}.
*
* @param name Tag name to be inflated.
* @param context The context the view is being created in.
* @param attrs Inflation attributes as specified in XML file.
*
* @return View Newly created view. Return null for the default behavior.
*/
@Override
public View onCreateView(String name, Context context, AttributeSet attrs) {
if (YogaLayout.class.getSimpleName().equals(name)) {
return new YogaLayout(context, attrs);
}
if (VirtualYogaLayout.class.getSimpleName().equals(name)) {
return new VirtualYogaLayout(context, attrs);
}
return null;
}
}

View File

@@ -0,0 +1,144 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--
Copyright (c) 2014-present, Facebook, Inc.
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
-->
<resources>
<declare-styleable name="yoga">
<attr name="yg_alignContent" format="enum">
<enum name="auto" value="0"/>
<enum name="flex_start" value="1"/>
<enum name="center" value="2"/>
<enum name="flex_end" value="3"/>
<enum name="stretch" value="4"/>
<enum name="baseline" value="5"/>
</attr>
<attr name="yg_alignItems" format="enum">
<enum name="auto" value="0"/>
<enum name="flex_start" value="1"/>
<enum name="center" value="2"/>
<enum name="flex_end" value="3"/>
<enum name="stretch" value="4"/>
<enum name="baseline" value="5"/>
</attr>
<attr name="yg_alignSelf" format="enum">
<enum name="auto" value="0"/>
<enum name="flex_start" value="1"/>
<enum name="center" value="2"/>
<enum name="flex_end" value="3"/>
<enum name="stretch" value="4"/>
<enum name="baseline" value="5"/>
</attr>
<attr name="yg_aspectRatio" format="float"/>
<attr name="yg_borderLeft" format="dimension"/>
<attr name="yg_borderTop" format="dimension"/>
<attr name="yg_borderRight" format="dimension"/>
<attr name="yg_borderBottom" format="dimension"/>
<attr name="yg_borderStart" format="dimension"/>
<attr name="yg_borderEnd" format="dimension"/>
<attr name="yg_borderHorizontal" format="dimension"/>
<attr name="yg_borderVertical" format="dimension"/>
<attr name="yg_borderAll" format="dimension"/>
<attr name="yg_direction" format="enum">
<enum name="inherit" value="0"/>
<enum name="ltr" value="1"/>
<enum name="rtl" value="2"/>
</attr>
<attr name="yg_display" format="enum">
<enum name="flex" value="0"/>
<enum name="none" value="1"/>
</attr>
<attr name="yg_flex" format="float"/>
<attr name="yg_flexBasis" format="float|string"/>
<attr name="yg_flexDirection" format="enum">
<enum name="column" value="0"/>
<enum name="column_reverse" value="1"/>
<enum name="row" value="2"/>
<enum name="row_reverse" value="3"/>
</attr>
<attr name="yg_flexGrow" format="float"/>
<attr name="yg_flexShrink" format="float"/>
<attr name="yg_height" format="dimension|string"/>
<attr name="yg_justifyContent" format="enum">
<enum name="flex_start" value="0"/>
<enum name="center" value="1"/>
<enum name="flex_end" value="2"/>
<enum name="space_between" value="3"/>
<enum name="space_around" value="4"/>
</attr>
<attr name="yg_marginLeft" format="dimension|string"/>
<attr name="yg_marginTop" format="dimension|string"/>
<attr name="yg_marginRight" format="dimension|string"/>
<attr name="yg_marginBottom" format="dimension|string"/>
<attr name="yg_marginStart" format="dimension|string"/>
<attr name="yg_marginEnd" format="dimension|string"/>
<attr name="yg_marginHorizontal" format="dimension|string"/>
<attr name="yg_marginVertical" format="dimension|string"/>
<attr name="yg_marginAll" format="dimension|string"/>
<attr name="yg_maxHeight" format="dimension|string"/>
<attr name="yg_maxWidth" format="dimension|string"/>
<attr name="yg_minHeight" format="dimension|string"/>
<attr name="yg_minWidth" format="dimension|string"/>
<attr name="yg_overflow" format="enum">
<enum name="visible" value="0"/>
<enum name="hidden" value="1"/>
<enum name="scroll" value="2"/>
</attr>
<attr name="yg_paddingLeft" format="dimension|string"/>
<attr name="yg_paddingTop" format="dimension|string"/>
<attr name="yg_paddingRight" format="dimension|string"/>
<attr name="yg_paddingBottom" format="dimension|string"/>
<attr name="yg_paddingStart" format="dimension|string"/>
<attr name="yg_paddingEnd" format="dimension|string"/>
<attr name="yg_paddingHorizontal" format="dimension|string"/>
<attr name="yg_paddingVertical" format="dimension|string"/>
<attr name="yg_paddingAll" format="dimension|string"/>
<attr name="yg_positionLeft" format="dimension|string"/>
<attr name="yg_positionTop" format="dimension|string"/>
<attr name="yg_positionRight" format="dimension|string"/>
<attr name="yg_positionBottom" format="dimension|string"/>
<attr name="yg_positionStart" format="dimension|string"/>
<attr name="yg_positionEnd" format="dimension|string"/>
<attr name="yg_positionHorizontal" format="dimension|string"/>
<attr name="yg_positionVertical" format="dimension|string"/>
<attr name="yg_positionAll" format="dimension|string"/>
<attr name="yg_positionType" format="enum">
<enum name="relative" value="0"/>
<enum name="absolute" value="1"/>
</attr>
<attr name="yg_width" format="dimension|string"/>
<attr name="yg_wrap" format="enum">
<enum name="no_wrap" value="0"/>
<enum name="wrap" value="1"/>
</attr>
</declare-styleable>
</resources>

25
benchmark/BUCK Normal file
View File

@@ -0,0 +1,25 @@
# Copyright (c) 2014-present, Facebook, Inc.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
load("//:yoga_defs.bzl", "yoga_dep")
cxx_binary(
name = "benchmark",
srcs = glob(["*.c"]),
headers = subdir_glob([("", "*.h")]),
header_namespace = "",
compiler_flags = [
"-fno-omit-frame-pointer",
"-fexceptions",
"-Wall",
"-Werror",
"-O3",
"-std=c11",
],
visibility = ["PUBLIC"],
deps = [
yoga_dep(":yoga"),
],
)

116
benchmark/YGBenchmark.c Normal file
View File

@@ -0,0 +1,116 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include "YGBenchmark.h"
#include <yoga/Yoga.h>
static YGSize _measure(YGNodeRef node,
float width,
YGMeasureMode widthMode,
float height,
YGMeasureMode heightMode) {
return (YGSize){
.width = widthMode == YGMeasureModeUndefined ? 10 : width,
.height = heightMode == YGMeasureModeUndefined ? 10 : width,
};
}
YGBENCHMARKS({
YGBENCHMARK("Stack with flex", {
const YGNodeRef root = YGNodeNew();
YGNodeStyleSetWidth(root, 100);
YGNodeStyleSetHeight(root, 100);
for (uint32_t i = 0; i < 10; i++) {
const YGNodeRef child = YGNodeNew();
YGNodeSetMeasureFunc(child, _measure);
YGNodeStyleSetFlex(child, 1);
YGNodeInsertChild(root, child, 0);
}
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
YGNodeFreeRecursive(root);
});
YGBENCHMARK("Align stretch in undefined axis", {
const YGNodeRef root = YGNodeNew();
for (uint32_t i = 0; i < 10; i++) {
const YGNodeRef child = YGNodeNew();
YGNodeStyleSetHeight(child, 20);
YGNodeSetMeasureFunc(child, _measure);
YGNodeInsertChild(root, child, 0);
}
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
YGNodeFreeRecursive(root);
});
YGBENCHMARK("Nested flex", {
const YGNodeRef root = YGNodeNew();
for (uint32_t i = 0; i < 10; i++) {
const YGNodeRef child = YGNodeNew();
YGNodeStyleSetFlex(child, 1);
YGNodeInsertChild(root, child, 0);
for (uint32_t ii = 0; ii < 10; ii++) {
const YGNodeRef grandChild = YGNodeNew();
YGNodeSetMeasureFunc(grandChild, _measure);
YGNodeStyleSetFlex(grandChild, 1);
YGNodeInsertChild(child, grandChild, 0);
}
}
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
YGNodeFreeRecursive(root);
});
YGBENCHMARK("Huge nested layout", {
const YGNodeRef root = YGNodeNew();
for (uint32_t i = 0; i < 10; i++) {
const YGNodeRef child = YGNodeNew();
YGNodeStyleSetFlexGrow(child, 1);
YGNodeStyleSetWidth(child, 10);
YGNodeStyleSetHeight(child, 10);
YGNodeInsertChild(root, child, 0);
for (uint32_t ii = 0; ii < 10; ii++) {
const YGNodeRef grandChild = YGNodeNew();
YGNodeStyleSetFlexDirection(grandChild, YGFlexDirectionRow);
YGNodeStyleSetFlexGrow(grandChild, 1);
YGNodeStyleSetWidth(grandChild, 10);
YGNodeStyleSetHeight(grandChild, 10);
YGNodeInsertChild(child, grandChild, 0);
for (uint32_t iii = 0; iii < 10; iii++) {
const YGNodeRef grandGrandChild = YGNodeNew();
YGNodeStyleSetFlexGrow(grandGrandChild, 1);
YGNodeStyleSetWidth(grandGrandChild, 10);
YGNodeStyleSetHeight(grandGrandChild, 10);
YGNodeInsertChild(grandChild, grandGrandChild, 0);
for (uint32_t iii = 0; iii < 10; iii++) {
const YGNodeRef grandGrandGrandChild = YGNodeNew();
YGNodeStyleSetFlexDirection(grandGrandGrandChild, YGFlexDirectionRow);
YGNodeStyleSetFlexGrow(grandGrandGrandChild, 1);
YGNodeStyleSetWidth(grandGrandGrandChild, 10);
YGNodeStyleSetHeight(grandGrandGrandChild, 10);
YGNodeInsertChild(grandGrandChild, grandGrandGrandChild, 0);
}
}
}
}
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
YGNodeFreeRecursive(root);
});
});

71
benchmark/YGBenchmark.h Normal file
View File

@@ -0,0 +1,71 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#pragma once
#include <math.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define NUM_REPETITIONS 1000
#define YGBENCHMARKS(BLOCK) \
int main(int argc, char const *argv[]) { \
clock_t __start; \
clock_t __endTimes[NUM_REPETITIONS]; \
{ BLOCK } \
return 0; \
}
#define YGBENCHMARK(NAME, BLOCK) \
__start = clock(); \
for (uint32_t __i = 0; __i < NUM_REPETITIONS; __i++) { \
{ BLOCK } \
__endTimes[__i] = clock(); \
} \
__printBenchmarkResult(NAME, __start, __endTimes);
int __compareDoubles(const void *a, const void *b) {
double arg1 = *(const double *) a;
double arg2 = *(const double *) b;
if (arg1 < arg2) {
return -1;
}
if (arg1 > arg2) {
return 1;
}
return 0;
}
void __printBenchmarkResult(char *name, clock_t start, clock_t *endTimes) {
double timesInMs[NUM_REPETITIONS];
double mean = 0;
clock_t lastEnd = start;
for (uint32_t i = 0; i < NUM_REPETITIONS; i++) {
timesInMs[i] = (endTimes[i] - lastEnd) / (double) CLOCKS_PER_SEC * 1000;
lastEnd = endTimes[i];
mean += timesInMs[i];
}
mean /= NUM_REPETITIONS;
qsort(timesInMs, NUM_REPETITIONS, sizeof(double), __compareDoubles);
double median = timesInMs[NUM_REPETITIONS / 2];
double variance = 0;
for (uint32_t i = 0; i < NUM_REPETITIONS; i++) {
variance += pow(timesInMs[i] - mean, 2);
}
variance /= NUM_REPETITIONS;
double stddev = sqrt(variance);
printf("%s: median: %lf ms, stddev: %lf ms\n", name, median, stddev);
}

62
build.gradle Normal file
View File

@@ -0,0 +1,62 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
maven { url 'https://maven.google.com/' }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
ext {
minSdkVersion = 14
targetSdkVersion = 25
compileSdkVersion = 26
buildToolsVersion = '26.0.2'
sourceCompatibilityVersion = JavaVersion.VERSION_1_7
targetCompatibilityVersion = JavaVersion.VERSION_1_7
}
// If you have an idea on how to avoid this, please get in touch or
// answer https://stackoverflow.com/questions/43867014/how-to-use-the-gradle-ndk-build-to-compile-for-the-host-machine.
task copyNativeLibs(type: Copy, dependsOn: ':buckBuildNative') {
from "${rootDir}/buck-out/gen/java/tests#default,shared-library-symlink-tree/"
include '*.so'
include '*.dylib'
into "$buildDir/jniLibs"
}
task buckBuildNative(type: Exec) {
workingDir rootDir
environment BUCKVERSION: 'last'
commandLine 'buck', 'build', '//java/...'
}
allprojects {
afterEvaluate {
tasks.withType(Test) {
dependsOn copyNativeLibs
def libDir = "${rootDir}/build/jniLibs"
systemProperty 'java.library.path', libDir
environment 'LD_LIBRARY_PATH', libDir
environment 'DYLD_LIBRARY_PATH', libDir
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

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