Compare commits
157 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
24e2fc95dd | ||
|
ce3f99939f | ||
|
11bc97b16c | ||
|
4804bcd594 | ||
|
ca2c607f90 | ||
|
6c67684fa6 | ||
|
835b2bbae8 | ||
|
47edd2586c | ||
|
ca483cae00 | ||
|
a20bde8444 | ||
|
ac885626b3 | ||
|
976ecc6816 | ||
|
d2f22283bb | ||
|
56b10fc35b | ||
|
5a3ceffba1 | ||
|
b378a685a4 | ||
|
fa50f048f1 | ||
|
f68b50bb4b | ||
|
aad1c3055c | ||
|
cd1dbc3f0f | ||
|
bf4ff0769d | ||
|
a141ebfb50 | ||
|
2fb01daf70 | ||
|
e9e1e084da | ||
|
629e401deb | ||
|
f4c2b6ae63 | ||
|
4487862227 | ||
|
927eca6604 | ||
|
f2612192c5 | ||
|
49bccf47fa | ||
|
fa54167a20 | ||
|
50feb21cb3 | ||
|
52ce5828c9 | ||
|
9cdaedfcb5 | ||
|
adad054cad | ||
|
b2b0c7ee37 | ||
|
488a7c1fe0 | ||
|
85c2e406e4 | ||
|
dcf57d2f7e | ||
|
3fefe9fc49 | ||
|
626a05fb6f | ||
|
ffcd2cfc8a | ||
|
181101c92d | ||
|
3db6804202 | ||
|
3fb135829d | ||
|
2c91e1e7d2 | ||
|
c3982b6c1e | ||
|
ae33c6c19c | ||
|
bcd68b997f | ||
|
fcfa1b9f01 | ||
|
d9a0822517 | ||
|
097e99b699 | ||
|
ff7bec703b | ||
|
c7ab004922 | ||
|
91230ae177 | ||
|
40eba60cf5 | ||
|
fb4cfed20d | ||
|
d3a9a84ac4 | ||
|
accad5366f | ||
|
8eca67e257 | ||
|
40e1bf6ce3 | ||
|
7b89a1dd48 | ||
|
203577724e | ||
|
e3dbef7cbd | ||
|
0ee3303791 | ||
|
83fddd8af6 | ||
|
77c05b5ff6 | ||
|
7c324f058c | ||
|
3db38f2a80 | ||
|
f6b17183c5 | ||
|
8f9d7e243e | ||
|
fde4db9383 | ||
|
3178e3bf15 | ||
|
cdfd05c742 | ||
|
76f6a54327 | ||
|
c91e4b3566 | ||
|
e24561bcef | ||
|
363e941867 | ||
|
3fb2c1888c | ||
|
aa5b296ac7 | ||
|
f2b5d0fef7 | ||
|
0684795a89 | ||
|
2ffc23f400 | ||
|
dc4d16401f | ||
|
849de89a58 | ||
|
f8a2903d02 | ||
|
60977de242 | ||
|
cb612bcfbe | ||
|
6be1c2cdb4 | ||
|
034ab0b3b1 | ||
|
8c50347f3c | ||
|
9f76fb6980 | ||
|
8b0ff0a25c | ||
|
8891ea1a7a | ||
|
ede2ad94bc | ||
|
eacf3cdbb4 | ||
|
3569a13b74 | ||
|
b2a96ec744 | ||
|
a505adb2b7 | ||
|
906b6e52f8 | ||
|
3292337754 | ||
|
eb4af86e3c | ||
|
1b3e971549 | ||
|
4615eee2d8 | ||
|
7c57245943 | ||
|
0d100ad7e9 | ||
|
0235789863 | ||
|
c080a46571 | ||
|
5f050cb590 | ||
|
25f14a1917 | ||
|
e9927377b5 | ||
|
3ea76f8a9b | ||
|
8a45ed9671 | ||
|
1520749351 | ||
|
f66f52d1ba | ||
|
49e18738c3 | ||
|
586b57009a | ||
|
5112564f08 | ||
|
34726a9926 | ||
|
5884ab7b76 | ||
|
60db018ce4 | ||
|
6b002bad3d | ||
|
5b173c1b61 | ||
|
bc2fb5c7ab | ||
|
ebdf82f491 | ||
|
36f6fa9861 | ||
|
91a34bb875 | ||
|
d342fb1879 | ||
|
b283572453 | ||
|
62a74a5ef9 | ||
|
a14aeb27bb | ||
|
249d010dad | ||
|
9b13fdeae4 | ||
|
794b6b35ce | ||
|
dcff4d3db2 | ||
|
b94466e502 | ||
|
11052053d8 | ||
|
6ab3984bba | ||
|
136e0c7e52 | ||
|
7e2ef926ea | ||
|
061981fb23 | ||
|
3d6fb2f2e5 | ||
|
a8e6123d47 | ||
|
406c8a2117 | ||
|
0445962bd4 | ||
|
09f0c2d8ce | ||
|
8dea884a69 | ||
|
57898762a2 | ||
|
01bf8d7b6c | ||
|
af8d55c08e | ||
|
53398b42c6 | ||
|
1bf142e048 | ||
|
0405c4f77d | ||
|
61595763b0 | ||
|
f6ecc8da7b | ||
|
32792a0de5 | ||
|
c3d60b55bd |
@@ -1,9 +1,9 @@
|
||||
[cxx]
|
||||
gtest_dep = //lib/gtest:gtest
|
||||
[android]
|
||||
target = Google Inc.:Google APIs:19
|
||||
target = android-23
|
||||
[ndk]
|
||||
ndk_version = 12.1.2977051
|
||||
ndk_version = 13.1.3345770
|
||||
compiler = clang
|
||||
app_platform = android-19
|
||||
cpu_abis = armv7, x86
|
||||
app_platform = android-21
|
||||
cpu_abis = arm64, armv7, x86, x86_64
|
||||
|
11
.editorconfig
Normal file
11
.editorconfig
Normal file
@@ -0,0 +1,11 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
2
.gitignore
vendored
2
.gitignore
vendored
@@ -63,3 +63,5 @@ Carthage/Build
|
||||
|
||||
# Gradle
|
||||
.gradle
|
||||
# NDK/CMake
|
||||
.externalNativeBuild
|
||||
|
40
.travis.yml
40
.travis.yml
@@ -9,6 +9,9 @@ os: osx
|
||||
osx_image: xcode8.2
|
||||
language: cpp
|
||||
compiler: clang
|
||||
cache:
|
||||
directories:
|
||||
- $HOME/Library/Caches/Homebrew
|
||||
|
||||
env:
|
||||
- TARGET=c
|
||||
@@ -19,9 +22,13 @@ env:
|
||||
- TARGET=android
|
||||
|
||||
before_install:
|
||||
- |
|
||||
if [[ -n "$encrypted_d27e803291ff_iv" ]]; then
|
||||
openssl aes-256-cbc -K $encrypted_d27e803291ff_key -iv $encrypted_d27e803291ff_iv -in scripts/setup-keys.enc -d >> gradle.properties;
|
||||
fi
|
||||
|
||||
- brew update > /dev/null
|
||||
- brew tap facebook/fb
|
||||
- brew install buck
|
||||
- brew install --HEAD facebook/fb/buck
|
||||
|
||||
# Java
|
||||
- |
|
||||
@@ -40,7 +47,11 @@ before_install:
|
||||
# iOS
|
||||
- |
|
||||
if [[ $TARGET = "ios" ]]; then
|
||||
brew outdated xctool || brew upgrade xctool
|
||||
brew outdated xctool || brew upgrade xctool;
|
||||
gem install xcpretty --no-document --quiet;
|
||||
gem install cocoapods --pre --no-document --quiet;
|
||||
pod repo update --silent;
|
||||
pod install --project-directory=YogaKit/YogaKitSample/;
|
||||
fi
|
||||
|
||||
# Emscripten (used for js tests)
|
||||
@@ -49,8 +60,8 @@ before_install:
|
||||
if [[ $TARGET = "js" ]]; then
|
||||
wget -O /tmp/emsdk-portable.tar.gz https://s3.amazonaws.com/mozilla-games/emscripten/releases/emsdk-portable.tar.gz &&
|
||||
tar xf /tmp/emsdk-portable.tar.gz -C /tmp/ &&
|
||||
/tmp/emsdk_portable/emsdk install latest >& /dev/null &&
|
||||
/tmp/emsdk_portable/emsdk activate latest
|
||||
/tmp/emsdk-portable/emsdk install latest 2>&1 | grep -v '^x ' &&
|
||||
/tmp/emsdk-portable/emsdk activate latest
|
||||
fi
|
||||
|
||||
# Android
|
||||
@@ -59,12 +70,9 @@ before_install:
|
||||
brew cask install java;
|
||||
export JAVA_HOME=$(/usr/libexec/java_home -v 1.8);
|
||||
export PATH=$JAVA_HOME/bin:$PATH;
|
||||
brew install android-sdk;
|
||||
export ANDROID_SDK=/usr/local/Cellar/android-sdk/24.4.1_1;
|
||||
export ANDROID_HOME=/usr/local/Cellar/android-sdk/24.4.1_1;
|
||||
brew install lib32stdc++6 lib32z1;
|
||||
echo y | $ANDROID_SDK/tools/android update sdk --filter android-19,addon-google_apis-google-19,build-tools-19.1.0 --no-ui;
|
||||
echo y | $ANDROID_SDK/tools/android update sdk -u;
|
||||
export TERMINAL=dumb;
|
||||
source scripts/android-setup.sh && installAndroidSDK
|
||||
export ANDROID_SDK=$ANDROID_HOME
|
||||
fi
|
||||
|
||||
# JavaScript
|
||||
@@ -73,7 +81,7 @@ before_install:
|
||||
cd javascript &&
|
||||
npm install &&
|
||||
unset CC && unset CXX && unset LINK &&
|
||||
source /tmp/emsdk_portable/emsdk_env.sh &&
|
||||
source /tmp/emsdk-portable/emsdk_env.sh &&
|
||||
npm run build:browser
|
||||
) fi
|
||||
|
||||
@@ -102,13 +110,17 @@ script:
|
||||
# iOS
|
||||
- |
|
||||
if [[ $TARGET = "ios" ]]; then
|
||||
buck test --verbose 0 //YogaKit:YogaKitTests --config cxx.default_platform=iphonesimulator-x86_64
|
||||
buck test --verbose 0 //YogaKit:YogaKitTests --config cxx.default_platform=iphonesimulator-x86_64 &&
|
||||
set -o pipefail &&
|
||||
xcodebuild build -workspace YogaKit/YogaKitSample/YogaKitSample.xcworkspace -scheme YogaKitSample -sdk iphonesimulator | xcpretty -c
|
||||
fi
|
||||
|
||||
# Android
|
||||
- |
|
||||
if [[ $TARGET = "android" ]]; then
|
||||
buck build --verbose 0 //android/sample:sample
|
||||
buck build --verbose 0 //android/sample:sample &&
|
||||
./gradlew testDebugUnit &&
|
||||
scripts/publish-snapshot.sh
|
||||
fi
|
||||
|
||||
# JavaScript
|
||||
|
3
BUCK
3
BUCK
@@ -12,9 +12,8 @@ GMOCK_OVERRIDE_FLAGS = [
|
||||
"-Wno-inconsistent-missing-override",
|
||||
]
|
||||
|
||||
COMPILER_FLAGS = BASE_COMPILER_FLAGS + [
|
||||
COMPILER_FLAGS = LIBRARY_COMPILER_FLAGS + [
|
||||
"-std=c11",
|
||||
"-fPIC",
|
||||
]
|
||||
|
||||
TEST_COMPILER_FLAGS = BASE_COMPILER_FLAGS + GMOCK_OVERRIDE_FLAGS + ["-std=c++11"]
|
||||
|
17
CMakeLists.txt
Normal file
17
CMakeLists.txt
Normal 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)
|
28
README.md
28
README.md
@@ -1,4 +1,4 @@
|
||||
# Yoga [](http://cocoapods.org/pods/YogaKit) [](https://www.npmjs.com/package/yoga-layout)
|
||||
# Yoga [](http://cocoapods.org/pods/YogaKit) [](https://www.npmjs.com/package/yoga-layout) [](https://bintray.com/facebook/maven/com.facebook.yoga%3Ayoga/_latestVersion) [](https://www.nuget.org/packages/Facebook.Yoga)
|
||||
|
||||
[](https://travis-ci.org/facebook/yoga)
|
||||
[](https://travis-ci.org/facebook/yoga)
|
||||
@@ -7,6 +7,9 @@
|
||||
[](https://travis-ci.org/facebook/yoga)
|
||||
[](https://travis-ci.org/facebook/yoga)
|
||||
|
||||
[]()
|
||||
[]()
|
||||
|
||||
## Building
|
||||
Yoga builds with [buck](https://buckbuild.com). Make sure you install buck before contributing to Yoga. Yoga's main implementation is in C, with bindings to supported languages and frameworks. When making changes to Yoga please ensure the changes are also propagated to these bindings when applicable.
|
||||
|
||||
@@ -35,3 +38,26 @@ For the main C implementation of Yoga clang-format is used to ensure a consisten
|
||||
|
||||
## Benchmarks
|
||||
Benchmarks are located in `benchmark/YGBenchmark.c` and can be run with `buck run //benchmark:benchmark`. If you think your change has affected performance please run this before and after your change to validate that nothing has regressed. Benchmarks are run on every commit in CI.
|
||||
|
||||
### JavaScript
|
||||
Installing through NPM
|
||||
```sh
|
||||
npm install yoga-layout
|
||||
```
|
||||
By default this will install the library and try to build for all platforms (node, browser asm, and standalone webpack). You may receive errors if you do not have the required platform development tools already installed. To preset the platform you'd like to build for you can set a .npmrc property first.
|
||||
```sh
|
||||
npm config set yoga-layout:platform standalone
|
||||
```
|
||||
This will now only run the standalone webpack build upon install.
|
||||
|
||||
## Build Platforms
|
||||
|
||||
| name | description |
|
||||
|----------------|-------------------------------------------------|
|
||||
| all (default) | Builds all of these platforms. |
|
||||
| browser | Builds asm js browser version. |
|
||||
| node | Builds node js version. |
|
||||
| standalone | Runs webpack. |
|
||||
| none | Does nothing. You can use the prepackaged libs. |
|
||||
|
||||
|
||||
|
@@ -1,14 +1,15 @@
|
||||
|
||||
YOGA_ROOT = '//...'
|
||||
YOGA_ROOTS = ['//...']
|
||||
JAVA_TARGET = '//java:java'
|
||||
INFER_ANNOTATIONS_TARGET = '//lib/infer-annotations:infer-annotations'
|
||||
JSR_305_TARGET = '//lib/jsr-305:jsr-305'
|
||||
JUNIT_TARGET = '//lib/junit:junit'
|
||||
PROGRUARD_ANNOTATIONS_TARGET = '//java/com/facebook/proguard/annotations:annotations'
|
||||
PROGRUARD_ANNOTATIONS_TARGET = '//java/proguard-annotations/src/main/java/com/facebook/proguard/annotations:annotations'
|
||||
SOLOADER_TARGET = '//lib/soloader:soloader'
|
||||
GTEST_TARGET = '//lib/gtest:gtest'
|
||||
JNI_TARGET = '//lib/jni:jni'
|
||||
FBJNI_TARGET = '//lib/fb:fbjni'
|
||||
FBJNI_JAVA_TARGET = '//lib/fb/src/main/java/com/facebook/jni:jni'
|
||||
APPCOMPAT_TARGET = '//lib/appcompat:appcompat'
|
||||
ANDROID_SUPPORT_TARGET = '//lib/android-support:android-support'
|
||||
ANDROID_TARGET = '//android:android'
|
||||
@@ -33,6 +34,10 @@ BASE_COMPILER_FLAGS = [
|
||||
'-O3',
|
||||
]
|
||||
|
||||
LIBRARY_COMPILER_FLAGS = BASE_COMPILER_FLAGS + [
|
||||
'-fPIC',
|
||||
]
|
||||
|
||||
def yoga_dep(dep):
|
||||
return '//' + dep
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
Pod::Spec.new do |spec|
|
||||
spec.name = 'Yoga'
|
||||
spec.version = '1.2.0'
|
||||
spec.version = '1.5.0'
|
||||
spec.license = { :type => 'BSD', :file => "LICENSE" }
|
||||
spec.homepage = 'https://facebook.github.io/yoga/'
|
||||
spec.documentation_url = 'https://facebook.github.io/yoga/docs/api/c/'
|
||||
@@ -11,7 +11,7 @@ Pod::Spec.new do |spec|
|
||||
spec.authors = 'Facebook'
|
||||
spec.source = {
|
||||
:git => 'https://github.com/facebook/yoga.git',
|
||||
:tag => '1.2.0',
|
||||
:tag => '1.5.0',
|
||||
}
|
||||
|
||||
spec.module_name = 'yoga'
|
||||
|
@@ -1,6 +1,6 @@
|
||||
podspec = Pod::Spec.new do |spec|
|
||||
spec.name = 'YogaKit'
|
||||
spec.version = '1.2.0'
|
||||
spec.version = '1.5.0'
|
||||
spec.license = { :type => 'BSD', :file => "LICENSE" }
|
||||
spec.homepage = 'https://facebook.github.io/yoga/'
|
||||
spec.documentation_url = 'https://facebook.github.io/yoga/docs/api/yogakit/'
|
||||
@@ -11,15 +11,15 @@ podspec = Pod::Spec.new do |spec|
|
||||
spec.authors = 'Facebook'
|
||||
spec.source = {
|
||||
:git => 'https://github.com/facebook/yoga.git',
|
||||
:tag => '1.2.0',
|
||||
:tag => '1.5.0',
|
||||
}
|
||||
|
||||
spec.platform = :ios
|
||||
spec.ios.deployment_target = '8.0'
|
||||
spec.ios.frameworks = 'UIKit'
|
||||
|
||||
spec.dependency 'Yoga', '~> 1.2'
|
||||
spec.source_files = 'YogaKit/Source/*.{h,m}'
|
||||
spec.dependency 'Yoga', '~> 1.5'
|
||||
spec.source_files = 'YogaKit/Source/*.{h,m,swift}'
|
||||
spec.public_header_files = 'YogaKit/Source/{YGLayout,UIView+Yoga}.h'
|
||||
spec.private_header_files = 'YogaKit/Source/YGLayout+Private.h'
|
||||
end
|
||||
|
@@ -1,46 +0,0 @@
|
||||
# CHANGELOG
|
||||
|
||||
The changelog for `YogaKit`.
|
||||
|
||||
1.2.0 (**upcoming release**)
|
||||
-----
|
||||
|
||||
### Breaking Changes
|
||||
|
||||
- `applyLayout()` has now been changed to `applyLayout(preservingOrigin:)`.
|
||||
|
||||
- Computed properties are no longer reflected in getter's of the affected properties.
|
||||
```swift
|
||||
// OLD
|
||||
view.yoga.margin = 10
|
||||
view.yoga.marginTop // 10
|
||||
view.yoga.marginLeft // 10
|
||||
|
||||
// NEW
|
||||
view.yoga.margin = 10
|
||||
view.yoga.marginTop // 0
|
||||
view.yoga.marginLeft // 0
|
||||
```
|
||||
|
||||
### Enhancements
|
||||
|
||||
- Pixel Rounding now uses `roundf()` instead of `round()`.
|
||||
|
||||
- There is now a method that allows "bulk" updates to YGLayout.
|
||||
```objc
|
||||
[view configureLayoutWithBlock:^(YGLayout *layout) {
|
||||
layout.isEnabled = YES;
|
||||
layout.width = 50;
|
||||
layout.height = 50;
|
||||
}];
|
||||
```
|
||||
|
||||
```swift
|
||||
view.configureLayout { (layout) in
|
||||
layout.isEnabled = true
|
||||
layout.width = 50
|
||||
layout.height = 50
|
||||
}
|
||||
```
|
||||
|
||||
- Added new `isDirty` property, and make `markDirty` a little more performant.
|
@@ -8,7 +8,7 @@
|
||||
YogaKit is available to install via [CocoaPods](https://cocoapods.org/).
|
||||
|
||||
```
|
||||
pod 'YogaKit', '~> 1.1'
|
||||
pod 'YogaKit', '~> 1.5'
|
||||
```
|
||||
|
||||
## Getting Started
|
||||
@@ -19,4 +19,4 @@ We also have a sample project. To try it out, clone this repo and open `YogaKitS
|
||||
## Contributing
|
||||
We welcome all pull-requests! At Facebook we sync the open source version of `YogaKit` daily, so we're always testing the latest changes.
|
||||
|
||||
See the [CONTRIBUTING](https://github.com/facebook/yoga/blob/master/CONTRIBUTING) file for how to help out.
|
||||
See the [CONTRIBUTING.md](https://github.com/facebook/yoga/blob/master/CONTRIBUTING.md) file for how to help out.
|
||||
|
@@ -9,6 +9,22 @@
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import <yoga/YGEnums.h>
|
||||
#import <yoga/Yoga.h>
|
||||
#import <yoga/YGMacros.h>
|
||||
|
||||
YG_EXTERN_C_BEGIN
|
||||
|
||||
extern YGValue YGPointValue(CGFloat value)
|
||||
NS_SWIFT_UNAVAILABLE("Use the swift Int and FloatingPoint extensions instead");
|
||||
extern YGValue YGPercentValue(CGFloat value)
|
||||
NS_SWIFT_UNAVAILABLE("Use the swift Int and FloatingPoint extensions instead");
|
||||
|
||||
YG_EXTERN_C_END
|
||||
|
||||
typedef NS_OPTIONS(NSInteger, YGDimensionFlexibility) {
|
||||
YGDimensionFlexibilityFlexibleWidth = 1 << 0,
|
||||
YGDimensionFlexibilityFlexibleHeigth = 1 << 1,
|
||||
};
|
||||
|
||||
@interface YGLayout : NSObject
|
||||
|
||||
@@ -36,34 +52,34 @@
|
||||
|
||||
@property (nonatomic, readwrite, assign) CGFloat flexGrow;
|
||||
@property (nonatomic, readwrite, assign) CGFloat flexShrink;
|
||||
@property (nonatomic, readwrite, assign) CGFloat flexBasis;
|
||||
@property (nonatomic, readwrite, assign) YGValue flexBasis;
|
||||
|
||||
@property (nonatomic, readwrite, assign) CGFloat left;
|
||||
@property (nonatomic, readwrite, assign) CGFloat top;
|
||||
@property (nonatomic, readwrite, assign) CGFloat right;
|
||||
@property (nonatomic, readwrite, assign) CGFloat bottom;
|
||||
@property (nonatomic, readwrite, assign) CGFloat start;
|
||||
@property (nonatomic, readwrite, assign) CGFloat end;
|
||||
@property (nonatomic, readwrite, assign) YGValue left;
|
||||
@property (nonatomic, readwrite, assign) YGValue top;
|
||||
@property (nonatomic, readwrite, assign) YGValue right;
|
||||
@property (nonatomic, readwrite, assign) YGValue bottom;
|
||||
@property (nonatomic, readwrite, assign) YGValue start;
|
||||
@property (nonatomic, readwrite, assign) YGValue end;
|
||||
|
||||
@property (nonatomic, readwrite, assign) CGFloat marginLeft;
|
||||
@property (nonatomic, readwrite, assign) CGFloat marginTop;
|
||||
@property (nonatomic, readwrite, assign) CGFloat marginRight;
|
||||
@property (nonatomic, readwrite, assign) CGFloat marginBottom;
|
||||
@property (nonatomic, readwrite, assign) CGFloat marginStart;
|
||||
@property (nonatomic, readwrite, assign) CGFloat marginEnd;
|
||||
@property (nonatomic, readwrite, assign) CGFloat marginHorizontal;
|
||||
@property (nonatomic, readwrite, assign) CGFloat marginVertical;
|
||||
@property (nonatomic, readwrite, assign) CGFloat margin;
|
||||
@property (nonatomic, readwrite, assign) YGValue marginLeft;
|
||||
@property (nonatomic, readwrite, assign) YGValue marginTop;
|
||||
@property (nonatomic, readwrite, assign) YGValue marginRight;
|
||||
@property (nonatomic, readwrite, assign) YGValue marginBottom;
|
||||
@property (nonatomic, readwrite, assign) YGValue marginStart;
|
||||
@property (nonatomic, readwrite, assign) YGValue marginEnd;
|
||||
@property (nonatomic, readwrite, assign) YGValue marginHorizontal;
|
||||
@property (nonatomic, readwrite, assign) YGValue marginVertical;
|
||||
@property (nonatomic, readwrite, assign) YGValue margin;
|
||||
|
||||
@property (nonatomic, readwrite, assign) CGFloat paddingLeft;
|
||||
@property (nonatomic, readwrite, assign) CGFloat paddingTop;
|
||||
@property (nonatomic, readwrite, assign) CGFloat paddingRight;
|
||||
@property (nonatomic, readwrite, assign) CGFloat paddingBottom;
|
||||
@property (nonatomic, readwrite, assign) CGFloat paddingStart;
|
||||
@property (nonatomic, readwrite, assign) CGFloat paddingEnd;
|
||||
@property (nonatomic, readwrite, assign) CGFloat paddingHorizontal;
|
||||
@property (nonatomic, readwrite, assign) CGFloat paddingVertical;
|
||||
@property (nonatomic, readwrite, assign) CGFloat padding;
|
||||
@property (nonatomic, readwrite, assign) YGValue paddingLeft;
|
||||
@property (nonatomic, readwrite, assign) YGValue paddingTop;
|
||||
@property (nonatomic, readwrite, assign) YGValue paddingRight;
|
||||
@property (nonatomic, readwrite, assign) YGValue paddingBottom;
|
||||
@property (nonatomic, readwrite, assign) YGValue paddingStart;
|
||||
@property (nonatomic, readwrite, assign) YGValue paddingEnd;
|
||||
@property (nonatomic, readwrite, assign) YGValue paddingHorizontal;
|
||||
@property (nonatomic, readwrite, assign) YGValue paddingVertical;
|
||||
@property (nonatomic, readwrite, assign) YGValue padding;
|
||||
|
||||
@property (nonatomic, readwrite, assign) CGFloat borderLeftWidth;
|
||||
@property (nonatomic, readwrite, assign) CGFloat borderTopWidth;
|
||||
@@ -73,12 +89,12 @@
|
||||
@property (nonatomic, readwrite, assign) CGFloat borderEndWidth;
|
||||
@property (nonatomic, readwrite, assign) CGFloat borderWidth;
|
||||
|
||||
@property (nonatomic, readwrite, assign) CGFloat width;
|
||||
@property (nonatomic, readwrite, assign) CGFloat height;
|
||||
@property (nonatomic, readwrite, assign) CGFloat minWidth;
|
||||
@property (nonatomic, readwrite, assign) CGFloat minHeight;
|
||||
@property (nonatomic, readwrite, assign) CGFloat maxWidth;
|
||||
@property (nonatomic, readwrite, assign) CGFloat maxHeight;
|
||||
@property (nonatomic, readwrite, assign) YGValue width;
|
||||
@property (nonatomic, readwrite, assign) YGValue height;
|
||||
@property (nonatomic, readwrite, assign) YGValue minWidth;
|
||||
@property (nonatomic, readwrite, assign) YGValue minHeight;
|
||||
@property (nonatomic, readwrite, assign) YGValue maxWidth;
|
||||
@property (nonatomic, readwrite, assign) YGValue maxHeight;
|
||||
|
||||
// Yoga specific properties, not compatible with flexbox specification
|
||||
@property (nonatomic, readwrite, assign) CGFloat aspectRatio;
|
||||
@@ -95,12 +111,26 @@
|
||||
- (void)applyLayoutPreservingOrigin:(BOOL)preserveOrigin
|
||||
NS_SWIFT_NAME(applyLayout(preservingOrigin:));
|
||||
|
||||
/**
|
||||
Perform a layout calculation and update the frames of the views in the hierarchy with the results.
|
||||
If the origin is not preserved, the root view's layout results will applied from {0,0}.
|
||||
*/
|
||||
- (void)applyLayoutPreservingOrigin:(BOOL)preserveOrigin
|
||||
dimensionFlexibility:(YGDimensionFlexibility)dimensionFlexibility
|
||||
NS_SWIFT_NAME(applyLayout(preservingOrigin:dimensionFlexibility:));
|
||||
|
||||
/**
|
||||
Returns the size of the view if no constraints were given. This could equivalent to calling [self
|
||||
sizeThatFits:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)];
|
||||
*/
|
||||
@property (nonatomic, readonly, assign) CGSize intrinsicSize;
|
||||
|
||||
/**
|
||||
Returns the size of the view based on provided constraints. Pass NaN for an unconstrained dimension.
|
||||
*/
|
||||
- (CGSize)calculateLayoutWithSize:(CGSize)size
|
||||
NS_SWIFT_NAME(calculateLayout(with:));
|
||||
|
||||
/**
|
||||
Returns the number of children that are using Flexbox.
|
||||
*/
|
||||
|
@@ -21,26 +21,30 @@
|
||||
YGNodeStyleSet##capitalized_name(self.node, lowercased_name); \
|
||||
}
|
||||
|
||||
#define YG_VALUE_PROPERTY(lowercased_name, capitalized_name) \
|
||||
- (CGFloat)lowercased_name \
|
||||
{ \
|
||||
YGValue value = YGNodeStyleGet##capitalized_name(self.node); \
|
||||
if (value.unit == YGUnitPoint) { \
|
||||
return value.value; \
|
||||
} else { \
|
||||
return YGUndefined; \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
- (void)set##capitalized_name:(CGFloat)lowercased_name \
|
||||
{ \
|
||||
YGNodeStyleSet##capitalized_name(self.node, lowercased_name); \
|
||||
#define YG_VALUE_PROPERTY(lowercased_name, capitalized_name) \
|
||||
- (YGValue)lowercased_name \
|
||||
{ \
|
||||
return YGNodeStyleGet##capitalized_name(self.node); \
|
||||
} \
|
||||
\
|
||||
- (void)set##capitalized_name:(YGValue)lowercased_name \
|
||||
{ \
|
||||
switch (lowercased_name.unit) { \
|
||||
case YGUnitPoint: \
|
||||
YGNodeStyleSet##capitalized_name(self.node, lowercased_name.value); \
|
||||
break; \
|
||||
case YGUnitPercent: \
|
||||
YGNodeStyleSet##capitalized_name##Percent(self.node, lowercased_name.value); \
|
||||
break; \
|
||||
default: \
|
||||
NSAssert(NO, @"Not implemented"); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define YG_EDGE_PROPERTY_GETTER(lowercased_name, capitalized_name, property, edge) \
|
||||
- (CGFloat)lowercased_name \
|
||||
{ \
|
||||
return YGNodeStyleGet##property(self.node, edge); \
|
||||
#define YG_EDGE_PROPERTY_GETTER(type, lowercased_name, capitalized_name, property, edge) \
|
||||
- (type)lowercased_name \
|
||||
{ \
|
||||
return YGNodeStyleGet##property(self.node, edge); \
|
||||
}
|
||||
|
||||
#define YG_EDGE_PROPERTY_SETTER(lowercased_name, capitalized_name, property, edge) \
|
||||
@@ -49,42 +53,50 @@
|
||||
YGNodeStyleSet##property(self.node, edge, lowercased_name); \
|
||||
}
|
||||
|
||||
#define YG_EDGE_PROPERTY(lowercased_name, capitalized_name, property, edge) \
|
||||
YG_EDGE_PROPERTY_GETTER(lowercased_name, capitalized_name, property, edge) \
|
||||
#define YG_EDGE_PROPERTY(lowercased_name, capitalized_name, property, edge) \
|
||||
YG_EDGE_PROPERTY_GETTER(CGFloat, lowercased_name, capitalized_name, property, edge) \
|
||||
YG_EDGE_PROPERTY_SETTER(lowercased_name, capitalized_name, property, edge)
|
||||
|
||||
#define YG_VALUE_EDGE_PROPERTY_GETTER(objc_lowercased_name, objc_capitalized_name, c_name, edge) \
|
||||
- (CGFloat)objc_lowercased_name \
|
||||
#define YG_VALUE_EDGE_PROPERTY_SETTER(objc_lowercased_name, objc_capitalized_name, c_name, edge) \
|
||||
- (void)set##objc_capitalized_name:(YGValue)objc_lowercased_name \
|
||||
{ \
|
||||
YGValue value = YGNodeStyleGet##c_name(self.node, edge); \
|
||||
if (value.unit == YGUnitPoint) { \
|
||||
return value.value; \
|
||||
} else { \
|
||||
return YGUndefined; \
|
||||
switch (objc_lowercased_name.unit) { \
|
||||
case YGUnitPoint: \
|
||||
YGNodeStyleSet##c_name(self.node, edge, objc_lowercased_name.value); \
|
||||
break; \
|
||||
case YGUnitPercent: \
|
||||
YGNodeStyleSet##c_name##Percent(self.node, edge, objc_lowercased_name.value); \
|
||||
break; \
|
||||
default: \
|
||||
NSAssert(NO, @"Not implemented"); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define YG_VALUE_EDGE_PROPERTY_SETTER(objc_lowercased_name, objc_capitalized_name, c_name, edge) \
|
||||
- (void)set##objc_capitalized_name:(CGFloat)objc_lowercased_name \
|
||||
{ \
|
||||
YGNodeStyleSet##c_name(self.node, edge, objc_lowercased_name); \
|
||||
}
|
||||
|
||||
#define YG_VALUE_EDGE_PROPERTY(lowercased_name, capitalized_name, property, edge) \
|
||||
YG_VALUE_EDGE_PROPERTY_GETTER(lowercased_name, capitalized_name, property, edge) \
|
||||
#define YG_VALUE_EDGE_PROPERTY(lowercased_name, capitalized_name, property, edge) \
|
||||
YG_EDGE_PROPERTY_GETTER(YGValue, lowercased_name, capitalized_name, property, edge) \
|
||||
YG_VALUE_EDGE_PROPERTY_SETTER(lowercased_name, capitalized_name, property, edge)
|
||||
|
||||
#define YG_VALUE_EDGES_PROPERTIES(lowercased_name, capitalized_name) \
|
||||
YG_VALUE_EDGE_PROPERTY(lowercased_name##Left, capitalized_name##Left, capitalized_name, YGEdgeLeft) \
|
||||
YG_VALUE_EDGE_PROPERTY(lowercased_name##Top, capitalized_name##Top, capitalized_name, YGEdgeTop) \
|
||||
YG_VALUE_EDGE_PROPERTY(lowercased_name##Right, capitalized_name##Right, capitalized_name, YGEdgeRight) \
|
||||
YG_VALUE_EDGE_PROPERTY(lowercased_name##Bottom, capitalized_name##Bottom, capitalized_name, YGEdgeBottom) \
|
||||
YG_VALUE_EDGE_PROPERTY(lowercased_name##Start, capitalized_name##Start, capitalized_name, YGEdgeStart) \
|
||||
YG_VALUE_EDGE_PROPERTY(lowercased_name##End, capitalized_name##End, capitalized_name, YGEdgeEnd) \
|
||||
#define YG_VALUE_EDGES_PROPERTIES(lowercased_name, capitalized_name) \
|
||||
YG_VALUE_EDGE_PROPERTY(lowercased_name##Left, capitalized_name##Left, capitalized_name, YGEdgeLeft) \
|
||||
YG_VALUE_EDGE_PROPERTY(lowercased_name##Top, capitalized_name##Top, capitalized_name, YGEdgeTop) \
|
||||
YG_VALUE_EDGE_PROPERTY(lowercased_name##Right, capitalized_name##Right, capitalized_name, YGEdgeRight) \
|
||||
YG_VALUE_EDGE_PROPERTY(lowercased_name##Bottom, capitalized_name##Bottom, capitalized_name, YGEdgeBottom) \
|
||||
YG_VALUE_EDGE_PROPERTY(lowercased_name##Start, capitalized_name##Start, capitalized_name, YGEdgeStart) \
|
||||
YG_VALUE_EDGE_PROPERTY(lowercased_name##End, capitalized_name##End, capitalized_name, YGEdgeEnd) \
|
||||
YG_VALUE_EDGE_PROPERTY(lowercased_name##Horizontal, capitalized_name##Horizontal, capitalized_name, YGEdgeHorizontal) \
|
||||
YG_VALUE_EDGE_PROPERTY(lowercased_name##Vertical, capitalized_name##Vertical, capitalized_name, YGEdgeVertical) \
|
||||
YG_VALUE_EDGE_PROPERTY(lowercased_name, capitalized_name, capitalized_name, YGEdgeAll)
|
||||
|
||||
YGValue YGPointValue(CGFloat value)
|
||||
{
|
||||
return (YGValue) { .value = value, .unit = YGUnitPoint };
|
||||
}
|
||||
|
||||
YGValue YGPercentValue(CGFloat value)
|
||||
{
|
||||
return (YGValue) { .value = value, .unit = YGUnitPercent };
|
||||
}
|
||||
|
||||
static YGConfigRef globalConfig;
|
||||
|
||||
@interface YGLayout ()
|
||||
@@ -103,6 +115,7 @@ static YGConfigRef globalConfig;
|
||||
{
|
||||
globalConfig = YGConfigNew();
|
||||
YGConfigSetExperimentalFeatureEnabled(globalConfig, YGExperimentalFeatureWebFlexBasis, true);
|
||||
YGConfigSetPointScaleFactor(globalConfig, [UIScreen mainScreen].scale);
|
||||
}
|
||||
|
||||
- (instancetype)initWithView:(UIView*)view
|
||||
@@ -235,6 +248,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, preserveOrigin);
|
||||
}
|
||||
|
||||
|
||||
- (CGSize)intrinsicSize
|
||||
{
|
||||
const CGSize constrainedSize = {
|
||||
@@ -244,8 +271,6 @@ YG_PROPERTY(CGFloat, aspectRatio, AspectRatio)
|
||||
return [self calculateLayoutWithSize:constrainedSize];
|
||||
}
|
||||
|
||||
#pragma mark - Private
|
||||
|
||||
- (CGSize)calculateLayoutWithSize:(CGSize)size
|
||||
{
|
||||
NSAssert([NSThread isMainThread], @"Yoga calculation must be done on main.");
|
||||
@@ -266,6 +291,8 @@ YG_PROPERTY(CGFloat, aspectRatio, AspectRatio)
|
||||
};
|
||||
}
|
||||
|
||||
#pragma mark - Private
|
||||
|
||||
static YGSize YGMeasureView(
|
||||
YGNodeRef node,
|
||||
float width,
|
||||
|
46
YogaKit/Source/YGLayoutExtensions.swift
Normal file
46
YogaKit/Source/YGLayoutExtensions.swift
Normal file
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
postfix operator %
|
||||
|
||||
extension Int {
|
||||
public static postfix func %(value: Int) -> YGValue {
|
||||
return YGValue(value: Float(value), unit: .percent)
|
||||
}
|
||||
}
|
||||
|
||||
extension Float {
|
||||
public static postfix func %(value: Float) -> YGValue {
|
||||
return YGValue(value: value, unit: .percent)
|
||||
}
|
||||
}
|
||||
|
||||
extension CGFloat {
|
||||
public static postfix func %(value: CGFloat) -> YGValue {
|
||||
return YGValue(value: Float(value), unit: .percent)
|
||||
}
|
||||
}
|
||||
|
||||
extension YGValue : ExpressibleByIntegerLiteral, ExpressibleByFloatLiteral {
|
||||
public init(integerLiteral value: Int) {
|
||||
self = YGValue(value: Float(value), unit: .point)
|
||||
}
|
||||
|
||||
public init(floatLiteral value: Float) {
|
||||
self = YGValue(value: value, unit: .point)
|
||||
}
|
||||
|
||||
public init(_ value: Float) {
|
||||
self = YGValue(value: value, unit: .point)
|
||||
}
|
||||
|
||||
public init(_ value: CGFloat) {
|
||||
self = YGValue(value: Float(value), unit: .point)
|
||||
}
|
||||
}
|
@@ -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
|
||||
@@ -30,11 +31,11 @@
|
||||
[view configureLayoutWithBlock:^(YGLayout *layout){
|
||||
XCTAssertNotNil(layout);
|
||||
layout.isEnabled = YES;
|
||||
layout.width = 25;
|
||||
layout.width = YGPointValue(25);
|
||||
}];
|
||||
|
||||
XCTAssertTrue(view.yoga.isEnabled);
|
||||
XCTAssertEqual(view.yoga.width, 25);
|
||||
XCTAssertEqual(view.yoga.width.value, 25);
|
||||
}
|
||||
|
||||
- (void)testNodesAreDeallocedWithSingleView
|
||||
@@ -43,7 +44,7 @@
|
||||
|
||||
@autoreleasepool {
|
||||
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
|
||||
view.yoga.flexBasis = 1;
|
||||
view.yoga.flexBasis = YGPointValue(1);
|
||||
|
||||
layoutRef = view.yoga;
|
||||
XCTAssertNotNil(layoutRef);
|
||||
@@ -62,11 +63,11 @@
|
||||
@autoreleasepool {
|
||||
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
|
||||
topLayout = view.yoga;
|
||||
topLayout.flexBasis = 1;
|
||||
topLayout.flexBasis = YGPointValue(1);
|
||||
|
||||
UIView *subview = [[UIView alloc] initWithFrame:CGRectZero];
|
||||
subviewLayout = subview.yoga;
|
||||
subviewLayout.flexBasis = 1;
|
||||
subviewLayout.flexBasis = YGPointValue(1);
|
||||
|
||||
view = nil;
|
||||
}
|
||||
@@ -112,9 +113,9 @@
|
||||
|
||||
UIView *textBadgeView = [[UIView alloc] initWithFrame:CGRectZero];
|
||||
textBadgeView.yoga.isEnabled = YES;
|
||||
textBadgeView.yoga.margin = 0;
|
||||
textBadgeView.yoga.width = 10;
|
||||
textBadgeView.yoga.height = 10;
|
||||
textBadgeView.yoga.margin = YGPointValue(0);
|
||||
textBadgeView.yoga.width = YGPointValue(10);
|
||||
textBadgeView.yoga.height = YGPointValue(10);
|
||||
[container addSubview:textBadgeView];
|
||||
|
||||
const CGSize textBadgeViewSize = textBadgeView.yoga.intrinsicSize;
|
||||
@@ -135,14 +136,14 @@
|
||||
|
||||
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
|
||||
view.yoga.isEnabled = YES;
|
||||
view.yoga.flexBasis = 0;
|
||||
view.yoga.flexBasis = YGPointValue(0);
|
||||
view.yoga.flexGrow = 1;
|
||||
[container addSubview:view];
|
||||
|
||||
UIView *view2 = [[UIView alloc] initWithFrame:CGRectZero];
|
||||
view2.yoga.isEnabled = YES;
|
||||
view2.yoga.marginTop = 25;
|
||||
view2.yoga.flexBasis = 0;
|
||||
view2.yoga.marginTop = YGPointValue(25);
|
||||
view2.yoga.flexBasis = YGPointValue(0);
|
||||
view2.yoga.flexGrow = 1;
|
||||
[container addSubview:view2];
|
||||
|
||||
@@ -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 = YGPointValue(100);
|
||||
view.yoga.height = YGPointValue(100);
|
||||
[container addSubview:view];
|
||||
|
||||
[container.yoga applyLayoutPreservingOrigin:YES dimensionFlexibility:YGDimensionFlexibilityFlexibleWidth];
|
||||
XCTAssertEqual(100, container.frame.size.width);
|
||||
XCTAssertEqual(200, container.frame.size.height);
|
||||
}
|
||||
|
||||
- (void)testContainerWithFlexibleHeightGetsCorrectlySized
|
||||
{
|
||||
UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0,0,200,200)];
|
||||
container.yoga.isEnabled = YES;
|
||||
|
||||
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
|
||||
view.yoga.isEnabled = YES;
|
||||
view.yoga.width = YGPointValue(100);
|
||||
view.yoga.height = YGPointValue(100);
|
||||
[container addSubview:view];
|
||||
|
||||
[container.yoga applyLayoutPreservingOrigin:YES dimensionFlexibility: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 = YGPointValue(100);
|
||||
view.yoga.height = YGPointValue(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];
|
||||
@@ -388,12 +437,12 @@
|
||||
XCTAssertTrue(view.yoga.isLeaf);
|
||||
|
||||
view.yoga.isEnabled = YES;
|
||||
view.yoga.width = 50.0;
|
||||
view.yoga.width = YGPointValue(50);
|
||||
XCTAssertTrue(view.yoga.isLeaf);
|
||||
|
||||
UIView *const subview = view.subviews[0];
|
||||
subview.yoga.isEnabled = YES;
|
||||
subview.yoga.width = 50.0;
|
||||
subview.yoga.width = YGPointValue(50);
|
||||
XCTAssertFalse(view.yoga.isLeaf);
|
||||
}
|
||||
|
||||
@@ -405,14 +454,14 @@
|
||||
|
||||
UIView *subview1 = [[UIView alloc] initWithFrame:CGRectZero];
|
||||
subview1.yoga.isEnabled = YES;
|
||||
subview1.yoga.width = 100;
|
||||
subview1.yoga.width = YGPointValue(100);
|
||||
subview1.yoga.flexGrow = 1;
|
||||
subview1.yoga.flexDirection = YGFlexDirectionColumn;
|
||||
[container addSubview:subview1];
|
||||
|
||||
UIView *subview2 = [[UIView alloc] initWithFrame:CGRectZero];
|
||||
subview2.yoga.isEnabled = YES;
|
||||
subview2.yoga.width = 150;
|
||||
subview2.yoga.width = YGPointValue(150);
|
||||
subview2.yoga.flexGrow = 1;
|
||||
subview2.yoga.flexDirection = YGFlexDirectionColumn;
|
||||
[container addSubview:subview2];
|
||||
@@ -473,155 +522,195 @@
|
||||
[container.yoga applyLayoutPreservingOrigin:YES];
|
||||
}
|
||||
|
||||
- (void)testPointPercent
|
||||
{
|
||||
XCTAssertEqual(YGPointValue(1).value, 1);
|
||||
XCTAssertEqual(YGPointValue(1).unit, YGUnitPoint);
|
||||
XCTAssertEqual(YGPercentValue(2).value, 2);
|
||||
XCTAssertEqual(YGPercentValue(2).unit, YGUnitPercent);
|
||||
}
|
||||
|
||||
- (void)testPositionalPropertiesWork
|
||||
{
|
||||
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
|
||||
|
||||
view.yoga.left = 1;
|
||||
XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeLeft).value, 1);
|
||||
XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeLeft).unit, YGUnitPoint);
|
||||
XCTAssertEqual(view.yoga.left, 1);
|
||||
view.yoga.left = YGPointValue(1);
|
||||
XCTAssertEqual(view.yoga.left.value, 1);
|
||||
XCTAssertEqual(view.yoga.left.unit, YGUnitPoint);
|
||||
view.yoga.left = YGPercentValue(2);
|
||||
XCTAssertEqual(view.yoga.left.value, 2);
|
||||
XCTAssertEqual(view.yoga.left.unit, YGUnitPercent);
|
||||
|
||||
view.yoga.right = 2;
|
||||
XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeRight).value, 2);
|
||||
XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeRight).unit, YGUnitPoint);
|
||||
XCTAssertEqual(view.yoga.right, 2);
|
||||
view.yoga.right = YGPointValue(3);
|
||||
XCTAssertEqual(view.yoga.right.value, 3);
|
||||
XCTAssertEqual(view.yoga.right.unit, YGUnitPoint);
|
||||
view.yoga.right = YGPercentValue(4);
|
||||
XCTAssertEqual(view.yoga.right.value, 4);
|
||||
XCTAssertEqual(view.yoga.right.unit, YGUnitPercent);
|
||||
|
||||
view.yoga.top = 3;
|
||||
XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeTop).value, 3);
|
||||
XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeTop).unit, YGUnitPoint);
|
||||
XCTAssertEqual(view.yoga.top, 3);
|
||||
view.yoga.top = YGPointValue(5);
|
||||
XCTAssertEqual(view.yoga.top.value, 5);
|
||||
XCTAssertEqual(view.yoga.top.unit, YGUnitPoint);
|
||||
view.yoga.top = YGPercentValue(6);
|
||||
XCTAssertEqual(view.yoga.top.value, 6);
|
||||
XCTAssertEqual(view.yoga.top.unit, YGUnitPercent);
|
||||
|
||||
view.yoga.bottom = 4;
|
||||
XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeBottom).value, 4);
|
||||
XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeBottom).unit, YGUnitPoint);
|
||||
XCTAssertEqual(view.yoga.bottom, 4);
|
||||
view.yoga.bottom = YGPointValue(7);
|
||||
XCTAssertEqual(view.yoga.bottom.value, 7);
|
||||
XCTAssertEqual(view.yoga.bottom.unit, YGUnitPoint);
|
||||
view.yoga.bottom = YGPercentValue(8);
|
||||
XCTAssertEqual(view.yoga.bottom.value, 8);
|
||||
XCTAssertEqual(view.yoga.bottom.unit, YGUnitPercent);
|
||||
|
||||
view.yoga.start = 5;
|
||||
XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeStart).value, 5);
|
||||
XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeStart).unit, YGUnitPoint);
|
||||
XCTAssertEqual(view.yoga.start, 5);
|
||||
view.yoga.start = YGPointValue(9);
|
||||
XCTAssertEqual(view.yoga.start.value, 9);
|
||||
XCTAssertEqual(view.yoga.start.unit, YGUnitPoint);
|
||||
view.yoga.start = YGPercentValue(10);
|
||||
XCTAssertEqual(view.yoga.start.value, 10);
|
||||
XCTAssertEqual(view.yoga.start.unit, YGUnitPercent);
|
||||
|
||||
view.yoga.end = 6;
|
||||
XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeEnd).value, 6);
|
||||
XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeEnd).unit, YGUnitPoint);
|
||||
XCTAssertEqual(view.yoga.end, 6);
|
||||
view.yoga.end = YGPointValue(11);
|
||||
XCTAssertEqual(view.yoga.end.value, 11);
|
||||
XCTAssertEqual(view.yoga.end.unit, YGUnitPoint);
|
||||
view.yoga.end = YGPercentValue(12);
|
||||
XCTAssertEqual(view.yoga.end.value, 12);
|
||||
XCTAssertEqual(view.yoga.end.unit, YGUnitPercent);
|
||||
}
|
||||
|
||||
- (void)testMarginPropertiesWork
|
||||
{
|
||||
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
|
||||
|
||||
view.yoga.margin = 1;
|
||||
XCTAssertEqual(view.yoga.margin, 1);
|
||||
XCTAssertTrue(isnan(view.yoga.marginLeft));
|
||||
XCTAssertTrue(isnan(view.yoga.marginRight));
|
||||
XCTAssertTrue(isnan(view.yoga.marginStart));
|
||||
XCTAssertTrue(isnan(view.yoga.marginEnd));
|
||||
XCTAssertTrue(isnan(view.yoga.marginTop));
|
||||
XCTAssertTrue(isnan(view.yoga.marginBottom));
|
||||
XCTAssertTrue(isnan(view.yoga.marginHorizontal));
|
||||
XCTAssertTrue(isnan(view.yoga.marginVertical));
|
||||
view.yoga.margin = YGPointValue(1);
|
||||
XCTAssertEqual(view.yoga.margin.value, 1);
|
||||
XCTAssertEqual(view.yoga.margin.unit, YGUnitPoint);
|
||||
view.yoga.margin = YGPercentValue(2);
|
||||
XCTAssertEqual(view.yoga.margin.value, 2);
|
||||
XCTAssertEqual(view.yoga.margin.unit, YGUnitPercent);
|
||||
|
||||
view.yoga.marginHorizontal = 2;
|
||||
XCTAssertEqual(view.yoga.marginHorizontal, 2);
|
||||
XCTAssertTrue(isnan(view.yoga.marginLeft));
|
||||
XCTAssertTrue(isnan(view.yoga.marginRight));
|
||||
XCTAssertTrue(isnan(view.yoga.marginStart));
|
||||
XCTAssertTrue(isnan(view.yoga.marginEnd));
|
||||
view.yoga.marginHorizontal = YGPointValue(3);
|
||||
XCTAssertEqual(view.yoga.marginHorizontal.value, 3);
|
||||
XCTAssertEqual(view.yoga.marginHorizontal.unit, YGUnitPoint);
|
||||
view.yoga.marginHorizontal = YGPercentValue(4);
|
||||
XCTAssertEqual(view.yoga.marginHorizontal.value, 4);
|
||||
XCTAssertEqual(view.yoga.marginHorizontal.unit, YGUnitPercent);
|
||||
|
||||
view.yoga.marginVertical = 3;
|
||||
XCTAssertEqual(view.yoga.marginVertical, 3);
|
||||
XCTAssertTrue(isnan(view.yoga.marginTop));
|
||||
XCTAssertTrue(isnan(view.yoga.marginBottom));
|
||||
view.yoga.marginVertical = YGPointValue(5);
|
||||
XCTAssertEqual(view.yoga.marginVertical.value, 5);
|
||||
XCTAssertEqual(view.yoga.marginVertical.unit, YGUnitPoint);
|
||||
view.yoga.marginVertical = YGPercentValue(6);
|
||||
XCTAssertEqual(view.yoga.marginVertical.value, 6);
|
||||
XCTAssertEqual(view.yoga.marginVertical.unit, YGUnitPercent);
|
||||
|
||||
view.yoga.marginLeft = 4;
|
||||
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeLeft).value, 4);
|
||||
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeLeft).unit, YGUnitPoint);
|
||||
XCTAssertEqual(view.yoga.marginLeft, 4);
|
||||
view.yoga.marginLeft = YGPointValue(7);
|
||||
XCTAssertEqual(view.yoga.marginLeft.value, 7);
|
||||
XCTAssertEqual(view.yoga.marginLeft.unit, YGUnitPoint);
|
||||
view.yoga.marginLeft = YGPercentValue(8);
|
||||
XCTAssertEqual(view.yoga.marginLeft.value, 8);
|
||||
XCTAssertEqual(view.yoga.marginLeft.unit, YGUnitPercent);
|
||||
|
||||
view.yoga.marginRight = 5;
|
||||
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeRight).value, 5);
|
||||
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeRight).unit, YGUnitPoint);
|
||||
XCTAssertEqual(view.yoga.marginRight, 5);
|
||||
view.yoga.marginRight = YGPointValue(9);
|
||||
XCTAssertEqual(view.yoga.marginRight.value, 9);
|
||||
XCTAssertEqual(view.yoga.marginRight.unit, YGUnitPoint);
|
||||
view.yoga.marginRight = YGPercentValue(10);
|
||||
XCTAssertEqual(view.yoga.marginRight.value, 10);
|
||||
XCTAssertEqual(view.yoga.marginRight.unit, YGUnitPercent);
|
||||
|
||||
view.yoga.marginTop = 6;
|
||||
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeTop).value, 6);
|
||||
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeTop).unit, YGUnitPoint);
|
||||
XCTAssertEqual(view.yoga.marginTop, 6);
|
||||
view.yoga.marginTop = YGPointValue(11);
|
||||
XCTAssertEqual(view.yoga.marginTop.value, 11);
|
||||
XCTAssertEqual(view.yoga.marginTop.unit, YGUnitPoint);
|
||||
view.yoga.marginTop = YGPercentValue(12);
|
||||
XCTAssertEqual(view.yoga.marginTop.value, 12);
|
||||
XCTAssertEqual(view.yoga.marginTop.unit, YGUnitPercent);
|
||||
|
||||
view.yoga.marginBottom = 7;
|
||||
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeBottom).value, 7);
|
||||
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeBottom).unit, YGUnitPoint);
|
||||
XCTAssertEqual(view.yoga.marginBottom, 7);
|
||||
view.yoga.marginBottom = YGPointValue(13);
|
||||
XCTAssertEqual(view.yoga.marginBottom.value, 13);
|
||||
XCTAssertEqual(view.yoga.marginBottom.unit, YGUnitPoint);
|
||||
view.yoga.marginBottom = YGPercentValue(14);
|
||||
XCTAssertEqual(view.yoga.marginBottom.value, 14);
|
||||
XCTAssertEqual(view.yoga.marginBottom.unit, YGUnitPercent);
|
||||
|
||||
view.yoga.marginStart = 8;
|
||||
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeStart).value, 8);
|
||||
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeStart).unit, YGUnitPoint);
|
||||
XCTAssertEqual(view.yoga.marginStart, 8);
|
||||
view.yoga.marginStart = YGPointValue(15);
|
||||
XCTAssertEqual(view.yoga.marginStart.value, 15);
|
||||
XCTAssertEqual(view.yoga.marginStart.unit, YGUnitPoint);
|
||||
view.yoga.marginStart = YGPercentValue(16);
|
||||
XCTAssertEqual(view.yoga.marginStart.value, 16);
|
||||
XCTAssertEqual(view.yoga.marginStart.unit, YGUnitPercent);
|
||||
|
||||
view.yoga.marginEnd = 9;
|
||||
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeEnd).value, 9);
|
||||
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeEnd).unit, YGUnitPoint);
|
||||
XCTAssertEqual(view.yoga.marginEnd, 9);
|
||||
view.yoga.marginEnd = YGPointValue(17);
|
||||
XCTAssertEqual(view.yoga.marginEnd.value, 17);
|
||||
XCTAssertEqual(view.yoga.marginEnd.unit, YGUnitPoint);
|
||||
view.yoga.marginEnd = YGPercentValue(18);
|
||||
XCTAssertEqual(view.yoga.marginEnd.value, 18);
|
||||
XCTAssertEqual(view.yoga.marginEnd.unit, YGUnitPercent);
|
||||
}
|
||||
|
||||
- (void)testPaddingPropertiesWork
|
||||
{
|
||||
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
|
||||
|
||||
view.yoga.padding = 1;
|
||||
XCTAssertEqual(view.yoga.padding, 1);
|
||||
XCTAssertTrue(isnan(view.yoga.paddingLeft));
|
||||
XCTAssertTrue(isnan(view.yoga.paddingRight));
|
||||
XCTAssertTrue(isnan(view.yoga.paddingStart));
|
||||
XCTAssertTrue(isnan(view.yoga.paddingEnd));
|
||||
XCTAssertTrue(isnan(view.yoga.paddingTop));
|
||||
XCTAssertTrue(isnan(view.yoga.paddingBottom));
|
||||
XCTAssertTrue(isnan(view.yoga.paddingHorizontal));
|
||||
XCTAssertTrue(isnan(view.yoga.paddingVertical));
|
||||
view.yoga.padding = YGPointValue(1);
|
||||
XCTAssertEqual(view.yoga.padding.value, 1);
|
||||
XCTAssertEqual(view.yoga.padding.unit, YGUnitPoint);
|
||||
view.yoga.padding = YGPercentValue(2);
|
||||
XCTAssertEqual(view.yoga.padding.value, 2);
|
||||
XCTAssertEqual(view.yoga.padding.unit, YGUnitPercent);
|
||||
|
||||
view.yoga.paddingHorizontal = 2;
|
||||
XCTAssertEqual(view.yoga.paddingHorizontal, 2);
|
||||
XCTAssertTrue(isnan(view.yoga.paddingLeft));
|
||||
XCTAssertTrue(isnan(view.yoga.paddingRight));
|
||||
XCTAssertTrue(isnan(view.yoga.paddingStart));
|
||||
XCTAssertTrue(isnan(view.yoga.paddingEnd));
|
||||
view.yoga.paddingHorizontal = YGPointValue(3);
|
||||
XCTAssertEqual(view.yoga.paddingHorizontal.value, 3);
|
||||
XCTAssertEqual(view.yoga.paddingHorizontal.unit, YGUnitPoint);
|
||||
view.yoga.paddingHorizontal = YGPercentValue(4);
|
||||
XCTAssertEqual(view.yoga.paddingHorizontal.value, 4);
|
||||
XCTAssertEqual(view.yoga.paddingHorizontal.unit, YGUnitPercent);
|
||||
|
||||
view.yoga.paddingVertical = 3;
|
||||
XCTAssertEqual(view.yoga.paddingVertical, 3);
|
||||
XCTAssertTrue(isnan(view.yoga.paddingTop));
|
||||
XCTAssertTrue(isnan(view.yoga.paddingBottom));
|
||||
view.yoga.paddingVertical = YGPointValue(5);
|
||||
XCTAssertEqual(view.yoga.paddingVertical.value, 5);
|
||||
XCTAssertEqual(view.yoga.paddingVertical.unit, YGUnitPoint);
|
||||
view.yoga.paddingVertical = YGPercentValue(6);
|
||||
XCTAssertEqual(view.yoga.paddingVertical.value, 6);
|
||||
XCTAssertEqual(view.yoga.paddingVertical.unit, YGUnitPercent);
|
||||
|
||||
view.yoga.paddingLeft = 4;
|
||||
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeLeft).value, 4);
|
||||
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeLeft).unit, YGUnitPoint);
|
||||
XCTAssertEqual(view.yoga.paddingLeft, 4);
|
||||
view.yoga.paddingLeft = YGPointValue(7);
|
||||
XCTAssertEqual(view.yoga.paddingLeft.value, 7);
|
||||
XCTAssertEqual(view.yoga.paddingLeft.unit, YGUnitPoint);
|
||||
view.yoga.paddingLeft = YGPercentValue(8);
|
||||
XCTAssertEqual(view.yoga.paddingLeft.value, 8);
|
||||
XCTAssertEqual(view.yoga.paddingLeft.unit, YGUnitPercent);
|
||||
|
||||
view.yoga.paddingRight = 5;
|
||||
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeRight).value, 5);
|
||||
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeRight).unit, YGUnitPoint);
|
||||
XCTAssertEqual(view.yoga.paddingRight, 5);
|
||||
view.yoga.paddingRight = YGPointValue(9);
|
||||
XCTAssertEqual(view.yoga.paddingRight.value, 9);
|
||||
XCTAssertEqual(view.yoga.paddingRight.unit, YGUnitPoint);
|
||||
view.yoga.paddingRight = YGPercentValue(10);
|
||||
XCTAssertEqual(view.yoga.paddingRight.value, 10);
|
||||
XCTAssertEqual(view.yoga.paddingRight.unit, YGUnitPercent);
|
||||
|
||||
view.yoga.paddingTop = 6;
|
||||
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeTop).value, 6);
|
||||
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeTop).unit, YGUnitPoint);
|
||||
XCTAssertEqual(view.yoga.paddingTop, 6);
|
||||
view.yoga.paddingTop = YGPointValue(11);
|
||||
XCTAssertEqual(view.yoga.paddingTop.value, 11);
|
||||
XCTAssertEqual(view.yoga.paddingTop.unit, YGUnitPoint);
|
||||
view.yoga.paddingTop = YGPercentValue(12);
|
||||
XCTAssertEqual(view.yoga.paddingTop.value, 12);
|
||||
XCTAssertEqual(view.yoga.paddingTop.unit, YGUnitPercent);
|
||||
|
||||
view.yoga.paddingBottom = 7;
|
||||
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeBottom).value, 7);
|
||||
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeBottom).unit, YGUnitPoint);
|
||||
XCTAssertEqual(view.yoga.paddingBottom, 7);
|
||||
view.yoga.paddingBottom = YGPointValue(13);
|
||||
XCTAssertEqual(view.yoga.paddingBottom.value, 13);
|
||||
XCTAssertEqual(view.yoga.paddingBottom.unit, YGUnitPoint);
|
||||
view.yoga.paddingBottom = YGPercentValue(14);
|
||||
XCTAssertEqual(view.yoga.paddingBottom.value, 14);
|
||||
XCTAssertEqual(view.yoga.paddingBottom.unit, YGUnitPercent);
|
||||
|
||||
view.yoga.paddingStart = 8;
|
||||
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeStart).value, 8);
|
||||
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeStart).unit, YGUnitPoint);
|
||||
XCTAssertEqual(view.yoga.paddingStart, 8);
|
||||
view.yoga.paddingStart = YGPointValue(15);
|
||||
XCTAssertEqual(view.yoga.paddingStart.value, 15);
|
||||
XCTAssertEqual(view.yoga.paddingStart.unit, YGUnitPoint);
|
||||
view.yoga.paddingStart = YGPercentValue(16);
|
||||
XCTAssertEqual(view.yoga.paddingStart.value, 16);
|
||||
XCTAssertEqual(view.yoga.paddingStart.unit, YGUnitPercent);
|
||||
|
||||
view.yoga.paddingEnd = 9;
|
||||
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeEnd).value, 9);
|
||||
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeEnd).unit, YGUnitPoint);
|
||||
XCTAssertEqual(view.yoga.paddingEnd, 9);
|
||||
view.yoga.paddingEnd = YGPointValue(17);
|
||||
XCTAssertEqual(view.yoga.paddingEnd.value, 17);
|
||||
XCTAssertEqual(view.yoga.paddingEnd.unit, YGUnitPoint);
|
||||
view.yoga.paddingEnd = YGPercentValue(18);
|
||||
XCTAssertEqual(view.yoga.paddingEnd.value, 18);
|
||||
XCTAssertEqual(view.yoga.paddingEnd.unit, YGUnitPercent);
|
||||
}
|
||||
|
||||
- (void)testBorderWidthPropertiesWork
|
||||
@@ -630,12 +719,6 @@
|
||||
|
||||
view.yoga.borderWidth = 1;
|
||||
XCTAssertEqual(view.yoga.borderWidth, 1);
|
||||
XCTAssertTrue(isnan(view.yoga.borderLeftWidth));
|
||||
XCTAssertTrue(isnan(view.yoga.borderRightWidth));
|
||||
XCTAssertTrue(isnan(view.yoga.borderStartWidth));
|
||||
XCTAssertTrue(isnan(view.yoga.borderEndWidth));
|
||||
XCTAssertTrue(isnan(view.yoga.borderTopWidth));
|
||||
XCTAssertTrue(isnan(view.yoga.borderBottomWidth));
|
||||
|
||||
view.yoga.borderLeftWidth = 2;
|
||||
XCTAssertEqual(view.yoga.borderLeftWidth, 2);
|
||||
|
@@ -4,9 +4,9 @@ PODS:
|
||||
- IGListKit/Default (2.1.0):
|
||||
- IGListKit/Diffing
|
||||
- IGListKit/Diffing (2.1.0)
|
||||
- Yoga (1.2.0)
|
||||
- YogaKit (1.2.0):
|
||||
- Yoga (~> 1.2)
|
||||
- Yoga (1.5.0)
|
||||
- YogaKit (1.5.0):
|
||||
- Yoga (~> 1.5)
|
||||
|
||||
DEPENDENCIES:
|
||||
- IGListKit (~> 2.1.0)
|
||||
@@ -14,13 +14,13 @@ DEPENDENCIES:
|
||||
|
||||
EXTERNAL SOURCES:
|
||||
YogaKit:
|
||||
:path: "../../YogaKit.podspec"
|
||||
:path: ../../YogaKit.podspec
|
||||
|
||||
SPEC CHECKSUMS:
|
||||
IGListKit: b826c68ef7a4ae1626c09d4d3e1ea7a169e6c36e
|
||||
Yoga: 20fc010c282cc5f3c27ce512de1329cd1e72b077
|
||||
YogaKit: 72d5c8a806dc5cf2aa50c93a6dd88913cdbec6fe
|
||||
Yoga: 2ed1d7accfef3610a67f58c0cf101a0662137f2c
|
||||
YogaKit: 31576530e8fcae3175469719ec3212397403330b
|
||||
|
||||
PODFILE CHECKSUM: 216f8e7127767709e0e43f3711208d238fa5c404
|
||||
|
||||
COCOAPODS: 1.2.0
|
||||
COCOAPODS: 1.1.1
|
||||
|
@@ -0,0 +1,101 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "0820"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
buildImplicitDependencies = "YES">
|
||||
<BuildActionEntries>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "13687D421DF8748300E7C260"
|
||||
BuildableName = "YogaKitSample.app"
|
||||
BlueprintName = "YogaKitSample"
|
||||
ReferencedContainer = "container:YogaKitSample.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
</BuildActionEntries>
|
||||
</BuildAction>
|
||||
<TestAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||
<Testables>
|
||||
<TestableReference
|
||||
skipped = "NO">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "638A944E1E215CC800A726AD"
|
||||
BuildableName = "YogaKitSampleTests.xctest"
|
||||
BlueprintName = "YogaKitSampleTests"
|
||||
ReferencedContainer = "container:YogaKitSample.xcodeproj">
|
||||
</BuildableReference>
|
||||
</TestableReference>
|
||||
</Testables>
|
||||
<MacroExpansion>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "13687D421DF8748300E7C260"
|
||||
BuildableName = "YogaKitSample.app"
|
||||
BlueprintName = "YogaKitSample"
|
||||
ReferencedContainer = "container:YogaKitSample.xcodeproj">
|
||||
</BuildableReference>
|
||||
</MacroExpansion>
|
||||
<AdditionalOptions>
|
||||
</AdditionalOptions>
|
||||
</TestAction>
|
||||
<LaunchAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
launchStyle = "0"
|
||||
useCustomWorkingDirectory = "NO"
|
||||
ignoresPersistentStateOnLaunch = "NO"
|
||||
debugDocumentVersioning = "YES"
|
||||
debugServiceExtension = "internal"
|
||||
allowLocationSimulation = "YES">
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "13687D421DF8748300E7C260"
|
||||
BuildableName = "YogaKitSample.app"
|
||||
BlueprintName = "YogaKitSample"
|
||||
ReferencedContainer = "container:YogaKitSample.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
<AdditionalOptions>
|
||||
</AdditionalOptions>
|
||||
</LaunchAction>
|
||||
<ProfileAction
|
||||
buildConfiguration = "Release"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||
savedToolIdentifier = ""
|
||||
useCustomWorkingDirectory = "NO"
|
||||
debugDocumentVersioning = "YES">
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "13687D421DF8748300E7C260"
|
||||
BuildableName = "YogaKitSample.app"
|
||||
BlueprintName = "YogaKitSample"
|
||||
ReferencedContainer = "container:YogaKitSample.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
</ProfileAction>
|
||||
<AnalyzeAction
|
||||
buildConfiguration = "Debug">
|
||||
</AnalyzeAction>
|
||||
<ArchiveAction
|
||||
buildConfiguration = "Release"
|
||||
revealArchiveInOrganizer = "YES">
|
||||
</ArchiveAction>
|
||||
</Scheme>
|
@@ -12,6 +12,11 @@ import YogaKit
|
||||
|
||||
struct DemoItem {
|
||||
let name: String
|
||||
root.backgroundColor = .red
|
||||
root.yoga.isEnabled = true
|
||||
root.yoga.width = YGValue(self.view.bounds.size.width)
|
||||
root.yoga.height = YGValue(self.view.bounds.size.height)
|
||||
root.yoga.alignItems = .center
|
||||
}
|
||||
|
||||
final class SwiftViewController: UIViewController, IGListAdapterDataSource {
|
||||
|
@@ -17,16 +17,16 @@
|
||||
UIView *root = self.view;
|
||||
root.backgroundColor = [UIColor redColor];
|
||||
root.yoga.isEnabled = YES;
|
||||
root.yoga.width = self.view.bounds.size.width;
|
||||
root.yoga.height = self.view.bounds.size.height;
|
||||
root.yoga.width = YGPointValue(self.view.bounds.size.width);
|
||||
root.yoga.height = YGPointValue(self.view.bounds.size.height);
|
||||
root.yoga.alignItems = YGAlignCenter;
|
||||
root.yoga.justifyContent = YGJustifyCenter;
|
||||
|
||||
UIView *child1 = [UIView new];
|
||||
child1.backgroundColor = [UIColor blueColor];
|
||||
child1.yoga.isEnabled = YES;
|
||||
child1.yoga.width = 100;
|
||||
child1.yoga.height = 100;
|
||||
child1.yoga.width = YGPointValue(100);
|
||||
child1.yoga.height = YGPointValue(100);
|
||||
|
||||
UIView *child2 = [UIView new];
|
||||
child2.backgroundColor = [UIColor greenColor];
|
||||
|
@@ -15,32 +15,38 @@ final class BasicViewController: UIViewController {
|
||||
|
||||
let root = self.view!
|
||||
root.backgroundColor = .white
|
||||
root.yoga.isEnabled = true
|
||||
root.yoga.width = containerSize.width
|
||||
root.yoga.height = containerSize.height
|
||||
root.yoga.alignItems = .center
|
||||
root.yoga.justifyContent = .center
|
||||
root.configureLayout { (layout) in
|
||||
layout.isEnabled = true
|
||||
layout.width = YGValue(containerSize.width)
|
||||
layout.height = YGValue(containerSize.height)
|
||||
layout.alignItems = .center
|
||||
layout.justifyContent = .center
|
||||
}
|
||||
|
||||
let child1 = UIView()
|
||||
child1.backgroundColor = .blue
|
||||
child1.yoga.isEnabled = true
|
||||
child1.yoga.width = 100
|
||||
child1.yoga.height = 10
|
||||
child1.yoga.marginBottom = 25
|
||||
child1.configureLayout { (layout) in
|
||||
layout.isEnabled = true
|
||||
layout.width = 100
|
||||
layout.height = 10
|
||||
layout.marginBottom = 25
|
||||
}
|
||||
root.addSubview(child1)
|
||||
|
||||
let child2 = UIView()
|
||||
child2.yoga.isEnabled = true
|
||||
child2.yoga.alignSelf = .flexEnd
|
||||
let child2 = UIView(frame: CGRect(x: 0, y: 0, width: 200, height: 200))
|
||||
child2.backgroundColor = .green
|
||||
child2.frame = CGRect(x: 0, y: 0, width: 200, height: 100)
|
||||
child2.configureLayout { (layout) in
|
||||
layout.isEnabled = true
|
||||
layout.alignSelf = .flexEnd
|
||||
}
|
||||
root.addSubview(child2)
|
||||
|
||||
let child3 = UIView()
|
||||
child3.yoga.isEnabled = true
|
||||
child3.yoga.alignSelf = .flexStart
|
||||
let child3 = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
|
||||
child3.backgroundColor = .yellow
|
||||
child3.frame = CGRect(x: 0, y: 0, width: 100, height: 100)
|
||||
child3.configureLayout { (layout) in
|
||||
layout.isEnabled = true
|
||||
layout.alignSelf = .flexStart
|
||||
}
|
||||
root.addSubview(child3)
|
||||
|
||||
root.yoga.applyLayout(preservingOrigin: true)
|
||||
|
@@ -17,40 +17,50 @@ final class LayoutInclusionViewController: UIViewController {
|
||||
override func viewDidLoad() {
|
||||
let root = self.view!
|
||||
root.backgroundColor = .white
|
||||
root.yoga.isEnabled = true
|
||||
root.yoga.flexDirection = .column
|
||||
root.yoga.justifyContent = .spaceAround
|
||||
root.configureLayout { (layout) in
|
||||
layout.isEnabled = true
|
||||
layout.flexDirection = .column
|
||||
layout.justifyContent = .spaceAround
|
||||
}
|
||||
|
||||
contentView.backgroundColor = .clear
|
||||
contentView.layer.borderColor = UIColor.lightGray.cgColor
|
||||
contentView.layer.borderWidth = 1.0
|
||||
contentView.yoga.isEnabled = true
|
||||
contentView.yoga.height = 300
|
||||
contentView.yoga.width = self.view.bounds.size.width
|
||||
contentView.yoga.flexDirection = .row
|
||||
contentView.yoga.justifyContent = .center
|
||||
contentView.yoga.paddingHorizontal = 25
|
||||
contentView.configureLayout { (layout) in
|
||||
layout.isEnabled = true
|
||||
layout.height = 300
|
||||
layout.width = YGValue(self.view.bounds.size.width)
|
||||
layout.flexDirection = .row
|
||||
layout.justifyContent = .center
|
||||
layout.paddingHorizontal = 25
|
||||
}
|
||||
self.view.addSubview(contentView)
|
||||
|
||||
let redView = UIView(frame: .zero)
|
||||
redView.backgroundColor = .red
|
||||
redView.yoga.isEnabled = true
|
||||
redView.yoga.flexGrow = 1
|
||||
redView.yoga.flexShrink = 1
|
||||
redView.configureLayout { (layout) in
|
||||
layout.isEnabled = true
|
||||
layout.flexGrow = 1
|
||||
layout.flexShrink = 1
|
||||
}
|
||||
contentView.addSubview(redView)
|
||||
|
||||
disappearingView.backgroundColor = .blue
|
||||
disappearingView.yoga.isEnabled = true
|
||||
disappearingView.yoga.flexGrow = 1
|
||||
disappearingView.configureLayout { (layout) in
|
||||
layout.isEnabled = true
|
||||
layout.flexGrow = 1
|
||||
}
|
||||
contentView.addSubview(disappearingView)
|
||||
|
||||
button.setTitle("Add Blue View", for: UIControlState.selected)
|
||||
button.setTitle("Remove Blue View", for: UIControlState.normal)
|
||||
button.addTarget(self, action: #selector(buttonWasTapped), for: UIControlEvents.touchUpInside)
|
||||
button.yoga.isEnabled = true
|
||||
button.yoga.height = 300
|
||||
button.yoga.width = 300
|
||||
button.yoga.alignSelf = .center
|
||||
button.configureLayout { (layout) in
|
||||
layout.isEnabled = true
|
||||
layout.height = 300
|
||||
layout.width = 300
|
||||
layout.alignSelf = .center
|
||||
}
|
||||
root.addSubview(button)
|
||||
|
||||
root.yoga.applyLayout(preservingOrigin: false)
|
||||
|
@@ -15,9 +15,11 @@ final class SingleLabelCollectionCell: UICollectionViewCell {
|
||||
override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
|
||||
contentView.yoga.isEnabled = true
|
||||
contentView.yoga.flexDirection = .column
|
||||
contentView.yoga.justifyContent = .flexEnd
|
||||
contentView.configureLayout { (layout) in
|
||||
layout.isEnabled = true
|
||||
layout.flexDirection = .column
|
||||
layout.justifyContent = .flexEnd
|
||||
}
|
||||
|
||||
label.textAlignment = .center
|
||||
label.numberOfLines = 1
|
||||
@@ -26,9 +28,11 @@ final class SingleLabelCollectionCell: UICollectionViewCell {
|
||||
|
||||
let border = UIView(frame: .zero)
|
||||
border.backgroundColor = .lightGray
|
||||
border.yoga.isEnabled = true
|
||||
border.yoga.height = 0.5
|
||||
border.yoga.marginHorizontal = 25
|
||||
border.configureLayout { (layout) in
|
||||
layout.isEnabled = true
|
||||
layout.height = 0.5
|
||||
layout.marginHorizontal = 25
|
||||
}
|
||||
contentView.addSubview(border)
|
||||
}
|
||||
|
||||
|
@@ -30,7 +30,3 @@ android_resource(
|
||||
"PUBLIC",
|
||||
],
|
||||
)
|
||||
|
||||
project_config(
|
||||
src_target = ":android",
|
||||
)
|
||||
|
21
android/README.md
Normal file
21
android/README.md
Normal file
@@ -0,0 +1,21 @@
|
||||
# YogaLayout [](https://facebook.github.io/yoga/docs/api/android/) [](https://facebook.github.io/yoga/docs/api/android/) [](https://bintray.com/facebook/maven/com.facebook.yoga.android%3Ayoga-layout/_latestVersion)
|
||||
|
||||
## Installation
|
||||
|
||||
YogaLayout is available via jcenter:
|
||||
|
||||
compile 'com.facebook.yoga.android:yoga-layout:1.2.0'
|
||||
|
||||
## Getting Started
|
||||
|
||||
Check out the docs [here](https://facebook.github.io/yoga/docs/api/android/).
|
||||
|
||||
We also have a sample project. To try it, clone the repo and run (with a device attached)
|
||||
|
||||
buck install -r android/sample
|
||||
|
||||
## Contributing
|
||||
|
||||
We welcome all pull-requests! At Facebook we sync the open source version of YogaKit daily, so we're always testing the latest changes.
|
||||
|
||||
See the CONTRIBUTING file for how to help out.
|
@@ -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.2.0'
|
||||
group = 'com.facebook.yoga.android'
|
||||
version = VERSION_NAME
|
||||
group = GROUP
|
||||
|
||||
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) {
|
||||
@@ -45,8 +42,4 @@ task javadocJar(type: Jar, dependsOn: javadoc) {
|
||||
from javadoc.destinationDir
|
||||
}
|
||||
|
||||
ext {
|
||||
bintrayName = "com.facebook.yoga.android:yoga-layout"
|
||||
}
|
||||
|
||||
apply from: rootProject.file('gradle/android-jcenter-install.gradle')
|
||||
apply from: rootProject.file('gradle/release.gradle')
|
||||
|
5
android/gradle.properties
Normal file
5
android/gradle.properties
Normal file
@@ -0,0 +1,5 @@
|
||||
GROUP=com.facebook.yoga.android
|
||||
POM_NAME=YogaLayout
|
||||
POM_DESCRIPTION=YogaLayout
|
||||
POM_ARTIFACT_ID=yoga-layout
|
||||
POM_PACKAGING=aar
|
@@ -22,6 +22,8 @@
|
||||
android:targetSdkVersion="19"
|
||||
/>
|
||||
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
|
||||
<application
|
||||
android:label="@string/app_name"
|
||||
android:icon="@drawable/ic_launcher"
|
||||
@@ -42,6 +44,11 @@
|
||||
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".BenchmarkActivity"
|
||||
android:exported="false"
|
||||
/>
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
@@ -33,7 +33,3 @@ keystore(
|
||||
properties = "debug.keystore.properties",
|
||||
store = "debug.keystore",
|
||||
)
|
||||
|
||||
project_config(
|
||||
src_target = ":sample",
|
||||
)
|
||||
|
@@ -0,0 +1,113 @@
|
||||
// Copyright 2004-present Facebook. All Rights Reserved.
|
||||
|
||||
package com.facebook.samples.yoga;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v4.app.FragmentPagerAdapter;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.Menu;
|
||||
import android.support.v7.app.ActionBar;
|
||||
|
||||
import com.facebook.samples.yoga.R;
|
||||
import com.facebook.yoga.android.YogaViewLayoutFactory;
|
||||
|
||||
public class BenchmarkActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
LayoutInflater.from(this).setFactory(YogaViewLayoutFactory.getInstance());
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.benchmark_select_layout);
|
||||
|
||||
ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
|
||||
viewPager.setAdapter(new PagerAdapter(getSupportFragmentManager()));
|
||||
|
||||
final ActionBar actionBar = getSupportActionBar();
|
||||
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
|
||||
|
||||
ActionBar.TabListener tabListener = new ActionBar.TabListener() {
|
||||
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
|
||||
ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
|
||||
viewPager.setCurrentItem(tab.getPosition());
|
||||
}
|
||||
|
||||
public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) {
|
||||
}
|
||||
|
||||
public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) {
|
||||
}
|
||||
};
|
||||
actionBar.addTab(
|
||||
actionBar.newTab()
|
||||
.setText("Inflate")
|
||||
.setTabListener(tabListener));
|
||||
actionBar.addTab(
|
||||
actionBar.newTab()
|
||||
.setText("Measure")
|
||||
.setTabListener(tabListener));
|
||||
actionBar.addTab(
|
||||
actionBar.newTab()
|
||||
.setText("Layout")
|
||||
.setTabListener(tabListener));
|
||||
|
||||
viewPager.setOnPageChangeListener(
|
||||
new ViewPager.SimpleOnPageChangeListener() {
|
||||
@Override
|
||||
public void onPageSelected(int position) {
|
||||
// When swiping between pages, select the
|
||||
// corresponding tab.
|
||||
actionBar.setSelectedNavigationItem(position);
|
||||
}
|
||||
});
|
||||
|
||||
viewPager.setOffscreenPageLimit(3);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
MenuInflater inflater = getMenuInflater();
|
||||
inflater.inflate(R.menu.action_bar_benchmark, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
// There is only one option
|
||||
Intent intent = new Intent(this, MainActivity.class);
|
||||
startActivity(intent);
|
||||
this.finish();
|
||||
return true;
|
||||
}
|
||||
|
||||
public static class PagerAdapter extends FragmentPagerAdapter {
|
||||
public PagerAdapter(FragmentManager fm) {
|
||||
super(fm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment getItem(int i) {
|
||||
switch (i) {
|
||||
case 0:
|
||||
return new BenchmarkInflate();
|
||||
case 1:
|
||||
return new BenchmarkMeasure();
|
||||
default:
|
||||
return new BenchmarkLayout();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,193 @@
|
||||
// Copyright 2004-present Facebook. All Rights Reserved.
|
||||
|
||||
package com.facebook.samples.yoga;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.PrintWriter;
|
||||
import java.lang.Math;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.text.DateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
import android.os.Environment;
|
||||
|
||||
import static java.util.Collections.sort;
|
||||
|
||||
public class BenchmarkAggregator {
|
||||
|
||||
private final int GRAPH_WIDTH = 30;
|
||||
private final int GRAPH_HEIGHT = 6;
|
||||
|
||||
private List<Long> times;
|
||||
private boolean tracing;
|
||||
private long lastTraceStart;
|
||||
|
||||
private boolean statsFresh;
|
||||
private long mean;
|
||||
private long variance;
|
||||
private long stddev;
|
||||
private long min;
|
||||
private long max;
|
||||
private long p10;
|
||||
private long p50;
|
||||
private long p90;
|
||||
|
||||
private String name;
|
||||
|
||||
public BenchmarkAggregator(String name) {
|
||||
times = new ArrayList<>();
|
||||
tracing = false;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void startTrace() {
|
||||
if (tracing) {
|
||||
throw new RuntimeException("Cannot start trace while running previous one");
|
||||
}
|
||||
tracing = true;
|
||||
lastTraceStart = System.nanoTime();
|
||||
}
|
||||
|
||||
public void endTrace() {
|
||||
if (!tracing) {
|
||||
throw new RuntimeException("Cannot stop trace if none are running!");
|
||||
}
|
||||
times.add(System.nanoTime() - lastTraceStart);
|
||||
tracing = false;
|
||||
statsFresh = false;
|
||||
}
|
||||
|
||||
private void computeStats() {
|
||||
if (statsFresh) {
|
||||
return;
|
||||
}
|
||||
|
||||
sort(times);
|
||||
|
||||
min = Long.MAX_VALUE;
|
||||
max = -1;
|
||||
mean = 0;
|
||||
for (long f: times) {
|
||||
mean += f;
|
||||
if (f < min) {
|
||||
min = f;
|
||||
}
|
||||
if (f > max) {
|
||||
max = f;
|
||||
}
|
||||
}
|
||||
mean /= times.size();
|
||||
|
||||
variance = 0;
|
||||
for (long f: times) {
|
||||
variance += (f-mean)*(f-mean);
|
||||
}
|
||||
variance /= times.size();
|
||||
stddev = (long) Math.sqrt((double) variance);
|
||||
|
||||
p10 = times.get(times.size()*10/100);
|
||||
p50 = times.get(times.size()*50/100);
|
||||
p90 = times.get(times.size()*90/100);
|
||||
|
||||
statsFresh = true;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
computeStats();
|
||||
return String.format(
|
||||
"%s:\n" +
|
||||
"| %d samples\n" +
|
||||
"| Mean %.3f\u00B1%.3fms\n" + // plusminus
|
||||
"| Min %.3fms ; Max %.3fms\n" +
|
||||
"| p10 %.3fms ; p50 %.3fms ; p90 %.3fms\n" +
|
||||
"%s",
|
||||
name,
|
||||
times.size(),
|
||||
mean/10e6,
|
||||
stddev/10e6,
|
||||
min/10e6,
|
||||
max/10e6,
|
||||
p10/10e6,
|
||||
p50/10e6,
|
||||
p90/10e6,
|
||||
makeGraph());
|
||||
}
|
||||
|
||||
private String makeGraph() {
|
||||
char canvas[][] = new char[GRAPH_HEIGHT][GRAPH_WIDTH];
|
||||
for (int i = 0; i < GRAPH_HEIGHT; i++)
|
||||
for (int j = 0; j < GRAPH_WIDTH; j++)
|
||||
canvas[i][j] = ' ';
|
||||
|
||||
long bucketSize = (p90 - p10) / GRAPH_WIDTH+1;
|
||||
int bucketCount[] = new int[GRAPH_WIDTH];
|
||||
for (long time : times) {
|
||||
if (time<p90 && time>p10) {
|
||||
bucketCount[(int) ((time - p10) / bucketSize)]++;
|
||||
}
|
||||
}
|
||||
|
||||
int maxBucket = 0;
|
||||
for (int i = 0; i < GRAPH_WIDTH; i++)
|
||||
if (bucketCount[i] > maxBucket) {
|
||||
maxBucket = bucketCount[i];
|
||||
}
|
||||
|
||||
for (int i = 0; i < GRAPH_HEIGHT; i++)
|
||||
for (int j = 0; j < GRAPH_WIDTH; j++)
|
||||
if (i < bucketCount[j] * GRAPH_HEIGHT / maxBucket) {
|
||||
canvas[i][j] = 'Z';
|
||||
}
|
||||
|
||||
String graph = new String();
|
||||
for (int i = 0; i < GRAPH_HEIGHT; i++)
|
||||
{
|
||||
int percentage = 100 * (GRAPH_HEIGHT - i - 1) * maxBucket / (times.size() * GRAPH_HEIGHT);
|
||||
graph += String.format("| %2d%% ", percentage);
|
||||
for (int j = 0; j < GRAPH_WIDTH; j++)
|
||||
graph += canvas[GRAPH_HEIGHT-1-i][j];
|
||||
graph += '\n';
|
||||
}
|
||||
|
||||
graph += "| p10";
|
||||
for (int i = 0; i < GRAPH_WIDTH-6; i++)
|
||||
graph += " ";
|
||||
graph += "p90\n";
|
||||
return graph;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dumps the collected times to a file on the device. This allows us to grab the raw data
|
||||
* and perform more in-depth analysis.
|
||||
*/
|
||||
public void dump(Context context) {
|
||||
String state = Environment.getExternalStorageState();
|
||||
if (!Environment.MEDIA_MOUNTED.equals(state)) {
|
||||
Log.e("YogaLayoutBenchmark","No external file storage");
|
||||
return;
|
||||
}
|
||||
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
|
||||
String filename = format.format(new Date()) + "_" + name.replace(' ','_');
|
||||
File file = new File(context.getExternalFilesDir(
|
||||
Environment.DIRECTORY_DOCUMENTS), filename);
|
||||
|
||||
try {
|
||||
PrintWriter printWriter = new PrintWriter(file);
|
||||
for (long l : times) {
|
||||
printWriter.println(l);
|
||||
}
|
||||
printWriter.close();
|
||||
|
||||
Log.i("YogaLayoutBenchmark","Benchmark data saved in "+file.getPath());
|
||||
} catch (java.io.IOException e) {
|
||||
Log.e("YogaLayoutBenchmark", "Could not save benchmark data", e);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,110 @@
|
||||
// Copyright 2004-present Facebook. All Rights Reserved.
|
||||
|
||||
package com.facebook.samples.yoga;
|
||||
|
||||
|
||||
import java.util.Random;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewParent;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.AdapterView;
|
||||
|
||||
import com.facebook.samples.yoga.R;
|
||||
import com.facebook.yoga.android.YogaLayout;
|
||||
|
||||
public class BenchmarkFragment extends Fragment implements AdapterView.OnItemSelectedListener {
|
||||
private LayoutInflater mInflater;
|
||||
|
||||
protected com.facebook.yoga.android.YogaLayout rootLayout;
|
||||
protected int yogaLayout;
|
||||
protected int linearLayout;
|
||||
|
||||
static final Random random = new Random();
|
||||
|
||||
static void randomizeText(View root) {
|
||||
if (root instanceof TextView) {
|
||||
((TextView) root).setText("" + random.nextInt(1000));
|
||||
((TextView) root).setTextSize(10 + random.nextInt(20));
|
||||
ViewParent parent = root.getParent();
|
||||
if (parent instanceof YogaLayout) {
|
||||
((YogaLayout) parent).invalidate(root);
|
||||
}
|
||||
} else if (root instanceof ViewGroup) {
|
||||
for (int i = 0; i < ((ViewGroup) root).getChildCount(); i++) {
|
||||
randomizeText(((ViewGroup) root).getChildAt(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public BenchmarkFragment() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(
|
||||
LayoutInflater inflater,
|
||||
ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
mInflater = inflater;
|
||||
|
||||
rootLayout = (YogaLayout) inflater.inflate(
|
||||
R.layout.benchmark_fragment,
|
||||
container,
|
||||
false);
|
||||
|
||||
Spinner benchmarkSelect = (Spinner) rootLayout.findViewById(R.id.benchmarkSelect);
|
||||
String[] items = new String[]{"Basic", "Typical", "Nested"};
|
||||
ArrayAdapter<String> adapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_spinner_dropdown_item, items);
|
||||
benchmarkSelect.setAdapter(adapter);
|
||||
benchmarkSelect.setOnItemSelectedListener(this);
|
||||
return rootLayout;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
|
||||
switch (pos) {
|
||||
case 0:
|
||||
yogaLayout = R.layout.benchmark_layout_1;
|
||||
linearLayout = R.layout.benchmark_layout_1_linear;
|
||||
break;
|
||||
case 1:
|
||||
yogaLayout = R.layout.benchmark_layout_2;
|
||||
linearLayout = R.layout.benchmark_layout_2_linear;
|
||||
break;
|
||||
case 2:
|
||||
default:
|
||||
yogaLayout = R.layout.benchmark_layout_3;
|
||||
linearLayout = R.layout.benchmark_layout_3_linear;
|
||||
break;
|
||||
}
|
||||
updatePreview();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> parent) {
|
||||
yogaLayout = R.layout.benchmark_layout_1;
|
||||
linearLayout = R.layout.benchmark_layout_1_linear;
|
||||
updatePreview();
|
||||
}
|
||||
|
||||
private void updatePreview() {
|
||||
LinearLayout previewLayout = (LinearLayout) rootLayout.findViewById(R.id.preview);
|
||||
View v = mInflater.inflate(yogaLayout, rootLayout, false);
|
||||
v.setLayoutParams(new LinearLayout.LayoutParams(
|
||||
LinearLayout.LayoutParams.MATCH_PARENT,
|
||||
LinearLayout.LayoutParams.MATCH_PARENT));
|
||||
previewLayout.removeAllViews();
|
||||
previewLayout.addView(v);
|
||||
}
|
||||
}
|
@@ -0,0 +1,65 @@
|
||||
// Copyright 2004-present Facebook. All Rights Reserved.
|
||||
|
||||
package com.facebook.samples.yoga;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Button;
|
||||
import android.view.ViewGroup;
|
||||
import android.util.Log;
|
||||
import com.facebook.samples.yoga.R;
|
||||
|
||||
public class BenchmarkInflate extends BenchmarkFragment {
|
||||
|
||||
@Override
|
||||
public View onCreateView(
|
||||
LayoutInflater inflater,
|
||||
ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
super.onCreateView(inflater, container, savedInstanceState);
|
||||
|
||||
Button b = (Button) rootLayout.findViewById(R.id.btn);
|
||||
b.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
startBenchmark();
|
||||
}
|
||||
});
|
||||
|
||||
return rootLayout;
|
||||
}
|
||||
|
||||
protected void startBenchmark() {
|
||||
LayoutInflater inflater = LayoutInflater.from(getActivity());
|
||||
TextView textView = (TextView) rootLayout.findViewById(R.id.text);
|
||||
|
||||
final int ITERATIONS = 500;
|
||||
|
||||
inflater.inflate(yogaLayout, null);
|
||||
inflater.inflate(linearLayout, null);
|
||||
|
||||
BenchmarkAggregator yogaInflationAggregator = new BenchmarkAggregator("Yoga Inflate");
|
||||
BenchmarkAggregator linearInflationAggregator = new BenchmarkAggregator("Linear Inflate");
|
||||
for (int i = 0; i < ITERATIONS; i++) {
|
||||
yogaInflationAggregator.startTrace();
|
||||
inflater.inflate(yogaLayout, null);
|
||||
yogaInflationAggregator.endTrace();
|
||||
linearInflationAggregator.startTrace();
|
||||
inflater.inflate(linearLayout, null);
|
||||
linearInflationAggregator.endTrace();
|
||||
}
|
||||
|
||||
textView.setText(
|
||||
yogaInflationAggregator.toString()+
|
||||
"\n"+
|
||||
linearInflationAggregator.toString());
|
||||
Log.i(
|
||||
"YogaLayoutBenchmark",
|
||||
yogaInflationAggregator.toString()+
|
||||
"\n"+
|
||||
linearInflationAggregator.toString());
|
||||
rootLayout.invalidate();
|
||||
}
|
||||
}
|
@@ -0,0 +1,74 @@
|
||||
// Copyright 2004-present Facebook. All Rights Reserved.
|
||||
|
||||
package com.facebook.samples.yoga;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
import com.facebook.samples.yoga.R;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class BenchmarkLayout extends BenchmarkFragment {
|
||||
|
||||
@Override
|
||||
public View onCreateView(
|
||||
LayoutInflater inflater,
|
||||
ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
super.onCreateView(inflater, container, savedInstanceState);
|
||||
|
||||
Button b = (Button) rootLayout.findViewById(R.id.btn);
|
||||
b.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
startBenchmark();
|
||||
}
|
||||
});
|
||||
|
||||
return rootLayout;
|
||||
}
|
||||
|
||||
protected void startBenchmark() {
|
||||
LayoutInflater inflater = LayoutInflater.from(getActivity());
|
||||
TextView textView = (TextView) rootLayout.findViewById(R.id.text);
|
||||
Random random = new Random();
|
||||
|
||||
final int ITERATIONS = 500;
|
||||
|
||||
BenchmarkAggregator yogaInflationAggregator = new BenchmarkAggregator("Yoga Layout");
|
||||
BenchmarkAggregator linearInflationAggregator = new BenchmarkAggregator("Linear Layout");
|
||||
View yogaView = inflater.inflate(yogaLayout, null);
|
||||
View linearView = inflater.inflate(linearLayout, null);
|
||||
for (int i = 0; i < ITERATIONS; i++) {
|
||||
randomizeText(yogaView);
|
||||
randomizeText(linearView);
|
||||
yogaView.measure(
|
||||
View.MeasureSpec.makeMeasureSpec(1000, View.MeasureSpec.EXACTLY),
|
||||
View.MeasureSpec.makeMeasureSpec(1000, View.MeasureSpec.EXACTLY));
|
||||
linearView.measure(
|
||||
View.MeasureSpec.makeMeasureSpec(1000, View.MeasureSpec.EXACTLY),
|
||||
View.MeasureSpec.makeMeasureSpec(1000, View.MeasureSpec.EXACTLY));
|
||||
yogaInflationAggregator.startTrace();
|
||||
yogaView.layout(0, 0, yogaView.getMeasuredWidth(), yogaView.getMeasuredHeight());
|
||||
yogaInflationAggregator.endTrace();
|
||||
linearInflationAggregator.startTrace();
|
||||
linearView.layout(0, 0, linearView.getMeasuredWidth(), linearView.getMeasuredHeight());
|
||||
linearInflationAggregator.endTrace();
|
||||
}
|
||||
|
||||
textView.setText(
|
||||
yogaInflationAggregator.toString()+
|
||||
"\n"+
|
||||
linearInflationAggregator.toString());
|
||||
Log.i(
|
||||
"YogaLayoutBenchmark",
|
||||
yogaInflationAggregator.toString()+
|
||||
"\n"+
|
||||
linearInflationAggregator.toString());
|
||||
}
|
||||
}
|
@@ -0,0 +1,75 @@
|
||||
// Copyright 2004-present Facebook. All Rights Reserved.
|
||||
|
||||
package com.facebook.samples.yoga;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
import com.facebook.samples.yoga.R;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class BenchmarkMeasure extends BenchmarkFragment {
|
||||
|
||||
@Override
|
||||
public View onCreateView(
|
||||
LayoutInflater inflater,
|
||||
ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
super.onCreateView(inflater, container, savedInstanceState);
|
||||
|
||||
Button b = (Button) rootLayout.findViewById(R.id.btn);
|
||||
b.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
startBenchmark();
|
||||
}
|
||||
});
|
||||
|
||||
return rootLayout;
|
||||
}
|
||||
|
||||
protected void startBenchmark() {
|
||||
LayoutInflater inflater = LayoutInflater.from(getActivity());
|
||||
TextView textView = (TextView) rootLayout.findViewById(R.id.text);
|
||||
Random random = new Random();
|
||||
|
||||
final int ITERATIONS = 500;
|
||||
|
||||
BenchmarkAggregator yogaMeasureAggregator = new BenchmarkAggregator("Yoga Measure");
|
||||
BenchmarkAggregator linearMeasureAggregator = new BenchmarkAggregator("Linear Measure");
|
||||
View yogaView = inflater.inflate(yogaLayout, null);
|
||||
View linearView = inflater.inflate(linearLayout, null);
|
||||
for (int i = 0; i < ITERATIONS; i++) {
|
||||
randomizeText(yogaView);
|
||||
randomizeText(linearView);
|
||||
yogaMeasureAggregator.startTrace();
|
||||
yogaView.measure(
|
||||
View.MeasureSpec.makeMeasureSpec(1000, View.MeasureSpec.EXACTLY),
|
||||
View.MeasureSpec.makeMeasureSpec(1000, View.MeasureSpec.EXACTLY));
|
||||
yogaMeasureAggregator.endTrace();
|
||||
linearMeasureAggregator.startTrace();
|
||||
linearView.measure(
|
||||
View.MeasureSpec.makeMeasureSpec(1000, View.MeasureSpec.EXACTLY),
|
||||
View.MeasureSpec.makeMeasureSpec(1000, View.MeasureSpec.EXACTLY));
|
||||
linearMeasureAggregator.endTrace();
|
||||
}
|
||||
|
||||
textView.setText(
|
||||
yogaMeasureAggregator.toString()+
|
||||
"\n"+
|
||||
linearMeasureAggregator.toString());
|
||||
Log.i(
|
||||
"YogaLayoutBenchmark",
|
||||
yogaMeasureAggregator.toString()+
|
||||
"\n"+
|
||||
linearMeasureAggregator.toString());
|
||||
|
||||
yogaMeasureAggregator.dump(getActivity());
|
||||
linearMeasureAggregator.dump(getActivity());
|
||||
}
|
||||
}
|
@@ -8,9 +8,13 @@
|
||||
|
||||
package com.facebook.samples.yoga;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.Menu;
|
||||
|
||||
import com.facebook.samples.yoga.R;
|
||||
import com.facebook.soloader.SoLoader;
|
||||
@@ -21,7 +25,7 @@ import com.facebook.yoga.android.YogaViewLayoutFactory;
|
||||
* {@code main_layout.xml}) that shows off the awesome functionality of the Yoga layout engine
|
||||
* as well as some optimisations on layout systems that it facilitates.
|
||||
*/
|
||||
public class MainActivity extends ActionBarActivity {
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
@@ -31,4 +35,20 @@ public class MainActivity extends ActionBarActivity {
|
||||
|
||||
setContentView(R.layout.main_layout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
MenuInflater inflater = getMenuInflater();
|
||||
inflater.inflate(R.menu.action_bar_home, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
// There is only one option
|
||||
Intent intent = new Intent(this, BenchmarkActivity.class);
|
||||
startActivity(intent);
|
||||
this.finish();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
50
android/sample/res/layout/benchmark_fragment.xml
Normal file
50
android/sample/res/layout/benchmark_fragment.xml
Normal file
@@ -0,0 +1,50 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<YogaLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:yoga="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/rt"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
yoga:yg_flexDirection="column"
|
||||
>
|
||||
<VirtualYogaLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
yoga:yg_flexDirection="row"
|
||||
yoga:yg_height="50dp"
|
||||
>
|
||||
<Button
|
||||
android:id="@+id/btn"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:text="Run benchmark"
|
||||
yoga:yg_flex="1"
|
||||
/>
|
||||
<Spinner
|
||||
android:id="@+id/benchmarkSelect"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:spinnerMode="dropdown"
|
||||
/>
|
||||
</VirtualYogaLayout>
|
||||
<TextView
|
||||
android:id="@+id/text"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:textSize="10sp"
|
||||
android:fontFamily="monospace"
|
||||
yoga:yg_flex="1"
|
||||
/>
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="2dp"
|
||||
android:background="@color/yoga_grey"
|
||||
/>
|
||||
<LinearLayout
|
||||
android:id="@+id/preview"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="60dp"
|
||||
android:orientation="horizontal"
|
||||
/>
|
||||
</YogaLayout>
|
30
android/sample/res/layout/benchmark_layout_1.xml
Normal file
30
android/sample/res/layout/benchmark_layout_1.xml
Normal file
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<YogaLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:yoga="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="60dp"
|
||||
yoga:yg_flexDirection="row"
|
||||
yoga:yg_alignItems="center"
|
||||
>
|
||||
<View
|
||||
android:layout_width="50dp"
|
||||
android:layout_height="50dp"
|
||||
android:background="@color/yoga_blue"
|
||||
yoga:yg_flex="0"
|
||||
yoga:yg_marginAll="5dp"
|
||||
/>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/child_1_text"
|
||||
yoga:yg_flex="0"
|
||||
/>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/child_2_text"
|
||||
yoga:yg_flex="1"
|
||||
yoga:yg_marginHorizontal="5dp"
|
||||
/>
|
||||
</YogaLayout>
|
28
android/sample/res/layout/benchmark_layout_1_linear.xml
Normal file
28
android/sample/res/layout/benchmark_layout_1_linear.xml
Normal file
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center"
|
||||
>
|
||||
<ImageView
|
||||
android:layout_width="50dp"
|
||||
android:layout_height="50dp"
|
||||
android:layout_margin="5dp"
|
||||
android:src="@drawable/ic_launcher"
|
||||
/>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/child_1_text"
|
||||
/>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:layout_marginLeft="5dp"
|
||||
android:layout_marginRight="5dp"
|
||||
android:text="@string/child_2_text"
|
||||
/>
|
||||
</LinearLayout>
|
104
android/sample/res/layout/benchmark_layout_2.xml
Normal file
104
android/sample/res/layout/benchmark_layout_2.xml
Normal file
@@ -0,0 +1,104 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<YogaLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:yoga="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="60dp"
|
||||
yoga:yg_flexDirection="column"
|
||||
yoga:yg_alignItems="stretch"
|
||||
>
|
||||
<View
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/yoga_blue"
|
||||
yoga:yg_flex="1"
|
||||
/>
|
||||
<VirtualYogaLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
yoga:height="40dp"
|
||||
yoga:yg_flexDirection="row"
|
||||
yoga:yg_alignItems="stretch"
|
||||
>
|
||||
<View
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/yoga_blue"
|
||||
yoga:yg_marginAll="10dp"
|
||||
yoga:yg_aspectRatio="1"
|
||||
/>
|
||||
<VirtualYogaLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
yoga:height="40dp"
|
||||
yoga:yg_flexDirection="column"
|
||||
yoga:yg_alignItems="stretch"
|
||||
yoga:yg_flex="1"
|
||||
yoga:yg_justifyContent="space_around"
|
||||
>
|
||||
<VirtualYogaLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
yoga:height="8dp"
|
||||
yoga:yg_flexDirection="row"
|
||||
yoga:yg_alignItems="stretch"
|
||||
>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/child_1_text"
|
||||
android:textSize="5sp"
|
||||
yoga:yg_flex="1"
|
||||
/>
|
||||
<View
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/yoga_blue"
|
||||
yoga:yg_aspectRatio="1"
|
||||
/>
|
||||
</VirtualYogaLayout>
|
||||
<VirtualYogaLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
yoga:height="8dp"
|
||||
yoga:yg_flexDirection="row"
|
||||
yoga:yg_alignItems="stretch"
|
||||
>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/child_1_text"
|
||||
android:textSize="5sp"
|
||||
yoga:yg_flex="1"
|
||||
/>
|
||||
<View
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/yoga_blue"
|
||||
yoga:yg_aspectRatio="1"
|
||||
/>
|
||||
</VirtualYogaLayout>
|
||||
<VirtualYogaLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
yoga:height="8dp"
|
||||
yoga:yg_flexDirection="row"
|
||||
yoga:yg_alignItems="stretch"
|
||||
>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/child_1_text"
|
||||
android:textSize="5sp"
|
||||
yoga:yg_flex="1"
|
||||
/>
|
||||
<View
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/yoga_blue"
|
||||
yoga:yg_aspectRatio="1"
|
||||
/>
|
||||
</VirtualYogaLayout>
|
||||
</VirtualYogaLayout>
|
||||
</VirtualYogaLayout>
|
||||
</YogaLayout>
|
96
android/sample/res/layout/benchmark_layout_2_linear.xml
Normal file
96
android/sample/res/layout/benchmark_layout_2_linear.xml
Normal file
@@ -0,0 +1,96 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:yoga="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="60dp"
|
||||
android:orientation="vertical"
|
||||
>
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/ic_launcher"
|
||||
android:background="@color/yoga_blue"
|
||||
android:layout_weight="1"
|
||||
/>
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="40dp"
|
||||
android:orientation="horizontal"
|
||||
>
|
||||
<View
|
||||
android:layout_width="20dp"
|
||||
android:layout_height="20dp"
|
||||
android:src="@drawable/ic_launcher"
|
||||
android:background="@color/yoga_blue"
|
||||
android:layout_margin="10dp"
|
||||
/>
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="40dp"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical"
|
||||
>
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="8dp"
|
||||
android:orientation="horizontal"
|
||||
android:layout_marginTop="4dp"
|
||||
>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/child_1_text"
|
||||
android:textSize="5sp"
|
||||
android:layout_weight="1"
|
||||
/>
|
||||
<View
|
||||
android:layout_width="8dp"
|
||||
android:layout_height="8dp"
|
||||
android:src="@drawable/ic_launcher"
|
||||
android:background="@color/yoga_blue"
|
||||
/>
|
||||
</LinearLayout>
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="8dp"
|
||||
android:orientation="horizontal"
|
||||
android:layout_marginTop="4dp"
|
||||
>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/child_1_text"
|
||||
android:textSize="5sp"
|
||||
android:layout_weight="1"
|
||||
/>
|
||||
<View
|
||||
android:layout_width="8dp"
|
||||
android:layout_height="8dp"
|
||||
android:src="@drawable/ic_launcher"
|
||||
android:background="@color/yoga_blue"
|
||||
/>
|
||||
</LinearLayout>
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="8dp"
|
||||
android:orientation="horizontal"
|
||||
android:layout_marginTop="4dp"
|
||||
>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/child_1_text"
|
||||
android:textSize="5sp"
|
||||
android:layout_weight="1"
|
||||
/>
|
||||
<View
|
||||
android:layout_width="8dp"
|
||||
android:layout_height="8dp"
|
||||
android:src="@drawable/ic_launcher"
|
||||
android:background="@color/yoga_blue"
|
||||
/>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
206
android/sample/res/layout/benchmark_layout_3.xml
Normal file
206
android/sample/res/layout/benchmark_layout_3.xml
Normal file
@@ -0,0 +1,206 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<YogaLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:yoga="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
yoga:yg_alignItems="center"
|
||||
yoga:yg_flexDirection="row"
|
||||
yoga:yg_justifyContent="center"
|
||||
>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/yoga_blue"
|
||||
yoga:yg_marginLeft="10dp"
|
||||
/>
|
||||
<VirtualYogaLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
yoga:yg_flexDirection="column"
|
||||
yoga:yg_flex="1"
|
||||
>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/yoga_grey"
|
||||
yoga:yg_marginLeft="10dp"
|
||||
/>
|
||||
<VirtualYogaLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
yoga:yg_flexDirection="row"
|
||||
yoga:yg_flex="1"
|
||||
>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/yoga_grey"
|
||||
yoga:yg_marginLeft="10dp"
|
||||
/>
|
||||
<VirtualYogaLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
yoga:yg_flexDirection="row"
|
||||
yoga:yg_flex="1"
|
||||
>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/yoga_blue"
|
||||
yoga:yg_marginLeft="10dp"
|
||||
/>
|
||||
<VirtualYogaLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
yoga:yg_flexDirection="row"
|
||||
yoga:yg_flex="1"
|
||||
>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/yoga_grey"
|
||||
yoga:yg_marginLeft="10dp"
|
||||
/>
|
||||
<VirtualYogaLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
yoga:yg_flexDirection="row"
|
||||
yoga:yg_flex="1"
|
||||
>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/yoga_grey"
|
||||
yoga:yg_marginLeft="10dp"
|
||||
/>
|
||||
<VirtualYogaLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
yoga:yg_flexDirection="column"
|
||||
yoga:yg_flex="1"
|
||||
>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/yoga_blue"
|
||||
yoga:yg_marginLeft="10dp"
|
||||
/>
|
||||
<VirtualYogaLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
yoga:yg_flexDirection="row"
|
||||
yoga:yg_flex="1"
|
||||
>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/yoga_grey"
|
||||
yoga:yg_marginLeft="10dp"
|
||||
/>
|
||||
<VirtualYogaLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
yoga:yg_flexDirection="row"
|
||||
yoga:yg_flex="1"
|
||||
>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/yoga_grey"
|
||||
yoga:yg_marginLeft="10dp"
|
||||
/>
|
||||
<VirtualYogaLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
yoga:yg_flexDirection="row"
|
||||
yoga:yg_flex="1"
|
||||
>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/yoga_blue"
|
||||
yoga:yg_marginLeft="10dp"
|
||||
/>
|
||||
<VirtualYogaLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
yoga:yg_flexDirection="row"
|
||||
yoga:yg_flex="1"
|
||||
>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/yoga_grey"
|
||||
yoga:yg_marginLeft="10dp"
|
||||
/>
|
||||
<VirtualYogaLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
yoga:yg_flexDirection="column"
|
||||
yoga:yg_flex="1"
|
||||
>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/yoga_grey"
|
||||
yoga:yg_marginLeft="10dp"
|
||||
/>
|
||||
<VirtualYogaLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
yoga:yg_flexDirection="row"
|
||||
yoga:yg_flex="1"
|
||||
>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/yoga_blue"
|
||||
yoga:yg_marginLeft="10dp"
|
||||
/>
|
||||
<VirtualYogaLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
yoga:yg_flexDirection="row"
|
||||
yoga:yg_flex="1"
|
||||
>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/yoga_grey"
|
||||
yoga:yg_marginLeft="10dp"
|
||||
/>
|
||||
<VirtualYogaLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
yoga:yg_flexDirection="row"
|
||||
yoga:yg_flex="1"
|
||||
>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/yoga_grey"
|
||||
yoga:yg_marginLeft="10dp"
|
||||
/>
|
||||
<VirtualYogaLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
yoga:yg_flexDirection="row"
|
||||
yoga:yg_flex="1"
|
||||
>
|
||||
</VirtualYogaLayout>
|
||||
</VirtualYogaLayout>
|
||||
</VirtualYogaLayout>
|
||||
</VirtualYogaLayout>
|
||||
</VirtualYogaLayout>
|
||||
</VirtualYogaLayout>
|
||||
</VirtualYogaLayout>
|
||||
</VirtualYogaLayout>
|
||||
</VirtualYogaLayout>
|
||||
</VirtualYogaLayout>
|
||||
</VirtualYogaLayout>
|
||||
</VirtualYogaLayout>
|
||||
</VirtualYogaLayout>
|
||||
</VirtualYogaLayout>
|
||||
</VirtualYogaLayout>
|
||||
</YogaLayout>
|
204
android/sample/res/layout/benchmark_layout_3_linear.xml
Normal file
204
android/sample/res/layout/benchmark_layout_3_linear.xml
Normal file
@@ -0,0 +1,204 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:orientation="horizontal"
|
||||
>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:background="@color/yoga_blue"
|
||||
/>
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical"
|
||||
>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:background="@color/yoga_grey"
|
||||
/>
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:orientation="horizontal"
|
||||
>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:background="@color/yoga_grey"
|
||||
/>
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:orientation="horizontal"
|
||||
>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:background="@color/yoga_blue"
|
||||
/>
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:orientation="horizontal"
|
||||
>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:background="@color/yoga_grey"
|
||||
/>
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:orientation="horizontal"
|
||||
>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:background="@color/yoga_grey"
|
||||
/>
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical"
|
||||
>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:background="@color/yoga_blue"
|
||||
/>
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:orientation="horizontal"
|
||||
>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:background="@color/yoga_grey"
|
||||
/>
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:orientation="horizontal"
|
||||
>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:background="@color/yoga_grey"
|
||||
/>
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:orientation="horizontal"
|
||||
>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:background="@color/yoga_blue"
|
||||
/>
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:orientation="horizontal"
|
||||
>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:background="@color/yoga_grey"
|
||||
/>
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical"
|
||||
>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:background="@color/yoga_grey"
|
||||
/>
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:orientation="horizontal"
|
||||
>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:background="@color/yoga_blue"
|
||||
/>
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:orientation="horizontal"
|
||||
>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:background="@color/yoga_grey"
|
||||
/>
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:orientation="horizontal"
|
||||
>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:background="@color/yoga_grey"
|
||||
/>
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:orientation="horizontal"
|
||||
>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
7
android/sample/res/layout/benchmark_select_layout.xml
Normal file
7
android/sample/res/layout/benchmark_select_layout.xml
Normal file
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<android.support.v4.view.ViewPager
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/viewpager"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
/>
|
@@ -18,10 +18,10 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/sample_children_background"
|
||||
yoga:yg_margin_horizontal="10dp"
|
||||
yoga:yg_margin_top="5dp"
|
||||
yoga:yg_flex_direction="row"
|
||||
yoga:yg_align_items="center"
|
||||
yoga:yg_marginHorizontal="10dp"
|
||||
yoga:yg_marginTop="5dp"
|
||||
yoga:yg_flexDirection="row"
|
||||
yoga:yg_alignItems="center"
|
||||
>
|
||||
<ImageView
|
||||
android:layout_width="50dp"
|
||||
@@ -35,17 +35,17 @@
|
||||
android:text="@string/child_1_text"
|
||||
android:textColor="@color/children_text"
|
||||
yoga:yg_flex="1"
|
||||
yoga:yg_margin_start="8dp"
|
||||
yoga:yg_marginStart="8dp"
|
||||
/>
|
||||
</YogaLayout>
|
||||
<YogaLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/sample_children_background"
|
||||
yoga:yg_margin_horizontal="10dp"
|
||||
yoga:yg_margin_top="5dp"
|
||||
yoga:yg_flex_direction="row"
|
||||
yoga:yg_align_items="center"
|
||||
yoga:yg_marginHorizontal="10dp"
|
||||
yoga:yg_marginTop="5dp"
|
||||
yoga:yg_flexDirection="row"
|
||||
yoga:yg_alignItems="center"
|
||||
>
|
||||
<ImageView
|
||||
android:layout_width="50dp"
|
||||
@@ -59,17 +59,17 @@
|
||||
android:text="@string/child_2_text"
|
||||
android:textColor="@color/children_text"
|
||||
yoga:yg_flex="1"
|
||||
yoga:yg_margin_start="8dp"
|
||||
yoga:yg_marginStart="8dp"
|
||||
/>
|
||||
</YogaLayout>
|
||||
<YogaLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/sample_children_background"
|
||||
yoga:yg_margin_horizontal="10dp"
|
||||
yoga:yg_margin_top="5dp"
|
||||
yoga:yg_flex_direction="row"
|
||||
yoga:yg_align_items="center"
|
||||
yoga:yg_marginHorizontal="10dp"
|
||||
yoga:yg_marginTop="5dp"
|
||||
yoga:yg_flexDirection="row"
|
||||
yoga:yg_alignItems="center"
|
||||
>
|
||||
<ImageView
|
||||
android:layout_width="50dp"
|
||||
@@ -83,17 +83,17 @@
|
||||
android:text="@string/child_3_text"
|
||||
android:textColor="@color/children_text"
|
||||
yoga:yg_flex="1"
|
||||
yoga:yg_margin_start="8dp"
|
||||
yoga:yg_marginStart="8dp"
|
||||
/>
|
||||
</YogaLayout>
|
||||
<YogaLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/sample_children_background"
|
||||
yoga:yg_margin_horizontal="10dp"
|
||||
yoga:yg_margin_top="5dp"
|
||||
yoga:yg_flex_direction="row"
|
||||
yoga:yg_align_items="center"
|
||||
yoga:yg_marginHorizontal="10dp"
|
||||
yoga:yg_marginTop="5dp"
|
||||
yoga:yg_flexDirection="row"
|
||||
yoga:yg_alignItems="center"
|
||||
>
|
||||
<ImageView
|
||||
android:layout_width="50dp"
|
||||
@@ -107,17 +107,17 @@
|
||||
android:text="@string/child_4_text"
|
||||
android:textColor="@color/children_text"
|
||||
yoga:yg_flex="1"
|
||||
yoga:yg_margin_start="8dp"
|
||||
yoga:yg_marginStart="8dp"
|
||||
/>
|
||||
</YogaLayout>
|
||||
<YogaLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/sample_children_background"
|
||||
yoga:yg_margin_horizontal="10dp"
|
||||
yoga:yg_margin_top="5dp"
|
||||
yoga:yg_flex_direction="row"
|
||||
yoga:yg_align_items="center"
|
||||
yoga:yg_marginHorizontal="10dp"
|
||||
yoga:yg_marginTop="5dp"
|
||||
yoga:yg_flexDirection="row"
|
||||
yoga:yg_alignItems="center"
|
||||
>
|
||||
<ImageView
|
||||
android:layout_width="50dp"
|
||||
@@ -131,7 +131,7 @@
|
||||
android:text="@string/child_5_text"
|
||||
android:textColor="@color/children_text"
|
||||
yoga:yg_flex="1"
|
||||
yoga:yg_margin_start="10dp"
|
||||
yoga:yg_marginStart="10dp"
|
||||
/>
|
||||
</YogaLayout>
|
||||
</YogaLayout>
|
||||
|
19
android/sample/res/menu/action_bar_benchmark.xml
Normal file
19
android/sample/res/menu/action_bar_benchmark.xml
Normal file
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!--
|
||||
Copyright 2014-present, Facebook, Inc.
|
||||
All rights reserved.
|
||||
|
||||
This source code is licensed under the license found in the
|
||||
LICENSE-examples file in the root directory of this source tree.
|
||||
-->
|
||||
|
||||
<menu
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
>
|
||||
<item
|
||||
android:id="@+id/action_home"
|
||||
android:title="Home"
|
||||
android:showAsAction="always"
|
||||
/>
|
||||
</menu>
|
19
android/sample/res/menu/action_bar_home.xml
Normal file
19
android/sample/res/menu/action_bar_home.xml
Normal file
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!--
|
||||
Copyright 2014-present, Facebook, Inc.
|
||||
All rights reserved.
|
||||
|
||||
This source code is licensed under the license found in the
|
||||
LICENSE-examples file in the root directory of this source tree.
|
||||
-->
|
||||
|
||||
<menu
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
>
|
||||
<item
|
||||
android:id="@+id/action_benchmark"
|
||||
android:title="Benchmark"
|
||||
android:showAsAction="always"
|
||||
/>
|
||||
</menu>
|
@@ -23,6 +23,7 @@ import android.util.SparseArray;
|
||||
import android.util.TypedValue;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.util.Log;
|
||||
|
||||
import com.facebook.yoga.android.R;
|
||||
import com.facebook.yoga.YogaAlign;
|
||||
@@ -36,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;
|
||||
@@ -51,7 +52,7 @@ import com.facebook.yoga.YogaWrap;
|
||||
* <pre>{@code
|
||||
* <YogaLayout
|
||||
* xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
* xmlns:yoga="http://schemas.android.com/lib/com.facebook.yoga.android"
|
||||
* xmlns:yoga="http://schemas.android.com/apk/com.facebook.yoga.android"
|
||||
* android:layout_width="match_parent"
|
||||
* android:layout_height="match_parent"
|
||||
* yoga:flex_direction="row"
|
||||
@@ -90,15 +91,20 @@ public class YogaLayout extends ViewGroup {
|
||||
mYogaNode.setData(this);
|
||||
mYogaNode.setMeasureFunction(new ViewMeasureFunction());
|
||||
|
||||
final LayoutParams layoutParams = new LayoutParams(context, attrs);
|
||||
LayoutParams layoutParams = null;
|
||||
if (attrs != null) {
|
||||
layoutParams = new LayoutParams(context, attrs);
|
||||
} else {
|
||||
layoutParams = (LayoutParams) generateDefaultLayoutParams();
|
||||
}
|
||||
applyLayoutParams(layoutParams, mYogaNode, this);
|
||||
}
|
||||
|
||||
YogaNode getYogaNode() {
|
||||
public YogaNode getYogaNode() {
|
||||
return mYogaNode;
|
||||
}
|
||||
|
||||
YogaNode getYogaNodeForView(View view) {
|
||||
public YogaNode getYogaNodeForView(View view) {
|
||||
return mYogaNodes.get(view);
|
||||
}
|
||||
|
||||
@@ -153,7 +159,11 @@ public class YogaLayout extends ViewGroup {
|
||||
if (child instanceof YogaLayout) {
|
||||
childNode = ((YogaLayout) child).getYogaNode();
|
||||
} else {
|
||||
childNode = new YogaNode();
|
||||
if(mYogaNodes.containsKey(child)) {
|
||||
childNode = mYogaNodes.get(child);
|
||||
} else {
|
||||
childNode = new YogaNode();
|
||||
}
|
||||
|
||||
childNode.setData(child);
|
||||
childNode.setMeasureFunction(new ViewMeasureFunction());
|
||||
@@ -278,6 +288,7 @@ public class YogaLayout extends ViewGroup {
|
||||
|
||||
private void applyLayoutRecursive(YogaNode node, float xOffset, float yOffset) {
|
||||
View view = (View) node.getData();
|
||||
|
||||
if (view != null && view != this) {
|
||||
if (view.getVisibility() == GONE) {
|
||||
return;
|
||||
@@ -360,7 +371,6 @@ public class YogaLayout extends ViewGroup {
|
||||
if (widthMode == MeasureSpec.AT_MOST) {
|
||||
mYogaNode.setMaxWidth(widthSize);
|
||||
}
|
||||
|
||||
mYogaNode.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
||||
}
|
||||
|
||||
@@ -403,31 +413,31 @@ public class YogaLayout extends ViewGroup {
|
||||
final int attribute = layoutParameters.numericAttributes.keyAt(i);
|
||||
final float value = layoutParameters.numericAttributes.valueAt(i);
|
||||
|
||||
if (attribute == R.styleable.yoga_yg_align_content) {
|
||||
if (attribute == R.styleable.yoga_yg_alignContent) {
|
||||
node.setAlignContent(YogaAlign.fromInt(Math.round(value)));
|
||||
} else if (attribute == R.styleable.yoga_yg_align_items) {
|
||||
} else if (attribute == R.styleable.yoga_yg_alignItems) {
|
||||
node.setAlignItems(YogaAlign.fromInt(Math.round(value)));
|
||||
} else if (attribute == R.styleable.yoga_yg_align_self) {
|
||||
} else if (attribute == R.styleable.yoga_yg_alignSelf) {
|
||||
node.setAlignSelf(YogaAlign.fromInt(Math.round(value)));
|
||||
} else if (attribute == R.styleable.yoga_yg_aspect_ratio) {
|
||||
} else if (attribute == R.styleable.yoga_yg_aspectRatio) {
|
||||
node.setAspectRatio(value);
|
||||
} else if (attribute == R.styleable.yoga_yg_border_left) {
|
||||
} else if (attribute == R.styleable.yoga_yg_borderLeft) {
|
||||
node.setBorder(YogaEdge.LEFT, value);
|
||||
} else if (attribute == R.styleable.yoga_yg_border_top) {
|
||||
} else if (attribute == R.styleable.yoga_yg_borderTop) {
|
||||
node.setBorder(YogaEdge.TOP, value);
|
||||
} else if (attribute == R.styleable.yoga_yg_border_right) {
|
||||
} else if (attribute == R.styleable.yoga_yg_borderRight) {
|
||||
node.setBorder(YogaEdge.RIGHT, value);
|
||||
} else if (attribute == R.styleable.yoga_yg_border_bottom) {
|
||||
} else if (attribute == R.styleable.yoga_yg_borderBottom) {
|
||||
node.setBorder(YogaEdge.BOTTOM, value);
|
||||
} else if (attribute == R.styleable.yoga_yg_border_start) {
|
||||
} else if (attribute == R.styleable.yoga_yg_borderStart) {
|
||||
node.setBorder(YogaEdge.START, value);
|
||||
} else if (attribute == R.styleable.yoga_yg_border_end) {
|
||||
} else if (attribute == R.styleable.yoga_yg_borderEnd) {
|
||||
node.setBorder(YogaEdge.END, value);
|
||||
} else if (attribute == R.styleable.yoga_yg_border_horizontal) {
|
||||
} else if (attribute == R.styleable.yoga_yg_borderHorizontal) {
|
||||
node.setBorder(YogaEdge.HORIZONTAL, value);
|
||||
} else if (attribute == R.styleable.yoga_yg_border_vertical) {
|
||||
} else if (attribute == R.styleable.yoga_yg_borderVertical) {
|
||||
node.setBorder(YogaEdge.VERTICAL, value);
|
||||
} else if (attribute == R.styleable.yoga_yg_border_all) {
|
||||
} else if (attribute == R.styleable.yoga_yg_borderAll) {
|
||||
node.setBorder(YogaEdge.ALL, value);
|
||||
} else if (attribute == R.styleable.yoga_yg_direction) {
|
||||
node.setDirection(YogaDirection.fromInt(Math.round(value)));
|
||||
@@ -435,83 +445,83 @@ public class YogaLayout extends ViewGroup {
|
||||
node.setDisplay(YogaDisplay.fromInt(Math.round(value)));
|
||||
} else if (attribute == R.styleable.yoga_yg_flex) {
|
||||
node.setFlex(value);
|
||||
} else if (attribute == R.styleable.yoga_yg_flex_basis) {
|
||||
} else if (attribute == R.styleable.yoga_yg_flexBasis) {
|
||||
node.setFlexBasis(value);
|
||||
} else if (attribute == R.styleable.yoga_yg_flex_direction) {
|
||||
} else if (attribute == R.styleable.yoga_yg_flexDirection) {
|
||||
node.setFlexDirection(YogaFlexDirection.fromInt(Math.round(value)));
|
||||
} else if (attribute == R.styleable.yoga_yg_flex_grow) {
|
||||
} else if (attribute == R.styleable.yoga_yg_flexGrow) {
|
||||
node.setFlexGrow(value);
|
||||
} else if (attribute == R.styleable.yoga_yg_flex_shrink) {
|
||||
} else if (attribute == R.styleable.yoga_yg_flexShrink) {
|
||||
node.setFlexShrink(value);
|
||||
} else if (attribute == R.styleable.yoga_yg_height) {
|
||||
node.setHeight(value);
|
||||
} else if (attribute == R.styleable.yoga_yg_margin_left) {
|
||||
} else if (attribute == R.styleable.yoga_yg_marginLeft) {
|
||||
node.setMargin(YogaEdge.LEFT, value);
|
||||
} else if (attribute == R.styleable.yoga_yg_justify_content) {
|
||||
} else if (attribute == R.styleable.yoga_yg_justifyContent) {
|
||||
node.setJustifyContent(YogaJustify.fromInt(Math.round(value)));
|
||||
} else if (attribute == R.styleable.yoga_yg_margin_top) {
|
||||
} else if (attribute == R.styleable.yoga_yg_marginTop) {
|
||||
node.setMargin(YogaEdge.TOP, value);
|
||||
} else if (attribute == R.styleable.yoga_yg_margin_right) {
|
||||
} else if (attribute == R.styleable.yoga_yg_marginRight) {
|
||||
node.setMargin(YogaEdge.RIGHT, value);
|
||||
} else if (attribute == R.styleable.yoga_yg_margin_bottom) {
|
||||
} else if (attribute == R.styleable.yoga_yg_marginBottom) {
|
||||
node.setMargin(YogaEdge.BOTTOM, value);
|
||||
} else if (attribute == R.styleable.yoga_yg_margin_start) {
|
||||
} else if (attribute == R.styleable.yoga_yg_marginStart) {
|
||||
node.setMargin(YogaEdge.START, value);
|
||||
} else if (attribute == R.styleable.yoga_yg_margin_end) {
|
||||
} else if (attribute == R.styleable.yoga_yg_marginEnd) {
|
||||
node.setMargin(YogaEdge.END, value);
|
||||
} else if (attribute == R.styleable.yoga_yg_margin_horizontal) {
|
||||
} else if (attribute == R.styleable.yoga_yg_marginHorizontal) {
|
||||
node.setMargin(YogaEdge.HORIZONTAL, value);
|
||||
} else if (attribute == R.styleable.yoga_yg_margin_vertical) {
|
||||
} else if (attribute == R.styleable.yoga_yg_marginVertical) {
|
||||
node.setMargin(YogaEdge.VERTICAL, value);
|
||||
} else if (attribute == R.styleable.yoga_yg_margin_all) {
|
||||
} else if (attribute == R.styleable.yoga_yg_marginAll) {
|
||||
node.setMargin(YogaEdge.ALL, value);
|
||||
} else if (attribute == R.styleable.yoga_yg_max_height) {
|
||||
} else if (attribute == R.styleable.yoga_yg_maxHeight) {
|
||||
node.setMaxHeight(value);
|
||||
} else if (attribute == R.styleable.yoga_yg_max_width) {
|
||||
} else if (attribute == R.styleable.yoga_yg_maxWidth) {
|
||||
node.setMaxWidth(value);
|
||||
} else if (attribute == R.styleable.yoga_yg_min_height) {
|
||||
} else if (attribute == R.styleable.yoga_yg_minHeight) {
|
||||
node.setMinHeight(value);
|
||||
} else if (attribute == R.styleable.yoga_yg_min_width) {
|
||||
} else if (attribute == R.styleable.yoga_yg_minWidth) {
|
||||
node.setMinWidth(value);
|
||||
} else if (attribute == R.styleable.yoga_yg_overflow) {
|
||||
node.setOverflow(YogaOverflow.fromInt(Math.round(value)));
|
||||
} else if (attribute == R.styleable.yoga_yg_padding_left) {
|
||||
} else if (attribute == R.styleable.yoga_yg_paddingLeft) {
|
||||
node.setPadding(YogaEdge.LEFT, value);
|
||||
} else if (attribute == R.styleable.yoga_yg_padding_top) {
|
||||
} else if (attribute == R.styleable.yoga_yg_paddingTop) {
|
||||
node.setPadding(YogaEdge.TOP, value);
|
||||
} else if (attribute == R.styleable.yoga_yg_padding_right) {
|
||||
} else if (attribute == R.styleable.yoga_yg_paddingRight) {
|
||||
node.setPadding(YogaEdge.RIGHT, value);
|
||||
} else if (attribute == R.styleable.yoga_yg_padding_bottom) {
|
||||
} else if (attribute == R.styleable.yoga_yg_paddingBottom) {
|
||||
node.setPadding(YogaEdge.BOTTOM, value);
|
||||
} else if (attribute == R.styleable.yoga_yg_padding_start) {
|
||||
} else if (attribute == R.styleable.yoga_yg_paddingStart) {
|
||||
node.setPadding(YogaEdge.START, value);
|
||||
} else if (attribute == R.styleable.yoga_yg_padding_end) {
|
||||
} else if (attribute == R.styleable.yoga_yg_paddingEnd) {
|
||||
node.setPadding(YogaEdge.END, value);
|
||||
} else if (attribute == R.styleable.yoga_yg_padding_horizontal) {
|
||||
} else if (attribute == R.styleable.yoga_yg_paddingHorizontal) {
|
||||
node.setPadding(YogaEdge.HORIZONTAL, value);
|
||||
} else if (attribute == R.styleable.yoga_yg_padding_vertical) {
|
||||
} else if (attribute == R.styleable.yoga_yg_paddingVertical) {
|
||||
node.setPadding(YogaEdge.VERTICAL, value);
|
||||
} else if (attribute == R.styleable.yoga_yg_padding_all) {
|
||||
} else if (attribute == R.styleable.yoga_yg_paddingAll) {
|
||||
node.setPadding(YogaEdge.ALL, value);
|
||||
} else if (attribute == R.styleable.yoga_yg_position_left) {
|
||||
} else if (attribute == R.styleable.yoga_yg_positionLeft) {
|
||||
node.setPosition(YogaEdge.LEFT, value);
|
||||
} else if (attribute == R.styleable.yoga_yg_position_top) {
|
||||
} else if (attribute == R.styleable.yoga_yg_positionTop) {
|
||||
node.setPosition(YogaEdge.TOP, value);
|
||||
} else if (attribute == R.styleable.yoga_yg_position_right) {
|
||||
} else if (attribute == R.styleable.yoga_yg_positionRight) {
|
||||
node.setPosition(YogaEdge.RIGHT, value);
|
||||
} else if (attribute == R.styleable.yoga_yg_position_bottom) {
|
||||
} else if (attribute == R.styleable.yoga_yg_positionBottom) {
|
||||
node.setPosition(YogaEdge.BOTTOM, value);
|
||||
} else if (attribute == R.styleable.yoga_yg_position_start) {
|
||||
} else if (attribute == R.styleable.yoga_yg_positionStart) {
|
||||
node.setPosition(YogaEdge.START, value);
|
||||
} else if (attribute == R.styleable.yoga_yg_position_end) {
|
||||
} else if (attribute == R.styleable.yoga_yg_positionEnd) {
|
||||
node.setPosition(YogaEdge.END, value);
|
||||
} else if (attribute == R.styleable.yoga_yg_position_horizontal) {
|
||||
} else if (attribute == R.styleable.yoga_yg_positionHorizontal) {
|
||||
node.setPosition(YogaEdge.HORIZONTAL, value);
|
||||
} else if (attribute == R.styleable.yoga_yg_position_vertical) {
|
||||
} else if (attribute == R.styleable.yoga_yg_positionVertical) {
|
||||
node.setPosition(YogaEdge.VERTICAL, value);
|
||||
} else if (attribute == R.styleable.yoga_yg_position_all) {
|
||||
} else if (attribute == R.styleable.yoga_yg_positionAll) {
|
||||
node.setPosition(YogaEdge.ALL, value);
|
||||
} else if (attribute == R.styleable.yoga_yg_position_type) {
|
||||
} else if (attribute == R.styleable.yoga_yg_positionType) {
|
||||
node.setPositionType(YogaPositionType.fromInt(Math.round(value)));
|
||||
} else if (attribute == R.styleable.yoga_yg_width) {
|
||||
node.setWidth(value);
|
||||
@@ -525,23 +535,23 @@ public class YogaLayout extends ViewGroup {
|
||||
final String value = layoutParameters.stringAttributes.valueAt(i);
|
||||
|
||||
if (value.equals("auto")) {
|
||||
if (attribute == R.styleable.yoga_yg_margin_left) {
|
||||
if (attribute == R.styleable.yoga_yg_marginLeft) {
|
||||
node.setMarginAuto(YogaEdge.LEFT);
|
||||
} else if (attribute == R.styleable.yoga_yg_margin_top) {
|
||||
} else if (attribute == R.styleable.yoga_yg_marginTop) {
|
||||
node.setMarginAuto(YogaEdge.TOP);
|
||||
} else if (attribute == R.styleable.yoga_yg_margin_right) {
|
||||
} else if (attribute == R.styleable.yoga_yg_marginRight) {
|
||||
node.setMarginAuto(YogaEdge.RIGHT);
|
||||
} else if (attribute == R.styleable.yoga_yg_margin_bottom) {
|
||||
} else if (attribute == R.styleable.yoga_yg_marginBottom) {
|
||||
node.setMarginAuto(YogaEdge.BOTTOM);
|
||||
} else if (attribute == R.styleable.yoga_yg_margin_start) {
|
||||
} else if (attribute == R.styleable.yoga_yg_marginStart) {
|
||||
node.setMarginAuto(YogaEdge.START);
|
||||
} else if (attribute == R.styleable.yoga_yg_margin_end) {
|
||||
} else if (attribute == R.styleable.yoga_yg_marginEnd) {
|
||||
node.setMarginAuto(YogaEdge.END);
|
||||
} else if (attribute == R.styleable.yoga_yg_margin_horizontal) {
|
||||
} else if (attribute == R.styleable.yoga_yg_marginHorizontal) {
|
||||
node.setMarginAuto(YogaEdge.HORIZONTAL);
|
||||
} else if (attribute == R.styleable.yoga_yg_margin_vertical) {
|
||||
} else if (attribute == R.styleable.yoga_yg_marginVertical) {
|
||||
node.setMarginAuto(YogaEdge.VERTICAL);
|
||||
} else if (attribute == R.styleable.yoga_yg_margin_all) {
|
||||
} else if (attribute == R.styleable.yoga_yg_marginAll) {
|
||||
node.setMarginAuto(YogaEdge.ALL);
|
||||
}
|
||||
}
|
||||
@@ -549,71 +559,71 @@ public class YogaLayout extends ViewGroup {
|
||||
if (value.endsWith("%")) {
|
||||
final float numericValue = Float.parseFloat(value.substring(0, value.length()-1));
|
||||
|
||||
if (attribute == R.styleable.yoga_yg_flex_basis) {
|
||||
if (attribute == R.styleable.yoga_yg_flexBasis) {
|
||||
node.setFlexBasisPercent(numericValue);
|
||||
} else if (attribute == R.styleable.yoga_yg_height) {
|
||||
node.setHeightPercent(numericValue);
|
||||
} else if (attribute == R.styleable.yoga_yg_margin_left) {
|
||||
} else if (attribute == R.styleable.yoga_yg_marginLeft) {
|
||||
node.setMarginPercent(YogaEdge.LEFT, numericValue);
|
||||
} else if (attribute == R.styleable.yoga_yg_margin_top) {
|
||||
} else if (attribute == R.styleable.yoga_yg_marginTop) {
|
||||
node.setMarginPercent(YogaEdge.TOP, numericValue);
|
||||
} else if (attribute == R.styleable.yoga_yg_margin_right) {
|
||||
} else if (attribute == R.styleable.yoga_yg_marginRight) {
|
||||
node.setMarginPercent(YogaEdge.RIGHT, numericValue);
|
||||
} else if (attribute == R.styleable.yoga_yg_margin_bottom) {
|
||||
} else if (attribute == R.styleable.yoga_yg_marginBottom) {
|
||||
node.setMarginPercent(YogaEdge.BOTTOM, numericValue);
|
||||
} else if (attribute == R.styleable.yoga_yg_margin_start) {
|
||||
} else if (attribute == R.styleable.yoga_yg_marginStart) {
|
||||
node.setMarginPercent(YogaEdge.START, numericValue);
|
||||
} else if (attribute == R.styleable.yoga_yg_margin_end) {
|
||||
} else if (attribute == R.styleable.yoga_yg_marginEnd) {
|
||||
node.setMarginPercent(YogaEdge.END, numericValue);
|
||||
} else if (attribute == R.styleable.yoga_yg_margin_horizontal) {
|
||||
} else if (attribute == R.styleable.yoga_yg_marginHorizontal) {
|
||||
node.setMarginPercent(YogaEdge.HORIZONTAL, numericValue);
|
||||
} else if (attribute == R.styleable.yoga_yg_margin_vertical) {
|
||||
} else if (attribute == R.styleable.yoga_yg_marginVertical) {
|
||||
node.setMarginPercent(YogaEdge.VERTICAL, numericValue);
|
||||
} else if (attribute == R.styleable.yoga_yg_margin_all) {
|
||||
} else if (attribute == R.styleable.yoga_yg_marginAll) {
|
||||
node.setMarginPercent(YogaEdge.ALL, numericValue);
|
||||
} else if (attribute == R.styleable.yoga_yg_max_height) {
|
||||
} else if (attribute == R.styleable.yoga_yg_maxHeight) {
|
||||
node.setMaxHeightPercent(numericValue);
|
||||
} else if (attribute == R.styleable.yoga_yg_max_width) {
|
||||
} else if (attribute == R.styleable.yoga_yg_maxWidth) {
|
||||
node.setMaxWidthPercent(numericValue);
|
||||
} else if (attribute == R.styleable.yoga_yg_min_height) {
|
||||
} else if (attribute == R.styleable.yoga_yg_minHeight) {
|
||||
node.setMinHeightPercent(numericValue);
|
||||
} else if (attribute == R.styleable.yoga_yg_min_width) {
|
||||
} else if (attribute == R.styleable.yoga_yg_minWidth) {
|
||||
node.setMinWidthPercent(numericValue);
|
||||
} else if (attribute == R.styleable.yoga_yg_padding_left) {
|
||||
} else if (attribute == R.styleable.yoga_yg_paddingLeft) {
|
||||
node.setPaddingPercent(YogaEdge.LEFT, numericValue);
|
||||
} else if (attribute == R.styleable.yoga_yg_padding_top) {
|
||||
} else if (attribute == R.styleable.yoga_yg_paddingTop) {
|
||||
node.setPaddingPercent(YogaEdge.TOP, numericValue);
|
||||
} else if (attribute == R.styleable.yoga_yg_padding_right) {
|
||||
} else if (attribute == R.styleable.yoga_yg_paddingRight) {
|
||||
node.setPaddingPercent(YogaEdge.RIGHT, numericValue);
|
||||
} else if (attribute == R.styleable.yoga_yg_padding_bottom) {
|
||||
} else if (attribute == R.styleable.yoga_yg_paddingBottom) {
|
||||
node.setPaddingPercent(YogaEdge.BOTTOM, numericValue);
|
||||
} else if (attribute == R.styleable.yoga_yg_padding_start) {
|
||||
} else if (attribute == R.styleable.yoga_yg_paddingStart) {
|
||||
node.setPaddingPercent(YogaEdge.START, numericValue);
|
||||
} else if (attribute == R.styleable.yoga_yg_padding_end) {
|
||||
} else if (attribute == R.styleable.yoga_yg_paddingEnd) {
|
||||
node.setPaddingPercent(YogaEdge.END, numericValue);
|
||||
} else if (attribute == R.styleable.yoga_yg_padding_horizontal) {
|
||||
} else if (attribute == R.styleable.yoga_yg_paddingHorizontal) {
|
||||
node.setPaddingPercent(YogaEdge.HORIZONTAL, numericValue);
|
||||
} else if (attribute == R.styleable.yoga_yg_padding_vertical) {
|
||||
} else if (attribute == R.styleable.yoga_yg_paddingVertical) {
|
||||
node.setPaddingPercent(YogaEdge.VERTICAL, numericValue);
|
||||
} else if (attribute == R.styleable.yoga_yg_padding_all) {
|
||||
} else if (attribute == R.styleable.yoga_yg_paddingAll) {
|
||||
node.setPaddingPercent(YogaEdge.ALL, numericValue);
|
||||
} else if (attribute == R.styleable.yoga_yg_position_left) {
|
||||
} else if (attribute == R.styleable.yoga_yg_positionLeft) {
|
||||
node.setPositionPercent(YogaEdge.LEFT, numericValue);
|
||||
} else if (attribute == R.styleable.yoga_yg_position_top) {
|
||||
} else if (attribute == R.styleable.yoga_yg_positionTop) {
|
||||
node.setPositionPercent(YogaEdge.TOP, numericValue);
|
||||
} else if (attribute == R.styleable.yoga_yg_position_right) {
|
||||
} else if (attribute == R.styleable.yoga_yg_positionRight) {
|
||||
node.setPositionPercent(YogaEdge.RIGHT, numericValue);
|
||||
} else if (attribute == R.styleable.yoga_yg_position_bottom) {
|
||||
} else if (attribute == R.styleable.yoga_yg_positionBottom) {
|
||||
node.setPositionPercent(YogaEdge.BOTTOM, numericValue);
|
||||
} else if (attribute == R.styleable.yoga_yg_position_start) {
|
||||
} else if (attribute == R.styleable.yoga_yg_positionStart) {
|
||||
node.setPositionPercent(YogaEdge.START, numericValue);
|
||||
} else if (attribute == R.styleable.yoga_yg_position_end) {
|
||||
} else if (attribute == R.styleable.yoga_yg_positionEnd) {
|
||||
node.setPositionPercent(YogaEdge.END, numericValue);
|
||||
} else if (attribute == R.styleable.yoga_yg_position_horizontal) {
|
||||
} else if (attribute == R.styleable.yoga_yg_positionHorizontal) {
|
||||
node.setPositionPercent(YogaEdge.HORIZONTAL, numericValue);
|
||||
} else if (attribute == R.styleable.yoga_yg_position_vertical) {
|
||||
} else if (attribute == R.styleable.yoga_yg_positionVertical) {
|
||||
node.setPositionPercent(YogaEdge.VERTICAL, numericValue);
|
||||
} else if (attribute == R.styleable.yoga_yg_position_all) {
|
||||
} else if (attribute == R.styleable.yoga_yg_positionAll) {
|
||||
node.setPositionPercent(YogaEdge.ALL, numericValue);
|
||||
} else if (attribute == R.styleable.yoga_yg_width) {
|
||||
node.setWidthPercent(numericValue);
|
||||
@@ -779,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,
|
||||
|
@@ -12,7 +12,7 @@
|
||||
<resources>
|
||||
<declare-styleable name="yoga">
|
||||
|
||||
<attr name="yg_align_content" format="enum">
|
||||
<attr name="yg_alignContent" format="enum">
|
||||
<enum name="auto" value="0"/>
|
||||
<enum name="flex_start" value="1"/>
|
||||
<enum name="center" value="2"/>
|
||||
@@ -21,7 +21,7 @@
|
||||
<enum name="baseline" value="5"/>
|
||||
</attr>
|
||||
|
||||
<attr name="yg_align_items" format="enum">
|
||||
<attr name="yg_alignItems" format="enum">
|
||||
<enum name="auto" value="0"/>
|
||||
<enum name="flex_start" value="1"/>
|
||||
<enum name="center" value="2"/>
|
||||
@@ -30,7 +30,7 @@
|
||||
<enum name="baseline" value="5"/>
|
||||
</attr>
|
||||
|
||||
<attr name="yg_align_self" format="enum">
|
||||
<attr name="yg_alignSelf" format="enum">
|
||||
<enum name="auto" value="0"/>
|
||||
<enum name="flex_start" value="1"/>
|
||||
<enum name="center" value="2"/>
|
||||
@@ -39,17 +39,17 @@
|
||||
<enum name="baseline" value="5"/>
|
||||
</attr>
|
||||
|
||||
<attr name="yg_aspect_ratio" format="float"/>
|
||||
<attr name="yg_aspectRatio" format="float"/>
|
||||
|
||||
<attr name="yg_border_left" format="dimension"/>
|
||||
<attr name="yg_border_top" format="dimension"/>
|
||||
<attr name="yg_border_right" format="dimension"/>
|
||||
<attr name="yg_border_bottom" format="dimension"/>
|
||||
<attr name="yg_border_start" format="dimension"/>
|
||||
<attr name="yg_border_end" format="dimension"/>
|
||||
<attr name="yg_border_horizontal" format="dimension"/>
|
||||
<attr name="yg_border_vertical" format="dimension"/>
|
||||
<attr name="yg_border_all" format="dimension"/>
|
||||
<attr name="yg_borderLeft" format="dimension"/>
|
||||
<attr name="yg_borderTop" format="dimension"/>
|
||||
<attr name="yg_borderRight" format="dimension"/>
|
||||
<attr name="yg_borderBottom" format="dimension"/>
|
||||
<attr name="yg_borderStart" format="dimension"/>
|
||||
<attr name="yg_borderEnd" format="dimension"/>
|
||||
<attr name="yg_borderHorizontal" format="dimension"/>
|
||||
<attr name="yg_borderVertical" format="dimension"/>
|
||||
<attr name="yg_borderAll" format="dimension"/>
|
||||
|
||||
<attr name="yg_direction" format="enum">
|
||||
<enum name="inherit" value="0"/>
|
||||
@@ -64,22 +64,22 @@
|
||||
|
||||
<attr name="yg_flex" format="float"/>
|
||||
|
||||
<attr name="yg_flex_basis" format="float|string"/>
|
||||
<attr name="yg_flexBasis" format="float|string"/>
|
||||
|
||||
<attr name="yg_flex_direction" format="enum">
|
||||
<attr name="yg_flexDirection" format="enum">
|
||||
<enum name="column" value="0"/>
|
||||
<enum name="column_reverse" value="1"/>
|
||||
<enum name="row" value="2"/>
|
||||
<enum name="row_reverse" value="3"/>
|
||||
</attr>
|
||||
|
||||
<attr name="yg_flex_grow" format="float"/>
|
||||
<attr name="yg_flexGrow" format="float"/>
|
||||
|
||||
<attr name="yg_flex_shrink" format="float"/>
|
||||
<attr name="yg_flexShrink" format="float"/>
|
||||
|
||||
<attr name="yg_height" format="dimension|string"/>
|
||||
|
||||
<attr name="yg_justify_content" format="enum">
|
||||
<attr name="yg_justifyContent" format="enum">
|
||||
<enum name="flex_start" value="0"/>
|
||||
<enum name="center" value="1"/>
|
||||
<enum name="flex_end" value="2"/>
|
||||
@@ -87,23 +87,23 @@
|
||||
<enum name="space_around" value="4"/>
|
||||
</attr>
|
||||
|
||||
<attr name="yg_margin_left" format="dimension|string"/>
|
||||
<attr name="yg_margin_top" format="dimension|string"/>
|
||||
<attr name="yg_margin_right" format="dimension|string"/>
|
||||
<attr name="yg_margin_bottom" format="dimension|string"/>
|
||||
<attr name="yg_margin_start" format="dimension|string"/>
|
||||
<attr name="yg_margin_end" format="dimension|string"/>
|
||||
<attr name="yg_margin_horizontal" format="dimension|string"/>
|
||||
<attr name="yg_margin_vertical" format="dimension|string"/>
|
||||
<attr name="yg_margin_all" format="dimension|string"/>
|
||||
<attr name="yg_marginLeft" format="dimension|string"/>
|
||||
<attr name="yg_marginTop" format="dimension|string"/>
|
||||
<attr name="yg_marginRight" format="dimension|string"/>
|
||||
<attr name="yg_marginBottom" format="dimension|string"/>
|
||||
<attr name="yg_marginStart" format="dimension|string"/>
|
||||
<attr name="yg_marginEnd" format="dimension|string"/>
|
||||
<attr name="yg_marginHorizontal" format="dimension|string"/>
|
||||
<attr name="yg_marginVertical" format="dimension|string"/>
|
||||
<attr name="yg_marginAll" format="dimension|string"/>
|
||||
|
||||
<attr name="yg_max_height" format="dimension|string"/>
|
||||
<attr name="yg_maxHeight" format="dimension|string"/>
|
||||
|
||||
<attr name="yg_max_width" format="dimension|string"/>
|
||||
<attr name="yg_maxWidth" format="dimension|string"/>
|
||||
|
||||
<attr name="yg_min_height" format="dimension|string"/>
|
||||
<attr name="yg_minHeight" format="dimension|string"/>
|
||||
|
||||
<attr name="yg_min_width" format="dimension|string"/>
|
||||
<attr name="yg_minWidth" format="dimension|string"/>
|
||||
|
||||
<attr name="yg_overflow" format="enum">
|
||||
<enum name="visible" value="0"/>
|
||||
@@ -111,27 +111,27 @@
|
||||
<enum name="scroll" value="2"/>
|
||||
</attr>
|
||||
|
||||
<attr name="yg_padding_left" format="dimension|string"/>
|
||||
<attr name="yg_padding_top" format="dimension|string"/>
|
||||
<attr name="yg_padding_right" format="dimension|string"/>
|
||||
<attr name="yg_padding_bottom" format="dimension|string"/>
|
||||
<attr name="yg_padding_start" format="dimension|string"/>
|
||||
<attr name="yg_padding_end" format="dimension|string"/>
|
||||
<attr name="yg_padding_horizontal" format="dimension|string"/>
|
||||
<attr name="yg_padding_vertical" format="dimension|string"/>
|
||||
<attr name="yg_padding_all" format="dimension|string"/>
|
||||
<attr name="yg_paddingLeft" format="dimension|string"/>
|
||||
<attr name="yg_paddingTop" format="dimension|string"/>
|
||||
<attr name="yg_paddingRight" format="dimension|string"/>
|
||||
<attr name="yg_paddingBottom" format="dimension|string"/>
|
||||
<attr name="yg_paddingStart" format="dimension|string"/>
|
||||
<attr name="yg_paddingEnd" format="dimension|string"/>
|
||||
<attr name="yg_paddingHorizontal" format="dimension|string"/>
|
||||
<attr name="yg_paddingVertical" format="dimension|string"/>
|
||||
<attr name="yg_paddingAll" format="dimension|string"/>
|
||||
|
||||
<attr name="yg_position_left" format="dimension|string"/>
|
||||
<attr name="yg_position_top" format="dimension|string"/>
|
||||
<attr name="yg_position_right" format="dimension|string"/>
|
||||
<attr name="yg_position_bottom" format="dimension|string"/>
|
||||
<attr name="yg_position_start" format="dimension|string"/>
|
||||
<attr name="yg_position_end" format="dimension|string"/>
|
||||
<attr name="yg_position_horizontal" format="dimension|string"/>
|
||||
<attr name="yg_position_vertical" format="dimension|string"/>
|
||||
<attr name="yg_position_all" format="dimension|string"/>
|
||||
<attr name="yg_positionLeft" format="dimension|string"/>
|
||||
<attr name="yg_positionTop" format="dimension|string"/>
|
||||
<attr name="yg_positionRight" format="dimension|string"/>
|
||||
<attr name="yg_positionBottom" format="dimension|string"/>
|
||||
<attr name="yg_positionStart" format="dimension|string"/>
|
||||
<attr name="yg_positionEnd" format="dimension|string"/>
|
||||
<attr name="yg_positionHorizontal" format="dimension|string"/>
|
||||
<attr name="yg_positionVertical" format="dimension|string"/>
|
||||
<attr name="yg_positionAll" format="dimension|string"/>
|
||||
|
||||
<attr name="yg_position_type" format="enum">
|
||||
<attr name="yg_positionType" format="enum">
|
||||
<enum name="relative" value="0"/>
|
||||
<enum name="absolute" value="1"/>
|
||||
</attr>
|
||||
|
44
build.gradle
44
build.gradle
@@ -5,7 +5,7 @@ buildscript {
|
||||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:2.2.2'
|
||||
classpath 'com.android.tools.build:gradle:2.3.3'
|
||||
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,45 @@ 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 = 14
|
||||
targetSdkVersion = 25
|
||||
compileSdkVersion = 25
|
||||
buildToolsVersion = '25.0.2'
|
||||
sourceCompatibilityVersion = JavaVersion.VERSION_1_7
|
||||
targetCompatibilityVersion = JavaVersion.VERSION_1_7
|
||||
}
|
||||
|
||||
// If you have an idea on how to avoid this, please get in touch or
|
||||
// answer https://stackoverflow.com/questions/43867014/how-to-use-the-gradle-ndk-build-to-compile-for-the-host-machine.
|
||||
task copyNativeLibs(type: Copy, dependsOn: ':buckBuildNative') {
|
||||
from "${rootDir}/buck-out/gen/java/tests#default,shared-library-symlink-tree/"
|
||||
include '*.so'
|
||||
include '*.dylib'
|
||||
into "$buildDir/jniLibs"
|
||||
}
|
||||
|
||||
task buckBuildNative(type: Exec) {
|
||||
workingDir rootDir
|
||||
environment BUCKVERSION: 'last'
|
||||
commandLine 'buck', 'build', '//java/...'
|
||||
}
|
||||
|
||||
allprojects {
|
||||
afterEvaluate {
|
||||
tasks.withType(Test) {
|
||||
dependsOn copyNativeLibs
|
||||
def libDir = "${rootDir}/build/jniLibs"
|
||||
systemProperty 'java.library.path', libDir
|
||||
environment 'LD_LIBRARY_PATH', libDir
|
||||
environment 'DYLD_LIBRARY_PATH', libDir
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
task clean(type: Delete) {
|
||||
delete rootProject.buildDir
|
||||
}
|
||||
|
3
csharp/.gitignore
vendored
3
csharp/.gitignore
vendored
@@ -267,3 +267,6 @@ paket-files/
|
||||
# Python Tools for Visual Studio (PTVS)
|
||||
__pycache__/
|
||||
*.pyc
|
||||
|
||||
# local buck build
|
||||
lib/
|
||||
|
@@ -267,3 +267,6 @@ paket-files/
|
||||
# Python Tools for Visual Studio (PTVS)
|
||||
__pycache__/
|
||||
*.pyc
|
||||
|
||||
# local buck build
|
||||
lib/
|
||||
|
@@ -4,17 +4,17 @@
|
||||
<BuildDependsOn>NativeLibraryARMV7;NativeLibraryX86;$(BuildDependsOn)</BuildDependsOn>
|
||||
</PropertyGroup>
|
||||
<Target Name="NativeLibraryARMV7" Outputs="$(ProjectDir)/lib/armeabi-v7a/libyoga.so">
|
||||
<Exec WorkingDirectory="$(ProjectDir)" Command="$(ProjectDir)../../Mac/buck-build.sh //csharp:yoganet#android-armv7,shared" />
|
||||
<Exec WorkingDirectory="$(ProjectDir)" Command="$(ProjectDir)../../build-native.sh" />
|
||||
<Copy SourceFiles="$(ProjectDir)../../../buck-out/gen/csharp/yoganet#android-armv7,shared/libyoga.so" DestinationFiles="$(ProjectDir)/lib/armeabi-v7a/libyoga.so" SkipUnchangedFiles="true" />
|
||||
</Target>
|
||||
<!--
|
||||
<Target Name="NativeLibraryARM64" Outputs="$(ProjectDir)/lib/arm64-v8a/libyoga.so">
|
||||
<Exec WorkingDirectory="$(ProjectDir)" Command="$(ProjectDir)../../Mac/buck-build.sh //csharp:yoganet#android-arm64,shared" />
|
||||
<Exec WorkingDirectory="$(ProjectDir)" Command="$(ProjectDir)../../build-native.sh" />
|
||||
<Copy SourceFiles="$(ProjectDir)../../../buck-out/gen/csharp/yoganet#android-arm64,shared/libyoga.so" DestinationFiles="$(ProjectDir)/lib/arm64-v8/libyoga.so" SkipUnchangedFiles="true" />
|
||||
</Target>
|
||||
-->
|
||||
<Target Name="NativeLibraryX86" Outputs="$(ProjectDir)/lib/x86/libyoga.so">
|
||||
<Exec WorkingDirectory="$(ProjectDir)" Command="$(ProjectDir)../../Mac/buck-build.sh //csharp:yoganet#android-x86,shared" />
|
||||
<Exec WorkingDirectory="$(ProjectDir)" Command="$(ProjectDir)../../build-native.sh" />
|
||||
<Copy SourceFiles="$(ProjectDir)../../../buck-out/gen/csharp/yoganet#android-x86,shared/libyoga.so" DestinationFiles="$(ProjectDir)/lib/x86/libyoga.so" SkipUnchangedFiles="true" />
|
||||
</Target>
|
||||
</Project>
|
||||
|
@@ -10,11 +10,15 @@
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="$(MSBuildThisFileDirectory)BaselineFunction.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Logger.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)MeasureFunction.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)MeasureOutput.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Native.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)YGConfigHandle.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)YGNodeHandle.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)YogaAlign.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)YogaBaselineFunc.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)YogaConfig.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)YogaConstants.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)YogaDimension.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)YogaDirection.cs" />
|
||||
|
17
csharp/Facebook.Yoga/Logger.cs
Normal file
17
csharp/Facebook.Yoga/Logger.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
namespace Facebook.Yoga
|
||||
{
|
||||
public delegate void Logger(
|
||||
YogaConfig config,
|
||||
YogaNode node,
|
||||
YogaLogLevel level,
|
||||
string message);
|
||||
}
|
@@ -26,96 +26,9 @@ namespace Facebook.Yoga
|
||||
private const string DllName = "yoga";
|
||||
#endif
|
||||
|
||||
internal class YGNodeHandle : SafeHandle
|
||||
{
|
||||
#if (UNITY_IOS && !UNITY_EDITOR) || __IOS__
|
||||
private GCHandle _managed;
|
||||
#endif
|
||||
|
||||
private YGNodeHandle() : base(IntPtr.Zero, true)
|
||||
{
|
||||
}
|
||||
|
||||
public override bool IsInvalid
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.handle == IntPtr.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
protected override bool ReleaseHandle()
|
||||
{
|
||||
#if (UNITY_IOS && !UNITY_EDITOR) || __IOS__
|
||||
if (_managed.IsAllocated)
|
||||
{
|
||||
_managed.Free();
|
||||
}
|
||||
#endif
|
||||
Native.YGNodeFree(this.handle);
|
||||
GC.KeepAlive(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
#if (UNITY_IOS && !UNITY_EDITOR) || __IOS__
|
||||
public void SetContext(YogaNode node)
|
||||
{
|
||||
if (!_managed.IsAllocated)
|
||||
{
|
||||
_managed = GCHandle.Alloc(node, GCHandleType.Weak);
|
||||
Native.YGNodeSetContext(this.handle, GCHandle.ToIntPtr(_managed));
|
||||
}
|
||||
}
|
||||
|
||||
public static YogaNode GetManaged(IntPtr ygNodePtr)
|
||||
{
|
||||
var node =
|
||||
GCHandle.FromIntPtr(Native.YGNodeGetContext(ygNodePtr)).Target as YogaNode;
|
||||
if (node == null)
|
||||
{
|
||||
throw new InvalidOperationException("YogaNode is already deallocated");
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
internal class YGConfigHandle : SafeHandle
|
||||
{
|
||||
#if (UNITY_IOS && !UNITY_EDITOR) || __IOS__
|
||||
private GCHandle _managed;
|
||||
#endif
|
||||
|
||||
private YGConfigHandle() : base(IntPtr.Zero, true)
|
||||
{
|
||||
}
|
||||
|
||||
public override bool IsInvalid
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.handle == IntPtr.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
protected override bool ReleaseHandle()
|
||||
{
|
||||
#if (UNITY_IOS && !UNITY_EDITOR) || __IOS__
|
||||
if (_managed.IsAllocated)
|
||||
{
|
||||
_managed.Free();
|
||||
}
|
||||
#endif
|
||||
Native.YGConfigFree(this.handle);
|
||||
GC.KeepAlive(this);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void YGInteropSetLogger(
|
||||
[MarshalAs(UnmanagedType.FunctionPtr)] YogaLogger.Func func);
|
||||
[MarshalAs(UnmanagedType.FunctionPtr)] YogaLogger logger);
|
||||
|
||||
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern YGNodeHandle YGNodeNew();
|
||||
@@ -129,6 +42,9 @@ namespace Facebook.Yoga
|
||||
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void YGNodeReset(YGNodeHandle node);
|
||||
|
||||
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern YGConfigHandle YGConfigGetDefault();
|
||||
|
||||
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern YGConfigHandle YGConfigNew();
|
||||
|
||||
@@ -138,6 +54,9 @@ namespace Facebook.Yoga
|
||||
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int YGNodeGetInstanceCount();
|
||||
|
||||
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int YGConfigGetInstanceCount();
|
||||
|
||||
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void YGConfigSetExperimentalFeatureEnabled(
|
||||
YGConfigHandle config,
|
||||
@@ -149,6 +68,19 @@ namespace Facebook.Yoga
|
||||
YGConfigHandle config,
|
||||
YogaExperimentalFeature feature);
|
||||
|
||||
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void YGConfigSetUseWebDefaults(
|
||||
YGConfigHandle config,
|
||||
bool useWebDefaults);
|
||||
|
||||
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern bool YGConfigGetUseWebDefaults(YGConfigHandle config);
|
||||
|
||||
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void YGConfigSetPointScaleFactor(
|
||||
YGConfigHandle config,
|
||||
float pixelsInPoint);
|
||||
|
||||
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void YGNodeInsertChild(
|
||||
YGNodeHandle node,
|
||||
@@ -429,15 +361,19 @@ namespace Facebook.Yoga
|
||||
|
||||
#endregion
|
||||
|
||||
#region IOS
|
||||
#region Context
|
||||
|
||||
#if (UNITY_IOS && !UNITY_EDITOR) || __IOS__
|
||||
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr YGNodeGetContext(IntPtr node);
|
||||
|
||||
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void YGNodeSetContext(IntPtr node, IntPtr managed);
|
||||
#endif
|
||||
|
||||
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr YGConfigGetContext(IntPtr config);
|
||||
|
||||
[DllImport(DllName, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void YGConfigSetContext(IntPtr config, IntPtr managed);
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
84
csharp/Facebook.Yoga/YGConfigHandle.cs
Normal file
84
csharp/Facebook.Yoga/YGConfigHandle.cs
Normal file
@@ -0,0 +1,84 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Facebook.Yoga
|
||||
{
|
||||
internal class YGConfigHandle : SafeHandle
|
||||
{
|
||||
internal static readonly YGConfigHandle Default = Native.YGConfigGetDefault();
|
||||
private GCHandle _managedConfigHandle;
|
||||
|
||||
private YGConfigHandle() : base(IntPtr.Zero, true)
|
||||
{
|
||||
}
|
||||
|
||||
public override bool IsInvalid
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.handle == IntPtr.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
protected override bool ReleaseHandle()
|
||||
{
|
||||
if (this.handle != Default.handle)
|
||||
{
|
||||
ReleaseManaged();
|
||||
if (!IsInvalid)
|
||||
{
|
||||
Native.YGConfigFree(this.handle);
|
||||
}
|
||||
}
|
||||
GC.KeepAlive(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void SetContext(YogaConfig config)
|
||||
{
|
||||
if (!_managedConfigHandle.IsAllocated)
|
||||
{
|
||||
#if UNITY_5_4_OR_NEWER
|
||||
// Weak causes 'GCHandle value belongs to a different domain' error
|
||||
_managedConfigHandle = GCHandle.Alloc(config);
|
||||
#else
|
||||
_managedConfigHandle = GCHandle.Alloc(config, GCHandleType.Weak);
|
||||
#endif
|
||||
var managedConfigPtr = GCHandle.ToIntPtr(_managedConfigHandle);
|
||||
Native.YGConfigSetContext(this.handle, managedConfigPtr);
|
||||
}
|
||||
}
|
||||
|
||||
private void ReleaseManaged()
|
||||
{
|
||||
if (_managedConfigHandle.IsAllocated)
|
||||
{
|
||||
_managedConfigHandle.Free();
|
||||
}
|
||||
}
|
||||
|
||||
public static YogaConfig GetManaged(IntPtr unmanagedConfigPtr)
|
||||
{
|
||||
if (unmanagedConfigPtr != IntPtr.Zero)
|
||||
{
|
||||
var managedConfigPtr = Native.YGConfigGetContext(unmanagedConfigPtr);
|
||||
var config = GCHandle.FromIntPtr(managedConfigPtr).Target as YogaConfig;
|
||||
if (config == null)
|
||||
{
|
||||
throw new InvalidOperationException("YogaConfig is already deallocated");
|
||||
}
|
||||
return config;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
80
csharp/Facebook.Yoga/YGNodeHandle.cs
Normal file
80
csharp/Facebook.Yoga/YGNodeHandle.cs
Normal file
@@ -0,0 +1,80 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Facebook.Yoga
|
||||
{
|
||||
internal class YGNodeHandle : SafeHandle
|
||||
{
|
||||
private GCHandle _managedNodeHandle;
|
||||
|
||||
private YGNodeHandle() : base(IntPtr.Zero, true)
|
||||
{
|
||||
}
|
||||
|
||||
public override bool IsInvalid
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.handle == IntPtr.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
protected override bool ReleaseHandle()
|
||||
{
|
||||
ReleaseManaged();
|
||||
if (!IsInvalid)
|
||||
{
|
||||
Native.YGNodeFree(this.handle);
|
||||
GC.KeepAlive(this);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void SetContext(YogaNode node)
|
||||
{
|
||||
if (!_managedNodeHandle.IsAllocated)
|
||||
{
|
||||
#if UNITY_5_4_OR_NEWER
|
||||
// Weak causes 'GCHandle value belongs to a different domain' error
|
||||
_managedNodeHandle = GCHandle.Alloc(node);
|
||||
#else
|
||||
_managedNodeHandle = GCHandle.Alloc(node, GCHandleType.Weak);
|
||||
#endif
|
||||
var managedNodePtr = GCHandle.ToIntPtr(_managedNodeHandle);
|
||||
Native.YGNodeSetContext(this.handle, managedNodePtr);
|
||||
}
|
||||
}
|
||||
|
||||
public void ReleaseManaged()
|
||||
{
|
||||
if (_managedNodeHandle.IsAllocated)
|
||||
{
|
||||
_managedNodeHandle.Free();
|
||||
}
|
||||
}
|
||||
|
||||
public static YogaNode GetManaged(IntPtr unmanagedNodePtr)
|
||||
{
|
||||
if (unmanagedNodePtr != IntPtr.Zero)
|
||||
{
|
||||
var managedNodePtr = Native.YGNodeGetContext(unmanagedNodePtr);
|
||||
var node = GCHandle.FromIntPtr(managedNodePtr).Target as YogaNode;
|
||||
if (node == null)
|
||||
{
|
||||
throw new InvalidOperationException("YogaNode is already deallocated");
|
||||
}
|
||||
return node;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@@ -13,5 +13,5 @@ using System.Runtime.InteropServices;
|
||||
namespace Facebook.Yoga
|
||||
{
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
public delegate float YogaBaselineFunc(IntPtr node, float width, float height);
|
||||
public delegate float YogaBaselineFunc(IntPtr unmanagedNodePtr, float width, float height);
|
||||
}
|
||||
|
140
csharp/Facebook.Yoga/YogaConfig.cs
Normal file
140
csharp/Facebook.Yoga/YogaConfig.cs
Normal file
@@ -0,0 +1,140 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
#if __IOS__
|
||||
using ObjCRuntime;
|
||||
#endif
|
||||
#if ENABLE_IL2CPP
|
||||
using AOT;
|
||||
#endif
|
||||
|
||||
namespace Facebook.Yoga
|
||||
{
|
||||
public class YogaConfig
|
||||
{
|
||||
internal static readonly YogaConfig Default = new YogaConfig(YGConfigHandle.Default);
|
||||
private static YogaLogger _managedLogger;
|
||||
|
||||
private YGConfigHandle _ygConfig;
|
||||
private Logger _logger;
|
||||
|
||||
private YogaConfig(YGConfigHandle ygConfig)
|
||||
{
|
||||
_ygConfig = ygConfig;
|
||||
if (_ygConfig.IsInvalid)
|
||||
{
|
||||
throw new InvalidOperationException("Failed to allocate native memory");
|
||||
}
|
||||
|
||||
_ygConfig.SetContext(this);
|
||||
|
||||
if (_ygConfig == YGConfigHandle.Default)
|
||||
{
|
||||
_managedLogger = LoggerInternal;
|
||||
Native.YGInteropSetLogger(_managedLogger);
|
||||
}
|
||||
}
|
||||
|
||||
public YogaConfig()
|
||||
: this(Native.YGConfigNew())
|
||||
{
|
||||
}
|
||||
|
||||
internal YGConfigHandle Handle
|
||||
{
|
||||
get {
|
||||
return _ygConfig;
|
||||
}
|
||||
}
|
||||
|
||||
#if (UNITY_IOS && !UNITY_EDITOR) || ENABLE_IL2CPP || __IOS__
|
||||
[MonoPInvokeCallback(typeof(YogaLogger))]
|
||||
#endif
|
||||
private static void LoggerInternal(
|
||||
IntPtr unmanagedConfigPtr,
|
||||
IntPtr unmanagedNodePtr,
|
||||
YogaLogLevel level,
|
||||
string message)
|
||||
{
|
||||
var config = YGConfigHandle.GetManaged(unmanagedConfigPtr);
|
||||
if (config == null || config._logger == null)
|
||||
{
|
||||
// Default logger
|
||||
System.Diagnostics.Debug.WriteLine(message);
|
||||
}
|
||||
else
|
||||
{
|
||||
var node = YGNodeHandle.GetManaged(unmanagedNodePtr);
|
||||
config._logger(config, node, level, message);
|
||||
}
|
||||
|
||||
if (level == YogaLogLevel.Error || level == YogaLogLevel.Fatal)
|
||||
{
|
||||
throw new InvalidOperationException(message);
|
||||
}
|
||||
}
|
||||
|
||||
public Logger Logger
|
||||
{
|
||||
get {
|
||||
return _logger;
|
||||
}
|
||||
|
||||
set {
|
||||
_logger = value;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetExperimentalFeatureEnabled(
|
||||
YogaExperimentalFeature feature,
|
||||
bool enabled)
|
||||
{
|
||||
Native.YGConfigSetExperimentalFeatureEnabled(_ygConfig, feature, enabled);
|
||||
}
|
||||
|
||||
public bool IsExperimentalFeatureEnabled(YogaExperimentalFeature feature)
|
||||
{
|
||||
return Native.YGConfigIsExperimentalFeatureEnabled(_ygConfig, feature);
|
||||
}
|
||||
|
||||
public bool UseWebDefaults
|
||||
{
|
||||
get
|
||||
{
|
||||
return Native.YGConfigGetUseWebDefaults(_ygConfig);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
Native.YGConfigSetUseWebDefaults(_ygConfig, value);
|
||||
}
|
||||
}
|
||||
|
||||
public float PointScaleFactor
|
||||
{
|
||||
set
|
||||
{
|
||||
Native.YGConfigSetPointScaleFactor(_ygConfig, value);
|
||||
}
|
||||
}
|
||||
|
||||
public static int GetInstanceCount()
|
||||
{
|
||||
return Native.YGConfigGetInstanceCount();
|
||||
}
|
||||
|
||||
public static void SetDefaultLogger(Logger logger)
|
||||
{
|
||||
Default.Logger = logger;
|
||||
}
|
||||
}
|
||||
}
|
@@ -11,8 +11,6 @@ namespace Facebook.Yoga
|
||||
{
|
||||
public enum YogaExperimentalFeature
|
||||
{
|
||||
Rounding,
|
||||
WebFlexBasis,
|
||||
MinFlexFix,
|
||||
}
|
||||
}
|
||||
|
@@ -16,5 +16,6 @@ namespace Facebook.Yoga
|
||||
Info,
|
||||
Debug,
|
||||
Verbose,
|
||||
Fatal,
|
||||
}
|
||||
}
|
||||
|
@@ -10,45 +10,12 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
#if __IOS__
|
||||
using ObjCRuntime;
|
||||
#endif
|
||||
|
||||
namespace Facebook.Yoga
|
||||
{
|
||||
internal static class YogaLogger
|
||||
{
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
public delegate void Func(YogaLogLevel level, string message);
|
||||
|
||||
private static bool _initialized;
|
||||
private static Func _managedLogger = LoggerInternal;
|
||||
|
||||
public static Func Logger = null;
|
||||
|
||||
#if (UNITY_IOS && !UNITY_EDITOR) || __IOS__
|
||||
[MonoPInvokeCallback(typeof(Func))]
|
||||
#endif
|
||||
public static void LoggerInternal(YogaLogLevel level, string message)
|
||||
{
|
||||
if (Logger != null)
|
||||
{
|
||||
Logger(level, message);
|
||||
}
|
||||
|
||||
if (level == YogaLogLevel.Error)
|
||||
{
|
||||
throw new InvalidOperationException(message);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Initialize()
|
||||
{
|
||||
if (!_initialized)
|
||||
{
|
||||
Native.YGInteropSetLogger(_managedLogger);
|
||||
_initialized = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
public delegate void YogaLogger(
|
||||
IntPtr unmanagedConfigPtr,
|
||||
IntPtr unmanagedNotePtr,
|
||||
YogaLogLevel level,
|
||||
string message);
|
||||
}
|
||||
|
@@ -14,7 +14,7 @@ namespace Facebook.Yoga
|
||||
{
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
public delegate YogaSize YogaMeasureFunc(
|
||||
IntPtr node,
|
||||
IntPtr unmanagedNodePtr,
|
||||
float width,
|
||||
YogaMeasureMode widthMode,
|
||||
float height,
|
||||
|
@@ -10,91 +10,44 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
#if (UNITY_IOS && !UNITY_EDITOR) || __IOS__
|
||||
using System.Runtime.InteropServices;
|
||||
#endif
|
||||
#if __IOS__
|
||||
using ObjCRuntime;
|
||||
#endif
|
||||
#if ENABLE_IL2CPP
|
||||
using AOT;
|
||||
#endif
|
||||
|
||||
namespace Facebook.Yoga
|
||||
{
|
||||
public class YogaConfig
|
||||
{
|
||||
|
||||
private Native.YGConfigHandle _ygConfig;
|
||||
|
||||
public YogaConfig()
|
||||
{
|
||||
_ygConfig = Native.YGConfigNew();
|
||||
if (_ygConfig.IsInvalid)
|
||||
{
|
||||
throw new InvalidOperationException("Failed to allocate native memory");
|
||||
}
|
||||
}
|
||||
|
||||
internal Native.YGConfigHandle Handle {
|
||||
get {
|
||||
return _ygConfig;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetExperimentalFeatureEnabled(
|
||||
YogaExperimentalFeature feature,
|
||||
bool enabled)
|
||||
{
|
||||
Native.YGConfigSetExperimentalFeatureEnabled(_ygConfig, feature, enabled);
|
||||
}
|
||||
|
||||
public bool IsExperimentalFeatureEnabled(YogaExperimentalFeature feature)
|
||||
{
|
||||
return Native.YGConfigIsExperimentalFeatureEnabled(_ygConfig, feature);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public partial class YogaNode : IEnumerable<YogaNode>
|
||||
{
|
||||
private Native.YGNodeHandle _ygNode;
|
||||
private readonly YGNodeHandle _ygNode;
|
||||
private readonly YogaConfig _config;
|
||||
private WeakReference _parent;
|
||||
private List<YogaNode> _children;
|
||||
private MeasureFunction _measureFunction;
|
||||
private BaselineFunction _baselineFunction;
|
||||
private object _data;
|
||||
#if (UNITY_IOS && !UNITY_EDITOR) || __IOS__
|
||||
private static YogaMeasureFunc _managedMeasure = MeasureInternalIOS;
|
||||
private static YogaBaselineFunc _managedBaseline = BaselineInternalIOS;
|
||||
#else
|
||||
private YogaMeasureFunc _managedMeasure;
|
||||
private YogaBaselineFunc _managedBaseline;
|
||||
#endif
|
||||
private object _data;
|
||||
|
||||
public YogaNode()
|
||||
public YogaNode(YogaConfig config = null)
|
||||
{
|
||||
YogaLogger.Initialize();
|
||||
|
||||
_ygNode = Native.YGNodeNew();
|
||||
_config = config == null ? YogaConfig.Default : config;
|
||||
_ygNode = Native.YGNodeNewWithConfig(_config.Handle);
|
||||
if (_ygNode.IsInvalid)
|
||||
{
|
||||
throw new InvalidOperationException("Failed to allocate native memory");
|
||||
}
|
||||
}
|
||||
|
||||
public YogaNode(YogaConfig config)
|
||||
{
|
||||
YogaLogger.Initialize();
|
||||
|
||||
_ygNode = Native.YGNodeNewWithConfig(config.Handle);
|
||||
if (_ygNode.IsInvalid)
|
||||
{
|
||||
throw new InvalidOperationException("Failed to allocate native memory");
|
||||
}
|
||||
_ygNode.SetContext(this);
|
||||
}
|
||||
|
||||
public YogaNode(YogaNode srcNode)
|
||||
: this()
|
||||
: this(srcNode._config)
|
||||
{
|
||||
CopyStyle(srcNode);
|
||||
}
|
||||
@@ -105,7 +58,9 @@ namespace Facebook.Yoga
|
||||
_baselineFunction = null;
|
||||
_data = null;
|
||||
|
||||
_ygNode.ReleaseManaged();
|
||||
Native.YGNodeReset(_ygNode);
|
||||
_ygNode.SetContext(this);
|
||||
}
|
||||
|
||||
public bool IsDirty
|
||||
@@ -466,7 +421,7 @@ namespace Facebook.Yoga
|
||||
}
|
||||
}
|
||||
|
||||
public float StyleAspectRatio
|
||||
public float AspectRatio
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -595,6 +550,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)
|
||||
@@ -614,28 +583,15 @@ namespace Facebook.Yoga
|
||||
public void SetMeasureFunction(MeasureFunction measureFunction)
|
||||
{
|
||||
_measureFunction = measureFunction;
|
||||
if (measureFunction != null)
|
||||
{
|
||||
#if (UNITY_IOS && !UNITY_EDITOR) || __IOS__
|
||||
_ygNode.SetContext(this);
|
||||
#else
|
||||
_managedMeasure = MeasureInternal;
|
||||
#endif
|
||||
}
|
||||
_managedMeasure = measureFunction != null ? MeasureInternal : (YogaMeasureFunc)null;
|
||||
Native.YGNodeSetMeasureFunc(_ygNode, _managedMeasure);
|
||||
}
|
||||
|
||||
public void SetBaselineFunction(BaselineFunction baselineFunction)
|
||||
{
|
||||
_baselineFunction = baselineFunction;
|
||||
if (baselineFunction != null)
|
||||
{
|
||||
#if (UNITY_IOS && !UNITY_EDITOR) || __IOS__
|
||||
_ygNode.SetContext(this);
|
||||
#else
|
||||
_managedBaseline = BaselineInternal;
|
||||
#endif
|
||||
}
|
||||
_managedBaseline =
|
||||
baselineFunction != null ? BaselineInternal : (YogaBaselineFunc)null;
|
||||
Native.YGNodeSetBaselineFunc(_ygNode, _managedBaseline);
|
||||
}
|
||||
|
||||
@@ -648,65 +604,48 @@ namespace Facebook.Yoga
|
||||
Native.YGNodeStyleGetDirection(_ygNode));
|
||||
}
|
||||
|
||||
#if (UNITY_IOS && !UNITY_EDITOR) || __IOS__
|
||||
#if (UNITY_IOS && !UNITY_EDITOR) || ENABLE_IL2CPP || __IOS__
|
||||
[MonoPInvokeCallback(typeof(YogaMeasureFunc))]
|
||||
private static YogaSize MeasureInternalIOS(
|
||||
IntPtr ygNodePtr,
|
||||
float width,
|
||||
YogaMeasureMode widthMode,
|
||||
float height,
|
||||
YogaMeasureMode heightMode)
|
||||
{
|
||||
var node = Native.YGNodeHandle.GetManaged(ygNodePtr);
|
||||
return node.MeasureInternal(IntPtr.Zero, width, widthMode, height, heightMode);
|
||||
}
|
||||
#endif
|
||||
|
||||
private YogaSize MeasureInternal(
|
||||
IntPtr node,
|
||||
private static YogaSize MeasureInternal(
|
||||
IntPtr unmanagedNodePtr,
|
||||
float width,
|
||||
YogaMeasureMode widthMode,
|
||||
float height,
|
||||
YogaMeasureMode heightMode)
|
||||
{
|
||||
if (_measureFunction == null)
|
||||
var node = YGNodeHandle.GetManaged(unmanagedNodePtr);
|
||||
if (node == null || node._measureFunction == null)
|
||||
{
|
||||
throw new InvalidOperationException("Measure function is not defined.");
|
||||
}
|
||||
|
||||
return _measureFunction(this, width, widthMode, height, heightMode);
|
||||
return node._measureFunction(node, width, widthMode, height, heightMode);
|
||||
}
|
||||
|
||||
#if (UNITY_IOS && !UNITY_EDITOR) || __IOS__
|
||||
#if (UNITY_IOS && !UNITY_EDITOR) || ENABLE_IL2CPP || __IOS__
|
||||
[MonoPInvokeCallback(typeof(YogaBaselineFunc))]
|
||||
private static float BaselineInternalIOS(
|
||||
IntPtr ygNodePtr,
|
||||
#endif
|
||||
private static float BaselineInternal(
|
||||
IntPtr unmanagedNodePtr,
|
||||
float width,
|
||||
float height)
|
||||
{
|
||||
var node = Native.YGNodeHandle.GetManaged(ygNodePtr);
|
||||
return node.BaselineInternal(IntPtr.Zero, width, height);
|
||||
}
|
||||
#endif
|
||||
|
||||
private float BaselineInternal(IntPtr node, float width, float height)
|
||||
{
|
||||
if (_baselineFunction == null)
|
||||
var node = YGNodeHandle.GetManaged(unmanagedNodePtr);
|
||||
if (node == null || node._baselineFunction == null)
|
||||
{
|
||||
throw new InvalidOperationException("Baseline function is not defined.");
|
||||
}
|
||||
|
||||
return _baselineFunction(this, width, height);
|
||||
return node._baselineFunction(node, width, height);
|
||||
}
|
||||
|
||||
public string Print(YogaPrintOptions options =
|
||||
YogaPrintOptions.Layout|YogaPrintOptions.Style|YogaPrintOptions.Children)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
YogaLogger.Func orig = YogaLogger.Logger;
|
||||
YogaLogger.Logger = (level, message) => {sb.Append(message);};
|
||||
Logger orig = _config.Logger;
|
||||
_config.Logger = (config, node, level, message) => {sb.Append(message);};
|
||||
Native.YGNodePrint(_ygNode, options);
|
||||
YogaLogger.Logger = orig;
|
||||
_config.Logger = orig;
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
|
17
csharp/Facebook.Yoga/YogaNodeType.cs
Normal file
17
csharp/Facebook.Yoga/YogaNodeType.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
namespace Facebook.Yoga
|
||||
{
|
||||
public enum YogaNodeType
|
||||
{
|
||||
Default,
|
||||
Text,
|
||||
}
|
||||
}
|
@@ -9,6 +9,7 @@
|
||||
|
||||
namespace Facebook.Yoga
|
||||
{
|
||||
[System.Flags]
|
||||
public enum YogaPrintOptions
|
||||
{
|
||||
Layout = 1,
|
||||
|
@@ -4,7 +4,7 @@
|
||||
<CompileDependsOn>NativeLibrary;$(CompileDependsOn)</CompileDependsOn>
|
||||
</PropertyGroup>
|
||||
<Target Name="NativeLibrary" Outputs="$(ProjectDir)libyoga.dylib">
|
||||
<Exec WorkingDirectory="$(ProjectDir)" Command="$(ProjectDir)buck-build.sh //csharp:yoganet-macosx" />
|
||||
<Exec WorkingDirectory="$(ProjectDir)" Command="$(ProjectDir)../build-native.sh" />
|
||||
<Copy SourceFiles="$(ProjectDir)..\..\buck-out\gen\csharp\yoganet-macosx\libyoga.dylib" DestinationFiles="$(ProjectDir)libyoga.dylib" SkipUnchangedFiles="true" />
|
||||
</Target>
|
||||
</Project>
|
@@ -33,6 +33,9 @@ namespace Facebook.Yoga.Mac.Tests
|
||||
|
||||
}
|
||||
|
||||
[System.Runtime.InteropServices.DllImport("/usr/lib/libSystem.dylib")]
|
||||
static extern void _exit(int exit_code);
|
||||
|
||||
class NSRunLoopIntegration : NSObject, IMainLoopIntegration
|
||||
{
|
||||
public void InitializeToolkit()
|
||||
@@ -51,7 +54,7 @@ namespace Facebook.Yoga.Mac.Tests
|
||||
|
||||
public void Shutdown()
|
||||
{
|
||||
Environment.Exit(TestRunner.ExitCode);
|
||||
_exit(TestRunner.ExitCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +0,0 @@
|
||||
#!/bin/sh
|
||||
if buck --version >/dev/null 2>&1; then true; else
|
||||
echo "SKIP: Need to install buck https://buckbuild.com/setup/getting_started.html"
|
||||
exit 0
|
||||
fi
|
||||
buck build $1
|
@@ -0,0 +1,124 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{D6477AD6-9EDD-4EBA-8C60-CD31F77C52C6}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Facebook.Yoga</RootNamespace>
|
||||
<AssemblyName>Facebook.Yoga</AssemblyName>
|
||||
<DefaultLanguage>en-US</DefaultLanguage>
|
||||
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
|
||||
<TargetPlatformVersion>10.0.14393.0</TargetPlatformVersion>
|
||||
<TargetPlatformMinVersion>10.0.10240.0</TargetPlatformMinVersion>
|
||||
<MinimumVisualStudioVersion>14</MinimumVisualStudioVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<ProjectTypeGuids>{A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\x86\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
|
||||
<NoWarn>;2008</NoWarn>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<OutputPath>bin\x86\Release\</OutputPath>
|
||||
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<NoWarn>;2008</NoWarn>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|ARM'">
|
||||
<PlatformTarget>ARM</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\ARM\Debug\</OutputPath>
|
||||
<DefineConstants>TRACE;DEBUG;NETFX_CORE;WINDOWS_UWP;WINDOWS_UWP_ARM</DefineConstants>
|
||||
<NoWarn>;2008</NoWarn>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|ARM'">
|
||||
<PlatformTarget>ARM</PlatformTarget>
|
||||
<OutputPath>bin\ARM\Release\</OutputPath>
|
||||
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP;WINDOWS_UWP_ARM</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<NoWarn>;2008</NoWarn>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\x64\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
|
||||
<NoWarn>;2008</NoWarn>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<OutputPath>bin\x64\Release\</OutputPath>
|
||||
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<NoWarn>;2008</NoWarn>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<!-- A reference to the entire .Net Framework and Windows SDK are automatically included -->
|
||||
<None Include="project.json" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Properties\" />
|
||||
</ItemGroup>
|
||||
<Import Project="..\..\Facebook.Yoga\Facebook.Yoga.Shared.projitems" Label="Shared" />
|
||||
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' < '14.0' ">
|
||||
<VisualStudioVersion>14.0</VisualStudioVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
16
csharp/Windows/Facebook.Yoga.Universal/project.json
Normal file
16
csharp/Windows/Facebook.Yoga.Universal/project.json
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"Microsoft.NETCore.UniversalWindowsPlatform": "5.1.0"
|
||||
},
|
||||
"frameworks": {
|
||||
"uap10.0": {}
|
||||
},
|
||||
"runtimes": {
|
||||
"win10-arm": {},
|
||||
"win10-arm-aot": {},
|
||||
"win10-x86": {},
|
||||
"win10-x86-aot": {},
|
||||
"win10-x64": {},
|
||||
"win10-x64-aot": {}
|
||||
}
|
||||
}
|
@@ -29,11 +29,16 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Facebook.Yoga.Desktop.Tests
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Facebook.Yoga.Universal.Tests", "Facebook.Yoga.Universal.Tests\Facebook.Yoga.Universal.Tests.csproj", "{0C76D2FE-6767-44FE-B03D-21B2076BAA73}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Universal", "Universal", "{6669329B-017F-45B3-8611-53AFD065E45C}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Facebook.Yoga.Universal", "Facebook.Yoga.Universal\Facebook.Yoga.Universal.csproj", "{D6477AD6-9EDD-4EBA-8C60-CD31F77C52C6}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SharedMSBuildProjectFiles) = preSolution
|
||||
..\Facebook.Yoga\Facebook.Yoga.Shared.projitems*{3aace384-fdec-4d91-a3b2-eeb21b46c9ad}*SharedItemsImports = 4
|
||||
..\tests\Facebook.Yoga\Facebook.Yoga.Shared.Tests.projitems*{4edc82d9-a201-4831-8fe0-98f468f8e4ae}*SharedItemsImports = 13
|
||||
..\Facebook.Yoga\Facebook.Yoga.Shared.projitems*{91c42d32-291d-4b72-90b4-551663d60b8b}*SharedItemsImports = 13
|
||||
..\Facebook.Yoga\Facebook.Yoga.Shared.projitems*{d6477ad6-9edd-4eba-8c60-cd31f77c52c6}*SharedItemsImports = 4
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -118,6 +123,22 @@ Global
|
||||
{0C76D2FE-6767-44FE-B03D-21B2076BAA73}.Release|ARM.ActiveCfg = Release|ARM
|
||||
{0C76D2FE-6767-44FE-B03D-21B2076BAA73}.Release|x64.ActiveCfg = Release|x64
|
||||
{0C76D2FE-6767-44FE-B03D-21B2076BAA73}.Release|x86.ActiveCfg = Release|x86
|
||||
{D6477AD6-9EDD-4EBA-8C60-CD31F77C52C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{D6477AD6-9EDD-4EBA-8C60-CD31F77C52C6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{D6477AD6-9EDD-4EBA-8C60-CD31F77C52C6}.Debug|ARM.ActiveCfg = Debug|ARM
|
||||
{D6477AD6-9EDD-4EBA-8C60-CD31F77C52C6}.Debug|ARM.Build.0 = Debug|ARM
|
||||
{D6477AD6-9EDD-4EBA-8C60-CD31F77C52C6}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{D6477AD6-9EDD-4EBA-8C60-CD31F77C52C6}.Debug|x64.Build.0 = Debug|x64
|
||||
{D6477AD6-9EDD-4EBA-8C60-CD31F77C52C6}.Debug|x86.ActiveCfg = Debug|x86
|
||||
{D6477AD6-9EDD-4EBA-8C60-CD31F77C52C6}.Debug|x86.Build.0 = Debug|x86
|
||||
{D6477AD6-9EDD-4EBA-8C60-CD31F77C52C6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{D6477AD6-9EDD-4EBA-8C60-CD31F77C52C6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{D6477AD6-9EDD-4EBA-8C60-CD31F77C52C6}.Release|ARM.ActiveCfg = Release|ARM
|
||||
{D6477AD6-9EDD-4EBA-8C60-CD31F77C52C6}.Release|ARM.Build.0 = Release|ARM
|
||||
{D6477AD6-9EDD-4EBA-8C60-CD31F77C52C6}.Release|x64.ActiveCfg = Release|x64
|
||||
{D6477AD6-9EDD-4EBA-8C60-CD31F77C52C6}.Release|x64.Build.0 = Release|x64
|
||||
{D6477AD6-9EDD-4EBA-8C60-CD31F77C52C6}.Release|x86.ActiveCfg = Release|x86
|
||||
{D6477AD6-9EDD-4EBA-8C60-CD31F77C52C6}.Release|x86.Build.0 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
@@ -130,5 +151,6 @@ Global
|
||||
{4EDC82D9-A201-4831-8FE0-98F468F8E4AE} = {39A2FFDA-C093-4FA6-8143-45B5019E7DAC}
|
||||
{AC23F444-5545-4196-8B9F-5C1F6B3E7FB3} = {5289E508-8386-45A1-A12B-258A5899CD45}
|
||||
{0C76D2FE-6767-44FE-B03D-21B2076BAA73} = {5289E508-8386-45A1-A12B-258A5899CD45}
|
||||
{D6477AD6-9EDD-4EBA-8C60-CD31F77C52C6} = {6669329B-017F-45B3-8611-53AFD065E45C}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
@@ -9,19 +9,23 @@
|
||||
|
||||
#include "YGInterop.h"
|
||||
|
||||
static YGInteropLoggerFunc gManagedFunc;
|
||||
static YGInteropLogger gManagedLogger;
|
||||
|
||||
static int unmanagedLogger(YGLogLevel level, const char *format, va_list args) {
|
||||
static int unmanagedLogger(const YGConfigRef config,
|
||||
const YGNodeRef node,
|
||||
YGLogLevel level,
|
||||
const char *format,
|
||||
va_list args) {
|
||||
int result = 0;
|
||||
if (gManagedFunc) {
|
||||
char buffer[256];
|
||||
result = vsnprintf(buffer, sizeof(buffer), format, args);
|
||||
(*gManagedFunc)(level, buffer);
|
||||
if (gManagedLogger) {
|
||||
char message[8192];
|
||||
result = vsnprintf(message, sizeof(message), format, args);
|
||||
(*gManagedLogger)(config, node, level, message);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void YGInteropSetLogger(YGInteropLoggerFunc managedFunc) {
|
||||
gManagedFunc = managedFunc;
|
||||
YGSetLogger(&unmanagedLogger);
|
||||
void YGInteropSetLogger(YGInteropLogger managedLogger) {
|
||||
gManagedLogger = managedLogger;
|
||||
YGConfigSetLogger(YGConfigGetDefault(), &unmanagedLogger);
|
||||
}
|
||||
|
@@ -13,8 +13,13 @@
|
||||
|
||||
YG_EXTERN_C_BEGIN
|
||||
|
||||
typedef void (*YGInteropLoggerFunc)(YGLogLevel level, const char *message);
|
||||
typedef int (*YGInteropLogger)(const void *unmanagedConfigPtr,
|
||||
const void *unmanagedNodePtr,
|
||||
YGLogLevel level,
|
||||
const char *message);
|
||||
|
||||
WIN_EXPORT void YGInteropSetLogger(YGInteropLoggerFunc managedFunc);
|
||||
WIN_EXPORT YGConfigRef YGConfigGetDefault();
|
||||
|
||||
WIN_EXPORT void YGInteropSetLogger(YGInteropLogger managedLogger);
|
||||
|
||||
YG_EXTERN_C_END
|
||||
|
@@ -104,7 +104,7 @@
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<OutDir>bin\Universal\$(PlatformTarget)\$(Configuration)\</OutDir>
|
||||
<IntDir>obj\$(PlatformTarget)\$(Configuration)\</IntDir>
|
||||
<IntDir>obj\Universal\$(PlatformTarget)\$(Configuration)\</IntDir>
|
||||
<TargetName>yoga</TargetName>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">
|
||||
@@ -242,6 +242,7 @@
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\yoga\YGEnums.h" />
|
||||
<ClInclude Include="..\..\yoga\Yoga.h" />
|
||||
<ClInclude Include="..\..\yoga\YGMacros.h" />
|
||||
<ClInclude Include="..\..\yoga\YGNodeList.h" />
|
||||
@@ -251,6 +252,7 @@
|
||||
<ClInclude Include="targetver.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\yoga\YGEnums.c" />
|
||||
<ClCompile Include="..\..\yoga\Yoga.c" />
|
||||
<ClCompile Include="..\..\yoga\YGNodeList.c" />
|
||||
<ClCompile Include="YGInterop.cpp" />
|
||||
|
@@ -36,6 +36,9 @@
|
||||
<ClInclude Include="resource.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\yoga\YGEnums.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="stdafx.cpp">
|
||||
@@ -53,6 +56,9 @@
|
||||
<ClCompile Include="YGInterop.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\yoga\YGEnums.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="Yoga.rc">
|
||||
|
@@ -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">
|
||||
|
@@ -1,16 +1,25 @@
|
||||
#!/bin/sh
|
||||
if buck --version >/dev/null 2>&1; then true; else
|
||||
cd `dirname "$0"`
|
||||
echo $ANDROID_SDK
|
||||
BUCK_RELEASE=2017.05.09.01
|
||||
echo "buck $BUCK_RELEASE"
|
||||
BUCK=lib/buck-$BUCK_RELEASE/bin/buck
|
||||
if $BUCK --version >/dev/null 2>&1; then true; else
|
||||
echo "Building Buck!"
|
||||
mkdir lib
|
||||
BUCK_PATH=buck-$BUCK_RELEASE
|
||||
mkdir -p lib
|
||||
cd lib
|
||||
git clone https://github.com/facebook/buck.git --depth 1
|
||||
cd buck
|
||||
rm -f $BUCK_PATH.tar.gz
|
||||
curl -O -J -L https://github.com/facebook/buck/archive/v$BUCK_RELEASE.tar.gz
|
||||
tar xzf $BUCK_PATH.tar.gz
|
||||
cd $BUCK_PATH
|
||||
ant
|
||||
cd ..
|
||||
cd ..
|
||||
cd ../..
|
||||
fi
|
||||
buck build //:yoga
|
||||
buck build //csharp:yoganet-ios
|
||||
buck build //csharp:yoganet-macosx
|
||||
buck build //csharp:yoganet#android-x86,shared
|
||||
buck build //csharp:yoganet#android-armv7,shared
|
||||
|
||||
$BUCK build \
|
||||
//csharp:yoganet-ios \
|
||||
//csharp:yoganet-macosx \
|
||||
//csharp:yoganet#android-armv7,shared \
|
||||
//csharp:yoganet#android-x86,shared
|
||||
|
||||
|
@@ -4,7 +4,7 @@
|
||||
<CompileDependsOn>NativeLibrary;$(CompileDependsOn)</CompileDependsOn>
|
||||
</PropertyGroup>
|
||||
<Target Name="NativeLibrary" Outputs="$(ProjectDir)libyoga.a">
|
||||
<Exec WorkingDirectory="$(ProjectDir)" Command="$(ProjectDir)../../Mac/buck-build.sh //csharp:yoganet-ios" />
|
||||
<Exec WorkingDirectory="$(ProjectDir)" Command="$(ProjectDir)../../build-native.sh" />
|
||||
<Copy SourceFiles="$(ProjectDir)..\..\..\buck-out\gen\csharp\yoganet-ios\libyoga.a" DestinationFiles="$(ProjectDir)libyoga.a" SkipUnchangedFiles="true" />
|
||||
</Target>
|
||||
</Project>
|
||||
|
@@ -12,10 +12,6 @@
|
||||
<description>A subset of CSS's flexbox layout algorithm and box model.</description>
|
||||
<copyright>Copyright 2016 Facebook</copyright>
|
||||
<tags>flexbox flex-box css layout css-layout yoga facebook native</tags>
|
||||
<dependencies>
|
||||
<group targetFramework=".NETStandard1.1" />
|
||||
<group targetFramework="uap10.0" />
|
||||
</dependencies>
|
||||
</metadata>
|
||||
<files>
|
||||
<!-- build -->
|
||||
@@ -28,7 +24,7 @@
|
||||
<file src="..\yoga_windows\bin\Release\Facebook.Yoga.dll" target="lib\netstandard"/>
|
||||
|
||||
<!-- UAP -->
|
||||
<file src="..\yoga_windows\bin\Release\Facebook.Yoga.dll" target="lib\uap10.0"/>
|
||||
<file src="..\yoga_universal\bin\Release\Facebook.Yoga.dll" target="lib\uap10.0"/>
|
||||
|
||||
<!-- net45 -->
|
||||
<file src="..\yoga_windows\bin\Release\Facebook.Yoga.dll" target="lib\net45" />
|
||||
@@ -44,24 +40,24 @@
|
||||
<file src="..\yoga_android\bin\Release\Facebook.Yoga.dll" target="lib\MonoAndroid" />
|
||||
|
||||
<!-- runtimes -->
|
||||
<file src="..\yoga_windows\bin\x86\Release\Facebook.Yoga.dll" target="runtimes\win10-x86\lib\netstandard"/>
|
||||
<file src="..\yoga_windows\bin\x86\Release\Facebook.Yoga.pdb" target="runtimes\win10-x86\lib\netstandard"/>
|
||||
<file src="..\yoga_universal\bin\x86\Release\Facebook.Yoga.dll" target="runtimes\win10-x86\lib\netstandard1.0"/>
|
||||
<file src="..\yoga_universal\bin\x86\Release\Facebook.Yoga.pdb" target="runtimes\win10-x86\lib\netstandard1.0"/>
|
||||
|
||||
<file src="..\yoga_windows\bin\x64\Release\Facebook.Yoga.dll" target="runtimes\win10-x64\lib\netstandard"/>
|
||||
<file src="..\yoga_windows\bin\x64\Release\Facebook.Yoga.pdb" target="runtimes\win10-x64\lib\netstandard"/>
|
||||
<file src="..\yoga_universal\bin\x64\Release\Facebook.Yoga.dll" target="runtimes\win10-x64\lib\netstandard1.0"/>
|
||||
<file src="..\yoga_universal\bin\x64\Release\Facebook.Yoga.pdb" target="runtimes\win10-x64\lib\netstandard1.0"/>
|
||||
|
||||
<file src="..\yoga_windows\bin\ARM\Release\Facebook.Yoga.dll" target="runtimes\win10-arm\lib\netstandard"/>
|
||||
<file src="..\yoga_windows\bin\ARM\Release\Facebook.Yoga.pdb" target="runtimes\win10-arm\lib\netstandard"/>
|
||||
<file src="..\yoga_universal\bin\ARM\Release\Facebook.Yoga.dll" target="runtimes\win10-arm\lib\netstandard1.0"/>
|
||||
<file src="..\yoga_universal\bin\ARM\Release\Facebook.Yoga.pdb" target="runtimes\win10-arm\lib\netstandard1.0"/>
|
||||
|
||||
|
||||
<file src="..\yoga_windows\bin\x86\Release\Facebook.Yoga.dll" target="runtimes\win-x86\lib\netstandard"/>
|
||||
<file src="..\yoga_windows\bin\x86\Release\Facebook.Yoga.pdb" target="runtimes\win-x86\lib\netstandard"/>
|
||||
<file src="..\yoga_windows\bin\x86\Release\Facebook.Yoga.dll" target="runtimes\win-x86\lib\netstandard1.0"/>
|
||||
<file src="..\yoga_windows\bin\x86\Release\Facebook.Yoga.pdb" target="runtimes\win-x86\lib\netstandard1.0"/>
|
||||
|
||||
<file src="..\yoga_windows\bin\x64\Release\Facebook.Yoga.dll" target="runtimes\win-x64\lib\netstandard"/>
|
||||
<file src="..\yoga_windows\bin\x64\Release\Facebook.Yoga.pdb" target="runtimes\win-x64\lib\netstandard"/>
|
||||
<file src="..\yoga_windows\bin\x64\Release\Facebook.Yoga.dll" target="runtimes\win-x64\lib\netstandard1.0"/>
|
||||
<file src="..\yoga_windows\bin\x64\Release\Facebook.Yoga.pdb" target="runtimes\win-x64\lib\netstandard1.0"/>
|
||||
|
||||
<file src="..\yoga_windows\bin\ARM\Release\Facebook.Yoga.dll" target="runtimes\win8-arm\lib\netstandard"/>
|
||||
<file src="..\yoga_windows\bin\ARM\Release\Facebook.Yoga.pdb" target="runtimes\win8-arm\lib\netstandard"/>
|
||||
<file src="..\yoga_windows\bin\ARM\Release\Facebook.Yoga.dll" target="runtimes\win8-arm\lib\netstandard1.0"/>
|
||||
<file src="..\yoga_windows\bin\ARM\Release\Facebook.Yoga.pdb" target="runtimes\win8-arm\lib\netstandard1.0"/>
|
||||
|
||||
|
||||
<!-- Native -->
|
||||
|
@@ -22,6 +22,7 @@
|
||||
<Compile Include="$(MSBuildThisFileDirectory)YGMinMaxDimensionTest.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)YGPaddingTest.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)YGRoundingTest.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)YogaConfigTest.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)YogaNodeSpacingTest.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)YogaNodeTest.cs" />
|
||||
</ItemGroup>
|
||||
|
@@ -285,6 +285,30 @@ namespace Facebook.Yoga
|
||||
root_child1.Width = 50;
|
||||
root_child1.Height = 50;
|
||||
root.Insert(1, root_child1);
|
||||
|
||||
YogaNode root_child2 = new YogaNode(config);
|
||||
root_child2.PositionType = YogaPositionType.Absolute;
|
||||
root_child2.Left = 0;
|
||||
root_child2.Top = 0;
|
||||
root_child2.MarginLeft = 10;
|
||||
root_child2.MarginTop = 10;
|
||||
root_child2.MarginRight = 10;
|
||||
root_child2.MarginBottom = 10;
|
||||
root_child2.Width = 50;
|
||||
root_child2.Height = 50;
|
||||
root.Insert(2, root_child2);
|
||||
|
||||
YogaNode root_child3 = new YogaNode(config);
|
||||
root_child3.PositionType = YogaPositionType.Absolute;
|
||||
root_child3.Right = 0;
|
||||
root_child3.Bottom = 0;
|
||||
root_child3.MarginLeft = 10;
|
||||
root_child3.MarginTop = 10;
|
||||
root_child3.MarginRight = 10;
|
||||
root_child3.MarginBottom = 10;
|
||||
root_child3.Width = 50;
|
||||
root_child3.Height = 50;
|
||||
root.Insert(3, root_child3);
|
||||
root.StyleDirection = YogaDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
@@ -303,6 +327,16 @@ namespace Facebook.Yoga
|
||||
Assert.AreEqual(50f, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(50f, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(20f, root_child2.LayoutX);
|
||||
Assert.AreEqual(20f, root_child2.LayoutY);
|
||||
Assert.AreEqual(50f, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(50f, root_child2.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(30f, root_child3.LayoutX);
|
||||
Assert.AreEqual(30f, root_child3.LayoutY);
|
||||
Assert.AreEqual(50f, root_child3.LayoutWidth);
|
||||
Assert.AreEqual(50f, root_child3.LayoutHeight);
|
||||
|
||||
root.StyleDirection = YogaDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
@@ -320,6 +354,16 @@ namespace Facebook.Yoga
|
||||
Assert.AreEqual(40f, root_child1.LayoutY);
|
||||
Assert.AreEqual(50f, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(50f, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(20f, root_child2.LayoutX);
|
||||
Assert.AreEqual(20f, root_child2.LayoutY);
|
||||
Assert.AreEqual(50f, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(50f, root_child2.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(30f, root_child3.LayoutX);
|
||||
Assert.AreEqual(30f, root_child3.LayoutY);
|
||||
Assert.AreEqual(50f, root_child3.LayoutWidth);
|
||||
Assert.AreEqual(50f, root_child3.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -719,5 +763,279 @@ namespace Facebook.Yoga
|
||||
Assert.AreEqual(40f, root_child0.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_position_root_with_rtl_should_position_withoutdirection()
|
||||
{
|
||||
YogaConfig config = new YogaConfig();
|
||||
|
||||
YogaNode root = new YogaNode(config);
|
||||
root.Left = 72;
|
||||
root.Width = 52;
|
||||
root.Height = 52;
|
||||
root.StyleDirection = YogaDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(72f, root.LayoutX);
|
||||
Assert.AreEqual(0f, root.LayoutY);
|
||||
Assert.AreEqual(52f, root.LayoutWidth);
|
||||
Assert.AreEqual(52f, root.LayoutHeight);
|
||||
|
||||
root.StyleDirection = YogaDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(72f, root.LayoutX);
|
||||
Assert.AreEqual(0f, root.LayoutY);
|
||||
Assert.AreEqual(52f, root.LayoutWidth);
|
||||
Assert.AreEqual(52f, root.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_absolute_layout_percentage_bottom_based_on_parent_height()
|
||||
{
|
||||
YogaConfig config = new YogaConfig();
|
||||
|
||||
YogaNode root = new YogaNode(config);
|
||||
root.Width = 100;
|
||||
root.Height = 200;
|
||||
|
||||
YogaNode root_child0 = new YogaNode(config);
|
||||
root_child0.PositionType = YogaPositionType.Absolute;
|
||||
root_child0.Top = 50.Percent();
|
||||
root_child0.Width = 10;
|
||||
root_child0.Height = 10;
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
YogaNode root_child1 = new YogaNode(config);
|
||||
root_child1.PositionType = YogaPositionType.Absolute;
|
||||
root_child1.Bottom = 50.Percent();
|
||||
root_child1.Width = 10;
|
||||
root_child1.Height = 10;
|
||||
root.Insert(1, root_child1);
|
||||
|
||||
YogaNode root_child2 = new YogaNode(config);
|
||||
root_child2.PositionType = YogaPositionType.Absolute;
|
||||
root_child2.Top = 10.Percent();
|
||||
root_child2.Bottom = 10.Percent();
|
||||
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(100f, root.LayoutWidth);
|
||||
Assert.AreEqual(200f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child0.LayoutX);
|
||||
Assert.AreEqual(100f, root_child0.LayoutY);
|
||||
Assert.AreEqual(10f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10f, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child1.LayoutX);
|
||||
Assert.AreEqual(90f, root_child1.LayoutY);
|
||||
Assert.AreEqual(10f, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(10f, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child2.LayoutX);
|
||||
Assert.AreEqual(20f, root_child2.LayoutY);
|
||||
Assert.AreEqual(10f, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(160f, root_child2.LayoutHeight);
|
||||
|
||||
root.StyleDirection = YogaDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0f, root.LayoutX);
|
||||
Assert.AreEqual(0f, root.LayoutY);
|
||||
Assert.AreEqual(100f, root.LayoutWidth);
|
||||
Assert.AreEqual(200f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(90f, root_child0.LayoutX);
|
||||
Assert.AreEqual(100f, root_child0.LayoutY);
|
||||
Assert.AreEqual(10f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(10f, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(90f, root_child1.LayoutX);
|
||||
Assert.AreEqual(90f, root_child1.LayoutY);
|
||||
Assert.AreEqual(10f, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(10f, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(90f, root_child2.LayoutX);
|
||||
Assert.AreEqual(20f, root_child2.LayoutY);
|
||||
Assert.AreEqual(10f, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(160f, root_child2.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_absolute_layout_in_wrap_reverse_column_container()
|
||||
{
|
||||
YogaConfig config = new YogaConfig();
|
||||
|
||||
YogaNode root = new YogaNode(config);
|
||||
root.Wrap = YogaWrap.WrapReverse;
|
||||
root.Width = 100;
|
||||
root.Height = 100;
|
||||
|
||||
YogaNode root_child0 = new YogaNode(config);
|
||||
root_child0.PositionType = YogaPositionType.Absolute;
|
||||
root_child0.Width = 20;
|
||||
root_child0.Height = 20;
|
||||
root.Insert(0, root_child0);
|
||||
root.StyleDirection = YogaDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0f, root.LayoutX);
|
||||
Assert.AreEqual(0f, root.LayoutY);
|
||||
Assert.AreEqual(100f, root.LayoutWidth);
|
||||
Assert.AreEqual(100f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(80f, root_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0.LayoutY);
|
||||
Assert.AreEqual(20f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(20f, root_child0.LayoutHeight);
|
||||
|
||||
root.StyleDirection = YogaDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0f, root.LayoutX);
|
||||
Assert.AreEqual(0f, root.LayoutY);
|
||||
Assert.AreEqual(100f, root.LayoutWidth);
|
||||
Assert.AreEqual(100f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0.LayoutY);
|
||||
Assert.AreEqual(20f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(20f, root_child0.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_absolute_layout_in_wrap_reverse_row_container()
|
||||
{
|
||||
YogaConfig config = new YogaConfig();
|
||||
|
||||
YogaNode root = new YogaNode(config);
|
||||
root.FlexDirection = YogaFlexDirection.Row;
|
||||
root.Wrap = YogaWrap.WrapReverse;
|
||||
root.Width = 100;
|
||||
root.Height = 100;
|
||||
|
||||
YogaNode root_child0 = new YogaNode(config);
|
||||
root_child0.PositionType = YogaPositionType.Absolute;
|
||||
root_child0.Width = 20;
|
||||
root_child0.Height = 20;
|
||||
root.Insert(0, root_child0);
|
||||
root.StyleDirection = YogaDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0f, root.LayoutX);
|
||||
Assert.AreEqual(0f, root.LayoutY);
|
||||
Assert.AreEqual(100f, root.LayoutWidth);
|
||||
Assert.AreEqual(100f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child0.LayoutX);
|
||||
Assert.AreEqual(80f, root_child0.LayoutY);
|
||||
Assert.AreEqual(20f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(20f, root_child0.LayoutHeight);
|
||||
|
||||
root.StyleDirection = YogaDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0f, root.LayoutX);
|
||||
Assert.AreEqual(0f, root.LayoutY);
|
||||
Assert.AreEqual(100f, root.LayoutWidth);
|
||||
Assert.AreEqual(100f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(80f, root_child0.LayoutX);
|
||||
Assert.AreEqual(80f, root_child0.LayoutY);
|
||||
Assert.AreEqual(20f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(20f, root_child0.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_absolute_layout_in_wrap_reverse_column_container_flex_end()
|
||||
{
|
||||
YogaConfig config = new YogaConfig();
|
||||
|
||||
YogaNode root = new YogaNode(config);
|
||||
root.Wrap = YogaWrap.WrapReverse;
|
||||
root.Width = 100;
|
||||
root.Height = 100;
|
||||
|
||||
YogaNode root_child0 = new YogaNode(config);
|
||||
root_child0.AlignSelf = YogaAlign.FlexEnd;
|
||||
root_child0.PositionType = YogaPositionType.Absolute;
|
||||
root_child0.Width = 20;
|
||||
root_child0.Height = 20;
|
||||
root.Insert(0, root_child0);
|
||||
root.StyleDirection = YogaDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0f, root.LayoutX);
|
||||
Assert.AreEqual(0f, root.LayoutY);
|
||||
Assert.AreEqual(100f, root.LayoutWidth);
|
||||
Assert.AreEqual(100f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0.LayoutY);
|
||||
Assert.AreEqual(20f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(20f, root_child0.LayoutHeight);
|
||||
|
||||
root.StyleDirection = YogaDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0f, root.LayoutX);
|
||||
Assert.AreEqual(0f, root.LayoutY);
|
||||
Assert.AreEqual(100f, root.LayoutWidth);
|
||||
Assert.AreEqual(100f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(80f, root_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0.LayoutY);
|
||||
Assert.AreEqual(20f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(20f, root_child0.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_absolute_layout_in_wrap_reverse_row_container_flex_end()
|
||||
{
|
||||
YogaConfig config = new YogaConfig();
|
||||
|
||||
YogaNode root = new YogaNode(config);
|
||||
root.FlexDirection = YogaFlexDirection.Row;
|
||||
root.Wrap = YogaWrap.WrapReverse;
|
||||
root.Width = 100;
|
||||
root.Height = 100;
|
||||
|
||||
YogaNode root_child0 = new YogaNode(config);
|
||||
root_child0.AlignSelf = YogaAlign.FlexEnd;
|
||||
root_child0.PositionType = YogaPositionType.Absolute;
|
||||
root_child0.Width = 20;
|
||||
root_child0.Height = 20;
|
||||
root.Insert(0, root_child0);
|
||||
root.StyleDirection = YogaDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0f, root.LayoutX);
|
||||
Assert.AreEqual(0f, root.LayoutY);
|
||||
Assert.AreEqual(100f, root.LayoutWidth);
|
||||
Assert.AreEqual(100f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0.LayoutY);
|
||||
Assert.AreEqual(20f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(20f, root_child0.LayoutHeight);
|
||||
|
||||
root.StyleDirection = YogaDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0f, root.LayoutX);
|
||||
Assert.AreEqual(0f, root.LayoutY);
|
||||
Assert.AreEqual(100f, root.LayoutWidth);
|
||||
Assert.AreEqual(100f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(80f, root_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0.LayoutY);
|
||||
Assert.AreEqual(20f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(20f, root_child0.LayoutHeight);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -1587,5 +1587,376 @@ namespace Facebook.Yoga
|
||||
Assert.AreEqual(20f, root_child3.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_align_items_center_child_with_margin_bigger_than_parent()
|
||||
{
|
||||
YogaConfig config = new YogaConfig();
|
||||
|
||||
YogaNode root = new YogaNode(config);
|
||||
root.JustifyContent = YogaJustify.Center;
|
||||
root.AlignItems = YogaAlign.Center;
|
||||
root.Width = 52;
|
||||
root.Height = 52;
|
||||
|
||||
YogaNode root_child0 = new YogaNode(config);
|
||||
root_child0.AlignItems = YogaAlign.Center;
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
YogaNode root_child0_child0 = new YogaNode(config);
|
||||
root_child0_child0.MarginLeft = 10;
|
||||
root_child0_child0.MarginRight = 10;
|
||||
root_child0_child0.Width = 52;
|
||||
root_child0_child0.Height = 52;
|
||||
root_child0.Insert(0, root_child0_child0);
|
||||
root.StyleDirection = YogaDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0f, root.LayoutX);
|
||||
Assert.AreEqual(0f, root.LayoutY);
|
||||
Assert.AreEqual(52f, root.LayoutWidth);
|
||||
Assert.AreEqual(52f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(-10f, root_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0.LayoutY);
|
||||
Assert.AreEqual(72f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(52f, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(10f, root_child0_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0_child0.LayoutY);
|
||||
Assert.AreEqual(52f, root_child0_child0.LayoutWidth);
|
||||
Assert.AreEqual(52f, root_child0_child0.LayoutHeight);
|
||||
|
||||
root.StyleDirection = YogaDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0f, root.LayoutX);
|
||||
Assert.AreEqual(0f, root.LayoutY);
|
||||
Assert.AreEqual(52f, root.LayoutWidth);
|
||||
Assert.AreEqual(52f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(-10f, root_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0.LayoutY);
|
||||
Assert.AreEqual(72f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(52f, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(10f, root_child0_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0_child0.LayoutY);
|
||||
Assert.AreEqual(52f, root_child0_child0.LayoutWidth);
|
||||
Assert.AreEqual(52f, root_child0_child0.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_align_items_flex_end_child_with_margin_bigger_than_parent()
|
||||
{
|
||||
YogaConfig config = new YogaConfig();
|
||||
|
||||
YogaNode root = new YogaNode(config);
|
||||
root.JustifyContent = YogaJustify.Center;
|
||||
root.AlignItems = YogaAlign.Center;
|
||||
root.Width = 52;
|
||||
root.Height = 52;
|
||||
|
||||
YogaNode root_child0 = new YogaNode(config);
|
||||
root_child0.AlignItems = YogaAlign.FlexEnd;
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
YogaNode root_child0_child0 = new YogaNode(config);
|
||||
root_child0_child0.MarginLeft = 10;
|
||||
root_child0_child0.MarginRight = 10;
|
||||
root_child0_child0.Width = 52;
|
||||
root_child0_child0.Height = 52;
|
||||
root_child0.Insert(0, root_child0_child0);
|
||||
root.StyleDirection = YogaDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0f, root.LayoutX);
|
||||
Assert.AreEqual(0f, root.LayoutY);
|
||||
Assert.AreEqual(52f, root.LayoutWidth);
|
||||
Assert.AreEqual(52f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(-10f, root_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0.LayoutY);
|
||||
Assert.AreEqual(72f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(52f, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(10f, root_child0_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0_child0.LayoutY);
|
||||
Assert.AreEqual(52f, root_child0_child0.LayoutWidth);
|
||||
Assert.AreEqual(52f, root_child0_child0.LayoutHeight);
|
||||
|
||||
root.StyleDirection = YogaDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0f, root.LayoutX);
|
||||
Assert.AreEqual(0f, root.LayoutY);
|
||||
Assert.AreEqual(52f, root.LayoutWidth);
|
||||
Assert.AreEqual(52f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(-10f, root_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0.LayoutY);
|
||||
Assert.AreEqual(72f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(52f, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(10f, root_child0_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0_child0.LayoutY);
|
||||
Assert.AreEqual(52f, root_child0_child0.LayoutWidth);
|
||||
Assert.AreEqual(52f, root_child0_child0.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_align_items_center_child_without_margin_bigger_than_parent()
|
||||
{
|
||||
YogaConfig config = new YogaConfig();
|
||||
|
||||
YogaNode root = new YogaNode(config);
|
||||
root.JustifyContent = YogaJustify.Center;
|
||||
root.AlignItems = YogaAlign.Center;
|
||||
root.Width = 52;
|
||||
root.Height = 52;
|
||||
|
||||
YogaNode root_child0 = new YogaNode(config);
|
||||
root_child0.AlignItems = YogaAlign.Center;
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
YogaNode root_child0_child0 = new YogaNode(config);
|
||||
root_child0_child0.Width = 72;
|
||||
root_child0_child0.Height = 72;
|
||||
root_child0.Insert(0, root_child0_child0);
|
||||
root.StyleDirection = YogaDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0f, root.LayoutX);
|
||||
Assert.AreEqual(0f, root.LayoutY);
|
||||
Assert.AreEqual(52f, root.LayoutWidth);
|
||||
Assert.AreEqual(52f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(-10f, root_child0.LayoutX);
|
||||
Assert.AreEqual(-10f, root_child0.LayoutY);
|
||||
Assert.AreEqual(72f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(72f, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child0_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0_child0.LayoutY);
|
||||
Assert.AreEqual(72f, root_child0_child0.LayoutWidth);
|
||||
Assert.AreEqual(72f, root_child0_child0.LayoutHeight);
|
||||
|
||||
root.StyleDirection = YogaDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0f, root.LayoutX);
|
||||
Assert.AreEqual(0f, root.LayoutY);
|
||||
Assert.AreEqual(52f, root.LayoutWidth);
|
||||
Assert.AreEqual(52f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(-10f, root_child0.LayoutX);
|
||||
Assert.AreEqual(-10f, root_child0.LayoutY);
|
||||
Assert.AreEqual(72f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(72f, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child0_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0_child0.LayoutY);
|
||||
Assert.AreEqual(72f, root_child0_child0.LayoutWidth);
|
||||
Assert.AreEqual(72f, root_child0_child0.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_align_items_flex_end_child_without_margin_bigger_than_parent()
|
||||
{
|
||||
YogaConfig config = new YogaConfig();
|
||||
|
||||
YogaNode root = new YogaNode(config);
|
||||
root.JustifyContent = YogaJustify.Center;
|
||||
root.AlignItems = YogaAlign.Center;
|
||||
root.Width = 52;
|
||||
root.Height = 52;
|
||||
|
||||
YogaNode root_child0 = new YogaNode(config);
|
||||
root_child0.AlignItems = YogaAlign.FlexEnd;
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
YogaNode root_child0_child0 = new YogaNode(config);
|
||||
root_child0_child0.Width = 72;
|
||||
root_child0_child0.Height = 72;
|
||||
root_child0.Insert(0, root_child0_child0);
|
||||
root.StyleDirection = YogaDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0f, root.LayoutX);
|
||||
Assert.AreEqual(0f, root.LayoutY);
|
||||
Assert.AreEqual(52f, root.LayoutWidth);
|
||||
Assert.AreEqual(52f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(-10f, root_child0.LayoutX);
|
||||
Assert.AreEqual(-10f, root_child0.LayoutY);
|
||||
Assert.AreEqual(72f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(72f, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child0_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0_child0.LayoutY);
|
||||
Assert.AreEqual(72f, root_child0_child0.LayoutWidth);
|
||||
Assert.AreEqual(72f, root_child0_child0.LayoutHeight);
|
||||
|
||||
root.StyleDirection = YogaDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0f, root.LayoutX);
|
||||
Assert.AreEqual(0f, root.LayoutY);
|
||||
Assert.AreEqual(52f, root.LayoutWidth);
|
||||
Assert.AreEqual(52f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(-10f, root_child0.LayoutX);
|
||||
Assert.AreEqual(-10f, root_child0.LayoutY);
|
||||
Assert.AreEqual(72f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(72f, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child0_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0_child0.LayoutY);
|
||||
Assert.AreEqual(72f, root_child0_child0.LayoutWidth);
|
||||
Assert.AreEqual(72f, root_child0_child0.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_align_center_should_size_based_on_content()
|
||||
{
|
||||
YogaConfig config = new YogaConfig();
|
||||
|
||||
YogaNode root = new YogaNode(config);
|
||||
root.AlignItems = YogaAlign.Center;
|
||||
root.MarginTop = 20;
|
||||
root.Width = 100;
|
||||
root.Height = 100;
|
||||
|
||||
YogaNode root_child0 = new YogaNode(config);
|
||||
root_child0.JustifyContent = YogaJustify.Center;
|
||||
root_child0.FlexShrink = 1;
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
YogaNode root_child0_child0 = new YogaNode(config);
|
||||
root_child0_child0.FlexGrow = 1;
|
||||
root_child0_child0.FlexShrink = 1;
|
||||
root_child0.Insert(0, root_child0_child0);
|
||||
|
||||
YogaNode root_child0_child0_child0 = new YogaNode(config);
|
||||
root_child0_child0_child0.Width = 20;
|
||||
root_child0_child0_child0.Height = 20;
|
||||
root_child0_child0.Insert(0, root_child0_child0_child0);
|
||||
root.StyleDirection = YogaDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0f, root.LayoutX);
|
||||
Assert.AreEqual(20f, root.LayoutY);
|
||||
Assert.AreEqual(100f, root.LayoutWidth);
|
||||
Assert.AreEqual(100f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(40f, root_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0.LayoutY);
|
||||
Assert.AreEqual(20f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(20f, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child0_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0_child0.LayoutY);
|
||||
Assert.AreEqual(20f, root_child0_child0.LayoutWidth);
|
||||
Assert.AreEqual(20f, root_child0_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child0_child0_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0_child0_child0.LayoutY);
|
||||
Assert.AreEqual(20f, root_child0_child0_child0.LayoutWidth);
|
||||
Assert.AreEqual(20f, root_child0_child0_child0.LayoutHeight);
|
||||
|
||||
root.StyleDirection = YogaDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0f, root.LayoutX);
|
||||
Assert.AreEqual(20f, root.LayoutY);
|
||||
Assert.AreEqual(100f, root.LayoutWidth);
|
||||
Assert.AreEqual(100f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(40f, root_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0.LayoutY);
|
||||
Assert.AreEqual(20f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(20f, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child0_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0_child0.LayoutY);
|
||||
Assert.AreEqual(20f, root_child0_child0.LayoutWidth);
|
||||
Assert.AreEqual(20f, root_child0_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child0_child0_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0_child0_child0.LayoutY);
|
||||
Assert.AreEqual(20f, root_child0_child0_child0.LayoutWidth);
|
||||
Assert.AreEqual(20f, root_child0_child0_child0.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_align_strech_should_size_based_on_parent()
|
||||
{
|
||||
YogaConfig config = new YogaConfig();
|
||||
|
||||
YogaNode root = new YogaNode(config);
|
||||
root.MarginTop = 20;
|
||||
root.Width = 100;
|
||||
root.Height = 100;
|
||||
|
||||
YogaNode root_child0 = new YogaNode(config);
|
||||
root_child0.JustifyContent = YogaJustify.Center;
|
||||
root_child0.FlexShrink = 1;
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
YogaNode root_child0_child0 = new YogaNode(config);
|
||||
root_child0_child0.FlexGrow = 1;
|
||||
root_child0_child0.FlexShrink = 1;
|
||||
root_child0.Insert(0, root_child0_child0);
|
||||
|
||||
YogaNode root_child0_child0_child0 = new YogaNode(config);
|
||||
root_child0_child0_child0.Width = 20;
|
||||
root_child0_child0_child0.Height = 20;
|
||||
root_child0_child0.Insert(0, root_child0_child0_child0);
|
||||
root.StyleDirection = YogaDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0f, root.LayoutX);
|
||||
Assert.AreEqual(20f, root.LayoutY);
|
||||
Assert.AreEqual(100f, root.LayoutWidth);
|
||||
Assert.AreEqual(100f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0.LayoutY);
|
||||
Assert.AreEqual(100f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(20f, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child0_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0_child0.LayoutY);
|
||||
Assert.AreEqual(100f, root_child0_child0.LayoutWidth);
|
||||
Assert.AreEqual(20f, root_child0_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child0_child0_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0_child0_child0.LayoutY);
|
||||
Assert.AreEqual(20f, root_child0_child0_child0.LayoutWidth);
|
||||
Assert.AreEqual(20f, root_child0_child0_child0.LayoutHeight);
|
||||
|
||||
root.StyleDirection = YogaDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0f, root.LayoutX);
|
||||
Assert.AreEqual(20f, root.LayoutY);
|
||||
Assert.AreEqual(100f, root.LayoutWidth);
|
||||
Assert.AreEqual(100f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0.LayoutY);
|
||||
Assert.AreEqual(100f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(20f, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child0_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0_child0.LayoutY);
|
||||
Assert.AreEqual(100f, root_child0_child0.LayoutWidth);
|
||||
Assert.AreEqual(20f, root_child0_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(80f, root_child0_child0_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0_child0_child0.LayoutY);
|
||||
Assert.AreEqual(20f, root_child0_child0_child0.LayoutWidth);
|
||||
Assert.AreEqual(20f, root_child0_child0_child0.LayoutHeight);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -429,5 +429,73 @@ namespace Facebook.Yoga
|
||||
Assert.AreEqual(0f, root_child0_child0.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_flex_grow_less_than_factor_one()
|
||||
{
|
||||
YogaConfig config = new YogaConfig();
|
||||
|
||||
YogaNode root = new YogaNode(config);
|
||||
root.Width = 200;
|
||||
root.Height = 500;
|
||||
|
||||
YogaNode root_child0 = new YogaNode(config);
|
||||
root_child0.FlexGrow = 0.2f;
|
||||
root_child0.FlexBasis = 40;
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
YogaNode root_child1 = new YogaNode(config);
|
||||
root_child1.FlexGrow = 0.2f;
|
||||
root.Insert(1, root_child1);
|
||||
|
||||
YogaNode root_child2 = new YogaNode(config);
|
||||
root_child2.FlexGrow = 0.4f;
|
||||
root.Insert(2, root_child2);
|
||||
root.StyleDirection = YogaDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0f, root.LayoutX);
|
||||
Assert.AreEqual(0f, root.LayoutY);
|
||||
Assert.AreEqual(200f, root.LayoutWidth);
|
||||
Assert.AreEqual(500f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0.LayoutY);
|
||||
Assert.AreEqual(200f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(132f, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child1.LayoutX);
|
||||
Assert.AreEqual(132f, root_child1.LayoutY);
|
||||
Assert.AreEqual(200f, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(92f, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child2.LayoutX);
|
||||
Assert.AreEqual(224f, root_child2.LayoutY);
|
||||
Assert.AreEqual(200f, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(184f, root_child2.LayoutHeight);
|
||||
|
||||
root.StyleDirection = YogaDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0f, root.LayoutX);
|
||||
Assert.AreEqual(0f, root.LayoutY);
|
||||
Assert.AreEqual(200f, root.LayoutWidth);
|
||||
Assert.AreEqual(500f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0.LayoutY);
|
||||
Assert.AreEqual(200f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(132f, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child1.LayoutX);
|
||||
Assert.AreEqual(132f, root_child1.LayoutY);
|
||||
Assert.AreEqual(200f, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(92f, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child2.LayoutX);
|
||||
Assert.AreEqual(224f, root_child2.LayoutY);
|
||||
Assert.AreEqual(200f, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(184f, root_child2.LayoutHeight);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -1381,5 +1381,365 @@ namespace Facebook.Yoga
|
||||
Assert.AreEqual(80f, root_child0_child1.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_wrapped_column_max_height()
|
||||
{
|
||||
YogaConfig config = new YogaConfig();
|
||||
|
||||
YogaNode root = new YogaNode(config);
|
||||
root.JustifyContent = YogaJustify.Center;
|
||||
root.AlignContent = YogaAlign.Center;
|
||||
root.AlignItems = YogaAlign.Center;
|
||||
root.Wrap = YogaWrap.Wrap;
|
||||
root.Width = 700;
|
||||
root.Height = 500;
|
||||
|
||||
YogaNode root_child0 = new YogaNode(config);
|
||||
root_child0.Width = 100;
|
||||
root_child0.Height = 500;
|
||||
root_child0.MaxHeight = 200;
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
YogaNode root_child1 = new YogaNode(config);
|
||||
root_child1.MarginLeft = 20;
|
||||
root_child1.MarginTop = 20;
|
||||
root_child1.MarginRight = 20;
|
||||
root_child1.MarginBottom = 20;
|
||||
root_child1.Width = 200;
|
||||
root_child1.Height = 200;
|
||||
root.Insert(1, root_child1);
|
||||
|
||||
YogaNode root_child2 = new YogaNode(config);
|
||||
root_child2.Width = 100;
|
||||
root_child2.Height = 100;
|
||||
root.Insert(2, root_child2);
|
||||
root.StyleDirection = YogaDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0f, root.LayoutX);
|
||||
Assert.AreEqual(0f, root.LayoutY);
|
||||
Assert.AreEqual(700f, root.LayoutWidth);
|
||||
Assert.AreEqual(500f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(250f, root_child0.LayoutX);
|
||||
Assert.AreEqual(30f, root_child0.LayoutY);
|
||||
Assert.AreEqual(100f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(200f, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(200f, root_child1.LayoutX);
|
||||
Assert.AreEqual(250f, root_child1.LayoutY);
|
||||
Assert.AreEqual(200f, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(200f, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(420f, root_child2.LayoutX);
|
||||
Assert.AreEqual(200f, root_child2.LayoutY);
|
||||
Assert.AreEqual(100f, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(100f, root_child2.LayoutHeight);
|
||||
|
||||
root.StyleDirection = YogaDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0f, root.LayoutX);
|
||||
Assert.AreEqual(0f, root.LayoutY);
|
||||
Assert.AreEqual(700f, root.LayoutWidth);
|
||||
Assert.AreEqual(500f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(350f, root_child0.LayoutX);
|
||||
Assert.AreEqual(30f, root_child0.LayoutY);
|
||||
Assert.AreEqual(100f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(200f, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(300f, root_child1.LayoutX);
|
||||
Assert.AreEqual(250f, root_child1.LayoutY);
|
||||
Assert.AreEqual(200f, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(200f, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(180f, root_child2.LayoutX);
|
||||
Assert.AreEqual(200f, root_child2.LayoutY);
|
||||
Assert.AreEqual(100f, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(100f, root_child2.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_wrapped_column_max_height_flex()
|
||||
{
|
||||
YogaConfig config = new YogaConfig();
|
||||
|
||||
YogaNode root = new YogaNode(config);
|
||||
root.JustifyContent = YogaJustify.Center;
|
||||
root.AlignContent = YogaAlign.Center;
|
||||
root.AlignItems = YogaAlign.Center;
|
||||
root.Wrap = YogaWrap.Wrap;
|
||||
root.Width = 700;
|
||||
root.Height = 500;
|
||||
|
||||
YogaNode root_child0 = new YogaNode(config);
|
||||
root_child0.FlexGrow = 1;
|
||||
root_child0.FlexShrink = 1;
|
||||
root_child0.FlexBasis = 0.Percent();
|
||||
root_child0.Width = 100;
|
||||
root_child0.Height = 500;
|
||||
root_child0.MaxHeight = 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_child1.MarginLeft = 20;
|
||||
root_child1.MarginTop = 20;
|
||||
root_child1.MarginRight = 20;
|
||||
root_child1.MarginBottom = 20;
|
||||
root_child1.Width = 200;
|
||||
root_child1.Height = 200;
|
||||
root.Insert(1, root_child1);
|
||||
|
||||
YogaNode root_child2 = new YogaNode(config);
|
||||
root_child2.Width = 100;
|
||||
root_child2.Height = 100;
|
||||
root.Insert(2, root_child2);
|
||||
root.StyleDirection = YogaDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0f, root.LayoutX);
|
||||
Assert.AreEqual(0f, root.LayoutY);
|
||||
Assert.AreEqual(700f, root.LayoutWidth);
|
||||
Assert.AreEqual(500f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(300f, root_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0.LayoutY);
|
||||
Assert.AreEqual(100f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(180f, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(250f, root_child1.LayoutX);
|
||||
Assert.AreEqual(200f, root_child1.LayoutY);
|
||||
Assert.AreEqual(200f, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(180f, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(300f, root_child2.LayoutX);
|
||||
Assert.AreEqual(400f, root_child2.LayoutY);
|
||||
Assert.AreEqual(100f, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(100f, root_child2.LayoutHeight);
|
||||
|
||||
root.StyleDirection = YogaDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0f, root.LayoutX);
|
||||
Assert.AreEqual(0f, root.LayoutY);
|
||||
Assert.AreEqual(700f, root.LayoutWidth);
|
||||
Assert.AreEqual(500f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(300f, root_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0.LayoutY);
|
||||
Assert.AreEqual(100f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(180f, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(250f, root_child1.LayoutX);
|
||||
Assert.AreEqual(200f, root_child1.LayoutY);
|
||||
Assert.AreEqual(200f, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(180f, root_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(300f, root_child2.LayoutX);
|
||||
Assert.AreEqual(400f, root_child2.LayoutY);
|
||||
Assert.AreEqual(100f, root_child2.LayoutWidth);
|
||||
Assert.AreEqual(100f, root_child2.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_wrap_nodes_with_content_sizing_overflowing_margin()
|
||||
{
|
||||
YogaConfig config = new YogaConfig();
|
||||
|
||||
YogaNode root = new YogaNode(config);
|
||||
root.Width = 500;
|
||||
root.Height = 500;
|
||||
|
||||
YogaNode root_child0 = new YogaNode(config);
|
||||
root_child0.FlexDirection = YogaFlexDirection.Row;
|
||||
root_child0.Wrap = YogaWrap.Wrap;
|
||||
root_child0.Width = 85;
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
YogaNode root_child0_child0 = new YogaNode(config);
|
||||
root_child0.Insert(0, root_child0_child0);
|
||||
|
||||
YogaNode root_child0_child0_child0 = new YogaNode(config);
|
||||
root_child0_child0_child0.Width = 40;
|
||||
root_child0_child0_child0.Height = 40;
|
||||
root_child0_child0.Insert(0, root_child0_child0_child0);
|
||||
|
||||
YogaNode root_child0_child1 = new YogaNode(config);
|
||||
root_child0_child1.MarginRight = 10;
|
||||
root_child0.Insert(1, root_child0_child1);
|
||||
|
||||
YogaNode root_child0_child1_child0 = new YogaNode(config);
|
||||
root_child0_child1_child0.Width = 40;
|
||||
root_child0_child1_child0.Height = 40;
|
||||
root_child0_child1.Insert(0, root_child0_child1_child0);
|
||||
root.StyleDirection = YogaDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0f, root.LayoutX);
|
||||
Assert.AreEqual(0f, root.LayoutY);
|
||||
Assert.AreEqual(500f, root.LayoutWidth);
|
||||
Assert.AreEqual(500f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0.LayoutY);
|
||||
Assert.AreEqual(85f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(80f, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child0_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0_child0.LayoutY);
|
||||
Assert.AreEqual(40f, root_child0_child0.LayoutWidth);
|
||||
Assert.AreEqual(40f, root_child0_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child0_child0_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0_child0_child0.LayoutY);
|
||||
Assert.AreEqual(40f, root_child0_child0_child0.LayoutWidth);
|
||||
Assert.AreEqual(40f, root_child0_child0_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child0_child1.LayoutX);
|
||||
Assert.AreEqual(40f, root_child0_child1.LayoutY);
|
||||
Assert.AreEqual(40f, root_child0_child1.LayoutWidth);
|
||||
Assert.AreEqual(40f, root_child0_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child0_child1_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0_child1_child0.LayoutY);
|
||||
Assert.AreEqual(40f, root_child0_child1_child0.LayoutWidth);
|
||||
Assert.AreEqual(40f, root_child0_child1_child0.LayoutHeight);
|
||||
|
||||
root.StyleDirection = YogaDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0f, root.LayoutX);
|
||||
Assert.AreEqual(0f, root.LayoutY);
|
||||
Assert.AreEqual(500f, root.LayoutWidth);
|
||||
Assert.AreEqual(500f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(415f, root_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0.LayoutY);
|
||||
Assert.AreEqual(85f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(80f, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(45f, root_child0_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0_child0.LayoutY);
|
||||
Assert.AreEqual(40f, root_child0_child0.LayoutWidth);
|
||||
Assert.AreEqual(40f, root_child0_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child0_child0_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0_child0_child0.LayoutY);
|
||||
Assert.AreEqual(40f, root_child0_child0_child0.LayoutWidth);
|
||||
Assert.AreEqual(40f, root_child0_child0_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(35f, root_child0_child1.LayoutX);
|
||||
Assert.AreEqual(40f, root_child0_child1.LayoutY);
|
||||
Assert.AreEqual(40f, root_child0_child1.LayoutWidth);
|
||||
Assert.AreEqual(40f, root_child0_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child0_child1_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0_child1_child0.LayoutY);
|
||||
Assert.AreEqual(40f, root_child0_child1_child0.LayoutWidth);
|
||||
Assert.AreEqual(40f, root_child0_child1_child0.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_wrap_nodes_with_content_sizing_margin_cross()
|
||||
{
|
||||
YogaConfig config = new YogaConfig();
|
||||
|
||||
YogaNode root = new YogaNode(config);
|
||||
root.Width = 500;
|
||||
root.Height = 500;
|
||||
|
||||
YogaNode root_child0 = new YogaNode(config);
|
||||
root_child0.FlexDirection = YogaFlexDirection.Row;
|
||||
root_child0.Wrap = YogaWrap.Wrap;
|
||||
root_child0.Width = 70;
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
YogaNode root_child0_child0 = new YogaNode(config);
|
||||
root_child0.Insert(0, root_child0_child0);
|
||||
|
||||
YogaNode root_child0_child0_child0 = new YogaNode(config);
|
||||
root_child0_child0_child0.Width = 40;
|
||||
root_child0_child0_child0.Height = 40;
|
||||
root_child0_child0.Insert(0, root_child0_child0_child0);
|
||||
|
||||
YogaNode root_child0_child1 = new YogaNode(config);
|
||||
root_child0_child1.MarginTop = 10;
|
||||
root_child0.Insert(1, root_child0_child1);
|
||||
|
||||
YogaNode root_child0_child1_child0 = new YogaNode(config);
|
||||
root_child0_child1_child0.Width = 40;
|
||||
root_child0_child1_child0.Height = 40;
|
||||
root_child0_child1.Insert(0, root_child0_child1_child0);
|
||||
root.StyleDirection = YogaDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0f, root.LayoutX);
|
||||
Assert.AreEqual(0f, root.LayoutY);
|
||||
Assert.AreEqual(500f, root.LayoutWidth);
|
||||
Assert.AreEqual(500f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0.LayoutY);
|
||||
Assert.AreEqual(70f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(90f, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child0_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0_child0.LayoutY);
|
||||
Assert.AreEqual(40f, root_child0_child0.LayoutWidth);
|
||||
Assert.AreEqual(40f, root_child0_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child0_child0_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0_child0_child0.LayoutY);
|
||||
Assert.AreEqual(40f, root_child0_child0_child0.LayoutWidth);
|
||||
Assert.AreEqual(40f, root_child0_child0_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child0_child1.LayoutX);
|
||||
Assert.AreEqual(50f, root_child0_child1.LayoutY);
|
||||
Assert.AreEqual(40f, root_child0_child1.LayoutWidth);
|
||||
Assert.AreEqual(40f, root_child0_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child0_child1_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0_child1_child0.LayoutY);
|
||||
Assert.AreEqual(40f, root_child0_child1_child0.LayoutWidth);
|
||||
Assert.AreEqual(40f, root_child0_child1_child0.LayoutHeight);
|
||||
|
||||
root.StyleDirection = YogaDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0f, root.LayoutX);
|
||||
Assert.AreEqual(0f, root.LayoutY);
|
||||
Assert.AreEqual(500f, root.LayoutWidth);
|
||||
Assert.AreEqual(500f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(430f, root_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0.LayoutY);
|
||||
Assert.AreEqual(70f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(90f, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(30f, root_child0_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0_child0.LayoutY);
|
||||
Assert.AreEqual(40f, root_child0_child0.LayoutWidth);
|
||||
Assert.AreEqual(40f, root_child0_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child0_child0_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0_child0_child0.LayoutY);
|
||||
Assert.AreEqual(40f, root_child0_child0_child0.LayoutWidth);
|
||||
Assert.AreEqual(40f, root_child0_child0_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(30f, root_child0_child1.LayoutX);
|
||||
Assert.AreEqual(50f, root_child0_child1.LayoutY);
|
||||
Assert.AreEqual(40f, root_child0_child1.LayoutWidth);
|
||||
Assert.AreEqual(40f, root_child0_child1.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child0_child1_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0_child1_child0.LayoutY);
|
||||
Assert.AreEqual(40f, root_child0_child1_child0.LayoutWidth);
|
||||
Assert.AreEqual(40f, root_child0_child1_child0.LayoutHeight);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -1352,5 +1352,260 @@ namespace Facebook.Yoga
|
||||
Assert.AreEqual(50f, root_child1.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_margin_should_not_be_part_of_max_height()
|
||||
{
|
||||
YogaConfig config = new YogaConfig();
|
||||
|
||||
YogaNode root = new YogaNode(config);
|
||||
root.Width = 250;
|
||||
root.Height = 250;
|
||||
|
||||
YogaNode root_child0 = new YogaNode(config);
|
||||
root_child0.MarginTop = 20;
|
||||
root_child0.Width = 100;
|
||||
root_child0.Height = 100;
|
||||
root_child0.MaxHeight = 100;
|
||||
root.Insert(0, root_child0);
|
||||
root.StyleDirection = YogaDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0f, root.LayoutX);
|
||||
Assert.AreEqual(0f, root.LayoutY);
|
||||
Assert.AreEqual(250f, root.LayoutWidth);
|
||||
Assert.AreEqual(250f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child0.LayoutX);
|
||||
Assert.AreEqual(20f, root_child0.LayoutY);
|
||||
Assert.AreEqual(100f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(100f, root_child0.LayoutHeight);
|
||||
|
||||
root.StyleDirection = YogaDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0f, root.LayoutX);
|
||||
Assert.AreEqual(0f, root.LayoutY);
|
||||
Assert.AreEqual(250f, root.LayoutWidth);
|
||||
Assert.AreEqual(250f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(150f, root_child0.LayoutX);
|
||||
Assert.AreEqual(20f, root_child0.LayoutY);
|
||||
Assert.AreEqual(100f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(100f, root_child0.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_margin_should_not_be_part_of_max_width()
|
||||
{
|
||||
YogaConfig config = new YogaConfig();
|
||||
|
||||
YogaNode root = new YogaNode(config);
|
||||
root.Width = 250;
|
||||
root.Height = 250;
|
||||
|
||||
YogaNode root_child0 = new YogaNode(config);
|
||||
root_child0.MarginLeft = 20;
|
||||
root_child0.Width = 100;
|
||||
root_child0.MaxWidth = 100;
|
||||
root_child0.Height = 100;
|
||||
root.Insert(0, root_child0);
|
||||
root.StyleDirection = YogaDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0f, root.LayoutX);
|
||||
Assert.AreEqual(0f, root.LayoutY);
|
||||
Assert.AreEqual(250f, root.LayoutWidth);
|
||||
Assert.AreEqual(250f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(20f, root_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0.LayoutY);
|
||||
Assert.AreEqual(100f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(100f, root_child0.LayoutHeight);
|
||||
|
||||
root.StyleDirection = YogaDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0f, root.LayoutX);
|
||||
Assert.AreEqual(0f, root.LayoutY);
|
||||
Assert.AreEqual(250f, root.LayoutWidth);
|
||||
Assert.AreEqual(250f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(150f, root_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0.LayoutY);
|
||||
Assert.AreEqual(100f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(100f, root_child0.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_margin_auto_left_right_child_bigger_than_parent()
|
||||
{
|
||||
YogaConfig config = new YogaConfig();
|
||||
|
||||
YogaNode root = new YogaNode(config);
|
||||
root.JustifyContent = YogaJustify.Center;
|
||||
root.Width = 52;
|
||||
root.Height = 52;
|
||||
|
||||
YogaNode root_child0 = new YogaNode(config);
|
||||
root_child0.MarginLeft = YogaValue.Auto();
|
||||
root_child0.MarginRight = YogaValue.Auto();
|
||||
root_child0.Width = 72;
|
||||
root_child0.Height = 72;
|
||||
root.Insert(0, root_child0);
|
||||
root.StyleDirection = YogaDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0f, root.LayoutX);
|
||||
Assert.AreEqual(0f, root.LayoutY);
|
||||
Assert.AreEqual(52f, root.LayoutWidth);
|
||||
Assert.AreEqual(52f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child0.LayoutX);
|
||||
Assert.AreEqual(-10f, root_child0.LayoutY);
|
||||
Assert.AreEqual(72f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(72f, root_child0.LayoutHeight);
|
||||
|
||||
root.StyleDirection = YogaDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0f, root.LayoutX);
|
||||
Assert.AreEqual(0f, root.LayoutY);
|
||||
Assert.AreEqual(52f, root.LayoutWidth);
|
||||
Assert.AreEqual(52f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(-20f, root_child0.LayoutX);
|
||||
Assert.AreEqual(-10f, root_child0.LayoutY);
|
||||
Assert.AreEqual(72f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(72f, root_child0.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_margin_auto_left_child_bigger_than_parent()
|
||||
{
|
||||
YogaConfig config = new YogaConfig();
|
||||
|
||||
YogaNode root = new YogaNode(config);
|
||||
root.JustifyContent = YogaJustify.Center;
|
||||
root.Width = 52;
|
||||
root.Height = 52;
|
||||
|
||||
YogaNode root_child0 = new YogaNode(config);
|
||||
root_child0.MarginLeft = YogaValue.Auto();
|
||||
root_child0.Width = 72;
|
||||
root_child0.Height = 72;
|
||||
root.Insert(0, root_child0);
|
||||
root.StyleDirection = YogaDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0f, root.LayoutX);
|
||||
Assert.AreEqual(0f, root.LayoutY);
|
||||
Assert.AreEqual(52f, root.LayoutWidth);
|
||||
Assert.AreEqual(52f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child0.LayoutX);
|
||||
Assert.AreEqual(-10f, root_child0.LayoutY);
|
||||
Assert.AreEqual(72f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(72f, root_child0.LayoutHeight);
|
||||
|
||||
root.StyleDirection = YogaDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0f, root.LayoutX);
|
||||
Assert.AreEqual(0f, root.LayoutY);
|
||||
Assert.AreEqual(52f, root.LayoutWidth);
|
||||
Assert.AreEqual(52f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(-20f, root_child0.LayoutX);
|
||||
Assert.AreEqual(-10f, root_child0.LayoutY);
|
||||
Assert.AreEqual(72f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(72f, root_child0.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_margin_fix_left_auto_right_child_bigger_than_parent()
|
||||
{
|
||||
YogaConfig config = new YogaConfig();
|
||||
|
||||
YogaNode root = new YogaNode(config);
|
||||
root.JustifyContent = YogaJustify.Center;
|
||||
root.Width = 52;
|
||||
root.Height = 52;
|
||||
|
||||
YogaNode root_child0 = new YogaNode(config);
|
||||
root_child0.MarginLeft = 10;
|
||||
root_child0.MarginRight = YogaValue.Auto();
|
||||
root_child0.Width = 72;
|
||||
root_child0.Height = 72;
|
||||
root.Insert(0, root_child0);
|
||||
root.StyleDirection = YogaDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0f, root.LayoutX);
|
||||
Assert.AreEqual(0f, root.LayoutY);
|
||||
Assert.AreEqual(52f, root.LayoutWidth);
|
||||
Assert.AreEqual(52f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(10f, root_child0.LayoutX);
|
||||
Assert.AreEqual(-10f, root_child0.LayoutY);
|
||||
Assert.AreEqual(72f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(72f, root_child0.LayoutHeight);
|
||||
|
||||
root.StyleDirection = YogaDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0f, root.LayoutX);
|
||||
Assert.AreEqual(0f, root.LayoutY);
|
||||
Assert.AreEqual(52f, root.LayoutWidth);
|
||||
Assert.AreEqual(52f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(-20f, root_child0.LayoutX);
|
||||
Assert.AreEqual(-10f, root_child0.LayoutY);
|
||||
Assert.AreEqual(72f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(72f, root_child0.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_margin_auto_left_fix_right_child_bigger_than_parent()
|
||||
{
|
||||
YogaConfig config = new YogaConfig();
|
||||
|
||||
YogaNode root = new YogaNode(config);
|
||||
root.JustifyContent = YogaJustify.Center;
|
||||
root.Width = 52;
|
||||
root.Height = 52;
|
||||
|
||||
YogaNode root_child0 = new YogaNode(config);
|
||||
root_child0.MarginLeft = YogaValue.Auto();
|
||||
root_child0.MarginRight = 10;
|
||||
root_child0.Width = 72;
|
||||
root_child0.Height = 72;
|
||||
root.Insert(0, root_child0);
|
||||
root.StyleDirection = YogaDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0f, root.LayoutX);
|
||||
Assert.AreEqual(0f, root.LayoutY);
|
||||
Assert.AreEqual(52f, root.LayoutWidth);
|
||||
Assert.AreEqual(52f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child0.LayoutX);
|
||||
Assert.AreEqual(-10f, root_child0.LayoutY);
|
||||
Assert.AreEqual(72f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(72f, root_child0.LayoutHeight);
|
||||
|
||||
root.StyleDirection = YogaDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0f, root.LayoutX);
|
||||
Assert.AreEqual(0f, root.LayoutY);
|
||||
Assert.AreEqual(52f, root.LayoutWidth);
|
||||
Assert.AreEqual(52f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(-30f, root_child0.LayoutX);
|
||||
Assert.AreEqual(-10f, root_child0.LayoutY);
|
||||
Assert.AreEqual(72f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(72f, root_child0.LayoutHeight);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -366,7 +366,6 @@ namespace Facebook.Yoga
|
||||
public void Test_flex_grow_to_min()
|
||||
{
|
||||
YogaConfig config = new YogaConfig();
|
||||
config.SetExperimentalFeatureEnabled(YogaExperimentalFeature.MinFlexFix, true);
|
||||
|
||||
YogaNode root = new YogaNode(config);
|
||||
root.Width = 100;
|
||||
@@ -422,7 +421,6 @@ namespace Facebook.Yoga
|
||||
public void Test_flex_grow_in_at_most_container()
|
||||
{
|
||||
YogaConfig config = new YogaConfig();
|
||||
config.SetExperimentalFeatureEnabled(YogaExperimentalFeature.MinFlexFix, true);
|
||||
|
||||
YogaNode root = new YogaNode(config);
|
||||
root.FlexDirection = YogaFlexDirection.Row;
|
||||
@@ -475,6 +473,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()
|
||||
{
|
||||
@@ -585,6 +676,203 @@ namespace Facebook.Yoga
|
||||
Assert.AreEqual(20f, root_child0_child0.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_flex_root_ignored()
|
||||
{
|
||||
YogaConfig config = new YogaConfig();
|
||||
|
||||
YogaNode root = new YogaNode(config);
|
||||
root.FlexGrow = 1;
|
||||
root.Width = 100;
|
||||
root.MinHeight = 100;
|
||||
root.MaxHeight = 500;
|
||||
|
||||
YogaNode root_child0 = new YogaNode(config);
|
||||
root_child0.FlexGrow = 1;
|
||||
root_child0.FlexBasis = 200;
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
YogaNode root_child1 = new YogaNode(config);
|
||||
root_child1.Height = 100;
|
||||
root.Insert(1, root_child1);
|
||||
root.StyleDirection = YogaDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0f, root.LayoutX);
|
||||
Assert.AreEqual(0f, root.LayoutY);
|
||||
Assert.AreEqual(100f, 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(200f, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child1.LayoutX);
|
||||
Assert.AreEqual(200f, root_child1.LayoutY);
|
||||
Assert.AreEqual(100f, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(100f, root_child1.LayoutHeight);
|
||||
|
||||
root.StyleDirection = YogaDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0f, root.LayoutX);
|
||||
Assert.AreEqual(0f, root.LayoutY);
|
||||
Assert.AreEqual(100f, 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(200f, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child1.LayoutX);
|
||||
Assert.AreEqual(200f, root_child1.LayoutY);
|
||||
Assert.AreEqual(100f, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(100f, root_child1.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_flex_grow_root_minimized()
|
||||
{
|
||||
YogaConfig config = new YogaConfig();
|
||||
|
||||
YogaNode root = new YogaNode(config);
|
||||
root.Width = 100;
|
||||
root.MinHeight = 100;
|
||||
root.MaxHeight = 500;
|
||||
|
||||
YogaNode root_child0 = new YogaNode(config);
|
||||
root_child0.FlexGrow = 1;
|
||||
root_child0.MinHeight = 100;
|
||||
root_child0.MaxHeight = 500;
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
YogaNode root_child0_child0 = new YogaNode(config);
|
||||
root_child0_child0.FlexGrow = 1;
|
||||
root_child0_child0.FlexBasis = 200;
|
||||
root_child0.Insert(0, root_child0_child0);
|
||||
|
||||
YogaNode root_child0_child1 = new YogaNode(config);
|
||||
root_child0_child1.Height = 100;
|
||||
root_child0.Insert(1, root_child0_child1);
|
||||
root.StyleDirection = YogaDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0f, root.LayoutX);
|
||||
Assert.AreEqual(0f, root.LayoutY);
|
||||
Assert.AreEqual(100f, 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(0f, root_child0_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0_child0.LayoutY);
|
||||
Assert.AreEqual(100f, root_child0_child0.LayoutWidth);
|
||||
Assert.AreEqual(200f, root_child0_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child0_child1.LayoutX);
|
||||
Assert.AreEqual(200f, root_child0_child1.LayoutY);
|
||||
Assert.AreEqual(100f, root_child0_child1.LayoutWidth);
|
||||
Assert.AreEqual(100f, root_child0_child1.LayoutHeight);
|
||||
|
||||
root.StyleDirection = YogaDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0f, root.LayoutX);
|
||||
Assert.AreEqual(0f, root.LayoutY);
|
||||
Assert.AreEqual(100f, 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(0f, root_child0_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0_child0.LayoutY);
|
||||
Assert.AreEqual(100f, root_child0_child0.LayoutWidth);
|
||||
Assert.AreEqual(200f, root_child0_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child0_child1.LayoutX);
|
||||
Assert.AreEqual(200f, root_child0_child1.LayoutY);
|
||||
Assert.AreEqual(100f, root_child0_child1.LayoutWidth);
|
||||
Assert.AreEqual(100f, root_child0_child1.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_flex_grow_height_maximized()
|
||||
{
|
||||
YogaConfig config = new YogaConfig();
|
||||
|
||||
YogaNode root = new YogaNode(config);
|
||||
root.Width = 100;
|
||||
root.Height = 500;
|
||||
|
||||
YogaNode root_child0 = new YogaNode(config);
|
||||
root_child0.FlexGrow = 1;
|
||||
root_child0.MinHeight = 100;
|
||||
root_child0.MaxHeight = 500;
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
YogaNode root_child0_child0 = new YogaNode(config);
|
||||
root_child0_child0.FlexGrow = 1;
|
||||
root_child0_child0.FlexBasis = 200;
|
||||
root_child0.Insert(0, root_child0_child0);
|
||||
|
||||
YogaNode root_child0_child1 = new YogaNode(config);
|
||||
root_child0_child1.Height = 100;
|
||||
root_child0.Insert(1, root_child0_child1);
|
||||
root.StyleDirection = YogaDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0f, root.LayoutX);
|
||||
Assert.AreEqual(0f, root.LayoutY);
|
||||
Assert.AreEqual(100f, root.LayoutWidth);
|
||||
Assert.AreEqual(500f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0.LayoutY);
|
||||
Assert.AreEqual(100f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(500f, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child0_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0_child0.LayoutY);
|
||||
Assert.AreEqual(100f, root_child0_child0.LayoutWidth);
|
||||
Assert.AreEqual(400f, root_child0_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child0_child1.LayoutX);
|
||||
Assert.AreEqual(400f, root_child0_child1.LayoutY);
|
||||
Assert.AreEqual(100f, root_child0_child1.LayoutWidth);
|
||||
Assert.AreEqual(100f, root_child0_child1.LayoutHeight);
|
||||
|
||||
root.StyleDirection = YogaDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0f, root.LayoutX);
|
||||
Assert.AreEqual(0f, root.LayoutY);
|
||||
Assert.AreEqual(100f, root.LayoutWidth);
|
||||
Assert.AreEqual(500f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0.LayoutY);
|
||||
Assert.AreEqual(100f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(500f, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child0_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0_child0.LayoutY);
|
||||
Assert.AreEqual(100f, root_child0_child0.LayoutWidth);
|
||||
Assert.AreEqual(400f, root_child0_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child0_child1.LayoutX);
|
||||
Assert.AreEqual(400f, root_child0_child1.LayoutY);
|
||||
Assert.AreEqual(100f, root_child0_child1.LayoutWidth);
|
||||
Assert.AreEqual(100f, root_child0_child1.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_flex_grow_within_constrained_min_row()
|
||||
{
|
||||
@@ -814,6 +1102,64 @@ namespace Facebook.Yoga
|
||||
Assert.AreEqual(50f, root_child1.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_child_min_max_width_flexing()
|
||||
{
|
||||
YogaConfig config = new YogaConfig();
|
||||
|
||||
YogaNode root = new YogaNode(config);
|
||||
root.FlexDirection = YogaFlexDirection.Row;
|
||||
root.Width = 120;
|
||||
root.Height = 50;
|
||||
|
||||
YogaNode root_child0 = new YogaNode(config);
|
||||
root_child0.FlexGrow = 1;
|
||||
root_child0.FlexBasis = 0;
|
||||
root_child0.MinWidth = 60;
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
YogaNode root_child1 = new YogaNode(config);
|
||||
root_child1.FlexGrow = 1;
|
||||
root_child1.FlexBasis = 50.Percent();
|
||||
root_child1.MaxWidth = 20;
|
||||
root.Insert(1, root_child1);
|
||||
root.StyleDirection = YogaDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0f, root.LayoutX);
|
||||
Assert.AreEqual(0f, root.LayoutY);
|
||||
Assert.AreEqual(120f, root.LayoutWidth);
|
||||
Assert.AreEqual(50f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0.LayoutY);
|
||||
Assert.AreEqual(100f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(50f, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(100f, root_child1.LayoutX);
|
||||
Assert.AreEqual(0f, root_child1.LayoutY);
|
||||
Assert.AreEqual(20f, 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(120f, root.LayoutWidth);
|
||||
Assert.AreEqual(50f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(20f, root_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0.LayoutY);
|
||||
Assert.AreEqual(100f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(50f, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child1.LayoutX);
|
||||
Assert.AreEqual(0f, root_child1.LayoutY);
|
||||
Assert.AreEqual(20f, root_child1.LayoutWidth);
|
||||
Assert.AreEqual(50f, root_child1.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_min_width_overrides_width()
|
||||
{
|
||||
|
@@ -21,7 +21,6 @@ namespace Facebook.Yoga
|
||||
public void Test_percentage_width_height()
|
||||
{
|
||||
YogaConfig config = new YogaConfig();
|
||||
config.SetExperimentalFeatureEnabled(YogaExperimentalFeature.Rounding, true);
|
||||
|
||||
YogaNode root = new YogaNode(config);
|
||||
root.FlexDirection = YogaFlexDirection.Row;
|
||||
@@ -63,7 +62,6 @@ namespace Facebook.Yoga
|
||||
public void Test_percentage_position_left_top()
|
||||
{
|
||||
YogaConfig config = new YogaConfig();
|
||||
config.SetExperimentalFeatureEnabled(YogaExperimentalFeature.Rounding, true);
|
||||
|
||||
YogaNode root = new YogaNode(config);
|
||||
root.FlexDirection = YogaFlexDirection.Row;
|
||||
@@ -107,7 +105,6 @@ namespace Facebook.Yoga
|
||||
public void Test_percentage_position_bottom_right()
|
||||
{
|
||||
YogaConfig config = new YogaConfig();
|
||||
config.SetExperimentalFeatureEnabled(YogaExperimentalFeature.Rounding, true);
|
||||
|
||||
YogaNode root = new YogaNode(config);
|
||||
root.FlexDirection = YogaFlexDirection.Row;
|
||||
@@ -151,7 +148,6 @@ namespace Facebook.Yoga
|
||||
public void Test_percentage_flex_basis()
|
||||
{
|
||||
YogaConfig config = new YogaConfig();
|
||||
config.SetExperimentalFeatureEnabled(YogaExperimentalFeature.Rounding, true);
|
||||
|
||||
YogaNode root = new YogaNode(config);
|
||||
root.FlexDirection = YogaFlexDirection.Row;
|
||||
@@ -208,7 +204,6 @@ namespace Facebook.Yoga
|
||||
public void Test_percentage_flex_basis_cross()
|
||||
{
|
||||
YogaConfig config = new YogaConfig();
|
||||
config.SetExperimentalFeatureEnabled(YogaExperimentalFeature.Rounding, true);
|
||||
|
||||
YogaNode root = new YogaNode(config);
|
||||
root.Width = 200;
|
||||
@@ -264,7 +259,6 @@ namespace Facebook.Yoga
|
||||
public void Test_percentage_flex_basis_cross_min_height()
|
||||
{
|
||||
YogaConfig config = new YogaConfig();
|
||||
config.SetExperimentalFeatureEnabled(YogaExperimentalFeature.Rounding, true);
|
||||
|
||||
YogaNode root = new YogaNode(config);
|
||||
root.Width = 200;
|
||||
@@ -320,7 +314,6 @@ namespace Facebook.Yoga
|
||||
public void Test_percentage_flex_basis_main_max_height()
|
||||
{
|
||||
YogaConfig config = new YogaConfig();
|
||||
config.SetExperimentalFeatureEnabled(YogaExperimentalFeature.Rounding, true);
|
||||
|
||||
YogaNode root = new YogaNode(config);
|
||||
root.FlexDirection = YogaFlexDirection.Row;
|
||||
@@ -379,7 +372,6 @@ namespace Facebook.Yoga
|
||||
public void Test_percentage_flex_basis_cross_max_height()
|
||||
{
|
||||
YogaConfig config = new YogaConfig();
|
||||
config.SetExperimentalFeatureEnabled(YogaExperimentalFeature.Rounding, true);
|
||||
|
||||
YogaNode root = new YogaNode(config);
|
||||
root.Width = 200;
|
||||
@@ -437,7 +429,6 @@ namespace Facebook.Yoga
|
||||
public void Test_percentage_flex_basis_main_max_width()
|
||||
{
|
||||
YogaConfig config = new YogaConfig();
|
||||
config.SetExperimentalFeatureEnabled(YogaExperimentalFeature.Rounding, true);
|
||||
|
||||
YogaNode root = new YogaNode(config);
|
||||
root.FlexDirection = YogaFlexDirection.Row;
|
||||
@@ -496,7 +487,6 @@ namespace Facebook.Yoga
|
||||
public void Test_percentage_flex_basis_cross_max_width()
|
||||
{
|
||||
YogaConfig config = new YogaConfig();
|
||||
config.SetExperimentalFeatureEnabled(YogaExperimentalFeature.Rounding, true);
|
||||
|
||||
YogaNode root = new YogaNode(config);
|
||||
root.Width = 200;
|
||||
@@ -554,7 +544,6 @@ namespace Facebook.Yoga
|
||||
public void Test_percentage_flex_basis_main_min_width()
|
||||
{
|
||||
YogaConfig config = new YogaConfig();
|
||||
config.SetExperimentalFeatureEnabled(YogaExperimentalFeature.Rounding, true);
|
||||
|
||||
YogaNode root = new YogaNode(config);
|
||||
root.FlexDirection = YogaFlexDirection.Row;
|
||||
@@ -613,7 +602,6 @@ namespace Facebook.Yoga
|
||||
public void Test_percentage_flex_basis_cross_min_width()
|
||||
{
|
||||
YogaConfig config = new YogaConfig();
|
||||
config.SetExperimentalFeatureEnabled(YogaExperimentalFeature.Rounding, true);
|
||||
|
||||
YogaNode root = new YogaNode(config);
|
||||
root.Width = 200;
|
||||
@@ -671,7 +659,6 @@ namespace Facebook.Yoga
|
||||
public void Test_percentage_multiple_nested_with_padding_margin_and_percentage_values()
|
||||
{
|
||||
YogaConfig config = new YogaConfig();
|
||||
config.SetExperimentalFeatureEnabled(YogaExperimentalFeature.Rounding, true);
|
||||
|
||||
YogaNode root = new YogaNode(config);
|
||||
root.Width = 200;
|
||||
@@ -781,7 +768,6 @@ namespace Facebook.Yoga
|
||||
public void Test_percentage_margin_should_calculate_based_only_on_width()
|
||||
{
|
||||
YogaConfig config = new YogaConfig();
|
||||
config.SetExperimentalFeatureEnabled(YogaExperimentalFeature.Rounding, true);
|
||||
|
||||
YogaNode root = new YogaNode(config);
|
||||
root.Width = 200;
|
||||
@@ -840,7 +826,6 @@ namespace Facebook.Yoga
|
||||
public void Test_percentage_padding_should_calculate_based_only_on_width()
|
||||
{
|
||||
YogaConfig config = new YogaConfig();
|
||||
config.SetExperimentalFeatureEnabled(YogaExperimentalFeature.Rounding, true);
|
||||
|
||||
YogaNode root = new YogaNode(config);
|
||||
root.Width = 200;
|
||||
@@ -899,7 +884,6 @@ namespace Facebook.Yoga
|
||||
public void Test_percentage_absolute_position()
|
||||
{
|
||||
YogaConfig config = new YogaConfig();
|
||||
config.SetExperimentalFeatureEnabled(YogaExperimentalFeature.Rounding, true);
|
||||
|
||||
YogaNode root = new YogaNode(config);
|
||||
root.Width = 200;
|
||||
@@ -1063,7 +1047,6 @@ namespace Facebook.Yoga
|
||||
public void Test_percentage_container_in_wrapping_container()
|
||||
{
|
||||
YogaConfig config = new YogaConfig();
|
||||
config.SetExperimentalFeatureEnabled(YogaExperimentalFeature.MinFlexFix, true);
|
||||
|
||||
YogaNode root = new YogaNode(config);
|
||||
root.JustifyContent = YogaJustify.Center;
|
||||
@@ -1146,5 +1129,76 @@ namespace Facebook.Yoga
|
||||
Assert.AreEqual(50f, root_child0_child0_child1.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_percent_absolute_position()
|
||||
{
|
||||
YogaConfig config = new YogaConfig();
|
||||
|
||||
YogaNode root = new YogaNode(config);
|
||||
root.Width = 60;
|
||||
root.Height = 50;
|
||||
|
||||
YogaNode root_child0 = new YogaNode(config);
|
||||
root_child0.FlexDirection = YogaFlexDirection.Row;
|
||||
root_child0.PositionType = YogaPositionType.Absolute;
|
||||
root_child0.Left = 50.Percent();
|
||||
root_child0.Width = 100.Percent();
|
||||
root_child0.Height = 50;
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
YogaNode root_child0_child0 = new YogaNode(config);
|
||||
root_child0_child0.Width = 100.Percent();
|
||||
root_child0.Insert(0, root_child0_child0);
|
||||
|
||||
YogaNode root_child0_child1 = new YogaNode(config);
|
||||
root_child0_child1.Width = 100.Percent();
|
||||
root_child0.Insert(1, root_child0_child1);
|
||||
root.StyleDirection = YogaDirection.LTR;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0f, root.LayoutX);
|
||||
Assert.AreEqual(0f, root.LayoutY);
|
||||
Assert.AreEqual(60f, root.LayoutWidth);
|
||||
Assert.AreEqual(50f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(30f, root_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0.LayoutY);
|
||||
Assert.AreEqual(60f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(50f, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child0_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0_child0.LayoutY);
|
||||
Assert.AreEqual(60f, root_child0_child0.LayoutWidth);
|
||||
Assert.AreEqual(50f, root_child0_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(60f, root_child0_child1.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0_child1.LayoutY);
|
||||
Assert.AreEqual(60f, root_child0_child1.LayoutWidth);
|
||||
Assert.AreEqual(50f, root_child0_child1.LayoutHeight);
|
||||
|
||||
root.StyleDirection = YogaDirection.RTL;
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0f, root.LayoutX);
|
||||
Assert.AreEqual(0f, root.LayoutY);
|
||||
Assert.AreEqual(60f, root.LayoutWidth);
|
||||
Assert.AreEqual(50f, root.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(30f, root_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0.LayoutY);
|
||||
Assert.AreEqual(60f, root_child0.LayoutWidth);
|
||||
Assert.AreEqual(50f, root_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(0f, root_child0_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0_child0.LayoutY);
|
||||
Assert.AreEqual(60f, root_child0_child0.LayoutWidth);
|
||||
Assert.AreEqual(50f, root_child0_child0.LayoutHeight);
|
||||
|
||||
Assert.AreEqual(-60f, root_child0_child1.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0_child1.LayoutY);
|
||||
Assert.AreEqual(60f, root_child0_child1.LayoutWidth);
|
||||
Assert.AreEqual(50f, root_child0_child1.LayoutHeight);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -21,7 +21,6 @@ namespace Facebook.Yoga
|
||||
public void Test_rounding_flex_basis_flex_grow_row_width_of_100()
|
||||
{
|
||||
YogaConfig config = new YogaConfig();
|
||||
config.SetExperimentalFeatureEnabled(YogaExperimentalFeature.Rounding, true);
|
||||
|
||||
YogaNode root = new YogaNode(config);
|
||||
root.FlexDirection = YogaFlexDirection.Row;
|
||||
@@ -90,7 +89,6 @@ namespace Facebook.Yoga
|
||||
public void Test_rounding_flex_basis_flex_grow_row_prime_number_width()
|
||||
{
|
||||
YogaConfig config = new YogaConfig();
|
||||
config.SetExperimentalFeatureEnabled(YogaExperimentalFeature.Rounding, true);
|
||||
|
||||
YogaNode root = new YogaNode(config);
|
||||
root.FlexDirection = YogaFlexDirection.Row;
|
||||
@@ -187,7 +185,6 @@ namespace Facebook.Yoga
|
||||
public void Test_rounding_flex_basis_flex_shrink_row()
|
||||
{
|
||||
YogaConfig config = new YogaConfig();
|
||||
config.SetExperimentalFeatureEnabled(YogaExperimentalFeature.Rounding, true);
|
||||
|
||||
YogaNode root = new YogaNode(config);
|
||||
root.FlexDirection = YogaFlexDirection.Row;
|
||||
@@ -257,7 +254,6 @@ namespace Facebook.Yoga
|
||||
public void Test_rounding_flex_basis_overrides_main_size()
|
||||
{
|
||||
YogaConfig config = new YogaConfig();
|
||||
config.SetExperimentalFeatureEnabled(YogaExperimentalFeature.Rounding, true);
|
||||
|
||||
YogaNode root = new YogaNode(config);
|
||||
root.Width = 100;
|
||||
@@ -329,7 +325,6 @@ namespace Facebook.Yoga
|
||||
public void Test_rounding_total_fractial()
|
||||
{
|
||||
YogaConfig config = new YogaConfig();
|
||||
config.SetExperimentalFeatureEnabled(YogaExperimentalFeature.Rounding, true);
|
||||
|
||||
YogaNode root = new YogaNode(config);
|
||||
root.Width = 87.4f;
|
||||
@@ -401,7 +396,6 @@ namespace Facebook.Yoga
|
||||
public void Test_rounding_total_fractial_nested()
|
||||
{
|
||||
YogaConfig config = new YogaConfig();
|
||||
config.SetExperimentalFeatureEnabled(YogaExperimentalFeature.Rounding, true);
|
||||
|
||||
YogaNode root = new YogaNode(config);
|
||||
root.Width = 87.4f;
|
||||
@@ -507,7 +501,6 @@ namespace Facebook.Yoga
|
||||
public void Test_rounding_fractial_input_1()
|
||||
{
|
||||
YogaConfig config = new YogaConfig();
|
||||
config.SetExperimentalFeatureEnabled(YogaExperimentalFeature.Rounding, true);
|
||||
|
||||
YogaNode root = new YogaNode(config);
|
||||
root.Width = 100;
|
||||
@@ -579,7 +572,6 @@ namespace Facebook.Yoga
|
||||
public void Test_rounding_fractial_input_2()
|
||||
{
|
||||
YogaConfig config = new YogaConfig();
|
||||
config.SetExperimentalFeatureEnabled(YogaExperimentalFeature.Rounding, true);
|
||||
|
||||
YogaNode root = new YogaNode(config);
|
||||
root.Width = 100;
|
||||
@@ -651,7 +643,6 @@ namespace Facebook.Yoga
|
||||
public void Test_rounding_fractial_input_3()
|
||||
{
|
||||
YogaConfig config = new YogaConfig();
|
||||
config.SetExperimentalFeatureEnabled(YogaExperimentalFeature.Rounding, true);
|
||||
|
||||
YogaNode root = new YogaNode(config);
|
||||
root.Top = 0.3f;
|
||||
@@ -684,17 +675,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,24 +698,23 @@ 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]
|
||||
public void Test_rounding_fractial_input_4()
|
||||
{
|
||||
YogaConfig config = new YogaConfig();
|
||||
config.SetExperimentalFeatureEnabled(YogaExperimentalFeature.Rounding, true);
|
||||
|
||||
YogaNode root = new YogaNode(config);
|
||||
root.Top = 0.7f;
|
||||
@@ -793,5 +783,305 @@ namespace Facebook.Yoga
|
||||
Assert.AreEqual(24f, root_child2.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_rounding_inner_node_controversy_horizontal()
|
||||
{
|
||||
YogaConfig config = new YogaConfig();
|
||||
|
||||
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();
|
||||
|
||||
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();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
138
csharp/tests/Facebook.Yoga/YogaConfigTest.cs
Normal file
138
csharp/tests/Facebook.Yoga/YogaConfigTest.cs
Normal file
@@ -0,0 +1,138 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
|
||||
/**
|
||||
* Tests for {@link YogaConfig}.
|
||||
*/
|
||||
namespace Facebook.Yoga
|
||||
{
|
||||
[TestFixture]
|
||||
public class YogaConfigTest
|
||||
{
|
||||
[Test]
|
||||
public void TestUseWebDefaults()
|
||||
{
|
||||
YogaNode node0 = new YogaNode(new YogaConfig{UseWebDefaults = true});
|
||||
Assert.AreEqual(YogaFlexDirection.Row, node0.FlexDirection);
|
||||
|
||||
node0.Reset();
|
||||
Assert.AreEqual(YogaFlexDirection.Row, node0.FlexDirection);
|
||||
|
||||
YogaConfig config = new YogaConfig();
|
||||
config.UseWebDefaults = true;
|
||||
YogaNode node1 = new YogaNode(config);
|
||||
Assert.AreEqual(YogaFlexDirection.Row, node1.FlexDirection);
|
||||
|
||||
node1.Reset();
|
||||
Assert.AreEqual(YogaFlexDirection.Row, node1.FlexDirection);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestDefaultConfig()
|
||||
{
|
||||
YogaNode node0 = new YogaNode();
|
||||
Assert.AreEqual(YogaFlexDirection.Column, node0.FlexDirection);
|
||||
|
||||
YogaNode node1 = new YogaNode(new YogaConfig());
|
||||
Assert.AreEqual(YogaFlexDirection.Column, node1.FlexDirection);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCopyConstructor()
|
||||
{
|
||||
YogaNode srcNode = new YogaNode(new YogaConfig{UseWebDefaults = true});
|
||||
YogaNode node0 = new YogaNode(srcNode);
|
||||
Assert.AreEqual(YogaFlexDirection.Row, node0.FlexDirection);
|
||||
|
||||
node0.FlexDirection = YogaFlexDirection.Column;
|
||||
Assert.AreEqual(YogaFlexDirection.Column, node0.FlexDirection);
|
||||
|
||||
node0.Reset();
|
||||
Assert.AreEqual(YogaFlexDirection.Row, node0.FlexDirection);
|
||||
|
||||
YogaNode node1 = new YogaNode(srcNode)
|
||||
{
|
||||
FlexDirection = YogaFlexDirection.Column
|
||||
};
|
||||
Assert.AreEqual(YogaFlexDirection.Column, node1.FlexDirection);
|
||||
|
||||
node1.Reset();
|
||||
Assert.AreEqual(YogaFlexDirection.Row, node1.FlexDirection);
|
||||
}
|
||||
|
||||
#if !UNITY_5_4_OR_NEWER
|
||||
public static void ForceGC()
|
||||
{
|
||||
YogaNodeTest.ForceGC();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestDestructor()
|
||||
{
|
||||
ForceGC();
|
||||
int instanceCount = YogaConfig.GetInstanceCount();
|
||||
TestDestructorForGC(instanceCount);
|
||||
ForceGC();
|
||||
Assert.AreEqual(instanceCount, YogaConfig.GetInstanceCount());
|
||||
}
|
||||
|
||||
private void TestDestructorForGC(int instanceCount)
|
||||
{
|
||||
YogaConfig config = new YogaConfig();
|
||||
Assert.IsNotNull(config);
|
||||
Assert.AreEqual(instanceCount + 1, YogaConfig.GetInstanceCount());
|
||||
config = null;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestRetainConfig()
|
||||
{
|
||||
ForceGC();
|
||||
int nodeInstanceCount = YogaNode.GetInstanceCount();
|
||||
int configInstanceCount = YogaConfig.GetInstanceCount();
|
||||
TestRetainConfigForGC(nodeInstanceCount, configInstanceCount);
|
||||
ForceGC();
|
||||
|
||||
Assert.AreEqual(nodeInstanceCount, YogaNode.GetInstanceCount());
|
||||
Assert.AreEqual(configInstanceCount, YogaConfig.GetInstanceCount());
|
||||
}
|
||||
|
||||
private void TestRetainConfigForGC(int nodeInstanceCount, int configInstanceCount)
|
||||
{
|
||||
ForceGC();
|
||||
Assert.AreEqual(nodeInstanceCount, YogaNode.GetInstanceCount());
|
||||
Assert.AreEqual(configInstanceCount, YogaConfig.GetInstanceCount());
|
||||
YogaNode node = TestRetainConfigForGC2(nodeInstanceCount, configInstanceCount);
|
||||
ForceGC();
|
||||
Assert.IsNotNull(node);
|
||||
Assert.AreEqual(configInstanceCount + 1, YogaConfig.GetInstanceCount());
|
||||
Assert.AreEqual(nodeInstanceCount + 1, YogaNode.GetInstanceCount());
|
||||
node = null;
|
||||
}
|
||||
|
||||
private YogaNode TestRetainConfigForGC2(int nodeInstanceCount, int configInstanceCount)
|
||||
{
|
||||
YogaConfig config = new YogaConfig();
|
||||
Assert.IsNotNull(config);
|
||||
Assert.AreEqual(configInstanceCount + 1, YogaConfig.GetInstanceCount());
|
||||
|
||||
YogaNode node = new YogaNode(config);
|
||||
Assert.IsNotNull(node);
|
||||
Assert.AreEqual(nodeInstanceCount + 1, YogaNode.GetInstanceCount());
|
||||
|
||||
config = null;
|
||||
|
||||
return node;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
@@ -73,25 +73,22 @@ namespace Facebook.Yoga
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException("System.NullReferenceException")]
|
||||
public void TestRemoveAtFromEmpty()
|
||||
{
|
||||
YogaNode parent = new YogaNode();
|
||||
parent.RemoveAt(0);
|
||||
Assert.Throws<NullReferenceException>(() => parent.RemoveAt(0));
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException("System.ArgumentOutOfRangeException")]
|
||||
public void TestRemoveAtOutOfRange()
|
||||
{
|
||||
YogaNode parent = new YogaNode();
|
||||
YogaNode child = new YogaNode();
|
||||
parent.Insert(0, child);
|
||||
parent.RemoveAt(1);
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => parent.RemoveAt(1));
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException("System.InvalidOperationException")]
|
||||
public void TestCannotAddChildToMultipleParents()
|
||||
{
|
||||
YogaNode parent1 = new YogaNode();
|
||||
@@ -99,7 +96,7 @@ namespace Facebook.Yoga
|
||||
YogaNode child = new YogaNode();
|
||||
|
||||
parent1.Insert(0, child);
|
||||
parent2.Insert(0, child);
|
||||
Assert.Throws<InvalidOperationException>(() => parent2.Insert(0, child));
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -113,23 +110,21 @@ namespace Facebook.Yoga
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException("System.InvalidOperationException")]
|
||||
public void TestResetParent()
|
||||
{
|
||||
YogaNode parent = new YogaNode();
|
||||
YogaNode child = new YogaNode();
|
||||
parent.Insert(0, child);
|
||||
parent.Reset();
|
||||
Assert.Throws<InvalidOperationException>(() => parent.Reset());
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException("System.InvalidOperationException")]
|
||||
public void TestResetChild()
|
||||
{
|
||||
YogaNode parent = new YogaNode();
|
||||
YogaNode child = new YogaNode();
|
||||
parent.Insert(0, child);
|
||||
child.Reset();
|
||||
Assert.Throws<InvalidOperationException>(() => child.Reset());
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -169,12 +164,19 @@ namespace Facebook.Yoga
|
||||
return MeasureOutput.Make(123.4f, 81.7f);
|
||||
});
|
||||
node.CalculateLayout();
|
||||
Assert.AreEqual(124.0f, node.LayoutWidth);
|
||||
Assert.AreEqual(82.0f, node.LayoutHeight);
|
||||
|
||||
node = new YogaNode(new YogaConfig{PointScaleFactor = 0});
|
||||
node.SetMeasureFunction((_, width, widthMode, height, heightMode) => {
|
||||
return MeasureOutput.Make(123.4f, 81.7f);
|
||||
});
|
||||
node.CalculateLayout();
|
||||
Assert.AreEqual(123.4f, node.LayoutWidth);
|
||||
Assert.AreEqual(81.7f, node.LayoutHeight);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException("System.InvalidOperationException")]
|
||||
public void TestChildWithMeasureFunc()
|
||||
{
|
||||
YogaNode node = new YogaNode();
|
||||
@@ -182,19 +184,20 @@ namespace Facebook.Yoga
|
||||
return MeasureOutput.Make(100, 150);
|
||||
});
|
||||
YogaNode child = new YogaNode();
|
||||
node.Insert(0, child);
|
||||
Assert.Throws<InvalidOperationException>(() => node.Insert(0, child));
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException("System.InvalidOperationException")]
|
||||
public void TestMeasureFuncWithChild()
|
||||
{
|
||||
YogaNode node = new YogaNode();
|
||||
YogaNode child = new YogaNode();
|
||||
node.Insert(0, child);
|
||||
node.SetMeasureFunction((_, width, widthMode, height, heightMode) => {
|
||||
return MeasureOutput.Make(100, 150);
|
||||
});
|
||||
Assert.Throws<InvalidOperationException>(() =>
|
||||
node.SetMeasureFunction((_, width, widthMode, height, heightMode) => {
|
||||
return MeasureOutput.Make(100, 150);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -245,6 +248,26 @@ namespace Facebook.Yoga
|
||||
Assert.AreEqual(0, child2.LayoutY);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestPrintOneNode()
|
||||
{
|
||||
YogaNode node = new YogaNode();
|
||||
node.Width = 100;
|
||||
node.Height = 120;
|
||||
node.CalculateLayout();
|
||||
Assert.AreEqual("<div layout=\"width: 100; height: 120; top: 0; left: 0;\" style=\"width: 100px; height: 120px; \" ></div>", node.Print());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestPrintWithLogger()
|
||||
{
|
||||
YogaNode node = new YogaNode(new YogaConfig{Logger = (c, n, l, m) => {}});
|
||||
node.Width = 110;
|
||||
node.Height = 105;
|
||||
node.CalculateLayout();
|
||||
Assert.AreEqual("<div layout=\"width: 110; height: 105; top: 0; left: 0;\" style=\"width: 110px; height: 105px; \" ></div>", node.Print());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestPrint()
|
||||
{
|
||||
@@ -260,7 +283,7 @@ namespace Facebook.Yoga
|
||||
parent.Insert(0, child0);
|
||||
parent.Insert(0, child1);
|
||||
parent.CalculateLayout();
|
||||
Assert.AreEqual("{layout: {width: 100, height: 120, top: 0, left: 0}, flexDirection: 'column', alignItems: 'stretch', flexGrow: 0, flexShrink: 0, flexBasis: nan%, overflow: 'visible', width: 100pt, height: 120pt, children: [\n {layout: {width: 35, height: 45, top: 0, left: 0}, flexDirection: 'column', alignItems: 'stretch', flexGrow: 0, flexShrink: 0, flexBasis: nan%, overflow: 'visible', width: 35pt, height: 45pt, },\n {layout: {width: 30, height: 40, top: 45, left: 0}, flexDirection: 'column', alignItems: 'stretch', flexGrow: 0, flexShrink: 0, flexBasis: nan%, overflow: 'visible', width: 30pt, height: 40pt, },\n]},\n", parent.Print());
|
||||
Assert.AreEqual("<div layout=\"width: 100; height: 120; top: 0; left: 0;\" style=\"width: 100px; height: 120px; \" >\n <div layout=\"width: 35; height: 45; top: 0; left: 0;\" style=\"width: 35px; height: 45px; \" ></div>\n <div layout=\"width: 30; height: 40; top: 45; left: 0;\" style=\"width: 30px; height: 40px; \" ></div>\n</div>", parent.Print());
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -306,9 +329,10 @@ namespace Facebook.Yoga
|
||||
Assert.AreEqual(90.Pt(), node4.MaxHeight);
|
||||
}
|
||||
|
||||
private void ForceGC()
|
||||
#if !UNITY_5_4_OR_NEWER
|
||||
public static void ForceGC()
|
||||
{
|
||||
GC.Collect(GC.MaxGeneration);
|
||||
GC.Collect();
|
||||
GC.WaitForPendingFinalizers();
|
||||
}
|
||||
|
||||
@@ -365,6 +389,7 @@ namespace Facebook.Yoga
|
||||
child = null;
|
||||
}
|
||||
|
||||
#if YOGA_ENABLE_GC_TEST
|
||||
[Test]
|
||||
public void TestParentDestructor()
|
||||
{
|
||||
@@ -386,6 +411,7 @@ namespace Facebook.Yoga
|
||||
Assert.AreEqual(instanceCount + 1, YogaNode.GetInstanceCount());
|
||||
parent.Insert(0, child);
|
||||
}
|
||||
#endif
|
||||
|
||||
[Test]
|
||||
public void TestClearWithChildDestructor()
|
||||
@@ -433,6 +459,7 @@ namespace Facebook.Yoga
|
||||
return MeasureOutput.Make(120, 130);
|
||||
});
|
||||
}
|
||||
#endif
|
||||
|
||||
[Test]
|
||||
public void TestLayoutMargin() {
|
||||
|
@@ -24,5 +24,5 @@ ROOT=`buck root|tail -1`
|
||||
DYLIB=`buck targets --show-output $TARGET|tail -1|awk '{print $2}'`
|
||||
cp $ROOT/$DYLIB .
|
||||
|
||||
mcs -debug -t:library -r:$NUNIT/nunit.framework.dll -out:YogaTest.dll *.cs ../../../csharp/Facebook.Yoga/*cs
|
||||
mcs -debug -d:YOGA_ENABLE_GC_TEST -t:library -r:$NUNIT/nunit.framework.dll -out:YogaTest.dll *.cs ../../../csharp/Facebook.Yoga/*cs
|
||||
MONO_PATH=$NUNIT mono --arch=64 --debug $NUNIT/nunit-console.exe YogaTest.dll
|
||||
|
@@ -11,14 +11,14 @@ GEM
|
||||
coffee-script (2.4.1)
|
||||
coffee-script-source
|
||||
execjs
|
||||
coffee-script-source (1.10.0)
|
||||
coffee-script-source (1.12.2)
|
||||
colorator (1.1.0)
|
||||
ethon (0.9.1)
|
||||
ethon (0.10.1)
|
||||
ffi (>= 1.3.0)
|
||||
execjs (2.7.0)
|
||||
faraday (0.9.2)
|
||||
faraday (0.12.0.1)
|
||||
multipart-post (>= 1.2, < 3)
|
||||
ffi (1.9.14)
|
||||
ffi (1.9.18)
|
||||
forwardable-extended (2.6.0)
|
||||
gemoji (2.1.0)
|
||||
github-pages (104)
|
||||
@@ -51,10 +51,10 @@ GEM
|
||||
octokit (~> 4.0)
|
||||
public_suffix (~> 1.4)
|
||||
typhoeus (~> 0.7)
|
||||
html-pipeline (2.4.2)
|
||||
html-pipeline (2.5.0)
|
||||
activesupport (>= 2)
|
||||
nokogiri (>= 1.4)
|
||||
i18n (0.7.0)
|
||||
i18n (0.8.1)
|
||||
jekyll (3.3.0)
|
||||
addressable (~> 2.4)
|
||||
colorator (~> 1.0)
|
||||
@@ -98,7 +98,7 @@ GEM
|
||||
gemoji (~> 2.0)
|
||||
html-pipeline (~> 2.2)
|
||||
jekyll (>= 3.0)
|
||||
json (1.8.3)
|
||||
json (1.8.6)
|
||||
kramdown (1.11.1)
|
||||
liquid (3.0.6)
|
||||
listen (3.0.6)
|
||||
@@ -107,39 +107,36 @@ GEM
|
||||
mercenary (0.3.6)
|
||||
mini_portile2 (2.1.0)
|
||||
minima (2.0.0)
|
||||
minitest (5.9.1)
|
||||
minitest (5.10.1)
|
||||
multipart-post (2.0.0)
|
||||
net-dns (0.8.0)
|
||||
nokogiri (1.6.8.1)
|
||||
nokogiri (1.7.1)
|
||||
mini_portile2 (~> 2.1.0)
|
||||
octokit (4.4.1)
|
||||
sawyer (~> 0.7.0, >= 0.5.3)
|
||||
octokit (4.6.2)
|
||||
sawyer (~> 0.8.0, >= 0.5.3)
|
||||
pathutil (0.14.0)
|
||||
forwardable-extended (~> 2.6)
|
||||
public_suffix (1.5.3)
|
||||
rb-fsevent (0.9.8)
|
||||
rb-inotify (0.9.7)
|
||||
rb-inotify (0.9.8)
|
||||
ffi (>= 0.5.0)
|
||||
rouge (1.11.1)
|
||||
safe_yaml (1.0.4)
|
||||
sass (3.4.22)
|
||||
sawyer (0.7.0)
|
||||
addressable (>= 2.3.5, < 2.5)
|
||||
faraday (~> 0.8, < 0.10)
|
||||
sass (3.4.23)
|
||||
sawyer (0.8.1)
|
||||
addressable (>= 2.3.5, < 2.6)
|
||||
faraday (~> 0.8, < 1.0)
|
||||
terminal-table (1.7.3)
|
||||
unicode-display_width (~> 1.1.1)
|
||||
thread_safe (0.3.5)
|
||||
thread_safe (0.3.6)
|
||||
typhoeus (0.8.0)
|
||||
ethon (>= 0.8.0)
|
||||
tzinfo (1.2.2)
|
||||
tzinfo (1.2.3)
|
||||
thread_safe (~> 0.1)
|
||||
unicode-display_width (1.1.1)
|
||||
unicode-display_width (1.1.3)
|
||||
|
||||
PLATFORMS
|
||||
ruby
|
||||
|
||||
DEPENDENCIES
|
||||
github-pages (~> 104)
|
||||
|
||||
BUNDLED WITH
|
||||
1.13.1
|
||||
|
@@ -4,7 +4,7 @@ This directory will contain the user, feature and API documentation for Yoga. Th
|
||||
|
||||
### Contributing
|
||||
|
||||
See [CONTRIBUTING.md](./CONTRIBUTING.md) for details on how to add or modify content.
|
||||
See [CONTRIBUTING.md](https://github.com/facebook/yoga/blob/master/CONTRIBUTING.md) for details on how to add or modify content.
|
||||
|
||||
### Run the Site Locally
|
||||
|
||||
|
@@ -6,19 +6,79 @@ permalink: /docs/api/android/
|
||||
---
|
||||
|
||||
To include the java bindings and `.so` libraries, add to your build:
|
||||
<script src="https://gist.github.com/rspencer01/e3cb51e789147b359d842aac6fa30f9f.js"></script>
|
||||
|
||||
There is an easy interface to Yoga called `YogaLayout`. This is a view group that lays out its children using Yoga. We recommend looking at the sample app for details on its usage. However, as an overview you can simply define XML layouts such as
|
||||
<script src="https://gist.github.com/rspencer01/c1964b98f0c60de7c49683a049ed0640.js"></script>
|
||||
```java
|
||||
compile 'com.facebook.yoga:yoga:1.5.0'
|
||||
```
|
||||
|
||||
There is an easy interface to Yoga called `YogaLayout`. This is a view group that lays out its children using Yoga. We recommend looking at the sample app for details on its usage. However, as an overview you can simply define XML layouts such as:
|
||||
|
||||
```xml
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<YogaLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:yoga="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
yoga:yg_alignItems="stretch"
|
||||
>
|
||||
<YogaLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/sample_children_background"
|
||||
yoga:yg_marginHorizontal="10dp"
|
||||
yoga:yg_marginTop="5dp"
|
||||
yoga:yg_flexDirection="row"
|
||||
yoga:yg_alignItems="center"
|
||||
>
|
||||
<ImageView
|
||||
android:layout_width="50dp"
|
||||
android:layout_height="50dp"
|
||||
android:src="@drawable/ic_launcher"
|
||||
yoga:yg_flex="0"
|
||||
/>
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/child_1_text"
|
||||
android:textColor="@color/children_text"
|
||||
yoga:yg_flex="1"
|
||||
yoga:yg_marginStart="8dp"
|
||||
/>
|
||||
</YogaLayout>
|
||||
</YogaLayout>
|
||||
```
|
||||
|
||||
Note that there are some caveats, such as requiring the custom `YogaLayoutViewFactory` in order to have tags `YogaLayout` instead of `com.facebook.samples.yoga.YogaLayout`.
|
||||
|
||||
To include this in your project, add to your build:
|
||||
<script src="https://gist.github.com/rspencer01/499a9e02185985bf3167f818d9c3398f.js"></script>
|
||||
|
||||
```java
|
||||
compile 'com.facebook.yoga.android:yoga-layout:1.5.0'
|
||||
```
|
||||
|
||||
## Snapshot releases
|
||||
|
||||
> IMPORTANT: This will break and may set your house on fire. Snapshots are unsigned and automatically published by our CI system. Use them for testing purposes only.
|
||||
|
||||
If you want to live on the bleeding edge, you can use the SNAPSHOT releases
|
||||
which represent the most recent commit on `master` by adding these targets to
|
||||
your gradle config:
|
||||
|
||||
```gradle
|
||||
repositories {
|
||||
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile 'com.facebook.yoga:yoga:1.5.1-SNAPSHOT'
|
||||
compile 'com.facebook.yoga.android:yoga-layout:1.5.1-SNAPSHOT'
|
||||
}
|
||||
```
|
||||
|
||||
## layout\_width and layout\_height
|
||||
|
||||
If either are set to an actual size (in px or dp etc) then this is taken as a default for `yoga:height` or `yoga:width`. Otherwise they are ignored.
|
||||
If either are set to an actual size (in px or dp etc) then this is taken as a default for `yoga:yg_height` or `yoga:ygWidth`. Otherwise they are ignored.
|
||||
|
||||
## VirtualYogaLayout
|
||||
|
||||
@@ -26,11 +86,11 @@ Sometimes you will nest `YogaLayout`s within `YogaLayout`s in order to get your
|
||||
|
||||
## RTL locales
|
||||
|
||||
RTL locales are supported by default. That is, unless you explicitly set the `yoga:direction="ltr|rtl|inherit"` attribute on a view, it will obtain the locale direction _at runtime_. This means that the layout will rearrange properly, even if the locale changes while your app is running!
|
||||
RTL locales are supported by default. That is, unless you explicitly set the `yoga:yg_direction="ltr|rtl|inherit"` attribute on a view, it will obtain the locale direction At runtime_. This means that the layout will rearrange properly, even if the locale changes while your app is running!
|
||||
|
||||
## Attributes
|
||||
|
||||
The list of all attributes can be found in [attrs.xml](https://github.com/facebook/yoga/blob/master/android/sample/res/com/facebook/samples/yoga/res/values/attrs.xml), but logically map from the Yoga properties.
|
||||
The list of all attributes can be found in [attrs.xml](https://github.com/facebook/yoga/blob/master/android/src/main/res/values/attrs.xml), but logically map from the Yoga properties.
|
||||
|
||||
## Auto margins
|
||||
|
||||
|
@@ -10,7 +10,12 @@ permalink: /docs/api/c/
|
||||
|
||||
The following functions control the lifecycle of a `YGNodeRef`.
|
||||
|
||||
<script src="https://gist.github.com/emilsjolander/99e454d04df4765147f407bde131feca.js"></script>
|
||||
```c
|
||||
YGNodeRef YGNodeNew();
|
||||
void YGNodeReset(YGNodeRef node);
|
||||
void YGNodeFree(YGNodeRef node);
|
||||
void YGNodeFreeRecursive(YGNodeRef node);
|
||||
```
|
||||
|
||||
- `YGNodeReset` will reset a node to its initial state so it can be re-used without needing to re-allocate a new node.
|
||||
- `YGNodeFreeRecursive` is mostly used for testing and will free not only the node itself but also its children.
|
||||
@@ -19,19 +24,167 @@ The following functions control the lifecycle of a `YGNodeRef`.
|
||||
|
||||
The following functions help manage the children of a node.
|
||||
|
||||
<script src="https://gist.github.com/emilsjolander/7e162314294087bb78817c064d345afb.js"></script>
|
||||
```c
|
||||
void YGNodeInsertChild(YGNodeRef node, YGNodeRef child, uint32_t index);
|
||||
void YGNodeRemoveChild(YGNodeRef node, YGNodeRef child);
|
||||
YGNodeRef YGNodeGetChild(YGNodeRef node, uint32_t index);
|
||||
uint32_t YGNodeGetChildCount(YGNodeRef node);
|
||||
```
|
||||
|
||||
### Style getters & setters
|
||||
|
||||
The large part of Yoga's API consists of setters and getters for styles. These all follow the same general structure. Bellow are the function and enums used to control the various styles. For an in depth guide to how each style works see the getting started guide.
|
||||
|
||||
<script src="https://gist.github.com/emilsjolander/74913a3326d952ff5a65dabe5ce4baf8.js"></script>
|
||||
```c
|
||||
typedef enum YGDirection {
|
||||
YGDirectionInherit,
|
||||
YGDirectionLTR,
|
||||
YGDirectionRTL,
|
||||
} YGDirection;
|
||||
|
||||
void YGNodeStyleSetDirection(YGNodeRef node, YGDirection direction);
|
||||
YGDirection YGNodeStyleGetDirection(YGNodeRef node);
|
||||
|
||||
typedef enum YGFlexDirection {
|
||||
YGFlexDirectionColumn,
|
||||
YGFlexDirectionColumnReverse,
|
||||
YGFlexDirectionRow,
|
||||
YGFlexDirectionRowReverse,
|
||||
} YGFlexDirection;
|
||||
|
||||
void YGNodeStyleSetFlexDirection(YGNodeRef node,
|
||||
YGFlexDirection flexDirection);
|
||||
YGFlexDirection YGNodeStyleGetFlexDirection(YGNodeRef node);
|
||||
|
||||
typedef enum YGJustify {
|
||||
YGJustifyFlexStart,
|
||||
YGJustifyCenter,
|
||||
YGJustifyFlexEnd,
|
||||
YGJustifySpaceBetween,
|
||||
YGJustifySpaceAround,
|
||||
} YGJustify;
|
||||
|
||||
void YGNodeStyleSetJustifyContent(YGNodeRef node,
|
||||
YGJustify justifyContent);
|
||||
YGJustify YGNodeStyleGetJustifyContent(YGNodeRef node);
|
||||
|
||||
typedef enum YGAlign {
|
||||
YGAlignAuto,
|
||||
YGAlignFlexStart,
|
||||
YGAlignCenter,
|
||||
YGAlignFlexEnd,
|
||||
YGAlignStretch,
|
||||
} YGAlign;
|
||||
|
||||
void YGNodeStyleSetAlignContent(YGNodeRef node, YGAlign alignContent);
|
||||
YGAlign YGNodeStyleGetAlignContent(YGNodeRef node);
|
||||
|
||||
void YGNodeStyleSetAlignItems(YGNodeRef node, YGAlign alignItems);
|
||||
YGAlign YGNodeStyleGetAlignItems(YGNodeRef node);
|
||||
|
||||
void YGNodeStyleSetAlignSelf(YGNodeRef node, YGAlign alignSelf);
|
||||
YGAlign YGNodeStyleGetAlignSelf(YGNodeRef node);
|
||||
|
||||
typedef enum YGPositionType {
|
||||
YGPositionTypeRelative,
|
||||
YGPositionTypeAbsolute,
|
||||
} YGPositionType;
|
||||
|
||||
void YGNodeStyleSetPositionType(YGNodeRef node,
|
||||
YGPositionType positionType);
|
||||
YGPositionType YGNodeStyleGetPositionType(YGNodeRef node);
|
||||
|
||||
typedef enum YGWrap {
|
||||
YGWrapNoWrap,
|
||||
YGWrapWrap,
|
||||
} YGWrap;
|
||||
|
||||
void YGNodeStyleSetFlexWrap(YGNodeRef node, YGWrap flexWrap);
|
||||
YGWrap YGNodeStyleGetFlexWrap(YGNodeRef node);
|
||||
|
||||
typedef enum YGOverflow {
|
||||
YGOverflowVisible,
|
||||
YGOverflowHidden,
|
||||
YGOverflowScroll,
|
||||
} YGOverflow;
|
||||
|
||||
void YGNodeStyleSetOverflow(YGNodeRef node, YGOverflow overflow);
|
||||
YGOverflow YGNodeStyleGetOverflow(YGNodeRef node);
|
||||
|
||||
void YGNodeStyleSetFlex(YGNodeRef node, float flex);
|
||||
|
||||
void YGNodeStyleSetFlexGrow(YGNodeRef node, float flexGrow);
|
||||
float YGNodeStyleGetFlexGrow(YGNodeRef node);
|
||||
|
||||
void YGNodeStyleSetFlexShrink(YGNodeRef node, float flexShrink);
|
||||
float YGNodeStyleGetFlexShrink(YGNodeRef node);
|
||||
|
||||
void YGNodeStyleSetFlexBasis(YGNodeRef node, float flexBasis);
|
||||
float YGNodeStyleGetFlexBasis(YGNodeRef node);
|
||||
|
||||
typedef enum YGEdge {
|
||||
YGEdgeLeft,
|
||||
YGEdgeTop,
|
||||
YGEdgeRight,
|
||||
YGEdgeBottom,
|
||||
YGEdgeStart,
|
||||
YGEdgeEnd,
|
||||
YGEdgeHorizontal,
|
||||
YGEdgeVertical,
|
||||
YGEdgeAll,
|
||||
} YGEdge;
|
||||
|
||||
void YGNodeStyleSetPosition(YGNodeRef node, YGEdge edge, float position);
|
||||
float YGNodeStyleGetPosition(YGNodeRef node, YGEdge edge);
|
||||
|
||||
void YGNodeStyleSetMargin(YGNodeRef node, YGEdge edge, float margin);
|
||||
float YGNodeStyleGetMargin(YGNodeRef node, YGEdge edge);
|
||||
|
||||
void YGNodeStyleSetPadding(YGNodeRef node, YGEdge edge, float padding);
|
||||
float YGNodeStyleGetPadding(YGNodeRef node, YGEdge edge);
|
||||
|
||||
void YGNodeStyleSetBorder(YGNodeRef node, YGEdge edge, float border);
|
||||
float YGNodeStyleGetBorder(YGNodeRef node, YGEdge edge);
|
||||
|
||||
void YGNodeStyleSetWidth(YGNodeRef node, float width);
|
||||
float YGNodeStyleGetWidth(YGNodeRef node);
|
||||
|
||||
void YGNodeStyleSetHeight(YGNodeRef node, float height);
|
||||
float YGNodeStyleGetHeight(YGNodeRef node);
|
||||
|
||||
void YGNodeStyleSetMinWidth(YGNodeRef node, float minWidth);
|
||||
float YGNodeStyleGetMinWidth(YGNodeRef node);
|
||||
|
||||
void YGNodeStyleSetMinHeight(YGNodeRef node, float minHeight);
|
||||
float YGNodeStyleGetMinHeight(YGNodeRef node);
|
||||
|
||||
void YGNodeStyleSetMaxWidth(YGNodeRef node, float maxWidth);
|
||||
float YGNodeStyleGetMaxWidth(YGNodeRef node);
|
||||
|
||||
void YGNodeStyleSetMaxHeight(YGNodeRef node, float maxHeight);
|
||||
float YGNodeStyleGetMaxHeight(YGNodeRef node);
|
||||
|
||||
void YGNodeStyleSetAspectRatio(YGNodeRef node, float aspectRatio);
|
||||
float YGNodeStyleGetAspectRatio(YGNodeRef node);
|
||||
```
|
||||
|
||||
### Layout results
|
||||
|
||||
Once you have set up a tree of nodes with styles you will want to get the result of a layout calculation. Call `YGNodeCalculateLayout` with the desired width and height or `YGUndefined` to perform the layout calculation. Once this function returns the results of the layout calculation is stored on each node. Traverse the tree and retrieve the values from each node.
|
||||
|
||||
<script src="https://gist.github.com/emilsjolander/7c7c9c61b69daff5b925719065fb0dc9.js"></script>
|
||||
```c
|
||||
void YGNodeCalculateLayout(YGNodeRef node,
|
||||
float availableWidth,
|
||||
float availableHeight,
|
||||
YGDirection parentDirection);
|
||||
float YGNodeLayoutGetLeft(YGNodeRef node);
|
||||
float YGNodeLayoutGetTop(YGNodeRef node);
|
||||
float YGNodeLayoutGetRight(YGNodeRef node);
|
||||
float YGNodeLayoutGetBottom(YGNodeRef node);
|
||||
float YGNodeLayoutGetWidth(YGNodeRef node);
|
||||
float YGNodeLayoutGetHeight(YGNodeRef node);
|
||||
YGDirection YGNodeLayoutGetDirection(YGNodeRef node);
|
||||
```
|
||||
|
||||
### Custom measurements
|
||||
|
||||
@@ -41,34 +194,103 @@ Certain nodes need the ability to measure themselves, the most common example is
|
||||
|
||||
> A measure function can only be attached to a leaf node in the hierarchy.
|
||||
|
||||
<script src="https://gist.github.com/emilsjolander/73f9118d8bd27f9cb3744c08f1e53a32.js"></script>
|
||||
```c
|
||||
typedef enum YGMeasureMode {
|
||||
YGMeasureModeUndefined,
|
||||
YGMeasureModeExactly,
|
||||
YGMeasureModeAtMost,
|
||||
} YGMeasureMode;
|
||||
|
||||
typedef struct YGSize {
|
||||
float width;
|
||||
float height;
|
||||
} YGSize;
|
||||
|
||||
typedef YGSize (*YGMeasureFunc)(YGNodeRef node,
|
||||
float width,
|
||||
YGMeasureMode widthMode,
|
||||
float height,
|
||||
YGMeasureMode heightMode);
|
||||
|
||||
void YGNodeSetMeasureFunc(YGNodeRef node, YGMeasureFunc measureFunc);
|
||||
YGMeasureFunc YGNodeGetMeasureFunc(YGNodeRef node);
|
||||
|
||||
void YGNodeMarkDirty(YGNodeRef node);
|
||||
bool YGNodeIsDirty(YGNodeRef node);
|
||||
```
|
||||
|
||||
### Context
|
||||
|
||||
Context is important when integrating Yoga into another layout system. Context allows you to associate another object with a `YGNodeRef`. This context can then be retrieved from a `YGNodeRef` when for example its measure function is called. This is what enables Yoga to rely on the Android and iOS system implementations of text measurement in React Native.
|
||||
|
||||
<script src="https://gist.github.com/emilsjolander/c3d23a1b880d59627e959f3447a9511b.js"></script>
|
||||
```c
|
||||
void YGNodeSetContext(YGNodeRef node, void *context);
|
||||
void *YGNodeGetContext(YGNodeRef node);
|
||||
```
|
||||
|
||||
### Logging
|
||||
|
||||
Yoga will by default log to stdout and stderr. You may however customize this to instead log to your own logger.
|
||||
|
||||
<script src="https://gist.github.com/emilsjolander/b538718ffd7a55efc80845468e0f063e.js"></script>
|
||||
```c
|
||||
typedef enum YGLogLevel {
|
||||
YGLogLevelError,
|
||||
YGLogLevelWarn,
|
||||
YGLogLevelInfo,
|
||||
YGLogLevelDebug,
|
||||
YGLogLevelVerbose,
|
||||
} YGLogLevel;
|
||||
|
||||
typedef int (*YGLogger)(YGLogLevel level, char *format, va_list args);
|
||||
void YGSetLogger(YGLogger logger);
|
||||
void YGLog(YGLogLevel level, char *message, ...);
|
||||
```
|
||||
|
||||
### Experiments
|
||||
|
||||
Yoga has the concept of experiments. An experiment is a feature which is not yet stable. To enable a feature use the following functions. Once a feature has been tested and is ready to be released as a stable API we will remove its feature flag.
|
||||
|
||||
<script src="https://gist.github.com/emilsjolander/002516a55e10947e4bdcf5484eee8745.js"></script>
|
||||
```c
|
||||
typedef enum YGExperimentalFeature {
|
||||
// Current experiments
|
||||
} YGExperimentalFeature;
|
||||
|
||||
void YGSetExperimentalFeatureEnabled(YGExperimentalFeature feature,
|
||||
bool enabled);
|
||||
bool YGIsExperimentalFeatureEnabled(YGExperimentalFeature feature);
|
||||
```
|
||||
|
||||
### Custom allocators
|
||||
|
||||
You may want to swap out the allocator used in Yoga. These functions allow that.
|
||||
|
||||
<script src="https://gist.github.com/emilsjolander/f45053d4f09a9faaf94a8fc071f0224f.js"></script>
|
||||
```c
|
||||
typedef void *(*YGMalloc)(size_t size);
|
||||
typedef void *(*YGCalloc)(size_t count, size_t size);
|
||||
typedef void *(*YGRealloc)(void *ptr, size_t size);
|
||||
typedef void (*YGFree)(void *ptr);
|
||||
|
||||
void YGSetMemoryFuncs(YGMalloc cssMalloc,
|
||||
YGCalloc cssCalloc,
|
||||
YGRealloc cssRealloc,
|
||||
YGFree cssFree);
|
||||
```
|
||||
|
||||
### Printing
|
||||
|
||||
Yoga has some hooks to print debug information while calculating layout. With the printing APIs you can add additional information to a node when it is printed.
|
||||
|
||||
<script src="https://gist.github.com/emilsjolander/c9fbaba914d699ecc91841f4f5515f20.js"></script>
|
||||
```c
|
||||
typedef enum YGPrintOptions {
|
||||
YGPrintOptionsLayout = 1,
|
||||
YGPrintOptionsStyle = 2,
|
||||
YGPrintOptionsChildren = 4,
|
||||
} YGPrintOptions;
|
||||
|
||||
typedef void (*YGPrintFunc)(YGNodeRef node);
|
||||
|
||||
void YGNodeSetPrintFunc(YGNodeRef node, YGPrintFunc printFunc);
|
||||
YGPrintFunc YGNodeGetPrintFunc(YGNodeRef node);
|
||||
|
||||
void YGNodePrint(YGNodeRef node, YGPrintOptions options);
|
||||
```
|
||||
|
@@ -10,25 +10,176 @@ permalink: /docs/api/csharp/
|
||||
|
||||
Create a `YogaNode` via its default constructor or the static `Create()` builder method and use `Reset` if you want to pool and re-use nodes. The native memory of a `YogaNode` will automatically be freed when the node is garbage collected.
|
||||
|
||||
<script src="https://gist.github.com/emilsjolander/ce73212ee5fdb543d463822c3dd172b4.js"></script>
|
||||
```csharp
|
||||
YogaNode();
|
||||
void Reset();
|
||||
|
||||
static YogaNode Create(
|
||||
YogaDirection? styleDirection = null,
|
||||
YogaFlexDirection? flexDirection = null,
|
||||
YogaJustify? justifyContent = null,
|
||||
YogaAlign? alignContent = null,
|
||||
YogaAlign? alignItems = null,
|
||||
YogaAlign? alignSelf = null,
|
||||
YogaPositionType? positionType = null,
|
||||
YogaWrap? wrap = null,
|
||||
YogaOverflow? overflow = null,
|
||||
float? flex = null,
|
||||
float? flexGrow = null,
|
||||
float? flexShrink = null,
|
||||
float? flexBasis = null,
|
||||
Spacing position = null,
|
||||
Spacing margin = null,
|
||||
Spacing padding = null,
|
||||
Spacing border = null,
|
||||
float? Width = null,
|
||||
float? Height = null,
|
||||
float? MaxWidth = null,
|
||||
float? MaxHeight = null,
|
||||
float? MinWidth = null,
|
||||
float? MinHeight = null);
|
||||
```
|
||||
|
||||
### Children
|
||||
|
||||
The following methods help manage the children of a node.
|
||||
|
||||
<script src="https://gist.github.com/emilsjolander/2b0ea738d3c24644fa98910b276620e4.js"></script>
|
||||
```csharp
|
||||
int Count { get };
|
||||
YogaNode this[int index] { get };
|
||||
void Insert(int index, YogaNode node);
|
||||
void RemoveAt(int index);
|
||||
void Clear();
|
||||
int IndexOf(YogaNode node);
|
||||
```
|
||||
|
||||
### Style getters & setters
|
||||
|
||||
The large part of Yoga's API consists of properties, setters, and getters for styles. These all follow the same general structure. Bellow are the function and enums used to control the various styles. For an in depth guide to how each style works see the getting started guide.
|
||||
|
||||
<script src="https://gist.github.com/emilsjolander/a84208768e0006b8421a322c40f98539.js"></script>
|
||||
```csharp
|
||||
enum YogaDirection
|
||||
{
|
||||
Inherit,
|
||||
LTR,
|
||||
RTL,
|
||||
}
|
||||
|
||||
YogaDirection StyleDirection {get, set};
|
||||
|
||||
enum YogaFlexDirection
|
||||
{
|
||||
Column,
|
||||
ColumnReverse,
|
||||
Row,
|
||||
RowReverse,
|
||||
}
|
||||
|
||||
YogaFlexDirection FlexDirection {get, set};
|
||||
|
||||
enum YogaJustify
|
||||
{
|
||||
FlexStart,
|
||||
Center,
|
||||
FlexEnd,
|
||||
SpaceBetween,
|
||||
SpaceAround,
|
||||
}
|
||||
|
||||
YogaJustify JustifyContent {get, set};
|
||||
|
||||
enum YogaAlign
|
||||
{
|
||||
Auto,
|
||||
FlexStart,
|
||||
Center,
|
||||
FlexEnd,
|
||||
Stretch,
|
||||
}
|
||||
|
||||
YogaAlign AlignItems {get, set};
|
||||
YogaAlign AlignSelf {get, set};
|
||||
YogaAlign AlignContent {get, set};
|
||||
|
||||
enum YogaPositionType
|
||||
{
|
||||
Relative,
|
||||
Absolute,
|
||||
}
|
||||
|
||||
YogaPositionType PositionType {get, set};
|
||||
|
||||
enum YogaWrap
|
||||
{
|
||||
NoWrap,
|
||||
Wrap,
|
||||
}
|
||||
|
||||
YogaWrap Wrap {get, set};
|
||||
|
||||
enum YogaOverflow
|
||||
{
|
||||
Visible,
|
||||
Hidden,
|
||||
Scroll,
|
||||
}
|
||||
|
||||
YogaOverflow Overflow {get, set};
|
||||
|
||||
float Flex {set};
|
||||
float FlexGrow {get, set};
|
||||
float FlexShrink {get, set};
|
||||
float FlexBasis {get, set};
|
||||
|
||||
enum YogaEdge
|
||||
{
|
||||
Left,
|
||||
Top,
|
||||
Right,
|
||||
Bottom,
|
||||
Start,
|
||||
End,
|
||||
Horizontal,
|
||||
Vertical,
|
||||
All,
|
||||
}
|
||||
|
||||
float GetMargin(YogaEdge edge);
|
||||
void SetMargin(YogaEdge edge, float margin);
|
||||
|
||||
float GetPadding(YogaEdge edge);
|
||||
void SetPadding(YogaEdge edge, float padding);
|
||||
|
||||
float GetBorder(YogaEdge edge);
|
||||
void SetBorder(YogaEdge edge, float border);
|
||||
|
||||
float GetPosition(YogaEdge edge);
|
||||
void SetPosition(YogaEdge edge, float position);
|
||||
|
||||
float Width {get, set};
|
||||
float Height {get, set};
|
||||
|
||||
float MaxWidth {get, set};
|
||||
float MinWidth {get, set};
|
||||
|
||||
float MaxHeight {get, set};
|
||||
float MinHeight {get, set};
|
||||
|
||||
float AspectRatio {get, set};
|
||||
```
|
||||
|
||||
### Layout results
|
||||
|
||||
Once you have set up a tree of nodes with styles you will want to get the result of a layout calculation. Call `CalculateLayout()` perform layout calculation. Once this function returns the results of the layout calculation is stored on each node. Traverse the tree and retrieve the values from each node.
|
||||
|
||||
<script src="https://gist.github.com/emilsjolander/b50acf9fc0877affeb0fc3e55b5c6b4c.js"></script>
|
||||
```csharp
|
||||
void CalculateLayout();
|
||||
float LayoutX {get};
|
||||
float LayoutY {get};
|
||||
float LayoutWidth {get};
|
||||
float LayoutHeight {get};
|
||||
YogaDirection LayoutDirection {get};
|
||||
```
|
||||
|
||||
### Custom measurements
|
||||
|
||||
@@ -38,16 +189,53 @@ Certain nodes need to ability to measure themselves, the most common example is
|
||||
|
||||
> A measure function can only be attached to a leaf node in the hierarchy.
|
||||
|
||||
<script src="https://gist.github.com/emilsjolander/57178307f515e5ea1ccfbedc05df429b.js"></script>
|
||||
```csharp
|
||||
enum YogaMeasureMode
|
||||
{
|
||||
Undefined,
|
||||
Exactly,
|
||||
AtMost,
|
||||
}
|
||||
|
||||
public delegate long MeasureFunction(
|
||||
YogaNode node,
|
||||
float width,
|
||||
YogaMeasureMode widthMode,
|
||||
float height,
|
||||
YogaMeasureMode heightMode);
|
||||
|
||||
class MeasureOutput
|
||||
{
|
||||
public static long Make(int width, int height);
|
||||
}
|
||||
|
||||
void SetMeasureFunction(MeasureFunction measureFunction);
|
||||
bool IsMeasureDefined();
|
||||
|
||||
bool IsDirty {get};
|
||||
void MarkDirty();
|
||||
```
|
||||
|
||||
### Data
|
||||
|
||||
Data is important when integrating Yoga into another layout system. Data allows you to associate another object with a `YogaNode`. This data can then be retrieved from a `YogaNode` when for example its measure function is called. This is what enables Yoga to rely on the Android system implementations of text measurement in React Native.
|
||||
|
||||
<script src="https://gist.github.com/emilsjolander/c099f826623d70fd6bf7dece14e76700.js"></script>
|
||||
```csharp
|
||||
object Data {get, set}
|
||||
```
|
||||
|
||||
### Experiments
|
||||
|
||||
Yoga has the concept of experiments. An experiment is a feature which is not yet stable. To enable a feature use the following functions. Once a feature has been tested and is ready to be released as a stable API we will remove its feature flag.
|
||||
|
||||
<script src="https://gist.github.com/emilsjolander/97b2500918687826cdfe9429638f2d57.js"></script>
|
||||
```csharp
|
||||
enum YogaExperimentalFeature {
|
||||
// Current experiments
|
||||
}
|
||||
|
||||
static void setExperimentalFeatureEnabled(
|
||||
YogaExperimentalFeature feature,
|
||||
boolean enabled);
|
||||
static boolean isExperimentalFeatureEnabled(
|
||||
YogaExperimentalFeature feature);
|
||||
```
|
||||
|
@@ -10,25 +10,166 @@ permalink: /docs/api/java/
|
||||
|
||||
Create a `YogaNode` via its default constructor and use `reset` if you want to pool and re-use nodes. The native memory of a `YogaNode` will automatically be freed when the node is garbage collected.
|
||||
|
||||
<script src="https://gist.github.com/emilsjolander/8775de8c778eb99a05a38e8257f0b4a7.js"></script>
|
||||
```java
|
||||
YogaNode();
|
||||
void reset();
|
||||
```
|
||||
|
||||
### Children
|
||||
|
||||
The following methods help manage the children of a node.
|
||||
|
||||
<script src="https://gist.github.com/emilsjolander/5d1c64d8d3be7f7942435c4f5bec45a5.js"></script>
|
||||
```java
|
||||
int getChildCount();
|
||||
YogaNodeType getChildAt(int i);
|
||||
void addChildAt(YogaNodeType child, int i);
|
||||
YogaNodeType removeChildAt(int i);
|
||||
YogaNodeType getParent();
|
||||
int indexOf(YogaNodeType child);
|
||||
```
|
||||
|
||||
### Style getters & setters
|
||||
|
||||
The large part of Yoga's API consists of setters and getters for styles. These all follow the same general structure. Bellow are the function and enums used to control the various styles. For an in depth guide to how each style works see the getting started guide.
|
||||
|
||||
<script src="https://gist.github.com/emilsjolander/f94ca2aa69441a3060a7c9f5126f202f.js"></script>
|
||||
```java
|
||||
enum YogaDirection {
|
||||
INHERIT,
|
||||
LTR,
|
||||
RTL
|
||||
}
|
||||
|
||||
YogaDirection getStyleDirection();
|
||||
void setDirection(YogaDirection direction);
|
||||
|
||||
enum YogaFlexDirection {
|
||||
COLUMN,
|
||||
COLUMN_REVERSE,
|
||||
ROW,
|
||||
ROW_REVERSE
|
||||
}
|
||||
|
||||
YogaFlexDirection getFlexDirection();
|
||||
void setFlexDirection(YogaFlexDirection flexDirection);
|
||||
|
||||
enum YogaJustify {
|
||||
FLEX_START,
|
||||
CENTER,
|
||||
FLEX_END,
|
||||
SPACE_BETWEEN,
|
||||
SPACE_AROUND
|
||||
}
|
||||
|
||||
YogaJustify getJustifyContent();
|
||||
void setJustifyContent(YogaJustify justifyContent);
|
||||
|
||||
enum YogaAlign {
|
||||
AUTO,
|
||||
FLEX_START,
|
||||
CENTER,
|
||||
FLEX_END,
|
||||
STRETCH
|
||||
}
|
||||
|
||||
YogaAlign getAlignItems();
|
||||
void setAlignItems(YogaAlign alignItems);
|
||||
|
||||
YogaAlign getAlignSelf();
|
||||
void setAlignSelf(YogaAlign alignSelf);
|
||||
|
||||
YogaAlign getAlignContent();
|
||||
void setAlignContent(YogaAlign alignContent);
|
||||
|
||||
enum YogaPositionType {
|
||||
RELATIVE,
|
||||
ABSOLUTE
|
||||
}
|
||||
|
||||
YogaPositionType getPositionType();
|
||||
void setPositionType(YogaPositionType positionType);
|
||||
|
||||
enum YogaWrap {
|
||||
NO_WRAP,
|
||||
WRAP
|
||||
}
|
||||
|
||||
void setWrap(YogaWrap flexWrap);
|
||||
|
||||
enum YogaOverflow {
|
||||
VISIBLE,
|
||||
HIDDEN,
|
||||
SCROLL
|
||||
}
|
||||
|
||||
YogaOverflow getOverflow();
|
||||
void setOverflow(YogaOverflow overflow);
|
||||
|
||||
void setFlex(float flex);
|
||||
float getFlexGrow();
|
||||
void setFlexGrow(float flexGrow);
|
||||
float getFlexShrink();
|
||||
void setFlexShrink(float flexShrink);
|
||||
float getFlexBasis();
|
||||
void setFlexBasis(float flexBasis);
|
||||
|
||||
enum YogaEdge {
|
||||
LEFT,
|
||||
TOP,
|
||||
RIGHT,
|
||||
BOTTOM,
|
||||
START,
|
||||
END,
|
||||
HORIZONTAL,
|
||||
VERTICAL,
|
||||
ALL
|
||||
}
|
||||
|
||||
float getMargin(YogaEdge edge);
|
||||
void setMargin(YogaEdge edge, float margin);
|
||||
|
||||
float getPadding(YogaEdge edge);
|
||||
void setPadding(YogaEdge edge, float padding);
|
||||
|
||||
float getBorder(YogaEdge edge);
|
||||
void setBorder(YogaEdge edge, float border);
|
||||
|
||||
float getPosition(YogaEdge edge);
|
||||
void setPosition(YogaEdge edge, float position);
|
||||
|
||||
float getWidth();
|
||||
void setWidth(float width);
|
||||
|
||||
float getHeight();
|
||||
void setHeight(float height);
|
||||
|
||||
float getMaxWidth();
|
||||
void setMaxWidth(float maxWidth);
|
||||
|
||||
float getMinWidth();
|
||||
void setMinWidth(float minWidth);
|
||||
|
||||
float getMaxHeight();
|
||||
void setMaxHeight(float maxHeight);
|
||||
|
||||
float getMinHeight();
|
||||
void setMinHeight(float minHeight);
|
||||
|
||||
float getAspectRatio();
|
||||
void setAspectRatio(float aspectRatio);
|
||||
```
|
||||
|
||||
### Layout results
|
||||
|
||||
Once you have set up a tree of nodes with styles you will want to get the result of a layout calculation. Call `calculateLayout()` perform layout calculation. Once this function returns the results of the layout calculation is stored on each node. Traverse the tree and retrieve the values from each node.
|
||||
|
||||
<script src="https://gist.github.com/emilsjolander/613a80ae11abce423a4806521e1e315b.js"></script>
|
||||
```java
|
||||
void calculateLayout();
|
||||
float getLayoutX();
|
||||
float getLayoutY();
|
||||
float getLayoutWidth();
|
||||
float getLayoutHeight();
|
||||
YogaDirection getLayoutDirection();
|
||||
```
|
||||
|
||||
### Custom measurements
|
||||
|
||||
@@ -38,22 +179,74 @@ Certain nodes need to ability to measure themselves, the most common example is
|
||||
|
||||
> A measure function can only be attached to a leaf node in the hierarchy.
|
||||
|
||||
<script src="https://gist.github.com/emilsjolander/70fd958b87647abbba604956709a9026.js"></script>
|
||||
```java
|
||||
enum YogaMeasureMode {
|
||||
UNDEFINED,
|
||||
EXACTLY,
|
||||
AT_MOST
|
||||
}
|
||||
|
||||
interface YogaMeasureFunction {
|
||||
long measure(
|
||||
YogaNode node,
|
||||
float width,
|
||||
YogaMeasureMode widthMode,
|
||||
float height,
|
||||
YogaMeasureMode heightMode);
|
||||
}
|
||||
|
||||
class YogaMeasureOutput {
|
||||
static long make(int width, int height);
|
||||
}
|
||||
|
||||
void setMeasureFunction(YogaMeasureFunction measureFunction);
|
||||
boolean isMeasureDefined();
|
||||
|
||||
boolean isDirty();
|
||||
void dirty();
|
||||
```
|
||||
|
||||
### Data
|
||||
|
||||
Data is important when integrating Yoga into another layout system. Data allows you to associate another object with a `YogaNode`. This data can then be retrieved from a `YogaNode` when for example its measure function is called. This is what enables Yoga to rely on the Android system implementations of text measurement in React Native.
|
||||
|
||||
<script src="https://gist.github.com/emilsjolander/3f10f3fa91120960b71783780f528973.js"></script>
|
||||
```java
|
||||
void setData(Object data);
|
||||
Object getData();
|
||||
```
|
||||
|
||||
### Logging
|
||||
|
||||
Yoga will by default log to stdout and stderr (or logcat on Android). You may however customize this to instead log to your own logger.
|
||||
|
||||
<script src="https://gist.github.com/emilsjolander/6d012f5d48be0e98b7f9c2225c358f6e.js"></script>
|
||||
```java
|
||||
enum YogaLogLevel {
|
||||
ERROR,
|
||||
WARN,
|
||||
INFO,
|
||||
DEBUG,
|
||||
VERBOSE
|
||||
}
|
||||
|
||||
interface YogaLogger {
|
||||
void log(YogaLogLevel level, String message);
|
||||
}
|
||||
|
||||
void setLogger(YogaLogger logger);
|
||||
```
|
||||
|
||||
### Experiments
|
||||
|
||||
Yoga has the concept of experiments. An experiment is a feature which is not yet stable. To enable a feature use the following functions. Once a feature has been tested and is ready to be released as a stable API we will remove its feature flag.
|
||||
|
||||
<script src="https://gist.github.com/emilsjolander/97b2500918687826cdfe9429638f2d57.js"></script>
|
||||
```java
|
||||
enum YogaExperimentalFeature {
|
||||
// Current experiments
|
||||
}
|
||||
|
||||
static void setExperimentalFeatureEnabled(
|
||||
YogaExperimentalFeature feature,
|
||||
boolean enabled);
|
||||
static boolean isExperimentalFeatureEnabled(
|
||||
YogaExperimentalFeature feature);
|
||||
```
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user