Remove YogaKit Integration (#4830)

Summary:
Pull Request resolved: https://github.com/facebook/flipper/pull/4830

YogaKit is a library which allows integrating Yoga layouts directly with UIKit. It is not used by higher level libraries like ComponentKit or React Native, but is used by a smattering of surfaces and shared components in Origami Studio and Instagram. See the following search for `YogaKit/UIView+Yoga.h`.

{F1026467213}

It is not really being developed anymore, and doesn't have much of a future, so I am deprecating it in OSS, to remove after the next OSS Yoga release. This means Flipper in OSS will not be able to rely on it.

Instead of special-casing for OSS vs not, this change removes the current YogaKit integration with the layout plugin, since it sounds like we are building a new layout plugin anyway, and I'm not aware of any new surfaces being built on top of YogaKit.

Removing Yoga as a dependency from Flipper should also allow us to fixup the current OSS Flipper build, along with a whole bunch of hacks RN's open source build currently does to produce a Yoga pod compatible with both RN and Flipper.

There are probably some OSS related lockfiles that can be updated after this, for things like the FlipperKit sample app. I did not do that as part of this change, since I don't know how healthy all of that infra is or how it integrates with the offline mirror used.

Reviewed By: passy

Differential Revision: D46664918

fbshipit-source-id: 9d4dd56aa4c7f55e97ac643aa6e4deb9375e582c
This commit is contained in:
Nick Gerleman
2023-06-13 11:11:08 -07:00
committed by Facebook GitHub Bot
parent ce4768116f
commit 6c43d39c20
3 changed files with 2 additions and 331 deletions

View File

@@ -1,37 +0,0 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <Foundation/Foundation.h>
#define APPLY_ENUM_TO_YOGA_PROPERTY(varName, enumName) \
^(NSString * newValue) { \
NSNumber* varName = \
[[enumName##EnumMap allKeysForObject:newValue] lastObject]; \
if (varName == nil) { \
return; \
} \
node.yoga.varName = (enumName)[varName unsignedIntegerValue]; \
}
#define APPLY_VALUE_TO_YGVALUE(varName) \
^(NSNumber * value) { \
YGValue newValue = node.yoga.varName; \
newValue.value = [value floatValue]; \
node.yoga.varName = newValue; \
}
#define APPLY_UNIT_TO_YGVALUE(varName, enumName) \
^(NSString * value) { \
NSNumber* varName = \
[[enumName##EnumMap allKeysForObject:value] lastObject]; \
if (varName == nil) { \
return; \
} \
YGValue newValue = node.yoga.varName; \
newValue.unit = (enumName)[varName unsignedIntegerValue]; \
node.yoga.varName = newValue; \
}

View File

@@ -14,29 +14,13 @@
#import <FlipperKitLayoutHelpers/SKHiddenWindow.h>
#import <FlipperKitLayoutHelpers/SKNamed.h>
#import <FlipperKitLayoutHelpers/SKObject.h>
#import <FlipperKitLayoutHelpers/SKYogaKitHelper.h>
#import <FlipperKitLayoutHelpers/UIColor+SKSonarValueCoder.h>
#import <YogaKit/UIView+Yoga.h>
@implementation SKViewDescriptor
static NSDictionary* YGDirectionEnumMap = nil;
static NSDictionary* YGFlexDirectionEnumMap = nil;
static NSDictionary* YGJustifyEnumMap = nil;
static NSDictionary* YGAlignEnumMap = nil;
static NSDictionary* YGPositionTypeEnumMap = nil;
static NSDictionary* YGWrapEnumMap = nil;
static NSDictionary* YGOverflowEnumMap = nil;
static NSDictionary* YGDisplayEnumMap = nil;
static NSDictionary* YGUnitEnumMap = nil;
- (instancetype)initWithDescriptorMapper:
(id<SKDescriptorMapperProtocol>)mapper {
if (self = [super initWithDescriptorMapper:mapper]) {
initEnumDictionaries();
}
return self;
return [super initWithDescriptorMapper:mapper];
}
- (NSString*)identifierForNode:(UIView*)node {
@@ -125,102 +109,6 @@ static NSDictionary* YGUnitEnumMap = nil;
@"shouldGroupAccessibilityChildren" : SKMutableObject(
@(node.shouldGroupAccessibilityChildren)),
}],
!node.isYogaEnabled
? nil
: [SKNamed
newWithName:@"YGLayout"
withValue:@{
@"direction" : SKMutableObject(
YGDirectionEnumMap[@(node.yoga.direction)]),
@"justifyContent" : SKMutableObject(
YGJustifyEnumMap[@(node.yoga.justifyContent)]),
@"aligns" : @{
@"alignContent" : SKMutableObject(
YGAlignEnumMap[@(node.yoga.alignContent)]),
@"alignItems" : SKMutableObject(
YGAlignEnumMap[@(node.yoga.alignItems)]),
@"alignSelf" : SKMutableObject(
YGAlignEnumMap[@(node.yoga.alignSelf)]),
},
@"position" : @{
@"type" : SKMutableObject(
YGPositionTypeEnumMap[@(node.yoga.position)]),
@"left" : SKYGValueObject(node.yoga.left),
@"top" : SKYGValueObject(node.yoga.top),
@"right" : SKYGValueObject(node.yoga.right),
@"bottom" : SKYGValueObject(node.yoga.bottom),
@"start" : SKYGValueObject(node.yoga.start),
@"end" : SKYGValueObject(node.yoga.end),
},
@"overflow" : SKMutableObject(
YGOverflowEnumMap[@(node.yoga.overflow)]),
@"display" : SKMutableObject(
YGDisplayEnumMap[@(node.yoga.display)]),
@"flex" : @{
@"flexDirection" :
SKMutableObject(YGFlexDirectionEnumMap[
@(node.yoga.flexDirection)]),
@"flexWrap" : SKMutableObject(
YGWrapEnumMap[@(node.yoga.flexWrap)]),
@"flexGrow" : SKMutableObject(@(node.yoga.flexGrow)),
@"flexShrink" :
SKMutableObject(@(node.yoga.flexShrink)),
@"flexBasis" : SKYGValueObject(node.yoga.flexBasis),
},
@"margin" : @{
@"left" : SKYGValueObject(node.yoga.marginLeft),
@"top" : SKYGValueObject(node.yoga.marginTop),
@"right" : SKYGValueObject(node.yoga.marginRight),
@"bottom" : SKYGValueObject(node.yoga.marginBottom),
@"start" : SKYGValueObject(node.yoga.marginStart),
@"end" : SKYGValueObject(node.yoga.marginEnd),
@"horizontal" :
SKYGValueObject(node.yoga.marginHorizontal),
@"vertical" :
SKYGValueObject(node.yoga.marginVertical),
@"all" : SKYGValueObject(node.yoga.margin),
},
@"padding" : @{
@"left" : SKYGValueObject(node.yoga.paddingLeft),
@"top" : SKYGValueObject(node.yoga.paddingTop),
@"right" : SKYGValueObject(node.yoga.paddingRight),
@"bottom" : SKYGValueObject(node.yoga.paddingBottom),
@"start" : SKYGValueObject(node.yoga.paddingStart),
@"end" : SKYGValueObject(node.yoga.paddingEnd),
@"horizontal" :
SKYGValueObject(node.yoga.paddingHorizontal),
@"vertical" :
SKYGValueObject(node.yoga.paddingVertical),
@"all" : SKYGValueObject(node.yoga.padding),
},
@"border" : @{
@"leftWidth" :
SKMutableObject(@(node.yoga.borderLeftWidth)),
@"topWidth" :
SKMutableObject(@(node.yoga.borderTopWidth)),
@"rightWidth" :
SKMutableObject(@(node.yoga.borderRightWidth)),
@"bottomWidth" :
SKMutableObject(@(node.yoga.borderBottomWidth)),
@"startWidth" :
SKMutableObject(@(node.yoga.borderStartWidth)),
@"endWidth" :
SKMutableObject(@(node.yoga.borderEndWidth)),
@"all" : SKMutableObject(@(node.yoga.borderWidth)),
},
@"dimensions" : @{
@"width" : SKYGValueObject(node.yoga.width),
@"height" : SKYGValueObject(node.yoga.height),
@"minWidth" : SKYGValueObject(node.yoga.minWidth),
@"minHeight" : SKYGValueObject(node.yoga.minHeight),
@"maxWidth" : SKYGValueObject(node.yoga.maxWidth),
@"maxHeight" : SKYGValueObject(node.yoga.maxHeight),
},
@"aspectRatio" :
SKMutableObject(@(node.yoga.aspectRatio)),
@"resolvedDirection" : SKObject(
YGDirectionEnumMap[@(node.yoga.resolvedDirection)]),
}],
nil];
}
@@ -290,109 +178,6 @@ static NSDictionary* YGUnitEnumMap = nil;
@"CALayer.masksToBounds": ^(NSNumber *value) {
node.layer.masksToBounds = [value boolValue];
},
// YGLayout
@"YGLayout.direction": APPLY_ENUM_TO_YOGA_PROPERTY(direction, YGDirection),
@"YGLayout.justifyContent": APPLY_ENUM_TO_YOGA_PROPERTY(justifyContent, YGJustify),
@"YGLayout.aligns.alignContent": APPLY_ENUM_TO_YOGA_PROPERTY(alignContent, YGAlign),
@"YGLayout.aligns.alignItems": APPLY_ENUM_TO_YOGA_PROPERTY(alignItems, YGAlign),
@"YGLayout.aligns.alignSelf": APPLY_ENUM_TO_YOGA_PROPERTY(alignSelf, YGAlign),
@"YGLayout.position.type": APPLY_ENUM_TO_YOGA_PROPERTY(position, YGPositionType),
@"YGLayout.position.left.value": APPLY_VALUE_TO_YGVALUE(left),
@"YGLayout.position.left.unit": APPLY_UNIT_TO_YGVALUE(left, YGUnit),
@"YGLayout.position.top.value": APPLY_VALUE_TO_YGVALUE(top),
@"YGLayout.position.top.unit": APPLY_UNIT_TO_YGVALUE(top, YGUnit),
@"YGLayout.position.right.value": APPLY_VALUE_TO_YGVALUE(right),
@"YGLayout.position.right.unit": APPLY_UNIT_TO_YGVALUE(right, YGUnit),
@"YGLayout.position.bottom.value": APPLY_VALUE_TO_YGVALUE(bottom),
@"YGLayout.position.bottom.unit": APPLY_UNIT_TO_YGVALUE(bottom, YGUnit),
@"YGLayout.position.start.value": APPLY_VALUE_TO_YGVALUE(start),
@"YGLayout.position.start.unit": APPLY_UNIT_TO_YGVALUE(start, YGUnit),
@"YGLayout.position.end.value": APPLY_VALUE_TO_YGVALUE(end),
@"YGLayout.position.end.unit": APPLY_UNIT_TO_YGVALUE(end, YGUnit),
@"YGLayout.overflow": APPLY_ENUM_TO_YOGA_PROPERTY(overflow, YGOverflow),
@"YGLayout.display": APPLY_ENUM_TO_YOGA_PROPERTY(display, YGDisplay),
@"YGLayout.flex.flexDirection": APPLY_ENUM_TO_YOGA_PROPERTY(flexDirection, YGFlexDirection),
@"YGLayout.flex.flexWrap": APPLY_ENUM_TO_YOGA_PROPERTY(flexWrap, YGWrap),
@"YGLayout.flex.flexGrow": ^(NSNumber *value) {
node.yoga.flexGrow = [value floatValue];
},
@"YGLayout.flex.flexShrink": ^(NSNumber *value) {
node.yoga.flexShrink = [value floatValue];
},
@"YGLayout.flex.flexBasis.value": APPLY_VALUE_TO_YGVALUE(flexBasis),
@"YGLayout.flex.flexBasis.unit": APPLY_UNIT_TO_YGVALUE(flexBasis, YGUnit),
@"YGLayout.margin.left.value": APPLY_VALUE_TO_YGVALUE(marginLeft),
@"YGLayout.margin.left.unit": APPLY_UNIT_TO_YGVALUE(marginLeft, YGUnit),
@"YGLayout.margin.top.value": APPLY_VALUE_TO_YGVALUE(marginTop),
@"YGLayout.margin.top.unit": APPLY_UNIT_TO_YGVALUE(marginTop, YGUnit),
@"YGLayout.margin.right.value": APPLY_VALUE_TO_YGVALUE(marginRight),
@"YGLayout.margin.right.unit": APPLY_UNIT_TO_YGVALUE(marginRight, YGUnit),
@"YGLayout.margin.bottom.value": APPLY_VALUE_TO_YGVALUE(marginBottom),
@"YGLayout.margin.bottom.unit": APPLY_UNIT_TO_YGVALUE(marginBottom, YGUnit),
@"YGLayout.margin.start.value": APPLY_VALUE_TO_YGVALUE(marginStart),
@"YGLayout.margin.start.unit": APPLY_UNIT_TO_YGVALUE(marginStart, YGUnit),
@"YGLayout.margin.end.value": APPLY_VALUE_TO_YGVALUE(marginEnd),
@"YGLayout.margin.end.unit": APPLY_UNIT_TO_YGVALUE(marginEnd, YGUnit),
@"YGLayout.margin.horizontal.value": APPLY_VALUE_TO_YGVALUE(marginHorizontal),
@"YGLayout.margin.horizontal.unit": APPLY_UNIT_TO_YGVALUE(marginHorizontal, YGUnit),
@"YGLayout.margin.vertical.value": APPLY_VALUE_TO_YGVALUE(marginVertical),
@"YGLayout.margin.vertical.unit": APPLY_UNIT_TO_YGVALUE(marginVertical, YGUnit),
@"YGLayout.margin.all.value": APPLY_VALUE_TO_YGVALUE(margin),
@"YGLayout.margin.all.unit": APPLY_UNIT_TO_YGVALUE(margin, YGUnit),
@"YGLayout.padding.left.value": APPLY_VALUE_TO_YGVALUE(paddingLeft),
@"YGLayout.padding.left.unit": APPLY_UNIT_TO_YGVALUE(paddingLeft, YGUnit),
@"YGLayout.padding.top.value": APPLY_VALUE_TO_YGVALUE(paddingTop),
@"YGLayout.padding.top.unit": APPLY_UNIT_TO_YGVALUE(paddingTop, YGUnit),
@"YGLayout.padding.right.value": APPLY_VALUE_TO_YGVALUE(paddingRight),
@"YGLayout.padding.right.unit": APPLY_UNIT_TO_YGVALUE(paddingRight, YGUnit),
@"YGLayout.padding.bottom.value": APPLY_VALUE_TO_YGVALUE(paddingBottom),
@"YGLayout.padding.bottom.unit": APPLY_UNIT_TO_YGVALUE(paddingBottom, YGUnit),
@"YGLayout.padding.start.value": APPLY_VALUE_TO_YGVALUE(paddingStart),
@"YGLayout.padding.start.unit": APPLY_UNIT_TO_YGVALUE(paddingStart, YGUnit),
@"YGLayout.padding.end.value": APPLY_VALUE_TO_YGVALUE(paddingEnd),
@"YGLayout.padding.end.unit": APPLY_UNIT_TO_YGVALUE(paddingEnd, YGUnit),
@"YGLayout.padding.horizontal.value": APPLY_VALUE_TO_YGVALUE(paddingHorizontal),
@"YGLayout.padding.horizontal.unit": APPLY_UNIT_TO_YGVALUE(paddingHorizontal, YGUnit),
@"YGLayout.padding.vertical.value": APPLY_VALUE_TO_YGVALUE(paddingVertical),
@"YGLayout.padding.vertical.unit": APPLY_UNIT_TO_YGVALUE(paddingVertical, YGUnit),
@"YGLayout.padding.all.value": APPLY_VALUE_TO_YGVALUE(padding),
@"YGLayout.padding.all.unit": APPLY_UNIT_TO_YGVALUE(padding, YGUnit),
@"YGLayout.border.leftWidth": ^(NSNumber *value) {
node.yoga.borderLeftWidth = [value floatValue];
},
@"YGLayout.border.topWidth": ^(NSNumber *value) {
node.yoga.borderTopWidth = [value floatValue];
},
@"YGLayout.border.rightWidth": ^(NSNumber *value) {
node.yoga.borderRightWidth = [value floatValue];
},
@"YGLayout.border.bottomWidth": ^(NSNumber *value) {
node.yoga.borderBottomWidth = [value floatValue];
},
@"YGLayout.border.startWidth": ^(NSNumber *value) {
node.yoga.borderStartWidth = [value floatValue];
},
@"YGLayout.border.endWidth": ^(NSNumber *value) {
node.yoga.borderEndWidth = [value floatValue];
},
@"YGLayout.border.all": ^(NSNumber *value) {
node.yoga.borderWidth = [value floatValue];
},
@"YGLayout.dimensions.width.value": APPLY_VALUE_TO_YGVALUE(width),
@"YGLayout.dimensions.width.unit": APPLY_UNIT_TO_YGVALUE(width, YGUnit),
@"YGLayout.dimensions.height.value": APPLY_VALUE_TO_YGVALUE(height),
@"YGLayout.dimensions.height.unit": APPLY_UNIT_TO_YGVALUE(height, YGUnit),
@"YGLayout.dimensions.minWidth.value": APPLY_VALUE_TO_YGVALUE(minWidth),
@"YGLayout.dimensions.minWidth.unit": APPLY_UNIT_TO_YGVALUE(minWidth, YGUnit),
@"YGLayout.dimensions.minHeight.value": APPLY_VALUE_TO_YGVALUE(minHeight),
@"YGLayout.dimensions.minHeight.unit": APPLY_UNIT_TO_YGVALUE(minHeight, YGUnit),
@"YGLayout.dimensions.maxWidth.value": APPLY_VALUE_TO_YGVALUE(maxWidth),
@"YGLayout.dimensions.maxWidth.unit": APPLY_UNIT_TO_YGVALUE(maxWidth, YGUnit),
@"YGLayout.dimensions.maxHeight.value": APPLY_VALUE_TO_YGVALUE(maxHeight),
@"YGLayout.dimensions.maxHeight.unit": APPLY_UNIT_TO_YGVALUE(maxHeight, YGUnit),
@"YGLayout.aspectRatio": ^(NSNumber *value) {
node.yoga.aspectRatio = [value floatValue];
},
// Accessibility
@"Accessibility.isAccessibilityElement": ^(NSNumber *value) {
node.isAccessibilityElement = [value boolValue];
@@ -544,79 +329,6 @@ return dataMutations;
}
}
static void initEnumDictionaries() {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
YGDirectionEnumMap = @{
@(YGDirectionInherit) : @"inherit",
@(YGDirectionLTR) : @"LTR",
@(YGDirectionRTL) : @"RTL",
};
YGFlexDirectionEnumMap = @{
@(YGFlexDirectionColumn) : @"column",
@(YGFlexDirectionColumnReverse) : @"column-reverse",
@(YGFlexDirectionRow) : @"row",
@(YGFlexDirectionRowReverse) : @"row-reverse",
};
YGJustifyEnumMap = @{
@(YGJustifyFlexStart) : @"flex-start",
@(YGJustifyCenter) : @"center",
@(YGJustifyFlexEnd) : @"flex-end",
@(YGJustifySpaceBetween) : @"space-between",
@(YGJustifySpaceAround) : @"space-around",
};
YGAlignEnumMap = @{
@(YGAlignAuto) : @"auto",
@(YGAlignFlexStart) : @"flex-start",
@(YGAlignCenter) : @"end",
@(YGAlignFlexEnd) : @"flex-end",
@(YGAlignStretch) : @"stretch",
@(YGAlignBaseline) : @"baseline",
@(YGAlignSpaceBetween) : @"space-between",
@(YGAlignSpaceAround) : @"space-around",
};
YGPositionTypeEnumMap = @{
@(YGPositionTypeRelative) : @"relative",
@(YGPositionTypeAbsolute) : @"absolute",
};
YGWrapEnumMap = @{
@(YGWrapNoWrap) : @"no-wrap",
@(YGWrapWrap) : @"wrap",
@(YGWrapWrapReverse) : @"wrap-reverse",
};
YGOverflowEnumMap = @{
@(YGOverflowVisible) : @"visible",
@(YGOverflowHidden) : @"hidden",
@(YGOverflowScroll) : @"scroll",
};
YGDisplayEnumMap = @{
@(YGDisplayFlex) : @"flex",
@(YGDisplayNone) : @"none",
};
YGUnitEnumMap = @{
@(YGUnitUndefined) : @"undefined",
@(YGUnitPoint) : @"point",
@(YGUnitPercent) : @"percent",
@(YGUnitAuto) : @"auto",
};
});
}
static NSDictionary* SKYGValueObject(YGValue value) {
return @{
@"value" : SKMutableObject(@(value.value)),
@"unit" : SKMutableObject(YGUnitEnumMap[@(value.unit)]),
};
}
/*
Takes the originalTraits, and set all bits from toggleTraits to the toggleValue
e.g. originalTraits = UIAccessibilityTraitButton | UIAccessibilityTraitSelected