From 2a3f4a3817b4b1c680d7571820104f71dc3e984a Mon Sep 17 00:00:00 2001 From: Songwen Ding Date: Thu, 30 Jan 2020 13:52:52 +0800 Subject: [PATCH 01/34] feature: support swift package manager --- .gitignore | 3 +++ Package.swift | 38 ++++++++++++++++++++++++++++++++++++ yoga/event/event.h | 2 +- yoga/include/public-header.h | 15 ++++++++++++++ 4 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 Package.swift create mode 100644 yoga/include/public-header.h diff --git a/.gitignore b/.gitignore index c4a6bf0f..bf158efc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .DS_STORE + /buck-cache/ /buck-out/ /.buckconfig.local @@ -7,6 +8,8 @@ /gentest/test.html .buckversion +.build/ + # Jekyll /.sass-cache/ /_site/ diff --git a/Package.swift b/Package.swift new file mode 100644 index 00000000..3aaa86be --- /dev/null +++ b/Package.swift @@ -0,0 +1,38 @@ +// swift-tools-version:5.0 + +import PackageDescription + +let package = Package( + name: "YogaKit", + platforms: [ + .macOS(.v10_10), + .iOS(.v8), + .tvOS(.v9), + .watchOS(.v2) + ], + products: [ + .library( + name: "YogaKit", + type: .static, + targets: ["YogaKit"] + ) + ], + dependencies: [], + targets: [ + .target( + name: "YogaKit", + path: "yoga", + exclude: [], + sources: ["./"], + publicHeadersPath: "include", + cSettings: [ + .headerSearchPath("./") + ] + ) + ], + swiftLanguageVersions: [ + .version("5") + ], + cLanguageStandard: .gnu11, + cxxLanguageStandard: .gnucxx14 +) diff --git a/yoga/event/event.h b/yoga/event/event.h index 309dacb5..0ec2ce96 100644 --- a/yoga/event/event.h +++ b/yoga/event/event.h @@ -10,7 +10,7 @@ #include #include #include -#include +#include "../YGEnums.h" struct YGConfig; struct YGNode; diff --git a/yoga/include/public-header.h b/yoga/include/public-header.h new file mode 100644 index 00000000..f76b0ce2 --- /dev/null +++ b/yoga/include/public-header.h @@ -0,0 +1,15 @@ +/* + * 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. + */ + +#pragma once + +@import Foundation; + +#include "../Yoga.h" +#include "../YGMacros.h" +#include "../YGValue.h" +#include "../YGEnums.h" -- 2.50.1.windows.1 From e983c4a5ef32edfcda36b8197701196a56e610d5 Mon Sep 17 00:00:00 2001 From: Pasquale Anatriello Date: Thu, 30 Jan 2020 03:41:45 -0800 Subject: [PATCH 02/34] Swap child Yoga Summary: Changelog: [Internal] Expose the replaceChild Yoga call to Java Reviewed By: SidharthGuglani Differential Revision: D19497193 fbshipit-source-id: 153243cc1d8c23dcaf2c772ca794bd59a230f652 --- java/com/facebook/yoga/YogaNative.java | 1 + java/com/facebook/yoga/YogaNode.java | 2 + java/com/facebook/yoga/YogaNodeJNIBase.java | 87 +++++++++++++++------ java/jni/YGJNIVanilla.cpp | 11 +++ yoga/Yoga.cpp | 8 ++ yoga/Yoga.h | 5 ++ 6 files changed, 92 insertions(+), 22 deletions(-) diff --git a/java/com/facebook/yoga/YogaNative.java b/java/com/facebook/yoga/YogaNative.java index 334eaab5..3674b42f 100644 --- a/java/com/facebook/yoga/YogaNative.java +++ b/java/com/facebook/yoga/YogaNative.java @@ -34,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); diff --git a/java/com/facebook/yoga/YogaNode.java b/java/com/facebook/yoga/YogaNode.java index baa0c517..9fc8bac9 100644 --- a/java/com/facebook/yoga/YogaNode.java +++ b/java/com/facebook/yoga/YogaNode.java @@ -214,4 +214,6 @@ public abstract class YogaNode { public abstract void print(); public abstract YogaNode cloneWithoutChildren(); + + public abstract YogaNode cloneWithChildren(); } diff --git a/java/com/facebook/yoga/YogaNodeJNIBase.java b/java/com/facebook/yoga/YogaNodeJNIBase.java index 6372ddd7..e20a5389 100644 --- a/java/com/facebook/yoga/YogaNodeJNIBase.java +++ b/java/com/facebook/yoga/YogaNodeJNIBase.java @@ -39,11 +39,9 @@ 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; @@ -59,7 +57,7 @@ public abstract class YogaNodeJNIBase extends YogaNode implements Cloneable { } YogaNodeJNIBase(YogaConfig config) { - this(YogaNative.jni_YGNodeNewWithConfigJNI(((YogaConfigJNIBase)config).mNativePointer)); + this(YogaNative.jni_YGNodeNewWithConfigJNI(((YogaConfigJNIBase) config).mNativePointer)); } public void reset() { @@ -106,6 +104,32 @@ public abstract class YogaNodeJNIBase extends YogaNode implements Cloneable { return YogaNative.jni_YGNodeIsReferenceBaselineJNI(mNativePointer); } + public void swapChildAt(YogaNode newChild, int position) { + 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(); + 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 { @@ -138,10 +162,9 @@ public abstract class YogaNodeJNIBase extends YogaNode implements Cloneable { } /** - * 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}. */ @@ -168,7 +191,7 @@ public abstract class YogaNodeJNIBase extends YogaNode implements Cloneable { ArrayList n = new ArrayList<>(); n.add(this); for (int i = 0; i < n.size(); ++i) { - List children = n.get(i).mChildren; + List children = n.get(i).mChildren; if (children != null) { n.addAll(children); } @@ -509,8 +532,8 @@ 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() { YogaNative.jni_YGNodePrintJNI(mNativePointer); @@ -559,7 +582,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 @@ -575,9 +600,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"); } @@ -589,7 +618,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]; @@ -600,9 +631,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"); } @@ -614,7 +649,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]; @@ -625,9 +663,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"); } @@ -638,7 +680,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 diff --git a/java/jni/YGJNIVanilla.cpp b/java/jni/YGJNIVanilla.cpp index b9b590ac..6e66c06e 100644 --- a/java/jni/YGJNIVanilla.cpp +++ b/java/jni/YGJNIVanilla.cpp @@ -225,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, @@ -754,6 +764,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}, diff --git a/yoga/Yoga.cpp b/yoga/Yoga.cpp index 41de5119..e30a36b7 100644 --- a/yoga/Yoga.cpp +++ b/yoga/Yoga.cpp @@ -386,6 +386,14 @@ YOGA_EXPORT void YGNodeInsertChild( owner->markDirtyAndPropogate(); } +YOGA_EXPORT void YGNodeSwapChild( + const YGNodeRef owner, + const YGNodeRef child, + const uint32_t index) { + owner->replaceChild(child, index); + child->setOwner(owner); +} + YOGA_EXPORT void YGNodeRemoveChild( const YGNodeRef owner, const YGNodeRef excludedChild) { diff --git a/yoga/Yoga.h b/yoga/Yoga.h index 68ed0a62..2fe60a41 100644 --- a/yoga/Yoga.h +++ b/yoga/Yoga.h @@ -69,6 +69,11 @@ WIN_EXPORT void YGNodeInsertChild( YGNodeRef child, uint32_t index); +WIN_EXPORT void YGNodeSwapChild( + YGNodeRef node, + YGNodeRef child, + uint32_t index); + WIN_EXPORT void YGNodeRemoveChild(YGNodeRef node, YGNodeRef child); WIN_EXPORT void YGNodeRemoveAllChildren(YGNodeRef node); WIN_EXPORT YGNodeRef YGNodeGetChild(YGNodeRef node, uint32_t index); -- 2.50.1.windows.1 From a1278cee05f5c533afe81e7c28e1bed916887d30 Mon Sep 17 00:00:00 2001 From: Christoph Purrer Date: Wed, 5 Feb 2020 13:35:21 -0800 Subject: [PATCH 03/34] 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 --- yoga/YGValue.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/yoga/YGValue.h b/yoga/YGValue.h index aaa10c3f..a2000978 100644 --- a/yoga/YGValue.h +++ b/yoga/YGValue.h @@ -11,6 +11,13 @@ #include "YGEnums.h" #include "YGMacros.h" +#if defined(_MSC_VER) && defined(__clang__) +#define COMPILING_WITH_CLANG_ON_WINDOWS +#endif +#if defined(COMPILING_WITH_CLANG_ON_WINDOWS) +#include +constexpr float YGUndefined = std::numeric_limits::quiet_NaN(); +#else YG_EXTERN_C_BEGIN // Not defined in MSVC++ @@ -20,6 +27,7 @@ static const uint32_t __nan = 0x7fc00000; #endif #define YGUndefined NAN +#endif typedef struct YGValue { float value; @@ -30,7 +38,10 @@ YOGA_EXPORT extern const YGValue YGValueAuto; YOGA_EXPORT extern const YGValue YGValueUndefined; YOGA_EXPORT extern const YGValue YGValueZero; +#if !defined(COMPILING_WITH_CLANG_ON_WINDOWS) YG_EXTERN_C_END +#endif +#undef COMPILING_WITH_CLANG_ON_WINDOWS #ifdef __cplusplus -- 2.50.1.windows.1 From bfc3b2f86f86f0b4cd1616a3450e249a8e6c9313 Mon Sep 17 00:00:00 2001 From: Sidharth Guglani Date: Tue, 18 Feb 2020 08:09:53 -0800 Subject: [PATCH 04/34] 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 --- YogaKit/Source/UIView+Yoga.h | 15 +- YogaKit/Source/UIView+Yoga.m | 18 +- YogaKit/Source/YGLayout+Private.h | 6 +- YogaKit/Source/YGLayout.h | 154 +++--- YogaKit/Source/YGLayout.m | 448 +++++++++--------- YogaKit/Tests/YogaKitTests.m | 351 +++++++------- .../YogaKitSample/ViewController.m | 64 ++- csharp/Yoga/YGInterop.cpp | 11 +- csharp/Yoga/YGInterop.h | 9 +- csharp/Yoga/dllmain.cpp | 3 +- csharp/Yoga/targetver.h | 5 +- java/jni/ScopedGlobalRef.h | 8 +- java/jni/ScopedLocalRef.h | 8 +- java/jni/common.cpp | 7 +- java/jni/common.h | 7 +- javascript/sources/Size.hh | 4 +- javascript/sources/Value.hh | 4 +- 17 files changed, 568 insertions(+), 554 deletions(-) diff --git a/YogaKit/Source/UIView+Yoga.h b/YogaKit/Source/UIView+Yoga.h index cac23385..4c85dcc4 100644 --- a/YogaKit/Source/UIView+Yoga.h +++ b/YogaKit/Source/UIView+Yoga.h @@ -5,28 +5,29 @@ * LICENSE file in the root directory of this source tree. */ -#import "YGLayout.h" #import +#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:)); diff --git a/YogaKit/Source/UIView+Yoga.m b/YogaKit/Source/UIView+Yoga.m index ba133919..e472c9c7 100644 --- a/YogaKit/Source/UIView+Yoga.m +++ b/YogaKit/Source/UIView+Yoga.m @@ -5,32 +5,30 @@ * LICENSE file in the root directory of this source tree. */ +#import #import "UIView+Yoga.h" #import "YGLayout+Private.h" -#import -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); } diff --git a/YogaKit/Source/YGLayout+Private.h b/YogaKit/Source/YGLayout+Private.h index 00ab40f5..0588d950 100644 --- a/YogaKit/Source/YGLayout+Private.h +++ b/YogaKit/Source/YGLayout+Private.h @@ -5,13 +5,13 @@ * LICENSE file in the root directory of this source tree. */ -#import "YGLayout.h" #import +#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 diff --git a/YogaKit/Source/YGLayout.h b/YogaKit/Source/YGLayout.h index 19f3982b..5a60f95e 100644 --- a/YogaKit/Source/YGLayout.h +++ b/YogaKit/Source/YGLayout.h @@ -7,15 +7,15 @@ #import #import -#import #import +#import 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. diff --git a/YogaKit/Source/YGLayout.m b/YogaKit/Source/YGLayout.m index 692020ca..4a95a5ca 100644 --- a/YogaKit/Source/YGLayout.m +++ b/YogaKit/Source/YGLayout.m @@ -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 *subviews) -{ +static BOOL YGNodeHasExactSameChildren( + const YGNodeRef node, + NSArray* subviews) { if (YGNodeGetChildCount(node) != subviews.count) { return NO; } - for (int i=0; i * 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 *subviewsToInclude = [[NSMutableArray alloc] initWithCapacity:view.subviews.count]; - for (UIView *subview in view.subviews) { + NSMutableArray* 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 diff --git a/java/jni/ScopedGlobalRef.h b/java/jni/ScopedGlobalRef.h index b1c18e68..fa98214a 100644 --- a/java/jni/ScopedGlobalRef.h +++ b/java/jni/ScopedGlobalRef.h @@ -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; diff --git a/java/jni/ScopedLocalRef.h b/java/jni/ScopedLocalRef.h index 0c5e9440..2368ced2 100644 --- a/java/jni/ScopedLocalRef.h +++ b/java/jni/ScopedLocalRef.h @@ -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; diff --git a/java/jni/common.cpp b/java/jni/common.cpp index 143c695f..37b56770 100644 --- a/java/jni/common.cpp +++ b/java/jni/common.cpp @@ -77,8 +77,11 @@ DEFINE_CALL_METHOD_FOR_PRIMITIVE_INTERFACE(void, Void) { assertNoPendingJniException(env); } -ScopedLocalRef -callStaticObjectMethod(JNIEnv* env, jclass clazz, jmethodID methodId, ...) { +ScopedLocalRef callStaticObjectMethod( + JNIEnv* env, + jclass clazz, + jmethodID methodId, + ...) { va_list args; va_start(args, methodId); jobject result = env->CallStaticObjectMethodV(clazz, methodId, args); diff --git a/java/jni/common.h b/java/jni/common.h index 19eca6a4..fda1e06d 100644 --- a/java/jni/common.h +++ b/java/jni/common.h @@ -61,8 +61,11 @@ 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 -callStaticObjectMethod(JNIEnv* env, jclass clazz, jmethodID methodId, ...); +ScopedLocalRef callStaticObjectMethod( + JNIEnv* env, + jclass clazz, + jmethodID methodId, + ...); /** * Given a local or a global reference, this method creates a new global diff --git a/javascript/sources/Size.hh b/javascript/sources/Size.hh index d7ea6da9..9f550a96 100644 --- a/javascript/sources/Size.hh +++ b/javascript/sources/Size.hh @@ -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); } }; diff --git a/javascript/sources/Value.hh b/javascript/sources/Value.hh index e7a9cf66..2581ae4a 100644 --- a/javascript/sources/Value.hh +++ b/javascript/sources/Value.hh @@ -21,7 +21,5 @@ struct Value { Value(int unit, double value) : unit(unit), value(value) {} - void toJS(nbind::cbOutput expose) const { - expose(unit, value); - } + void toJS(nbind::cbOutput expose) const { expose(unit, value); } }; -- 2.50.1.windows.1 From 6c61cd5f05abe51d33c67db13df74206a908e1d6 Mon Sep 17 00:00:00 2001 From: Sidharth Guglani Date: Wed, 19 Feb 2020 11:10:06 -0800 Subject: [PATCH 05/34] 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 --- website/src/components/Playground/src/Editor.css | 3 ++- website/src/components/Playground/src/Editor.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/website/src/components/Playground/src/Editor.css b/website/src/components/Playground/src/Editor.css index f53451f7..78974f63 100644 --- a/website/src/components/Playground/src/Editor.css +++ b/website/src/components/Playground/src/Editor.css @@ -51,7 +51,8 @@ } .Editor .ant-tabs-tabpane { - overflow-y: scroll; + overflow-y: auto; + height: 45vh; padding: 15px; } diff --git a/website/src/components/Playground/src/Editor.js b/website/src/components/Playground/src/Editor.js index f7076865..4b6b6593 100644 --- a/website/src/components/Playground/src/Editor.js +++ b/website/src/components/Playground/src/Editor.js @@ -196,7 +196,7 @@ export default class Editor extends Component { onChange={this.props.onChangeLayout} /> - +

Width × Height -- 2.50.1.windows.1 From 2d52b5a8733bccba663b15817685b13d8b5eb9da Mon Sep 17 00:00:00 2001 From: Sidharth Guglani Date: Tue, 25 Feb 2020 07:27:56 -0800 Subject: [PATCH 06/34] 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 --- website/src/components/Playground/src/Editor.css | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/website/src/components/Playground/src/Editor.css b/website/src/components/Playground/src/Editor.css index 78974f63..57954947 100644 --- a/website/src/components/Playground/src/Editor.css +++ b/website/src/components/Playground/src/Editor.css @@ -52,7 +52,9 @@ .Editor .ant-tabs-tabpane { overflow-y: auto; - height: 45vh; + min-height: 320px; + height: 100%; + max-height: 25vh; padding: 15px; } -- 2.50.1.windows.1 From adb87e347f7488405be77d5fb964290c55a11c7f Mon Sep 17 00:00:00 2001 From: Jesse Katsumata Date: Mon, 9 Mar 2020 15:34:16 -0700 Subject: [PATCH 07/34] 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 --- yoga/YGNode.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yoga/YGNode.h b/yoga/YGNode.h index 95962e68..9aef1ec6 100644 --- a/yoga/YGNode.h +++ b/yoga/YGNode.h @@ -73,7 +73,7 @@ private: } // DANGER DANGER DANGER! - // If the the node assigned to has children, we'd either have to deallocate + // If the node assigned to has children, we'd either have to deallocate // them (potentially incorrect) or ignore them (danger of leaks). Only ever // use this after checking that there are no children. // DO NOT CHANGE THE VISIBILITY OF THIS METHOD! -- 2.50.1.windows.1 From 63a463d01149d363cd9c57fa8d07074203cf5a0a Mon Sep 17 00:00:00 2001 From: Nate Stedman Date: Tue, 10 Mar 2020 09:35:55 -0700 Subject: [PATCH 08/34] Mark YogaKit as modular Differential Revision: D20364340 fbshipit-source-id: ce4bc1f474177ffc9c77eb2f10bdb7cb549dd6d8 --- YogaKit/BUCK | 2 ++ 1 file changed, 2 insertions(+) diff --git a/YogaKit/BUCK b/YogaKit/BUCK index c3d534e8..0bff3caa 100644 --- a/YogaKit/BUCK +++ b/YogaKit/BUCK @@ -42,6 +42,8 @@ yoga_apple_library( ], header_path_prefix = "", link_whole = True, + modular = True, + module_name = "YogaKit", visibility = ["PUBLIC"], deps = [ yoga_dep(":yoga"), -- 2.50.1.windows.1 From b280a19b0a61d6119ac48b441bcfd9cedd416113 Mon Sep 17 00:00:00 2001 From: Adam Ernst Date: Tue, 10 Mar 2020 10:55:08 -0700 Subject: [PATCH 09/34] Run 'arc lint-deps' Reviewed By: d16r Differential Revision: D20362505 fbshipit-source-id: f3b7e62f7665d20a32788042772b731d6ed53f36 --- YogaKit/BUCK | 1 + 1 file changed, 1 insertion(+) diff --git a/YogaKit/BUCK b/YogaKit/BUCK index 0bff3caa..acefcdb3 100644 --- a/YogaKit/BUCK +++ b/YogaKit/BUCK @@ -37,6 +37,7 @@ 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", ], -- 2.50.1.windows.1 From 4f1231f411b88c6e280a7ad2aa1354dc111b337d Mon Sep 17 00:00:00 2001 From: Lior Israeli Date: Tue, 24 Mar 2020 05:18:30 -0700 Subject: [PATCH 10/34] Fix typo in buck targets Summary: Proguard is spelled wrong Reviewed By: SidharthGuglani Differential Revision: D20619173 fbshipit-source-id: 463788454ad7e72337121ed63ab79129db45113e --- android/BUCK | 4 ++-- java/BUCK | 6 +++--- lib/fb/src/main/java/com/facebook/jni/BUCK | 4 ++-- tools/build_defs/oss/yoga_defs.bzl | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/android/BUCK b/android/BUCK index 649b96a3..6acb3325 100644 --- a/android/BUCK +++ b/android/BUCK @@ -3,7 +3,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", "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", @@ -15,7 +15,7 @@ yoga_android_aar( ANDROID_JAVA_TARGET, ANDROID_RES_TARGET, JAVA_TARGET, - PROGRUARD_ANNOTATIONS_TARGET, + PROGUARD_ANNOTATIONS_TARGET, ], ) diff --git a/java/BUCK b/java/BUCK index 72be4261..221e8265 100644 --- a/java/BUCK +++ b/java/BUCK @@ -3,7 +3,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", "ANDROID", "CXX_LIBRARY_WHITELIST", "JNI_TARGET", "JSR_305_TARGET", "JUNIT_TARGET", "PROGRUARD_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") +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"), @@ -71,7 +71,7 @@ yoga_java_library( visibility = ["PUBLIC"], deps = [ JSR_305_TARGET, - PROGRUARD_ANNOTATIONS_TARGET, + PROGUARD_ANNOTATIONS_TARGET, ], ) @@ -85,7 +85,7 @@ yoga_java_library( ":java-interface", ":jni", JSR_305_TARGET, - PROGRUARD_ANNOTATIONS_TARGET, + PROGUARD_ANNOTATIONS_TARGET, SOLOADER_TARGET, ], ) diff --git a/lib/fb/src/main/java/com/facebook/jni/BUCK b/lib/fb/src/main/java/com/facebook/jni/BUCK index e048811d..38526c26 100644 --- a/lib/fb/src/main/java/com/facebook/jni/BUCK +++ b/lib/fb/src/main/java/com/facebook/jni/BUCK @@ -3,7 +3,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", "JSR_305_TARGET", "PROGRUARD_ANNOTATIONS_TARGET", "SOLOADER_TARGET", "yoga_java_library") +load("//tools/build_defs/oss:yoga_defs.bzl", "JSR_305_TARGET", "PROGUARD_ANNOTATIONS_TARGET", "SOLOADER_TARGET", "yoga_java_library") yoga_java_library( name = "jni", @@ -13,7 +13,7 @@ yoga_java_library( "PUBLIC", ], deps = [ - PROGRUARD_ANNOTATIONS_TARGET, + PROGUARD_ANNOTATIONS_TARGET, SOLOADER_TARGET, JSR_305_TARGET, ], diff --git a/tools/build_defs/oss/yoga_defs.bzl b/tools/build_defs/oss/yoga_defs.bzl index 4c50e984..253449b3 100644 --- a/tools/build_defs/oss/yoga_defs.bzl +++ b/tools/build_defs/oss/yoga_defs.bzl @@ -14,7 +14,7 @@ JSR_305_TARGET = "//lib/jsr-305:jsr-305" JUNIT_TARGET = "//lib/junit:junit" -PROGRUARD_ANNOTATIONS_TARGET = "//java/proguard-annotations/src/main/java/com/facebook/proguard/annotations:annotations" +PROGUARD_ANNOTATIONS_TARGET = "//java/proguard-annotations/src/main/java/com/facebook/proguard/annotations:annotations" SOLOADER_TARGET = "//lib/soloader:soloader" -- 2.50.1.windows.1 From 5bf93e81ba4547902d7554d055f0b53eb7bafdfa Mon Sep 17 00:00:00 2001 From: Michael Bolin Date: Tue, 24 Mar 2020 20:18:20 -0700 Subject: [PATCH 11/34] 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 --- website/package.json | 2 +- .../Playground/src/CodeJavaScript.js | 8 ++++--- .../components/Playground/src/CodeLitho.js | 4 ++-- .../components/Playground/src/URLShortener.js | 4 +--- .../Playground/src/YogaEnumSelect.js | 5 +---- website/src/pages/docs/index.js | 21 +++++++++---------- website/yarn.lock | 8 +++---- 7 files changed, 24 insertions(+), 28 deletions(-) diff --git a/website/package.json b/website/package.json index 442b13f6..218c1e73 100644 --- a/website/package.json +++ b/website/package.json @@ -32,6 +32,6 @@ "develop": "gatsby develop" }, "devDependencies": { - "prettier": "1.17.0" + "prettier": "2.0.2" } } diff --git a/website/src/components/Playground/src/CodeJavaScript.js b/website/src/components/Playground/src/CodeJavaScript.js index a16a586c..efa48ec0 100644 --- a/website/src/components/Playground/src/CodeJavaScript.js +++ b/website/src/components/Playground/src/CodeJavaScript.js @@ -27,9 +27,11 @@ export const JSEnumLookup = { }; function getEnum(yogaEnum: string, value: string | number): string { - return `yoga.${Object.keys(yoga) - .filter(key => key.toLowerCase().startsWith(yogaEnum.toLowerCase())) - .find(key => yoga[key] === value) || value}`; + return `yoga.${ + Object.keys(yoga) + .filter(key => key.toLowerCase().startsWith(yogaEnum.toLowerCase())) + .find(key => yoga[key] === value) || value + }`; } function setProperty( diff --git a/website/src/components/Playground/src/CodeLitho.js b/website/src/components/Playground/src/CodeLitho.js index 0e9f782b..66e89a3e 100644 --- a/website/src/components/Playground/src/CodeLitho.js +++ b/website/src/components/Playground/src/CodeLitho.js @@ -47,8 +47,8 @@ function dipOrPercent(value) { return value === 'auto' ? 'Auto' : typeof value === 'string' && /%$/.test(value) - ? 'Percent' - : 'Dip'; + ? 'Percent' + : 'Dip'; } function getValue(value) { diff --git a/website/src/components/Playground/src/URLShortener.js b/website/src/components/Playground/src/URLShortener.js index 77130a0f..27049801 100644 --- a/website/src/components/Playground/src/URLShortener.js +++ b/website/src/components/Playground/src/URLShortener.js @@ -52,9 +52,7 @@ export default class URLShortener extends Component<{}, State> { } fetch( - `https://cors-anywhere.herokuapp.com/tinyurl.com/api-create.php?url=${ - window.location.href - }`, + `https://cors-anywhere.herokuapp.com/tinyurl.com/api-create.php?url=${window.location.href}`, ) .then(res => res.text()) .then(shortURL => this.setState({shortURL, loading: false})) diff --git a/website/src/components/Playground/src/YogaEnumSelect.js b/website/src/components/Playground/src/YogaEnumSelect.js index 04ce3968..8c7f297e 100644 --- a/website/src/components/Playground/src/YogaEnumSelect.js +++ b/website/src/components/Playground/src/YogaEnumSelect.js @@ -57,10 +57,7 @@ export default class YogaEnumSelect extends Component { getTitle = (property: string, key: string): string => { const replacer = new RegExp(`^${property}_`); - return key - .replace(replacer, '') - .replace('_', ' ') - .toLowerCase(); + return key.replace(replacer, '').replace('_', ' ').toLowerCase(); }; render() { diff --git a/website/src/pages/docs/index.js b/website/src/pages/docs/index.js index 66e0a363..96dee1ae 100644 --- a/website/src/pages/docs/index.js +++ b/website/src/pages/docs/index.js @@ -49,17 +49,16 @@ export default ({data}) => ( ({node}) => node.fileAbsolutePath.indexOf(`/${category}/`) > -1, ) - .map( - ({node}) => - node.frontmatter.redirect ? ( - - {node.frontmatter.title} - - ) : ( - - {node.frontmatter.title} - - ), + .map(({node}) => + node.frontmatter.redirect ? ( + + {node.frontmatter.title} + + ) : ( + + {node.frontmatter.title} + + ), )} ), diff --git a/website/yarn.lock b/website/yarn.lock index 509efeca..9cb28ac6 100644 --- a/website/yarn.lock +++ b/website/yarn.lock @@ -6978,10 +6978,10 @@ preserve@^0.2.0: version "0.2.0" resolved "https://registry.yarnpkg.com/preserve/-/preserve-0.2.0.tgz#815ed1f6ebc65926f865b310c0713bcb3315ce4b" -prettier@1.17.0: - version "1.17.0" - resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.17.0.tgz#53b303676eed22cc14a9f0cec09b477b3026c008" - integrity sha512-sXe5lSt2WQlCbydGETgfm1YBShgOX4HxQkFPvbxkcwgDvGDeqVau8h+12+lmSVlP3rHPz0oavfddSZg/q+Szjw== +prettier@2.0.2: + version "2.0.2" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.0.2.tgz#1ba8f3eb92231e769b7fcd7cb73ae1b6b74ade08" + integrity sha512-5xJQIPT8BraI7ZnaDwSbu5zLrB6vvi8hVV58yHQ+QK64qrY40dULy0HSRlQ2/2IdzeBpjhDkqdcFBnFeDEMVdg== pretty-bytes@^4.0.2: version "4.0.2" -- 2.50.1.windows.1 From 0f08aa53dab729324b9706a833e219ee654c64a6 Mon Sep 17 00:00:00 2001 From: Michael Bolin Date: Tue, 24 Mar 2020 21:35:58 -0700 Subject: [PATCH 12/34] Back out "Upgrade Prettier from 1.17 to 2.0.2." Differential Revision: D20639755 fbshipit-source-id: 5028563f9cf0527a30b4259daac50cdc03934bfd --- website/package.json | 2 +- .../Playground/src/CodeJavaScript.js | 8 +++---- .../components/Playground/src/CodeLitho.js | 4 ++-- .../components/Playground/src/URLShortener.js | 4 +++- .../Playground/src/YogaEnumSelect.js | 5 ++++- website/src/pages/docs/index.js | 21 ++++++++++--------- website/yarn.lock | 8 +++---- 7 files changed, 28 insertions(+), 24 deletions(-) diff --git a/website/package.json b/website/package.json index 218c1e73..442b13f6 100644 --- a/website/package.json +++ b/website/package.json @@ -32,6 +32,6 @@ "develop": "gatsby develop" }, "devDependencies": { - "prettier": "2.0.2" + "prettier": "1.17.0" } } diff --git a/website/src/components/Playground/src/CodeJavaScript.js b/website/src/components/Playground/src/CodeJavaScript.js index efa48ec0..a16a586c 100644 --- a/website/src/components/Playground/src/CodeJavaScript.js +++ b/website/src/components/Playground/src/CodeJavaScript.js @@ -27,11 +27,9 @@ export const JSEnumLookup = { }; function getEnum(yogaEnum: string, value: string | number): string { - return `yoga.${ - Object.keys(yoga) - .filter(key => key.toLowerCase().startsWith(yogaEnum.toLowerCase())) - .find(key => yoga[key] === value) || value - }`; + return `yoga.${Object.keys(yoga) + .filter(key => key.toLowerCase().startsWith(yogaEnum.toLowerCase())) + .find(key => yoga[key] === value) || value}`; } function setProperty( diff --git a/website/src/components/Playground/src/CodeLitho.js b/website/src/components/Playground/src/CodeLitho.js index 66e89a3e..0e9f782b 100644 --- a/website/src/components/Playground/src/CodeLitho.js +++ b/website/src/components/Playground/src/CodeLitho.js @@ -47,8 +47,8 @@ function dipOrPercent(value) { return value === 'auto' ? 'Auto' : typeof value === 'string' && /%$/.test(value) - ? 'Percent' - : 'Dip'; + ? 'Percent' + : 'Dip'; } function getValue(value) { diff --git a/website/src/components/Playground/src/URLShortener.js b/website/src/components/Playground/src/URLShortener.js index 27049801..77130a0f 100644 --- a/website/src/components/Playground/src/URLShortener.js +++ b/website/src/components/Playground/src/URLShortener.js @@ -52,7 +52,9 @@ export default class URLShortener extends Component<{}, State> { } fetch( - `https://cors-anywhere.herokuapp.com/tinyurl.com/api-create.php?url=${window.location.href}`, + `https://cors-anywhere.herokuapp.com/tinyurl.com/api-create.php?url=${ + window.location.href + }`, ) .then(res => res.text()) .then(shortURL => this.setState({shortURL, loading: false})) diff --git a/website/src/components/Playground/src/YogaEnumSelect.js b/website/src/components/Playground/src/YogaEnumSelect.js index 8c7f297e..04ce3968 100644 --- a/website/src/components/Playground/src/YogaEnumSelect.js +++ b/website/src/components/Playground/src/YogaEnumSelect.js @@ -57,7 +57,10 @@ export default class YogaEnumSelect extends Component { getTitle = (property: string, key: string): string => { const replacer = new RegExp(`^${property}_`); - return key.replace(replacer, '').replace('_', ' ').toLowerCase(); + return key + .replace(replacer, '') + .replace('_', ' ') + .toLowerCase(); }; render() { diff --git a/website/src/pages/docs/index.js b/website/src/pages/docs/index.js index 96dee1ae..66e0a363 100644 --- a/website/src/pages/docs/index.js +++ b/website/src/pages/docs/index.js @@ -49,16 +49,17 @@ export default ({data}) => ( ({node}) => node.fileAbsolutePath.indexOf(`/${category}/`) > -1, ) - .map(({node}) => - node.frontmatter.redirect ? ( - - {node.frontmatter.title} - - ) : ( - - {node.frontmatter.title} - - ), + .map( + ({node}) => + node.frontmatter.redirect ? ( + + {node.frontmatter.title} + + ) : ( + + {node.frontmatter.title} + + ), )} ), diff --git a/website/yarn.lock b/website/yarn.lock index 9cb28ac6..509efeca 100644 --- a/website/yarn.lock +++ b/website/yarn.lock @@ -6978,10 +6978,10 @@ preserve@^0.2.0: version "0.2.0" resolved "https://registry.yarnpkg.com/preserve/-/preserve-0.2.0.tgz#815ed1f6ebc65926f865b310c0713bcb3315ce4b" -prettier@2.0.2: - version "2.0.2" - resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.0.2.tgz#1ba8f3eb92231e769b7fcd7cb73ae1b6b74ade08" - integrity sha512-5xJQIPT8BraI7ZnaDwSbu5zLrB6vvi8hVV58yHQ+QK64qrY40dULy0HSRlQ2/2IdzeBpjhDkqdcFBnFeDEMVdg== +prettier@1.17.0: + version "1.17.0" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.17.0.tgz#53b303676eed22cc14a9f0cec09b477b3026c008" + integrity sha512-sXe5lSt2WQlCbydGETgfm1YBShgOX4HxQkFPvbxkcwgDvGDeqVau8h+12+lmSVlP3rHPz0oavfddSZg/q+Szjw== pretty-bytes@^4.0.2: version "4.0.2" -- 2.50.1.windows.1 From ecd7790dd8192b4c2944f85e28df2fc589b908c0 Mon Sep 17 00:00:00 2001 From: Sidharth Guglani Date: Wed, 1 Apr 2020 14:37:45 -0700 Subject: [PATCH 13/34] 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 --- yoga/Yoga.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/yoga/Yoga.cpp b/yoga/Yoga.cpp index e30a36b7..d916a45f 100644 --- a/yoga/Yoga.cpp +++ b/yoga/Yoga.cpp @@ -2338,7 +2338,8 @@ static void YGDistributeFreeSpaceFirstPass( // first and second passes. deltaFreeSpace += boundMainSize - childFlexBasis; collectedFlexItemsValues.totalFlexShrinkScaledFactors -= - flexShrinkScaledFactor; + (-currentRelativeChild->resolveFlexShrink() * + currentRelativeChild->getLayout().computedFlexBasis.unwrap()); } } } else if ( -- 2.50.1.windows.1 From 2049c85a6cda69f54ed4657199f888e8be513328 Mon Sep 17 00:00:00 2001 From: Sidharth Guglani Date: Wed, 1 Apr 2020 14:37:45 -0700 Subject: [PATCH 14/34] Unit tests for flexshrink min width cases Reviewed By: pasqualeanatriello Differential Revision: D20219428 fbshipit-source-id: 8cbd028627095d9f7b393489ddba1f31c3207b67 --- tests/YGFlexTest.cpp | 118 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) diff --git a/tests/YGFlexTest.cpp b/tests/YGFlexTest.cpp index 21c7578d..ab6dec76 100644 --- a/tests/YGFlexTest.cpp +++ b/tests/YGFlexTest.cpp @@ -605,3 +605,121 @@ TEST(YogaTest, flex_grow_less_than_factor_one) { YGConfigFree(config); } + +TEST(YogaTest, flex_shrink_min_width) { + const YGConfigRef config = YGConfigNew(); + YGConfigSetUseWebDefaults(config, true); + + const YGNodeRef root = YGNodeNewWithConfig(config); + YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); + YGNodeStyleSetWidth(root, 500); + YGNodeStyleSetHeight(root, 500); + + const YGNodeRef root_child0 = YGNodeNewWithConfig(config); + YGNodeStyleSetFlexDirection(root_child0, YGFlexDirectionRow); + YGNodeStyleSetWidth(root_child0, 100); + YGNodeStyleSetMinWidth(root_child0, 301); + YGNodeStyleSetHeight(root_child0, 100); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child1 = YGNodeNewWithConfig(config); + YGNodeStyleSetFlexDirection(root_child1, YGFlexDirectionRow); + YGNodeStyleSetWidth(root_child1, 100); + YGNodeStyleSetMinWidth(root_child1, 25); + YGNodeStyleSetHeight(root_child1, 100); + YGNodeInsertChild(root, root_child1, 1); + + const YGNodeRef root_child2 = YGNodeNewWithConfig(config); + YGNodeStyleSetFlexDirection(root_child2, YGFlexDirectionRow); + YGNodeStyleSetWidth(root_child2, 100); + YGNodeStyleSetHeight(root_child2, 100); + YGNodeInsertChild(root, root_child2, 2); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(500, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(500, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(301, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(301, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(401, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(99, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child2)); + + YGNodeFreeRecursive(root); + + YGConfigFree(config); +} + +TEST(YogaTest, flex_shrink_flex_grow_min_width) { + const YGConfigRef config = YGConfigNew(); + YGConfigSetUseWebDefaults(config, true); + + const YGNodeRef root = YGNodeNewWithConfig(config); + YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); + YGNodeStyleSetWidth(root, 500); + YGNodeStyleSetHeight(root, 500); + + const YGNodeRef root_child0 = YGNodeNewWithConfig(config); + YGNodeStyleSetFlexDirection(root_child0, YGFlexDirectionRow); + YGNodeStyleSetFlexGrow(root_child0, 0); + YGNodeStyleSetFlexShrink(root_child0, 1); + YGNodeStyleSetWidth(root_child0, 100); + YGNodeStyleSetMinWidth(root_child0, 301); + YGNodeStyleSetHeight(root_child0, 100); + YGNodeInsertChild(root, root_child0, 0); + + const YGNodeRef root_child1 = YGNodeNewWithConfig(config); + YGNodeStyleSetFlexDirection(root_child1, YGFlexDirectionRow); + YGNodeStyleSetFlexGrow(root_child1, 1); + YGNodeStyleSetFlexShrink(root_child1, 1); + YGNodeStyleSetWidth(root_child1, 100); + YGNodeStyleSetMinWidth(root_child1, 25); + YGNodeStyleSetHeight(root_child1, 100); + YGNodeInsertChild(root, root_child1, 1); + + const YGNodeRef root_child2 = YGNodeNewWithConfig(config); + YGNodeStyleSetFlexDirection(root_child2, YGFlexDirectionRow); + YGNodeStyleSetWidth(root_child2, 100); + YGNodeStyleSetHeight(root_child2, 100); + YGNodeStyleSetFlexShrink(root_child2, 1); + YGNodeStyleSetFlexGrow(root_child2, 1); + YGNodeInsertChild(root, root_child2, 2); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(500, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(500, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(301, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0)); + + ASSERT_FLOAT_EQ(301, YGNodeLayoutGetLeft(root_child1)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child1)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child1)); + + ASSERT_FLOAT_EQ(401, YGNodeLayoutGetLeft(root_child2)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2)); + ASSERT_FLOAT_EQ(99, YGNodeLayoutGetWidth(root_child2)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child2)); + + YGNodeFreeRecursive(root); + + YGConfigFree(config); +} -- 2.50.1.windows.1 From 5eba2d42bd6fde1092439cbc3388ae0a3cc561d9 Mon Sep 17 00:00:00 2001 From: Gavin Weng Date: Mon, 6 Apr 2020 11:45:21 -0700 Subject: [PATCH 15/34] 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 --- BUCK | 14 ++++++++++++++ android/BUCK | 1 + java/BUCK | 4 ++-- testutil/BUCK | 14 +++++++++++++- 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/BUCK b/BUCK index fa0e5580..eb96206f 100644 --- a/BUCK +++ b/BUCK @@ -40,6 +40,20 @@ yoga_cxx_library( ], ) +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", + ], +) + yoga_cxx_library( name = "yogaForDebug", srcs = glob(["yoga/**/*.cpp"]), diff --git a/android/BUCK b/android/BUCK index 6acb3325..72548072 100644 --- a/android/BUCK +++ b/android/BUCK @@ -7,6 +7,7 @@ load("//tools/build_defs/oss:yoga_defs.bzl", "ANDROID_JAVA_TARGET", "ANDROID_RES yoga_android_aar( name = "android", + enable_relinker = True, manifest_skeleton = "src/main/AndroidManifest.xml", visibility = [ "PUBLIC", diff --git a/java/BUCK b/java/BUCK index 221e8265..d08cb37b 100644 --- a/java/BUCK +++ b/java/BUCK @@ -7,7 +7,7 @@ load("//tools/build_defs/oss:yoga_defs.bzl", "ANDROID", "CXX_LIBRARY_WHITELIST", 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 = [ @@ -54,7 +54,7 @@ yoga_cxx_library( visibility = ["PUBLIC"], deps = [ JNI_TARGET, - yoga_dep(":yoga"), + yoga_dep(":yoga-static"), ":ndklog", ], ) diff --git a/testutil/BUCK b/testutil/BUCK index 56ee97fe..acbabc11 100644 --- a/testutil/BUCK +++ b/testutil/BUCK @@ -11,6 +11,18 @@ yoga_cxx_library( deps = [yoga_dep(":yoga")], ) +yoga_cxx_library( + name = "testutil-jni", + srcs = ["src/main/cpp/testutil/testutil.cpp"], + header_namespace = "", + exported_headers = subdir_glob([("src/main/cpp/include", "yoga/testutil/testutil.h")]), + compiler_flags = LIBRARY_COMPILER_FLAGS, + platforms = ANDROID, + soname = "libyoga_testutil.$(ext)", + visibility = ["PUBLIC"], + deps = [yoga_dep("java:jni")], +) + yoga_java_library( name = "java", srcs = ["src/main/java/com/facebook/yoga/TestUtil.java"], @@ -32,7 +44,7 @@ yoga_cxx_library( soname = "libyoga_testutil_jni.$(ext)", visibility = ["PUBLIC"], deps = [ - ":testutil", + ":testutil-jni", FBJNI_TARGET, ], ) -- 2.50.1.windows.1 From be51bc44a48da64c346309995b443c96610b43a1 Mon Sep 17 00:00:00 2001 From: Gavin Weng Date: Mon, 6 Apr 2020 19:51:09 -0700 Subject: [PATCH 16/34] Revert Name Change for FBLite Summary: To unblock Reviewed By: Arieg419 Differential Revision: D20879886 fbshipit-source-id: 428f9147e540b94dec7f72a7f844949722165a07 --- java/BUCK | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java/BUCK b/java/BUCK index d08cb37b..034024cd 100644 --- a/java/BUCK +++ b/java/BUCK @@ -54,7 +54,7 @@ yoga_cxx_library( visibility = ["PUBLIC"], deps = [ JNI_TARGET, - yoga_dep(":yoga-static"), + yoga_dep(":yoga"), ":ndklog", ], ) -- 2.50.1.windows.1 From 8c53c2dcca9a7acf3733c00e5820f5a18f075024 Mon Sep 17 00:00:00 2001 From: George Zahariev Date: Thu, 9 Apr 2020 10:55:48 -0700 Subject: [PATCH 17/34] 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 --- website/package.json | 2 +- website/yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/website/package.json b/website/package.json index 442b13f6..53445418 100644 --- a/website/package.json +++ b/website/package.json @@ -32,6 +32,6 @@ "develop": "gatsby develop" }, "devDependencies": { - "prettier": "1.17.0" + "prettier": "1.19.1" } } diff --git a/website/yarn.lock b/website/yarn.lock index 509efeca..fa5a26e2 100644 --- a/website/yarn.lock +++ b/website/yarn.lock @@ -6978,10 +6978,10 @@ preserve@^0.2.0: version "0.2.0" resolved "https://registry.yarnpkg.com/preserve/-/preserve-0.2.0.tgz#815ed1f6ebc65926f865b310c0713bcb3315ce4b" -prettier@1.17.0: - version "1.17.0" - resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.17.0.tgz#53b303676eed22cc14a9f0cec09b477b3026c008" - integrity sha512-sXe5lSt2WQlCbydGETgfm1YBShgOX4HxQkFPvbxkcwgDvGDeqVau8h+12+lmSVlP3rHPz0oavfddSZg/q+Szjw== +prettier@1.19.1: + version "1.19.1" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.19.1.tgz#f7d7f5ff8a9cd872a7be4ca142095956a60797cb" + integrity sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew== pretty-bytes@^4.0.2: version "4.0.2" -- 2.50.1.windows.1 From f7bc0ad2489c1b09d0cc0d53f668861f5d7875a0 Mon Sep 17 00:00:00 2001 From: George Zahariev Date: Thu, 9 Apr 2020 10:55:48 -0700 Subject: [PATCH 18/34] 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 --- .../components/Playground/src/CodeLitho.js | 4 ++-- .../components/Playground/src/URLShortener.js | 4 +--- website/src/pages/docs/index.js | 21 +++++++++---------- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/website/src/components/Playground/src/CodeLitho.js b/website/src/components/Playground/src/CodeLitho.js index 0e9f782b..66e89a3e 100644 --- a/website/src/components/Playground/src/CodeLitho.js +++ b/website/src/components/Playground/src/CodeLitho.js @@ -47,8 +47,8 @@ function dipOrPercent(value) { return value === 'auto' ? 'Auto' : typeof value === 'string' && /%$/.test(value) - ? 'Percent' - : 'Dip'; + ? 'Percent' + : 'Dip'; } function getValue(value) { diff --git a/website/src/components/Playground/src/URLShortener.js b/website/src/components/Playground/src/URLShortener.js index 77130a0f..27049801 100644 --- a/website/src/components/Playground/src/URLShortener.js +++ b/website/src/components/Playground/src/URLShortener.js @@ -52,9 +52,7 @@ export default class URLShortener extends Component<{}, State> { } fetch( - `https://cors-anywhere.herokuapp.com/tinyurl.com/api-create.php?url=${ - window.location.href - }`, + `https://cors-anywhere.herokuapp.com/tinyurl.com/api-create.php?url=${window.location.href}`, ) .then(res => res.text()) .then(shortURL => this.setState({shortURL, loading: false})) diff --git a/website/src/pages/docs/index.js b/website/src/pages/docs/index.js index 66e0a363..96dee1ae 100644 --- a/website/src/pages/docs/index.js +++ b/website/src/pages/docs/index.js @@ -49,17 +49,16 @@ export default ({data}) => ( ({node}) => node.fileAbsolutePath.indexOf(`/${category}/`) > -1, ) - .map( - ({node}) => - node.frontmatter.redirect ? ( - - {node.frontmatter.title} - - ) : ( - - {node.frontmatter.title} - - ), + .map(({node}) => + node.frontmatter.redirect ? ( + + {node.frontmatter.title} + + ) : ( + + {node.frontmatter.title} + + ), )} ), -- 2.50.1.windows.1 From e5743e851bde6611529a8c57401ad6445ca57b32 Mon Sep 17 00:00:00 2001 From: Sidharth Guglani Date: Tue, 14 Apr 2020 02:04:17 -0700 Subject: [PATCH 19/34] 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 --- yoga/Yoga.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/yoga/Yoga.cpp b/yoga/Yoga.cpp index d916a45f..d6f4a114 100644 --- a/yoga/Yoga.cpp +++ b/yoga/Yoga.cpp @@ -1663,8 +1663,8 @@ static void YGNodeAbsoluteLayoutChild( static void YGNodeWithMeasureFuncSetMeasuredDimensions( const YGNodeRef node, - const float availableWidth, - const float availableHeight, + float availableWidth, + float availableHeight, const YGMeasureMode widthMeasureMode, const YGMeasureMode heightMeasureMode, const float ownerWidth, @@ -1677,6 +1677,13 @@ static void YGNodeWithMeasureFuncSetMeasuredDimensions( node->hasMeasureFunc(), "Expected node to have custom measure function"); + if (widthMeasureMode == YGMeasureModeUndefined) { + availableWidth = YGUndefined; + } + if (heightMeasureMode == YGMeasureModeUndefined) { + availableHeight = YGUndefined; + } + const float paddingAndBorderAxisRow = YGNodePaddingAndBorderForAxis(node, YGFlexDirectionRow, ownerWidth); const float paddingAndBorderAxisColumn = -- 2.50.1.windows.1 From 9b96a5362a873935c50b444aa271927257c2f984 Mon Sep 17 00:00:00 2001 From: empyrical Date: Tue, 14 Apr 2020 16:39:32 -0700 Subject: [PATCH 20/34] 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 --- Yoga.podspec | 2 +- yoga/YGNode.h | 5 +++++ yoga/YGStyle.h | 5 +++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Yoga.podspec b/Yoga.podspec index 24e1c0b8..2b09977d 100644 --- a/Yoga.podspec +++ b/Yoga.podspec @@ -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 diff --git a/yoga/YGNode.h b/yoga/YGNode.h index 9aef1ec6..63d98fe3 100644 --- a/yoga/YGNode.h +++ b/yoga/YGNode.h @@ -6,6 +6,9 @@ */ #pragma once + +#ifdef __cplusplus + #include #include #include "BitUtils.h" @@ -330,3 +333,5 @@ public: bool isLayoutTreeEqualToNode(const YGNode& node) const; void reset(); }; + +#endif diff --git a/yoga/YGStyle.h b/yoga/YGStyle.h index 9bfbc442..aab7599c 100644 --- a/yoga/YGStyle.h +++ b/yoga/YGStyle.h @@ -6,6 +6,9 @@ */ #pragma once + +#ifdef __cplusplus + #include #include #include @@ -229,3 +232,5 @@ YOGA_EXPORT bool operator==(const YGStyle& lhs, const YGStyle& rhs); YOGA_EXPORT inline bool operator!=(const YGStyle& lhs, const YGStyle& rhs) { return !(lhs == rhs); } + +#endif -- 2.50.1.windows.1 From e637cf2d72654d4b125e84de86bbcd2f30604cf6 Mon Sep 17 00:00:00 2001 From: Sidharth Guglani Date: Wed, 15 Apr 2020 00:47:07 -0700 Subject: [PATCH 21/34] 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 --- testutil/BUCK | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/testutil/BUCK b/testutil/BUCK index acbabc11..1a66f91b 100644 --- a/testutil/BUCK +++ b/testutil/BUCK @@ -20,7 +20,10 @@ yoga_cxx_library( platforms = ANDROID, soname = "libyoga_testutil.$(ext)", visibility = ["PUBLIC"], - deps = [yoga_dep("java:jni")], + deps = [ + yoga_dep("java:jni"), + yoga_dep(":yoga"), + ], ) yoga_java_library( -- 2.50.1.windows.1 From 92b76447b772e39d4ac209d25f123e9655be2f62 Mon Sep 17 00:00:00 2001 From: Sidharth Guglani Date: Fri, 17 Apr 2020 05:25:22 -0700 Subject: [PATCH 22/34] 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 --- yoga/YGLayout.h | 2 +- yoga/Yoga-internal.h | 8 ++++---- yoga/Yoga.cpp | 6 ++++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/yoga/YGLayout.h b/yoga/YGLayout.h index 30b8dd76..b7604d8e 100644 --- a/yoga/YGLayout.h +++ b/yoga/YGLayout.h @@ -36,7 +36,7 @@ public: // Instead of recomputing the entire layout every single time, we cache some // information to break early when nothing changed uint32_t generationCount = 0; - YGDirection lastOwnerDirection = (YGDirection) -1; + YGDirection lastOwnerDirection = YGDirectionInherit; uint32_t nextCachedMeasurementsIndex = 0; std::array diff --git a/yoga/Yoga-internal.h b/yoga/Yoga-internal.h index 0b3368a0..1a22f24c 100644 --- a/yoga/Yoga-internal.h +++ b/yoga/Yoga-internal.h @@ -54,10 +54,10 @@ struct YGCachedMeasurement { float computedHeight; YGCachedMeasurement() - : availableWidth(0), - availableHeight(0), - widthMeasureMode((YGMeasureMode) -1), - heightMeasureMode((YGMeasureMode) -1), + : availableWidth(-1), + availableHeight(-1), + widthMeasureMode(YGMeasureModeUndefined), + heightMeasureMode(YGMeasureModeUndefined), computedWidth(-1), computedHeight(-1) {} diff --git a/yoga/Yoga.cpp b/yoga/Yoga.cpp index d6f4a114..bb7da7bf 100644 --- a/yoga/Yoga.cpp +++ b/yoga/Yoga.cpp @@ -3821,8 +3821,10 @@ bool YGLayoutNodeInternal( if (needToVisitNode) { // Invalidate the cached results. layout->nextCachedMeasurementsIndex = 0; - layout->cachedLayout.widthMeasureMode = (YGMeasureMode) -1; - layout->cachedLayout.heightMeasureMode = (YGMeasureMode) -1; + layout->cachedLayout.availableWidth = -1; + layout->cachedLayout.availableHeight = -1; + layout->cachedLayout.widthMeasureMode = YGMeasureModeUndefined; + layout->cachedLayout.heightMeasureMode = YGMeasureModeUndefined; layout->cachedLayout.computedWidth = -1; layout->cachedLayout.computedHeight = -1; } -- 2.50.1.windows.1 From 1bd4123df1e493990fe96ab5bc459edfb5dada3b Mon Sep 17 00:00:00 2001 From: acton393 Date: Fri, 17 Apr 2020 05:43:28 -0700 Subject: [PATCH 23/34] 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 --- java/com/facebook/yoga/YogaNodeJNIBase.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java/com/facebook/yoga/YogaNodeJNIBase.java b/java/com/facebook/yoga/YogaNodeJNIBase.java index e20a5389..406e75e5 100644 --- a/java/com/facebook/yoga/YogaNodeJNIBase.java +++ b/java/com/facebook/yoga/YogaNodeJNIBase.java @@ -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; -- 2.50.1.windows.1 From a96a36ef592eefc206053b95f4ace080f251850a Mon Sep 17 00:00:00 2001 From: Gavin Weng Date: Fri, 17 Apr 2020 17:31:39 -0700 Subject: [PATCH 24/34] Link yogacore statically into yoga Summary: A revert of D20879886. Reviewed By: iliagore Differential Revision: D20979490 fbshipit-source-id: cb37f931654450c408e72578abcc549f35727b07 --- java/BUCK | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java/BUCK b/java/BUCK index 034024cd..d08cb37b 100644 --- a/java/BUCK +++ b/java/BUCK @@ -54,7 +54,7 @@ yoga_cxx_library( visibility = ["PUBLIC"], deps = [ JNI_TARGET, - yoga_dep(":yoga"), + yoga_dep(":yoga-static"), ":ndklog", ], ) -- 2.50.1.windows.1 From 884f147742771cea14fcfb1f4ac485b187e7c3fe Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Mon, 20 Apr 2020 12:01:56 -0700 Subject: [PATCH 25/34] 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 --- yoga/YGNode.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yoga/YGNode.cpp b/yoga/YGNode.cpp index c15af8de..23d5c40b 100644 --- a/yoga/YGNode.cpp +++ b/yoga/YGNode.cpp @@ -29,7 +29,7 @@ YGNode::YGNode(YGNode&& node) { config_ = node.config_; resolvedDimensions_ = node.resolvedDimensions_; for (auto c : children_) { - c->setOwner(c); + c->setOwner(this); } } -- 2.50.1.windows.1 From 83b27417ae6a1d577b1fddfa3c9433c2dc42a460 Mon Sep 17 00:00:00 2001 From: Sidharth Guglani Date: Mon, 27 Apr 2020 14:38:51 -0700 Subject: [PATCH 26/34] 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 --- yoga/Yoga.cpp | 26 +++++++++++++------------- yoga/Yoga.h | 4 ++-- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/yoga/Yoga.cpp b/yoga/Yoga.cpp index bb7da7bf..c2a5c286 100644 --- a/yoga/Yoga.cpp +++ b/yoga/Yoga.cpp @@ -3664,8 +3664,8 @@ static inline bool YGMeasureModeNewMeasureSizeIsStricterAndStillValid( } YOGA_EXPORT float YGRoundValueToPixelGrid( - const float value, - const float pointScaleFactor, + const double value, + const double pointScaleFactor, const bool forceCeil, const bool forceFloor) { double scaledValue = ((double) value) * pointScaleFactor; @@ -4081,24 +4081,24 @@ YOGA_EXPORT void YGConfigSetPointScaleFactor( static void YGRoundToPixelGrid( const YGNodeRef node, - const float pointScaleFactor, - const float absoluteLeft, - const float absoluteTop) { + const double pointScaleFactor, + const double absoluteLeft, + const double absoluteTop) { if (pointScaleFactor == 0.0f) { return; } - const float nodeLeft = node->getLayout().position[YGEdgeLeft]; - const float nodeTop = node->getLayout().position[YGEdgeTop]; + const double nodeLeft = node->getLayout().position[YGEdgeLeft]; + const double nodeTop = node->getLayout().position[YGEdgeTop]; - const float nodeWidth = node->getLayout().dimensions[YGDimensionWidth]; - const float nodeHeight = node->getLayout().dimensions[YGDimensionHeight]; + const double nodeWidth = node->getLayout().dimensions[YGDimensionWidth]; + const double nodeHeight = node->getLayout().dimensions[YGDimensionHeight]; - const float absoluteNodeLeft = absoluteLeft + nodeLeft; - const float absoluteNodeTop = absoluteTop + nodeTop; + const double absoluteNodeLeft = absoluteLeft + nodeLeft; + const double absoluteNodeTop = absoluteTop + nodeTop; - const float absoluteNodeRight = absoluteNodeLeft + nodeWidth; - const float absoluteNodeBottom = absoluteNodeTop + nodeHeight; + const double absoluteNodeRight = absoluteNodeLeft + nodeWidth; + const double absoluteNodeBottom = absoluteNodeTop + nodeHeight; // If a node has a custom measure function we never want to round down its // size as this could lead to unwanted text truncation. diff --git a/yoga/Yoga.h b/yoga/Yoga.h index 2fe60a41..87901a28 100644 --- a/yoga/Yoga.h +++ b/yoga/Yoga.h @@ -352,8 +352,8 @@ WIN_EXPORT void YGConfigSetContext(YGConfigRef config, void* context); WIN_EXPORT void* YGConfigGetContext(YGConfigRef config); WIN_EXPORT float YGRoundValueToPixelGrid( - float value, - float pointScaleFactor, + double value, + double pointScaleFactor, bool forceCeil, bool forceFloor); -- 2.50.1.windows.1 From ac7c85c0a629e5029d7e36304d4c02c71da0f41a Mon Sep 17 00:00:00 2001 From: Jon Janzen Date: Tue, 12 May 2020 11:44:50 -0700 Subject: [PATCH 27/34] 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 --- .github/workflows/ci.yml | 56 +++++++++++++++++++++++++++ .travis.yml | 77 ------------------------------------- scripts/publish-snapshot.sh | 12 +++--- 3 files changed, 62 insertions(+), 83 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..ccb6b297 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,56 @@ +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: Install dependencies + run: | + 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 + 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 "::set-env name=PATH::$PATH:$HOME/buck/bin/" + export PATH=$PATH:$HOME/buck/bin/ + buck --version + export TERMINAL=dumb + source scripts/android-setup.sh && installAndroidSDK + echo "::set-env name=ANDROID_SDK::$ANDROID_HOME" + echo "::set-env name=ANDROID_NDK_REPOSITORY::$HOME/android-ndk" + echo "::set-env name=ANDROID_NDK_HOME::$ANDROID_NDK_REPOSITORY/android-ndk-r15c" + - name: Build + run: ./gradlew testDebugUnit && scripts/publish-snapshot.sh diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 3ae55d1f..00000000 --- a/.travis.yml +++ /dev/null @@ -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 diff --git a/scripts/publish-snapshot.sh b/scripts/publish-snapshot.sh index 02c45457..c494f97f 100755 --- a/scripts/publish-snapshot.sh +++ b/scripts/publish-snapshot.sh @@ -14,14 +14,14 @@ set -e BASEDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )" IS_SNAPSHOT="$(grep 'VERSION_NAME=[0-9\.]\+-SNAPSHOT' "$BASEDIR/gradle.properties")" -if [ "$TRAVIS_REPO_SLUG" != "facebook/yoga" ]; then - echo >&2 "Skipping repository. Expected project to be 'facebook/yoga', but was '$TRAVIS_REPO_SLUG'." +if [ "$GITHUB_REPOSITORY" != "facebook/yoga" ]; then + echo >&2 "Skipping repository. Expected project to be 'facebook/yoga', but was '$GITHUB_REPOSITORY'." exit -elif [ "$TRAVIS_BRANCH" != "master" ]; then - echo >&2 "Skipping build. Expected branch name to be 'master', but was '$TRAVIS_BRANCH'." +elif [ "$GITHUB_REF" != "refs/heads/master" ]; then + echo >&2 "Skipping build. Expected ref name to be 'refs/heads/master', but was '$GITHUB_REF'." exit -elif [ "$TRAVIS_PULL_REQUEST" != "false" ]; then - echo >&2 "Skipping build. Only considering non-PR builds, but URL was '$TRAVIS_PULL_REQUEST'." +elif [ "$GITHUB_EVENT_NAME" != "push" ]; then + echo >&2 "Skipping build. Only considering push builds, but event was '$GITHUB_EVENT_NAME'." exit elif [ "$IS_SNAPSHOT" == "" ]; then echo >&2 "Skipping build. Given build doesn't appear to be a SNAPSHOT release." -- 2.50.1.windows.1 From 07c0d539bdb3a248762d0a06fd3f622b278a7ecb Mon Sep 17 00:00:00 2001 From: Sidharth Guglani Date: Thu, 14 May 2020 06:32:13 -0700 Subject: [PATCH 28/34] 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 --- java/jni/YGJNIVanilla.cpp | 7 +++++++ tests/YGMeasureTest.cpp | 4 ++-- yoga/Utils.cpp | 4 ++++ yoga/Utils.h | 2 ++ yoga/Yoga.cpp | 6 +++--- yoga/log.cpp | 4 ---- 6 files changed, 18 insertions(+), 9 deletions(-) diff --git a/java/jni/YGJNIVanilla.cpp b/java/jni/YGJNIVanilla.cpp index 6e66c06e..698ab561 100644 --- a/java/jni/YGJNIVanilla.cpp +++ b/java/jni/YGJNIVanilla.cpp @@ -388,6 +388,13 @@ static void jni_YGNodeCalculateLayoutJNI( 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, "", "(Ljava/lang/String;)V"); + auto throwable = env->NewObject(cl, methodId, env->NewStringUTF(ex.what())); + env->Throw(static_cast(throwable)); } } diff --git a/tests/YGMeasureTest.cpp b/tests/YGMeasureTest.cpp index b5bbe5d4..e47607d4 100644 --- a/tests/YGMeasureTest.cpp +++ b/tests/YGMeasureTest.cpp @@ -580,7 +580,7 @@ TEST(YogaDeathTest, cannot_add_child_to_node_with_measure_func) { root->setMeasureFunc(_measure); const YGNodeRef root_child0 = YGNodeNew(); - ASSERT_DEATH(YGNodeInsertChild(root, root_child0, 0), "Cannot add child.*"); + ASSERT_THROW(YGNodeInsertChild(root, root_child0, 0), std::logic_error); YGNodeFree(root_child0); YGNodeFreeRecursive(root); } @@ -589,7 +589,7 @@ TEST(YogaDeathTest, cannot_add_nonnull_measure_func_to_non_leaf_node) { const YGNodeRef root = YGNodeNew(); const YGNodeRef root_child0 = YGNodeNew(); YGNodeInsertChild(root, root_child0, 0); - ASSERT_DEATH(root->setMeasureFunc(_measure), "Cannot set measure function.*"); + ASSERT_THROW(root->setMeasureFunc(_measure), std::logic_error); YGNodeFreeRecursive(root); } diff --git a/yoga/Utils.cpp b/yoga/Utils.cpp index 761f3515..f6e55d0d 100644 --- a/yoga/Utils.cpp +++ b/yoga/Utils.cpp @@ -65,3 +65,7 @@ YGFloatOptional YGFloatOptionalMax(YGFloatOptional op1, YGFloatOptional op2) { } return op1.isUndefined() ? op2 : op1; } + +void throwLogicalErrorWithMessage(const char* message) { + throw std::logic_error(message); +} diff --git a/yoga/Utils.h b/yoga/Utils.h index bce8dfca..e9edf2f9 100644 --- a/yoga/Utils.h +++ b/yoga/Utils.h @@ -141,3 +141,5 @@ inline YGFloatOptional YGResolveValueMargin( const float ownerSize) { return value.isAuto() ? YGFloatOptional{0} : YGResolveValue(value, ownerSize); } + +void throwLogicalErrorWithMessage(const char* message); diff --git a/yoga/Yoga.cpp b/yoga/Yoga.cpp index c2a5c286..91e09c15 100644 --- a/yoga/Yoga.cpp +++ b/yoga/Yoga.cpp @@ -249,9 +249,6 @@ YOGA_EXPORT YGNodeRef YGNodeClone(YGNodeRef oldNode) { static YGConfigRef YGConfigClone(const YGConfig& oldConfig) { const YGConfigRef config = new YGConfig(oldConfig); YGAssert(config != nullptr, "Could not allocate memory for config"); - if (config == nullptr) { - abort(); - } gConfigInstanceCount++; return config; } @@ -4341,6 +4338,7 @@ YOGA_EXPORT void YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour( void YGAssert(const bool condition, const char* message) { if (!condition) { Log::log(YGNodeRef{nullptr}, YGLogLevelFatal, nullptr, "%s\n", message); + throwLogicalErrorWithMessage(message); } } @@ -4350,6 +4348,7 @@ void YGAssertWithNode( const char* message) { if (!condition) { Log::log(node, YGLogLevelFatal, nullptr, "%s\n", message); + throwLogicalErrorWithMessage(message); } } @@ -4359,6 +4358,7 @@ void YGAssertWithConfig( const char* message) { if (!condition) { Log::log(config, YGLogLevelFatal, nullptr, "%s\n", message); + throwLogicalErrorWithMessage(message); } } diff --git a/yoga/log.cpp b/yoga/log.cpp index fe6fbbc6..eb3da039 100644 --- a/yoga/log.cpp +++ b/yoga/log.cpp @@ -26,10 +26,6 @@ void vlog( va_list args) { YGConfig* logConfig = config != nullptr ? config : YGConfigGetDefault(); logConfig->log(logConfig, node, level, context, format, args); - - if (level == YGLogLevelFatal) { - abort(); - } } } // namespace -- 2.50.1.windows.1 From 4135420cba9540c2d5157dc42fecace4df59af45 Mon Sep 17 00:00:00 2001 From: Jon Janzen Date: Thu, 14 May 2020 12:19:37 -0700 Subject: [PATCH 29/34] 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 --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ccb6b297..c5f2c014 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,8 +34,8 @@ jobs: - uses: actions/checkout@v2 - name: Install dependencies run: | - 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; + 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 -- 2.50.1.windows.1 From ede65bbce4a45aa62d7cb78c8786a2c0eea69661 Mon Sep 17 00:00:00 2001 From: Steven Koeber Date: Thu, 4 Jun 2020 06:35:13 -0700 Subject: [PATCH 30/34] Buckification of Yoga build script Reviewed By: liorisraeli87, k21 Differential Revision: D21429174 fbshipit-source-id: f12c8349cc59398553773df7bc15f0f83bd571b4 --- lib/soloader/BUCK | 5 ++--- tools/build_defs/oss/yoga_defs.bzl | 3 +++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/soloader/BUCK b/lib/soloader/BUCK index 04e2f5ff..eaff4f68 100644 --- a/lib/soloader/BUCK +++ b/lib/soloader/BUCK @@ -3,10 +3,9 @@ # 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:fb_native_wrapper.bzl", "fb_native") -load("//tools/build_defs/oss:yoga_defs.bzl", "YOGA_ROOTS") +load("//tools/build_defs/oss:yoga_defs.bzl", "YOGA_ROOTS", "yoga_prebuilt_aar") -fb_native.android_prebuilt_aar( +yoga_prebuilt_aar( name = "soloader", aar = "soloader-0.5.1.aar", visibility = YOGA_ROOTS, diff --git a/tools/build_defs/oss/yoga_defs.bzl b/tools/build_defs/oss/yoga_defs.bzl index 253449b3..2c108c20 100644 --- a/tools/build_defs/oss/yoga_defs.bzl +++ b/tools/build_defs/oss/yoga_defs.bzl @@ -202,6 +202,9 @@ def yoga_prebuilt_cxx_library(*args, **kwargs): def yoga_prebuilt_jar(*args, **kwargs): native.prebuilt_jar(*args, **kwargs) +def yoga_prebuilt_aar(*args, **kwargs): + native.android_prebuilt_aar(*args, **kwargs) + def is_apple_platform(): return True -- 2.50.1.windows.1 From 633cdc908857a580e73bc209864cc227e25f78b4 Mon Sep 17 00:00:00 2001 From: Sidharth Guglani Date: Mon, 8 Jun 2020 08:07:37 -0700 Subject: [PATCH 31/34] 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 --- yoga/Utils.cpp | 7 +++++++ yoga/Utils.h | 2 ++ yoga/Yoga.cpp | 16 ++++++++-------- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/yoga/Utils.cpp b/yoga/Utils.cpp index f6e55d0d..c4281b60 100644 --- a/yoga/Utils.cpp +++ b/yoga/Utils.cpp @@ -52,6 +52,13 @@ bool YGFloatsEqual(const float a, const float b) { return yoga::isUndefined(a) && yoga::isUndefined(b); } +bool YGDoubleEqual(const double a, const double b) { + if (!yoga::isUndefined(a) && !yoga::isUndefined(b)) { + return fabs(a - b) < 0.0001f; + } + return yoga::isUndefined(a) && yoga::isUndefined(b); +} + float YGFloatSanitize(const float val) { return yoga::isUndefined(val) ? 0 : val; } diff --git a/yoga/Utils.h b/yoga/Utils.h index e9edf2f9..57e1d45d 100644 --- a/yoga/Utils.h +++ b/yoga/Utils.h @@ -64,6 +64,8 @@ inline bool YGValueEqual( // difference between two floats is less than 0.0001f or both are undefined. bool YGFloatsEqual(const float a, const float b); +bool YGDoubleEqual(const double a, const double b); + float YGFloatMax(const float a, const float b); YGFloatOptional YGFloatOptionalMax( diff --git a/yoga/Yoga.cpp b/yoga/Yoga.cpp index 91e09c15..cb06c10e 100644 --- a/yoga/Yoga.cpp +++ b/yoga/Yoga.cpp @@ -3668,7 +3668,7 @@ YOGA_EXPORT float YGRoundValueToPixelGrid( double scaledValue = ((double) value) * pointScaleFactor; // We want to calculate `fractial` such that `floor(scaledValue) = scaledValue // - fractial`. - float fractial = fmodf(scaledValue, 1.0f); + double fractial = fmod(scaledValue, 1.0f); if (fractial < 0) { // This branch is for handling negative numbers for `value`. // @@ -3687,10 +3687,10 @@ YOGA_EXPORT float YGRoundValueToPixelGrid( // - Finding the `floor`: -2.2 - fractial2 = -2.2 - 0.8 = -3 ++fractial; } - if (YGFloatsEqual(fractial, 0)) { + if (YGDoubleEqual(fractial, 0)) { // First we check if the value is already rounded scaledValue = scaledValue - fractial; - } else if (YGFloatsEqual(fractial, 1.0f)) { + } else if (YGDoubleEqual(fractial, 1.0f)) { scaledValue = scaledValue - fractial + 1.0f; } else if (forceCeil) { // Next we check if we need to use forced rounding @@ -3701,7 +3701,7 @@ YOGA_EXPORT float YGRoundValueToPixelGrid( // Finally we just round the value scaledValue = scaledValue - fractial + (!YGFloatIsUndefined(fractial) && - (fractial > 0.5f || YGFloatsEqual(fractial, 0.5f)) + (fractial > 0.5f || YGDoubleEqual(fractial, 0.5f)) ? 1.0f : 0.0f); } @@ -4113,11 +4113,11 @@ static void YGRoundToPixelGrid( // whole number, we don't have any fraction To verify if the result is close // to whole number we want to check both floor and ceil numbers const bool hasFractionalWidth = - !YGFloatsEqual(fmodf(nodeWidth * pointScaleFactor, 1.0), 0) && - !YGFloatsEqual(fmodf(nodeWidth * pointScaleFactor, 1.0), 1.0); + !YGDoubleEqual(fmod(nodeWidth * pointScaleFactor, 1.0), 0) && + !YGDoubleEqual(fmod(nodeWidth * pointScaleFactor, 1.0), 1.0); const bool hasFractionalHeight = - !YGFloatsEqual(fmodf(nodeHeight * pointScaleFactor, 1.0), 0) && - !YGFloatsEqual(fmodf(nodeHeight * pointScaleFactor, 1.0), 1.0); + !YGDoubleEqual(fmod(nodeHeight * pointScaleFactor, 1.0), 0) && + !YGDoubleEqual(fmod(nodeHeight * pointScaleFactor, 1.0), 1.0); node->setLayoutDimension( YGRoundValueToPixelGrid( -- 2.50.1.windows.1 From d74a1069a03c5e184209a43e883b406786d8bbd0 Mon Sep 17 00:00:00 2001 From: Stiopa Koltsov Date: Wed, 24 Jun 2020 12:15:15 -0700 Subject: [PATCH 32/34] 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 --- java/BUCK | 2 ++ 1 file changed, 2 insertions(+) diff --git a/java/BUCK b/java/BUCK index d08cb37b..a658d7e9 100644 --- a/java/BUCK +++ b/java/BUCK @@ -1,3 +1,5 @@ +# BUILD FILE SYNTAX: PYTHON_DSL + # Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the -- 2.50.1.windows.1 From a93e5d63c9d26e378c07f3adfd86e16a4ca88143 Mon Sep 17 00:00:00 2001 From: Amir Shalem Date: Mon, 6 Jul 2020 03:41:19 -0700 Subject: [PATCH 33/34] 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 (https://github.com/facebook/yoga/commit/05f36a835a3a66b1b8affcdb036ec47117a8d28f) 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 --- java/jni/YGJNIVanilla.cpp | 2 +- .../com/facebook/yoga/YogaLoggerTest.java | 52 +++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/java/jni/YGJNIVanilla.cpp b/java/jni/YGJNIVanilla.cpp index 698ab561..65343821 100644 --- a/java/jni/YGJNIVanilla.cpp +++ b/java/jni/YGJNIVanilla.cpp @@ -196,7 +196,7 @@ static void jni_YGConfigSetLoggerJNI( delete context; YGConfigSetContext(config, nullptr); } - config->setLogger(nullptr); + YGConfigSetLogger(config, nullptr); } } diff --git a/java/tests/com/facebook/yoga/YogaLoggerTest.java b/java/tests/com/facebook/yoga/YogaLoggerTest.java index 17316f6e..f88409d6 100644 --- a/java/tests/com/facebook/yoga/YogaLoggerTest.java +++ b/java/tests/com/facebook/yoga/YogaLoggerTest.java @@ -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 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(); -- 2.50.1.windows.1 From 2e50059ad1b6049ec2df493e389c41438cec2b11 Mon Sep 17 00:00:00 2001 From: DingSoung <> Date: Fri, 10 Jul 2020 11:05:26 +0800 Subject: [PATCH 34/34] =?UTF-8?q?chore:=20=E6=B7=BB=E5=8A=A0Playground=20?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + Package.swift | 4 ++-- Playground.playground/Contents.swift | 26 +++++++++++++++++++++ Playground.playground/contents.xcplayground | 4 ++++ 4 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 Playground.playground/Contents.swift create mode 100644 Playground.playground/contents.xcplayground diff --git a/.gitignore b/.gitignore index bf158efc..eea230b0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .DS_STORE +*.xcodeproj /buck-cache/ /buck-out/ diff --git a/Package.swift b/Package.swift index 3aaa86be..11700f8f 100644 --- a/Package.swift +++ b/Package.swift @@ -13,7 +13,7 @@ let package = Package( products: [ .library( name: "YogaKit", - type: .static, + //type: .dynamic, targets: ["YogaKit"] ) ], @@ -22,7 +22,7 @@ let package = Package( .target( name: "YogaKit", path: "yoga", - exclude: [], + //exclude: [], sources: ["./"], publicHeadersPath: "include", cSettings: [ diff --git a/Playground.playground/Contents.swift b/Playground.playground/Contents.swift new file mode 100644 index 00000000..71440e08 --- /dev/null +++ b/Playground.playground/Contents.swift @@ -0,0 +1,26 @@ +//: A UIKit based Playground for presenting user interface + +import UIKit +import PlaygroundSupport +import YogaKit + +let globalConfig: YGConfigRef = YGConfigNew() +var node:YGNodeRef = YGNodeNewWithConfig(globalConfig) + + +class MyViewController : UIViewController { + override func loadView() { + let view = UIView() + view.backgroundColor = .white + + let label = UILabel() + label.frame = CGRect(x: 150, y: 200, width: 200, height: 20) + label.text = "Hello World!" + label.textColor = .black + + view.addSubview(label) + self.view = view + } +} +// Present the view controller in the Live View window +PlaygroundPage.current.liveView = MyViewController() diff --git a/Playground.playground/contents.xcplayground b/Playground.playground/contents.xcplayground new file mode 100644 index 00000000..3b151081 --- /dev/null +++ b/Playground.playground/contents.xcplayground @@ -0,0 +1,4 @@ + + + + \ No newline at end of file -- 2.50.1.windows.1