Compare commits

..

30 Commits
1.4.0 ... 1.4.1

Author SHA1 Message Date
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
116 changed files with 2233 additions and 805 deletions

View File

@@ -1,7 +1,7 @@
[cxx]
gtest_dep = //lib/gtest:gtest
[android]
target = Google Inc.:Google APIs:19
target = android-23
[ndk]
ndk_version = 13.1.3345770
compiler = clang

2
.gitignore vendored
View File

@@ -63,3 +63,5 @@ Carthage/Build
# Gradle
.gradle
# NDK/CMake
.externalNativeBuild

17
CMakeLists.txt Normal file
View File

@@ -0,0 +1,17 @@
#
# Copyright (c) 2014-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree. An additional grant
# of patent rights can be found in the PATENTS file in the same directory.
#
cmake_minimum_required(VERSION 3.4.1)
set(CMAKE_VERBOSE_MAKEFILE on)
file(GLOB yogacore_SRC yoga/*.c)
add_library(yogacore STATIC ${yogacore_SRC})
target_link_libraries(yogacore android log)

View File

@@ -10,6 +10,11 @@
#import <UIKit/UIKit.h>
#import <yoga/YGEnums.h>
typedef NS_OPTIONS(NSInteger, YGDimensionFlexibility) {
YGDimensionFlexibilityFlexibleWidth = 1 << 0,
YGDimensionFlexibilityFlexibleHeigth = 1 << 1,
};
@interface YGLayout : NSObject
/**
@@ -95,6 +100,13 @@
- (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)];

View File

@@ -235,6 +235,20 @@ YG_PROPERTY(CGFloat, aspectRatio, AspectRatio)
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 & YGDimensionFlexibilityFlexibleHeigth) {
size.height = YGUndefined;
}
[self calculateLayoutWithSize:size];
YGApplyLayoutToViewHierarchy(self.view, NO);
}
- (CGSize)intrinsicSize
{
const CGSize constrainedSize = {

View File

@@ -21,7 +21,8 @@
- (void)testConfigureLayoutIsNoOpWithNilBlock
{
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
XCTAssertNoThrow([view configureLayoutWithBlock:nil]);
id block = nil;
XCTAssertNoThrow([view configureLayoutWithBlock:block]);
}
- (void)testConfigureLayoutBlockWorksWithValidBlock
@@ -153,6 +154,54 @@
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 = 100;
view.yoga.height = 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 = 100;
view.yoga.height = 100;
[container addSubview:view];
[container.yoga applyLayoutPreservingOrigin:YES dimensionFlexibility:YGDimensionFlexibilityFlexibleHeigth];
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 = 100;
view.yoga.height = 100;
[container addSubview:view];
[container.yoga applyLayoutPreservingOrigin:YES dimensionFlexibility:YGDimensionFlexibilityFlexibleWidth | YGDimensionFlexibilityFlexibleHeigth];
XCTAssertEqual(100, container.frame.size.width);
XCTAssertEqual(100, container.frame.size.height);
}
- (void)testMarkingDirtyOnlyWorksOnLeafNodes
{
UIView *container = [[UIView alloc] initWithFrame:CGRectZero];

View File

@@ -30,7 +30,3 @@ android_resource(
"PUBLIC",
],
)
project_config(
src_target = ":android",
)

View File

@@ -1,31 +1,28 @@
apply plugin: "com.jfrog.bintray"
apply plugin: 'com.jfrog.bintray'
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'maven-publish'
targetCompatibility = '1.7'
sourceCompatibility = '1.7'
version = '1.3.0'
version = '1.4.1'
group = 'com.facebook.yoga.android'
android {
compileSdkVersion 19
buildToolsVersion "19.1.0"
compileSdkVersion rootProject.compileSdkVersion
buildToolsVersion rootProject.buildToolsVersion
defaultConfig {
minSdkVersion 15
targetSdkVersion 19
minSdkVersion rootProject.minSdkVersion
targetSdkVersion rootProject.targetSdkVersion
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
targetCompatibility rootProject.targetCompatibilityVersion
sourceCompatibility rootProject.sourceCompatibilityVersion
}
}
dependencies {
compile 'com.facebook.yoga:yoga:1.2.0'
compile project(':yoga')
}
task sourcesJar(type: Jar) {
@@ -46,7 +43,7 @@ task javadocJar(type: Jar, dependsOn: javadoc) {
}
ext {
bintrayName = "com.facebook.yoga.android:yoga-layout"
bintrayName = 'com.facebook.yoga.android:yoga-layout'
}
apply from: rootProject.file('gradle/android-jcenter-install.gradle')

View File

@@ -33,7 +33,3 @@ keystore(
properties = "debug.keystore.properties",
store = "debug.keystore",
)
project_config(
src_target = ":sample",
)

View File

@@ -37,7 +37,7 @@ import com.facebook.yoga.YogaMeasureFunction;
import com.facebook.yoga.YogaMeasureMode;
import com.facebook.yoga.YogaMeasureOutput;
import com.facebook.yoga.YogaNode;
import com.facebook.yoga.YogaNodeAPI;
import com.facebook.yoga.YogaNode;
import com.facebook.yoga.YogaOverflow;
import com.facebook.yoga.YogaPositionType;
import com.facebook.yoga.YogaWrap;
@@ -789,7 +789,7 @@ public class YogaLayout extends ViewGroup {
* @return A measurement output ({@code YogaMeasureOutput}) for the node
*/
public long measure(
YogaNodeAPI node,
YogaNode node,
float width,
YogaMeasureMode widthMode,
float height,

View File

@@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.2'
classpath 'com.android.tools.build:gradle:2.3.1'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
classpath 'com.nabilhachicha:android-native-dependencies:0.1'
@@ -18,15 +18,18 @@ buildscript {
allprojects {
repositories {
jcenter()
flatDir {
dirs "${rootDir}/lib/jsr-305"
dirs "${rootDir}/lib/soloader"
dirs "${rootDir}/lib/appcompat"
dirs "${rootDir}/lib/android-support"
}
}
}
ext {
minSdkVersion = 15
targetSdkVersion = 25
compileSdkVersion = 25
buildToolsVersion = '25.0.2'
sourceCompatibilityVersion = JavaVersion.VERSION_1_7
targetCompatibilityVersion = JavaVersion.VERSION_1_7
}
task clean(type: Delete) {
delete rootProject.buildDir
}

View File

@@ -26,8 +26,8 @@ namespace Facebook.Yoga
{
public partial class YogaNode : IEnumerable<YogaNode>
{
private Native.YGNodeHandle _ygNode;
private YogaConfig _config;
private readonly Native.YGNodeHandle _ygNode;
private readonly YogaConfig _config;
private WeakReference _parent;
private List<YogaNode> _children;
private MeasureFunction _measureFunction;
@@ -447,7 +447,7 @@ namespace Facebook.Yoga
}
}
public float StyleAspectRatio
public float AspectRatio
{
get
{
@@ -576,6 +576,20 @@ namespace Facebook.Yoga
Native.YGNodeRemoveChild(_ygNode, child._ygNode);
}
public void AddChild(YogaNode child)
{
Insert(Count, child);
}
public void RemoveChild(YogaNode child)
{
int index = IndexOf(child);
if (index >= 0)
{
RemoveAt(index);
}
}
public void Clear()
{
if (_children != null)

View File

@@ -9,6 +9,7 @@
namespace Facebook.Yoga
{
[System.Flags]
public enum YogaPrintOptions
{
Layout = 1,

View File

@@ -243,6 +243,7 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="..\..\yoga\Yoga.h" />
<ClInclude Include="..\..\yoga\YGEnums.c" />
<ClInclude Include="..\..\yoga\YGMacros.h" />
<ClInclude Include="..\..\yoga\YGNodeList.h" />
<ClInclude Include="resource.h" />
@@ -252,6 +253,7 @@
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\yoga\Yoga.c" />
<ClCompile Include="..\..\yoga\YGEnums.c" />
<ClCompile Include="..\..\yoga\YGNodeList.c" />
<ClCompile Include="YGInterop.cpp" />
<ClCompile Include="dllmain.cpp">

View File

@@ -228,6 +228,7 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="..\..\yoga\Yoga.h" />
<ClInclude Include="..\..\yoga\YGEnums.h" />
<ClInclude Include="..\..\yoga\YGMacros.h" />
<ClInclude Include="..\..\yoga\YGNodeList.h" />
<ClInclude Include="resource.h" />
@@ -237,6 +238,7 @@
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\yoga\Yoga.c" />
<ClCompile Include="..\..\yoga\YGEnums.c" />
<ClCompile Include="..\..\yoga\YGNodeList.c" />
<ClCompile Include="YGInterop.cpp" />
<ClCompile Include="dllmain.cpp">

View File

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

View File

@@ -684,17 +684,17 @@ namespace Facebook.Yoga
Assert.AreEqual(0f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(100f, root_child0.LayoutWidth);
Assert.AreEqual(64f, root_child0.LayoutHeight);
Assert.AreEqual(65f, root_child0.LayoutHeight);
Assert.AreEqual(0f, root_child1.LayoutX);
Assert.AreEqual(64f, root_child1.LayoutY);
Assert.AreEqual(100f, root_child1.LayoutWidth);
Assert.AreEqual(25f, root_child1.LayoutHeight);
Assert.AreEqual(24f, root_child1.LayoutHeight);
Assert.AreEqual(0f, root_child2.LayoutX);
Assert.AreEqual(89f, root_child2.LayoutY);
Assert.AreEqual(100f, root_child2.LayoutWidth);
Assert.AreEqual(24f, root_child2.LayoutHeight);
Assert.AreEqual(25f, root_child2.LayoutHeight);
root.StyleDirection = YogaDirection.RTL;
root.CalculateLayout();
@@ -707,17 +707,17 @@ namespace Facebook.Yoga
Assert.AreEqual(0f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(100f, root_child0.LayoutWidth);
Assert.AreEqual(64f, root_child0.LayoutHeight);
Assert.AreEqual(65f, root_child0.LayoutHeight);
Assert.AreEqual(0f, root_child1.LayoutX);
Assert.AreEqual(64f, root_child1.LayoutY);
Assert.AreEqual(100f, root_child1.LayoutWidth);
Assert.AreEqual(25f, root_child1.LayoutHeight);
Assert.AreEqual(24f, root_child1.LayoutHeight);
Assert.AreEqual(0f, root_child2.LayoutX);
Assert.AreEqual(89f, root_child2.LayoutY);
Assert.AreEqual(100f, root_child2.LayoutWidth);
Assert.AreEqual(24f, root_child2.LayoutHeight);
Assert.AreEqual(25f, root_child2.LayoutHeight);
}
[Test]
@@ -793,5 +793,308 @@ namespace Facebook.Yoga
Assert.AreEqual(24f, root_child2.LayoutHeight);
}
[Test]
public void Test_rounding_inner_node_controversy_horizontal()
{
YogaConfig config = new YogaConfig();
config.SetExperimentalFeatureEnabled(YogaExperimentalFeature.Rounding, true);
YogaNode root = new YogaNode(config);
root.FlexDirection = YogaFlexDirection.Row;
root.Width = 320;
YogaNode root_child0 = new YogaNode(config);
root_child0.FlexGrow = 1;
root_child0.Height = 10;
root.Insert(0, root_child0);
YogaNode root_child1 = new YogaNode(config);
root_child1.FlexGrow = 1;
root_child1.Height = 10;
root.Insert(1, root_child1);
YogaNode root_child1_child0 = new YogaNode(config);
root_child1_child0.FlexGrow = 1;
root_child1_child0.Height = 10;
root_child1.Insert(0, root_child1_child0);
YogaNode root_child2 = new YogaNode(config);
root_child2.FlexGrow = 1;
root_child2.Height = 10;
root.Insert(2, root_child2);
root.StyleDirection = YogaDirection.LTR;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(320f, root.LayoutWidth);
Assert.AreEqual(10f, root.LayoutHeight);
Assert.AreEqual(0f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(107f, root_child0.LayoutWidth);
Assert.AreEqual(10f, root_child0.LayoutHeight);
Assert.AreEqual(107f, root_child1.LayoutX);
Assert.AreEqual(0f, root_child1.LayoutY);
Assert.AreEqual(106f, root_child1.LayoutWidth);
Assert.AreEqual(10f, root_child1.LayoutHeight);
Assert.AreEqual(0f, root_child1_child0.LayoutX);
Assert.AreEqual(0f, root_child1_child0.LayoutY);
Assert.AreEqual(106f, root_child1_child0.LayoutWidth);
Assert.AreEqual(10f, root_child1_child0.LayoutHeight);
Assert.AreEqual(213f, root_child2.LayoutX);
Assert.AreEqual(0f, root_child2.LayoutY);
Assert.AreEqual(107f, root_child2.LayoutWidth);
Assert.AreEqual(10f, root_child2.LayoutHeight);
root.StyleDirection = YogaDirection.RTL;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(320f, root.LayoutWidth);
Assert.AreEqual(10f, root.LayoutHeight);
Assert.AreEqual(213f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(107f, root_child0.LayoutWidth);
Assert.AreEqual(10f, root_child0.LayoutHeight);
Assert.AreEqual(107f, root_child1.LayoutX);
Assert.AreEqual(0f, root_child1.LayoutY);
Assert.AreEqual(106f, root_child1.LayoutWidth);
Assert.AreEqual(10f, root_child1.LayoutHeight);
Assert.AreEqual(0f, root_child1_child0.LayoutX);
Assert.AreEqual(0f, root_child1_child0.LayoutY);
Assert.AreEqual(106f, root_child1_child0.LayoutWidth);
Assert.AreEqual(10f, root_child1_child0.LayoutHeight);
Assert.AreEqual(0f, root_child2.LayoutX);
Assert.AreEqual(0f, root_child2.LayoutY);
Assert.AreEqual(107f, root_child2.LayoutWidth);
Assert.AreEqual(10f, root_child2.LayoutHeight);
}
[Test]
public void Test_rounding_inner_node_controversy_vertical()
{
YogaConfig config = new YogaConfig();
config.SetExperimentalFeatureEnabled(YogaExperimentalFeature.Rounding, true);
YogaNode root = new YogaNode(config);
root.Height = 320;
YogaNode root_child0 = new YogaNode(config);
root_child0.FlexGrow = 1;
root_child0.Width = 10;
root.Insert(0, root_child0);
YogaNode root_child1 = new YogaNode(config);
root_child1.FlexGrow = 1;
root_child1.Width = 10;
root.Insert(1, root_child1);
YogaNode root_child1_child0 = new YogaNode(config);
root_child1_child0.FlexGrow = 1;
root_child1_child0.Width = 10;
root_child1.Insert(0, root_child1_child0);
YogaNode root_child2 = new YogaNode(config);
root_child2.FlexGrow = 1;
root_child2.Width = 10;
root.Insert(2, root_child2);
root.StyleDirection = YogaDirection.LTR;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(10f, root.LayoutWidth);
Assert.AreEqual(320f, root.LayoutHeight);
Assert.AreEqual(0f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(10f, root_child0.LayoutWidth);
Assert.AreEqual(107f, root_child0.LayoutHeight);
Assert.AreEqual(0f, root_child1.LayoutX);
Assert.AreEqual(107f, root_child1.LayoutY);
Assert.AreEqual(10f, root_child1.LayoutWidth);
Assert.AreEqual(106f, root_child1.LayoutHeight);
Assert.AreEqual(0f, root_child1_child0.LayoutX);
Assert.AreEqual(0f, root_child1_child0.LayoutY);
Assert.AreEqual(10f, root_child1_child0.LayoutWidth);
Assert.AreEqual(106f, root_child1_child0.LayoutHeight);
Assert.AreEqual(0f, root_child2.LayoutX);
Assert.AreEqual(213f, root_child2.LayoutY);
Assert.AreEqual(10f, root_child2.LayoutWidth);
Assert.AreEqual(107f, root_child2.LayoutHeight);
root.StyleDirection = YogaDirection.RTL;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(10f, root.LayoutWidth);
Assert.AreEqual(320f, root.LayoutHeight);
Assert.AreEqual(0f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(10f, root_child0.LayoutWidth);
Assert.AreEqual(107f, root_child0.LayoutHeight);
Assert.AreEqual(0f, root_child1.LayoutX);
Assert.AreEqual(107f, root_child1.LayoutY);
Assert.AreEqual(10f, root_child1.LayoutWidth);
Assert.AreEqual(106f, root_child1.LayoutHeight);
Assert.AreEqual(0f, root_child1_child0.LayoutX);
Assert.AreEqual(0f, root_child1_child0.LayoutY);
Assert.AreEqual(10f, root_child1_child0.LayoutWidth);
Assert.AreEqual(106f, root_child1_child0.LayoutHeight);
Assert.AreEqual(0f, root_child2.LayoutX);
Assert.AreEqual(213f, root_child2.LayoutY);
Assert.AreEqual(10f, root_child2.LayoutWidth);
Assert.AreEqual(107f, root_child2.LayoutHeight);
}
[Test]
public void Test_rounding_inner_node_controversy_combined()
{
YogaConfig config = new YogaConfig();
config.SetExperimentalFeatureEnabled(YogaExperimentalFeature.Rounding, true);
YogaNode root = new YogaNode(config);
root.FlexDirection = YogaFlexDirection.Row;
root.Width = 640;
root.Height = 320;
YogaNode root_child0 = new YogaNode(config);
root_child0.FlexGrow = 1;
root_child0.Height = 100.Percent();
root.Insert(0, root_child0);
YogaNode root_child1 = new YogaNode(config);
root_child1.FlexGrow = 1;
root_child1.Height = 100.Percent();
root.Insert(1, root_child1);
YogaNode root_child1_child0 = new YogaNode(config);
root_child1_child0.FlexGrow = 1;
root_child1_child0.Width = 100.Percent();
root_child1.Insert(0, root_child1_child0);
YogaNode root_child1_child1 = new YogaNode(config);
root_child1_child1.FlexGrow = 1;
root_child1_child1.Width = 100.Percent();
root_child1.Insert(1, root_child1_child1);
YogaNode root_child1_child1_child0 = new YogaNode(config);
root_child1_child1_child0.FlexGrow = 1;
root_child1_child1_child0.Width = 100.Percent();
root_child1_child1.Insert(0, root_child1_child1_child0);
YogaNode root_child1_child2 = new YogaNode(config);
root_child1_child2.FlexGrow = 1;
root_child1_child2.Width = 100.Percent();
root_child1.Insert(2, root_child1_child2);
YogaNode root_child2 = new YogaNode(config);
root_child2.FlexGrow = 1;
root_child2.Height = 100.Percent();
root.Insert(2, root_child2);
root.StyleDirection = YogaDirection.LTR;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(640f, root.LayoutWidth);
Assert.AreEqual(320f, root.LayoutHeight);
Assert.AreEqual(0f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(213f, root_child0.LayoutWidth);
Assert.AreEqual(320f, root_child0.LayoutHeight);
Assert.AreEqual(213f, root_child1.LayoutX);
Assert.AreEqual(0f, root_child1.LayoutY);
Assert.AreEqual(214f, root_child1.LayoutWidth);
Assert.AreEqual(320f, root_child1.LayoutHeight);
Assert.AreEqual(0f, root_child1_child0.LayoutX);
Assert.AreEqual(0f, root_child1_child0.LayoutY);
Assert.AreEqual(214f, root_child1_child0.LayoutWidth);
Assert.AreEqual(107f, root_child1_child0.LayoutHeight);
Assert.AreEqual(0f, root_child1_child1.LayoutX);
Assert.AreEqual(107f, root_child1_child1.LayoutY);
Assert.AreEqual(214f, root_child1_child1.LayoutWidth);
Assert.AreEqual(106f, root_child1_child1.LayoutHeight);
Assert.AreEqual(0f, root_child1_child1_child0.LayoutX);
Assert.AreEqual(0f, root_child1_child1_child0.LayoutY);
Assert.AreEqual(214f, root_child1_child1_child0.LayoutWidth);
Assert.AreEqual(106f, root_child1_child1_child0.LayoutHeight);
Assert.AreEqual(0f, root_child1_child2.LayoutX);
Assert.AreEqual(213f, root_child1_child2.LayoutY);
Assert.AreEqual(214f, root_child1_child2.LayoutWidth);
Assert.AreEqual(107f, root_child1_child2.LayoutHeight);
Assert.AreEqual(427f, root_child2.LayoutX);
Assert.AreEqual(0f, root_child2.LayoutY);
Assert.AreEqual(213f, root_child2.LayoutWidth);
Assert.AreEqual(320f, root_child2.LayoutHeight);
root.StyleDirection = YogaDirection.RTL;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(640f, root.LayoutWidth);
Assert.AreEqual(320f, root.LayoutHeight);
Assert.AreEqual(427f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(213f, root_child0.LayoutWidth);
Assert.AreEqual(320f, root_child0.LayoutHeight);
Assert.AreEqual(213f, root_child1.LayoutX);
Assert.AreEqual(0f, root_child1.LayoutY);
Assert.AreEqual(214f, root_child1.LayoutWidth);
Assert.AreEqual(320f, root_child1.LayoutHeight);
Assert.AreEqual(0f, root_child1_child0.LayoutX);
Assert.AreEqual(0f, root_child1_child0.LayoutY);
Assert.AreEqual(214f, root_child1_child0.LayoutWidth);
Assert.AreEqual(107f, root_child1_child0.LayoutHeight);
Assert.AreEqual(0f, root_child1_child1.LayoutX);
Assert.AreEqual(107f, root_child1_child1.LayoutY);
Assert.AreEqual(214f, root_child1_child1.LayoutWidth);
Assert.AreEqual(106f, root_child1_child1.LayoutHeight);
Assert.AreEqual(0f, root_child1_child1_child0.LayoutX);
Assert.AreEqual(0f, root_child1_child1_child0.LayoutY);
Assert.AreEqual(214f, root_child1_child1_child0.LayoutWidth);
Assert.AreEqual(106f, root_child1_child1_child0.LayoutHeight);
Assert.AreEqual(0f, root_child1_child2.LayoutX);
Assert.AreEqual(213f, root_child1_child2.LayoutY);
Assert.AreEqual(214f, root_child1_child2.LayoutWidth);
Assert.AreEqual(107f, root_child1_child2.LayoutHeight);
Assert.AreEqual(0f, root_child2.LayoutX);
Assert.AreEqual(0f, root_child2.LayoutY);
Assert.AreEqual(213f, root_child2.LayoutWidth);
Assert.AreEqual(320f, root_child2.LayoutHeight);
}
}
}

View File

@@ -188,7 +188,7 @@ enum YogaMeasureMode {
interface YogaMeasureFunction {
long measure(
YogaNodeAPI node,
YogaNode node,
float width,
YogaMeasureMode widthMode,
float height,

View File

@@ -223,6 +223,8 @@ for name, values in sorted(ENUMS.items()):
with open(root + '/csharp/Facebook.Yoga/Yoga%s.cs' % name, 'w') as f:
f.write(LICENSE)
f.write('namespace Facebook.Yoga\n{\n')
if isinstance(next(iter(values or []), None), tuple):
f.write(' [System.Flags]\n')
f.write(' public enum Yoga%s\n {\n' % name)
for value in values:
if isinstance(value, tuple):

View File

@@ -41,6 +41,15 @@
</div>
</div>
<div id="flex_grow_child" style="flex-direction: row;">
<div style="height: 100px; flex-grow: 1; flex-basis: 0px;"></div>
</div>
<div id="flex_grow_within_constrained_min_max_column" style="min-height: 100px; max-height: 200px">
<div style="flex-grow:1;"></div>
<div style="height: 50px;"></div>
</div>
<div id="flex_grow_within_max_width" style="width: 200px; height: 100px;">
<div style="flex-direction: row; max-width: 100px;">
<div style="height: 20px; flex-grow: 1;"></div>

View File

@@ -62,3 +62,34 @@
<div style="height: 10px; flex-grow:1;"></div>
<div style="height: 10px; flex-grow:1;"></div>
</div>
<div id="rounding_inner_node_controversy_horizontal" experiments="Rounding" style="width: 320px; flex-direction: row;">
<div style="height: 10px; flex-grow:1;"></div>
<div style="height: 10px; flex-grow:1;">
<div style="height: 10px; flex-grow:1;">
</div>
</div>
<div style="height: 10px; flex-grow:1;"></div>
</div>
<div id="rounding_inner_node_controversy_vertical" experiments="Rounding" style="height: 320px;">
<div style="width: 10px; flex-grow:1;"></div>
<div style="width: 10px; flex-grow:1;">
<div style="width: 10px; flex-grow:1;">
</div>
</div>
<div style="width: 10px; flex-grow:1;"></div>
</div>
<div id="rounding_inner_node_controversy_combined" experiments="Rounding" style="width: 640px; height: 320px; flex-direction: row;">
<div style="height: 100%; flex-grow:1;"></div>
<div style="height: 100%; flex-grow:1; flex-direction: column;">
<div style="width: 100%; flex-grow:1;"></div>
<div style="width: 100%; flex-grow:1;">
<div style="flex-grow:1; width: 100%;">
</div>
</div>
<div style="width: 100%; flex-grow:1;"></div>
</div>
<div style="height: 100%; flex-grow:1;"></div>
</div>

View File

@@ -420,25 +420,46 @@ function getDefaultStyleValue(style) {
return getComputedStyle(node, null).getPropertyValue(style);
}
function calculateTree(root) {
function getRoundedSize(node) {
var boundingRect = node.getBoundingClientRect();
return {
width: Math.round(boundingRect.right) - Math.round(boundingRect.left),
height: Math.round(boundingRect.bottom) - Math.round(boundingRect.top)
};
}
function calculateTree(root, roundToPixelGrid) {
var rootLayout = [];
// Any occurrence of "Rounding" mark during node tree traverse turns this feature on for whole subtree.
if ((root.getAttribute('experiments') || '').split(' ').indexOf('Rounding') != -1) {
roundToPixelGrid = true;
}
for (var i = 0; i < root.children.length; i++) {
var child = root.children[i];
rootLayout.push({
var layout = {
name: child.id !== '' ? child.id : 'INSERT_NAME_HERE',
left: child.offsetLeft + child.parentNode.clientLeft,
top: child.offsetTop + child.parentNode.clientTop,
width: child.offsetWidth,
height: child.offsetHeight,
children: calculateTree(child),
children: calculateTree(child, roundToPixelGrid),
style: getYogaStyle(child),
declaredStyle: child.style,
rawStyle: child.getAttribute('style'),
experiments: child.getAttribute('experiments')
? child.getAttribute('experiments').split(' ')
: [],
});
};
if (roundToPixelGrid) {
var size = getRoundedSize(child);
layout.width = size.width;
layout.height = size.height;
}
rootLayout.push(layout);
}
return rootLayout;

4
gradle.properties Normal file
View File

@@ -0,0 +1,4 @@
bintrayUsername=
bintrayApiKey=
bintrayGpgPassword=
dryRun=false

View File

@@ -12,19 +12,19 @@ ext {
}
def getBintrayUsername() {
return hasProperty('bintrayUsername') ? property('bintrayUsername') : System.getenv('BINTRAY_USERNAME')
return property('bintrayUsername') || System.getenv('BINTRAY_USERNAME')
}
def getBintrayApiKey() {
return hasProperty('bintrayApiKey') ? property('bintrayApiKey') : System.getenv('BINTRAY_API_KEY')
return property('bintrayApiKey') || System.getenv('BINTRAY_API_KEY')
}
def getBintrayGpgPassword() {
return hasProperty('bintrayGpgPassword') ? property('bintrayGpgPassword') : System.getenv('BINTRAY_GPG_PASSWORD')
return property('bintrayGpgPassword') || System.getenv('BINTRAY_GPG_PASSWORD')
}
def dryRunOnly() {
return hasProperty('dryRun') ? property('dryRun').toBoolean() : false
return hasProperty('dryRun') ? property('dryRun').toBoolean() : false
}
def pomConfig = {

BIN
gradle/wrapper/gradle-wrapper.jar vendored Normal file

Binary file not shown.

View File

@@ -0,0 +1,6 @@
#Tue Apr 18 14:49:25 CEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.5-bin.zip

172
gradlew vendored Executable file
View File

@@ -0,0 +1,172 @@
#!/usr/bin/env sh
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn ( ) {
echo "$*"
}
die ( ) {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Escape application args
save ( ) {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=$(save "$@")
# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi
exec "$JAVACMD" "$@"

40
java/CMakeLists.txt Normal file
View File

@@ -0,0 +1,40 @@
#
# Copyright (c) 2014-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree. An additional grant
# of patent rights can be found in the PATENTS file in the same directory.
#
cmake_minimum_required(VERSION 3.4.1)
set(CMAKE_VERBOSE_MAKEFILE on)
# configure import libs
set(libfb_DIR ${CMAKE_SOURCE_DIR}/../lib/fb/src/main/cpp)
set(yogacore_DIR ${CMAKE_SOURCE_DIR}/..)
set(build_DIR ${CMAKE_SOURCE_DIR}/build)
set(libfb_build_DIR ${build_DIR}/libfb/${ANDROID_ABI})
set(yogacore_build_DIR ${build_DIR}/yogacore/${ANDROID_ABI})
file(MAKE_DIRECTORY ${build_DIR})
add_subdirectory(${libfb_DIR} ${libfb_build_DIR})
add_subdirectory(${yogacore_DIR} ${yogacore_build_DIR})
add_compile_options(
-fno-omit-frame-pointer
-fexceptions
-Wall
-std=c++11)
add_library(yoga SHARED jni/YGJNI.cpp)
target_include_directories(yoga PRIVATE
${libfb_DIR}/include
${yogacore_DIR})
target_link_libraries(yoga yogacore fb)

View File

@@ -1,32 +1,39 @@
apply plugin: "com.jfrog.bintray"
apply plugin: 'com.jfrog.bintray'
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'maven-publish'
targetCompatibility = '1.7'
sourceCompatibility = '1.7'
version = '1.3.1'
version = '1.4.2'
group = 'com.facebook.yoga'
// We currently build the native libraries with buck and bundle them together
// at this point into the AAR
task buckBuildAndCopy(type: Exec) {
commandLine '../scripts/build_natives_for_gradle.sh'
}
android {
compileSdkVersion 19
buildToolsVersion "19.1.0"
compileSdkVersion rootProject.compileSdkVersion
buildToolsVersion rootProject.buildToolsVersion
defaultConfig {
minSdkVersion 15
targetSdkVersion 19
minSdkVersion rootProject.minSdkVersion
targetSdkVersion rootProject.targetSdkVersion
ndk {
abiFilters 'x86', 'x86_64', 'armeabi', 'armeabi-v7a', 'arm64-v8a'
}
externalNativeBuild {
cmake {
arguments '-DANDROID_TOOLCHAIN=clang', '-DANDROID_STL=c++_static'
}
}
}
externalNativeBuild {
cmake {
path 'CMakeLists.txt'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
targetCompatibility rootProject.targetCompatibilityVersion
sourceCompatibility rootProject.sourceCompatibilityVersion
}
sourceSets {
@@ -39,12 +46,10 @@ android {
}
}
preBuild.dependsOn buckBuildAndCopy
dependencies {
compile(name: 'jsr305')
compile(name: 'soloader-0.1.0', ext: 'aar')
provided(project(':yoga:proguard-annotations'))
compile 'com.google.code.findbugs:jsr305:3.0.1'
compile 'com.facebook.soloader:soloader:0.2.0'
provided project(':yoga:proguard-annotations')
}
task sourcesJar(type: Jar) {
@@ -65,7 +70,7 @@ task javadocJar(type: Jar, dependsOn: javadoc) {
}
ext {
bintrayName = "com.facebook.yoga:yoga"
bintrayName = 'com.facebook.yoga:yoga'
}
apply from: rootProject.file('gradle/android-jcenter-install.gradle')

View File

@@ -18,5 +18,5 @@ public interface YogaBaselineFunction {
* default to the computed height of the node.
*/
@DoNotStrip
float baseline(YogaNodeAPI node, float width, float height);
float baseline(YogaNode node, float width, float height);
}

View File

@@ -18,7 +18,7 @@ public interface YogaMeasureFunction {
*/
@DoNotStrip
long measure(
YogaNodeAPI node,
YogaNode node,
float width,
YogaMeasureMode widthMode,
float height,

View File

@@ -18,7 +18,7 @@ import com.facebook.proguard.annotations.DoNotStrip;
import com.facebook.soloader.SoLoader;
@DoNotStrip
public class YogaNode implements YogaNodeAPI<YogaNode> {
public class YogaNode {
static {
SoLoader.loadLibrary("yoga");
@@ -106,7 +106,6 @@ public class YogaNode implements YogaNodeAPI<YogaNode> {
}
private native void jni_YGNodeFree(long nativePointer);
@Override
protected void finalize() throws Throwable {
try {
jni_YGNodeFree(mNativePointer);
@@ -116,7 +115,6 @@ public class YogaNode implements YogaNodeAPI<YogaNode> {
}
private native void jni_YGNodeReset(long nativePointer);
@Override
public void reset() {
mEdgeSetFlag = 0;
mHasSetPosition = false;
@@ -141,23 +139,21 @@ public class YogaNode implements YogaNodeAPI<YogaNode> {
mLayoutDirection = 0;
mMeasureFunction = null;
mBaselineFunction = null;
mData = null;
jni_YGNodeReset(mNativePointer);
}
@Override
public int getChildCount() {
return mChildren == null ? 0 : mChildren.size();
}
@Override
public YogaNode getChildAt(int i) {
return mChildren.get(i);
}
private native void jni_YGNodeInsertChild(long nativePointer, long childPointer, int index);
@Override
public void addChildAt(YogaNode child, int i) {
if (child.mParent != null) {
throw new IllegalStateException("Child already has a parent, it must be removed first.");
@@ -172,7 +168,6 @@ public class YogaNode implements YogaNodeAPI<YogaNode> {
}
private native void jni_YGNodeRemoveChild(long nativePointer, long childPointer);
@Override
public YogaNode removeChildAt(int i) {
final YogaNode child = mChildren.remove(i);
@@ -181,221 +176,184 @@ public class YogaNode implements YogaNodeAPI<YogaNode> {
return child;
}
@Override
public @Nullable
YogaNode getParent() {
return mParent;
}
@Override
public int indexOf(YogaNode child) {
return mChildren == null ? -1 : mChildren.indexOf(child);
}
private native void jni_YGNodeCalculateLayout(long nativePointer, float width, float height);
@Override
public void calculateLayout(float width, float height) {
jni_YGNodeCalculateLayout(mNativePointer, width, height);
}
@Override
public boolean hasNewLayout() {
return mHasNewLayout;
}
private native void jni_YGNodeMarkDirty(long nativePointer);
@Override
public void dirty() {
jni_YGNodeMarkDirty(mNativePointer);
}
private native boolean jni_YGNodeIsDirty(long nativePointer);
@Override
public boolean isDirty() {
return jni_YGNodeIsDirty(mNativePointer);
}
private native void jni_YGNodeCopyStyle(long dstNativePointer, long srcNativePointer);
@Override
public void copyStyle(YogaNode srcNode) {
jni_YGNodeCopyStyle(mNativePointer, srcNode.mNativePointer);
}
@Override
public void markLayoutSeen() {
mHasNewLayout = false;
}
private native int jni_YGNodeStyleGetDirection(long nativePointer);
@Override
public YogaDirection getStyleDirection() {
return YogaDirection.fromInt(jni_YGNodeStyleGetDirection(mNativePointer));
}
private native void jni_YGNodeStyleSetDirection(long nativePointer, int direction);
@Override
public void setDirection(YogaDirection direction) {
jni_YGNodeStyleSetDirection(mNativePointer, direction.intValue());
}
private native int jni_YGNodeStyleGetFlexDirection(long nativePointer);
@Override
public YogaFlexDirection getFlexDirection() {
return YogaFlexDirection.fromInt(jni_YGNodeStyleGetFlexDirection(mNativePointer));
}
private native void jni_YGNodeStyleSetFlexDirection(long nativePointer, int flexDirection);
@Override
public void setFlexDirection(YogaFlexDirection flexDirection) {
jni_YGNodeStyleSetFlexDirection(mNativePointer, flexDirection.intValue());
}
private native int jni_YGNodeStyleGetJustifyContent(long nativePointer);
@Override
public YogaJustify getJustifyContent() {
return YogaJustify.fromInt(jni_YGNodeStyleGetJustifyContent(mNativePointer));
}
private native void jni_YGNodeStyleSetJustifyContent(long nativePointer, int justifyContent);
@Override
public void setJustifyContent(YogaJustify justifyContent) {
jni_YGNodeStyleSetJustifyContent(mNativePointer, justifyContent.intValue());
}
private native int jni_YGNodeStyleGetAlignItems(long nativePointer);
@Override
public YogaAlign getAlignItems() {
return YogaAlign.fromInt(jni_YGNodeStyleGetAlignItems(mNativePointer));
}
private native void jni_YGNodeStyleSetAlignItems(long nativePointer, int alignItems);
@Override
public void setAlignItems(YogaAlign alignItems) {
jni_YGNodeStyleSetAlignItems(mNativePointer, alignItems.intValue());
}
private native int jni_YGNodeStyleGetAlignSelf(long nativePointer);
@Override
public YogaAlign getAlignSelf() {
return YogaAlign.fromInt(jni_YGNodeStyleGetAlignSelf(mNativePointer));
}
private native void jni_YGNodeStyleSetAlignSelf(long nativePointer, int alignSelf);
@Override
public void setAlignSelf(YogaAlign alignSelf) {
jni_YGNodeStyleSetAlignSelf(mNativePointer, alignSelf.intValue());
}
private native int jni_YGNodeStyleGetAlignContent(long nativePointer);
@Override
public YogaAlign getAlignContent() {
return YogaAlign.fromInt(jni_YGNodeStyleGetAlignContent(mNativePointer));
}
private native void jni_YGNodeStyleSetAlignContent(long nativePointer, int alignContent);
@Override
public void setAlignContent(YogaAlign alignContent) {
jni_YGNodeStyleSetAlignContent(mNativePointer, alignContent.intValue());
}
private native int jni_YGNodeStyleGetPositionType(long nativePointer);
@Override
public YogaPositionType getPositionType() {
return YogaPositionType.fromInt(jni_YGNodeStyleGetPositionType(mNativePointer));
}
private native void jni_YGNodeStyleSetPositionType(long nativePointer, int positionType);
@Override
public void setPositionType(YogaPositionType positionType) {
jni_YGNodeStyleSetPositionType(mNativePointer, positionType.intValue());
}
private native void jni_YGNodeStyleSetFlexWrap(long nativePointer, int wrapType);
@Override
public void setWrap(YogaWrap flexWrap) {
jni_YGNodeStyleSetFlexWrap(mNativePointer, flexWrap.intValue());
}
private native int jni_YGNodeStyleGetOverflow(long nativePointer);
@Override
public YogaOverflow getOverflow() {
return YogaOverflow.fromInt(jni_YGNodeStyleGetOverflow(mNativePointer));
}
private native void jni_YGNodeStyleSetOverflow(long nativePointer, int overflow);
@Override
public void setOverflow(YogaOverflow overflow) {
jni_YGNodeStyleSetOverflow(mNativePointer, overflow.intValue());
}
private native int jni_YGNodeStyleGetDisplay(long nativePointer);
@Override
public YogaDisplay getDisplay() {
return YogaDisplay.fromInt(jni_YGNodeStyleGetDisplay(mNativePointer));
}
private native void jni_YGNodeStyleSetDisplay(long nativePointer, int display);
@Override
public void setDisplay(YogaDisplay display) {
jni_YGNodeStyleSetDisplay(mNativePointer, display.intValue());
}
private native void jni_YGNodeStyleSetFlex(long nativePointer, float flex);
@Override
public void setFlex(float flex) {
jni_YGNodeStyleSetFlex(mNativePointer, flex);
}
private native float jni_YGNodeStyleGetFlexGrow(long nativePointer);
@Override
public float getFlexGrow() {
return jni_YGNodeStyleGetFlexGrow(mNativePointer);
}
private native void jni_YGNodeStyleSetFlexGrow(long nativePointer, float flexGrow);
@Override
public void setFlexGrow(float flexGrow) {
jni_YGNodeStyleSetFlexGrow(mNativePointer, flexGrow);
}
private native float jni_YGNodeStyleGetFlexShrink(long nativePointer);
@Override
public float getFlexShrink() {
return jni_YGNodeStyleGetFlexShrink(mNativePointer);
}
private native void jni_YGNodeStyleSetFlexShrink(long nativePointer, float flexShrink);
@Override
public void setFlexShrink(float flexShrink) {
jni_YGNodeStyleSetFlexShrink(mNativePointer, flexShrink);
}
private native Object jni_YGNodeStyleGetFlexBasis(long nativePointer);
@Override
public YogaValue getFlexBasis() {
return (YogaValue) jni_YGNodeStyleGetFlexBasis(mNativePointer);
}
private native void jni_YGNodeStyleSetFlexBasis(long nativePointer, float flexBasis);
@Override
public void setFlexBasis(float flexBasis) {
jni_YGNodeStyleSetFlexBasis(mNativePointer, flexBasis);
}
private native void jni_YGNodeStyleSetFlexBasisPercent(long nativePointer, float percent);
@Override
public void setFlexBasisPercent(float percent) {
jni_YGNodeStyleSetFlexBasisPercent(mNativePointer, percent);
}
private native void jni_YGNodeStyleSetFlexBasisAuto(long nativePointer);
@Override
public void setFlexBasisAuto() {
jni_YGNodeStyleSetFlexBasisAuto(mNativePointer);
}
private native Object jni_YGNodeStyleGetMargin(long nativePointer, int edge);
@Override
public YogaValue getMargin(YogaEdge edge) {
if (!((mEdgeSetFlag & MARGIN) == MARGIN)) {
return YogaValue.UNDEFINED;
@@ -404,28 +362,24 @@ public class YogaNode implements YogaNodeAPI<YogaNode> {
}
private native void jni_YGNodeStyleSetMargin(long nativePointer, int edge, float margin);
@Override
public void setMargin(YogaEdge edge, float margin) {
mEdgeSetFlag |= MARGIN;
jni_YGNodeStyleSetMargin(mNativePointer, edge.intValue(), margin);
}
private native void jni_YGNodeStyleSetMarginPercent(long nativePointer, int edge, float percent);
@Override
public void setMarginPercent(YogaEdge edge, float percent) {
mEdgeSetFlag |= MARGIN;
jni_YGNodeStyleSetMarginPercent(mNativePointer, edge.intValue(), percent);
}
private native void jni_YGNodeStyleSetMarginAuto(long nativePointer, int edge);
@Override
public void setMarginAuto(YogaEdge edge) {
mEdgeSetFlag |= MARGIN;
jni_YGNodeStyleSetMarginAuto(mNativePointer, edge.intValue());
}
private native Object jni_YGNodeStyleGetPadding(long nativePointer, int edge);
@Override
public YogaValue getPadding(YogaEdge edge) {
if (!((mEdgeSetFlag & PADDING) == PADDING)) {
return YogaValue.UNDEFINED;
@@ -434,21 +388,18 @@ public class YogaNode implements YogaNodeAPI<YogaNode> {
}
private native void jni_YGNodeStyleSetPadding(long nativePointer, int edge, float padding);
@Override
public void setPadding(YogaEdge edge, float padding) {
mEdgeSetFlag |= PADDING;
jni_YGNodeStyleSetPadding(mNativePointer, edge.intValue(), padding);
}
private native void jni_YGNodeStyleSetPaddingPercent(long nativePointer, int edge, float percent);
@Override
public void setPaddingPercent(YogaEdge edge, float percent) {
mEdgeSetFlag |= PADDING;
jni_YGNodeStyleSetPaddingPercent(mNativePointer, edge.intValue(), percent);
}
private native float jni_YGNodeStyleGetBorder(long nativePointer, int edge);
@Override
public float getBorder(YogaEdge edge) {
if (!((mEdgeSetFlag & BORDER) == BORDER)) {
return YogaConstants.UNDEFINED;
@@ -457,14 +408,12 @@ public class YogaNode implements YogaNodeAPI<YogaNode> {
}
private native void jni_YGNodeStyleSetBorder(long nativePointer, int edge, float border);
@Override
public void setBorder(YogaEdge edge, float border) {
mEdgeSetFlag |= BORDER;
jni_YGNodeStyleSetBorder(mNativePointer, edge.intValue(), border);
}
private native Object jni_YGNodeStyleGetPosition(long nativePointer, int edge);
@Override
public YogaValue getPosition(YogaEdge edge) {
if (!mHasSetPosition) {
return YogaValue.UNDEFINED;
@@ -473,135 +422,113 @@ public class YogaNode implements YogaNodeAPI<YogaNode> {
}
private native void jni_YGNodeStyleSetPosition(long nativePointer, int edge, float position);
@Override
public void setPosition(YogaEdge edge, float position) {
mHasSetPosition = true;
jni_YGNodeStyleSetPosition(mNativePointer, edge.intValue(), position);
}
private native void jni_YGNodeStyleSetPositionPercent(long nativePointer, int edge, float percent);
@Override
public void setPositionPercent(YogaEdge edge, float percent) {
mHasSetPosition = true;
jni_YGNodeStyleSetPositionPercent(mNativePointer, edge.intValue(), percent);
}
private native Object jni_YGNodeStyleGetWidth(long nativePointer);
@Override
public YogaValue getWidth() {
return (YogaValue) jni_YGNodeStyleGetWidth(mNativePointer);
}
private native void jni_YGNodeStyleSetWidth(long nativePointer, float width);
@Override
public void setWidth(float width) {
jni_YGNodeStyleSetWidth(mNativePointer, width);
}
private native void jni_YGNodeStyleSetWidthPercent(long nativePointer, float percent);
@Override
public void setWidthPercent(float percent) {
jni_YGNodeStyleSetWidthPercent(mNativePointer, percent);
}
private native void jni_YGNodeStyleSetWidthAuto(long nativePointer);
@Override
public void setWidthAuto() {
jni_YGNodeStyleSetWidthAuto(mNativePointer);
}
private native Object jni_YGNodeStyleGetHeight(long nativePointer);
@Override
public YogaValue getHeight() {
return (YogaValue) jni_YGNodeStyleGetHeight(mNativePointer);
}
private native void jni_YGNodeStyleSetHeight(long nativePointer, float height);
@Override
public void setHeight(float height) {
jni_YGNodeStyleSetHeight(mNativePointer, height);
}
private native void jni_YGNodeStyleSetHeightPercent(long nativePointer, float percent);
@Override
public void setHeightPercent(float percent) {
jni_YGNodeStyleSetHeightPercent(mNativePointer, percent);
}
private native void jni_YGNodeStyleSetHeightAuto(long nativePointer);
@Override
public void setHeightAuto() {
jni_YGNodeStyleSetHeightAuto(mNativePointer);
}
private native Object jni_YGNodeStyleGetMinWidth(long nativePointer);
@Override
public YogaValue getMinWidth() {
return (YogaValue) jni_YGNodeStyleGetMinWidth(mNativePointer);
}
private native void jni_YGNodeStyleSetMinWidth(long nativePointer, float minWidth);
@Override
public void setMinWidth(float minWidth) {
jni_YGNodeStyleSetMinWidth(mNativePointer, minWidth);
}
private native void jni_YGNodeStyleSetMinWidthPercent(long nativePointer, float percent);
@Override
public void setMinWidthPercent(float percent) {
jni_YGNodeStyleSetMinWidthPercent(mNativePointer, percent);
}
private native Object jni_YGNodeStyleGetMinHeight(long nativePointer);
@Override
public YogaValue getMinHeight() {
return (YogaValue) jni_YGNodeStyleGetMinHeight(mNativePointer);
}
private native void jni_YGNodeStyleSetMinHeight(long nativePointer, float minHeight);
@Override
public void setMinHeight(float minHeight) {
jni_YGNodeStyleSetMinHeight(mNativePointer, minHeight);
}
private native void jni_YGNodeStyleSetMinHeightPercent(long nativePointer, float percent);
@Override
public void setMinHeightPercent(float percent) {
jni_YGNodeStyleSetMinHeightPercent(mNativePointer, percent);
}
private native Object jni_YGNodeStyleGetMaxWidth(long nativePointer);
@Override
public YogaValue getMaxWidth() {
return (YogaValue) jni_YGNodeStyleGetMaxWidth(mNativePointer);
}
private native void jni_YGNodeStyleSetMaxWidth(long nativePointer, float maxWidth);
@Override
public void setMaxWidth(float maxWidth) {
jni_YGNodeStyleSetMaxWidth(mNativePointer, maxWidth);
}
private native void jni_YGNodeStyleSetMaxWidthPercent(long nativePointer, float percent);
@Override
public void setMaxWidthPercent(float percent) {
jni_YGNodeStyleSetMaxWidthPercent(mNativePointer, percent);
}
private native Object jni_YGNodeStyleGetMaxHeight(long nativePointer);
@Override
public YogaValue getMaxHeight() {
return (YogaValue) jni_YGNodeStyleGetMaxHeight(mNativePointer);
}
private native void jni_YGNodeStyleSetMaxHeight(long nativePointer, float maxheight);
@Override
public void setMaxHeight(float maxheight) {
jni_YGNodeStyleSetMaxHeight(mNativePointer, maxheight);
}
private native void jni_YGNodeStyleSetMaxHeightPercent(long nativePointer, float percent);
@Override
public void setMaxHeightPercent(float percent) {
jni_YGNodeStyleSetMaxHeightPercent(mNativePointer, percent);
}
@@ -616,27 +543,22 @@ public class YogaNode implements YogaNodeAPI<YogaNode> {
jni_YGNodeStyleSetAspectRatio(mNativePointer, aspectRatio);
}
@Override
public float getLayoutX() {
return mLeft;
}
@Override
public float getLayoutY() {
return mTop;
}
@Override
public float getLayoutWidth() {
return mWidth;
}
@Override
public float getLayoutHeight() {
return mHeight;
}
@Override
public float getLayoutMargin(YogaEdge edge) {
switch (edge) {
case LEFT:
@@ -656,7 +578,6 @@ public class YogaNode implements YogaNodeAPI<YogaNode> {
}
}
@Override
public float getLayoutPadding(YogaEdge edge) {
switch (edge) {
case LEFT:
@@ -676,7 +597,6 @@ public class YogaNode implements YogaNodeAPI<YogaNode> {
}
}
@Override
public float getLayoutBorder(YogaEdge edge) {
switch (edge) {
case LEFT:
@@ -696,13 +616,11 @@ public class YogaNode implements YogaNodeAPI<YogaNode> {
}
}
@Override
public YogaDirection getLayoutDirection() {
return YogaDirection.fromInt(mLayoutDirection);
}
private native void jni_YGNodeSetHasMeasureFunc(long nativePointer, boolean hasMeasureFunc);
@Override
public void setMeasureFunction(YogaMeasureFunction measureFunction) {
mMeasureFunction = measureFunction;
jni_YGNodeSetHasMeasureFunc(mNativePointer, measureFunction != null);
@@ -728,7 +646,6 @@ public class YogaNode implements YogaNodeAPI<YogaNode> {
}
private native void jni_YGNodeSetHasBaselineFunc(long nativePointer, boolean hasMeasureFunc);
@Override
public void setBaselineFunction(YogaBaselineFunction baselineFunction) {
mBaselineFunction = baselineFunction;
jni_YGNodeSetHasBaselineFunc(mNativePointer, baselineFunction != null);
@@ -739,17 +656,14 @@ public class YogaNode implements YogaNodeAPI<YogaNode> {
return mBaselineFunction.baseline(this, width, height);
}
@Override
public boolean isMeasureDefined() {
return mMeasureFunction != null;
}
@Override
public void setData(Object data) {
mData = data;
}
@Override
public Object getData() {
return mData;
}

View File

@@ -1,100 +0,0 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
package com.facebook.yoga;
// This only exists for legacy reasons. It will be removed sometime in the near future.
public interface YogaNodeAPI<YogaNodeType extends YogaNodeAPI> {
int getChildCount();
YogaNodeType getChildAt(int i);
void addChildAt(YogaNodeType child, int i);
YogaNodeType removeChildAt(int i);
YogaNodeType getParent();
int indexOf(YogaNodeType child);
void setMeasureFunction(YogaMeasureFunction measureFunction);
void setBaselineFunction(YogaBaselineFunction measureFunction);
boolean isMeasureDefined();
void calculateLayout(float width, float height);
boolean isDirty();
boolean hasNewLayout();
void dirty();
void markLayoutSeen();
void copyStyle(YogaNodeType srcNode);
YogaDirection getStyleDirection();
void setDirection(YogaDirection direction);
YogaFlexDirection getFlexDirection();
void setFlexDirection(YogaFlexDirection flexDirection);
YogaJustify getJustifyContent();
void setJustifyContent(YogaJustify justifyContent);
YogaAlign getAlignItems();
void setAlignItems(YogaAlign alignItems);
YogaAlign getAlignSelf();
void setAlignSelf(YogaAlign alignSelf);
YogaAlign getAlignContent();
void setAlignContent(YogaAlign alignContent);
YogaPositionType getPositionType();
void setPositionType(YogaPositionType positionType);
void setWrap(YogaWrap flexWrap);
void setFlex(float flex);
float getFlexGrow();
void setFlexGrow(float flexGrow);
float getFlexShrink();
void setFlexShrink(float flexShrink);
YogaValue getFlexBasis();
void setFlexBasis(float flexBasis);
void setFlexBasisPercent(float percent);
void setFlexBasisAuto();
YogaValue getMargin(YogaEdge edge);
void setMargin(YogaEdge edge, float margin);
void setMarginPercent(YogaEdge edge, float percent);
void setMarginAuto(YogaEdge edge);
YogaValue getPadding(YogaEdge edge);
void setPadding(YogaEdge edge, float padding);
void setPaddingPercent(YogaEdge edge, float percent);
float getBorder(YogaEdge edge);
void setBorder(YogaEdge edge, float border);
YogaValue getPosition(YogaEdge edge);
void setPosition(YogaEdge edge, float position);
void setPositionPercent(YogaEdge edge, float percent);
YogaValue getWidth();
void setWidth(float width);
void setWidthPercent(float percent);
void setWidthAuto();
YogaValue getHeight();
void setHeight(float height);
void setHeightPercent(float percent);
void setHeightAuto();
YogaValue getMaxWidth();
void setMaxWidth(float maxWidth);
void setMaxWidthPercent(float percent);
YogaValue getMinWidth();
void setMinWidth(float minWidth);
void setMinWidthPercent(float percent);
YogaValue getMaxHeight();
void setMaxHeight(float maxHeight);
void setMaxHeightPercent(float percent);
YogaValue getMinHeight();
void setMinHeight(float minHeight);
void setMinHeightPercent(float percent);
float getLayoutX();
float getLayoutY();
float getLayoutWidth();
float getLayoutHeight();
float getLayoutMargin(YogaEdge edge);
float getLayoutPadding(YogaEdge edge);
float getLayoutBorder(YogaEdge edge);
YogaDirection getLayoutDirection();
YogaOverflow getOverflow();
void setOverflow(YogaOverflow overflow);
YogaDisplay getDisplay();
void setDisplay(YogaDisplay display);
void setData(Object data);
Object getData();
void reset();
}

View File

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

View File

@@ -674,17 +674,17 @@ public class YGRoundingTest {
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(100f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(64f, root_child0.getLayoutHeight(), 0.0f);
assertEquals(65f, root_child0.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child1.getLayoutX(), 0.0f);
assertEquals(64f, root_child1.getLayoutY(), 0.0f);
assertEquals(100f, root_child1.getLayoutWidth(), 0.0f);
assertEquals(25f, root_child1.getLayoutHeight(), 0.0f);
assertEquals(24f, root_child1.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child2.getLayoutX(), 0.0f);
assertEquals(89f, root_child2.getLayoutY(), 0.0f);
assertEquals(100f, root_child2.getLayoutWidth(), 0.0f);
assertEquals(24f, root_child2.getLayoutHeight(), 0.0f);
assertEquals(25f, root_child2.getLayoutHeight(), 0.0f);
root.setDirection(YogaDirection.RTL);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
@@ -697,17 +697,17 @@ public class YGRoundingTest {
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(100f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(64f, root_child0.getLayoutHeight(), 0.0f);
assertEquals(65f, root_child0.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child1.getLayoutX(), 0.0f);
assertEquals(64f, root_child1.getLayoutY(), 0.0f);
assertEquals(100f, root_child1.getLayoutWidth(), 0.0f);
assertEquals(25f, root_child1.getLayoutHeight(), 0.0f);
assertEquals(24f, root_child1.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child2.getLayoutX(), 0.0f);
assertEquals(89f, root_child2.getLayoutY(), 0.0f);
assertEquals(100f, root_child2.getLayoutWidth(), 0.0f);
assertEquals(24f, root_child2.getLayoutHeight(), 0.0f);
assertEquals(25f, root_child2.getLayoutHeight(), 0.0f);
}
@Test
@@ -782,4 +782,304 @@ public class YGRoundingTest {
assertEquals(24f, root_child2.getLayoutHeight(), 0.0f);
}
@Test
public void test_rounding_inner_node_controversy_horizontal() {
YogaConfig config = new YogaConfig();
config.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, true);
final YogaNode root = new YogaNode(config);
root.setFlexDirection(YogaFlexDirection.ROW);
root.setWidth(320f);
final YogaNode root_child0 = new YogaNode(config);
root_child0.setFlexGrow(1f);
root_child0.setHeight(10f);
root.addChildAt(root_child0, 0);
final YogaNode root_child1 = new YogaNode(config);
root_child1.setFlexGrow(1f);
root_child1.setHeight(10f);
root.addChildAt(root_child1, 1);
final YogaNode root_child1_child0 = new YogaNode(config);
root_child1_child0.setFlexGrow(1f);
root_child1_child0.setHeight(10f);
root_child1.addChildAt(root_child1_child0, 0);
final YogaNode root_child2 = new YogaNode(config);
root_child2.setFlexGrow(1f);
root_child2.setHeight(10f);
root.addChildAt(root_child2, 2);
root.setDirection(YogaDirection.LTR);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(320f, root.getLayoutWidth(), 0.0f);
assertEquals(10f, root.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(107f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(10f, root_child0.getLayoutHeight(), 0.0f);
assertEquals(107f, root_child1.getLayoutX(), 0.0f);
assertEquals(0f, root_child1.getLayoutY(), 0.0f);
assertEquals(106f, root_child1.getLayoutWidth(), 0.0f);
assertEquals(10f, root_child1.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child1_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child1_child0.getLayoutY(), 0.0f);
assertEquals(106f, root_child1_child0.getLayoutWidth(), 0.0f);
assertEquals(10f, root_child1_child0.getLayoutHeight(), 0.0f);
assertEquals(213f, root_child2.getLayoutX(), 0.0f);
assertEquals(0f, root_child2.getLayoutY(), 0.0f);
assertEquals(107f, root_child2.getLayoutWidth(), 0.0f);
assertEquals(10f, root_child2.getLayoutHeight(), 0.0f);
root.setDirection(YogaDirection.RTL);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(320f, root.getLayoutWidth(), 0.0f);
assertEquals(10f, root.getLayoutHeight(), 0.0f);
assertEquals(213f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(107f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(10f, root_child0.getLayoutHeight(), 0.0f);
assertEquals(107f, root_child1.getLayoutX(), 0.0f);
assertEquals(0f, root_child1.getLayoutY(), 0.0f);
assertEquals(106f, root_child1.getLayoutWidth(), 0.0f);
assertEquals(10f, root_child1.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child1_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child1_child0.getLayoutY(), 0.0f);
assertEquals(106f, root_child1_child0.getLayoutWidth(), 0.0f);
assertEquals(10f, root_child1_child0.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child2.getLayoutX(), 0.0f);
assertEquals(0f, root_child2.getLayoutY(), 0.0f);
assertEquals(107f, root_child2.getLayoutWidth(), 0.0f);
assertEquals(10f, root_child2.getLayoutHeight(), 0.0f);
}
@Test
public void test_rounding_inner_node_controversy_vertical() {
YogaConfig config = new YogaConfig();
config.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, true);
final YogaNode root = new YogaNode(config);
root.setHeight(320f);
final YogaNode root_child0 = new YogaNode(config);
root_child0.setFlexGrow(1f);
root_child0.setWidth(10f);
root.addChildAt(root_child0, 0);
final YogaNode root_child1 = new YogaNode(config);
root_child1.setFlexGrow(1f);
root_child1.setWidth(10f);
root.addChildAt(root_child1, 1);
final YogaNode root_child1_child0 = new YogaNode(config);
root_child1_child0.setFlexGrow(1f);
root_child1_child0.setWidth(10f);
root_child1.addChildAt(root_child1_child0, 0);
final YogaNode root_child2 = new YogaNode(config);
root_child2.setFlexGrow(1f);
root_child2.setWidth(10f);
root.addChildAt(root_child2, 2);
root.setDirection(YogaDirection.LTR);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(10f, root.getLayoutWidth(), 0.0f);
assertEquals(320f, root.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(10f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(107f, root_child0.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child1.getLayoutX(), 0.0f);
assertEquals(107f, root_child1.getLayoutY(), 0.0f);
assertEquals(10f, root_child1.getLayoutWidth(), 0.0f);
assertEquals(106f, root_child1.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child1_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child1_child0.getLayoutY(), 0.0f);
assertEquals(10f, root_child1_child0.getLayoutWidth(), 0.0f);
assertEquals(106f, root_child1_child0.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child2.getLayoutX(), 0.0f);
assertEquals(213f, root_child2.getLayoutY(), 0.0f);
assertEquals(10f, root_child2.getLayoutWidth(), 0.0f);
assertEquals(107f, root_child2.getLayoutHeight(), 0.0f);
root.setDirection(YogaDirection.RTL);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(10f, root.getLayoutWidth(), 0.0f);
assertEquals(320f, root.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(10f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(107f, root_child0.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child1.getLayoutX(), 0.0f);
assertEquals(107f, root_child1.getLayoutY(), 0.0f);
assertEquals(10f, root_child1.getLayoutWidth(), 0.0f);
assertEquals(106f, root_child1.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child1_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child1_child0.getLayoutY(), 0.0f);
assertEquals(10f, root_child1_child0.getLayoutWidth(), 0.0f);
assertEquals(106f, root_child1_child0.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child2.getLayoutX(), 0.0f);
assertEquals(213f, root_child2.getLayoutY(), 0.0f);
assertEquals(10f, root_child2.getLayoutWidth(), 0.0f);
assertEquals(107f, root_child2.getLayoutHeight(), 0.0f);
}
@Test
public void test_rounding_inner_node_controversy_combined() {
YogaConfig config = new YogaConfig();
config.setExperimentalFeatureEnabled(YogaExperimentalFeature.ROUNDING, true);
final YogaNode root = new YogaNode(config);
root.setFlexDirection(YogaFlexDirection.ROW);
root.setWidth(640f);
root.setHeight(320f);
final YogaNode root_child0 = new YogaNode(config);
root_child0.setFlexGrow(1f);
root_child0.setHeightPercent(100f);
root.addChildAt(root_child0, 0);
final YogaNode root_child1 = new YogaNode(config);
root_child1.setFlexGrow(1f);
root_child1.setHeightPercent(100f);
root.addChildAt(root_child1, 1);
final YogaNode root_child1_child0 = new YogaNode(config);
root_child1_child0.setFlexGrow(1f);
root_child1_child0.setWidthPercent(100f);
root_child1.addChildAt(root_child1_child0, 0);
final YogaNode root_child1_child1 = new YogaNode(config);
root_child1_child1.setFlexGrow(1f);
root_child1_child1.setWidthPercent(100f);
root_child1.addChildAt(root_child1_child1, 1);
final YogaNode root_child1_child1_child0 = new YogaNode(config);
root_child1_child1_child0.setFlexGrow(1f);
root_child1_child1_child0.setWidthPercent(100f);
root_child1_child1.addChildAt(root_child1_child1_child0, 0);
final YogaNode root_child1_child2 = new YogaNode(config);
root_child1_child2.setFlexGrow(1f);
root_child1_child2.setWidthPercent(100f);
root_child1.addChildAt(root_child1_child2, 2);
final YogaNode root_child2 = new YogaNode(config);
root_child2.setFlexGrow(1f);
root_child2.setHeightPercent(100f);
root.addChildAt(root_child2, 2);
root.setDirection(YogaDirection.LTR);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(640f, root.getLayoutWidth(), 0.0f);
assertEquals(320f, root.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(213f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(320f, root_child0.getLayoutHeight(), 0.0f);
assertEquals(213f, root_child1.getLayoutX(), 0.0f);
assertEquals(0f, root_child1.getLayoutY(), 0.0f);
assertEquals(214f, root_child1.getLayoutWidth(), 0.0f);
assertEquals(320f, root_child1.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child1_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child1_child0.getLayoutY(), 0.0f);
assertEquals(214f, root_child1_child0.getLayoutWidth(), 0.0f);
assertEquals(107f, root_child1_child0.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child1_child1.getLayoutX(), 0.0f);
assertEquals(107f, root_child1_child1.getLayoutY(), 0.0f);
assertEquals(214f, root_child1_child1.getLayoutWidth(), 0.0f);
assertEquals(106f, root_child1_child1.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child1_child1_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child1_child1_child0.getLayoutY(), 0.0f);
assertEquals(214f, root_child1_child1_child0.getLayoutWidth(), 0.0f);
assertEquals(106f, root_child1_child1_child0.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child1_child2.getLayoutX(), 0.0f);
assertEquals(213f, root_child1_child2.getLayoutY(), 0.0f);
assertEquals(214f, root_child1_child2.getLayoutWidth(), 0.0f);
assertEquals(107f, root_child1_child2.getLayoutHeight(), 0.0f);
assertEquals(427f, root_child2.getLayoutX(), 0.0f);
assertEquals(0f, root_child2.getLayoutY(), 0.0f);
assertEquals(213f, root_child2.getLayoutWidth(), 0.0f);
assertEquals(320f, root_child2.getLayoutHeight(), 0.0f);
root.setDirection(YogaDirection.RTL);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(640f, root.getLayoutWidth(), 0.0f);
assertEquals(320f, root.getLayoutHeight(), 0.0f);
assertEquals(427f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(213f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(320f, root_child0.getLayoutHeight(), 0.0f);
assertEquals(213f, root_child1.getLayoutX(), 0.0f);
assertEquals(0f, root_child1.getLayoutY(), 0.0f);
assertEquals(214f, root_child1.getLayoutWidth(), 0.0f);
assertEquals(320f, root_child1.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child1_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child1_child0.getLayoutY(), 0.0f);
assertEquals(214f, root_child1_child0.getLayoutWidth(), 0.0f);
assertEquals(107f, root_child1_child0.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child1_child1.getLayoutX(), 0.0f);
assertEquals(107f, root_child1_child1.getLayoutY(), 0.0f);
assertEquals(214f, root_child1_child1.getLayoutWidth(), 0.0f);
assertEquals(106f, root_child1_child1.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child1_child1_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child1_child1_child0.getLayoutY(), 0.0f);
assertEquals(214f, root_child1_child1_child0.getLayoutWidth(), 0.0f);
assertEquals(106f, root_child1_child1_child0.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child1_child2.getLayoutX(), 0.0f);
assertEquals(213f, root_child1_child2.getLayoutY(), 0.0f);
assertEquals(214f, root_child1_child2.getLayoutWidth(), 0.0f);
assertEquals(107f, root_child1_child2.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child2.getLayoutX(), 0.0f);
assertEquals(0f, root_child2.getLayoutY(), 0.0f);
assertEquals(213f, root_child2.getLayoutWidth(), 0.0f);
assertEquals(320f, root_child2.getLayoutHeight(), 0.0f);
}
}

View File

@@ -40,7 +40,7 @@ public class YogaNodeTest {
child2.setWidth(40);
child2.setHeight(40);
child2.setBaselineFunction(new YogaBaselineFunction() {
public float baseline(YogaNodeAPI node, float width, float height) {
public float baseline(YogaNode node, float width, float height) {
return 0;
}
});
@@ -57,7 +57,7 @@ public class YogaNodeTest {
final YogaNode node = new YogaNode();
node.setMeasureFunction(new YogaMeasureFunction() {
public long measure(
YogaNodeAPI node,
YogaNode node,
float width,
YogaMeasureMode widthMode,
float height,
@@ -75,7 +75,7 @@ public class YogaNodeTest {
final YogaNode node = new YogaNode();
node.setMeasureFunction(new YogaMeasureFunction() {
public long measure(
YogaNodeAPI node,
YogaNode node,
float width,
YogaMeasureMode widthMode,
float height,
@@ -93,7 +93,7 @@ public class YogaNodeTest {
final YogaNode node = new YogaNode();
node.setMeasureFunction(new YogaMeasureFunction() {
public long measure(
YogaNodeAPI node,
YogaNode node,
float width,
YogaMeasureMode widthMode,
float height,
@@ -111,7 +111,7 @@ public class YogaNodeTest {
final YogaNode node = new YogaNode();
node.setMeasureFunction(new YogaMeasureFunction() {
public long measure(
YogaNodeAPI node,
YogaNode node,
float width,
YogaMeasureMode widthMode,
float height,

View File

@@ -498,6 +498,105 @@ it("flex_grow_in_at_most_container", function () {
config.free();
}
});
it("flex_grow_child", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW);
var root_child0 = Yoga.Node.create(config);
root_child0.setFlexGrow(1);
root_child0.setFlexBasis(0);
root_child0.setHeight(100);
root.insertChild(root_child0, 0);
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_LTR);
console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")");
console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")");
console.assert(0 === root.getComputedWidth(), "0 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")");
console.assert(0 === root_child0.getComputedWidth(), "0 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")");
console.assert(100 === root_child0.getComputedHeight(), "100 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_RTL);
console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")");
console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")");
console.assert(0 === root.getComputedWidth(), "0 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")");
console.assert(0 === root_child0.getComputedWidth(), "0 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")");
console.assert(100 === root_child0.getComputedHeight(), "100 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
} finally {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});
it("flex_grow_within_constrained_min_max_column", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setMinHeight(100);
root.setMaxHeight(200);
var root_child0 = Yoga.Node.create(config);
root_child0.setFlexGrow(1);
root.insertChild(root_child0, 0);
var root_child1 = Yoga.Node.create(config);
root_child1.setHeight(50);
root.insertChild(root_child1, 1);
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_LTR);
console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")");
console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")");
console.assert(0 === root.getComputedWidth(), "0 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")");
console.assert(0 === root_child0.getComputedWidth(), "0 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")");
console.assert(50 === root_child0.getComputedHeight(), "50 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
console.assert(0 === root_child1.getComputedLeft(), "0 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")");
console.assert(50 === root_child1.getComputedTop(), "50 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")");
console.assert(0 === root_child1.getComputedWidth(), "0 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")");
console.assert(50 === root_child1.getComputedHeight(), "50 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")");
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_RTL);
console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")");
console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")");
console.assert(0 === root.getComputedWidth(), "0 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")");
console.assert(0 === root_child0.getComputedWidth(), "0 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")");
console.assert(50 === root_child0.getComputedHeight(), "50 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
console.assert(0 === root_child1.getComputedLeft(), "0 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")");
console.assert(50 === root_child1.getComputedTop(), "50 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")");
console.assert(0 === root_child1.getComputedWidth(), "0 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")");
console.assert(50 === root_child1.getComputedHeight(), "50 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")");
} finally {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});
it("flex_grow_within_max_width", function () {
var config = Yoga.Config.create();
@@ -1013,114 +1112,3 @@ it("min_max_percent_no_width_height", function () {
config.free();
}
});
it("min_width_in_flex_distribution", function () {
var config = Yoga.Config.create();
try {
var root = Yoga.Node.create(config);
root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW);
root.setWidth(300);
root.setHeight(300);
var root_child0 = Yoga.Node.create(config);
root_child0.setFlexGrow(2);
root_child0.setFlexShrink(1);
root_child0.setFlexBasis("0%");
root_child0.setMinWidth(100);
root_child0.setMaxWidth(200);
root.insertChild(root_child0, 0);
var root_child1 = Yoga.Node.create(config);
root_child1.setFlexGrow(1);
root_child1.setFlexShrink(1);
root_child1.setFlexBasis("0%");
root.insertChild(root_child1, 1);
var root_child2 = Yoga.Node.create(config);
root_child2.setFlexGrow(1);
root_child2.setFlexShrink(1);
root_child2.setFlexBasis("0%");
root.insertChild(root_child2, 2);
var root_child3 = Yoga.Node.create(config);
root_child3.setFlexGrow(1);
root_child3.setFlexShrink(1);
root_child3.setFlexBasis("0%");
root.insertChild(root_child3, 3);
var root_child4 = Yoga.Node.create(config);
root_child4.setFlexGrow(1);
root_child4.setFlexShrink(1);
root_child4.setFlexBasis("0%");
root.insertChild(root_child4, 4);
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_LTR);
console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")");
console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")");
console.assert(300 === root.getComputedWidth(), "300 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
console.assert(300 === root.getComputedHeight(), "300 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")");
console.assert(100 === root_child0.getComputedWidth(), "100 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")");
console.assert(300 === root_child0.getComputedHeight(), "300 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
console.assert(100 === root_child1.getComputedLeft(), "100 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")");
console.assert(0 === root_child1.getComputedTop(), "0 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")");
console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")");
console.assert(300 === root_child1.getComputedHeight(), "300 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")");
console.assert(150 === root_child2.getComputedLeft(), "150 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")");
console.assert(0 === root_child2.getComputedTop(), "0 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")");
console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")");
console.assert(300 === root_child2.getComputedHeight(), "300 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")");
console.assert(200 === root_child3.getComputedLeft(), "200 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")");
console.assert(0 === root_child3.getComputedTop(), "0 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")");
console.assert(50 === root_child3.getComputedWidth(), "50 === root_child3.getComputedWidth() (" + root_child3.getComputedWidth() + ")");
console.assert(300 === root_child3.getComputedHeight(), "300 === root_child3.getComputedHeight() (" + root_child3.getComputedHeight() + ")");
console.assert(250 === root_child4.getComputedLeft(), "250 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")");
console.assert(0 === root_child4.getComputedTop(), "0 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")");
console.assert(50 === root_child4.getComputedWidth(), "50 === root_child4.getComputedWidth() (" + root_child4.getComputedWidth() + ")");
console.assert(300 === root_child4.getComputedHeight(), "300 === root_child4.getComputedHeight() (" + root_child4.getComputedHeight() + ")");
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_RTL);
console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")");
console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")");
console.assert(300 === root.getComputedWidth(), "300 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
console.assert(300 === root.getComputedHeight(), "300 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
console.assert(200 === root_child0.getComputedLeft(), "200 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")");
console.assert(100 === root_child0.getComputedWidth(), "100 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")");
console.assert(300 === root_child0.getComputedHeight(), "300 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
console.assert(150 === root_child1.getComputedLeft(), "150 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")");
console.assert(0 === root_child1.getComputedTop(), "0 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")");
console.assert(50 === root_child1.getComputedWidth(), "50 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")");
console.assert(300 === root_child1.getComputedHeight(), "300 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")");
console.assert(100 === root_child2.getComputedLeft(), "100 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")");
console.assert(0 === root_child2.getComputedTop(), "0 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")");
console.assert(50 === root_child2.getComputedWidth(), "50 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")");
console.assert(300 === root_child2.getComputedHeight(), "300 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")");
console.assert(50 === root_child3.getComputedLeft(), "50 === root_child3.getComputedLeft() (" + root_child3.getComputedLeft() + ")");
console.assert(0 === root_child3.getComputedTop(), "0 === root_child3.getComputedTop() (" + root_child3.getComputedTop() + ")");
console.assert(50 === root_child3.getComputedWidth(), "50 === root_child3.getComputedWidth() (" + root_child3.getComputedWidth() + ")");
console.assert(300 === root_child3.getComputedHeight(), "300 === root_child3.getComputedHeight() (" + root_child3.getComputedHeight() + ")");
console.assert(0 === root_child4.getComputedLeft(), "0 === root_child4.getComputedLeft() (" + root_child4.getComputedLeft() + ")");
console.assert(0 === root_child4.getComputedTop(), "0 === root_child4.getComputedTop() (" + root_child4.getComputedTop() + ")");
console.assert(50 === root_child4.getComputedWidth(), "50 === root_child4.getComputedWidth() (" + root_child4.getComputedWidth() + ")");
console.assert(300 === root_child4.getComputedHeight(), "300 === root_child4.getComputedHeight() (" + root_child4.getComputedHeight() + ")");
} finally {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});

View File

@@ -709,17 +709,17 @@ it("rounding_fractial_input_3", function () {
console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")");
console.assert(100 === root_child0.getComputedWidth(), "100 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")");
console.assert(64 === root_child0.getComputedHeight(), "64 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
console.assert(65 === root_child0.getComputedHeight(), "65 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
console.assert(0 === root_child1.getComputedLeft(), "0 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")");
console.assert(64 === root_child1.getComputedTop(), "64 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")");
console.assert(100 === root_child1.getComputedWidth(), "100 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")");
console.assert(25 === root_child1.getComputedHeight(), "25 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")");
console.assert(24 === root_child1.getComputedHeight(), "24 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")");
console.assert(0 === root_child2.getComputedLeft(), "0 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")");
console.assert(89 === root_child2.getComputedTop(), "89 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")");
console.assert(100 === root_child2.getComputedWidth(), "100 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")");
console.assert(24 === root_child2.getComputedHeight(), "24 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")");
console.assert(25 === root_child2.getComputedHeight(), "25 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")");
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_RTL);
@@ -731,17 +731,17 @@ it("rounding_fractial_input_3", function () {
console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")");
console.assert(100 === root_child0.getComputedWidth(), "100 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")");
console.assert(64 === root_child0.getComputedHeight(), "64 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
console.assert(65 === root_child0.getComputedHeight(), "65 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
console.assert(0 === root_child1.getComputedLeft(), "0 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")");
console.assert(64 === root_child1.getComputedTop(), "64 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")");
console.assert(100 === root_child1.getComputedWidth(), "100 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")");
console.assert(25 === root_child1.getComputedHeight(), "25 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")");
console.assert(24 === root_child1.getComputedHeight(), "24 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")");
console.assert(0 === root_child2.getComputedLeft(), "0 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")");
console.assert(89 === root_child2.getComputedTop(), "89 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")");
console.assert(100 === root_child2.getComputedWidth(), "100 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")");
console.assert(24 === root_child2.getComputedHeight(), "24 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")");
console.assert(25 === root_child2.getComputedHeight(), "25 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")");
} finally {
if (typeof root !== "undefined") {
root.freeRecursive();
@@ -827,3 +827,318 @@ it("rounding_fractial_input_4", function () {
config.free();
}
});
it("rounding_inner_node_controversy_horizontal", function () {
var config = Yoga.Config.create();
config.setExperimentalFeatureEnabled(Yoga.EXPERIMENTAL_FEATURE_ROUNDING, true);
try {
var root = Yoga.Node.create(config);
root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW);
root.setWidth(320);
var root_child0 = Yoga.Node.create(config);
root_child0.setFlexGrow(1);
root_child0.setHeight(10);
root.insertChild(root_child0, 0);
var root_child1 = Yoga.Node.create(config);
root_child1.setFlexGrow(1);
root_child1.setHeight(10);
root.insertChild(root_child1, 1);
var root_child1_child0 = Yoga.Node.create(config);
root_child1_child0.setFlexGrow(1);
root_child1_child0.setHeight(10);
root_child1.insertChild(root_child1_child0, 0);
var root_child2 = Yoga.Node.create(config);
root_child2.setFlexGrow(1);
root_child2.setHeight(10);
root.insertChild(root_child2, 2);
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_LTR);
console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")");
console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")");
console.assert(320 === root.getComputedWidth(), "320 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
console.assert(10 === root.getComputedHeight(), "10 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")");
console.assert(107 === root_child0.getComputedWidth(), "107 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")");
console.assert(10 === root_child0.getComputedHeight(), "10 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
console.assert(107 === root_child1.getComputedLeft(), "107 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")");
console.assert(0 === root_child1.getComputedTop(), "0 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")");
console.assert(106 === root_child1.getComputedWidth(), "106 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")");
console.assert(10 === root_child1.getComputedHeight(), "10 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")");
console.assert(0 === root_child1_child0.getComputedLeft(), "0 === root_child1_child0.getComputedLeft() (" + root_child1_child0.getComputedLeft() + ")");
console.assert(0 === root_child1_child0.getComputedTop(), "0 === root_child1_child0.getComputedTop() (" + root_child1_child0.getComputedTop() + ")");
console.assert(106 === root_child1_child0.getComputedWidth(), "106 === root_child1_child0.getComputedWidth() (" + root_child1_child0.getComputedWidth() + ")");
console.assert(10 === root_child1_child0.getComputedHeight(), "10 === root_child1_child0.getComputedHeight() (" + root_child1_child0.getComputedHeight() + ")");
console.assert(213 === root_child2.getComputedLeft(), "213 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")");
console.assert(0 === root_child2.getComputedTop(), "0 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")");
console.assert(107 === root_child2.getComputedWidth(), "107 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")");
console.assert(10 === root_child2.getComputedHeight(), "10 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")");
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_RTL);
console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")");
console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")");
console.assert(320 === root.getComputedWidth(), "320 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
console.assert(10 === root.getComputedHeight(), "10 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
console.assert(213 === root_child0.getComputedLeft(), "213 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")");
console.assert(107 === root_child0.getComputedWidth(), "107 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")");
console.assert(10 === root_child0.getComputedHeight(), "10 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
console.assert(107 === root_child1.getComputedLeft(), "107 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")");
console.assert(0 === root_child1.getComputedTop(), "0 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")");
console.assert(106 === root_child1.getComputedWidth(), "106 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")");
console.assert(10 === root_child1.getComputedHeight(), "10 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")");
console.assert(0 === root_child1_child0.getComputedLeft(), "0 === root_child1_child0.getComputedLeft() (" + root_child1_child0.getComputedLeft() + ")");
console.assert(0 === root_child1_child0.getComputedTop(), "0 === root_child1_child0.getComputedTop() (" + root_child1_child0.getComputedTop() + ")");
console.assert(106 === root_child1_child0.getComputedWidth(), "106 === root_child1_child0.getComputedWidth() (" + root_child1_child0.getComputedWidth() + ")");
console.assert(10 === root_child1_child0.getComputedHeight(), "10 === root_child1_child0.getComputedHeight() (" + root_child1_child0.getComputedHeight() + ")");
console.assert(0 === root_child2.getComputedLeft(), "0 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")");
console.assert(0 === root_child2.getComputedTop(), "0 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")");
console.assert(107 === root_child2.getComputedWidth(), "107 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")");
console.assert(10 === root_child2.getComputedHeight(), "10 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")");
} finally {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});
it("rounding_inner_node_controversy_vertical", function () {
var config = Yoga.Config.create();
config.setExperimentalFeatureEnabled(Yoga.EXPERIMENTAL_FEATURE_ROUNDING, true);
try {
var root = Yoga.Node.create(config);
root.setHeight(320);
var root_child0 = Yoga.Node.create(config);
root_child0.setFlexGrow(1);
root_child0.setWidth(10);
root.insertChild(root_child0, 0);
var root_child1 = Yoga.Node.create(config);
root_child1.setFlexGrow(1);
root_child1.setWidth(10);
root.insertChild(root_child1, 1);
var root_child1_child0 = Yoga.Node.create(config);
root_child1_child0.setFlexGrow(1);
root_child1_child0.setWidth(10);
root_child1.insertChild(root_child1_child0, 0);
var root_child2 = Yoga.Node.create(config);
root_child2.setFlexGrow(1);
root_child2.setWidth(10);
root.insertChild(root_child2, 2);
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_LTR);
console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")");
console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")");
console.assert(10 === root.getComputedWidth(), "10 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
console.assert(320 === root.getComputedHeight(), "320 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")");
console.assert(10 === root_child0.getComputedWidth(), "10 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")");
console.assert(107 === root_child0.getComputedHeight(), "107 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
console.assert(0 === root_child1.getComputedLeft(), "0 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")");
console.assert(107 === root_child1.getComputedTop(), "107 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")");
console.assert(10 === root_child1.getComputedWidth(), "10 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")");
console.assert(106 === root_child1.getComputedHeight(), "106 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")");
console.assert(0 === root_child1_child0.getComputedLeft(), "0 === root_child1_child0.getComputedLeft() (" + root_child1_child0.getComputedLeft() + ")");
console.assert(0 === root_child1_child0.getComputedTop(), "0 === root_child1_child0.getComputedTop() (" + root_child1_child0.getComputedTop() + ")");
console.assert(10 === root_child1_child0.getComputedWidth(), "10 === root_child1_child0.getComputedWidth() (" + root_child1_child0.getComputedWidth() + ")");
console.assert(106 === root_child1_child0.getComputedHeight(), "106 === root_child1_child0.getComputedHeight() (" + root_child1_child0.getComputedHeight() + ")");
console.assert(0 === root_child2.getComputedLeft(), "0 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")");
console.assert(213 === root_child2.getComputedTop(), "213 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")");
console.assert(10 === root_child2.getComputedWidth(), "10 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")");
console.assert(107 === root_child2.getComputedHeight(), "107 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")");
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_RTL);
console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")");
console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")");
console.assert(10 === root.getComputedWidth(), "10 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
console.assert(320 === root.getComputedHeight(), "320 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")");
console.assert(10 === root_child0.getComputedWidth(), "10 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")");
console.assert(107 === root_child0.getComputedHeight(), "107 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
console.assert(0 === root_child1.getComputedLeft(), "0 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")");
console.assert(107 === root_child1.getComputedTop(), "107 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")");
console.assert(10 === root_child1.getComputedWidth(), "10 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")");
console.assert(106 === root_child1.getComputedHeight(), "106 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")");
console.assert(0 === root_child1_child0.getComputedLeft(), "0 === root_child1_child0.getComputedLeft() (" + root_child1_child0.getComputedLeft() + ")");
console.assert(0 === root_child1_child0.getComputedTop(), "0 === root_child1_child0.getComputedTop() (" + root_child1_child0.getComputedTop() + ")");
console.assert(10 === root_child1_child0.getComputedWidth(), "10 === root_child1_child0.getComputedWidth() (" + root_child1_child0.getComputedWidth() + ")");
console.assert(106 === root_child1_child0.getComputedHeight(), "106 === root_child1_child0.getComputedHeight() (" + root_child1_child0.getComputedHeight() + ")");
console.assert(0 === root_child2.getComputedLeft(), "0 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")");
console.assert(213 === root_child2.getComputedTop(), "213 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")");
console.assert(10 === root_child2.getComputedWidth(), "10 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")");
console.assert(107 === root_child2.getComputedHeight(), "107 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")");
} finally {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});
it("rounding_inner_node_controversy_combined", function () {
var config = Yoga.Config.create();
config.setExperimentalFeatureEnabled(Yoga.EXPERIMENTAL_FEATURE_ROUNDING, true);
try {
var root = Yoga.Node.create(config);
root.setFlexDirection(Yoga.FLEX_DIRECTION_ROW);
root.setWidth(640);
root.setHeight(320);
var root_child0 = Yoga.Node.create(config);
root_child0.setFlexGrow(1);
root_child0.setHeight("100%");
root.insertChild(root_child0, 0);
var root_child1 = Yoga.Node.create(config);
root_child1.setFlexGrow(1);
root_child1.setHeight("100%");
root.insertChild(root_child1, 1);
var root_child1_child0 = Yoga.Node.create(config);
root_child1_child0.setFlexGrow(1);
root_child1_child0.setWidth("100%");
root_child1.insertChild(root_child1_child0, 0);
var root_child1_child1 = Yoga.Node.create(config);
root_child1_child1.setFlexGrow(1);
root_child1_child1.setWidth("100%");
root_child1.insertChild(root_child1_child1, 1);
var root_child1_child1_child0 = Yoga.Node.create(config);
root_child1_child1_child0.setFlexGrow(1);
root_child1_child1_child0.setWidth("100%");
root_child1_child1.insertChild(root_child1_child1_child0, 0);
var root_child1_child2 = Yoga.Node.create(config);
root_child1_child2.setFlexGrow(1);
root_child1_child2.setWidth("100%");
root_child1.insertChild(root_child1_child2, 2);
var root_child2 = Yoga.Node.create(config);
root_child2.setFlexGrow(1);
root_child2.setHeight("100%");
root.insertChild(root_child2, 2);
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_LTR);
console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")");
console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")");
console.assert(640 === root.getComputedWidth(), "640 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
console.assert(320 === root.getComputedHeight(), "320 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")");
console.assert(213 === root_child0.getComputedWidth(), "213 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")");
console.assert(320 === root_child0.getComputedHeight(), "320 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
console.assert(213 === root_child1.getComputedLeft(), "213 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")");
console.assert(0 === root_child1.getComputedTop(), "0 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")");
console.assert(214 === root_child1.getComputedWidth(), "214 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")");
console.assert(320 === root_child1.getComputedHeight(), "320 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")");
console.assert(0 === root_child1_child0.getComputedLeft(), "0 === root_child1_child0.getComputedLeft() (" + root_child1_child0.getComputedLeft() + ")");
console.assert(0 === root_child1_child0.getComputedTop(), "0 === root_child1_child0.getComputedTop() (" + root_child1_child0.getComputedTop() + ")");
console.assert(214 === root_child1_child0.getComputedWidth(), "214 === root_child1_child0.getComputedWidth() (" + root_child1_child0.getComputedWidth() + ")");
console.assert(107 === root_child1_child0.getComputedHeight(), "107 === root_child1_child0.getComputedHeight() (" + root_child1_child0.getComputedHeight() + ")");
console.assert(0 === root_child1_child1.getComputedLeft(), "0 === root_child1_child1.getComputedLeft() (" + root_child1_child1.getComputedLeft() + ")");
console.assert(107 === root_child1_child1.getComputedTop(), "107 === root_child1_child1.getComputedTop() (" + root_child1_child1.getComputedTop() + ")");
console.assert(214 === root_child1_child1.getComputedWidth(), "214 === root_child1_child1.getComputedWidth() (" + root_child1_child1.getComputedWidth() + ")");
console.assert(106 === root_child1_child1.getComputedHeight(), "106 === root_child1_child1.getComputedHeight() (" + root_child1_child1.getComputedHeight() + ")");
console.assert(0 === root_child1_child1_child0.getComputedLeft(), "0 === root_child1_child1_child0.getComputedLeft() (" + root_child1_child1_child0.getComputedLeft() + ")");
console.assert(0 === root_child1_child1_child0.getComputedTop(), "0 === root_child1_child1_child0.getComputedTop() (" + root_child1_child1_child0.getComputedTop() + ")");
console.assert(214 === root_child1_child1_child0.getComputedWidth(), "214 === root_child1_child1_child0.getComputedWidth() (" + root_child1_child1_child0.getComputedWidth() + ")");
console.assert(106 === root_child1_child1_child0.getComputedHeight(), "106 === root_child1_child1_child0.getComputedHeight() (" + root_child1_child1_child0.getComputedHeight() + ")");
console.assert(0 === root_child1_child2.getComputedLeft(), "0 === root_child1_child2.getComputedLeft() (" + root_child1_child2.getComputedLeft() + ")");
console.assert(213 === root_child1_child2.getComputedTop(), "213 === root_child1_child2.getComputedTop() (" + root_child1_child2.getComputedTop() + ")");
console.assert(214 === root_child1_child2.getComputedWidth(), "214 === root_child1_child2.getComputedWidth() (" + root_child1_child2.getComputedWidth() + ")");
console.assert(107 === root_child1_child2.getComputedHeight(), "107 === root_child1_child2.getComputedHeight() (" + root_child1_child2.getComputedHeight() + ")");
console.assert(427 === root_child2.getComputedLeft(), "427 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")");
console.assert(0 === root_child2.getComputedTop(), "0 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")");
console.assert(213 === root_child2.getComputedWidth(), "213 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")");
console.assert(320 === root_child2.getComputedHeight(), "320 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")");
root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_RTL);
console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")");
console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")");
console.assert(640 === root.getComputedWidth(), "640 === root.getComputedWidth() (" + root.getComputedWidth() + ")");
console.assert(320 === root.getComputedHeight(), "320 === root.getComputedHeight() (" + root.getComputedHeight() + ")");
console.assert(427 === root_child0.getComputedLeft(), "427 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")");
console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")");
console.assert(213 === root_child0.getComputedWidth(), "213 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")");
console.assert(320 === root_child0.getComputedHeight(), "320 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")");
console.assert(213 === root_child1.getComputedLeft(), "213 === root_child1.getComputedLeft() (" + root_child1.getComputedLeft() + ")");
console.assert(0 === root_child1.getComputedTop(), "0 === root_child1.getComputedTop() (" + root_child1.getComputedTop() + ")");
console.assert(214 === root_child1.getComputedWidth(), "214 === root_child1.getComputedWidth() (" + root_child1.getComputedWidth() + ")");
console.assert(320 === root_child1.getComputedHeight(), "320 === root_child1.getComputedHeight() (" + root_child1.getComputedHeight() + ")");
console.assert(0 === root_child1_child0.getComputedLeft(), "0 === root_child1_child0.getComputedLeft() (" + root_child1_child0.getComputedLeft() + ")");
console.assert(0 === root_child1_child0.getComputedTop(), "0 === root_child1_child0.getComputedTop() (" + root_child1_child0.getComputedTop() + ")");
console.assert(214 === root_child1_child0.getComputedWidth(), "214 === root_child1_child0.getComputedWidth() (" + root_child1_child0.getComputedWidth() + ")");
console.assert(107 === root_child1_child0.getComputedHeight(), "107 === root_child1_child0.getComputedHeight() (" + root_child1_child0.getComputedHeight() + ")");
console.assert(0 === root_child1_child1.getComputedLeft(), "0 === root_child1_child1.getComputedLeft() (" + root_child1_child1.getComputedLeft() + ")");
console.assert(107 === root_child1_child1.getComputedTop(), "107 === root_child1_child1.getComputedTop() (" + root_child1_child1.getComputedTop() + ")");
console.assert(214 === root_child1_child1.getComputedWidth(), "214 === root_child1_child1.getComputedWidth() (" + root_child1_child1.getComputedWidth() + ")");
console.assert(106 === root_child1_child1.getComputedHeight(), "106 === root_child1_child1.getComputedHeight() (" + root_child1_child1.getComputedHeight() + ")");
console.assert(0 === root_child1_child1_child0.getComputedLeft(), "0 === root_child1_child1_child0.getComputedLeft() (" + root_child1_child1_child0.getComputedLeft() + ")");
console.assert(0 === root_child1_child1_child0.getComputedTop(), "0 === root_child1_child1_child0.getComputedTop() (" + root_child1_child1_child0.getComputedTop() + ")");
console.assert(214 === root_child1_child1_child0.getComputedWidth(), "214 === root_child1_child1_child0.getComputedWidth() (" + root_child1_child1_child0.getComputedWidth() + ")");
console.assert(106 === root_child1_child1_child0.getComputedHeight(), "106 === root_child1_child1_child0.getComputedHeight() (" + root_child1_child1_child0.getComputedHeight() + ")");
console.assert(0 === root_child1_child2.getComputedLeft(), "0 === root_child1_child2.getComputedLeft() (" + root_child1_child2.getComputedLeft() + ")");
console.assert(213 === root_child1_child2.getComputedTop(), "213 === root_child1_child2.getComputedTop() (" + root_child1_child2.getComputedTop() + ")");
console.assert(214 === root_child1_child2.getComputedWidth(), "214 === root_child1_child2.getComputedWidth() (" + root_child1_child2.getComputedWidth() + ")");
console.assert(107 === root_child1_child2.getComputedHeight(), "107 === root_child1_child2.getComputedHeight() (" + root_child1_child2.getComputedHeight() + ")");
console.assert(0 === root_child2.getComputedLeft(), "0 === root_child2.getComputedLeft() (" + root_child2.getComputedLeft() + ")");
console.assert(0 === root_child2.getComputedTop(), "0 === root_child2.getComputedTop() (" + root_child2.getComputedTop() + ")");
console.assert(213 === root_child2.getComputedWidth(), "213 === root_child2.getComputedWidth() (" + root_child2.getComputedWidth() + ")");
console.assert(320 === root_child2.getComputedHeight(), "320 === root_child2.getComputedHeight() (" + root_child2.getComputedHeight() + ")");
} finally {
if (typeof root !== "undefined") {
root.freeRecursive();
}
config.free();
}
});

View File

@@ -21,7 +21,7 @@ prebuilt_cxx_library(
cxx_library(
name = "fbjni",
srcs = glob(["**/*.cpp"]),
srcs = glob(["src/main/cpp/**/*.cpp"]),
compiler_flags = [
"-DLOG_TAG=\"libfb\"",
"-DDISABLE_CPUCAP",
@@ -35,7 +35,7 @@ cxx_library(
"-Wno-unused-parameter",
"-std=c++11",
],
exported_headers = subdir_glob([("include", "**/*.h")]),
exported_headers = subdir_glob([("src/main/cpp/include", "**/*.h")]),
header_namespace = "",
visibility = ["PUBLIC"],
deps = [

27
lib/fb/build.gradle Normal file
View File

@@ -0,0 +1,27 @@
apply plugin: 'com.android.library'
android {
compileSdkVersion rootProject.compileSdkVersion
buildToolsVersion rootProject.buildToolsVersion
defaultConfig {
minSdkVersion rootProject.minSdkVersion
targetSdkVersion rootProject.targetSdkVersion
ndk {
abiFilters 'x86', 'x86_64', 'armeabi', 'armeabi-v7a', 'arm64-v8a'
}
externalNativeBuild {
cmake {
arguments '-DANDROID_TOOLCHAIN=clang', '-DANDROID_STL=c++_static'
}
}
}
externalNativeBuild {
cmake {
path 'src/main/cpp/CMakeLists.txt'
}
}
}

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (c) 2014-present, Facebook, Inc.
All rights reserved.
This source code is licensed under the BSD-style license found in the
LICENSE file in the root directory of this source tree. An additional grant
of patent rights can be found in the PATENTS file in the same directory.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.facebook.libfb">
</manifest>

View File

@@ -0,0 +1,33 @@
#
# Copyright (c) 2014-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree. An additional grant
# of patent rights can be found in the PATENTS file in the same directory.
#
cmake_minimum_required(VERSION 3.4.1)
set(CMAKE_VERBOSE_MAKEFILE on)
add_compile_options(
-fno-omit-frame-pointer
-fexceptions
-Wall
-std=c++11
-DDISABLE_CPUCAP
-DDISABLE_XPLAT)
file(GLOB fb_SRC
*.cpp
jni/*.cpp
lyra/*.cpp)
add_library(fb SHARED
${fb_SRC})
target_include_directories(fb PRIVATE
include)
target_link_libraries(fb android log)

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