Compare commits

..

92 Commits

Author SHA1 Message Date
Pascal Hartig
8a65d8b6dc Release GitHub actions workflow (#1088)
Summary: Pull Request resolved: https://github.com/facebook/yoga/pull/1088

Reviewed By: mweststrate

Differential Revision: D28604872

Pulled By: passy

fbshipit-source-id: e77578d44557420be9b782dc90f047af697b7cb9
2021-05-21 11:41:13 -07:00
Pascal Hartig
0fcef77d7b Maven release docs (#1087)
Summary:
*Context: The Yoga OSS build has not been given a lot of attention over the past couple of years and is in serious disrepair. I'll try to get the release pipeline going again to publish to Maven Central as JCenter is shutting down. A bunch of intermediate commits may still have broken builds but will be inching closer to a working one.*

Adds some docs on how to use the release workflow.

Pull Request resolved: https://github.com/facebook/yoga/pull/1087

Reviewed By: priteshrnandgaonkar

Differential Revision: D28604686

Pulled By: passy

fbshipit-source-id: 44cac2cd0593a4f71d80df1ec5324c3c27fbe888
2021-05-21 11:41:13 -07:00
Pascal Hartig
e3a59aa50e Maven central publish (#1086)
Summary:
Sets up the plugins necessary to publish to Maven Central.

Pull Request resolved: https://github.com/facebook/yoga/pull/1086

Test Plan: ./gradlew publishToMavenLocal -PRELEASE_SIGNING_ENABLED=false

Reviewed By: mweststrate

Differential Revision: D28604529

Pulled By: passy

fbshipit-source-id: 2c35b94ce0e254bc7a8bc80e449ac5dadb5def38
2021-05-21 11:41:12 -07:00
Pascal Hartig
13e079e8f3 Upgrade Gradle setup (#1084)
Summary:
Trying to dust off the build setup and make it work again with a modern Android Studio / JVM.

Removing all JCenter setup, too, as this is no longer supported.

Pull Request resolved: https://github.com/facebook/yoga/pull/1084

Test Plan:
`./gradlew :yoga-layout:assembleDebug` works already.
Looking if CI here likes this.

Reviewed By: mweststrate

Differential Revision: D28602272

Pulled By: passy

fbshipit-source-id: 0cb86f548cc6366ccefcc92c185d6e7772e75547
2021-05-21 11:15:18 -07:00
Pascal Hartig
508f4eacdf Fix env setting and Android setup (#1085)
Summary:
*Context: The Yoga OSS build has not been given a lot of attention over the past couple of years and is in serious disrepair. I'll try to get the release pipeline going again to publish to Maven Central as JCenter is shutting down. A bunch of intermediate commits may still have broken builds but will be inching closer to a working one.*

The current way env variables are set is no longer supported for security reasons: https://github.blog/changelog/2020-10-01-github-actions-deprecating-set-env-and-add-path-commands/. The manual Android setup is also quite tricky to maintain and can mostly be done through GitHub Actions itself.

Please note that the actual build is still failing but that's because we're so far behind with the setup here that the Gradle version no longer works on a modern JVM. I'll fix that in subsequent diffs.

Pull Request resolved: https://github.com/facebook/yoga/pull/1085

Test Plan: CI

Reviewed By: mweststrate

Differential Revision: D28602084

Pulled By: passy

fbshipit-source-id: e334ed92d16a9baa185a84b23bb62801399e5650
2021-05-21 10:11:37 -07:00
Andres Suarez
a999150c19 Apply clang-format
Reviewed By: igorsugak

Differential Revision: D28477074

fbshipit-source-id: f15dfc45b9fb30c661ebe2899cd882676d0fdf2a
2021-05-20 21:24:14 -07:00
Aditya Sharat
cbf6495d66 Refactor YogaNode.Inputs freeze API
Summary:
`InternalNode` will eventually not have a pointer to its parent. This diff removes one of the usages of the `InternalNode#getParent()` API. `InternalNode` will also not host the `YogaNode` eventually; so this diff also removes one of the usages of the `InternalNode#getYogaNode()` api.

Now the `Inputs#freeze` api will pass the parent's `YogaNode` and the `YogaNode` of the node (this) being measured.

Changelog: [Internal] Passes The YogaNode and parent YogaNode in the Inputs.freeze API

Reviewed By: SidharthGuglani

Differential Revision: D27240229

fbshipit-source-id: efc4ec3249a963c3181111f9b989d8ed9e17feb4
2021-03-30 05:42:09 -07:00
Aditya Sharat
07eaeea7a4 Create YogaProps Interface
Summary:
Create YogaProps Interface; this interface represents the inputs to YogaNode for layout calculation.

Changelog: [Internal] Create YogaProps Interface; this interface represents the inputs to YogaNode for layout calculation.

Reviewed By: mihaelao

Differential Revision: D27229274

fbshipit-source-id: 5205caf2384661369d7a2d7e7f3e49ff831a1c92
2021-03-26 10:05:14 -07:00
Altaibayar Tseveenbayar
638690255c Yoga set as a static library also for debug+release builds in x64
Summary: Yoga set as a static library also for debug+release builds in x64

Reviewed By: SidharthGuglani

Differential Revision: D27230019

fbshipit-source-id: d77e2c4130cd8303d1585723bfad927b9ddba23e
2021-03-22 07:43:09 -07:00
Altaibayar Tseveenbayar
6c2ba945be Making yoga by default a static library
Summary: We are linking yoga as a static library in most of the places

Reviewed By: SidharthGuglani

Differential Revision: D27228933

fbshipit-source-id: 725d6551198c96925ae80b3a62ef9737ee7e3052
2021-03-22 04:32:44 -07:00
Altaibayar Tseveenbayar
db6be5286e C4244 possible precision loss warning fix
Summary:
Fixing `warning C4244: 'argument': conversion from 'double' to 'float', possible loss of data`

Changelog: [Internal]

Reviewed By: SidharthGuglani

Differential Revision: D27132355

fbshipit-source-id: 55ff35be368ef4f6093865eb88c17e753250d179
2021-03-19 19:23:54 -07:00
Altaibayar Tseveenbayar
67b6c24d7b Yoga Visual Studio project file fix
Summary: Yoga Visual Studio project file was outdated. Made it back working/compilable

Reviewed By: Andrey-Mishanin

Differential Revision: D27138942

fbshipit-source-id: 5d57e61dbb415db54e255e148739c2e670f3bd23
2021-03-18 03:44:00 -07:00
Pieter De Baets
b2095801ba Simplify YGNodeEmptyContainer / YGNodeWithMeasureFunc / YGNodeFixedSize
Summary:
These methods are only ever called just after setting the various YGStyle props. Therefore we can read any padding / margin / border state from there rather than recalculating it.

Changelog: [Internal]

Reviewed By: SidharthGuglani

Differential Revision: D27010098

fbshipit-source-id: a33f879b25c54cfdb0ffc724b6aa325858e97df5
2021-03-15 16:54:58 -07:00
Pieter De Baets
e87f429703 Simplify YGNodeCalculateAvailableInnerDim
Summary:
Avoid recalculating margin and padding by pre-subtracting the margin from `availableWidth` and inlining the calculation of `paddingAndBorderAxisCross`.

Changelog: [Internal]

Reviewed By: SidharthGuglani

Differential Revision: D27010094

fbshipit-source-id: afc3cf251a0306b9e5d7f0dc6856feee8d1dca6e
2021-03-15 16:54:58 -07:00
Pieter De Baets
41384fab7b Optimize edge value resolution
Summary:
Noticed in simpleperf this was a very hot method, showing 8ms spent in these methods in our sample application. By splitting the method out in a horizontal and vertical variant we can simplify cases enormously and check for begin/end in one go.

Changelog: [Internal]

Reviewed By: SidharthGuglani

Differential Revision: D27010008

fbshipit-source-id: 22fed58c7476e1d716b0191b55997c7a06e63223
2021-03-15 16:54:55 -07:00
Eric Rozell
342aebe1d7 Fixes layout of nodes with YGDisplayNone and YGPositionTypeAbsolute (#1068)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1068

There is an issue in react-native when the Yoga node position type is set to absolute and display: none is set where the node layout calculation gives the absolute dimensions, rather than the expected 0 x 0.

Here are some OSS issues tracking this:
https://github.com/facebook/react-native/issues/18415
https://github.com/microsoft/react-native-windows/issues/7289

## Changelog

[General] [Fix] - Fixes layout of nodes with YGDisplayNone and YGPositionTypeAbsolute

Reviewed By: Andrey-Mishanin

Differential Revision: D26849307

fbshipit-source-id: 197618aa3c4e1b3b7efeba7ea4efd30b2d1c982d
2021-03-10 13:10:32 -08:00
Andrew Coates
1745c23a12 Fix various C++ warnings (#31002)
Summary:
Fix warnings about implicit type truncation.

## Changelog

[Internal] [Fixed] - Fix various C++ warnings

Pull Request resolved: https://github.com/facebook/react-native/pull/31002

Test Plan:
Almost all the changes here are simply making explicit conversions which are already occurring.  With the exception of a couple of constants being changed from doubles to floats.

With these changes I am able to remove a bunch of warning suppressions in react-native-windows.

Reviewed By: shergin

Differential Revision: D26900502

Pulled By: rozele

fbshipit-source-id: d5e415282815c2212a840a863713287bbf118c10
2021-03-10 12:38:12 -08:00
Stiopa Koltsov
ccdea0f31b xplat: switch random files to Starlark
Summary:
We need to get rid of all `# BUILD FILE SYNTAX: PYTHON_DSL` to disable hybrid parser after we make Starlark default everywhere.

This is first bunch of changes.

Reviewed By: mzlee

Differential Revision: D26727784

fbshipit-source-id: 05c5f4d039feb4ce06169ac6d2fc5c49711125cd
2021-03-01 13:15:11 -08:00
Sidharth Guglani
c1a28f3f54 Add back snapshot in version for next release
Summary: Changelog: [Internal][Yoga] version bump

Reviewed By: pasqualeanatriello

Differential Revision: D26664063

fbshipit-source-id: ceb8d31a99f85db7d1fde20bd77584a537d356c6
2021-02-25 06:36:06 -08:00
Sidharth Guglani
0429704d5e version bump
Reviewed By: pasqualeanatriello

Differential Revision: D26664041

fbshipit-source-id: 5a4d0d176074c8831dd18681993463fe25e2642f
2021-02-25 06:36:05 -08:00
Sidharth Guglani
36e70c9ca0 Fix Yoga test
Summary: Changelog: [Internal][Yoga] Fixed unit test for default yoga style property

Reviewed By: pasqualeanatriello

Differential Revision: D26664040

fbshipit-source-id: 9c0af4e846ead3d90c75753e836570ccac760178
2021-02-25 06:36:02 -08:00
Aditya Sharat
de36e85004 Adds InternalNode#freeze() API
Summary:
Litho needs a new API which is called immediately before yoga begins layout calculations so that the InternalNode gets the opportunity to finalise itself; i.e. perform the last mutations and in effect avoid any more mutations to the hierarchy.

See D26373731 where the mutations from `Layout#collectResults` is moved back into the InternalNode.

Changelog: [Internal]  Adds new API to YogaNodeJNIBase

Reviewed By: SidharthGuglani

Differential Revision: D26373730

fbshipit-source-id: 471346d3444986ada91e86c95f5f9fb98bcd2fa6
2021-02-16 10:19:23 -08:00
Ruslan Serebriakov
651c527e94 CKDimension
Summary:
[rsrbk@devvm3461.lla0 /data/users/rsrbk/fbsource/fbobjc] fastmod --accept-all CKRelativeDimension RCRelativeDimension
[rsrbk@devvm3461.lla0 /data/users/rsrbk/fbsource/fbobjc] fastmod --accept-all CKRelativeSize RCRelativeSize
[rsrbk@devvm3461.lla0 /data/users/rsrbk/fbsource/fbobjc] fastmod --accept-all ComponentKit/RCDimension.h RenderCore/RCDimension.h

Reviewed By: kfirapps

Differential Revision: D26228615

fbshipit-source-id: 9c06128b324e1c6ece6fc21fbab1c041e5f5825a
2021-02-11 10:39:22 -08:00
Sidharth Guglani
2cb46cf3e2 instance of checks for YogaNodeJniBase
Summary:
Changelog:
[Internal][Yoga] - Added instance of checks in `YogaNodeJNIBase` class to prevent `ClassCastException`s. This was happening for some NT android tests - Mocked Yoga Node object was being passed in the `addChildAt` api

Stack Trace of exception
    java.lang.ClassCastException: com.facebook.yoga.YogaNode$MockitoMock$1408896622 cannot be cast to com.facebook.yoga.YogaNodeJNIBase
	at com.facebook.yoga.YogaNodeJNIBase.addChildAt(YogaNodeJNIBase.java:86)
	at com.facebook.litho.DefaultInternalNode.addChildAt(DefaultInternalNode.java:220)
	at com.facebook.litho.DefaultInternalNode.child(DefaultInternalNode.java:377)
	at com.facebook.litho.DefaultInternalNode.child(DefaultInternalNode.java:360)
	at com.facebook.litho.Column.resolve(Column.java:118)
	at com.facebook.litho.Layout.create(Layout.java:172)

Reviewed By: Andrey-Mishanin

Differential Revision: D26114992

fbshipit-source-id: 774a689609e67f9244b81c6788b62cd61cd96d14
2021-02-05 03:42:10 -08:00
Andres Suarez
584dfe961e Apply clang-format update fixes
Reviewed By: igorsugak

Differential Revision: D25861849

fbshipit-source-id: 840dc1061e557717c7f9ffcccbc09c24b96b78e0
2021-01-10 10:05:56 -08:00
Panagiotis Vekris
a38ec3d7a4 pin "classic" roots to v0.140
Summary:
In Flow v0.143 types-first will become the only supported mode in Flow.
As such the `types_first` configuration option will become invalid. To
prevent breaking roots that have `types_first=false` set and are **unversioned**,
this diff pins their version to v0.140, which is the last released version in fbsource.

## Repro

First compute the list of all `.flowconfig`s:
```
zbgf '.flowconfig$' | grep -v '^fbsource/fbcode/flow' | grep -v 'Binary file' | awk -F':' '{ print $1 }' | sort -u > all-flowconfigs.txt
```
Compute `.flowconfig`s that don’t have a version:
```
zbgs -f '\.flowconfig' '[version]' |  grep -v '^fbsource/fbcode/flow'  | grep -v 'Binary file' | awk -F':' '{ print $1 }' | sort -u > versioned-flowconfigs.txt
comm -23 all-flowconfigs.txt versioned-flowconfigs.txt > unversioned-flowconfigs.txt
```
Compute `.flowconfig`s that have `types_first=false`:
```
zbgr -f '\.flowconfig' '^types_first=false$' |  grep -v '^fbsource/fbcode/flow'  | grep -v 'Binary file' | awk -F':' '{ print $1 }' | sort -u > types_first-false-flowconfigs.txt
```
**and** no pinned version:
```
comm -12 unversioned-flowconfigs.txt types_first-false-flowconfigs.txt | grep 'fbsource' > pin-version-flowconfigs.txt
```
Update the `.flowconfig`s:
```
cat ~/scratch/flowconfigs/pin-version-flowconfigs-fbsource.txt | xargs -I{} bash -c 'printf "\n[version]\n^0.140.0\n" >> {}'
```

Reviewed By: mroch

Differential Revision: D25771452

fbshipit-source-id: 876d6310e4e1aafb81d3ef3051f4e9e9e838a633
2021-01-04 21:06:15 -08:00
Ron Edelstein
b043669972 Explicitly set autoglob (long tail)
Reviewed By: fbanurag, strulovich

Differential Revision: D25620908

fbshipit-source-id: 1dd737d451ddfd07baa427902bdf1c96d7e67e64
2020-12-17 19:34:48 -08:00
Kris Georges
e65b1ef654 Fix Yoga Playground website Litho codegen bugs
Summary:
Yoga Playground website

changing direction results in no change to Litho code because of this typo

Reviewed By: SidharthGuglani

Differential Revision: D24818769

fbshipit-source-id: 1633513d4a25aead2008b59d52f669293214c598
2020-11-10 08:22:42 -08:00
Pasquale Anatriello
07eac0c6e2 Fix clone issue in YogaNodeJNIBase
Summary:
Changelog:
Fix the cloneWithChildren implementation that was not copying the list of children on the java object.

We were missing on copying the list of children when cloning. This is pretty bad as it means that the clone operation was mutating the old node as well as the new. When multiple threads were involved this could cause crashes.

Reviewed By: SidharthGuglani

Differential Revision: D24565307

fbshipit-source-id: 4e2e111db389e25c315ce7603b4018ac695bb0f1
2020-10-29 09:25:03 -07:00
simek
64e2459427 remove most of tvOS remnants from the code (#29407)
Summary:
Refs: [0.62 release](https://reactnative.dev/blog/#moving-apple-tv-to-react-native-tvos), https://github.com/facebook/react-native/issues/28706, https://github.com/facebook/react-native/issues/28743, https://github.com/facebook/react-native/issues/29018

This PR removes most of the tvOS remnants in the code. Most of the changes are related to the tvOS platform removal from `.podspec` files, tvOS specific conditionals removal (Obj-C + JS) or tvOS CI/testing pipeline related code.

In addition to the changes listed above I have removed the deprecated `Platform.isTVOS` method. I'm not sure how `Platform.isTV` method is correlated with Android TV devices support which is technically not deprecated in the core so I left this method untouched for now.

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://github.com/facebook/react-native/wiki/Changelog
-->

* **[Internal] [Removed]** - remove most of tvOS remnants from the code:
  * `TVEventHandler`, `TVTouchable`, `RCTTVView`, `RCTTVRemoteHandler` and `RCTTVNavigationEventEmitter`
* **[Internal] [Removed]** - remove `TARGET_TV_OS` flag and all the usages
* **[iOS] [Removed]** - remove deprecated `Platform.isTVOS` method
* **[iOS] [Removed]** - remove deprecated and TV related props from View:
  * `isTVSelectable`, `hasTVPreferredFocus` and `tvParallaxProperties`
* **[iOS] [Removed]** - remove `BackHandler` utility implementation

Pull Request resolved: https://github.com/facebook/react-native/pull/29407

Test Plan: Local tests (and iOS CI run) do not yield any errors, but I'm not sure how the CI pipeline would react to those changes. That is the reason why this PR is being posted as Draft. Some tweaks and code adjustment could be required.

Reviewed By: PeteTheHeat

Differential Revision: D22619441

Pulled By: shergin

fbshipit-source-id: 9aaf3840c5e8bd469c2cfcfa7c5b441ef71b30b6
2020-09-28 21:26:01 -07:00
Panagiotis Vekris
f350c7a58e explicitly set types_first=false in flowconfigs
Summary:
In Flow version 0.134, [types-first](https://flow.org/en/docs/lang/types-first/) will become the default mode for Flow.
Given that this mode might introduce some errors due to missing annotations,
we're pinning the previously default mode, to avoid introducing new errors.

Note that in Jan 2021 we will be removing support for Flow classic mode.

* Documentation for properly upgrading to types-first: https://flow.org/en/docs/cli/annotate-exports/
* Announcement post: https://medium.com/flow-type/types-first-a-scalable-new-architecture-for-flow-3d8c7ba1d4eb

Reviewed By: mroch

Differential Revision: D23606450

fbshipit-source-id: f849275269974e17c0ebe00885e387ccd9956b6d
2020-09-10 16:13:45 -07:00
Paco Estevez Garcia
e0ae96368c Add DoNotStripAny
Summary:
This diff adds an annotation that also prevents stripping methods, fields and static blocks.

This is necessary for D23373168 to be OSS'd

Reviewed By: SidharthGuglani

Differential Revision: D23395925

fbshipit-source-id: 8456234cb75b15ae87580835e76f8e251ba09a9b
2020-08-28 06:44:45 -07:00
Jiawei Lv
e1c9d8800e Assign test_ownership_2020 as owner for unowned java tests in fbandroid
Summary: Changelog: [Internal]

Reviewed By: IanChilds

Differential Revision: D22980855

fbshipit-source-id: d5e394f16eaf0e50367b95b1eec98024b906d3d9
2020-08-11 17:19:05 -07:00
Thomas Nardone
084d5935e6 Tweak stdlib imports in event, utils
Summary:
Changelog:
[Internal][Fixed] - Tweaked stdlib imports

Reviewed By: SidharthGuglani

Differential Revision: D22860196

fbshipit-source-id: fc0fc1bf05ebbfae7e86bce5e960e58d5944ee5c
2020-08-03 09:39:32 -07:00
Valentin Shergin
fc88b2f774 Introducing YGPositionTypeStatic
Summary:
Changelog: [Internal] Fabric-specific internal change.
This diff introduces a new value for `YGPositionType`: `YGPositionTypeStatic`.
No part of Yoga, RN, Litho or CK uses this value yet. `relative` and `static` values behave the same way for now. We also do not change any defaults. So, it should be fine.

Reviewed By: SidharthGuglani

Differential Revision: D22386732

fbshipit-source-id: 39cd9e818458ac2a91efb175f24a74c8c303ff08
2020-07-20 00:33:02 -07:00
Stanislau Hlebik
5ac5624e3f remediation of S205607
fbshipit-source-id: 798decc90db4f13770e97cdce3c0df7d5421b2a3
2020-07-17 17:23:52 -07:00
Stanislau Hlebik
16f676eccf remediation of S205607
fbshipit-source-id: 5113fe0c527595e4227ff827253b7414abbdf7ac
2020-07-17 17:23:51 -07:00
Valentin Shergin
0767f4d105 Using YGPositionTypeAbsolute value where we compare absolute vs relative
Summary:
Now Yoga.cpp does not use the `YGPositionTypeRelative` value/constant, it uses `YGPositionTypeAbsolute` instead.
Now `YGPositionType` can only be `YGPositionTypeRelative` or `YGPositionTypeAbsolute`, so expressions `x == YGPositionTypeRelative` and `x != YGPositionTypeAbsolute` are equivalent.
The reasoning behind the change is that in all cases we actually check a node to be (or not to be) `absolute`, not `relative`. This will make a difference in the coming diffs in the stack when we will introduce a new value for the type: `static`.

We need to differentiate `static` and `relative` values t implement the `stacking context` feature in the W3C-compliant way (to fix bugs and avoid developer confusion). Read more here:
https://developer.mozilla.org/en-US/docs/Web/CSS/position

Changelog: [Internal] Internal change in Yoga.

Reviewed By: SidharthGuglani

Differential Revision: D22386733

fbshipit-source-id: 8e2c2b88b404660639f845783c8f93f0c62c0fbb
2020-07-14 15:31:07 -07:00
Amir Shalem
a93e5d63c9 Don't call config->setLogger(nullptr) directly to avoid having no logger at all
Summary:
Changelog: [Internal][Yoga] Don't call config->setLogger(nullptr) directly to avoid having no logger at all

Broken in D14151037 (05f36a835a) when it started calling
```
config->setLogger(nullptr);
```
instead of going thru
```
YGConfigSetLogger(config, nullptr);
```
which does the right thing by setting the logger to its default value:
https://www.internalfb.com/intern/diffusion/FBS/browsefile/master/xplat/yoga/yoga/Yoga.cpp?commit=835911317e8b3cf7da1866e40e1c79cda0690136&lines=4320-4330

Also by default YogaConfig always have a logger:
https://www.internalfb.com/intern/diffusion/FBS/browsefile/master/xplat/yoga/yoga/Yoga.cpp?commit=835911317e8b3cf7da1866e40e1c79cda0690136&lines=335-343

Reviewed By: SidharthGuglani

Differential Revision: D22387459

fbshipit-source-id: 4da91da87a696d38cc9d8db2acb5845d29398adb
2020-07-06 03:53:19 -07:00
Stiopa Koltsov
d74a1069a0 xplat: Disable Starlark in several files
Summary: Disable Starlark in several files which are not trivial to fix.

Reviewed By: scottrice

Differential Revision: D22202463

fbshipit-source-id: a3ff717f0f4b9cd7f492b8fcebdb91f232207222
2020-06-24 12:29:48 -07:00
Sidharth Guglani
633cdc9088 use fmod and YGDoubleEquals for double operations instead of float
Summary: Changelog: [Internal][Yoga] Use double operations during rounding

Reviewed By: mdvacca

Differential Revision: D21840018

fbshipit-source-id: c5d17fcb8984b1da9832a15ccd4d628e8d742c6a
2020-06-08 08:11:18 -07:00
Steven Koeber
ede65bbce4 Buckification of Yoga build script
Reviewed By: liorisraeli87, k21

Differential Revision: D21429174

fbshipit-source-id: f12c8349cc59398553773df7bc15f0f83bd571b4
2020-06-04 06:54:18 -07:00
Jon Janzen
4135420cba Fix GitHub Actions secrets access (#1005)
Summary:
Ref: [Secrets documentation](https://help.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets#using-encrypted-secrets-in-a-workflow)

In combination with setting the secrets in the GitHub settings, this should fully migrate yoga to GH actions.

Pull Request resolved: https://github.com/facebook/yoga/pull/1005

Test Plan: GitHub Actions CI on the PR attached to this diff

Reviewed By: SidharthGuglani

Differential Revision: D21574995

Pulled By: bigfootjon

fbshipit-source-id: e9ee6d7cf1ae131afdc3aa3778667f1e9b9de833
2020-05-14 12:21:28 -07:00
Sidharth Guglani
07c0d539bd throw std::logic_error instead of aborting the process and convert to java exception
Summary: Changelog: [Internal][Yoga] throw std::logic_error instead of aborting the process and convert to java exception for jni layer

Reviewed By: pasqualeanatriello

Differential Revision: D21301235

fbshipit-source-id: 148b27920e62990a271e1d0df8c85a2cc42f4fd4
2020-05-14 06:39:25 -07:00
Jon Janzen
ac7c85c0a6 Migrate CI from TravisCI to GitHub Actions (#1004)
Summary:
Migrate from TravisCI to GitHub Actions. Facebook employees can read about this migration [here](https://fburl.com/rfp033ou).

CC: wittgenst
Pull Request resolved: https://github.com/facebook/yoga/pull/1004

Test Plan: GitHub Actions CI on my personal GitHub: https://github.com/bigfootjon/yoga/runs/653755729

Reviewed By: passy

Differential Revision: D21431309

Pulled By: bigfootjon

fbshipit-source-id: 490a8679bc0cfec26b13c8c584a928f03c6e26e7
2020-05-12 12:01:53 -07:00
Sidharth Guglani
83b27417ae Fix rounding error using double instead of float
Summary: Changelog: [Internal] [Yoga] Use double instead of float during rounding process to prevent loss of precision.

Reviewed By: mdvacca

Differential Revision: D21227565

fbshipit-source-id: 380b57535a356624cda8dc2017871a4ef3c882d1
2020-04-27 14:48:15 -07:00
Valentin Shergin
884f147742 Fixed incorrect owner assignment in YGNode move constructor
Summary:
Assigning self as an owner makes a cycle which is obviously a bug.

Changelog: [Internal] Small change in Yoga (should not affect RN).

Reviewed By: SidharthGuglani

Differential Revision: D21111423

fbshipit-source-id: 1835561c055ac827f5ce98a044f25aed0d1845a5
2020-04-20 12:05:55 -07:00
Gavin Weng
a96a36ef59 Link yogacore statically into yoga
Summary: A revert of D20879886.

Reviewed By: iliagore

Differential Revision: D20979490

fbshipit-source-id: cb37f931654450c408e72578abcc549f35727b07
2020-04-17 17:34:17 -07:00
acton393
1bd4123df1 fix typo as there is no file called YGJNI.cpp (#990)
Summary:
fix typo in `YogaJNIBase.java` as there is no such file called `YGJNI.cpp`
Pull Request resolved: https://github.com/facebook/yoga/pull/990

Reviewed By: pasqualeanatriello

Differential Revision: D20735102

Pulled By: SidharthGuglani

fbshipit-source-id: 3f9f4d78ba390feae3451330f997a221ab4ec70e
2020-04-17 05:45:41 -07:00
Sidharth Guglani
92b76447b7 use default value of enums YGDirection and YGMeasureMode instead of -1
Summary:
Changelog:
[Internal][Yoga] YGDirection variable was initialized incorrectly by casting -1 to YGDirection. Changing it to default value of direction

Same for YGMeasureMode.

Reviewed By: pasqualeanatriello

Differential Revision: D20869042

fbshipit-source-id: 7bfe490193321baae875ef6fb49a938851950c9f
2020-04-17 05:32:05 -07:00
Sidharth Guglani
e637cf2d72 Add Yoga also as a dependency of testutil-jni
Summary:
`scripts/deploy_jcenter.sh` was failing

{F234018047}

Added `yoga` also as a dependency of `testutil-jni`

Reviewed By: gavinweng

Differential Revision: D21017796

fbshipit-source-id: 0c34e7fc2373906441bd7805f5687b2c5dab6242
2020-04-15 00:49:53 -07:00
empyrical
9b96a5362a Yoga Podspec: Export YGNode and YGStyle headers (#997)
Summary:
This pull request adds `YGNode.h` and `YGStyle.h` to the headers exported by Yoga's podspec. They are required by the new Fabric architecture of React Native.

The modulemap and its umbrella header automatically generated by Cocoapods adds all exported headers to the `modulemap`. Having YGNode and YGStyle exported through here has problems, because they are only available in environments that have C++ available, and will produce errors otherwise.

This pull request fences off the contents of those headers in an `#ifdef __cplusplus` block, so they will not cause errors when imported into environments where C++ isn't available.

I had considered adding a custom modulemap to the podspec as part of this pull request, but this way seems the least "invasive", and this way you are able to add and remove exported headers in the podspec without needing to worry about updating the umbrella header at the same time.

Changelog:

[Internal] - Yoga Podspec: Export YGNore and YGStyle headers

Pull Request resolved: https://github.com/facebook/yoga/pull/997

Reviewed By: hramos

Differential Revision: D20966075

Pulled By: mdvacca

fbshipit-source-id: 5f5caa6b639d11e660b968d681da9a4de6c0eb8e
2020-04-14 16:42:27 -07:00
Sidharth Guglani
e5743e851b Set width/height also to Undefined when we change the measure mode to Undefined
Summary:
Make sure width/height is always passed as Undefined when measure mode is changed to Undefined.

Changelog: [Internal][Yoga] Set width and height as Undefined when we change measure mode to Undefined

Reviewed By: alickbass

Differential Revision: D20029838

fbshipit-source-id: b9931f6ddb13ffd1565889535ade5bbffbe0c304
2020-04-14 02:09:29 -07:00
George Zahariev
f7bc0ad248 Upgrade Prettier in Xplat to version 1.19.1: format files
Summary:
Part two of D20879147 where we update the versions of Prettier used in Xplat. I will stack land the diffs.
Here, we format all the files, and use the drop conflicts flag. After this lands, I will go and format the files which had conflicts again.

Changelog: [Internal]

drop-conflicts
bypass-lint
allow-large-files

Reviewed By: gkz

Differential Revision: D20929844

fbshipit-source-id: 2c1df8966a48b5db4f890e2cc494cb1c69422b7d
2020-04-09 11:06:06 -07:00
George Zahariev
8c53c2dcca Upgrade Prettier in Xplat to version 1.19.1
Summary:
Upgrades Prettier in Xplat to 1.19.1
Ignores upgrading packages on already on versions greater than 1.19.1

Changelog: [Internal]

allow-large-files
bypass-lint

(Note: this ignores all push blocking failures!)

Reviewed By: gkz, cpojer

Differential Revision: D20879147

fbshipit-source-id: 0deee7ac941e91e1c3c3a1e7d3d3ed20de1d657d
2020-04-09 11:06:04 -07:00
Gavin Weng
be51bc44a4 Revert Name Change for FBLite
Summary: To unblock

Reviewed By: Arieg419

Differential Revision: D20879886

fbshipit-source-id: 428f9147e540b94dec7f72a7f844949722165a07
2020-04-06 19:53:50 -07:00
Gavin Weng
5eba2d42bd Enhance build process (#994)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/994

After building yoga aar, we found several issues:
1. More dynamic so files. This is bad as lower-end Android devices cannot load that many sos.
2. Size increase.
3. (Minor) The libs are stored in asset folder rather than "libs/".

We apply the following optimizations:
1. Remove dependency on memalign16 (this is brought in by a pure header dependency jni-hack);
2. Enable native relinker to remove unused symbols in the so files.
3. Link yogacore statically to reduce size churn.

Reviewed By: SidharthGuglani

Differential Revision: D20808623

fbshipit-source-id: 6c6bbd4f71b6bf6ad272ec05dd56696ddb14a8e0
2020-04-06 11:51:16 -07:00
Sidharth Guglani
2049c85a6c Unit tests for flexshrink min width cases
Reviewed By: pasqualeanatriello

Differential Revision: D20219428

fbshipit-source-id: 8cbd028627095d9f7b393489ddba1f31c3207b67
2020-04-01 14:56:49 -07:00
Sidharth Guglani
ecd7790dd8 Fix Yoga flexshrink with min-width sizing issue
Summary:
While resolving the flexible items we calculate totalFlexShrinkScaledFactors which uses the flexBasis or initial width of node (Not min-width).

At a later stage during distribution of space we are subtracting value from this which also takes care of min-width.

For example
If node has flexShrink 1 and width 100 and min-width 301  then totalFlexShrinkScaledFactors will become -1*100 = -100
but later we are subtracting -1 * 301 (min-width) = -301 which is ambiguous and causing layout inconsistencies with how web behaves.

Fixed this by only using the flexBasis or width for these calculations.

Changelog:
[Internal][Yoga] Fix layout issue when flexShrink and min-width are used together

Reviewed By: pasqualeanatriello

Differential Revision: D20219419

fbshipit-source-id: 948fbc06ca541d4ad307c88c8a2df65d157778b1
2020-04-01 14:56:45 -07:00
Michael Bolin
0f08aa53da Back out "Upgrade Prettier from 1.17 to 2.0.2."
Differential Revision: D20639755

fbshipit-source-id: 5028563f9cf0527a30b4259daac50cdc03934bfd
2020-03-24 21:41:08 -07:00
Michael Bolin
5bf93e81ba Upgrade Prettier from 1.17 to 2.0.2.
Summary:
This gets us on the latest Prettier 2.x:
https://prettier.io/blog/2020/03/21/2.0.0.html

Notably, this adds support for TypeScript 3.8,
which introduces new syntax, such as `import type`.

Reviewed By: zertosh

Differential Revision: D20636268

fbshipit-source-id: fca5833d003804333a05ba16325bbbe0e06d6c8a
2020-03-24 20:26:19 -07:00
Lior Israeli
4f1231f411 Fix typo in buck targets
Summary: Proguard is spelled wrong

Reviewed By: SidharthGuglani

Differential Revision: D20619173

fbshipit-source-id: 463788454ad7e72337121ed63ab79129db45113e
2020-03-24 05:37:47 -07:00
Adam Ernst
b280a19b0a Run 'arc lint-deps'
Reviewed By: d16r

Differential Revision: D20362505

fbshipit-source-id: f3b7e62f7665d20a32788042772b731d6ed53f36
2020-03-10 10:58:46 -07:00
Nate Stedman
63a463d011 Mark YogaKit as modular
Differential Revision: D20364340

fbshipit-source-id: ce4bc1f474177ffc9c77eb2f10bdb7cb549dd6d8
2020-03-10 09:38:56 -07:00
Jesse Katsumata
adb87e347f chore: fix typo in comments (#28269)
Summary:
Fixed some typos in the comment.

## Changelog

[Internal] [Fixed] - Fixed typo in the comments
Pull Request resolved: https://github.com/facebook/react-native/pull/28269

Test Plan: Changes are only made in the comments, so test is not necessary.

Reviewed By: cpojer

Differential Revision: D20342637

Pulled By: shergin

fbshipit-source-id: f6e7dd538ee54c43e1570c35e1f8c4502054e328
2020-03-09 16:03:44 -07:00
Sidharth Guglani
2d52b5a873 fix layout tab height issue in playground on home page
Summary: Fixed layout tab height issue properly

Reviewed By: danielbuechele

Differential Revision: D20003594

fbshipit-source-id: 6d9ce89a5d82a83937e5cb0f989bb028e07d576f
2020-02-25 07:34:37 -08:00
Sidharth Guglani
6c61cd5f05 Fix layout tab scrolling in playground
Summary: Add a scroll bar to layout tab in playground to fix the UI issue where margin, border were not accessible.

Reviewed By: danielbuechele

Differential Revision: D19906128

fbshipit-source-id: 2c2d7695f731b2d312b78eab31c66d737915eaae
2020-02-19 11:12:41 -08:00
Sidharth Guglani
bfc3b2f86f fix lint errors
Summary:
Changelog: [Internal][Yoga] Fixed lint errors

```arc lint --apply-patches --take CLANGFORMAT --paths-cmd 'hg files xplat/yoga'
```
Added .clang-tidy file

Reviewed By: zertosh

Differential Revision: D19948702

fbshipit-source-id: f77a16d6f2c532267597a84a9caded0aae68c3aa
2020-02-18 08:24:46 -08:00
Christoph Purrer
a1278cee05 Make YGValue.h compile with Clang on Windows
Summary:
- We use a fork of Microsoft's react-native-windows which uses a fork of Facebook's react-native
- YGValue.h does not compile with Clang on Windows
- This change should fix that
- I want to put the change here so that it bubbles back to our fork > https://our.intern.facebook.com/intern/diff/D19656093/

#Changelog:
[General][Fixed] Make YGValue.h compile with Clang on Windows

Reviewed By: SidharthGuglani

Differential Revision: D19717489

fbshipit-source-id: ad867ecaf910bb64a777a06c656a1867bb15484b
2020-02-05 13:44:21 -08:00
Pasquale Anatriello
e983c4a5ef Swap child Yoga
Summary:
Changelog: [Internal]

Expose the replaceChild Yoga call to Java

Reviewed By: SidharthGuglani

Differential Revision: D19497193

fbshipit-source-id: 153243cc1d8c23dcaf2c772ca794bd59a230f652
2020-01-30 04:32:20 -08:00
Amir Shalem
7f97e8b232 Allow redex to optimize more of yoga by removing unneeded @DoNotStrip marks
Summary:
There are multiple `DoNotStrip` in Yoga java binding, they aren't needed.

##Changelog:
[Internal][Yoga] Allow redex to optimize more of yoga by removing unneeded DoNotStrip marks

Reviewed By: SidharthGuglani

Differential Revision: D17519844

fbshipit-source-id: 8b26800d720f34cae87754d85460abf88acbe713
2019-12-04 01:34:54 -08:00
Sidharth Guglani
089095f532 create global ref properly in YogaJNIException
Summary:
##Changelog:
[Internal][Yoga] create global ref properly in YogaJNIException

Reviewed By: astreet

Differential Revision: D18775982

fbshipit-source-id: ee529d6178d40b5f887fa1327fe156fa466f154f
2019-12-03 16:02:13 -08:00
Sidharth Guglani
ac8eb111a9 Add defensive check for result returned after JNI function calls
Summary:
Added method which checks if value(methodId, fieldId, class ...) returned by JNI functions (getMethod, getField, getClass ...) is valid or not and throw exception if they are not valid

##Changelog:
[Internal][Yoga] Add defensive check for result returned after JNI calls

Reviewed By: astreet

Differential Revision: D18745718

fbshipit-source-id: 2af26eda15fbe7834e1c9b274deeed4f106274ab
2019-12-02 05:24:54 -08:00
Sidharth Guglani
073f49d0d0 Use YogaJniException in jni call exception handling
Summary:
##Changelog:
[Internal][Yoga] Use YogaJniException in jni call exception handling

Reviewed By: astreet

Differential Revision: D18745615

fbshipit-source-id: 5fcf4c31f04fade94ef98a5349782ed3d43805b0
2019-12-02 05:24:54 -08:00
Sidharth Guglani
67915b5905 Add YogaJniException class
Summary:
## Changelog:
[Internal][Yoga] Add YogaJniException class to be used later for jni exceptions

Reviewed By: astreet

Differential Revision: D18745609

fbshipit-source-id: 53503b54dbc59e9fe47f599dee6be9cb68134cb2
2019-12-02 05:24:53 -08:00
Sidharth Guglani
015df9c512 Remove bitfield.h
Summary:
##Changelog:

[Internal][Yoga] Remove Bitfield.h

Reviewed By: astreet

Differential Revision: D18519647

fbshipit-source-id: b46fe585d3ef5f1da7d2726b2d9f759a649be121
2019-11-27 14:19:47 -08:00
Sidharth Guglani
f7f134274c Remove bitfield from YGNode.h
Summary:
##Changelog:

[Internal][Yoga] remove Bitfield from YGNode.h

Reviewed By: astreet

Differential Revision: D18519633

fbshipit-source-id: b5a7d8d5ee960c5618df382900c4ded3da0587a6
2019-11-27 14:19:46 -08:00
Sergey Ryabov
aeb9549af7 Fix javadocs
Summary: Changelog: [Internal]

Reviewed By: muraziz

Differential Revision: D15538725

fbshipit-source-id: 5cf60f47b07ce355e40d5b064add1df980beed89
2019-11-22 10:25:41 -08:00
Sidharth Guglani
f3498a2959 Remove BItfield from YGLayout.h
Summary:
##Changelog:

[Internal][Yoga] Remove Bitfield from YGLayout

Reviewed By: astreet

Differential Revision: D18519623

fbshipit-source-id: 950b8cb1ca2cd0424b8d8748c4b71336b40fc15f
2019-11-22 04:51:14 -08:00
Sidharth Guglani
9d2ca758fa Remove Bitfield from YGStyle
Summary:
##Changelog:

[Internal][Yoga] Remove Bitfield from YGStyle

Reviewed By: astreet

Differential Revision: D18519614

fbshipit-source-id: 70f18bc679b62712d40d76bd793cf85906b067a1
2019-11-22 04:51:13 -08:00
Sidharth Guglani
9650c1903d converts BitfieldTests to BitUtilsTest
Summary: Use BitUtils for testing bit operations

Reviewed By: astreet

Differential Revision: D18596312

fbshipit-source-id: 83f93cd7f1f056b3f64070debbc452877b44ac7a
2019-11-22 04:51:13 -08:00
Sidharth Guglani
f4840a0148 Added BitUtils
Summary:
Adds BitUtils to be used later instead of Bitfield.h

##Changelog:
[Internal][Yoga] : Adds BitUtils to be used later instead of Bitfield.h

Reviewed By: astreet

Differential Revision: D18519609

fbshipit-source-id: 8353929543505a7d80d66281adb801d34372beed
2019-11-22 04:51:12 -08:00
Sidharth Guglani
198e99d30c Back out "not using templates for updating styles which are used via bitfield"
Reviewed By: astreet

Differential Revision: D18628090

fbshipit-source-id: 9d006534111f10ec25a0d56214792aeb96fbdef9
2019-11-22 04:51:11 -08:00
Sidharth Guglani
cd0191c247 not using templates for updating styles which are used via bitfield
Summary:
We want completely remove usages of Bitfield as it uses templates which bloats binary size
This stack will reduce 2.2 Kb in binary size bringing it down to 61.3KB on armv7

In this diff we are removing usage of template while updating styles.

## Changelog:
[Internal][Yoga] : Not using templates for updating styles

Reviewed By: astreet

Differential Revision: D18519570

fbshipit-source-id: 2324088b8c63154f818b1da1edf24c0533e10082
2019-11-15 06:39:29 -08:00
Sidharth Guglani
7ec0ef8470 add test for margin and padding percent applied on leaf nodes with measure function
Summary: Add tests for using margin and padding percent on nodes with measure function set on them

Reviewed By: alickbass

Differential Revision: D17130693

fbshipit-source-id: 9a5c963671f7649dead459969b008335f15e45ce
2019-11-15 05:13:35 -08:00
Sidharth Guglani
b88cf7ff67 use owner's width for resolving the margin and padding for node
Summary:
The margin and padding are resolved incorrectly for leaf nodes (nodes with measure function set) if margin and padding are used in percentages.
Here we were using node's width instead of container width to calculate the margin and padding.

Fixed this to use container's width.

## Changelog:

[General][Yoga] : Fixed an issue where margin and padding were resolved incorrectly for leaf nodes (nodes with measure function set) if margin and padding are used in percentages.

Reviewed By: alickbass

Differential Revision: D17130520

fbshipit-source-id: ac904d432f121973e7739debd9136909b5ca1427
2019-11-15 05:13:34 -08:00
Sidharth Guglani
20fe53b254 Add --version-script
Summary: Adds version script to exclude all exported symbols and export only JNI_onLoad

Reviewed By: Andrey-Mishanin

Differential Revision: D18076602

fbshipit-source-id: cac4ef9c800de6a3b2081a1f847fa918687896fe
2019-11-13 16:46:09 -08:00
Sidharth Guglani
f99da09716 Remove useVanillaJNI flag and usage of fbjni in yoga build
Summary:
## Changelog:

[General] [Yoga] - Use vanilla jni instead of fbjni for all the jni communication

Reviewed By: astreet

Differential Revision: D17808005

fbshipit-source-id: 5e9a1ed73978f519c71c248774a28e5a294e7c7f
2019-11-13 15:16:37 -08:00
Sidharth Guglani
5960dd888d Add test for margin top not calculated correctly if defined in percentage
Summary:
Unit tests for margin percent scenario where height was being used instead of width

## Changelog:

[Internal] [Yoga] - Added unit tests for margin percent

Reviewed By: alickbass

Differential Revision: D18448365

fbshipit-source-id: f4404b0c493938fc04dc685e97effa08bfd553b0
2019-11-13 07:25:59 -08:00
Sidharth Guglani
b0a0007d6e using width for calculating margin top percent
Summary:
In Yoga, margin is not calculated correctly when defined in terms of percentage at one place.
According to CSS docs , margin percentage should be calculated according to width of container's block in case of horizontal writing mode. (https://fburl.com/5imus0it)
We were using height of container causing some issues in both android and iOS.

## Changelog:

[Yoga] [Fixed] - margin if defined in percentage should use container's width in horizontal writing mode

Reviewed By: alickbass

Differential Revision: D18395285

fbshipit-source-id: 87ebd013e3cba36da45f6548e4dff1bce69cce9b
2019-11-13 05:29:36 -08:00
Pritesh Nandgaonkar
73a4a6d29f Fixes the Yogakit compilation bug for xcode11
Summary:
This fixes the yogakit compilation bug for xcode 11, where it fails to find swift core frameworks for pure objc project.

https://github.com/Carthage/Carthage/issues/2825
https://twitter.com/krzyzanowskim/status/1151549874653081601?s=21

Also published this podspec on cocoapods and deleted .swift-version file as it was not required, because swift version is mentioned in podspec

Reviewed By: SidharthGuglani

Differential Revision: D18420963

fbshipit-source-id: d617bf643ac6481d6add86e6a4bfadd6e0d0c229
2019-11-11 10:18:52 -08:00
Pritesh Nandgaonkar
0be0e9fc01 Solve lib lint failure
Summary:
This diff solves `pod lib lint` failure.

We want to make a new yoga release, as I landed some changes in its podspec which solves the broken flipper build for xcode 11.

{F221612119}

Reviewed By: passy

Differential Revision: D18382588

fbshipit-source-id: efddfa3e93ca59b79b887d04f83407b004d9a199
2019-11-08 04:03:00 -08:00
151 changed files with 3139 additions and 3503 deletions

58
.github/workflows/ci.yml vendored Normal file
View File

@@ -0,0 +1,58 @@
name: CI
on: [push, pull_request]
jobs:
website:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v1
with:
node-version: 8.x
- name: Install dependencies
run: yarn install --frozen-lockfile --ignore-scripts
working-directory: website
- name: Build
run: yarn build
working-directory: website
- name: Deploy
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_branch: gh-pages
publish_dir: website/public
cname: yogalayout.com
keep_files: true
user_name: 'Yoga-bot'
user_email: 'yogabot@fb.com'
android:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Install NDK 21
run: echo "y" | sudo /usr/local/lib/android/sdk/tools/bin/sdkmanager --install "ndk;21.0.6113669" "ndk;20.0.5594570" --sdk_root=${ANDROID_SDK_ROOT}
- name: Install dependencies
run: |
if [[ -n "${{ secrets.encrypted_d27e803291ff_iv }}" ]]; then
openssl aes-256-cbc -K ${{ secrets.encrypted_d27e803291ff_key }} -iv {{ secrets.encrypted_d27e803291ff_iv }} -in scripts/setup-keys.enc -d >> gradle.properties;
fi
sudo apt-get update
sudo apt-get install -y ninja-build
pushd $HOME
git clone --depth 1 https://github.com/facebook/buck.git
cd buck
ant
popd
echo "$HOME/buck/bin" >> $GITHUB_PATH
export PATH=$PATH:$HOME/buck/bin/
buck --version
- name: Build
# TODO: Run the tests here again. They're currently crashing the JVM in GitHub Actions for some reason.
run: ./gradlew :yoga-layout:assembleDebug && scripts/publish-snapshot.sh

32
.github/workflows/release.yml vendored Normal file
View File

@@ -0,0 +1,32 @@
name: Publish
on:
release:
types:
- created
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Install dependencies
run: source scripts/android-setup.sh && installAndroidSDK
- name: Write GPG Sec Ring
run: echo '${{ secrets.GPG_KEY_CONTENTS }}' | base64 -d > /tmp/secring.gpg
- name: Update gradle.properties
run: echo -e "signing.secretKeyRingFile=/tmp/secring.gpg\nsigning.keyId=${{ secrets.SIGNING_KEY_ID }}\nsigning.password=${{ secrets.SIGNING_PASSWORD }}\nmavenCentralPassword=${{ secrets.SONATYPE_NEXUS_PASSWORD }}\nmavenCentralUsername=${{ secrets.SONATYPE_NEXUS_USERNAME }}" >> gradle.properties
- name: Upload Android Archives
run: ./gradlew :yoga:assembleRelease publish --info
- name: Release and close
run: ./gradlew closeAndReleaseRepository
- name: Clean secrets
if: always()
run: rm /tmp/secring.gpg

3
.gitignore vendored
View File

@@ -6,6 +6,9 @@
/.buckd
/gentest/test.html
.buckversion
.cxx
.idea
/local.properties
# Jekyll
/.sass-cache/

View File

@@ -1 +0,0 @@
4.0

View File

@@ -1,77 +0,0 @@
language: java
os: linux
dist: trusty
addons:
apt:
sources:
- llvm-toolchain-trusty-6.0
- ubuntu-toolchain-r-test
packages:
- clang-6.0
env:
- TARGET: website
- TARGET: android
install:
- cd website
- yarn --ignore-scripts
- cd ..
cache:
directories:
- $HOME/buck
- $HOME/.gradle
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
# Android
- |
if [[ $TARGET = "android" ]]; then
pushd $HOME
git clone --depth 1 https://github.com/facebook/buck.git
cd buck
ant
popd
export PATH=$PATH:$HOME/buck/bin/
buck --version
export TERMINAL=dumb
source scripts/android-setup.sh && installAndroidSDK
export ANDROID_SDK=$ANDROID_HOME
export ANDROID_NDK_REPOSITORY=$HOME/android-ndk
export ANDROID_NDK_HOME=$ANDROID_NDK_REPOSITORY/android-ndk-r15c
fi
# Website
- |
if [[ $TARGET = "website" ]]; then
nvm install 8
nvm use 8
fi
script:
- |
if [[ $TARGET = "android" ]]; then
./gradlew testDebugUnit && scripts/publish-snapshot.sh
fi
- |
if [[ $TARGET = "website" ]]; then
pushd website
yarn build
popd
fi
deploy:
provider: pages
skip-cleanup: true
github-token: $GITHUB_TOKEN
fqdn: yogalayout.com
local-dir: website/public
email: yogabot@fb.com
name: Yoga-bot
keep-history: true
on:
branch: master
condition: $TARGET = website

31
BUCK
View File

@@ -2,7 +2,7 @@
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
load("//tools/build_defs/oss:yoga_defs.bzl", "BASE_COMPILER_FLAGS", "GTEST_TARGET", "LIBRARY_COMPILER_FLAGS", "subdir_glob", "yoga_cxx_library", "yoga_cxx_test", "yoga_dep")
load("//tools/build_defs/oss:yoga_defs.bzl", "BASE_COMPILER_FLAGS", "GTEST_TARGET", "LIBRARY_COMPILER_FLAGS", "YOGA_ROOTS", "subdir_glob", "yoga_cxx_library", "yoga_cxx_test", "yoga_dep", "yoga_prebuilt_cxx_library")
GMOCK_OVERRIDE_FLAGS = [
# gmock does not mark mocked methods as override, ignore the warnings in tests
@@ -14,6 +14,18 @@ TEST_COMPILER_FLAGS = BASE_COMPILER_FLAGS + GMOCK_OVERRIDE_FLAGS + [
"-DYG_ENABLE_EVENTS",
]
yoga_prebuilt_cxx_library(
name = "ndklog",
exported_platform_linker_flags = [
(
"^android.*",
["-llog"],
),
],
header_only = True,
visibility = YOGA_ROOTS,
)
yoga_cxx_library(
name = "yoga",
srcs = glob(["yoga/**/*.cpp"]),
@@ -24,7 +36,21 @@ yoga_cxx_library(
tests = [":YogaTests"],
visibility = ["PUBLIC"],
deps = [
yoga_dep("lib/fb:ndklog"),
":ndklog",
],
)
yoga_cxx_library(
name = "yoga-static",
srcs = glob(["yoga/**/*.cpp"]),
compiler_flags = LIBRARY_COMPILER_FLAGS,
preferred_linkage = "static",
public_include_directories = ["."],
raw_headers = glob(["yoga/**/*.h"]),
tests = [":YogaTests"],
visibility = ["PUBLIC"],
deps = [
":ndklog",
],
)
@@ -39,7 +65,6 @@ yoga_cxx_library(
visibility = ["PUBLIC"],
deps = [
":yoga",
yoga_dep("lib/fb:ndklog"),
],
)

View File

@@ -46,3 +46,29 @@ This will now only run the standalone webpack build upon install.
| node | Builds node js version. |
| standalone | Runs webpack. |
| none | Does nothing. You can use the prepackaged libs. |
## Maintainer Release Guide
To publish a new release, follow these steps:
1. Ensure you have your GPG key set up and your [OSS Sonatype](https://oss.sonatype.org/) credentials handy.
2. Add the follow entries to either your local `gradle.properties` (don't forget to revert) or your global `~/.gradle/gradle.properties`:
```
# You get these from https://oss.sonatype.org/#profile;User%20Token
mavenCentralRepositoryUsername=<username>
mavenCentralRepositoryPassword=<password>
# You can get the keyId (in GPG 1.4 format) by running `gpg1 --list-keys`.
signing.secretKeyRingFile=</path/to/secring.gpg>
signing.keyId=<key_id>
signing.password=<key_password>
```
3. Change the `VERSION_NAME` in `gradle.properties` to a non-SNAPSHOT release.
4. Commit and land the version change.
5. Run `./gradlew publishToMaven`.
6. Run `./gradlew closeAndReleaseRepository`.
7. Change the `VERSION_NAME` in `gradle.properties` back to a new SNAPSHOT release.
8. Commit and land the version change.
9. Celebrate! You've made a release!

View File

@@ -191,7 +191,6 @@
27595AD71E575C7800CCE2B1 /* SampleCxxModule.h in Headers */ = {isa = PBXBuildFile; fileRef = 3D92B0D41E03699D0018521A /* SampleCxxModule.h */; };
27595AD81E575C7800CCE2B1 /* SystraceSection.h in Headers */ = {isa = PBXBuildFile; fileRef = 3D92B0D51E03699D0018521A /* SystraceSection.h */; };
2D0EB9F32021067800CAF88A /* RCTUIUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = F1EFDA4E201F660F00EE6E4C /* RCTUIUtils.m */; };
2D16E68E1FA4FD3900B85C8A /* RCTTVNavigationEventEmitter.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = 3D0B842D1EC0B51200B2BD8E /* RCTTVNavigationEventEmitter.h */; };
2D1D83CE1F74E2DA00615550 /* libdouble-conversion.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3D383D621EBD27B9005632C8 /* libdouble-conversion.a */; };
2D3B5E931D9B087300451313 /* RCTErrorInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 3EDCA8A41D3591E700450C31 /* RCTErrorInfo.m */; };
2D3B5E941D9B087900451313 /* RCTBundleURLProvider.m in Sources */ = {isa = PBXBuildFile; fileRef = 68EFE4ED1CF6EB3900A1DE13 /* RCTBundleURLProvider.m */; };
@@ -269,8 +268,6 @@
3D0B842A1EC0B49400B2BD8E /* RCTTVRemoteHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = 3D0B84281EC0B49400B2BD8E /* RCTTVRemoteHandler.h */; };
3D0B842B1EC0B49400B2BD8E /* RCTTVRemoteHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 3D0B84291EC0B49400B2BD8E /* RCTTVRemoteHandler.m */; };
3D0B842C1EC0B4EA00B2BD8E /* RCTTVView.m in Sources */ = {isa = PBXBuildFile; fileRef = 130443D71E401AD800D93A67 /* RCTTVView.m */; };
3D0B842F1EC0B51200B2BD8E /* RCTTVNavigationEventEmitter.h in Headers */ = {isa = PBXBuildFile; fileRef = 3D0B842D1EC0B51200B2BD8E /* RCTTVNavigationEventEmitter.h */; };
3D0B84301EC0B51200B2BD8E /* RCTTVNavigationEventEmitter.m in Sources */ = {isa = PBXBuildFile; fileRef = 3D0B842E1EC0B51200B2BD8E /* RCTTVNavigationEventEmitter.m */; };
3D0E378A1F1CC40000DCAC9F /* RCTWebSocketModule.h in Headers */ = {isa = PBXBuildFile; fileRef = 3D0E37891F1CC40000DCAC9F /* RCTWebSocketModule.h */; };
3D0E378E1F1CC59100DCAC9F /* RCTWebSocketModule.h in Headers */ = {isa = PBXBuildFile; fileRef = 3D0E37891F1CC40000DCAC9F /* RCTWebSocketModule.h */; };
3D0E378F1F1CC5CF00DCAC9F /* RCTWebSocketModule.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = 3D0E37891F1CC40000DCAC9F /* RCTWebSocketModule.h */; };
@@ -1275,7 +1272,6 @@
594F0A471FD233BD007FBE96 /* RCTSurfaceView.h in Copy Headers */,
594F0A481FD233BD007FBE96 /* RCTSurfaceHostingView.h in Copy Headers */,
594F0A491FD233BD007FBE96 /* RCTSurfaceSizeMeasureMode.h in Copy Headers */,
2D16E68E1FA4FD3900B85C8A /* RCTTVNavigationEventEmitter.h in Copy Headers */,
59500D481F71C67600B122B7 /* RCTUIManagerUtils.h in Copy Headers */,
3D0E37901F1CC5E100DCAC9F /* RCTWebSocketModule.h in Copy Headers */,
5960C1BF1F0804F50066FD5B /* RCTLayoutAnimation.h in Copy Headers */,
@@ -1876,8 +1872,6 @@
39C50FFA2046EE3500CEE534 /* RCTVersion.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTVersion.m; sourceTree = "<group>"; };
3D0B84281EC0B49400B2BD8E /* RCTTVRemoteHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTTVRemoteHandler.h; sourceTree = "<group>"; };
3D0B84291EC0B49400B2BD8E /* RCTTVRemoteHandler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTTVRemoteHandler.m; sourceTree = "<group>"; };
3D0B842D1EC0B51200B2BD8E /* RCTTVNavigationEventEmitter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTTVNavigationEventEmitter.h; sourceTree = "<group>"; };
3D0B842E1EC0B51200B2BD8E /* RCTTVNavigationEventEmitter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTTVNavigationEventEmitter.m; sourceTree = "<group>"; };
3D0E37891F1CC40000DCAC9F /* RCTWebSocketModule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RCTWebSocketModule.h; path = WebSocket/RCTWebSocketModule.h; sourceTree = "<group>"; };
3D1E68D81CABD13900DD7465 /* RCTDisplayLink.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTDisplayLink.h; sourceTree = "<group>"; };
3D1E68D91CABD13900DD7465 /* RCTDisplayLink.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTDisplayLink.m; sourceTree = "<group>"; };
@@ -2346,8 +2340,6 @@
0EEEA8DE2239002200A8C82D /* RCTSurfacePresenterStub.m */,
13B07FED1A69327A00A75B9A /* RCTTiming.h */,
13B07FEE1A69327A00A75B9A /* RCTTiming.m */,
3D0B842D1EC0B51200B2BD8E /* RCTTVNavigationEventEmitter.h */,
3D0B842E1EC0B51200B2BD8E /* RCTTVNavigationEventEmitter.m */,
13E067481A70F434002CDEE1 /* RCTUIManager.h */,
13E067491A70F434002CDEE1 /* RCTUIManager.m */,
59EB6DB91EBD6FC90072A5E7 /* RCTUIManagerObserverCoordinator.h */,
@@ -2945,7 +2937,6 @@
3D302F311DF828F800D6DDAE /* RCTBundleURLProvider.h in Headers */,
3D302F321DF828F800D6DDAE /* RCTConvert.h in Headers */,
3D302F331DF828F800D6DDAE /* RCTDefines.h in Headers */,
3D0B842F1EC0B51200B2BD8E /* RCTTVNavigationEventEmitter.h in Headers */,
3D302F341DF828F800D6DDAE /* RCTDisplayLink.h in Headers */,
3D302F351DF828F800D6DDAE /* RCTErrorCustomizer.h in Headers */,
3D302F361DF828F800D6DDAE /* RCTErrorInfo.h in Headers */,
@@ -3994,7 +3985,6 @@
2D3B5EC81D9B095800451313 /* RCTActivityIndicatorViewManager.m in Sources */,
3DCD185D1DF978E7007FE5A1 /* RCTReloadCommand.m in Sources */,
130443DB1E401ADD00D93A67 /* RCTConvert+Transform.m in Sources */,
3D0B84301EC0B51200B2BD8E /* RCTTVNavigationEventEmitter.m in Sources */,
2D3B5EC61D9B095000451313 /* RCTProfileTrampoline-x86_64.S in Sources */,
2D3B5EA61D9B08CA00451313 /* RCTTouchEvent.m in Sources */,
2D8C2E331DA40441000EE098 /* RCTMultipartStreamReader.m in Sources */,

View File

@@ -33,6 +33,6 @@ Pod::Spec.new do |spec|
'-fPIC'
]
spec.source_files = 'yoga/**/*.{c,h,cpp}'
spec.public_header_files = 'yoga/{Yoga,YGEnums,YGMacros,YGValue}.h'
spec.public_header_files = 'yoga/{Yoga,YGEnums,YGMacros,YGNode,YGStyle,YGValue}.h'
end

View File

@@ -5,7 +5,7 @@
podspec = Pod::Spec.new do |spec|
spec.name = 'YogaKit'
spec.version = '1.17.0'
spec.version = '1.18.1'
spec.license = { :type => 'MIT', :file => "LICENSE" }
spec.homepage = 'https://facebook.github.io/yoga/'
spec.documentation_url = 'https://facebook.github.io/yoga/docs/'
@@ -16,26 +16,22 @@ podspec = Pod::Spec.new do |spec|
spec.authors = 'Facebook'
spec.source = {
:git => 'https://github.com/facebook/yoga.git',
:tag => spec.version.to_s,
:tag => "1.18.0",
}
spec.platform = :ios
spec.ios.deployment_target = '8.0'
spec.ios.frameworks = 'UIKit'
spec.default_subspec = "Core"
spec.dependency 'Yoga', '~> 1.14'
spec.module_name = 'YogaKit'
spec.subspec "Core" do |ss|
ss.source_files = 'YogaKit/Source/*.{h,m}'
ss.public_header_files = 'YogaKit/Source/{YGLayout,UIView+Yoga}.h'
ss.private_header_files = 'YogaKit/Source/YGLayout+Private.h'
end
spec.subspec 'SwiftExtension' do |ss|
ss.source_files = 'YogaKit/Source/*.{swift}'
end
spec.dependency 'Yoga', '~> 1.14'
# Fixes the bug related the xcode 11 not able to find swift related frameworks.
# https://github.com/Carthage/Carthage/issues/2825
# https://twitter.com/krzyzanowskim/status/1151549874653081601?s=21
spec.pod_target_xcconfig = {"LD_VERIFY_BITCODE": "NO"}
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'
spec.swift_version = '5.1'
end
# See https://github.com/facebook/yoga/pull/366

View File

@@ -37,11 +37,14 @@ yoga_apple_library(
),
compiler_flags = COMPILER_FLAGS,
frameworks = [
"$SDKROOT/System/Library/Frameworks/CoreGraphics.framework",
"$SDKROOT/System/Library/Frameworks/Foundation.framework",
"$SDKROOT/System/Library/Frameworks/UIKit.framework",
],
header_path_prefix = "",
link_whole = True,
modular = True,
module_name = "YogaKit",
visibility = ["PUBLIC"],
deps = [
yoga_dep(":yoga"),

View File

@@ -5,28 +5,29 @@
* LICENSE file in the root directory of this source tree.
*/
#import "YGLayout.h"
#import <UIKit/UIKit.h>
#import "YGLayout.h"
NS_ASSUME_NONNULL_BEGIN
typedef void (^YGLayoutConfigurationBlock)(YGLayout *layout);
typedef void (^YGLayoutConfigurationBlock)(YGLayout* layout);
@interface UIView (Yoga)
/**
The YGLayout that is attached to this view. It is lazily created.
*/
@property (nonatomic, readonly, strong) YGLayout *yoga;
@property(nonatomic, readonly, strong) YGLayout* yoga;
/**
Indicates whether or not Yoga is enabled
*/
@property (nonatomic, readonly, assign) BOOL isYogaEnabled;
@property(nonatomic, readonly, assign) BOOL isYogaEnabled;
/**
In ObjC land, every time you access `view.yoga.*` you are adding another `objc_msgSend`
to your code. If you plan on making multiple changes to YGLayout, it's more performant
to use this method, which uses a single objc_msgSend call.
In ObjC land, every time you access `view.yoga.*` you are adding another
`objc_msgSend` to your code. If you plan on making multiple changes to
YGLayout, it's more performant to use this method, which uses a single
objc_msgSend call.
*/
- (void)configureLayoutWithBlock:(YGLayoutConfigurationBlock)block
NS_SWIFT_NAME(configureLayout(block:));

View File

@@ -5,32 +5,30 @@
* LICENSE file in the root directory of this source tree.
*/
#import <objc/runtime.h>
#import "UIView+Yoga.h"
#import "YGLayout+Private.h"
#import <objc/runtime.h>
static const void *kYGYogaAssociatedKey = &kYGYogaAssociatedKey;
static const void* kYGYogaAssociatedKey = &kYGYogaAssociatedKey;
@implementation UIView (YogaKit)
- (YGLayout *)yoga
{
YGLayout *yoga = objc_getAssociatedObject(self, kYGYogaAssociatedKey);
- (YGLayout*)yoga {
YGLayout* yoga = objc_getAssociatedObject(self, kYGYogaAssociatedKey);
if (!yoga) {
yoga = [[YGLayout alloc] initWithView:self];
objc_setAssociatedObject(self, kYGYogaAssociatedKey, yoga, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
objc_setAssociatedObject(
self, kYGYogaAssociatedKey, yoga, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
return yoga;
}
- (BOOL)isYogaEnabled
{
- (BOOL)isYogaEnabled {
return objc_getAssociatedObject(self, kYGYogaAssociatedKey) != nil;
}
- (void)configureLayoutWithBlock:(YGLayoutConfigurationBlock)block
{
- (void)configureLayoutWithBlock:(YGLayoutConfigurationBlock)block {
if (block != nil) {
block(self.yoga);
}

View File

@@ -5,13 +5,13 @@
* LICENSE file in the root directory of this source tree.
*/
#import "YGLayout.h"
#import <yoga/Yoga.h>
#import "YGLayout.h"
@interface YGLayout ()
@property (nonatomic, assign, readonly) YGNodeRef node;
@property(nonatomic, assign, readonly) YGNodeRef node;
- (instancetype)initWithView:(UIView *)view;
- (instancetype)initWithView:(UIView*)view;
@end

View File

@@ -7,15 +7,15 @@
#import <UIKit/UIKit.h>
#import <yoga/YGEnums.h>
#import <yoga/Yoga.h>
#import <yoga/YGMacros.h>
#import <yoga/Yoga.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");
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
@@ -44,103 +44,107 @@ typedef NS_OPTIONS(NSInteger, YGDimensionFlexibility) {
The property that decides if we should include this view when calculating
layout. Defaults to YES.
*/
@property (nonatomic, readwrite, assign, setter=setIncludedInLayout:) BOOL isIncludedInLayout;
@property(nonatomic, readwrite, assign, setter=setIncludedInLayout:)
BOOL isIncludedInLayout;
/**
The property that decides during layout/sizing whether or not styling properties should be applied.
Defaults to NO.
The property that decides during layout/sizing whether or not styling
properties should be applied. Defaults to NO.
*/
@property (nonatomic, readwrite, assign, setter=setEnabled:) BOOL isEnabled;
@property(nonatomic, readwrite, assign, setter=setEnabled:) BOOL isEnabled;
@property (nonatomic, readwrite, assign) YGDirection direction;
@property (nonatomic, readwrite, assign) YGFlexDirection flexDirection;
@property (nonatomic, readwrite, assign) YGJustify justifyContent;
@property (nonatomic, readwrite, assign) YGAlign alignContent;
@property (nonatomic, readwrite, assign) YGAlign alignItems;
@property (nonatomic, readwrite, assign) YGAlign alignSelf;
@property (nonatomic, readwrite, assign) YGPositionType position;
@property (nonatomic, readwrite, assign) YGWrap flexWrap;
@property (nonatomic, readwrite, assign) YGOverflow overflow;
@property (nonatomic, readwrite, assign) YGDisplay display;
@property(nonatomic, readwrite, assign) YGDirection direction;
@property(nonatomic, readwrite, assign) YGFlexDirection flexDirection;
@property(nonatomic, readwrite, assign) YGJustify justifyContent;
@property(nonatomic, readwrite, assign) YGAlign alignContent;
@property(nonatomic, readwrite, assign) YGAlign alignItems;
@property(nonatomic, readwrite, assign) YGAlign alignSelf;
@property(nonatomic, readwrite, assign) YGPositionType position;
@property(nonatomic, readwrite, assign) YGWrap flexWrap;
@property(nonatomic, readwrite, assign) YGOverflow overflow;
@property(nonatomic, readwrite, assign) YGDisplay display;
@property (nonatomic, readwrite, assign) CGFloat flex;
@property (nonatomic, readwrite, assign) CGFloat flexGrow;
@property (nonatomic, readwrite, assign) CGFloat flexShrink;
@property (nonatomic, readwrite, assign) YGValue flexBasis;
@property(nonatomic, readwrite, assign) CGFloat flex;
@property(nonatomic, readwrite, assign) CGFloat flexGrow;
@property(nonatomic, readwrite, assign) CGFloat flexShrink;
@property(nonatomic, readwrite, assign) YGValue flexBasis;
@property (nonatomic, readwrite, assign) YGValue left;
@property (nonatomic, readwrite, assign) YGValue top;
@property (nonatomic, readwrite, assign) YGValue right;
@property (nonatomic, readwrite, assign) YGValue bottom;
@property (nonatomic, readwrite, assign) YGValue start;
@property (nonatomic, readwrite, assign) YGValue end;
@property(nonatomic, readwrite, assign) YGValue left;
@property(nonatomic, readwrite, assign) YGValue top;
@property(nonatomic, readwrite, assign) YGValue right;
@property(nonatomic, readwrite, assign) YGValue bottom;
@property(nonatomic, readwrite, assign) YGValue start;
@property(nonatomic, readwrite, assign) YGValue end;
@property (nonatomic, readwrite, assign) YGValue marginLeft;
@property (nonatomic, readwrite, assign) YGValue marginTop;
@property (nonatomic, readwrite, assign) YGValue marginRight;
@property (nonatomic, readwrite, assign) YGValue marginBottom;
@property (nonatomic, readwrite, assign) YGValue marginStart;
@property (nonatomic, readwrite, assign) YGValue marginEnd;
@property (nonatomic, readwrite, assign) YGValue marginHorizontal;
@property (nonatomic, readwrite, assign) YGValue marginVertical;
@property (nonatomic, readwrite, assign) YGValue margin;
@property(nonatomic, readwrite, assign) YGValue marginLeft;
@property(nonatomic, readwrite, assign) YGValue marginTop;
@property(nonatomic, readwrite, assign) YGValue marginRight;
@property(nonatomic, readwrite, assign) YGValue marginBottom;
@property(nonatomic, readwrite, assign) YGValue marginStart;
@property(nonatomic, readwrite, assign) YGValue marginEnd;
@property(nonatomic, readwrite, assign) YGValue marginHorizontal;
@property(nonatomic, readwrite, assign) YGValue marginVertical;
@property(nonatomic, readwrite, assign) YGValue margin;
@property (nonatomic, readwrite, assign) YGValue paddingLeft;
@property (nonatomic, readwrite, assign) YGValue paddingTop;
@property (nonatomic, readwrite, assign) YGValue paddingRight;
@property (nonatomic, readwrite, assign) YGValue paddingBottom;
@property (nonatomic, readwrite, assign) YGValue paddingStart;
@property (nonatomic, readwrite, assign) YGValue paddingEnd;
@property (nonatomic, readwrite, assign) YGValue paddingHorizontal;
@property (nonatomic, readwrite, assign) YGValue paddingVertical;
@property (nonatomic, readwrite, assign) YGValue padding;
@property(nonatomic, readwrite, assign) YGValue paddingLeft;
@property(nonatomic, readwrite, assign) YGValue paddingTop;
@property(nonatomic, readwrite, assign) YGValue paddingRight;
@property(nonatomic, readwrite, assign) YGValue paddingBottom;
@property(nonatomic, readwrite, assign) YGValue paddingStart;
@property(nonatomic, readwrite, assign) YGValue paddingEnd;
@property(nonatomic, readwrite, assign) YGValue paddingHorizontal;
@property(nonatomic, readwrite, assign) YGValue paddingVertical;
@property(nonatomic, readwrite, assign) YGValue padding;
@property (nonatomic, readwrite, assign) CGFloat borderLeftWidth;
@property (nonatomic, readwrite, assign) CGFloat borderTopWidth;
@property (nonatomic, readwrite, assign) CGFloat borderRightWidth;
@property (nonatomic, readwrite, assign) CGFloat borderBottomWidth;
@property (nonatomic, readwrite, assign) CGFloat borderStartWidth;
@property (nonatomic, readwrite, assign) CGFloat borderEndWidth;
@property (nonatomic, readwrite, assign) CGFloat borderWidth;
@property(nonatomic, readwrite, assign) CGFloat borderLeftWidth;
@property(nonatomic, readwrite, assign) CGFloat borderTopWidth;
@property(nonatomic, readwrite, assign) CGFloat borderRightWidth;
@property(nonatomic, readwrite, assign) CGFloat borderBottomWidth;
@property(nonatomic, readwrite, assign) CGFloat borderStartWidth;
@property(nonatomic, readwrite, assign) CGFloat borderEndWidth;
@property(nonatomic, readwrite, assign) CGFloat borderWidth;
@property (nonatomic, readwrite, assign) YGValue width;
@property (nonatomic, readwrite, assign) YGValue height;
@property (nonatomic, readwrite, assign) YGValue minWidth;
@property (nonatomic, readwrite, assign) YGValue minHeight;
@property (nonatomic, readwrite, assign) YGValue maxWidth;
@property (nonatomic, readwrite, assign) YGValue maxHeight;
@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;
@property(nonatomic, readwrite, assign) CGFloat aspectRatio;
/**
Get the resolved direction of this node. This won't be YGDirectionInherit
*/
@property (nonatomic, readonly, assign) YGDirection resolvedDirection;
@property(nonatomic, readonly, assign) YGDirection resolvedDirection;
/**
Perform a layout calculation and update the frames of the views in the hierarchy with the results.
If the origin is not preserved, the root view's layout results will applied from {0,0}.
Perform a layout calculation and update the frames of the views in the
hierarchy with the results. If the origin is not preserved, the root view's
layout results will applied from {0,0}.
*/
- (void)applyLayoutPreservingOrigin:(BOOL)preserveOrigin
NS_SWIFT_NAME(applyLayout(preservingOrigin:));
/**
Perform a layout calculation and update the frames of the views in the hierarchy with the results.
If the origin is not preserved, the root view's layout results will applied from {0,0}.
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)];
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;
@property(nonatomic, readonly, assign) CGSize intrinsicSize;
/**
Returns the size of the view based on provided constraints. Pass NaN for an unconstrained dimension.
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:));
@@ -148,19 +152,19 @@ typedef NS_OPTIONS(NSInteger, YGDimensionFlexibility) {
/**
Returns the number of children that are using Flexbox.
*/
@property (nonatomic, readonly, assign) NSUInteger numberOfChildren;
@property(nonatomic, readonly, assign) NSUInteger numberOfChildren;
/**
Return a BOOL indiciating whether or not we this node contains any subviews that are included in
Yoga's layout.
Return a BOOL indiciating whether or not we this node contains any subviews
that are included in Yoga's layout.
*/
@property (nonatomic, readonly, assign) BOOL isLeaf;
@property(nonatomic, readonly, assign) BOOL isLeaf;
/**
Return's a BOOL indicating if a view is dirty. When a node is dirty
it usually indicates that it will be remeasured on the next layout pass.
*/
@property (nonatomic, readonly, assign) BOOL isDirty;
@property(nonatomic, readonly, assign) BOOL isDirty;
/**
Mark that a view's layout needs to be recalculated. Only works for leaf views.

View File

@@ -5,153 +5,184 @@
* LICENSE file in the root directory of this source tree.
*/
#import "YGLayout+Private.h"
#import "UIView+Yoga.h"
#import "YGLayout+Private.h"
#define YG_PROPERTY(type, lowercased_name, capitalized_name) \
- (type)lowercased_name \
{ \
return YGNodeStyleGet##capitalized_name(self.node); \
} \
\
- (void)set##capitalized_name:(type)lowercased_name \
{ \
YGNodeStyleSet##capitalized_name(self.node, lowercased_name); \
#define YG_PROPERTY(type, lowercased_name, capitalized_name) \
-(type)lowercased_name { \
return YGNodeStyleGet##capitalized_name(self.node); \
} \
\
-(void)set##capitalized_name : (type)lowercased_name { \
YGNodeStyleSet##capitalized_name(self.node, lowercased_name); \
}
#define YG_VALUE_PROPERTY(lowercased_name, capitalized_name) \
-(YGValue)lowercased_name { \
return YGNodeStyleGet##capitalized_name(self.node); \
} \
\
-(void)set##capitalized_name : (YGValue)lowercased_name { \
switch (lowercased_name.unit) { \
case YGUnitUndefined: \
YGNodeStyleSet##capitalized_name(self.node, lowercased_name.value); \
break; \
case YGUnitPoint: \
YGNodeStyleSet##capitalized_name(self.node, lowercased_name.value); \
break; \
case YGUnitPercent: \
YGNodeStyleSet##capitalized_name##Percent( \
self.node, lowercased_name.value); \
break; \
default: \
NSAssert(NO, @"Not implemented"); \
} \
}
#define YG_AUTO_VALUE_PROPERTY(lowercased_name, capitalized_name) \
-(YGValue)lowercased_name { \
return YGNodeStyleGet##capitalized_name(self.node); \
} \
\
-(void)set##capitalized_name : (YGValue)lowercased_name { \
switch (lowercased_name.unit) { \
case YGUnitPoint: \
YGNodeStyleSet##capitalized_name(self.node, lowercased_name.value); \
break; \
case YGUnitPercent: \
YGNodeStyleSet##capitalized_name##Percent( \
self.node, lowercased_name.value); \
break; \
case YGUnitAuto: \
YGNodeStyleSet##capitalized_name##Auto(self.node); \
break; \
default: \
NSAssert(NO, @"Not implemented"); \
} \
}
#define YG_EDGE_PROPERTY_GETTER( \
type, lowercased_name, capitalized_name, property, edge) \
-(type)lowercased_name { \
return YGNodeStyleGet##property(self.node, edge); \
}
#define YG_EDGE_PROPERTY_SETTER( \
lowercased_name, capitalized_name, property, edge) \
-(void)set##capitalized_name : (CGFloat)lowercased_name { \
YGNodeStyleSet##property(self.node, edge, lowercased_name); \
}
#define YG_EDGE_PROPERTY(lowercased_name, capitalized_name, property, edge) \
YG_EDGE_PROPERTY_GETTER( \
CGFloat, lowercased_name, capitalized_name, property, edge) \
YG_EDGE_PROPERTY_SETTER(lowercased_name, capitalized_name, property, edge)
#define YG_VALUE_EDGE_PROPERTY_SETTER( \
objc_lowercased_name, objc_capitalized_name, c_name, edge) \
-(void)set##objc_capitalized_name : (YGValue)objc_lowercased_name { \
switch (objc_lowercased_name.unit) { \
case YGUnitUndefined: \
YGNodeStyleSet##c_name(self.node, edge, objc_lowercased_name.value); \
break; \
case YGUnitPoint: \
YGNodeStyleSet##c_name(self.node, edge, objc_lowercased_name.value); \
break; \
case YGUnitPercent: \
YGNodeStyleSet##c_name##Percent( \
self.node, edge, objc_lowercased_name.value); \
break; \
default: \
NSAssert(NO, @"Not implemented"); \
} \
}
#define YG_VALUE_EDGE_PROPERTY( \
lowercased_name, capitalized_name, property, edge) \
YG_EDGE_PROPERTY_GETTER( \
YGValue, lowercased_name, capitalized_name, property, edge) \
YG_VALUE_EDGE_PROPERTY_SETTER( \
lowercased_name, capitalized_name, property, edge)
#define YG_VALUE_EDGES_PROPERTIES(lowercased_name, capitalized_name) \
YG_VALUE_EDGE_PROPERTY( \
lowercased_name##Left, \
capitalized_name##Left, \
capitalized_name, \
YGEdgeLeft) \
YG_VALUE_EDGE_PROPERTY( \
lowercased_name##Top, \
capitalized_name##Top, \
capitalized_name, \
YGEdgeTop) \
YG_VALUE_EDGE_PROPERTY( \
lowercased_name##Right, \
capitalized_name##Right, \
capitalized_name, \
YGEdgeRight) \
YG_VALUE_EDGE_PROPERTY( \
lowercased_name##Bottom, \
capitalized_name##Bottom, \
capitalized_name, \
YGEdgeBottom) \
YG_VALUE_EDGE_PROPERTY( \
lowercased_name##Start, \
capitalized_name##Start, \
capitalized_name, \
YGEdgeStart) \
YG_VALUE_EDGE_PROPERTY( \
lowercased_name##End, \
capitalized_name##End, \
capitalized_name, \
YGEdgeEnd) \
YG_VALUE_EDGE_PROPERTY( \
lowercased_name##Horizontal, \
capitalized_name##Horizontal, \
capitalized_name, \
YGEdgeHorizontal) \
YG_VALUE_EDGE_PROPERTY( \
lowercased_name##Vertical, \
capitalized_name##Vertical, \
capitalized_name, \
YGEdgeVertical) \
YG_VALUE_EDGE_PROPERTY( \
lowercased_name, capitalized_name, capitalized_name, YGEdgeAll)
YGValue YGPointValue(CGFloat value) {
return (YGValue){.value = value, .unit = YGUnitPoint};
}
#define YG_VALUE_PROPERTY(lowercased_name, capitalized_name) \
- (YGValue)lowercased_name \
{ \
return YGNodeStyleGet##capitalized_name(self.node); \
} \
\
- (void)set##capitalized_name:(YGValue)lowercased_name \
{ \
switch (lowercased_name.unit) { \
case YGUnitUndefined: \
YGNodeStyleSet##capitalized_name(self.node, lowercased_name.value); \
break; \
case YGUnitPoint: \
YGNodeStyleSet##capitalized_name(self.node, lowercased_name.value); \
break; \
case YGUnitPercent: \
YGNodeStyleSet##capitalized_name##Percent(self.node, lowercased_name.value); \
break; \
default: \
NSAssert(NO, @"Not implemented"); \
} \
}
#define YG_AUTO_VALUE_PROPERTY(lowercased_name, capitalized_name) \
- (YGValue)lowercased_name \
{ \
return YGNodeStyleGet##capitalized_name(self.node); \
} \
\
- (void)set##capitalized_name:(YGValue)lowercased_name \
{ \
switch (lowercased_name.unit) { \
case YGUnitPoint: \
YGNodeStyleSet##capitalized_name(self.node, lowercased_name.value); \
break; \
case YGUnitPercent: \
YGNodeStyleSet##capitalized_name##Percent(self.node, lowercased_name.value); \
break; \
case YGUnitAuto: \
YGNodeStyleSet##capitalized_name##Auto(self.node); \
break; \
default: \
NSAssert(NO, @"Not implemented"); \
} \
}
#define YG_EDGE_PROPERTY_GETTER(type, lowercased_name, capitalized_name, property, edge) \
- (type)lowercased_name \
{ \
return YGNodeStyleGet##property(self.node, edge); \
}
#define YG_EDGE_PROPERTY_SETTER(lowercased_name, capitalized_name, property, edge) \
- (void)set##capitalized_name:(CGFloat)lowercased_name \
{ \
YGNodeStyleSet##property(self.node, edge, lowercased_name); \
}
#define YG_EDGE_PROPERTY(lowercased_name, capitalized_name, property, edge) \
YG_EDGE_PROPERTY_GETTER(CGFloat, lowercased_name, capitalized_name, property, edge) \
YG_EDGE_PROPERTY_SETTER(lowercased_name, capitalized_name, property, edge)
#define YG_VALUE_EDGE_PROPERTY_SETTER(objc_lowercased_name, objc_capitalized_name, c_name, edge) \
- (void)set##objc_capitalized_name:(YGValue)objc_lowercased_name \
{ \
switch (objc_lowercased_name.unit) { \
case YGUnitUndefined: \
YGNodeStyleSet##c_name(self.node, edge, objc_lowercased_name.value); \
break; \
case YGUnitPoint: \
YGNodeStyleSet##c_name(self.node, edge, objc_lowercased_name.value); \
break; \
case YGUnitPercent: \
YGNodeStyleSet##c_name##Percent(self.node, edge, objc_lowercased_name.value); \
break; \
default: \
NSAssert(NO, @"Not implemented"); \
} \
}
#define YG_VALUE_EDGE_PROPERTY(lowercased_name, capitalized_name, property, edge) \
YG_EDGE_PROPERTY_GETTER(YGValue, lowercased_name, capitalized_name, property, edge) \
YG_VALUE_EDGE_PROPERTY_SETTER(lowercased_name, capitalized_name, property, edge)
#define YG_VALUE_EDGES_PROPERTIES(lowercased_name, capitalized_name) \
YG_VALUE_EDGE_PROPERTY(lowercased_name##Left, capitalized_name##Left, capitalized_name, YGEdgeLeft) \
YG_VALUE_EDGE_PROPERTY(lowercased_name##Top, capitalized_name##Top, capitalized_name, YGEdgeTop) \
YG_VALUE_EDGE_PROPERTY(lowercased_name##Right, capitalized_name##Right, capitalized_name, YGEdgeRight) \
YG_VALUE_EDGE_PROPERTY(lowercased_name##Bottom, capitalized_name##Bottom, capitalized_name, YGEdgeBottom) \
YG_VALUE_EDGE_PROPERTY(lowercased_name##Start, capitalized_name##Start, capitalized_name, YGEdgeStart) \
YG_VALUE_EDGE_PROPERTY(lowercased_name##End, capitalized_name##End, capitalized_name, YGEdgeEnd) \
YG_VALUE_EDGE_PROPERTY(lowercased_name##Horizontal, capitalized_name##Horizontal, capitalized_name, YGEdgeHorizontal) \
YG_VALUE_EDGE_PROPERTY(lowercased_name##Vertical, capitalized_name##Vertical, capitalized_name, YGEdgeVertical) \
YG_VALUE_EDGE_PROPERTY(lowercased_name, capitalized_name, capitalized_name, YGEdgeAll)
YGValue YGPointValue(CGFloat value)
{
return (YGValue) { .value = value, .unit = YGUnitPoint };
}
YGValue YGPercentValue(CGFloat value)
{
return (YGValue) { .value = value, .unit = YGUnitPercent };
YGValue YGPercentValue(CGFloat value) {
return (YGValue){.value = value, .unit = YGUnitPercent};
}
static YGConfigRef globalConfig;
@interface YGLayout ()
@property (nonatomic, weak, readonly) UIView *view;
@property(nonatomic, weak, readonly) UIView* view;
@property(nonatomic, assign, readonly) BOOL isUIView;
@end
@implementation YGLayout
@synthesize isEnabled=_isEnabled;
@synthesize isIncludedInLayout=_isIncludedInLayout;
@synthesize node=_node;
@synthesize isEnabled = _isEnabled;
@synthesize isIncludedInLayout = _isIncludedInLayout;
@synthesize node = _node;
+ (void)initialize
{
+ (void)initialize {
globalConfig = YGConfigNew();
YGConfigSetExperimentalFeatureEnabled(globalConfig, YGExperimentalFeatureWebFlexBasis, true);
YGConfigSetExperimentalFeatureEnabled(
globalConfig, YGExperimentalFeatureWebFlexBasis, true);
YGConfigSetPointScaleFactor(globalConfig, [UIScreen mainScreen].scale);
}
- (instancetype)initWithView:(UIView*)view
{
- (instancetype)initWithView:(UIView*)view {
if (self = [super init]) {
_view = view;
_node = YGNodeNewWithConfig(globalConfig);
YGNodeSetContext(_node, (__bridge void *) view);
YGNodeSetContext(_node, (__bridge void*)view);
_isEnabled = NO;
_isIncludedInLayout = YES;
_isUIView = [view isMemberOfClass:[UIView class]];
@@ -160,18 +191,15 @@ static YGConfigRef globalConfig;
return self;
}
- (void)dealloc
{
- (void)dealloc {
YGNodeFree(self.node);
}
- (BOOL)isDirty
{
- (BOOL)isDirty {
return YGNodeIsDirty(self.node);
}
- (void)markDirty
{
- (void)markDirty {
if (self.isDirty || !self.isLeaf) {
return;
}
@@ -187,17 +215,17 @@ static YGConfigRef globalConfig;
YGNodeMarkDirty(node);
}
- (NSUInteger)numberOfChildren
{
- (NSUInteger)numberOfChildren {
return YGNodeGetChildCount(self.node);
}
- (BOOL)isLeaf
{
NSAssert([NSThread isMainThread], @"This method must be called on the main thread.");
- (BOOL)isLeaf {
NSAssert(
[NSThread isMainThread],
@"This method must be called on the main thread.");
if (self.isEnabled) {
for (UIView *subview in self.view.subviews) {
YGLayout *const yoga = subview.yoga;
for (UIView* subview in self.view.subviews) {
YGLayout* const yoga = subview.yoga;
if (yoga.isEnabled && yoga.isIncludedInLayout) {
return NO;
}
@@ -209,13 +237,11 @@ static YGConfigRef globalConfig;
#pragma mark - Style
- (YGPositionType)position
{
- (YGPositionType)position {
return YGNodeStyleGetPositionType(self.node);
}
- (void)setPosition:(YGPositionType)position
{
- (void)setPosition:(YGPositionType)position {
YGNodeStyleSetPositionType(self.node, position);
}
@@ -261,25 +287,23 @@ YG_PROPERTY(CGFloat, aspectRatio, AspectRatio)
#pragma mark - Layout and Sizing
- (YGDirection)resolvedDirection
{
- (YGDirection)resolvedDirection {
return YGNodeLayoutGetDirection(self.node);
}
- (void)applyLayout
{
- (void)applyLayout {
[self calculateLayoutWithSize:self.view.bounds.size];
YGApplyLayoutToViewHierarchy(self.view, NO);
}
- (void)applyLayoutPreservingOrigin:(BOOL)preserveOrigin
{
- (void)applyLayoutPreservingOrigin:(BOOL)preserveOrigin {
[self calculateLayoutWithSize:self.view.bounds.size];
YGApplyLayoutToViewHierarchy(self.view, preserveOrigin);
}
- (void)applyLayoutPreservingOrigin:(BOOL)preserveOrigin dimensionFlexibility:(YGDimensionFlexibility)dimensionFlexibility
{
- (void)applyLayoutPreservingOrigin:(BOOL)preserveOrigin
dimensionFlexibility:
(YGDimensionFlexibility)dimensionFlexibility {
CGSize size = self.view.bounds.size;
if (dimensionFlexibility & YGDimensionFlexibilityFlexibleWidth) {
size.width = YGUndefined;
@@ -291,18 +315,15 @@ YG_PROPERTY(CGFloat, aspectRatio, AspectRatio)
YGApplyLayoutToViewHierarchy(self.view, preserveOrigin);
}
- (CGSize)intrinsicSize
{
- (CGSize)intrinsicSize {
const CGSize constrainedSize = {
.width = YGUndefined,
.height = YGUndefined,
.width = YGUndefined,
.height = YGUndefined,
};
return [self calculateLayoutWithSize:constrainedSize];
}
- (CGSize)calculateLayoutWithSize:(CGSize)size
{
- (CGSize)calculateLayoutWithSize:(CGSize)size {
NSAssert([NSThread isMainThread], @"Yoga calculation must be done on main.");
NSAssert(self.isEnabled, @"Yoga is not enabled for this view.");
@@ -310,30 +331,28 @@ YG_PROPERTY(CGFloat, aspectRatio, AspectRatio)
const YGNodeRef node = self.node;
YGNodeCalculateLayout(
node,
size.width,
size.height,
YGNodeStyleGetDirection(node));
node, size.width, size.height, YGNodeStyleGetDirection(node));
return (CGSize) {
.width = YGNodeLayoutGetWidth(node),
.height = YGNodeLayoutGetHeight(node),
return (CGSize){
.width = YGNodeLayoutGetWidth(node),
.height = YGNodeLayoutGetHeight(node),
};
}
#pragma mark - Private
static YGSize YGMeasureView(
YGNodeRef node,
float width,
YGMeasureMode widthMode,
float height,
YGMeasureMode heightMode)
{
const CGFloat constrainedWidth = (widthMode == YGMeasureModeUndefined) ? CGFLOAT_MAX : width;
const CGFloat constrainedHeight = (heightMode == YGMeasureModeUndefined) ? CGFLOAT_MAX: height;
YGNodeRef node,
float width,
YGMeasureMode widthMode,
float height,
YGMeasureMode heightMode) {
const CGFloat constrainedWidth =
(widthMode == YGMeasureModeUndefined) ? CGFLOAT_MAX : width;
const CGFloat constrainedHeight =
(heightMode == YGMeasureModeUndefined) ? CGFLOAT_MAX : height;
UIView *view = (__bridge UIView*) YGNodeGetContext(node);
UIView* view = (__bridge UIView*)YGNodeGetContext(node);
CGSize sizeThatFits = CGSizeZero;
// The default implementation of sizeThatFits: returns the existing size of
@@ -349,17 +368,18 @@ static YGSize YGMeasureView(
}];
}
return (YGSize) {
.width = YGSanitizeMeasurement(constrainedWidth, sizeThatFits.width, widthMode),
.height = YGSanitizeMeasurement(constrainedHeight, sizeThatFits.height, heightMode),
return (YGSize){
.width = YGSanitizeMeasurement(
constrainedWidth, sizeThatFits.width, widthMode),
.height = YGSanitizeMeasurement(
constrainedHeight, sizeThatFits.height, heightMode),
};
}
static CGFloat YGSanitizeMeasurement(
CGFloat constrainedSize,
CGFloat measuredSize,
YGMeasureMode measureMode)
{
CGFloat constrainedSize,
CGFloat measuredSize,
YGMeasureMode measureMode) {
CGFloat result;
if (measureMode == YGMeasureModeExactly) {
result = constrainedSize;
@@ -372,13 +392,14 @@ static CGFloat YGSanitizeMeasurement(
return result;
}
static BOOL YGNodeHasExactSameChildren(const YGNodeRef node, NSArray<UIView *> *subviews)
{
static BOOL YGNodeHasExactSameChildren(
const YGNodeRef node,
NSArray<UIView*>* subviews) {
if (YGNodeGetChildCount(node) != subviews.count) {
return NO;
}
for (int i=0; i<subviews.count; i++) {
for (int i = 0; i < subviews.count; i++) {
if (YGNodeGetChild(node, i) != subviews[i].yoga.node) {
return NO;
}
@@ -387,9 +408,8 @@ static BOOL YGNodeHasExactSameChildren(const YGNodeRef node, NSArray<UIView *> *
return YES;
}
static void YGAttachNodesFromViewHierachy(UIView *const view)
{
YGLayout *const yoga = view.yoga;
static void YGAttachNodesFromViewHierachy(UIView* const view) {
YGLayout* const yoga = view.yoga;
const YGNodeRef node = yoga.node;
// Only leaf nodes should have a measure function
@@ -399,8 +419,9 @@ static void YGAttachNodesFromViewHierachy(UIView *const view)
} else {
YGNodeSetMeasureFunc(node, NULL);
NSMutableArray<UIView *> *subviewsToInclude = [[NSMutableArray alloc] initWithCapacity:view.subviews.count];
for (UIView *subview in view.subviews) {
NSMutableArray<UIView*>* subviewsToInclude =
[[NSMutableArray alloc] initWithCapacity:view.subviews.count];
for (UIView* subview in view.subviews) {
if (subview.yoga.isEnabled && subview.yoga.isIncludedInLayout) {
[subviewsToInclude addObject:subview];
}
@@ -408,19 +429,18 @@ static void YGAttachNodesFromViewHierachy(UIView *const view)
if (!YGNodeHasExactSameChildren(node, subviewsToInclude)) {
YGRemoveAllChildren(node);
for (int i=0; i<subviewsToInclude.count; i++) {
for (int i = 0; i < subviewsToInclude.count; i++) {
YGNodeInsertChild(node, subviewsToInclude[i].yoga.node, i);
}
}
for (UIView *const subview in subviewsToInclude) {
for (UIView* const subview in subviewsToInclude) {
YGAttachNodesFromViewHierachy(subview);
}
}
}
static void YGRemoveAllChildren(const YGNodeRef node)
{
static void YGRemoveAllChildren(const YGNodeRef node) {
if (node == NULL) {
return;
}
@@ -428,52 +448,56 @@ static void YGRemoveAllChildren(const YGNodeRef node)
YGNodeRemoveAllChildren(node);
}
static CGFloat YGRoundPixelValue(CGFloat value)
{
static CGFloat YGRoundPixelValue(CGFloat value) {
static CGFloat scale;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^(){
dispatch_once(&onceToken, ^() {
scale = [UIScreen mainScreen].scale;
});
return roundf(value * scale) / scale;
}
static void YGApplyLayoutToViewHierarchy(UIView *view, BOOL preserveOrigin)
{
NSCAssert([NSThread isMainThread], @"Framesetting should only be done on the main thread.");
static void YGApplyLayoutToViewHierarchy(UIView* view, BOOL preserveOrigin) {
NSCAssert(
[NSThread isMainThread],
@"Framesetting should only be done on the main thread.");
const YGLayout *yoga = view.yoga;
const YGLayout* yoga = view.yoga;
if (!yoga.isIncludedInLayout) {
return;
return;
}
YGNodeRef node = yoga.node;
const CGPoint topLeft = {
YGNodeLayoutGetLeft(node),
YGNodeLayoutGetTop(node),
YGNodeLayoutGetLeft(node),
YGNodeLayoutGetTop(node),
};
const CGPoint bottomRight = {
topLeft.x + YGNodeLayoutGetWidth(node),
topLeft.y + YGNodeLayoutGetHeight(node),
topLeft.x + YGNodeLayoutGetWidth(node),
topLeft.y + YGNodeLayoutGetHeight(node),
};
const CGPoint origin = preserveOrigin ? view.frame.origin : CGPointZero;
view.frame = (CGRect) {
.origin = {
.x = YGRoundPixelValue(topLeft.x + origin.x),
.y = YGRoundPixelValue(topLeft.y + origin.y),
},
.size = {
.width = YGRoundPixelValue(bottomRight.x) - YGRoundPixelValue(topLeft.x),
.height = YGRoundPixelValue(bottomRight.y) - YGRoundPixelValue(topLeft.y),
},
view.frame = (CGRect){
.origin =
{
.x = YGRoundPixelValue(topLeft.x + origin.x),
.y = YGRoundPixelValue(topLeft.y + origin.y),
},
.size =
{
.width = YGRoundPixelValue(bottomRight.x) -
YGRoundPixelValue(topLeft.x),
.height = YGRoundPixelValue(bottomRight.y) -
YGRoundPixelValue(topLeft.y),
},
};
if (!yoga.isLeaf) {
for (NSUInteger i=0; i<view.subviews.count; i++) {
for (NSUInteger i = 0; i < view.subviews.count; i++) {
YGApplyLayoutToViewHierarchy(view.subviews[i], NO);
}
}

View File

@@ -5,6 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/
import yoga;
postfix operator %
extension Int {
@@ -29,15 +30,15 @@ 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)
}

View File

@@ -16,17 +16,15 @@
@implementation YogaKitTests
- (void)testConfigureLayoutIsNoOpWithNilBlock
{
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
- (void)testConfigureLayoutIsNoOpWithNilBlock {
UIView* view = [[UIView alloc] initWithFrame:CGRectZero];
id block = nil;
XCTAssertNoThrow([view configureLayoutWithBlock:block]);
}
- (void)testConfigureLayoutBlockWorksWithValidBlock
{
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
[view configureLayoutWithBlock:^(YGLayout *layout){
- (void)testConfigureLayoutBlockWorksWithValidBlock {
UIView* view = [[UIView alloc] initWithFrame:CGRectZero];
[view configureLayoutWithBlock:^(YGLayout* layout) {
XCTAssertNotNil(layout);
layout.isEnabled = YES;
layout.width = YGPointValue(25);
@@ -36,12 +34,11 @@
XCTAssertEqual(view.yoga.width.value, 25);
}
- (void)testNodesAreDeallocedWithSingleView
{
__weak YGLayout *layoutRef = nil;
- (void)testNodesAreDeallocedWithSingleView {
__weak YGLayout* layoutRef = nil;
@autoreleasepool {
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
UIView* view = [[UIView alloc] initWithFrame:CGRectZero];
view.yoga.flexBasis = YGPointValue(1);
layoutRef = view.yoga;
@@ -53,17 +50,16 @@
XCTAssertNil(layoutRef);
}
- (void)testNodesAreDeallocedCascade
{
__weak YGLayout *topLayout = nil;
__weak YGLayout *subviewLayout = nil;
- (void)testNodesAreDeallocedCascade {
__weak YGLayout* topLayout = nil;
__weak YGLayout* subviewLayout = nil;
@autoreleasepool {
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
UIView* view = [[UIView alloc] initWithFrame:CGRectZero];
topLayout = view.yoga;
topLayout.flexBasis = YGPointValue(1);
UIView *subview = [[UIView alloc] initWithFrame:CGRectZero];
UIView* subview = [[UIView alloc] initWithFrame:CGRectZero];
subviewLayout = subview.yoga;
subviewLayout.flexBasis = YGPointValue(1);
@@ -74,9 +70,8 @@
XCTAssertNil(subviewLayout);
}
- (void)testIsEnabled
{
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
- (void)testIsEnabled {
UIView* view = [[UIView alloc] initWithFrame:CGRectZero];
XCTAssertFalse(view.yoga.isEnabled);
view.yoga.isEnabled = YES;
@@ -86,30 +81,31 @@
XCTAssertFalse(view.yoga.isEnabled);
}
- (void)testSizeThatFitsAsserts
{
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
dispatch_sync(dispatch_queue_create("com.facebook.Yoga.testing", DISPATCH_QUEUE_SERIAL), ^(void){
XCTAssertThrows(view.yoga.intrinsicSize);
});
- (void)testSizeThatFitsAsserts {
UIView* view = [[UIView alloc] initWithFrame:CGRectZero];
dispatch_sync(
dispatch_queue_create("com.facebook.Yoga.testing", DISPATCH_QUEUE_SERIAL),
^(void) {
XCTAssertThrows(view.yoga.intrinsicSize);
});
}
- (void)testSizeThatFitsSmoke
{
UIView *container = [[UIView alloc] initWithFrame:CGRectZero];
- (void)testSizeThatFitsSmoke {
UIView* container = [[UIView alloc] initWithFrame:CGRectZero];
container.yoga.isEnabled = YES;
container.yoga.flexDirection = YGFlexDirectionRow;
container.yoga.alignItems = YGAlignFlexStart;
UILabel *longTextLabel = [[UILabel alloc] initWithFrame:CGRectZero];
longTextLabel.text = @"This is a very very very very very very very very long piece of text.";
UILabel* longTextLabel = [[UILabel alloc] initWithFrame:CGRectZero];
longTextLabel.text =
@"This is a very very very very very very very very long piece of text.";
longTextLabel.lineBreakMode = NSLineBreakByTruncatingTail;
longTextLabel.numberOfLines = 1;
longTextLabel.yoga.isEnabled = YES;
longTextLabel.yoga.flexShrink = 1;
[container addSubview:longTextLabel];
UIView *textBadgeView = [[UIView alloc] initWithFrame:CGRectZero];
UIView* textBadgeView = [[UIView alloc] initWithFrame:CGRectZero];
textBadgeView.yoga.isEnabled = YES;
textBadgeView.yoga.margin = YGPointValue(0);
textBadgeView.yoga.width = YGPointValue(10);
@@ -124,7 +120,9 @@
const CGSize longTextLabelSize = longTextLabel.yoga.intrinsicSize;
XCTAssertEqual(longTextLabelSize.height, containerSize.height);
XCTAssertEqual(longTextLabelSize.width + textBadgeView.yoga.intrinsicSize.width, containerSize.width);
XCTAssertEqual(
longTextLabelSize.width + textBadgeView.yoga.intrinsicSize.width,
containerSize.width);
}
- (void)testSizeThatFitsEmptyView {
@@ -136,18 +134,17 @@
XCTAssertEqual(viewSize.width, 0);
}
- (void)testPreservingOrigin
{
UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0,0,50,75)];
- (void)testPreservingOrigin {
UIView* container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 50, 75)];
container.yoga.isEnabled = YES;
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
UIView* view = [[UIView alloc] initWithFrame:CGRectZero];
view.yoga.isEnabled = YES;
view.yoga.flexBasis = YGPointValue(0);
view.yoga.flexGrow = 1;
[container addSubview:view];
UIView *view2 = [[UIView alloc] initWithFrame:CGRectZero];
UIView* view2 = [[UIView alloc] initWithFrame:CGRectZero];
view2.yoga.isEnabled = YES;
view2.yoga.marginTop = YGPointValue(25);
view2.yoga.flexBasis = YGPointValue(0);
@@ -161,28 +158,28 @@
XCTAssertEqual(25, view2.frame.origin.y);
}
- (void)testContainerWithFlexibleWidthGetsCorrectlySized
{
UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0,0,200,200)];
- (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)];
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];
[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)];
- (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)];
UIView* view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
view.yoga.isEnabled = YES;
view.yoga.width = YGPointValue(100);
view.yoga.height = YGPointValue(100);
@@ -195,12 +192,11 @@
XCTAssertEqual(100, container.frame.size.height);
}
- (void)testContainerWithFlexibleWidthAndHeightGetsCorrectlySized
{
UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0,0,200,200)];
- (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)];
UIView* view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
view.yoga.isEnabled = YES;
view.yoga.width = YGPointValue(100);
view.yoga.height = YGPointValue(100);
@@ -214,12 +210,11 @@
XCTAssertEqual(100, container.frame.size.height);
}
- (void)testMarkingDirtyOnlyWorksOnLeafNodes
{
UIView *container = [[UIView alloc] initWithFrame:CGRectZero];
- (void)testMarkingDirtyOnlyWorksOnLeafNodes {
UIView* container = [[UIView alloc] initWithFrame:CGRectZero];
container.yoga.isEnabled = YES;
UIView *subview = [[UIView alloc] initWithFrame:CGRectZero];
UIView* subview = [[UIView alloc] initWithFrame:CGRectZero];
subview.yoga.isEnabled = YES;
[container addSubview:subview];
@@ -232,14 +227,13 @@
XCTAssertTrue(subview.yoga.isDirty);
}
- (void)testThatMarkingLeafsAsDirtyWillTriggerASizeRecalculation
{
UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 50)];
- (void)testThatMarkingLeafsAsDirtyWillTriggerASizeRecalculation {
UIView* container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 50)];
container.yoga.isEnabled = YES;
container.yoga.flexDirection = YGFlexDirectionRow;
container.yoga.alignItems = YGAlignFlexStart;
UILabel *view = [[UILabel alloc] initWithFrame:CGRectZero];
UILabel* view = [[UILabel alloc] initWithFrame:CGRectZero];
view.text = @"This is a short text.";
view.numberOfLines = 1;
view.yoga.isEnabled = YES;
@@ -257,61 +251,70 @@
XCTAssertFalse(CGSizeEqualToSize(view.frame.size, viewSizeAfterFirstPass));
}
- (void)testFrameAndOriginPlacement
{
- (void)testFrameAndOriginPlacement {
const CGSize containerSize = CGSizeMake(320, 50);
UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, containerSize.width, containerSize.height)];
UIView* container = [[UIView alloc]
initWithFrame:CGRectMake(
0, 0, containerSize.width, containerSize.height)];
container.yoga.isEnabled = YES;
container.yoga.flexDirection = YGFlexDirectionRow;
UIView *subview1 = [[UIView alloc] initWithFrame:CGRectZero];
UIView* subview1 = [[UIView alloc] initWithFrame:CGRectZero];
subview1.yoga.isEnabled = YES;
subview1.yoga.flexGrow = 1;
[container addSubview:subview1];
UIView *subview2 = [[UIView alloc] initWithFrame:CGRectZero];
UIView* subview2 = [[UIView alloc] initWithFrame:CGRectZero];
subview2.yoga.isEnabled = YES;
subview2.yoga.flexGrow = 1;
[container addSubview:subview2];
UIView *subview3 = [[UIView alloc] initWithFrame:CGRectZero];
UIView* subview3 = [[UIView alloc] initWithFrame:CGRectZero];
subview3.yoga.isEnabled = YES;
subview3.yoga.flexGrow = 1;
[container addSubview:subview3];
[container.yoga applyLayoutPreservingOrigin:YES];
XCTAssertEqualWithAccuracy(subview2.frame.origin.x, CGRectGetMaxX(subview1.frame), FLT_EPSILON);
XCTAssertEqualWithAccuracy(subview3.frame.origin.x, CGRectGetMaxX(subview2.frame), FLT_EPSILON);
XCTAssertEqualWithAccuracy(
subview2.frame.origin.x, CGRectGetMaxX(subview1.frame), FLT_EPSILON);
XCTAssertEqualWithAccuracy(
subview3.frame.origin.x, CGRectGetMaxX(subview2.frame), FLT_EPSILON);
CGFloat totalWidth = 0;
for (UIView *view in container.subviews) {
for (UIView* view in container.subviews) {
totalWidth += view.bounds.size.width;
}
XCTAssertEqual(containerSize.width, totalWidth, @"The container's width is %.6f, the subviews take up %.6f", containerSize.width, totalWidth);
XCTAssertEqual(
containerSize.width,
totalWidth,
@"The container's width is %.6f, the subviews take up %.6f",
containerSize.width,
totalWidth);
}
- (void)testThatLayoutIsCorrectWhenWeSwapViewOrder
{
- (void)testThatLayoutIsCorrectWhenWeSwapViewOrder {
const CGSize containerSize = CGSizeMake(300, 50);
UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, containerSize.width, containerSize.height)];
UIView* container = [[UIView alloc]
initWithFrame:CGRectMake(
0, 0, containerSize.width, containerSize.height)];
container.yoga.isEnabled = YES;
container.yoga.flexDirection = YGFlexDirectionRow;
UIView *subview1 = [[UIView alloc] initWithFrame:CGRectZero];
UIView* subview1 = [[UIView alloc] initWithFrame:CGRectZero];
subview1.yoga.isEnabled = YES;
subview1.yoga.flexGrow = 1;
[container addSubview:subview1];
UIView *subview2 = [[UIView alloc] initWithFrame:CGRectZero];
UIView* subview2 = [[UIView alloc] initWithFrame:CGRectZero];
subview2.yoga.isEnabled = YES;
subview2.yoga.flexGrow = 1;
[container addSubview:subview2];
UIView *subview3 = [[UIView alloc] initWithFrame:CGRectZero];
UIView* subview3 = [[UIView alloc] initWithFrame:CGRectZero];
subview3.yoga.isEnabled = YES;
subview3.yoga.flexGrow = 1;
[container addSubview:subview3];
@@ -333,32 +336,33 @@
XCTAssertTrue(CGRectEqualToRect(subview2.frame, CGRectMake(100, 0, 100, 50)));
}
- (void)testThatWeRespectIncludeInLayoutFlag
{
- (void)testThatWeRespectIncludeInLayoutFlag {
const CGSize containerSize = CGSizeMake(300, 50);
UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, containerSize.width, containerSize.height)];
UIView* container = [[UIView alloc]
initWithFrame:CGRectMake(
0, 0, containerSize.width, containerSize.height)];
container.yoga.isEnabled = YES;
container.yoga.flexDirection = YGFlexDirectionRow;
UIView *subview1 = [[UIView alloc] initWithFrame:CGRectZero];
UIView* subview1 = [[UIView alloc] initWithFrame:CGRectZero];
subview1.yoga.isEnabled = YES;
subview1.yoga.flexGrow = 1;
[container addSubview:subview1];
UIView *subview2 = [[UIView alloc] initWithFrame:CGRectZero];
UIView* subview2 = [[UIView alloc] initWithFrame:CGRectZero];
subview2.yoga.isEnabled = YES;
subview2.yoga.flexGrow = 1;
[container addSubview:subview2];
UIView *subview3 = [[UIView alloc] initWithFrame:CGRectZero];
UIView* subview3 = [[UIView alloc] initWithFrame:CGRectZero];
subview3.yoga.isEnabled = YES;
subview3.yoga.flexGrow = 1;
[container addSubview:subview3];
[container.yoga applyLayoutPreservingOrigin:YES];
for (UIView *subview in container.subviews) {
for (UIView* subview in container.subviews) {
XCTAssertEqual(subview.bounds.size.width, 100);
}
@@ -368,27 +372,27 @@
XCTAssertEqual(subview1.bounds.size.width, 150);
XCTAssertEqual(subview2.bounds.size.width, 150);
// We don't set the frame to zero, so, it should be set to what it was previously at.
// We don't set the frame to zero, so, it should be set to what it was
// previously at.
XCTAssertEqual(subview3.bounds.size.width, 100);
}
- (void)testThatNumberOfChildrenIsCorrectWhenWeIgnoreSubviews
{
UIView *container = [[UIView alloc] initWithFrame:CGRectZero];
- (void)testThatNumberOfChildrenIsCorrectWhenWeIgnoreSubviews {
UIView* container = [[UIView alloc] initWithFrame:CGRectZero];
container.yoga.isEnabled = YES;
container.yoga.flexDirection = YGFlexDirectionRow;
UIView *subview1 = [[UIView alloc] initWithFrame:CGRectZero];
UIView* subview1 = [[UIView alloc] initWithFrame:CGRectZero];
subview1.yoga.isEnabled = YES;
subview1.yoga.isIncludedInLayout = NO;
[container addSubview:subview1];
UIView *subview2 = [[UIView alloc] initWithFrame:CGRectZero];
UIView* subview2 = [[UIView alloc] initWithFrame:CGRectZero];
subview2.yoga.isEnabled = YES;
subview2.yoga.isIncludedInLayout = NO;
[container addSubview:subview2];
UIView *subview3 = [[UIView alloc] initWithFrame:CGRectZero];
UIView* subview3 = [[UIView alloc] initWithFrame:CGRectZero];
subview3.yoga.isEnabled = YES;
subview3.yoga.isIncludedInLayout = YES;
[container addSubview:subview3];
@@ -401,23 +405,22 @@
XCTAssertEqual(container.yoga.numberOfChildren, 2);
}
- (void)testThatViewNotIncludedInFirstLayoutPassAreIncludedInSecond
{
UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 50)];
- (void)testThatViewNotIncludedInFirstLayoutPassAreIncludedInSecond {
UIView* container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 50)];
container.yoga.isEnabled = YES;
container.yoga.flexDirection = YGFlexDirectionRow;
UIView *subview1 = [[UIView alloc] initWithFrame:CGRectZero];
UIView* subview1 = [[UIView alloc] initWithFrame:CGRectZero];
subview1.yoga.isEnabled = YES;
subview1.yoga.flexGrow = 1;
[container addSubview:subview1];
UIView *subview2 = [[UIView alloc] initWithFrame:CGRectZero];
UIView* subview2 = [[UIView alloc] initWithFrame:CGRectZero];
subview2.yoga.isEnabled = YES;
subview2.yoga.flexGrow = 1;
[container addSubview:subview2];
UIView *subview3 = [[UIView alloc] initWithFrame:CGRectZero];
UIView* subview3 = [[UIView alloc] initWithFrame:CGRectZero];
subview3.yoga.isEnabled = YES;
subview3.yoga.flexGrow = 1;
subview3.yoga.isIncludedInLayout = NO;
@@ -437,13 +440,12 @@
XCTAssertEqual(subview3.bounds.size.width, 100);
}
- (void)testIsLeafFlag
{
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
- (void)testIsLeafFlag {
UIView* view = [[UIView alloc] initWithFrame:CGRectZero];
XCTAssertTrue(view.yoga.isLeaf);
for (int i=0; i<10; i++) {
UIView *subview = [[UIView alloc] initWithFrame:CGRectZero];
for (int i = 0; i < 10; i++) {
UIView* subview = [[UIView alloc] initWithFrame:CGRectZero];
[view addSubview:subview];
}
XCTAssertTrue(view.yoga.isLeaf);
@@ -452,99 +454,95 @@
view.yoga.width = YGPointValue(50);
XCTAssertTrue(view.yoga.isLeaf);
UIView *const subview = view.subviews[0];
UIView* const subview = view.subviews[0];
subview.yoga.isEnabled = YES;
subview.yoga.width = YGPointValue(50);
XCTAssertFalse(view.yoga.isLeaf);
}
- (void)testThatWeCorrectlyAttachNestedViews
{
UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 50)];
container.yoga.isEnabled = YES;
container.yoga.flexDirection = YGFlexDirectionColumn;
- (void)testThatWeCorrectlyAttachNestedViews {
UIView* container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 50)];
container.yoga.isEnabled = YES;
container.yoga.flexDirection = YGFlexDirectionColumn;
UIView *subview1 = [[UIView alloc] initWithFrame:CGRectZero];
subview1.yoga.isEnabled = YES;
subview1.yoga.width = YGPointValue(100);
subview1.yoga.flexGrow = 1;
subview1.yoga.flexDirection = YGFlexDirectionColumn;
[container addSubview:subview1];
UIView* subview1 = [[UIView alloc] initWithFrame:CGRectZero];
subview1.yoga.isEnabled = YES;
subview1.yoga.width = YGPointValue(100);
subview1.yoga.flexGrow = 1;
subview1.yoga.flexDirection = YGFlexDirectionColumn;
[container addSubview:subview1];
UIView *subview2 = [[UIView alloc] initWithFrame:CGRectZero];
subview2.yoga.isEnabled = YES;
subview2.yoga.width = YGPointValue(150);
subview2.yoga.flexGrow = 1;
subview2.yoga.flexDirection = YGFlexDirectionColumn;
[container addSubview:subview2];
UIView* subview2 = [[UIView alloc] initWithFrame:CGRectZero];
subview2.yoga.isEnabled = YES;
subview2.yoga.width = YGPointValue(150);
subview2.yoga.flexGrow = 1;
subview2.yoga.flexDirection = YGFlexDirectionColumn;
[container addSubview:subview2];
for (UIView *view in @[subview1, subview2]) {
UIView *someView = [[UIView alloc] initWithFrame:CGRectZero];
someView.yoga.isEnabled = YES;
someView.yoga.flexGrow = 1;
[view addSubview:someView];
}
[container.yoga applyLayoutPreservingOrigin:YES];
for (UIView* view in @[ subview1, subview2 ]) {
UIView* someView = [[UIView alloc] initWithFrame:CGRectZero];
someView.yoga.isEnabled = YES;
someView.yoga.flexGrow = 1;
[view addSubview:someView];
}
[container.yoga applyLayoutPreservingOrigin:YES];
// Add the same amount of new views, reapply layout.
for (UIView *view in @[subview1, subview2]) {
UIView *someView = [[UIView alloc] initWithFrame:CGRectZero];
someView.yoga.isEnabled = YES;
someView.yoga.flexGrow = 1;
[view addSubview:someView];
}
[container.yoga applyLayoutPreservingOrigin:YES];
// Add the same amount of new views, reapply layout.
for (UIView* view in @[ subview1, subview2 ]) {
UIView* someView = [[UIView alloc] initWithFrame:CGRectZero];
someView.yoga.isEnabled = YES;
someView.yoga.flexGrow = 1;
[view addSubview:someView];
}
[container.yoga applyLayoutPreservingOrigin:YES];
XCTAssertEqual(subview1.bounds.size.width, 100);
XCTAssertEqual(subview1.bounds.size.height, 25);
for (UIView *subview in subview1.subviews) {
const CGSize subviewSize = subview.bounds.size;
XCTAssertNotEqual(subviewSize.width, 0);
XCTAssertNotEqual(subviewSize.height, 0);
XCTAssertFalse(isnan(subviewSize.height));
XCTAssertFalse(isnan(subviewSize.width));
}
XCTAssertEqual(subview1.bounds.size.width, 100);
XCTAssertEqual(subview1.bounds.size.height, 25);
for (UIView* subview in subview1.subviews) {
const CGSize subviewSize = subview.bounds.size;
XCTAssertNotEqual(subviewSize.width, 0);
XCTAssertNotEqual(subviewSize.height, 0);
XCTAssertFalse(isnan(subviewSize.height));
XCTAssertFalse(isnan(subviewSize.width));
}
XCTAssertEqual(subview2.bounds.size.width, 150);
XCTAssertEqual(subview2.bounds.size.height, 25);
for (UIView *subview in subview2.subviews) {
const CGSize subviewSize = subview.bounds.size;
XCTAssertNotEqual(subviewSize.width, 0);
XCTAssertNotEqual(subviewSize.height, 0);
XCTAssertFalse(isnan(subviewSize.height));
XCTAssertFalse(isnan(subviewSize.width));
}
XCTAssertEqual(subview2.bounds.size.width, 150);
XCTAssertEqual(subview2.bounds.size.height, 25);
for (UIView* subview in subview2.subviews) {
const CGSize subviewSize = subview.bounds.size;
XCTAssertNotEqual(subviewSize.width, 0);
XCTAssertNotEqual(subviewSize.height, 0);
XCTAssertFalse(isnan(subviewSize.height));
XCTAssertFalse(isnan(subviewSize.width));
}
}
- (void)testThatANonLeafNodeCanBecomeALeafNode
{
UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 50)];
container.yoga.isEnabled = YES;
- (void)testThatANonLeafNodeCanBecomeALeafNode {
UIView* container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 50)];
container.yoga.isEnabled = YES;
UIView *subview1 = [[UIView alloc] initWithFrame:CGRectZero];
subview1.yoga.isEnabled = YES;
[container addSubview:subview1];
UIView* subview1 = [[UIView alloc] initWithFrame:CGRectZero];
subview1.yoga.isEnabled = YES;
[container addSubview:subview1];
UIView *subview2 = [[UIView alloc] initWithFrame:CGRectZero];
subview2.yoga.isEnabled = YES;
[subview1 addSubview:subview2];
UIView* subview2 = [[UIView alloc] initWithFrame:CGRectZero];
subview2.yoga.isEnabled = YES;
[subview1 addSubview:subview2];
[container.yoga applyLayoutPreservingOrigin:YES];
[subview2 removeFromSuperview];
[container.yoga applyLayoutPreservingOrigin:YES];
[container.yoga applyLayoutPreservingOrigin:YES];
[subview2 removeFromSuperview];
[container.yoga applyLayoutPreservingOrigin:YES];
}
- (void)testPointPercent
{
- (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];
- (void)testPositionalPropertiesWork {
UIView* view = [[UIView alloc] initWithFrame:CGRectZero];
view.yoga.left = YGPointValue(1);
XCTAssertEqual(view.yoga.left.value, 1);
@@ -589,9 +587,8 @@
XCTAssertEqual(view.yoga.end.unit, YGUnitPercent);
}
- (void)testMarginPropertiesWork
{
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
- (void)testMarginPropertiesWork {
UIView* view = [[UIView alloc] initWithFrame:CGRectZero];
view.yoga.margin = YGPointValue(1);
XCTAssertEqual(view.yoga.margin.value, 1);
@@ -657,9 +654,8 @@
XCTAssertEqual(view.yoga.marginEnd.unit, YGUnitPercent);
}
- (void)testPaddingPropertiesWork
{
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
- (void)testPaddingPropertiesWork {
UIView* view = [[UIView alloc] initWithFrame:CGRectZero];
view.yoga.padding = YGPointValue(1);
XCTAssertEqual(view.yoga.padding.value, 1);
@@ -725,9 +721,8 @@
XCTAssertEqual(view.yoga.paddingEnd.unit, YGUnitPercent);
}
- (void)testBorderWidthPropertiesWork
{
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
- (void)testBorderWidthPropertiesWork {
UIView* view = [[UIView alloc] initWithFrame:CGRectZero];
view.yoga.borderWidth = 1;
XCTAssertEqual(view.yoga.borderWidth, 1);

View File

@@ -11,45 +11,41 @@
@implementation ViewController
- (void)viewDidLoad
{
UIView *root = self.view;
root.backgroundColor = [UIColor redColor];
root.yoga.isEnabled = YES;
root.yoga.width = YGPointValue(self.view.bounds.size.width);
root.yoga.height = YGPointValue(self.view.bounds.size.height);
root.yoga.alignItems = YGAlignCenter;
root.yoga.justifyContent = YGJustifyCenter;
- (void)viewDidLoad {
UIView* root = self.view;
root.backgroundColor = [UIColor redColor];
root.yoga.isEnabled = YES;
root.yoga.width = YGPointValue(self.view.bounds.size.width);
root.yoga.height = YGPointValue(self.view.bounds.size.height);
root.yoga.alignItems = YGAlignCenter;
root.yoga.justifyContent = YGJustifyCenter;
UIView *child1 = [UIView new];
child1.backgroundColor = [UIColor blueColor];
child1.yoga.isEnabled = YES;
child1.yoga.width = YGPointValue(100);
child1.yoga.height = YGPointValue(100);
UIView* child1 = [UIView new];
child1.backgroundColor = [UIColor blueColor];
child1.yoga.isEnabled = YES;
child1.yoga.width = YGPointValue(100);
child1.yoga.height = YGPointValue(100);
UIView *child2 = [UIView new];
child2.backgroundColor = [UIColor greenColor];
child2.frame = (CGRect) {
.size = {
.width = 200,
.height = 100,
}
};
UIView* child2 = [UIView new];
child2.backgroundColor = [UIColor greenColor];
child2.frame = (CGRect){
.size = {
.width = 200,
.height = 100,
}};
UIView *child3 = [UIView new];
child3.backgroundColor = [UIColor yellowColor];
child3.frame = (CGRect) {
.size = {
.width = 100,
.height = 100,
}
};
UIView* child3 = [UIView new];
child3.backgroundColor = [UIColor yellowColor];
child3.frame = (CGRect){
.size = {
.width = 100,
.height = 100,
}};
[child2 addSubview:child3];
[root addSubview:child1];
[root addSubview:child2];
[root.yoga applyLayoutPreservingOrigin:NO];
[child2 addSubview:child3];
[root addSubview:child1];
[root addSubview:child2];
[root.yoga applyLayoutPreservingOrigin:NO];
}
@end

View File

@@ -3,10 +3,11 @@
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
load("//tools/build_defs/oss:yoga_defs.bzl", "ANDROID_JAVA_TARGET", "ANDROID_RES_TARGET", "JAVA_TARGET", "PROGRUARD_ANNOTATIONS_TARGET", "yoga_android_aar", "yoga_android_resource")
load("//tools/build_defs/oss:yoga_defs.bzl", "ANDROID_JAVA_TARGET", "ANDROID_RES_TARGET", "JAVA_TARGET", "PROGUARD_ANNOTATIONS_TARGET", "yoga_android_aar", "yoga_android_resource")
yoga_android_aar(
name = "android",
enable_relinker = True,
manifest_skeleton = "src/main/AndroidManifest.xml",
visibility = [
"PUBLIC",
@@ -15,7 +16,7 @@ yoga_android_aar(
ANDROID_JAVA_TARGET,
ANDROID_RES_TARGET,
JAVA_TARGET,
PROGRUARD_ANNOTATIONS_TARGET,
PROGUARD_ANNOTATIONS_TARGET,
],
)

View File

@@ -5,17 +5,12 @@
* LICENSE file in the root directory of this source tree.
*/
apply plugin: 'com.jfrog.bintray'
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'maven-publish'
version = VERSION_NAME
group = GROUP
android {
compileSdkVersion rootProject.compileSdkVersion
buildToolsVersion rootProject.buildToolsVersion
ndkVersion rootProject.ndkVersion
defaultConfig {
minSdkVersion rootProject.minSdkVersion
@@ -32,21 +27,10 @@ dependencies {
api project(':yoga')
}
task sourcesJar(type: Jar) {
classifier = 'source'
from android.sourceSets.main.java.srcDirs
// We don't build Javadoc at this time as we can't disable "BUCK" files
// from mistakenly getting parsed as Java.
tasks.withType(Javadoc).all {
enabled = false
}
task javadoc(type: Javadoc) {
failOnError false
source = android.sourceSets.main.java.sourceFiles
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
classpath += configurations.compile
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
apply from: rootProject.file('gradle/release.gradle')
apply plugin: 'com.vanniktech.maven.publish'

View File

@@ -8,6 +8,7 @@ load("//tools/build_defs/oss:yoga_defs.bzl", "ANDROID_JAVA_TARGET", "ANDROID_SAM
yoga_android_library(
name = "yoga",
srcs = glob(["**/*.java"]),
autoglob = False,
visibility = [
"PUBLIC",
],

View File

@@ -8,6 +8,7 @@ load("//tools/build_defs/oss:yoga_defs.bzl", "ANDROID_RES_TARGET", "INFER_ANNOTA
yoga_android_library(
name = "android",
srcs = glob(["**/*.java"]),
autoglob = False,
visibility = [
"PUBLIC",
],

View File

@@ -10,14 +10,11 @@
buildscript {
repositories {
google()
jcenter()
maven { url 'https://maven.google.com/' }
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.0'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
classpath 'com.android.tools.build:gradle:4.2.1'
classpath 'com.vanniktech:gradle-maven-publish-plugin:0.15.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
@@ -26,15 +23,16 @@ buildscript {
allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}
ext {
minSdkVersion = 14
targetSdkVersion = 25
compileSdkVersion = 26
buildToolsVersion = '28.0.3'
targetSdkVersion = 29
compileSdkVersion = 29
buildToolsVersion = '30.0.2'
ndkVersion = '21.3.6528147'
sourceCompatibilityVersion = JavaVersion.VERSION_1_7
targetCompatibilityVersion = JavaVersion.VERSION_1_7
}

View File

@@ -9,11 +9,12 @@
static YGInteropLogger gManagedLogger;
static int unmanagedLogger(const YGConfigRef config,
const YGNodeRef node,
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 (gManagedLogger) {
char message[8192];

View File

@@ -11,10 +11,11 @@
YG_EXTERN_C_BEGIN
typedef int (*YGInteropLogger)(const void *unmanagedConfigPtr,
const void *unmanagedNodePtr,
YGLogLevel level,
const char *message);
typedef int (*YGInteropLogger)(
const void* unmanagedConfigPtr,
const void* unmanagedNodePtr,
YGLogLevel level,
const char* message);
WIN_EXPORT YGConfigRef YGConfigGetDefault();

View File

@@ -36,7 +36,7 @@
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
@@ -48,7 +48,7 @@
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
@@ -62,13 +62,13 @@
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
@@ -227,6 +227,8 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="..\..\yoga\event\event.h" />
<ClInclude Include="..\..\yoga\log.h" />
<ClInclude Include="..\..\yoga\Utils.h" />
<ClInclude Include="..\..\yoga\YGConfig.h" />
<ClInclude Include="..\..\yoga\YGEnums.h" />
@@ -236,6 +238,7 @@
<ClInclude Include="..\..\yoga\YGNode.h" />
<ClInclude Include="..\..\yoga\YGNodePrint.h" />
<ClInclude Include="..\..\yoga\YGStyle.h" />
<ClInclude Include="..\..\yoga\YGValue.h" />
<ClInclude Include="..\..\yoga\Yoga-internal.h" />
<ClInclude Include="..\..\yoga\Yoga.h" />
<ClInclude Include="resource.h" />
@@ -243,14 +246,16 @@
<ClInclude Include="targetver.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\yoga\event\event.cpp" />
<ClCompile Include="..\..\yoga\log.cpp" />
<ClCompile Include="..\..\yoga\Utils.cpp" />
<ClCompile Include="..\..\yoga\YGConfig.cpp" />
<ClCompile Include="..\..\yoga\YGEnums.cpp" />
<ClCompile Include="..\..\yoga\YGFloatOptional.cpp" />
<ClCompile Include="..\..\yoga\YGLayout.cpp" />
<ClCompile Include="..\..\yoga\YGNode.cpp" />
<ClCompile Include="..\..\yoga\YGNodePrint.cpp" />
<ClCompile Include="..\..\yoga\YGStyle.cpp" />
<ClCompile Include="..\..\yoga\YGValue.cpp" />
<ClCompile Include="..\..\yoga\Yoga.cpp" />
<ClCompile Include="YGInterop.cpp" />
<ClCompile Include="dllmain.cpp">

View File

@@ -1,104 +1,119 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="stdafx.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="targetver.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="resource.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\yoga\Utils.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\yoga\YGEnums.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\yoga\YGFloatOptional.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\yoga\YGLayout.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\yoga\YGMacros.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\yoga\YGNode.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\yoga\YGNodePrint.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\yoga\YGStyle.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\yoga\Yoga.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\yoga\Yoga-internal.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\yoga\YGConfig.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="stdafx.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="dllmain.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="YGInterop.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\yoga\Utils.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\yoga\YGEnums.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\yoga\YGFloatOptional.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\yoga\YGLayout.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\yoga\YGNode.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\yoga\YGNodePrint.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\yoga\YGStyle.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\yoga\Yoga.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\yoga\YGConfig.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Yoga.rc">
<Filter>Resource Files</Filter>
</ResourceCompile>
</ItemGroup>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="stdafx.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="targetver.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="resource.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\yoga\Utils.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\yoga\YGEnums.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\yoga\YGFloatOptional.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\yoga\YGLayout.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\yoga\YGMacros.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\yoga\YGNode.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\yoga\YGNodePrint.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\yoga\YGStyle.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\yoga\Yoga.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\yoga\Yoga-internal.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\yoga\YGConfig.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\yoga\YGValue.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\yoga\log.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\yoga\event\event.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="stdafx.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="dllmain.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="YGInterop.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\yoga\Utils.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\yoga\YGEnums.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\yoga\YGLayout.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\yoga\YGNode.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\yoga\YGNodePrint.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\yoga\YGStyle.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\yoga\Yoga.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\yoga\YGConfig.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\yoga\YGValue.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\yoga\event\event.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\yoga\log.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Yoga.rc">
<Filter>Resource Files</Filter>
</ResourceCompile>
</ItemGroup>
</Project>

View File

@@ -8,7 +8,8 @@
// dllmain.cpp : Defines the entry point for the DLL application.
#include "stdafx.h"
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
BOOL APIENTRY
DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
switch (ul_reason_for_call) {
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:

View File

@@ -9,7 +9,8 @@
// Including SDKDDKVer.h defines the highest available Windows platform.
// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and
// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h.
// If you wish to build your application for a previous Windows platform,
// include WinSDKVer.h and set the _WIN32_WINNT macro to the platform you wish
// to support before including SDKDDKVer.h.
#include <SDKDDKVer.h>

View File

@@ -1,9 +1,10 @@
/**
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
// @Generated by gentest/gentest.rb from gentest/fixtures/YGDisplayTest.html
using System;
@@ -333,5 +334,47 @@ namespace Facebook.Yoga
Assert.AreEqual(0f, root_child1.LayoutHeight);
}
[Test]
public void Test_display_none_with_position_absolute()
{
YogaConfig config = new YogaConfig();
YogaNode root = new YogaNode(config);
root.Width = 100;
root.Height = 100;
YogaNode root_child0 = new YogaNode(config);
root_child0.PositionType = YogaPositionType.Absolute;
root_child0.Width = 100;
root_child0.Height = 100;
root_child0.Display = YogaDisplay.None;
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(0f, root_child0.LayoutWidth);
Assert.AreEqual(0f, 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(0f, root_child0.LayoutWidth);
Assert.AreEqual(0f, root_child0.LayoutHeight);
}
}
}

View File

@@ -25,3 +25,7 @@
<div style="flex-grow: 1;"></div>
<div style="flex-grow: 1; display:none; top: 10px;"></div>
</div>
<div id="display_none_with_position_absolute" style="width: 100px; height: 100px;">
<div style="display:none; position: absolute; width: 100px; height: 100px"></div>
</div>

View File

@@ -120,8 +120,9 @@ CSEmitter.prototype = Object.create(Emitter.prototype, {
YGOverflowHidden:{value:'YogaOverflow.Hidden'},
YGOverflowVisible:{value:'YogaOverflow.Visible'},
YGPositionTypeAbsolute:{value:'YogaPositionType.Absolute'},
YGPositionTypeAbsolute:{value:'YogaPositionType.Static'},
YGPositionTypeRelative:{value:'YogaPositionType.Relative'},
YGPositionTypeAbsolute:{value:'YogaPositionType.Absolute'},
YGUndefined:{value:'YogaConstants.Undefined'},

View File

@@ -41,11 +41,11 @@ function assert(condition, message) {
function printTest(e, LTRContainer, RTLContainer, genericContainer) {
e.push([
'/**',
'/*',
' * Copyright (c) Facebook, Inc. and its affiliates.',
' *',
' * This source code is licensed under the MIT license found in the LICENSE',
' * file in the root directory of this source tree.',
' * This source code is licensed under the MIT license found in the',
' * LICENSE file in the root directory of this source tree.',
' */',
'// @Generated by gentest/gentest.rb from gentest/fixtures/' + document.title + '.html',
'',

View File

@@ -7,13 +7,14 @@
require 'watir'
require 'fileutils'
caps = Selenium::WebDriver::Remote::Capabilities.chrome(
"loggingPrefs"=>{
"browser"=>"ALL",
"performance"=>"ALL"
}
)
browser = Watir::Browser.new(:chrome, :desired_capabilities => caps, :switches => ['--force-device-scale-factor=1', '--window-position=0,0'])
browser = Watir::Browser.new(:chrome, "goog:loggingPrefs" => {
"browser" => "ALL",
"performance" => "ALL"
},
"chromeOptions" => {
"w3c" => "false"
},
:switches => ['--force-device-scale-factor=1', '--window-position=0,0'])
Dir.chdir(File.dirname($0))

View File

@@ -9,7 +9,7 @@
org.gradle.jvmargs=-Xmx1536M
VERSION_NAME=1.16.0-SNAPSHOT
VERSION_NAME=1.19.0
POM_URL=https://github.com/facebook/yoga
POM_SCM_URL=https://github.com/facebook/yoga.git
POM_SCM_CONNECTION=scm:git:https://github.com/facebook/yoga.git
@@ -17,5 +17,8 @@ POM_SCM_DEV_CONNECTION=scm:git:git@github.com:facebook/yoga.git
POM_LICENSE_NAME=MIT License
POM_LICENSE_URL=https://github.com/facebook/yoga/blob/master/LICENSE
POM_LICENSE_DIST=repo
POM_LICENCE_NAME=MIT License
POM_LICENCE_URL=https://github.com/facebook/yoga/blob/master/LICENSE
POM_LICENCE_DIST=repo
POM_DEVELOPER_ID=facebook
POM_DEVELOPER_NAME=facebook

View File

@@ -1,44 +0,0 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
// Configure the Android maven publication
apply plugin: 'com.github.dcendents.android-maven'
version = VERSION_NAME
group = GROUP
// Set the .aar / .jar base file name to match the artifact ID
// in case the module has a different name
project.archivesBaseName = POM_ARTIFACT_ID
install {
repositories.mavenInstaller {
// This generates POM.xml with proper parameters
pom.project {
name POM_NAME
artifactId POM_ARTIFACT_ID
packaging POM_PACKAGING
description POM_DESCRIPTION
url projectUrl
scm {
url scmUrl
connection scmConnection
developerConnection scmDeveloperConnection
}
licenses projectLicenses
developers {
developer {
id developerId
name developerName
}
}
}
}
}

View File

@@ -1,54 +0,0 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
// Android tasks for Javadoc and sources.jar generation
afterEvaluate { project ->
if (POM_PACKAGING == 'aar') {
task androidJavadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
exclude '**/pom.xml'
exclude '**/proguard_annotations.pro'
classpath += files(android.bootClasspath)
}
task androidJavadocJar(type: Jar) {
classifier = 'javadoc'
from androidJavadoc.destinationDir
}
task androidSourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.srcDirs
}
android.libraryVariants.all { variant ->
def name = variant.name.capitalize()
task "jar${name}"(type: Jar, dependsOn: variant.javaCompile) {
from variant.javaCompile.destinationDir
}
}
artifacts.add('archives', androidJavadocJar)
artifacts.add('archives', androidSourcesJar)
}
if (POM_PACKAGING == 'jar') {
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
artifacts.add('archives', javadocJar)
artifacts.add('archives', sourcesJar)
}
}

View File

@@ -1,70 +0,0 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
// Upload to Bintray
apply plugin: 'com.jfrog.bintray'
def getBintrayUsername() {
return project.hasProperty('bintrayUsername') ? property('bintrayUsername') : System.getenv('BINTRAY_USERNAME')
}
def getBintrayApiKey() {
return project.hasProperty('bintrayApiKey') ? property('bintrayApiKey') : System.getenv('BINTRAY_API_KEY')
}
def getBintrayGpgPassword() {
return project.hasProperty('bintrayGpgPassword') ? property('bintrayGpgPassword') : System.getenv('BINTRAY_GPG_PASSWORD')
}
def getMavenCentralUsername() {
return project.hasProperty('mavenCentralUsername') ? property('mavenCentralUsername') : System.getenv('MAVEN_CENTRAL_USERNAME')
}
def getMavenCentralPassword() {
return project.hasProperty('mavenCentralPassword') ? property('mavenCentralPassword') : System.getenv('MAVEN_CENTRAL_PASSWORD')
}
def shouldSyncWithMavenCentral() {
return project.hasProperty('syncWithMavenCentral') ? property('syncWithMavenCentral').toBoolean() : false
}
def dryRunOnly() {
return project.hasProperty('dryRun') ? property('dryRun').toBoolean() : false
}
bintray {
user = getBintrayUsername()
key = getBintrayApiKey()
configurations = ['archives']
pkg {
repo = bintrayRepo
userOrg = bintrayUserOrg
name = bintrayName
desc = bintrayDescription
websiteUrl = projectUrl
issueTrackerUrl = issuesUrl
vcsUrl = scmUrl
licenses = projectLicenses
dryRun = dryRunOnly()
override = true
publish = true
publicDownloadNumbers = true
version {
desc = bintrayDescription
gpg {
sign = true
passphrase = getBintrayGpgPassword()
}
mavenCentralSync {
sync = shouldSyncWithMavenCentral()
user = getMavenCentralUsername()
password = getMavenCentralPassword()
close = '1' // If set to 0, you have to manually click release
}
}
}
}

View File

@@ -1,96 +0,0 @@
/*
* Copyright 2013 Chris Banes
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
apply plugin: 'signing'
version = VERSION_NAME
group = GROUP
def isReleaseBuild() {
return VERSION_NAME.contains('SNAPSHOT') == false
}
def getReleaseRepositoryUrl() {
return hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL
: "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
}
def getSnapshotRepositoryUrl() {
return hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL
: "https://oss.sonatype.org/content/repositories/snapshots/"
}
def getRepositoryUsername() {
return hasProperty('SONATYPE_NEXUS_USERNAME') ? SONATYPE_NEXUS_USERNAME : ""
}
def getRepositoryPassword() {
return hasProperty('SONATYPE_NEXUS_PASSWORD') ? SONATYPE_NEXUS_PASSWORD : ""
}
afterEvaluate { project ->
uploadArchives {
repositories {
mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
pom.groupId = GROUP
pom.artifactId = POM_ARTIFACT_ID
pom.version = VERSION_NAME
repository(url: getReleaseRepositoryUrl()) {
authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
}
snapshotRepository(url: getSnapshotRepositoryUrl()) {
authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
}
pom.project {
name POM_NAME
packaging POM_PACKAGING
description POM_DESCRIPTION
url POM_URL
scm {
url POM_SCM_URL
connection POM_SCM_CONNECTION
developerConnection POM_SCM_DEV_CONNECTION
}
licenses {
license {
name POM_LICENSE_NAME
url POM_LICENSE_URL
distribution POM_LICENSE_DIST
}
}
developers {
developer {
id POM_DEVELOPER_ID
name POM_DEVELOPER_NAME
}
}
}
}
}
}
signing {
required { isReleaseBuild() && gradle.taskGraph.hasTask('uploadArchives') }
sign configurations.archives
}
}

View File

@@ -1,40 +0,0 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
// Set up everything required for releasing on Bintray
ext {
bintrayRepo = 'maven'
bintrayUserOrg = 'facebook'
bintrayName = "${GROUP}:${POM_ARTIFACT_ID}"
bintrayDescription = POM_DESCRIPTION
projectUrl = POM_URL
issuesUrl = 'https://github.com/facebook/yoga/issues'
scmUrl = POM_SCM_URL
scmConnection = POM_SCM_CONNECTION
scmDeveloperConnection = POM_SCM_DEV_CONNECTION
publishedGroupId = GROUP
libraryName = 'yoga'
artifact = 'yoga'
developerId = POM_DEVELOPER_ID
developerName = POM_DEVELOPER_NAME
projectLicenses = {
license {
name = POM_LICENSE_NAME
url = POM_LICENSE_URL
distribution = POM_LICENSE_DIST
}
}
}
// Set up the Android Maven publication (POM etc.)
apply from: rootProject.file('gradle/android-maven-install.gradle')
// Upload to Bintray
apply from: rootProject.file('gradle/bintray.gradle')

View File

@@ -1,15 +0,0 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
// Common Android tasks for all releases that generate Javadocs, sources, etc.
apply from: rootProject.file('gradle/android-tasks.gradle')
// Upload to Bintray
apply from: rootProject.file('gradle/release-bintray.gradle')
// Upload directly to standard Maven Central (for SNAPSHOTs)
apply from: rootProject.file('gradle/gradle-mvn-push.gradle')

View File

@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip

View File

@@ -3,11 +3,11 @@
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
load("//tools/build_defs/oss:yoga_defs.bzl", "ANDROID", "CXX_LIBRARY_WHITELIST", "FBJNI_JAVA_TARGET", "FBJNI_TARGET", "JNI_TARGET", "JSR_305_TARGET", "JUNIT_TARGET", "PROGRUARD_ANNOTATIONS_TARGET", "SOLOADER_TARGET", "yoga_cxx_lib", "yoga_cxx_library", "yoga_dep", "yoga_java_binary", "yoga_java_library", "yoga_java_test")
load("//tools/build_defs/oss:yoga_defs.bzl", "ANDROID", "CXX_LIBRARY_WHITELIST", "JNI_TARGET", "JSR_305_TARGET", "JUNIT_TARGET", "PROGUARD_ANNOTATIONS_TARGET", "SOLOADER_TARGET", "YOGA_ROOTS", "yoga_cxx_lib", "yoga_cxx_library", "yoga_dep", "yoga_java_binary", "yoga_java_library", "yoga_java_test", "yoga_prebuilt_cxx_library")
CXX_LIBRARY_WHITELIST_FOR_TESTS = CXX_LIBRARY_WHITELIST + [
yoga_cxx_lib("testutil:jni"),
yoga_cxx_lib("testutil:testutil"),
yoga_cxx_lib("testutil:testutil-jni"),
]
YOGA_JAVA_IMPLEMENTATION_FILES = [
@@ -16,6 +16,18 @@ YOGA_JAVA_IMPLEMENTATION_FILES = [
"com/facebook/yoga/YogaNative.java",
]
yoga_prebuilt_cxx_library(
name = "ndklog",
exported_platform_linker_flags = [
(
"^android.*",
["-llog"],
),
],
header_only = True,
visibility = YOGA_ROOTS,
)
yoga_cxx_library(
name = "jni",
srcs = glob(["jni/*.cpp"]),
@@ -41,9 +53,9 @@ yoga_cxx_library(
soname = "libyoga.$(ext)",
visibility = ["PUBLIC"],
deps = [
FBJNI_TARGET,
JNI_TARGET,
yoga_dep(":yoga"),
yoga_dep(":yoga-static"),
":ndklog",
],
)
@@ -59,7 +71,7 @@ yoga_java_library(
visibility = ["PUBLIC"],
deps = [
JSR_305_TARGET,
PROGRUARD_ANNOTATIONS_TARGET,
PROGUARD_ANNOTATIONS_TARGET,
],
)
@@ -72,9 +84,8 @@ yoga_java_library(
deps = [
":java-interface",
":jni",
FBJNI_JAVA_TARGET,
JSR_305_TARGET,
PROGRUARD_ANNOTATIONS_TARGET,
PROGUARD_ANNOTATIONS_TARGET,
SOLOADER_TARGET,
],
)
@@ -97,6 +108,7 @@ yoga_java_library(
yoga_java_test(
name = "tests",
srcs = glob(["tests/**/*.java"]),
contacts = ["oncall+yoga@xmail.facebook.com"],
cxx_library_whitelist = CXX_LIBRARY_WHITELIST_FOR_TESTS,
use_cxx_libraries = True,
visibility = ["PUBLIC"],
@@ -111,6 +123,5 @@ yoga_java_binary(
name = "yoga",
deps = [
":java",
FBJNI_JAVA_TARGET,
],
)

View File

@@ -8,17 +8,13 @@ cmake_minimum_required(VERSION 3.4.1)
set(CMAKE_VERBOSE_MAKEFILE on)
# configure import libs
set(libfb_DIR ${CMAKE_SOURCE_DIR}/../lib/fb/src/main/cpp)
set(yogacore_DIR ${CMAKE_SOURCE_DIR}/..)
set(build_DIR ${CMAKE_SOURCE_DIR}/build)
set(libfb_build_DIR ${build_DIR}/libfb/${ANDROID_ABI})
set(yogacore_build_DIR ${build_DIR}/yogacore/${ANDROID_ABI})
file(MAKE_DIRECTORY ${build_DIR})
add_subdirectory(${libfb_DIR} ${libfb_build_DIR})
add_subdirectory(${yogacore_DIR} ${yogacore_build_DIR})
add_compile_options(
@@ -33,10 +29,12 @@ add_compile_options(
file(GLOB jni_SRC
jni/*.cpp)
file(GLOB yogajni_version_script
yogajni.version)
add_library(yoga SHARED ${jni_SRC})
target_include_directories(yoga PRIVATE
${libfb_DIR}/include
${yogacore_DIR})
target_link_libraries(yoga -Wl,--gc-sections yogacore fb)
target_link_libraries(yoga -Wl,--gc-sections,--version-script=${yogajni_version_script} yogacore)

View File

@@ -5,17 +5,12 @@
* LICENSE file in the root directory of this source tree.
*/
apply plugin: 'com.jfrog.bintray'
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'maven-publish'
group = GROUP
version = VERSION_NAME
android {
compileSdkVersion rootProject.compileSdkVersion
buildToolsVersion rootProject.buildToolsVersion
ndkVersion rootProject.ndkVersion
defaultConfig {
minSdkVersion rootProject.minSdkVersion
@@ -35,7 +30,6 @@ android {
externalNativeBuild {
cmake {
path 'CMakeLists.txt'
version '3.6.0-rc2'
}
}
@@ -58,32 +52,11 @@ android {
}
dependencies {
implementation 'com.google.code.findbugs:jsr305:3.0.1'
implementation 'com.google.code.findbugs:jsr305:3.0.2'
implementation project(':yoga:proguard-annotations')
implementation 'com.facebook.soloader:soloader:0.5.1'
implementation 'com.facebook.soloader:soloader:0.10.1'
testImplementation 'junit:junit:4.12'
testImplementation project(':testutil')
}
task sourcesJar(type: Jar) {
classifier = 'source'
from android.sourceSets.main.java.srcDirs
}
task javadoc(type: Javadoc) {
failOnError false
source = android.sourceSets.main.java.sourceFiles
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
classpath += configurations.compile
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
ext {
bintrayName = 'com.facebook.yoga:yoga'
}
apply from: rootProject.file('gradle/release.gradle')
apply plugin: 'com.vanniktech.maven.publish'

View File

@@ -7,9 +7,6 @@
package com.facebook.yoga;
import com.facebook.proguard.annotations.DoNotStrip;
@DoNotStrip
public enum YogaAlign {
AUTO(0),
FLEX_START(1),

View File

@@ -7,14 +7,10 @@
package com.facebook.yoga;
import com.facebook.proguard.annotations.DoNotStrip;
@DoNotStrip
public interface YogaBaselineFunction {
/**
* Return the baseline of the node in points. When no baseline function is set the baseline
* default to the computed height of the node.
*/
@DoNotStrip
float baseline(YogaNode node, float width, float height);
}

View File

@@ -38,8 +38,4 @@ public abstract class YogaConfig {
public abstract YogaLogger getLogger();
abstract long getNativePointer();
public abstract void setUseVanillaJNI(boolean useVanillaJNI);
public abstract boolean useVanillaJNI();
}

View File

@@ -11,8 +11,4 @@ public abstract class YogaConfigFactory {
public static YogaConfig create() {
return new YogaConfigJNIFinalizer();
}
public static YogaConfig create(boolean useVanillaJNI) {
return new YogaConfigJNIFinalizer(useVanillaJNI);
}
}

View File

@@ -11,7 +11,6 @@ public abstract class YogaConfigJNIBase extends YogaConfig {
long mNativePointer;
private YogaLogger mLogger;
protected boolean useVanillaJNI = false;
private YogaConfigJNIBase(long nativePointer) {
if (nativePointer == 0) {
@@ -21,40 +20,27 @@ public abstract class YogaConfigJNIBase extends YogaConfig {
}
YogaConfigJNIBase() {
this(YogaNative.jni_YGConfigNew());
this(YogaNative.jni_YGConfigNewJNI());
}
YogaConfigJNIBase(boolean useVanillaJNI) {
this(useVanillaJNI ? YogaNative.jni_YGConfigNewJNI() : YogaNative.jni_YGConfigNew());
this.useVanillaJNI = useVanillaJNI;
this(YogaNative.jni_YGConfigNewJNI());
}
public void setExperimentalFeatureEnabled(YogaExperimentalFeature feature, boolean enabled) {
if (useVanillaJNI)
YogaNative.jni_YGConfigSetExperimentalFeatureEnabledJNI(mNativePointer, feature.intValue(), enabled);
else
YogaNative.jni_YGConfigSetExperimentalFeatureEnabled(mNativePointer, feature.intValue(), enabled);
YogaNative.jni_YGConfigSetExperimentalFeatureEnabledJNI(mNativePointer, feature.intValue(), enabled);
}
public void setUseWebDefaults(boolean useWebDefaults) {
if (useVanillaJNI)
YogaNative.jni_YGConfigSetUseWebDefaultsJNI(mNativePointer, useWebDefaults);
else
YogaNative.jni_YGConfigSetUseWebDefaults(mNativePointer, useWebDefaults);
YogaNative.jni_YGConfigSetUseWebDefaultsJNI(mNativePointer, useWebDefaults);
}
public void setPrintTreeFlag(boolean enable) {
if (useVanillaJNI)
YogaNative.jni_YGConfigSetPrintTreeFlagJNI(mNativePointer, enable);
else
YogaNative.jni_YGConfigSetPrintTreeFlag(mNativePointer, enable);
YogaNative.jni_YGConfigSetPrintTreeFlagJNI(mNativePointer, enable);
}
public void setPointScaleFactor(float pixelsInPoint) {
if (useVanillaJNI)
YogaNative.jni_YGConfigSetPointScaleFactorJNI(mNativePointer, pixelsInPoint);
else
YogaNative.jni_YGConfigSetPointScaleFactor(mNativePointer, pixelsInPoint);
YogaNative.jni_YGConfigSetPointScaleFactorJNI(mNativePointer, pixelsInPoint);
}
/**
@@ -63,10 +49,7 @@ public abstract class YogaConfigJNIBase extends YogaConfig {
* Because this was such a long-standing bug we must allow legacy users to switch back to this behaviour.
*/
public void setUseLegacyStretchBehaviour(boolean useLegacyStretchBehaviour) {
if (useVanillaJNI)
YogaNative.jni_YGConfigSetUseLegacyStretchBehaviourJNI(mNativePointer, useLegacyStretchBehaviour);
else
YogaNative.jni_YGConfigSetUseLegacyStretchBehaviour(mNativePointer, useLegacyStretchBehaviour);
YogaNative.jni_YGConfigSetUseLegacyStretchBehaviourJNI(mNativePointer, useLegacyStretchBehaviour);
}
/**
@@ -76,20 +59,13 @@ public abstract class YogaConfigJNIBase extends YogaConfig {
*/
public void setShouldDiffLayoutWithoutLegacyStretchBehaviour(
boolean shouldDiffLayoutWithoutLegacyStretchBehaviour) {
if (useVanillaJNI)
YogaNative.jni_YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviourJNI(
mNativePointer, shouldDiffLayoutWithoutLegacyStretchBehaviour);
else
YogaNative.jni_YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour(
mNativePointer, shouldDiffLayoutWithoutLegacyStretchBehaviour);
}
public void setLogger(YogaLogger logger) {
mLogger = logger;
if (useVanillaJNI)
YogaNative.jni_YGConfigSetLoggerJNI(mNativePointer, logger);
else
YogaNative.jni_YGConfigSetLogger(mNativePointer, logger);
YogaNative.jni_YGConfigSetLoggerJNI(mNativePointer, logger);
}
public YogaLogger getLogger() {
@@ -99,14 +75,4 @@ public abstract class YogaConfigJNIBase extends YogaConfig {
long getNativePointer() {
return mNativePointer;
}
@Override
public void setUseVanillaJNI(boolean useVanillaJNI) {
this.useVanillaJNI = useVanillaJNI;
}
@Override
public boolean useVanillaJNI() {
return this.useVanillaJNI;
}
}

View File

@@ -12,10 +12,6 @@ public class YogaConfigJNIFinalizer extends YogaConfigJNIBase {
super();
}
public YogaConfigJNIFinalizer(boolean useVanillaJNI) {
super(useVanillaJNI);
}
@Override
protected void finalize() throws Throwable {
try {
@@ -29,10 +25,7 @@ public class YogaConfigJNIFinalizer extends YogaConfigJNIBase {
if (mNativePointer != 0) {
long nativePointer = mNativePointer;
mNativePointer = 0;
if (useVanillaJNI)
YogaNative.jni_YGConfigFreeJNI(nativePointer);
else
YogaNative.jni_YGConfigFree(nativePointer);
YogaNative.jni_YGConfigFreeJNI(nativePointer);
}
}
}

View File

@@ -7,9 +7,6 @@
package com.facebook.yoga;
import com.facebook.proguard.annotations.DoNotStrip;
@DoNotStrip
public enum YogaDimension {
WIDTH(0),
HEIGHT(1);

View File

@@ -7,9 +7,6 @@
package com.facebook.yoga;
import com.facebook.proguard.annotations.DoNotStrip;
@DoNotStrip
public enum YogaDirection {
INHERIT(0),
LTR(1),

View File

@@ -7,9 +7,6 @@
package com.facebook.yoga;
import com.facebook.proguard.annotations.DoNotStrip;
@DoNotStrip
public enum YogaDisplay {
FLEX(0),
NONE(1);

View File

@@ -7,9 +7,6 @@
package com.facebook.yoga;
import com.facebook.proguard.annotations.DoNotStrip;
@DoNotStrip
public enum YogaEdge {
LEFT(0),
TOP(1),

View File

@@ -7,9 +7,6 @@
package com.facebook.yoga;
import com.facebook.proguard.annotations.DoNotStrip;
@DoNotStrip
public enum YogaExperimentalFeature {
WEB_FLEX_BASIS(0);

View File

@@ -7,9 +7,6 @@
package com.facebook.yoga;
import com.facebook.proguard.annotations.DoNotStrip;
@DoNotStrip
public enum YogaFlexDirection {
COLUMN(0),
COLUMN_REVERSE(1),

View File

@@ -7,9 +7,6 @@
package com.facebook.yoga;
import com.facebook.proguard.annotations.DoNotStrip;
@DoNotStrip
public enum YogaJustify {
FLEX_START(0),
CENTER(1),

View File

@@ -28,6 +28,7 @@ public enum YogaLogLevel {
return mIntValue;
}
@DoNotStrip
public static YogaLogLevel fromInt(int value) {
switch (value) {
case 0: return ERROR;

View File

@@ -7,14 +7,10 @@
package com.facebook.yoga;
import com.facebook.proguard.annotations.DoNotStrip;
@DoNotStrip
public interface YogaMeasureFunction {
/**
* Return a value created by YogaMeasureOutput.make(width, height);
*/
@DoNotStrip
long measure(
YogaNode node,
float width,

View File

@@ -7,9 +7,6 @@
package com.facebook.yoga;
import com.facebook.proguard.annotations.DoNotStrip;
@DoNotStrip
public enum YogaMeasureMode {
UNDEFINED(0),
EXACTLY(1),

View File

@@ -15,105 +15,7 @@ public class YogaNative {
static {
SoLoader.loadLibrary("yoga");
}
// YGConfig related
static native long jni_YGConfigNew();
static native void jni_YGConfigFree(long nativePointer);
static native void jni_YGConfigSetExperimentalFeatureEnabled(long nativePointer, int feature, boolean enabled);
static native void jni_YGConfigSetUseWebDefaults(long nativePointer, boolean useWebDefaults);
static native void jni_YGConfigSetPrintTreeFlag(long nativePointer, boolean enable);
static native void jni_YGConfigSetPointScaleFactor(long nativePointer, float pixelsInPoint);
static native void jni_YGConfigSetUseLegacyStretchBehaviour(long nativePointer, boolean useLegacyStretchBehaviour);
static native void jni_YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour(long nativePointer, boolean shouldDiffLayoutWithoutLegacyStretchBehaviour);
static native void jni_YGConfigSetLogger(long nativePointer, Object logger);
// YGNode related
static native long jni_YGNodeNew();
static native long jni_YGNodeNewWithConfig(long configPointer);
static native void jni_YGNodeFree(long nativePointer);
static native void jni_YGNodeReset(long nativePointer);
static native void jni_YGNodeInsertChild(long nativePointer, long childPointer, int index);
static native void jni_YGNodeSetIsReferenceBaseline(long nativePointer, boolean isReferenceBaseline);
static native boolean jni_YGNodeIsReferenceBaseline(long nativePointer);
static native void jni_YGNodeClearChildren(long nativePointer);
static native void jni_YGNodeRemoveChild(long nativePointer, long childPointer);
static native void jni_YGNodeCalculateLayout(long nativePointer, float width, float height, long[] nativePointers, YogaNodeJNIBase[] nodes);
static native void jni_YGNodeMarkDirty(long nativePointer);
static native void jni_YGNodeMarkDirtyAndPropogateToDescendants(long nativePointer);
static native boolean jni_YGNodeIsDirty(long nativePointer);
static native void jni_YGNodeCopyStyle(long dstNativePointer, long srcNativePointer);
static native int jni_YGNodeStyleGetDirection(long nativePointer);
static native void jni_YGNodeStyleSetDirection(long nativePointer, int direction);
static native int jni_YGNodeStyleGetFlexDirection(long nativePointer);
static native void jni_YGNodeStyleSetFlexDirection(long nativePointer, int flexDirection);
static native int jni_YGNodeStyleGetJustifyContent(long nativePointer);
static native void jni_YGNodeStyleSetJustifyContent(long nativePointer, int justifyContent);
static native int jni_YGNodeStyleGetAlignItems(long nativePointer);
static native void jni_YGNodeStyleSetAlignItems(long nativePointer, int alignItems);
static native int jni_YGNodeStyleGetAlignSelf(long nativePointer);
static native void jni_YGNodeStyleSetAlignSelf(long nativePointer, int alignSelf);
static native int jni_YGNodeStyleGetAlignContent(long nativePointer);
static native void jni_YGNodeStyleSetAlignContent(long nativePointer, int alignContent);
static native int jni_YGNodeStyleGetPositionType(long nativePointer);
static native void jni_YGNodeStyleSetPositionType(long nativePointer, int positionType);
static native int jni_YGNodeStyleGetFlexWrap(long nativePointer);
static native void jni_YGNodeStyleSetFlexWrap(long nativePointer, int wrapType);
static native int jni_YGNodeStyleGetOverflow(long nativePointer);
static native void jni_YGNodeStyleSetOverflow(long nativePointer, int overflow);
static native int jni_YGNodeStyleGetDisplay(long nativePointer);
static native void jni_YGNodeStyleSetDisplay(long nativePointer, int display);
static native float jni_YGNodeStyleGetFlex(long nativePointer);
static native void jni_YGNodeStyleSetFlex(long nativePointer, float flex);
static native float jni_YGNodeStyleGetFlexGrow(long nativePointer);
static native void jni_YGNodeStyleSetFlexGrow(long nativePointer, float flexGrow);
static native float jni_YGNodeStyleGetFlexShrink(long nativePointer);
static native void jni_YGNodeStyleSetFlexShrink(long nativePointer, float flexShrink);
static native long jni_YGNodeStyleGetFlexBasis(long nativePointer);
static native void jni_YGNodeStyleSetFlexBasis(long nativePointer, float flexBasis);
static native void jni_YGNodeStyleSetFlexBasisPercent(long nativePointer, float percent);
static native void jni_YGNodeStyleSetFlexBasisAuto(long nativePointer);
static native long jni_YGNodeStyleGetMargin(long nativePointer, int edge);
static native void jni_YGNodeStyleSetMargin(long nativePointer, int edge, float margin);
static native void jni_YGNodeStyleSetMarginPercent(long nativePointer, int edge, float percent);
static native void jni_YGNodeStyleSetMarginAuto(long nativePointer, int edge);
static native long jni_YGNodeStyleGetPadding(long nativePointer, int edge);
static native void jni_YGNodeStyleSetPadding(long nativePointer, int edge, float padding);
static native void jni_YGNodeStyleSetPaddingPercent(long nativePointer, int edge, float percent);
static native float jni_YGNodeStyleGetBorder(long nativePointer, int edge);
static native void jni_YGNodeStyleSetBorder(long nativePointer, int edge, float border);
static native long jni_YGNodeStyleGetPosition(long nativePointer, int edge);
static native void jni_YGNodeStyleSetPosition(long nativePointer, int edge, float position);
static native void jni_YGNodeStyleSetPositionPercent(long nativePointer, int edge, float percent);
static native long jni_YGNodeStyleGetWidth(long nativePointer);
static native void jni_YGNodeStyleSetWidth(long nativePointer, float width);
static native void jni_YGNodeStyleSetWidthPercent(long nativePointer, float percent);
static native void jni_YGNodeStyleSetWidthAuto(long nativePointer);
static native long jni_YGNodeStyleGetHeight(long nativePointer);
static native void jni_YGNodeStyleSetHeight(long nativePointer, float height);
static native void jni_YGNodeStyleSetHeightPercent(long nativePointer, float percent);
static native void jni_YGNodeStyleSetHeightAuto(long nativePointer);
static native long jni_YGNodeStyleGetMinWidth(long nativePointer);
static native void jni_YGNodeStyleSetMinWidth(long nativePointer, float minWidth);
static native void jni_YGNodeStyleSetMinWidthPercent(long nativePointer, float percent);
static native long jni_YGNodeStyleGetMinHeight(long nativePointer);
static native void jni_YGNodeStyleSetMinHeight(long nativePointer, float minHeight);
static native void jni_YGNodeStyleSetMinHeightPercent(long nativePointer, float percent);
static native long jni_YGNodeStyleGetMaxWidth(long nativePointer);
static native void jni_YGNodeStyleSetMaxWidth(long nativePointer, float maxWidth);
static native void jni_YGNodeStyleSetMaxWidthPercent(long nativePointer, float percent);
static native long jni_YGNodeStyleGetMaxHeight(long nativePointer);
static native void jni_YGNodeStyleSetMaxHeight(long nativePointer, float maxheight);
static native void jni_YGNodeStyleSetMaxHeightPercent(long nativePointer, float percent);
static native float jni_YGNodeStyleGetAspectRatio(long nativePointer);
static native void jni_YGNodeStyleSetAspectRatio(long nativePointer, float aspectRatio);
static native void jni_YGNodeSetHasMeasureFunc(long nativePointer, boolean hasMeasureFunc);
static native void jni_YGNodeSetHasBaselineFunc(long nativePointer, boolean hasMeasureFunc);
static native void jni_YGNodePrint(long nativePointer);
static native void jni_YGNodeSetStyleInputs(long nativePointer, float[] styleInputsArray, int size);
static native long jni_YGNodeClone(long nativePointer);
// JNI methods that use Vanilla JNI
// YGConfig related
static native long jni_YGConfigNewJNI();
@@ -132,6 +34,7 @@ public class YogaNative {
static native void jni_YGNodeFreeJNI(long nativePointer);
static native void jni_YGNodeResetJNI(long nativePointer);
static native void jni_YGNodeInsertChildJNI(long nativePointer, long childPointer, int index);
static native void jni_YGNodeSwapChildJNI(long nativePointer, long childPointer, int index);
static native void jni_YGNodeSetIsReferenceBaselineJNI(long nativePointer, boolean isReferenceBaseline);
static native boolean jni_YGNodeIsReferenceBaselineJNI(long nativePointer);
static native void jni_YGNodeClearChildrenJNI(long nativePointer);

View File

@@ -9,7 +9,15 @@ package com.facebook.yoga;
import javax.annotation.Nullable;
public abstract class YogaNode {
public abstract class YogaNode implements YogaProps {
/** The interface the {@link #getData()} object can optionally implement. */
public interface Inputs {
/** Requests the data object to disable mutations of its inputs. */
void freeze(final YogaNode node, final @Nullable YogaNode parent);
}
public abstract void reset();
public abstract int getChildCount();
@@ -25,12 +33,10 @@ public abstract class YogaNode {
public abstract YogaNode removeChildAt(int i);
/**
* @returns the {@link YogaNode} that owns this {@link YogaNode}.
* The owner is used to identify the YogaTree that a {@link YogaNode} belongs
* to.
* This method will return the parent of the {@link YogaNode} when the
* {@link YogaNode} only belongs to one YogaTree or null when the
* {@link YogaNode} is shared between two or more YogaTrees.
* @returns the {@link YogaNode} that owns this {@link YogaNode}. The owner is used to identify
* the YogaTree that a {@link YogaNode} belongs to. This method will return the parent of the
* {@link YogaNode} when the {@link YogaNode} only belongs to one YogaTree or null when the
* {@link YogaNode} is shared between two or more YogaTrees.
*/
@Nullable
public abstract YogaNode getOwner();
@@ -214,4 +220,6 @@ public abstract class YogaNode {
public abstract void print();
public abstract YogaNode cloneWithoutChildren();
public abstract YogaNode cloneWithChildren();
}

View File

@@ -12,10 +12,6 @@ public abstract class YogaNodeFactory {
return new YogaNodeJNIFinalizer();
}
public static YogaNode create(boolean useVanillaJNI) {
return new YogaNodeJNIFinalizer(useVanillaJNI);
}
public static YogaNode create(YogaConfig config) {
return new YogaNodeJNIFinalizer(config);
}

View File

@@ -15,7 +15,7 @@ import javax.annotation.Nullable;
@DoNotStrip
public abstract class YogaNodeJNIBase extends YogaNode implements Cloneable {
/* Those flags needs be in sync with YGJNI.cpp */
/* Those flags needs be in sync with YGJNI.h */
private static final byte MARGIN = 1;
private static final byte PADDING = 2;
private static final byte BORDER = 4;
@@ -39,16 +39,12 @@ public abstract class YogaNodeJNIBase extends YogaNode implements Cloneable {
protected long mNativePointer;
@Nullable private Object mData;
@DoNotStrip
private @Nullable float[] arr = null;
@DoNotStrip private @Nullable float[] arr = null;
@DoNotStrip
private int mLayoutDirection = 0;
@DoNotStrip private int mLayoutDirection = 0;
private boolean mHasNewLayout = true;
protected boolean useVanillaJNI = false;
private YogaNodeJNIBase(long nativePointer) {
if (nativePointer == 0) {
throw new IllegalStateException("Failed to allocate native memory");
@@ -57,17 +53,11 @@ public abstract class YogaNodeJNIBase extends YogaNode implements Cloneable {
}
YogaNodeJNIBase() {
this(YogaNative.jni_YGNodeNew());
}
YogaNodeJNIBase(boolean useVanillaJNI) {
this(useVanillaJNI ? YogaNative.jni_YGNodeNewJNI() : YogaNative.jni_YGNodeNew());
this.useVanillaJNI = useVanillaJNI;
this(YogaNative.jni_YGNodeNewJNI());
}
YogaNodeJNIBase(YogaConfig config) {
this(config.useVanillaJNI() ? YogaNative.jni_YGNodeNewWithConfigJNI(((YogaConfigJNIBase)config).mNativePointer) : YogaNative.jni_YGNodeNewWithConfig(((YogaConfigJNIBase)config).mNativePointer));
this.useVanillaJNI = config.useVanillaJNI();
this(YogaNative.jni_YGNodeNewWithConfigJNI(((YogaConfigJNIBase) config).mNativePointer));
}
public void reset() {
@@ -78,10 +68,7 @@ public abstract class YogaNodeJNIBase extends YogaNode implements Cloneable {
mHasNewLayout = true;
mLayoutDirection = 0;
if (useVanillaJNI)
YogaNative.jni_YGNodeResetJNI(mNativePointer);
else
YogaNative.jni_YGNodeReset(mNativePointer);
YogaNative.jni_YGNodeResetJNI(mNativePointer);
}
public int getChildCount() {
@@ -96,6 +83,9 @@ public abstract class YogaNodeJNIBase extends YogaNode implements Cloneable {
}
public void addChildAt(YogaNode c, int i) {
if (!(c instanceof YogaNodeJNIBase)) {
return;
}
YogaNodeJNIBase child = (YogaNodeJNIBase) c;
if (child.mOwner != null) {
throw new IllegalStateException("Child already has a parent, it must be removed first.");
@@ -106,28 +96,54 @@ public abstract class YogaNodeJNIBase extends YogaNode implements Cloneable {
}
mChildren.add(i, child);
child.mOwner = this;
if (useVanillaJNI)
YogaNative.jni_YGNodeInsertChildJNI(mNativePointer, child.mNativePointer, i);
else
YogaNative.jni_YGNodeInsertChild(mNativePointer, child.mNativePointer, i);
YogaNative.jni_YGNodeInsertChildJNI(mNativePointer, child.mNativePointer, i);
}
public void setIsReferenceBaseline(boolean isReferenceBaseline) {
if (useVanillaJNI)
YogaNative.jni_YGNodeSetIsReferenceBaselineJNI(mNativePointer, isReferenceBaseline);
else
YogaNative.jni_YGNodeSetIsReferenceBaseline(mNativePointer, isReferenceBaseline);
YogaNative.jni_YGNodeSetIsReferenceBaselineJNI(mNativePointer, isReferenceBaseline);
}
public boolean isReferenceBaseline() {
return useVanillaJNI ? YogaNative.jni_YGNodeIsReferenceBaselineJNI(mNativePointer) : YogaNative.jni_YGNodeIsReferenceBaseline(mNativePointer);
return YogaNative.jni_YGNodeIsReferenceBaselineJNI(mNativePointer);
}
public void swapChildAt(YogaNode newChild, int position) {
if (!(newChild instanceof YogaNodeJNIBase)) {
return;
}
YogaNodeJNIBase child = (YogaNodeJNIBase) newChild;
mChildren.remove(position);
mChildren.add(position, child);
child.mOwner = this;
YogaNative.jni_YGNodeSwapChildJNI(mNativePointer, child.mNativePointer, position);
}
@Override
public YogaNodeJNIBase cloneWithChildren() {
try {
YogaNodeJNIBase clonedYogaNode = (YogaNodeJNIBase) super.clone();
if (clonedYogaNode.mChildren != null) {
clonedYogaNode.mChildren = new ArrayList<>(clonedYogaNode.mChildren);
}
long clonedNativePointer = YogaNative.jni_YGNodeCloneJNI(mNativePointer);
clonedYogaNode.mOwner = null;
clonedYogaNode.mNativePointer = clonedNativePointer;
for (int i = 0; i < clonedYogaNode.getChildCount(); i++) {
clonedYogaNode.swapChildAt(clonedYogaNode.getChildAt(i).cloneWithChildren(), i);
}
return clonedYogaNode;
} catch (CloneNotSupportedException ex) {
// This class implements Cloneable, this should not happen
throw new RuntimeException(ex);
}
}
@Override
public YogaNodeJNIBase cloneWithoutChildren() {
try {
YogaNodeJNIBase clonedYogaNode = (YogaNodeJNIBase) super.clone();
long clonedNativePointer = useVanillaJNI ? YogaNative.jni_YGNodeCloneJNI(mNativePointer) : YogaNative.jni_YGNodeClone(mNativePointer);;
long clonedNativePointer = YogaNative.jni_YGNodeCloneJNI(mNativePointer);
clonedYogaNode.mOwner = null;
clonedYogaNode.mNativePointer = clonedNativePointer;
clonedYogaNode.clearChildren();
@@ -140,10 +156,7 @@ public abstract class YogaNodeJNIBase extends YogaNode implements Cloneable {
private void clearChildren() {
mChildren = null;
if (useVanillaJNI)
YogaNative.jni_YGNodeClearChildrenJNI(mNativePointer);
else
YogaNative.jni_YGNodeClearChildren(mNativePointer);
YogaNative.jni_YGNodeClearChildrenJNI(mNativePointer);
}
public YogaNodeJNIBase removeChildAt(int i) {
@@ -153,20 +166,16 @@ public abstract class YogaNodeJNIBase extends YogaNode implements Cloneable {
}
final YogaNodeJNIBase child = mChildren.remove(i);
child.mOwner = null;
if (useVanillaJNI)
YogaNative.jni_YGNodeRemoveChildJNI(mNativePointer, child.mNativePointer);
else
YogaNative.jni_YGNodeRemoveChild(mNativePointer, child.mNativePointer);
YogaNative.jni_YGNodeRemoveChildJNI(mNativePointer, child.mNativePointer);
return child;
}
/**
* @returns the {@link YogaNode} that owns this {@link YogaNode}.
* The owner is used to identify the YogaTree that a {@link YogaNode} belongs
* to.
* This method will return the parent of the {@link YogaNode} when the
* {@link YogaNode} only belongs to one YogaTree or null when the
* {@link YogaNode} is shared between two or more YogaTrees.
* The owner is used to identify the YogaTree that a {@link YogaNode} belongs to. This method will
* return the parent of the {@link YogaNode} when the {@link YogaNode} only belongs to one
* YogaTree or null when the {@link YogaNode} is shared between two or more YogaTrees.
*
* @return the {@link YogaNode} that owns this {@link YogaNode}.
*/
@Nullable
public YogaNodeJNIBase getOwner() {
@@ -188,12 +197,18 @@ public abstract class YogaNodeJNIBase extends YogaNode implements Cloneable {
long[] nativePointers = null;
YogaNodeJNIBase[] nodes = null;
freeze(null);
ArrayList<YogaNodeJNIBase> n = new ArrayList<>();
n.add(this);
for (int i = 0; i < n.size(); ++i) {
List<YogaNodeJNIBase> children = n.get(i).mChildren;
final YogaNodeJNIBase parent = n.get(i);
List<YogaNodeJNIBase> children = parent.mChildren;
if (children != null) {
n.addAll(children);
for (YogaNodeJNIBase child : children) {
child.freeze(parent);
n.add(child);
}
}
}
@@ -203,418 +218,295 @@ public abstract class YogaNodeJNIBase extends YogaNode implements Cloneable {
nativePointers[i] = nodes[i].mNativePointer;
}
if (useVanillaJNI)
YogaNative.jni_YGNodeCalculateLayoutJNI(mNativePointer, width, height, nativePointers, nodes);
else
YogaNative.jni_YGNodeCalculateLayout(mNativePointer, width, height, nativePointers, nodes);
YogaNative.jni_YGNodeCalculateLayoutJNI(mNativePointer, width, height, nativePointers, nodes);
}
private void freeze(YogaNode parent) {
Object data = getData();
if (data instanceof Inputs) {
((Inputs) data).freeze(this, parent);
}
}
public void dirty() {
if (useVanillaJNI)
YogaNative.jni_YGNodeMarkDirtyJNI(mNativePointer);
else
YogaNative.jni_YGNodeMarkDirty(mNativePointer);
YogaNative.jni_YGNodeMarkDirtyJNI(mNativePointer);
}
public void dirtyAllDescendants() {
if (useVanillaJNI)
YogaNative.jni_YGNodeMarkDirtyAndPropogateToDescendantsJNI(mNativePointer);
else
YogaNative.jni_YGNodeMarkDirtyAndPropogateToDescendants(mNativePointer);
YogaNative.jni_YGNodeMarkDirtyAndPropogateToDescendantsJNI(mNativePointer);
}
public boolean isDirty() {
return useVanillaJNI ? YogaNative.jni_YGNodeIsDirtyJNI(mNativePointer) : YogaNative.jni_YGNodeIsDirty(mNativePointer);
return YogaNative.jni_YGNodeIsDirtyJNI(mNativePointer);
}
@Override
public void copyStyle(YogaNode srcNode) {
if (useVanillaJNI)
YogaNative.jni_YGNodeCopyStyleJNI(mNativePointer, ((YogaNodeJNIBase) srcNode).mNativePointer);
else
YogaNative.jni_YGNodeCopyStyle(mNativePointer, ((YogaNodeJNIBase) srcNode).mNativePointer);
if (!(srcNode instanceof YogaNodeJNIBase)) {
return;
}
YogaNative.jni_YGNodeCopyStyleJNI(mNativePointer, ((YogaNodeJNIBase) srcNode).mNativePointer);
}
public YogaDirection getStyleDirection() {
return YogaDirection.fromInt(useVanillaJNI ? YogaNative.jni_YGNodeStyleGetDirectionJNI(mNativePointer) : YogaNative.jni_YGNodeStyleGetDirection(mNativePointer));
return YogaDirection.fromInt(YogaNative.jni_YGNodeStyleGetDirectionJNI(mNativePointer));
}
public void setDirection(YogaDirection direction) {
if (useVanillaJNI)
YogaNative.jni_YGNodeStyleSetDirectionJNI(mNativePointer, direction.intValue());
else
YogaNative.jni_YGNodeStyleSetDirection(mNativePointer, direction.intValue());
YogaNative.jni_YGNodeStyleSetDirectionJNI(mNativePointer, direction.intValue());
}
public YogaFlexDirection getFlexDirection() {
return YogaFlexDirection.fromInt(useVanillaJNI ? YogaNative.jni_YGNodeStyleGetFlexDirectionJNI(mNativePointer) : YogaNative.jni_YGNodeStyleGetFlexDirection(mNativePointer));
return YogaFlexDirection.fromInt(YogaNative.jni_YGNodeStyleGetFlexDirectionJNI(mNativePointer));
}
public void setFlexDirection(YogaFlexDirection flexDirection) {
if (useVanillaJNI)
YogaNative.jni_YGNodeStyleSetFlexDirectionJNI(mNativePointer, flexDirection.intValue());
else
YogaNative.jni_YGNodeStyleSetFlexDirection(mNativePointer, flexDirection.intValue());
YogaNative.jni_YGNodeStyleSetFlexDirectionJNI(mNativePointer, flexDirection.intValue());
}
public YogaJustify getJustifyContent() {
return YogaJustify.fromInt(useVanillaJNI ? YogaNative.jni_YGNodeStyleGetJustifyContentJNI(mNativePointer) : YogaNative.jni_YGNodeStyleGetJustifyContent(mNativePointer));
return YogaJustify.fromInt(YogaNative.jni_YGNodeStyleGetJustifyContentJNI(mNativePointer));
}
public void setJustifyContent(YogaJustify justifyContent) {
if (useVanillaJNI)
YogaNative.jni_YGNodeStyleSetJustifyContentJNI(mNativePointer, justifyContent.intValue());
else
YogaNative.jni_YGNodeStyleSetJustifyContent(mNativePointer, justifyContent.intValue());
YogaNative.jni_YGNodeStyleSetJustifyContentJNI(mNativePointer, justifyContent.intValue());
}
public YogaAlign getAlignItems() {
return YogaAlign.fromInt(useVanillaJNI ? YogaNative.jni_YGNodeStyleGetAlignItemsJNI(mNativePointer) : YogaNative.jni_YGNodeStyleGetAlignItems(mNativePointer));
return YogaAlign.fromInt(YogaNative.jni_YGNodeStyleGetAlignItemsJNI(mNativePointer));
}
public void setAlignItems(YogaAlign alignItems) {
if (useVanillaJNI)
YogaNative.jni_YGNodeStyleSetAlignItemsJNI(mNativePointer, alignItems.intValue());
else
YogaNative.jni_YGNodeStyleSetAlignItems(mNativePointer, alignItems.intValue());
YogaNative.jni_YGNodeStyleSetAlignItemsJNI(mNativePointer, alignItems.intValue());
}
public YogaAlign getAlignSelf() {
return YogaAlign.fromInt(useVanillaJNI ? YogaNative.jni_YGNodeStyleGetAlignSelfJNI(mNativePointer) : YogaNative.jni_YGNodeStyleGetAlignSelf(mNativePointer));
return YogaAlign.fromInt(YogaNative.jni_YGNodeStyleGetAlignSelfJNI(mNativePointer));
}
public void setAlignSelf(YogaAlign alignSelf) {
if (useVanillaJNI)
YogaNative.jni_YGNodeStyleSetAlignSelfJNI(mNativePointer, alignSelf.intValue());
else
YogaNative.jni_YGNodeStyleSetAlignSelf(mNativePointer, alignSelf.intValue());
YogaNative.jni_YGNodeStyleSetAlignSelfJNI(mNativePointer, alignSelf.intValue());
}
public YogaAlign getAlignContent() {
return YogaAlign.fromInt(useVanillaJNI ? YogaNative.jni_YGNodeStyleGetAlignContentJNI(mNativePointer) : YogaNative.jni_YGNodeStyleGetAlignContent(mNativePointer));
return YogaAlign.fromInt(YogaNative.jni_YGNodeStyleGetAlignContentJNI(mNativePointer));
}
public void setAlignContent(YogaAlign alignContent) {
if (useVanillaJNI)
YogaNative.jni_YGNodeStyleSetAlignContentJNI(mNativePointer, alignContent.intValue());
else
YogaNative.jni_YGNodeStyleSetAlignContent(mNativePointer, alignContent.intValue());
YogaNative.jni_YGNodeStyleSetAlignContentJNI(mNativePointer, alignContent.intValue());
}
public YogaPositionType getPositionType() {
return YogaPositionType.fromInt(useVanillaJNI ? YogaNative.jni_YGNodeStyleGetPositionTypeJNI(mNativePointer) : YogaNative.jni_YGNodeStyleGetPositionType(mNativePointer));
return YogaPositionType.fromInt(YogaNative.jni_YGNodeStyleGetPositionTypeJNI(mNativePointer));
}
public void setPositionType(YogaPositionType positionType) {
if (useVanillaJNI)
YogaNative.jni_YGNodeStyleSetPositionTypeJNI(mNativePointer, positionType.intValue());
else
YogaNative.jni_YGNodeStyleSetPositionType(mNativePointer, positionType.intValue());
YogaNative.jni_YGNodeStyleSetPositionTypeJNI(mNativePointer, positionType.intValue());
}
public YogaWrap getWrap() {
return YogaWrap.fromInt(useVanillaJNI ? YogaNative.jni_YGNodeStyleGetFlexWrapJNI(mNativePointer) : YogaNative.jni_YGNodeStyleGetFlexWrap(mNativePointer));
return YogaWrap.fromInt(YogaNative.jni_YGNodeStyleGetFlexWrapJNI(mNativePointer));
}
public void setWrap(YogaWrap flexWrap) {
if (useVanillaJNI)
YogaNative.jni_YGNodeStyleSetFlexWrapJNI(mNativePointer, flexWrap.intValue());
else
YogaNative.jni_YGNodeStyleSetFlexWrap(mNativePointer, flexWrap.intValue());
YogaNative.jni_YGNodeStyleSetFlexWrapJNI(mNativePointer, flexWrap.intValue());
}
public YogaOverflow getOverflow() {
return YogaOverflow.fromInt(useVanillaJNI ? YogaNative.jni_YGNodeStyleGetOverflowJNI(mNativePointer) : YogaNative.jni_YGNodeStyleGetOverflow(mNativePointer));
return YogaOverflow.fromInt(YogaNative.jni_YGNodeStyleGetOverflowJNI(mNativePointer));
}
public void setOverflow(YogaOverflow overflow) {
if (useVanillaJNI)
YogaNative.jni_YGNodeStyleSetOverflowJNI(mNativePointer, overflow.intValue());
else
YogaNative.jni_YGNodeStyleSetOverflow(mNativePointer, overflow.intValue());
YogaNative.jni_YGNodeStyleSetOverflowJNI(mNativePointer, overflow.intValue());
}
public YogaDisplay getDisplay() {
return YogaDisplay.fromInt(useVanillaJNI ? YogaNative.jni_YGNodeStyleGetDisplayJNI(mNativePointer) : YogaNative.jni_YGNodeStyleGetDisplay(mNativePointer));
return YogaDisplay.fromInt(YogaNative.jni_YGNodeStyleGetDisplayJNI(mNativePointer));
}
public void setDisplay(YogaDisplay display) {
if (useVanillaJNI)
YogaNative.jni_YGNodeStyleSetDisplayJNI(mNativePointer, display.intValue());
else
YogaNative.jni_YGNodeStyleSetDisplay(mNativePointer, display.intValue());
YogaNative.jni_YGNodeStyleSetDisplayJNI(mNativePointer, display.intValue());
}
public float getFlex() {
return useVanillaJNI ? YogaNative.jni_YGNodeStyleGetFlexJNI(mNativePointer) : YogaNative.jni_YGNodeStyleGetFlex(mNativePointer);
return YogaNative.jni_YGNodeStyleGetFlexJNI(mNativePointer);
}
public void setFlex(float flex) {
if (useVanillaJNI) {
YogaNative.jni_YGNodeStyleSetFlexJNI(mNativePointer, flex);
} else {
YogaNative.jni_YGNodeStyleSetFlex(mNativePointer, flex);
}
YogaNative.jni_YGNodeStyleSetFlexJNI(mNativePointer, flex);
}
public float getFlexGrow() {
return useVanillaJNI ? YogaNative.jni_YGNodeStyleGetFlexGrowJNI(mNativePointer) : YogaNative.jni_YGNodeStyleGetFlexGrow(mNativePointer);
return YogaNative.jni_YGNodeStyleGetFlexGrowJNI(mNativePointer);
}
public void setFlexGrow(float flexGrow) {
if (useVanillaJNI)
YogaNative.jni_YGNodeStyleSetFlexGrowJNI(mNativePointer, flexGrow);
else
YogaNative.jni_YGNodeStyleSetFlexGrow(mNativePointer, flexGrow);
YogaNative.jni_YGNodeStyleSetFlexGrowJNI(mNativePointer, flexGrow);
}
public float getFlexShrink() {
return useVanillaJNI ? YogaNative.jni_YGNodeStyleGetFlexShrinkJNI(mNativePointer) : YogaNative.jni_YGNodeStyleGetFlexShrink(mNativePointer);
return YogaNative.jni_YGNodeStyleGetFlexShrinkJNI(mNativePointer);
}
public void setFlexShrink(float flexShrink) {
if (useVanillaJNI)
YogaNative.jni_YGNodeStyleSetFlexShrinkJNI(mNativePointer, flexShrink);
else
YogaNative.jni_YGNodeStyleSetFlexShrink(mNativePointer, flexShrink);
YogaNative.jni_YGNodeStyleSetFlexShrinkJNI(mNativePointer, flexShrink);
}
public YogaValue getFlexBasis() {
return valueFromLong(useVanillaJNI ? YogaNative.jni_YGNodeStyleGetFlexBasisJNI(mNativePointer) : YogaNative.jni_YGNodeStyleGetFlexBasis(mNativePointer));
return valueFromLong(YogaNative.jni_YGNodeStyleGetFlexBasisJNI(mNativePointer));
}
public void setFlexBasis(float flexBasis) {
if (useVanillaJNI)
YogaNative.jni_YGNodeStyleSetFlexBasisJNI(mNativePointer, flexBasis);
else
YogaNative.jni_YGNodeStyleSetFlexBasis(mNativePointer, flexBasis);
YogaNative.jni_YGNodeStyleSetFlexBasisJNI(mNativePointer, flexBasis);
}
public void setFlexBasisPercent(float percent) {
if (useVanillaJNI)
YogaNative.jni_YGNodeStyleSetFlexBasisPercentJNI(mNativePointer, percent);
else
YogaNative.jni_YGNodeStyleSetFlexBasisPercent(mNativePointer, percent);
YogaNative.jni_YGNodeStyleSetFlexBasisPercentJNI(mNativePointer, percent);
}
public void setFlexBasisAuto() {
if (useVanillaJNI)
YogaNative.jni_YGNodeStyleSetFlexBasisAutoJNI(mNativePointer);
else
YogaNative.jni_YGNodeStyleSetFlexBasisAuto(mNativePointer);
YogaNative.jni_YGNodeStyleSetFlexBasisAutoJNI(mNativePointer);
}
public YogaValue getMargin(YogaEdge edge) {
return valueFromLong(useVanillaJNI ? YogaNative.jni_YGNodeStyleGetMarginJNI(mNativePointer, edge.intValue()) : YogaNative.jni_YGNodeStyleGetMargin(mNativePointer, edge.intValue()));
return valueFromLong(YogaNative.jni_YGNodeStyleGetMarginJNI(mNativePointer, edge.intValue()));
}
public void setMargin(YogaEdge edge, float margin) {
if (useVanillaJNI)
YogaNative.jni_YGNodeStyleSetMarginJNI(mNativePointer, edge.intValue(), margin);
else
YogaNative.jni_YGNodeStyleSetMargin(mNativePointer, edge.intValue(), margin);
YogaNative.jni_YGNodeStyleSetMarginJNI(mNativePointer, edge.intValue(), margin);
}
public void setMarginPercent(YogaEdge edge, float percent) {
if (useVanillaJNI)
YogaNative.jni_YGNodeStyleSetMarginPercentJNI(mNativePointer, edge.intValue(), percent);
else
YogaNative.jni_YGNodeStyleSetMarginPercent(mNativePointer, edge.intValue(), percent);
YogaNative.jni_YGNodeStyleSetMarginPercentJNI(mNativePointer, edge.intValue(), percent);
}
public void setMarginAuto(YogaEdge edge) {
if (useVanillaJNI)
YogaNative.jni_YGNodeStyleSetMarginAutoJNI(mNativePointer, edge.intValue());
else
YogaNative.jni_YGNodeStyleSetMarginAuto(mNativePointer, edge.intValue());
YogaNative.jni_YGNodeStyleSetMarginAutoJNI(mNativePointer, edge.intValue());
}
public YogaValue getPadding(YogaEdge edge) {
return valueFromLong(useVanillaJNI ? YogaNative.jni_YGNodeStyleGetPaddingJNI(mNativePointer, edge.intValue()) : YogaNative.jni_YGNodeStyleGetPadding(mNativePointer, edge.intValue()));
return valueFromLong(YogaNative.jni_YGNodeStyleGetPaddingJNI(mNativePointer, edge.intValue()));
}
public void setPadding(YogaEdge edge, float padding) {
if (useVanillaJNI)
YogaNative.jni_YGNodeStyleSetPaddingJNI(mNativePointer, edge.intValue(), padding);
else
YogaNative.jni_YGNodeStyleSetPadding(mNativePointer, edge.intValue(), padding);
YogaNative.jni_YGNodeStyleSetPaddingJNI(mNativePointer, edge.intValue(), padding);
}
public void setPaddingPercent(YogaEdge edge, float percent) {
if (useVanillaJNI)
YogaNative.jni_YGNodeStyleSetPaddingPercentJNI(mNativePointer, edge.intValue(), percent);
else
YogaNative.jni_YGNodeStyleSetPaddingPercent(mNativePointer, edge.intValue(), percent);
YogaNative.jni_YGNodeStyleSetPaddingPercentJNI(mNativePointer, edge.intValue(), percent);
}
public float getBorder(YogaEdge edge) {
return useVanillaJNI ? YogaNative.jni_YGNodeStyleGetBorderJNI(mNativePointer, edge.intValue()) : YogaNative.jni_YGNodeStyleGetBorder(mNativePointer, edge.intValue());
return YogaNative.jni_YGNodeStyleGetBorderJNI(mNativePointer, edge.intValue());
}
public void setBorder(YogaEdge edge, float border) {
if (useVanillaJNI)
YogaNative.jni_YGNodeStyleSetBorderJNI(mNativePointer, edge.intValue(), border);
else
YogaNative.jni_YGNodeStyleSetBorder(mNativePointer, edge.intValue(), border);
YogaNative.jni_YGNodeStyleSetBorderJNI(mNativePointer, edge.intValue(), border);
}
public YogaValue getPosition(YogaEdge edge) {
return valueFromLong(useVanillaJNI ? YogaNative.jni_YGNodeStyleGetPositionJNI(mNativePointer, edge.intValue()) : YogaNative.jni_YGNodeStyleGetPosition(mNativePointer, edge.intValue()));
return valueFromLong(YogaNative.jni_YGNodeStyleGetPositionJNI(mNativePointer, edge.intValue()));
}
public void setPosition(YogaEdge edge, float position) {
if (useVanillaJNI)
YogaNative.jni_YGNodeStyleSetPositionJNI(mNativePointer, edge.intValue(), position);
else
YogaNative.jni_YGNodeStyleSetPosition(mNativePointer, edge.intValue(), position);
YogaNative.jni_YGNodeStyleSetPositionJNI(mNativePointer, edge.intValue(), position);
}
public void setPositionPercent(YogaEdge edge, float percent) {
if (useVanillaJNI)
YogaNative.jni_YGNodeStyleSetPositionPercentJNI(mNativePointer, edge.intValue(), percent);
else
YogaNative.jni_YGNodeStyleSetPositionPercent(mNativePointer, edge.intValue(), percent);
YogaNative.jni_YGNodeStyleSetPositionPercentJNI(mNativePointer, edge.intValue(), percent);
}
public YogaValue getWidth() {
return valueFromLong(useVanillaJNI ? YogaNative.jni_YGNodeStyleGetWidthJNI(mNativePointer) : YogaNative.jni_YGNodeStyleGetWidth(mNativePointer));
return valueFromLong(YogaNative.jni_YGNodeStyleGetWidthJNI(mNativePointer));
}
public void setWidth(float width) {
if (useVanillaJNI)
YogaNative.jni_YGNodeStyleSetWidthJNI(mNativePointer, width);
else
YogaNative.jni_YGNodeStyleSetWidth(mNativePointer, width);
YogaNative.jni_YGNodeStyleSetWidthJNI(mNativePointer, width);
}
public void setWidthPercent(float percent) {
if (useVanillaJNI)
YogaNative.jni_YGNodeStyleSetWidthPercentJNI(mNativePointer, percent);
else
YogaNative.jni_YGNodeStyleSetWidthPercent(mNativePointer, percent);
YogaNative.jni_YGNodeStyleSetWidthPercentJNI(mNativePointer, percent);
}
public void setWidthAuto() {
if (useVanillaJNI)
YogaNative.jni_YGNodeStyleSetWidthAutoJNI(mNativePointer);
else
YogaNative.jni_YGNodeStyleSetWidthAuto(mNativePointer);
YogaNative.jni_YGNodeStyleSetWidthAutoJNI(mNativePointer);
}
public YogaValue getHeight() {
return valueFromLong(useVanillaJNI ? YogaNative.jni_YGNodeStyleGetHeightJNI(mNativePointer) : YogaNative.jni_YGNodeStyleGetHeight(mNativePointer));
return valueFromLong(YogaNative.jni_YGNodeStyleGetHeightJNI(mNativePointer));
}
public void setHeight(float height) {
if (useVanillaJNI)
YogaNative.jni_YGNodeStyleSetHeightJNI(mNativePointer, height);
else
YogaNative.jni_YGNodeStyleSetHeight(mNativePointer, height);
YogaNative.jni_YGNodeStyleSetHeightJNI(mNativePointer, height);
}
public void setHeightPercent(float percent) {
if (useVanillaJNI)
YogaNative.jni_YGNodeStyleSetHeightPercentJNI(mNativePointer, percent);
else
YogaNative.jni_YGNodeStyleSetHeightPercent(mNativePointer, percent);
YogaNative.jni_YGNodeStyleSetHeightPercentJNI(mNativePointer, percent);
}
public void setHeightAuto() {
if (useVanillaJNI)
YogaNative.jni_YGNodeStyleSetHeightAutoJNI(mNativePointer);
else
YogaNative.jni_YGNodeStyleSetHeightAuto(mNativePointer);
YogaNative.jni_YGNodeStyleSetHeightAutoJNI(mNativePointer);
}
public YogaValue getMinWidth() {
return valueFromLong(useVanillaJNI ? YogaNative.jni_YGNodeStyleGetMinWidthJNI(mNativePointer) : YogaNative.jni_YGNodeStyleGetMinWidth(mNativePointer));
return valueFromLong(YogaNative.jni_YGNodeStyleGetMinWidthJNI(mNativePointer));
}
public void setMinWidth(float minWidth) {
if (useVanillaJNI)
YogaNative.jni_YGNodeStyleSetMinWidthJNI(mNativePointer, minWidth);
else
YogaNative.jni_YGNodeStyleSetMinWidth(mNativePointer, minWidth);
YogaNative.jni_YGNodeStyleSetMinWidthJNI(mNativePointer, minWidth);
}
public void setMinWidthPercent(float percent) {
if (useVanillaJNI)
YogaNative.jni_YGNodeStyleSetMinWidthPercentJNI(mNativePointer, percent);
else
YogaNative.jni_YGNodeStyleSetMinWidthPercent(mNativePointer, percent);
YogaNative.jni_YGNodeStyleSetMinWidthPercentJNI(mNativePointer, percent);
}
public YogaValue getMinHeight() {
return valueFromLong(useVanillaJNI ? YogaNative.jni_YGNodeStyleGetMinHeightJNI(mNativePointer) : YogaNative.jni_YGNodeStyleGetMinHeight(mNativePointer));
return valueFromLong(YogaNative.jni_YGNodeStyleGetMinHeightJNI(mNativePointer));
}
public void setMinHeight(float minHeight) {
if (useVanillaJNI)
YogaNative.jni_YGNodeStyleSetMinHeightJNI(mNativePointer, minHeight);
else
YogaNative.jni_YGNodeStyleSetMinHeight(mNativePointer, minHeight);
YogaNative.jni_YGNodeStyleSetMinHeightJNI(mNativePointer, minHeight);
}
public void setMinHeightPercent(float percent) {
if (useVanillaJNI)
YogaNative.jni_YGNodeStyleSetMinHeightPercentJNI(mNativePointer, percent);
else
YogaNative.jni_YGNodeStyleSetMinHeightPercent(mNativePointer, percent);
YogaNative.jni_YGNodeStyleSetMinHeightPercentJNI(mNativePointer, percent);
}
public YogaValue getMaxWidth() {
return valueFromLong(useVanillaJNI ? YogaNative.jni_YGNodeStyleGetMaxWidthJNI(mNativePointer) : YogaNative.jni_YGNodeStyleGetMaxWidth(mNativePointer));
return valueFromLong(YogaNative.jni_YGNodeStyleGetMaxWidthJNI(mNativePointer));
}
public void setMaxWidth(float maxWidth) {
if (useVanillaJNI)
YogaNative.jni_YGNodeStyleSetMaxWidthJNI(mNativePointer, maxWidth);
else
YogaNative.jni_YGNodeStyleSetMaxWidth(mNativePointer, maxWidth);
YogaNative.jni_YGNodeStyleSetMaxWidthJNI(mNativePointer, maxWidth);
}
public void setMaxWidthPercent(float percent) {
if (useVanillaJNI)
YogaNative.jni_YGNodeStyleSetMaxWidthPercentJNI(mNativePointer, percent);
else
YogaNative.jni_YGNodeStyleSetMaxWidthPercent(mNativePointer, percent);
YogaNative.jni_YGNodeStyleSetMaxWidthPercentJNI(mNativePointer, percent);
}
public YogaValue getMaxHeight() {
return valueFromLong(useVanillaJNI ? YogaNative.jni_YGNodeStyleGetMaxHeightJNI(mNativePointer) : YogaNative.jni_YGNodeStyleGetMaxHeight(mNativePointer));
return valueFromLong(YogaNative.jni_YGNodeStyleGetMaxHeightJNI(mNativePointer));
}
public void setMaxHeight(float maxheight) {
if (useVanillaJNI)
YogaNative.jni_YGNodeStyleSetMaxHeightJNI(mNativePointer, maxheight);
else
YogaNative.jni_YGNodeStyleSetMaxHeight(mNativePointer, maxheight);
YogaNative.jni_YGNodeStyleSetMaxHeightJNI(mNativePointer, maxheight);
}
public void setMaxHeightPercent(float percent) {
if (useVanillaJNI)
YogaNative.jni_YGNodeStyleSetMaxHeightPercentJNI(mNativePointer, percent);
else
YogaNative.jni_YGNodeStyleSetMaxHeightPercent(mNativePointer, percent);
YogaNative.jni_YGNodeStyleSetMaxHeightPercentJNI(mNativePointer, percent);
}
public float getAspectRatio() {
return useVanillaJNI ? YogaNative.jni_YGNodeStyleGetAspectRatioJNI(mNativePointer) : YogaNative.jni_YGNodeStyleGetAspectRatio(mNativePointer);
return YogaNative.jni_YGNodeStyleGetAspectRatioJNI(mNativePointer);
}
public void setAspectRatio(float aspectRatio) {
if (useVanillaJNI)
YogaNative.jni_YGNodeStyleSetAspectRatioJNI(mNativePointer, aspectRatio);
else
YogaNative.jni_YGNodeStyleSetAspectRatio(mNativePointer, aspectRatio);
YogaNative.jni_YGNodeStyleSetAspectRatioJNI(mNativePointer, aspectRatio);
}
public void setMeasureFunction(YogaMeasureFunction measureFunction) {
mMeasureFunction = measureFunction;
if (useVanillaJNI)
YogaNative.jni_YGNodeSetHasMeasureFuncJNI(mNativePointer, measureFunction != null);
else
YogaNative.jni_YGNodeSetHasMeasureFunc(mNativePointer, measureFunction != null);
YogaNative.jni_YGNodeSetHasMeasureFuncJNI(mNativePointer, measureFunction != null);
}
// Implementation Note: Why this method needs to stay final
@@ -638,10 +530,7 @@ public abstract class YogaNodeJNIBase extends YogaNode implements Cloneable {
public void setBaselineFunction(YogaBaselineFunction baselineFunction) {
mBaselineFunction = baselineFunction;
if (useVanillaJNI)
YogaNative.jni_YGNodeSetHasBaselineFuncJNI(mNativePointer, baselineFunction != null);
else
YogaNative.jni_YGNodeSetHasBaselineFunc(mNativePointer, baselineFunction != null);
YogaNative.jni_YGNodeSetHasBaselineFuncJNI(mNativePointer, baselineFunction != null);
}
@DoNotStrip
@@ -668,14 +557,11 @@ public abstract class YogaNodeJNIBase extends YogaNode implements Cloneable {
}
/**
* Use the set logger (defaults to adb log) to print out the styles, children, and computed
* layout of the tree rooted at this node.
* Use the set logger (defaults to adb log) to print out the styles, children, and computed layout
* of the tree rooted at this node.
*/
public void print() {
if (useVanillaJNI)
YogaNative.jni_YGNodePrintJNI(mNativePointer);
else
YogaNative.jni_YGNodePrint(mNativePointer);
YogaNative.jni_YGNodePrintJNI(mNativePointer);
}
/**
@@ -683,7 +569,7 @@ public abstract class YogaNodeJNIBase extends YogaNode implements Cloneable {
* This is different than calling removeChildAt and addChildAt because this method ONLY replaces
* the child in the mChildren datastructure. @DoNotStrip: called from JNI
*
* @return the nativePointer of the newNode {@linl YogaNode}
* @return the nativePointer of the newNode {@link YogaNode}
*/
@DoNotStrip
private final long replaceChild(YogaNodeJNIBase newNode, int childIndex) {
@@ -721,7 +607,9 @@ public abstract class YogaNodeJNIBase extends YogaNode implements Cloneable {
}
public boolean getDoesLegacyStretchFlagAffectsLayout() {
return arr != null && (((int) arr[LAYOUT_EDGE_SET_FLAG_INDEX] & DOES_LEGACY_STRETCH_BEHAVIOUR) == DOES_LEGACY_STRETCH_BEHAVIOUR);
return arr != null
&& (((int) arr[LAYOUT_EDGE_SET_FLAG_INDEX] & DOES_LEGACY_STRETCH_BEHAVIOUR)
== DOES_LEGACY_STRETCH_BEHAVIOUR);
}
@Override
@@ -737,9 +625,13 @@ public abstract class YogaNodeJNIBase extends YogaNode implements Cloneable {
case BOTTOM:
return arr[LAYOUT_MARGIN_START_INDEX + 3];
case START:
return getLayoutDirection() == YogaDirection.RTL ? arr[LAYOUT_MARGIN_START_INDEX + 2] : arr[LAYOUT_MARGIN_START_INDEX];
return getLayoutDirection() == YogaDirection.RTL
? arr[LAYOUT_MARGIN_START_INDEX + 2]
: arr[LAYOUT_MARGIN_START_INDEX];
case END:
return getLayoutDirection() == YogaDirection.RTL ? arr[LAYOUT_MARGIN_START_INDEX] : arr[LAYOUT_MARGIN_START_INDEX + 2];
return getLayoutDirection() == YogaDirection.RTL
? arr[LAYOUT_MARGIN_START_INDEX]
: arr[LAYOUT_MARGIN_START_INDEX + 2];
default:
throw new IllegalArgumentException("Cannot get layout margins of multi-edge shorthands");
}
@@ -751,7 +643,9 @@ public abstract class YogaNodeJNIBase extends YogaNode implements Cloneable {
@Override
public float getLayoutPadding(YogaEdge edge) {
if (arr != null && ((int) arr[LAYOUT_EDGE_SET_FLAG_INDEX] & PADDING) == PADDING) {
int paddingStartIndex = LAYOUT_PADDING_START_INDEX - ((((int)arr[LAYOUT_EDGE_SET_FLAG_INDEX] & MARGIN) == MARGIN) ? 0 : 4);
int paddingStartIndex =
LAYOUT_PADDING_START_INDEX
- ((((int) arr[LAYOUT_EDGE_SET_FLAG_INDEX] & MARGIN) == MARGIN) ? 0 : 4);
switch (edge) {
case LEFT:
return arr[paddingStartIndex];
@@ -762,9 +656,13 @@ public abstract class YogaNodeJNIBase extends YogaNode implements Cloneable {
case BOTTOM:
return arr[paddingStartIndex + 3];
case START:
return getLayoutDirection() == YogaDirection.RTL ? arr[paddingStartIndex + 2] : arr[paddingStartIndex];
return getLayoutDirection() == YogaDirection.RTL
? arr[paddingStartIndex + 2]
: arr[paddingStartIndex];
case END:
return getLayoutDirection() == YogaDirection.RTL ? arr[paddingStartIndex] : arr[paddingStartIndex + 2];
return getLayoutDirection() == YogaDirection.RTL
? arr[paddingStartIndex]
: arr[paddingStartIndex + 2];
default:
throw new IllegalArgumentException("Cannot get layout paddings of multi-edge shorthands");
}
@@ -776,7 +674,10 @@ public abstract class YogaNodeJNIBase extends YogaNode implements Cloneable {
@Override
public float getLayoutBorder(YogaEdge edge) {
if (arr != null && ((int) arr[LAYOUT_EDGE_SET_FLAG_INDEX] & BORDER) == BORDER) {
int borderStartIndex = LAYOUT_BORDER_START_INDEX - ((((int) arr[LAYOUT_EDGE_SET_FLAG_INDEX] & MARGIN) == MARGIN) ? 0 : 4) - ((((int) arr[LAYOUT_EDGE_SET_FLAG_INDEX] & PADDING) == PADDING) ? 0 : 4);
int borderStartIndex =
LAYOUT_BORDER_START_INDEX
- ((((int) arr[LAYOUT_EDGE_SET_FLAG_INDEX] & MARGIN) == MARGIN) ? 0 : 4)
- ((((int) arr[LAYOUT_EDGE_SET_FLAG_INDEX] & PADDING) == PADDING) ? 0 : 4);
switch (edge) {
case LEFT:
return arr[borderStartIndex];
@@ -787,9 +688,13 @@ public abstract class YogaNodeJNIBase extends YogaNode implements Cloneable {
case BOTTOM:
return arr[borderStartIndex + 3];
case START:
return getLayoutDirection() == YogaDirection.RTL ? arr[borderStartIndex + 2] : arr[borderStartIndex];
return getLayoutDirection() == YogaDirection.RTL
? arr[borderStartIndex + 2]
: arr[borderStartIndex];
case END:
return getLayoutDirection() == YogaDirection.RTL ? arr[borderStartIndex] : arr[borderStartIndex + 2];
return getLayoutDirection() == YogaDirection.RTL
? arr[borderStartIndex]
: arr[borderStartIndex + 2];
default:
throw new IllegalArgumentException("Cannot get layout border of multi-edge shorthands");
}
@@ -800,7 +705,8 @@ public abstract class YogaNodeJNIBase extends YogaNode implements Cloneable {
@Override
public YogaDirection getLayoutDirection() {
return YogaDirection.fromInt(arr != null ? (int) arr[LAYOUT_DIRECTION_INDEX] : mLayoutDirection);
return YogaDirection.fromInt(
arr != null ? (int) arr[LAYOUT_DIRECTION_INDEX] : mLayoutDirection);
}
@Override

View File

@@ -12,10 +12,6 @@ public class YogaNodeJNIFinalizer extends YogaNodeJNIBase {
super();
}
public YogaNodeJNIFinalizer(boolean useVanillaJNI) {
super(useVanillaJNI);
}
public YogaNodeJNIFinalizer(YogaConfig config) {
super(config);
}
@@ -33,10 +29,7 @@ public class YogaNodeJNIFinalizer extends YogaNodeJNIBase {
if (mNativePointer != 0) {
long nativePointer = mNativePointer;
mNativePointer = 0;
if (useVanillaJNI)
YogaNative.jni_YGNodeFreeJNI(nativePointer);
else
YogaNative.jni_YGNodeFree(nativePointer);
YogaNative.jni_YGNodeFreeJNI(nativePointer);
}
}
}

View File

@@ -7,9 +7,6 @@
package com.facebook.yoga;
import com.facebook.proguard.annotations.DoNotStrip;
@DoNotStrip
public enum YogaNodeType {
DEFAULT(0),
TEXT(1);

View File

@@ -7,9 +7,6 @@
package com.facebook.yoga;
import com.facebook.proguard.annotations.DoNotStrip;
@DoNotStrip
public enum YogaOverflow {
VISIBLE(0),
HIDDEN(1),

View File

@@ -7,12 +7,10 @@
package com.facebook.yoga;
import com.facebook.proguard.annotations.DoNotStrip;
@DoNotStrip
public enum YogaPositionType {
RELATIVE(0),
ABSOLUTE(1);
STATIC(0),
RELATIVE(1),
ABSOLUTE(2);
private final int mIntValue;
@@ -26,8 +24,9 @@ public enum YogaPositionType {
public static YogaPositionType fromInt(int value) {
switch (value) {
case 0: return RELATIVE;
case 1: return ABSOLUTE;
case 0: return STATIC;
case 1: return RELATIVE;
case 2: return ABSOLUTE;
default: throw new IllegalArgumentException("Unknown enum value: " + value);
}
}

View File

@@ -7,9 +7,6 @@
package com.facebook.yoga;
import com.facebook.proguard.annotations.DoNotStrip;
@DoNotStrip
public enum YogaPrintOptions {
LAYOUT(1),
STYLE(2),

View File

@@ -0,0 +1,151 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
package com.facebook.yoga;
public interface YogaProps {
/* Width properties */
void setWidth(float width);
void setWidthPercent(float percent);
void setMinWidth(float minWidth);
void setMinWidthPercent(float percent);
void setMaxWidth(float maxWidth);
void setMaxWidthPercent(float percent);
void setWidthAuto();
/* Height properties */
void setHeight(float height);
void setHeightPercent(float percent);
void setMinHeight(float minHeight);
void setMinHeightPercent(float percent);
void setMaxHeight(float maxHeight);
void setMaxHeightPercent(float percent);
void setHeightAuto();
/* Margin properties */
void setMargin(YogaEdge edge, float margin);
void setMarginPercent(YogaEdge edge, float percent);
void setMarginAuto(YogaEdge edge);
/* Padding properties */
void setPadding(YogaEdge edge, float padding);
void setPaddingPercent(YogaEdge edge, float percent);
/* Position properties */
void setPositionType(YogaPositionType positionType);
void setPosition(YogaEdge edge, float position);
void setPositionPercent(YogaEdge edge, float percent);
/* Alignment properties */
void setAlignContent(YogaAlign alignContent);
void setAlignItems(YogaAlign alignItems);
void setAlignSelf(YogaAlign alignSelf);
/* Flex properties */
void setFlex(float flex);
void setFlexBasisAuto();
void setFlexBasisPercent(float percent);
void setFlexBasis(float flexBasis);
void setFlexDirection(YogaFlexDirection direction);
void setFlexGrow(float flexGrow);
void setFlexShrink(float flexShrink);
/* Other properties */
void setJustifyContent(YogaJustify justifyContent);
void setDirection(YogaDirection direction);
void setBorder(YogaEdge edge, float value);
void setWrap(YogaWrap wrap);
void setAspectRatio(float aspectRatio);
void setIsReferenceBaseline(boolean isReferenceBaseline);
void setMeasureFunction(YogaMeasureFunction measureFunction);
void setBaselineFunction(YogaBaselineFunction yogaBaselineFunction);
/* Getters */
YogaValue getWidth();
YogaValue getMinWidth();
YogaValue getMaxWidth();
YogaValue getHeight();
YogaValue getMinHeight();
YogaValue getMaxHeight();
YogaDirection getStyleDirection();
YogaFlexDirection getFlexDirection();
YogaJustify getJustifyContent();
YogaAlign getAlignItems();
YogaAlign getAlignSelf();
YogaAlign getAlignContent();
YogaPositionType getPositionType();
float getFlexGrow();
float getFlexShrink();
YogaValue getFlexBasis();
float getAspectRatio();
YogaValue getMargin(YogaEdge edge);
YogaValue getPadding(YogaEdge edge);
YogaValue getPosition(YogaEdge edge);
float getBorder(YogaEdge edge);
}

View File

@@ -7,9 +7,6 @@
package com.facebook.yoga;
import com.facebook.proguard.annotations.DoNotStrip;
@DoNotStrip
public class YogaStyleInputs {
public static final short LAYOUT_DIRECTION = 0;
public static final short FLEX_DIRECTION = 1;

View File

@@ -7,9 +7,6 @@
package com.facebook.yoga;
import com.facebook.proguard.annotations.DoNotStrip;
@DoNotStrip
public enum YogaUnit {
UNDEFINED(0),
POINT(1),

View File

@@ -7,9 +7,6 @@
package com.facebook.yoga;
import com.facebook.proguard.annotations.DoNotStrip;
@DoNotStrip
public enum YogaWrap {
NO_WRAP(0),
WRAP(1),

View File

@@ -84,9 +84,7 @@ public:
return *this;
}
~ScopedGlobalRef() {
reset();
}
~ScopedGlobalRef() { reset(); }
/**
* Deletes the currently held reference and reassigns a new one to the
@@ -120,9 +118,7 @@ public:
/**
* Returns true if the underlying JNI reference is not NULL.
*/
operator bool() const {
return mGlobalRef != NULL;
}
operator bool() const { return mGlobalRef != NULL; }
ScopedGlobalRef(const ScopedGlobalRef& ref) = delete;
ScopedGlobalRef& operator=(const ScopedGlobalRef& other) = delete;

View File

@@ -83,9 +83,7 @@ public:
return *this;
}
~ScopedLocalRef() {
reset();
}
~ScopedLocalRef() { reset(); }
/**
* Deletes the currently held reference and reassigns a new one to the
@@ -119,9 +117,7 @@ public:
/**
* Returns true if the underlying JNI reference is not NULL.
*/
operator bool() const {
return mLocalRef != NULL;
}
operator bool() const { return mLocalRef != NULL; }
ScopedLocalRef(const ScopedLocalRef& ref) = delete;
ScopedLocalRef& operator=(const ScopedLocalRef& other) = delete;

View File

@@ -1,712 +0,0 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include <fbjni/fbjni.h>
#include <yoga/YGNode.h>
#include <yoga/Yoga.h>
#include <yoga/Yoga-internal.h>
#include <yoga/log.h>
#include <cstdint>
#include <cstring>
#include <iostream>
#include <map>
#include "YGJTypes.h"
#include "YGJNIVanilla.h"
#include "YGJNI.h"
#include "yogajni.h"
using namespace facebook::jni;
using namespace std;
using facebook::yoga::detail::Log;
static inline local_ref<JYogaNode> YGNodeJobject(
YGNodeRef node,
void* layoutContext) {
return reinterpret_cast<PtrJNodeMap*>(layoutContext)->ref(node);
}
static void YGTransferLayoutDirection(
YGNodeRef node,
alias_ref<jobject> javaNode) {
static auto layoutDirectionField =
javaNode->getClass()->getField<jint>("mLayoutDirection");
javaNode->setFieldValue(
layoutDirectionField, static_cast<jint>(YGNodeLayoutGetDirection(node)));
}
static void YGTransferLayoutOutputsRecursive(
YGNodeRef root,
void* layoutContext) {
if (!root->getHasNewLayout()) {
return;
}
auto obj = YGNodeJobject(root, layoutContext);
if (!obj) {
Log::log(
root,
YGLogLevelError,
nullptr,
"Java YGNode was GCed during layout calculation\n");
return;
}
auto edgesSet = YGNodeEdges{root};
bool marginFieldSet = edgesSet.has(YGNodeEdges::MARGIN);
bool paddingFieldSet = edgesSet.has(YGNodeEdges::PADDING);
bool borderFieldSet = edgesSet.has(YGNodeEdges::BORDER);
int fieldFlags = edgesSet.get();
fieldFlags |= HAS_NEW_LAYOUT;
if (YGNodeLayoutGetDidLegacyStretchFlagAffectLayout(root)) {
fieldFlags |= DOES_LEGACY_STRETCH_BEHAVIOUR;
}
const int arrSize = 6 + (marginFieldSet ? 4 : 0) + (paddingFieldSet ? 4 : 0) +
(borderFieldSet ? 4 : 0);
float arr[18];
arr[LAYOUT_EDGE_SET_FLAG_INDEX] = fieldFlags;
arr[LAYOUT_WIDTH_INDEX] = YGNodeLayoutGetWidth(root);
arr[LAYOUT_HEIGHT_INDEX] = YGNodeLayoutGetHeight(root);
arr[LAYOUT_LEFT_INDEX] = YGNodeLayoutGetLeft(root);
arr[LAYOUT_TOP_INDEX] = YGNodeLayoutGetTop(root);
arr[LAYOUT_DIRECTION_INDEX] =
static_cast<jint>(YGNodeLayoutGetDirection(root));
if (marginFieldSet) {
arr[LAYOUT_MARGIN_START_INDEX] = YGNodeLayoutGetMargin(root, YGEdgeLeft);
arr[LAYOUT_MARGIN_START_INDEX + 1] = YGNodeLayoutGetMargin(root, YGEdgeTop);
arr[LAYOUT_MARGIN_START_INDEX + 2] =
YGNodeLayoutGetMargin(root, YGEdgeRight);
arr[LAYOUT_MARGIN_START_INDEX + 3] =
YGNodeLayoutGetMargin(root, YGEdgeBottom);
}
if (paddingFieldSet) {
int paddingStartIndex =
LAYOUT_PADDING_START_INDEX - (marginFieldSet ? 0 : 4);
arr[paddingStartIndex] = YGNodeLayoutGetPadding(root, YGEdgeLeft);
arr[paddingStartIndex + 1] = YGNodeLayoutGetPadding(root, YGEdgeTop);
arr[paddingStartIndex + 2] = YGNodeLayoutGetPadding(root, YGEdgeRight);
arr[paddingStartIndex + 3] = YGNodeLayoutGetPadding(root, YGEdgeBottom);
}
if (borderFieldSet) {
int borderStartIndex = LAYOUT_BORDER_START_INDEX -
(marginFieldSet ? 0 : 4) - (paddingFieldSet ? 0 : 4);
arr[borderStartIndex] = YGNodeLayoutGetBorder(root, YGEdgeLeft);
arr[borderStartIndex + 1] = YGNodeLayoutGetBorder(root, YGEdgeTop);
arr[borderStartIndex + 2] = YGNodeLayoutGetBorder(root, YGEdgeRight);
arr[borderStartIndex + 3] = YGNodeLayoutGetBorder(root, YGEdgeBottom);
}
static auto arrField = obj->getClass()->getField<jfloatArray>("arr");
local_ref<jfloatArray> arrFinal = make_float_array(arrSize);
arrFinal->setRegion(0, arrSize, arr);
obj->setFieldValue<jfloatArray>(arrField, arrFinal.get());
root->setHasNewLayout(false);
for (uint32_t i = 0; i < YGNodeGetChildCount(root); i++) {
YGTransferLayoutOutputsRecursive(YGNodeGetChild(root, i), layoutContext);
}
}
static void YGPrint(YGNodeRef node, void* layoutContext) {
if (auto obj = YGNodeJobject(node, layoutContext)) {
cout << obj->toString() << endl;
} else {
Log::log(
node,
YGLogLevelError,
nullptr,
"Java YGNode was GCed during layout calculation\n");
}
}
static float YGJNIBaselineFunc(
YGNodeRef node,
float width,
float height,
void* layoutContext) {
if (auto obj = YGNodeJobject(node, layoutContext)) {
return obj->baseline(width, height);
} else {
return height;
}
}
static inline YGNodeRef _jlong2YGNodeRef(jlong addr) {
return reinterpret_cast<YGNodeRef>(static_cast<intptr_t>(addr));
}
static inline YGConfigRef _jlong2YGConfigRef(jlong addr) {
return reinterpret_cast<YGConfigRef>(static_cast<intptr_t>(addr));
}
jlong jni_YGNodeClone(alias_ref<jobject> thiz, jlong nativePointer) {
auto node = _jlong2YGNodeRef(nativePointer);
const YGNodeRef clonedYogaNode = YGNodeClone(node);
clonedYogaNode->setContext(node->getContext());
return reinterpret_cast<jlong>(clonedYogaNode);
}
static YGSize YGJNIMeasureFunc(
YGNodeRef node,
float width,
YGMeasureMode widthMode,
float height,
YGMeasureMode heightMode,
void* layoutContext) {
if (auto obj = YGNodeJobject(node, layoutContext)) {
YGTransferLayoutDirection(node, obj);
const auto measureResult =
obj->measure(width, widthMode, height, heightMode);
static_assert(
sizeof(measureResult) == 8,
"Expected measureResult to be 8 bytes, or two 32 bit ints");
int32_t wBits = 0xFFFFFFFF & (measureResult >> 32);
int32_t hBits = 0xFFFFFFFF & measureResult;
const float* measuredWidth = reinterpret_cast<float*>(&wBits);
const float* measuredHeight = reinterpret_cast<float*>(&hBits);
return YGSize{*measuredWidth, *measuredHeight};
} else {
Log::log(
node,
YGLogLevelError,
nullptr,
"Java YGNode was GCed during layout calculation\n");
return YGSize{
widthMode == YGMeasureModeUndefined ? 0 : width,
heightMode == YGMeasureModeUndefined ? 0 : height,
};
}
}
static int YGJNILogFunc(
const YGConfigRef config,
const YGNodeRef node,
YGLogLevel level,
void* layoutContext,
const char* format,
va_list args) {
int result = vsnprintf(NULL, 0, format, args);
std::vector<char> buffer(1 + result);
vsnprintf(buffer.data(), buffer.size(), format, args);
auto jloggerPtr =
static_cast<global_ref<JYogaLogger>*>(YGConfigGetContext(config));
if (jloggerPtr != nullptr) {
(*jloggerPtr)
->log(
JYogaLogLevel::fromInt(level),
Environment::current()->NewStringUTF(buffer.data()));
}
return result;
}
jlong jni_YGNodeNew(alias_ref<jobject> thiz) {
const YGNodeRef node = YGNodeNew();
node->setContext(YGNodeContext{}.asVoidPtr);
node->setPrintFunc(YGPrint);
return reinterpret_cast<jlong>(node);
}
jlong jni_YGNodeNewWithConfig(alias_ref<jclass>, jlong configPointer) {
const YGNodeRef node = YGNodeNewWithConfig(_jlong2YGConfigRef(configPointer));
node->setContext(YGNodeContext{}.asVoidPtr);
return reinterpret_cast<jlong>(node);
}
void jni_YGNodeFree(alias_ref<jclass>, jlong nativePointer) {
if (nativePointer == 0) {
return;
}
const YGNodeRef node = _jlong2YGNodeRef(nativePointer);
YGNodeFree(node);
}
void jni_YGNodeClearChildren(jlong nativePointer) {
const YGNodeRef node = _jlong2YGNodeRef(nativePointer);
node->clearChildren();
}
void jni_YGNodeReset(jlong nativePointer) {
const YGNodeRef node = _jlong2YGNodeRef(nativePointer);
void* context = node->getContext();
YGNodeReset(node);
node->setContext(context);
}
void jni_YGNodePrint(jlong nativePointer) {
#ifdef DEBUG
const YGNodeRef node = _jlong2YGNodeRef(nativePointer);
YGNodePrint(
node,
(YGPrintOptions)(
YGPrintOptionsStyle | YGPrintOptionsLayout | YGPrintOptionsChildren));
#endif
}
void jni_YGNodeInsertChild(
jlong nativePointer,
jlong childPointer,
jint index) {
YGNodeInsertChild(
_jlong2YGNodeRef(nativePointer), _jlong2YGNodeRef(childPointer), index);
}
void jni_YGNodeRemoveChild(jlong nativePointer, jlong childPointer) {
YGNodeRemoveChild(
_jlong2YGNodeRef(nativePointer), _jlong2YGNodeRef(childPointer));
}
void jni_YGNodeSetIsReferenceBaseline(
jlong nativePointer,
jboolean isReferenceBaseline) {
YGNodeSetIsReferenceBaseline(
_jlong2YGNodeRef(nativePointer), isReferenceBaseline);
}
jboolean jni_YGNodeIsReferenceBaseline(jlong nativePointer) {
return YGNodeIsReferenceBaseline(_jlong2YGNodeRef(nativePointer));
}
void jni_YGNodeCalculateLayout(
alias_ref<jclass>,
jlong nativePointer,
jfloat width,
jfloat height,
alias_ref<JArrayLong> nativePointers,
alias_ref<JArrayClass<JYogaNode::javaobject>> javaNodes) {
void* layoutContext = nullptr;
auto map = PtrJNodeMap{};
if (nativePointers) {
map = PtrJNodeMap{nativePointers, javaNodes};
layoutContext = &map;
}
const YGNodeRef root = _jlong2YGNodeRef(nativePointer);
YGNodeCalculateLayoutWithContext(
root,
static_cast<float>(width),
static_cast<float>(height),
YGNodeStyleGetDirection(_jlong2YGNodeRef(nativePointer)),
layoutContext);
YGTransferLayoutOutputsRecursive(root, layoutContext);
}
void jni_YGNodeMarkDirty(jlong nativePointer) {
YGNodeMarkDirty(_jlong2YGNodeRef(nativePointer));
}
void jni_YGNodeMarkDirtyAndPropogateToDescendants(jlong nativePointer) {
YGNodeMarkDirtyAndPropogateToDescendants(_jlong2YGNodeRef(nativePointer));
}
jboolean jni_YGNodeIsDirty(jlong nativePointer) {
return (jboolean) _jlong2YGNodeRef(nativePointer)->isDirty();
}
void jni_YGNodeSetHasMeasureFunc(jlong nativePointer, jboolean hasMeasureFunc) {
_jlong2YGNodeRef(nativePointer)
->setMeasureFunc(hasMeasureFunc ? YGJNIMeasureFunc : nullptr);
}
void jni_YGNodeSetHasBaselineFunc(
jlong nativePointer,
jboolean hasBaselineFunc) {
_jlong2YGNodeRef(nativePointer)
->setBaselineFunc(hasBaselineFunc ? YGJNIBaselineFunc : nullptr);
}
void jni_YGNodeCopyStyle(jlong dstNativePointer, jlong srcNativePointer) {
YGNodeCopyStyle(
_jlong2YGNodeRef(dstNativePointer), _jlong2YGNodeRef(srcNativePointer));
}
#define YG_NODE_JNI_STYLE_PROP(javatype, type, name) \
javatype jni_YGNodeStyleGet##name(jlong nativePointer) { \
return (javatype) YGNodeStyleGet##name(_jlong2YGNodeRef(nativePointer)); \
} \
\
void jni_YGNodeStyleSet##name(jlong nativePointer, javatype value) { \
YGNodeStyleSet##name( \
_jlong2YGNodeRef(nativePointer), static_cast<type>(value)); \
}
#define YG_NODE_JNI_STYLE_UNIT_PROP(name) \
jlong jni_YGNodeStyleGet##name(jlong nativePointer) { \
return YogaValue::asJavaLong( \
YGNodeStyleGet##name(_jlong2YGNodeRef(nativePointer))); \
} \
\
void jni_YGNodeStyleSet##name(jlong nativePointer, jfloat value) { \
YGNodeStyleSet##name( \
_jlong2YGNodeRef(nativePointer), static_cast<float>(value)); \
} \
\
void jni_YGNodeStyleSet##name##Percent(jlong nativePointer, jfloat value) { \
YGNodeStyleSet##name##Percent( \
_jlong2YGNodeRef(nativePointer), static_cast<float>(value)); \
}
#define YG_NODE_JNI_STYLE_UNIT_PROP_AUTO(name) \
YG_NODE_JNI_STYLE_UNIT_PROP(name) \
void jni_YGNodeStyleSet##name##Auto(jlong nativePointer) { \
YGNodeStyleSet##name##Auto(_jlong2YGNodeRef(nativePointer)); \
}
#define YG_NODE_JNI_STYLE_EDGE_PROP(javatype, type, name) \
javatype jni_YGNodeStyleGet##name(jlong nativePointer, jint edge) { \
return (javatype) YGNodeStyleGet##name( \
_jlong2YGNodeRef(nativePointer), static_cast<YGEdge>(edge)); \
} \
\
void jni_YGNodeStyleSet##name( \
jlong nativePointer, jint edge, javatype value) { \
YGNodeStyleSet##name( \
_jlong2YGNodeRef(nativePointer), \
static_cast<YGEdge>(edge), \
static_cast<type>(value)); \
}
#define YG_NODE_JNI_STYLE_EDGE_UNIT_PROP(name) \
jlong jni_YGNodeStyleGet##name(jlong nativePointer, jint edge) { \
return YogaValue::asJavaLong(YGNodeStyleGet##name( \
_jlong2YGNodeRef(nativePointer), static_cast<YGEdge>(edge))); \
} \
\
void jni_YGNodeStyleSet##name( \
jlong nativePointer, jint edge, jfloat value) { \
YGNodeStyleSet##name( \
_jlong2YGNodeRef(nativePointer), \
static_cast<YGEdge>(edge), \
static_cast<float>(value)); \
} \
\
void jni_YGNodeStyleSet##name##Percent( \
jlong nativePointer, jint edge, jfloat value) { \
YGNodeStyleSet##name##Percent( \
_jlong2YGNodeRef(nativePointer), \
static_cast<YGEdge>(edge), \
static_cast<float>(value)); \
}
#define YG_NODE_JNI_STYLE_EDGE_UNIT_PROP_AUTO(name) \
YG_NODE_JNI_STYLE_EDGE_UNIT_PROP(name) \
void jni_YGNodeStyleSet##name##Auto(jlong nativePointer, jint edge) { \
YGNodeStyleSet##name##Auto( \
_jlong2YGNodeRef(nativePointer), static_cast<YGEdge>(edge)); \
}
YG_NODE_JNI_STYLE_PROP(jint, YGDirection, Direction);
YG_NODE_JNI_STYLE_PROP(jint, YGFlexDirection, FlexDirection);
YG_NODE_JNI_STYLE_PROP(jint, YGJustify, JustifyContent);
YG_NODE_JNI_STYLE_PROP(jint, YGAlign, AlignItems);
YG_NODE_JNI_STYLE_PROP(jint, YGAlign, AlignSelf);
YG_NODE_JNI_STYLE_PROP(jint, YGAlign, AlignContent);
YG_NODE_JNI_STYLE_PROP(jint, YGPositionType, PositionType);
YG_NODE_JNI_STYLE_PROP(jint, YGWrap, FlexWrap);
YG_NODE_JNI_STYLE_PROP(jint, YGOverflow, Overflow);
YG_NODE_JNI_STYLE_PROP(jint, YGDisplay, Display);
jfloat jni_YGNodeStyleGetFlex(jlong nativePointer) {
return YGNodeStyleGetFlex(_jlong2YGNodeRef(nativePointer));
}
void jni_YGNodeStyleSetFlex(jlong nativePointer, jfloat value) {
YGNodeStyleSetFlex(
_jlong2YGNodeRef(nativePointer), static_cast<float>(value));
}
YG_NODE_JNI_STYLE_PROP(jfloat, float, FlexGrow);
YG_NODE_JNI_STYLE_PROP(jfloat, float, FlexShrink);
YG_NODE_JNI_STYLE_UNIT_PROP_AUTO(FlexBasis);
YG_NODE_JNI_STYLE_EDGE_UNIT_PROP(Position);
YG_NODE_JNI_STYLE_UNIT_PROP_AUTO(Width);
YG_NODE_JNI_STYLE_UNIT_PROP(MinWidth);
YG_NODE_JNI_STYLE_UNIT_PROP(MaxWidth);
YG_NODE_JNI_STYLE_UNIT_PROP_AUTO(Height);
YG_NODE_JNI_STYLE_UNIT_PROP(MinHeight);
YG_NODE_JNI_STYLE_UNIT_PROP(MaxHeight);
// Yoga specific properties, not compatible with flexbox specification
YG_NODE_JNI_STYLE_PROP(jfloat, float, AspectRatio);
jlong jni_YGConfigNew(alias_ref<jclass>) {
return reinterpret_cast<jlong>(YGConfigNew());
}
void jni_YGConfigFree(alias_ref<jclass>, jlong nativePointer) {
const YGConfigRef config = _jlong2YGConfigRef(nativePointer);
// unique_ptr will destruct the underlying global_ref, if present.
auto context = std::unique_ptr<global_ref<JYogaLogger>>{
static_cast<global_ref<JYogaLogger>*>(YGConfigGetContext(config))};
YGConfigFree(config);
}
void jni_YGConfigSetExperimentalFeatureEnabled(
alias_ref<jclass>,
jlong nativePointer,
jint feature,
jboolean enabled) {
const YGConfigRef config = _jlong2YGConfigRef(nativePointer);
YGConfigSetExperimentalFeatureEnabled(
config, static_cast<YGExperimentalFeature>(feature), enabled);
}
void jni_YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour(
alias_ref<jclass>,
jlong nativePointer,
jboolean enabled) {
const YGConfigRef config = _jlong2YGConfigRef(nativePointer);
YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour(config, enabled);
}
void jni_YGConfigSetUseWebDefaults(
alias_ref<jclass>,
jlong nativePointer,
jboolean useWebDefaults) {
const YGConfigRef config = _jlong2YGConfigRef(nativePointer);
YGConfigSetUseWebDefaults(config, useWebDefaults);
}
void jni_YGConfigSetPrintTreeFlag(
alias_ref<jclass>,
jlong nativePointer,
jboolean enable) {
const YGConfigRef config = _jlong2YGConfigRef(nativePointer);
YGConfigSetPrintTreeFlag(config, enable);
}
void jni_YGConfigSetPointScaleFactor(
alias_ref<jclass>,
jlong nativePointer,
jfloat pixelsInPoint) {
const YGConfigRef config = _jlong2YGConfigRef(nativePointer);
YGConfigSetPointScaleFactor(config, pixelsInPoint);
}
void jni_YGConfigSetUseLegacyStretchBehaviour(
alias_ref<jclass>,
jlong nativePointer,
jboolean useLegacyStretchBehaviour) {
const YGConfigRef config = _jlong2YGConfigRef(nativePointer);
YGConfigSetUseLegacyStretchBehaviour(config, useLegacyStretchBehaviour);
}
void jni_YGConfigSetLogger(
alias_ref<jclass>,
jlong nativePointer,
alias_ref<jobject> logger) {
const YGConfigRef config = _jlong2YGConfigRef(nativePointer);
auto context =
reinterpret_cast<global_ref<JYogaLogger>*>(YGConfigGetContext(config));
if (logger) {
if (context == nullptr) {
context = new global_ref<JYogaLogger>{};
YGConfigSetContext(config, context);
}
*context = make_global(static_ref_cast<JYogaLogger::javaobject>(logger));
config->setLogger(YGJNILogFunc);
} else {
if (context != nullptr) {
delete context;
YGConfigSetContext(config, nullptr);
}
config->setLogger(nullptr);
}
}
jlong jni_YGNodeStyleGetMargin(jlong nativePointer, jint edge) {
YGNodeRef yogaNodeRef = _jlong2YGNodeRef(nativePointer);
if (!YGNodeEdges{yogaNodeRef}.has(YGNodeEdges::MARGIN)) {
return YogaValue::undefinedAsJavaLong();
}
return YogaValue::asJavaLong(
YGNodeStyleGetMargin(yogaNodeRef, static_cast<YGEdge>(edge)));
}
void jni_YGNodeStyleSetMargin(jlong nativePointer, jint edge, jfloat margin) {
YGNodeRef yogaNodeRef = _jlong2YGNodeRef(nativePointer);
YGNodeEdges{yogaNodeRef}.add(YGNodeEdges::MARGIN).setOn(yogaNodeRef);
YGNodeStyleSetMargin(
yogaNodeRef, static_cast<YGEdge>(edge), static_cast<float>(margin));
}
void jni_YGNodeStyleSetMarginPercent(
jlong nativePointer,
jint edge,
jfloat percent) {
YGNodeRef yogaNodeRef = _jlong2YGNodeRef(nativePointer);
YGNodeEdges{yogaNodeRef}.add(YGNodeEdges::MARGIN).setOn(yogaNodeRef);
YGNodeStyleSetMarginPercent(
yogaNodeRef, static_cast<YGEdge>(edge), static_cast<float>(percent));
}
void jni_YGNodeStyleSetMarginAuto(jlong nativePointer, jint edge) {
YGNodeRef yogaNodeRef = _jlong2YGNodeRef(nativePointer);
YGNodeEdges{yogaNodeRef}.add(YGNodeEdges::MARGIN).setOn(yogaNodeRef);
YGNodeStyleSetMarginAuto(yogaNodeRef, static_cast<YGEdge>(edge));
}
jlong jni_YGNodeStyleGetPadding(jlong nativePointer, jint edge) {
YGNodeRef yogaNodeRef = _jlong2YGNodeRef(nativePointer);
if (!YGNodeEdges{yogaNodeRef}.has(YGNodeEdges::PADDING)) {
return YogaValue::undefinedAsJavaLong();
}
return YogaValue::asJavaLong(
YGNodeStyleGetPadding(yogaNodeRef, static_cast<YGEdge>(edge)));
}
void jni_YGNodeStyleSetPadding(jlong nativePointer, jint edge, jfloat padding) {
YGNodeRef yogaNodeRef = _jlong2YGNodeRef(nativePointer);
YGNodeEdges{yogaNodeRef}.add(YGNodeEdges::PADDING).setOn(yogaNodeRef);
YGNodeStyleSetPadding(
yogaNodeRef, static_cast<YGEdge>(edge), static_cast<float>(padding));
}
void jni_YGNodeStyleSetPaddingPercent(
jlong nativePointer,
jint edge,
jfloat percent) {
YGNodeRef yogaNodeRef = _jlong2YGNodeRef(nativePointer);
YGNodeEdges{yogaNodeRef}.add(YGNodeEdges::PADDING).setOn(yogaNodeRef);
YGNodeStyleSetPaddingPercent(
yogaNodeRef, static_cast<YGEdge>(edge), static_cast<float>(percent));
}
jfloat jni_YGNodeStyleGetBorder(jlong nativePointer, jint edge) {
YGNodeRef yogaNodeRef = _jlong2YGNodeRef(nativePointer);
if (!YGNodeEdges{yogaNodeRef}.has(YGNodeEdges::BORDER)) {
return (jfloat) YGUndefined;
}
return (jfloat) YGNodeStyleGetBorder(yogaNodeRef, static_cast<YGEdge>(edge));
}
void jni_YGNodeStyleSetBorder(jlong nativePointer, jint edge, jfloat border) {
YGNodeRef yogaNodeRef = _jlong2YGNodeRef(nativePointer);
YGNodeEdges{yogaNodeRef}.add(YGNodeEdges::BORDER).setOn(yogaNodeRef);
YGNodeStyleSetBorder(
yogaNodeRef, static_cast<YGEdge>(edge), static_cast<float>(border));
}
#define YGMakeNativeMethod(name) makeNativeMethod(#name, name)
#define YGMakeCriticalNativeMethod(name) \
makeCriticalNativeMethod_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(#name, name)
jint YGJNI::registerNativeMethods(JavaVM* vm) {
jint ret = initialize(vm, [] {
registerNatives(
"com/facebook/yoga/YogaNative",
{
YGMakeNativeMethod(jni_YGNodeNew),
YGMakeNativeMethod(jni_YGNodeNewWithConfig),
YGMakeNativeMethod(jni_YGNodeFree),
YGMakeCriticalNativeMethod(jni_YGNodeReset),
YGMakeCriticalNativeMethod(jni_YGNodeClearChildren),
YGMakeCriticalNativeMethod(jni_YGNodeInsertChild),
YGMakeCriticalNativeMethod(jni_YGNodeRemoveChild),
YGMakeCriticalNativeMethod(jni_YGNodeSetIsReferenceBaseline),
YGMakeCriticalNativeMethod(jni_YGNodeIsReferenceBaseline),
YGMakeNativeMethod(jni_YGNodeCalculateLayout),
YGMakeCriticalNativeMethod(jni_YGNodeMarkDirty),
YGMakeCriticalNativeMethod(
jni_YGNodeMarkDirtyAndPropogateToDescendants),
YGMakeCriticalNativeMethod(jni_YGNodeIsDirty),
YGMakeCriticalNativeMethod(jni_YGNodeSetHasMeasureFunc),
YGMakeCriticalNativeMethod(jni_YGNodeSetHasBaselineFunc),
YGMakeCriticalNativeMethod(jni_YGNodeCopyStyle),
YGMakeCriticalNativeMethod(jni_YGNodeStyleGetDirection),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetDirection),
YGMakeCriticalNativeMethod(jni_YGNodeStyleGetFlexDirection),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetFlexDirection),
YGMakeCriticalNativeMethod(jni_YGNodeStyleGetJustifyContent),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetJustifyContent),
YGMakeCriticalNativeMethod(jni_YGNodeStyleGetAlignItems),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetAlignItems),
YGMakeCriticalNativeMethod(jni_YGNodeStyleGetAlignSelf),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetAlignSelf),
YGMakeCriticalNativeMethod(jni_YGNodeStyleGetAlignContent),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetAlignContent),
YGMakeCriticalNativeMethod(jni_YGNodeStyleGetPositionType),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetPositionType),
YGMakeCriticalNativeMethod(jni_YGNodeStyleGetFlexWrap),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetFlexWrap),
YGMakeCriticalNativeMethod(jni_YGNodeStyleGetOverflow),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetOverflow),
YGMakeCriticalNativeMethod(jni_YGNodeStyleGetDisplay),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetDisplay),
YGMakeCriticalNativeMethod(jni_YGNodeStyleGetFlex),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetFlex),
YGMakeCriticalNativeMethod(jni_YGNodeStyleGetFlexGrow),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetFlexGrow),
YGMakeCriticalNativeMethod(jni_YGNodeStyleGetFlexShrink),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetFlexShrink),
YGMakeCriticalNativeMethod(jni_YGNodeStyleGetFlexBasis),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetFlexBasis),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetFlexBasisPercent),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetFlexBasisAuto),
YGMakeCriticalNativeMethod(jni_YGNodeStyleGetMargin),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetMargin),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetMarginPercent),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetMarginAuto),
YGMakeCriticalNativeMethod(jni_YGNodeStyleGetPadding),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetPadding),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetPaddingPercent),
YGMakeCriticalNativeMethod(jni_YGNodeStyleGetBorder),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetBorder),
YGMakeCriticalNativeMethod(jni_YGNodeStyleGetPosition),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetPosition),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetPositionPercent),
YGMakeCriticalNativeMethod(jni_YGNodeStyleGetWidth),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetWidth),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetWidthPercent),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetWidthAuto),
YGMakeCriticalNativeMethod(jni_YGNodeStyleGetHeight),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetHeight),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetHeightPercent),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetHeightAuto),
YGMakeCriticalNativeMethod(jni_YGNodeStyleGetMinWidth),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetMinWidth),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetMinWidthPercent),
YGMakeCriticalNativeMethod(jni_YGNodeStyleGetMinHeight),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetMinHeight),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetMinHeightPercent),
YGMakeCriticalNativeMethod(jni_YGNodeStyleGetMaxWidth),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetMaxWidth),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetMaxWidthPercent),
YGMakeCriticalNativeMethod(jni_YGNodeStyleGetMaxHeight),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetMaxHeight),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetMaxHeightPercent),
YGMakeCriticalNativeMethod(jni_YGNodeStyleGetAspectRatio),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetAspectRatio),
YGMakeCriticalNativeMethod(jni_YGNodePrint),
YGMakeNativeMethod(jni_YGNodeClone),
YGMakeNativeMethod(jni_YGConfigNew),
YGMakeNativeMethod(jni_YGConfigFree),
YGMakeNativeMethod(jni_YGConfigSetExperimentalFeatureEnabled),
YGMakeNativeMethod(jni_YGConfigSetUseWebDefaults),
YGMakeNativeMethod(jni_YGConfigSetPrintTreeFlag),
YGMakeNativeMethod(jni_YGConfigSetPointScaleFactor),
YGMakeNativeMethod(jni_YGConfigSetUseLegacyStretchBehaviour),
YGMakeNativeMethod(jni_YGConfigSetLogger),
YGMakeNativeMethod(
jni_YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour),
});
});
return ret;
}

View File

@@ -15,6 +15,7 @@
#include <yoga/log.h>
#include <iostream>
#include <memory>
#include "YogaJniException.h"
using namespace facebook::yoga::vanillajni;
using facebook::yoga::detail::Log;
@@ -195,7 +196,7 @@ static void jni_YGConfigSetLoggerJNI(
delete context;
YGConfigSetContext(config, nullptr);
}
config->setLogger(nullptr);
YGConfigSetLogger(config, nullptr);
}
}
@@ -224,6 +225,16 @@ static void jni_YGNodeInsertChildJNI(
_jlong2YGNodeRef(nativePointer), _jlong2YGNodeRef(childPointer), index);
}
static void jni_YGNodeSwapChildJNI(
JNIEnv* env,
jobject obj,
jlong nativePointer,
jlong childPointer,
jint index) {
YGNodeSwapChild(
_jlong2YGNodeRef(nativePointer), _jlong2YGNodeRef(childPointer), index);
}
static void jni_YGNodeSetIsReferenceBaselineJNI(
JNIEnv* env,
jobject obj,
@@ -372,8 +383,18 @@ static void jni_YGNodeCalculateLayoutJNI(
YGNodeStyleGetDirection(_jlong2YGNodeRef(nativePointer)),
layoutContext);
YGTransferLayoutOutputsRecursive(env, obj, root, layoutContext);
} catch (jthrowable throwable) {
env->Throw(throwable);
} catch (const YogaJniException& jniException) {
ScopedLocalRef<jthrowable> throwable = jniException.getThrowable();
if (throwable.get()) {
env->Throw(throwable.get());
}
} catch (const std::logic_error& ex) {
env->ExceptionClear();
jclass cl = env->FindClass("Ljava/lang/IllegalStateException;");
static const jmethodID methodId = facebook::yoga::vanillajni::getMethodId(
env, cl, "<init>", "(Ljava/lang/String;)V");
auto throwable = env->NewObject(cl, methodId, env->NewStringUTF(ex.what()));
env->Throw(static_cast<jthrowable>(throwable));
}
}
@@ -705,8 +726,7 @@ static void jni_YGNodePrintJNI(JNIEnv* env, jobject obj, jlong nativePointer) {
const YGNodeRef node = _jlong2YGNodeRef(nativePointer);
YGNodePrint(
node,
(YGPrintOptions)(
YGPrintOptionsStyle | YGPrintOptionsLayout | YGPrintOptionsChildren));
(YGPrintOptions) (YGPrintOptionsStyle | YGPrintOptionsLayout | YGPrintOptionsChildren));
#endif
}
@@ -750,6 +770,7 @@ static JNINativeMethod methods[] = {
{"jni_YGNodeFreeJNI", "(J)V", (void*) jni_YGNodeFreeJNI},
{"jni_YGNodeResetJNI", "(J)V", (void*) jni_YGNodeResetJNI},
{"jni_YGNodeInsertChildJNI", "(JJI)V", (void*) jni_YGNodeInsertChildJNI},
{"jni_YGNodeSwapChildJNI", "(JJI)V", (void*) jni_YGNodeSwapChildJNI},
{"jni_YGNodeSetIsReferenceBaselineJNI",
"(JZ)V",
(void*) jni_YGNodeSetIsReferenceBaselineJNI},

View File

@@ -5,6 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/
#include "jni.h"
namespace YGJNIVanilla {
void registerNatives(JNIEnv* env);
};

View File

@@ -1,43 +0,0 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include "YGJTypes.h"
using facebook::jni::alias_ref;
using facebook::jni::local_ref;
jfloat JYogaNode::baseline(jfloat width, jfloat height) {
static auto javaMethod =
javaClassLocal()->getMethod<jfloat(jfloat, jfloat)>("baseline");
return javaMethod(self(), width, height);
}
jlong JYogaNode::measure(
jfloat width,
jint widthMode,
jfloat height,
jint heightMode) {
static auto javaMethod =
javaClassLocal()->getMethod<jlong(jfloat, jint, jfloat, jint)>("measure");
return javaMethod(self(), width, widthMode, height, heightMode);
}
facebook::jni::local_ref<JYogaLogLevel> JYogaLogLevel::fromInt(jint logLevel) {
static auto javaMethod =
javaClassStatic()->getStaticMethod<alias_ref<JYogaLogLevel>(jint)>(
"fromInt");
return javaMethod(javaClassStatic(), logLevel);
}
void JYogaLogger::log(
facebook::jni::alias_ref<JYogaLogLevel> logLevel,
jstring message) {
static auto javaMethod =
javaClassLocal()->getMethod<void(alias_ref<JYogaLogLevel>, jstring)>(
"log");
javaMethod(self(), logLevel, message);
}

View File

@@ -1,61 +0,0 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include <fbjni/fbjni.h>
#include <yoga/YGValue.h>
#include <yoga/Yoga.h>
#include <map>
using namespace facebook::jni;
using namespace std;
struct JYogaNode : public facebook::jni::JavaClass<JYogaNode> {
static constexpr auto kJavaDescriptor = "Lcom/facebook/yoga/YogaNodeJNIBase;";
jfloat baseline(jfloat width, jfloat height);
jlong measure(jfloat width, jint widthMode, jfloat height, jint heightMode);
};
struct JYogaLogLevel : public facebook::jni::JavaClass<JYogaLogLevel> {
static constexpr auto kJavaDescriptor = "Lcom/facebook/yoga/YogaLogLevel;";
static facebook::jni::local_ref<JYogaLogLevel> fromInt(jint);
};
struct JYogaLogger : public facebook::jni::JavaClass<JYogaLogger> {
static constexpr auto kJavaDescriptor = "Lcom/facebook/yoga/YogaLogger;";
void log(facebook::jni::alias_ref<JYogaLogLevel>, jstring);
};
class PtrJNodeMap {
using JNodeArray = JArrayClass<JYogaNode::javaobject>;
std::map<YGNodeRef, size_t> ptrsToIdxs_;
alias_ref<JNodeArray> javaNodes_;
public:
PtrJNodeMap() : ptrsToIdxs_{}, javaNodes_{} {}
PtrJNodeMap(
alias_ref<JArrayLong> nativePointers,
alias_ref<JNodeArray> javaNodes)
: javaNodes_{javaNodes} {
auto pin = nativePointers->pinCritical();
auto ptrs = pin.get();
for (size_t i = 0, n = pin.size(); i < n; ++i) {
ptrsToIdxs_[(YGNodeRef) ptrs[i]] = i;
}
}
local_ref<JYogaNode> ref(YGNodeRef node) {
auto idx = ptrsToIdxs_.find(node);
if (idx == ptrsToIdxs_.end()) {
return local_ref<JYogaNode>{};
} else {
return javaNodes_->getElement(idx->second);
}
}
};

View File

@@ -0,0 +1,52 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include <stdexcept>
#include <string>
#include "YogaJniException.h"
#include "common.h"
namespace facebook {
namespace yoga {
namespace vanillajni {
YogaJniException::YogaJniException() {
jclass cl = getCurrentEnv()->FindClass("Ljava/lang/RuntimeException;");
static const jmethodID methodId = facebook::yoga::vanillajni::getMethodId(
getCurrentEnv(), cl, "<init>", "()V");
auto throwable = getCurrentEnv()->NewObject(cl, methodId);
throwable_ =
newGlobalRef(getCurrentEnv(), static_cast<jthrowable>(throwable));
}
YogaJniException::YogaJniException(jthrowable throwable) {
throwable_ = newGlobalRef(getCurrentEnv(), throwable);
}
YogaJniException::YogaJniException(YogaJniException&& rhs)
: throwable_(std::move(rhs.throwable_)) {}
YogaJniException::YogaJniException(const YogaJniException& rhs) {
throwable_ = newGlobalRef(getCurrentEnv(), rhs.throwable_.get());
}
YogaJniException::~YogaJniException() {
try {
throwable_.reset();
} catch (...) {
std::terminate();
}
}
ScopedLocalRef<jthrowable> YogaJniException::getThrowable() const noexcept {
return make_local_ref(
getCurrentEnv(),
static_cast<jthrowable>(getCurrentEnv()->NewLocalRef(throwable_.get())));
}
} // namespace vanillajni
} // namespace yoga
} // namespace facebook

View File

@@ -0,0 +1,38 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include <stdexcept>
#include <string>
#include "common.h"
namespace facebook {
namespace yoga {
namespace vanillajni {
/**
* This class wraps a Java exception (jthrowable) into a C++ exception; A global
* reference to Java exception (jthrowable) is made so that the exception object
* does not gets cleared before jni call completion
*/
class YogaJniException : public std::exception {
public:
YogaJniException();
~YogaJniException() override;
explicit YogaJniException(jthrowable throwable);
YogaJniException(YogaJniException&& rhs);
YogaJniException(const YogaJniException& other);
ScopedLocalRef<jthrowable> getThrowable() const noexcept;
private:
ScopedGlobalRef<jthrowable> throwable_;
};
} // namespace vanillajni
} // namespace yoga
} // namespace facebook

View File

@@ -18,11 +18,11 @@ void registerNatives(
size_t numMethods) {
jclass clazz = env->FindClass(className);
assertNoPendingJniException(env);
assertNoPendingJniExceptionIf(env, !clazz);
env->RegisterNatives(clazz, methods, numMethods);
auto result = env->RegisterNatives(clazz, methods, numMethods);
assertNoPendingJniException(env);
assertNoPendingJniExceptionIf(env, result != JNI_OK);
}
jmethodID getStaticMethodId(
@@ -32,7 +32,7 @@ jmethodID getStaticMethodId(
const char* methodDescriptor) {
jmethodID methodId =
env->GetStaticMethodID(clazz, methodName, methodDescriptor);
assertNoPendingJniException(env);
assertNoPendingJniExceptionIf(env, !methodId);
return methodId;
}
@@ -42,7 +42,7 @@ jmethodID getMethodId(
const char* methodName,
const char* methodDescriptor) {
jmethodID methodId = env->GetMethodID(clazz, methodName, methodDescriptor);
assertNoPendingJniException(env);
assertNoPendingJniExceptionIf(env, !methodId);
return methodId;
}
@@ -52,7 +52,7 @@ jfieldID getFieldId(
const char* fieldName,
const char* fieldSignature) {
jfieldID fieldId = env->GetFieldID(clazz, fieldName, fieldSignature);
assertNoPendingJniException(env);
assertNoPendingJniExceptionIf(env, !fieldId);
return fieldId;
}
@@ -77,13 +77,16 @@ DEFINE_CALL_METHOD_FOR_PRIMITIVE_INTERFACE(void, Void) {
assertNoPendingJniException(env);
}
ScopedLocalRef<jobject>
callStaticObjectMethod(JNIEnv* env, jclass clazz, jmethodID methodId, ...) {
ScopedLocalRef<jobject> callStaticObjectMethod(
JNIEnv* env,
jclass clazz,
jmethodID methodId,
...) {
va_list args;
va_start(args, methodId);
jobject result = env->CallStaticObjectMethodV(clazz, methodId, args);
va_end(args);
assertNoPendingJniException(env);
assertNoPendingJniExceptionIf(env, !result);
return make_local_ref(env, result);
}
@@ -96,6 +99,16 @@ ScopedGlobalRef<jobject> newGlobalRef(JNIEnv* env, jobject obj) {
return make_global_ref(result);
}
ScopedGlobalRef<jthrowable> newGlobalRef(JNIEnv* env, jthrowable obj) {
jthrowable result = static_cast<jthrowable>(env->NewGlobalRef(obj));
if (!result) {
logErrorMessageAndDie("Could not obtain global reference from object");
}
return make_global_ref(result);
}
} // namespace vanillajni
} // namespace yoga
} // namespace facebook

View File

@@ -61,14 +61,19 @@ DEFINE_CALL_METHOD_FOR_PRIMITIVE_INTERFACE(void, Void);
DEFINE_CALL_METHOD_FOR_PRIMITIVE_INTERFACE(jlong, Long);
DEFINE_CALL_METHOD_FOR_PRIMITIVE_INTERFACE(jfloat, Float);
ScopedLocalRef<jobject>
callStaticObjectMethod(JNIEnv* env, jclass clazz, jmethodID methodId, ...);
ScopedLocalRef<jobject> callStaticObjectMethod(
JNIEnv* env,
jclass clazz,
jmethodID methodId,
...);
/**
* Given a local or a global reference, this method creates a new global
* reference out of it. If any error happens, aborts the process.
*/
ScopedGlobalRef<jobject> newGlobalRef(JNIEnv* env, jobject obj);
ScopedGlobalRef<jthrowable> newGlobalRef(JNIEnv* env, jthrowable obj);
} // namespace vanillajni
} // namespace yoga
} // namespace facebook

View File

@@ -7,6 +7,7 @@
#include "corefunctions.h"
#include "macros.h"
#include "YogaJniException.h"
namespace facebook {
namespace yoga {
@@ -72,7 +73,20 @@ void assertNoPendingJniException(JNIEnv* env) {
logErrorMessageAndDie("Unable to get pending JNI exception.");
}
env->ExceptionClear();
throw throwable;
throw YogaJniException(throwable);
}
void assertNoPendingJniExceptionIf(JNIEnv* env, bool condition) {
if (!condition) {
return;
}
if (env->ExceptionCheck() == JNI_TRUE) {
assertNoPendingJniException(env);
return;
}
throw YogaJniException();
}
} // namespace vanillajni

View File

@@ -47,6 +47,8 @@ void logErrorMessageAndDie(const char* message);
*/
void assertNoPendingJniException(JNIEnv* env);
void assertNoPendingJniExceptionIf(JNIEnv* env, bool condition);
} // namespace vanillajni
} // namespace yoga
} // namespace facebook

View File

@@ -4,20 +4,14 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include "yogajni.h"
#include "YGJNIVanilla.h"
#include <fbjni/fbjni.h>
#include "common.h"
using namespace facebook::jni;
using namespace facebook::yoga;
jint JNI_OnLoad(JavaVM* vm, void*) {
jint ret = YGJNI::registerNativeMethods(vm);
JNIEnv* env;
vanillajni::ensureInitialized(&env, vm);
jint ret = vanillajni::ensureInitialized(&env, vm);
YGJNIVanilla::registerNatives(env);
return ret;
}

View File

@@ -1,12 +0,0 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include <fbjni/fbjni.h>
namespace YGJNI {
jint registerNativeMethods(JavaVM* vm);
};

View File

@@ -10,4 +10,4 @@ apply plugin: 'java'
sourceCompatibility = '1.7'
targetCompatibility = '1.7'
apply from: rootProject.file('gradle/release.gradle')
apply plugin: 'com.vanniktech.maven.publish'

View File

@@ -0,0 +1,24 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
package com.facebook.proguard.annotations;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import static java.lang.annotation.RetentionPolicy.CLASS;
/**
* Add this annotation to a class to instruct Proguard to not strip it or any of its fields or
* methods out.
*
* <p>This is useful for methods called via reflection that could appear as unused to Proguard.
*/
@Target({ElementType.TYPE})
@Retention(CLASS)
public @interface DoNotStripAny {}

View File

@@ -28,25 +28,7 @@ public class TestParametrization {
return "JNI";
}
};
NodeFactory nodeFactoryUsingVanillaJNI = new NodeFactory() {
@Override
public YogaNode create() {
return YogaNodeFactory.create(true);
}
@Override
public YogaNode create(YogaConfig config) {
config.setUseVanillaJNI(true);
return YogaNodeFactory.create(config);
}
@Override
public String toString() {
return "VanillaJNI";
}
};
return Arrays.asList(nodeFactory, nodeFactoryUsingVanillaJNI);
return Arrays.asList(nodeFactory);
}

View File

@@ -1,9 +1,10 @@
/**
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
// @Generated by gentest/gentest.rb from gentest/fixtures/YGDisplayTest.html
package com.facebook.yoga;
@@ -337,6 +338,47 @@ public class YGDisplayTest {
assertEquals(0f, root_child1.getLayoutHeight(), 0.0f);
}
@Test
public void test_display_none_with_position_absolute() {
YogaConfig config = YogaConfigFactory.create();
final YogaNode root = createNode(config);
root.setWidth(100f);
root.setHeight(100f);
final YogaNode root_child0 = createNode(config);
root_child0.setPositionType(YogaPositionType.ABSOLUTE);
root_child0.setWidth(100f);
root_child0.setHeight(100f);
root_child0.setDisplay(YogaDisplay.NONE);
root.addChildAt(root_child0, 0);
root.setDirection(YogaDirection.LTR);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(100f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(0f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(0f, root_child0.getLayoutHeight(), 0.0f);
root.setDirection(YogaDirection.RTL);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(100f, root.getLayoutWidth(), 0.0f);
assertEquals(100f, root.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(0f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(0f, root_child0.getLayoutHeight(), 0.0f);
}
private YogaNode createNode(YogaConfig config) {
return mNodeFactory.create(config);
}

View File

@@ -9,10 +9,62 @@ package com.facebook.yoga;
import org.junit.Test;
import java.lang.ref.WeakReference;
import java.util.List;
import java.util.ArrayList;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
public class YogaLoggerTest {
@Test
public void testRemovingLoggerFromConfig() throws Exception {
final List<String> logs = new ArrayList<>();
final YogaConfig config = YogaConfigFactory.create();
YogaLogger logger = new YogaLogger() {
@Override
public void log(YogaLogLevel level, String message) {
logs.add(message);
}
};
config.setLogger(logger);
final YogaNode root = YogaNodeFactory.create(config);
root.setFlexDirection(YogaFlexDirection.ROW);
root.setAlignItems(YogaAlign.BASELINE);
final YogaNode child1 = YogaNodeFactory.create(config);
root.addChildAt(child1, 0);
final YogaNode child2 = YogaNodeFactory.create(config);
child2.setBaselineFunction(new YogaBaselineFunction() {
public float baseline(YogaNode node, float width, float height) {
return Float.NaN;
}
});
root.addChildAt(child2, 1);
assertEquals(logs.size(), 0);
try {
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
fail("Expected calculateLayout to throw");
} catch (IllegalStateException e) {
}
assertEquals(logs.size(), 1);
config.setLogger(null);
try {
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
fail("Expected calculateLayout to throw again");
} catch (IllegalStateException e) {
}
assertEquals(logs.size(), 1);
}
@Test
public void testLoggerLeak() throws Exception {
final YogaConfig config = YogaConfigFactory.create();

View File

@@ -191,7 +191,7 @@ public class YogaNodeStylePropertiesTest {
public void testPositionTypeDefault() {
final YogaNode node = createNode();
assertEquals(YogaPositionType.RELATIVE, node.getPositionType());
assertEquals(YogaPositionType.STATIC, node.getPositionType());
}
@Test

6
java/yogajni.version Normal file
View File

@@ -0,0 +1,6 @@
{
global:
JNI_OnLoad;
local:
*;
};

View File

@@ -7,5 +7,9 @@
[lints]
[options]
types_first=false
[strict]
[version]
^0.140.0

View File

@@ -23,8 +23,8 @@ static YGSize globalMeasureFunc(
Node const& node = *reinterpret_cast<Node const*>(YGNodeGetContext(nodeRef));
Size size = node.callMeasureFunc(width, widthMode, height, heightMode);
YGSize ygSize = {static_cast<float>(size.width),
static_cast<float>(size.height)};
YGSize ygSize = {
static_cast<float>(size.width), static_cast<float>(size.height)};
return ygSize;
}

View File

@@ -18,7 +18,5 @@ struct Size {
Size(double width, double height) : width(width), height(height) {}
void toJS(nbind::cbOutput expose) const {
expose(width, height);
}
void toJS(nbind::cbOutput expose) const { expose(width, height); }
};

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