Skip to content

Commit

Permalink
Rename enums
Browse files Browse the repository at this point in the history
Differential Revision: D4244360

fbshipit-source-id: c9fcbdd231098c9ff230a6055676bbc7cbd11001
  • Loading branch information
Emil Sjolander authored and Martin Konicek committed Dec 12, 2016
1 parent 11a2b21 commit d414fdc
Show file tree
Hide file tree
Showing 55 changed files with 2,212 additions and 1,902 deletions.
32 changes: 16 additions & 16 deletions Examples/UIExplorer/UIExplorerUnitTests/RCTShadowViewTests.m
Expand Up @@ -29,7 +29,7 @@ - (void)setUp
[super setUp];

self.parentView = [self _shadowViewWithConfig:^(CSSNodeRef node) {
CSSNodeStyleSetFlexDirection(node, CSSFlexDirectionColumn);
CSSNodeStyleSetFlexDirection(node, YGFlexDirectionColumn);
CSSNodeStyleSetWidth(node, 440);
CSSNodeStyleSetHeight(node, 440);
}];
Expand All @@ -56,19 +56,19 @@ - (void)testApplyingLayoutRecursivelyToShadowView

RCTShadowView *centerView = [self _shadowViewWithConfig:^(CSSNodeRef node) {
CSSNodeStyleSetFlex(node, 2);
CSSNodeStyleSetMargin(node, CSSEdgeLeft, 10);
CSSNodeStyleSetMargin(node, CSSEdgeRight, 10);
CSSNodeStyleSetMargin(node, YGEdgeLeft, 10);
CSSNodeStyleSetMargin(node, YGEdgeRight, 10);
}];

RCTShadowView *rightView = [self _shadowViewWithConfig:^(CSSNodeRef node) {
CSSNodeStyleSetFlex(node, 1);
}];

RCTShadowView *mainView = [self _shadowViewWithConfig:^(CSSNodeRef node) {
CSSNodeStyleSetFlexDirection(node, CSSFlexDirectionRow);
CSSNodeStyleSetFlexDirection(node, YGFlexDirectionRow);
CSSNodeStyleSetFlex(node, 2);
CSSNodeStyleSetMargin(node, CSSEdgeTop, 10);
CSSNodeStyleSetMargin(node, CSSEdgeBottom, 10);
CSSNodeStyleSetMargin(node, YGEdgeTop, 10);
CSSNodeStyleSetMargin(node, YGEdgeBottom, 10);
}];

[mainView insertReactSubview:leftView atIndex:0];
Expand All @@ -83,10 +83,10 @@ - (void)testApplyingLayoutRecursivelyToShadowView
CSSNodeStyleSetFlex(node, 1);
}];

CSSNodeStyleSetPadding(self.parentView.cssNode, CSSEdgeLeft, 10);
CSSNodeStyleSetPadding(self.parentView.cssNode, CSSEdgeTop, 10);
CSSNodeStyleSetPadding(self.parentView.cssNode, CSSEdgeRight, 10);
CSSNodeStyleSetPadding(self.parentView.cssNode, CSSEdgeBottom, 10);
CSSNodeStyleSetPadding(self.parentView.cssNode, YGEdgeLeft, 10);
CSSNodeStyleSetPadding(self.parentView.cssNode, YGEdgeTop, 10);
CSSNodeStyleSetPadding(self.parentView.cssNode, YGEdgeRight, 10);
CSSNodeStyleSetPadding(self.parentView.cssNode, YGEdgeBottom, 10);

[self.parentView insertReactSubview:headerView atIndex:0];
[self.parentView insertReactSubview:mainView atIndex:1];
Expand Down Expand Up @@ -132,8 +132,8 @@ - (void)testAncestorCheck
- (void)testAssignsSuggestedWidthDimension
{
[self _withShadowViewWithStyle:^(CSSNodeRef node) {
CSSNodeStyleSetPosition(node, CSSEdgeLeft, 0);
CSSNodeStyleSetPosition(node, CSSEdgeTop, 0);
CSSNodeStyleSetPosition(node, YGEdgeLeft, 0);
CSSNodeStyleSetPosition(node, YGEdgeTop, 0);
CSSNodeStyleSetHeight(node, 10);
}
assertRelativeLayout:CGRectMake(0, 0, 3, 10)
Expand All @@ -143,8 +143,8 @@ - (void)testAssignsSuggestedWidthDimension
- (void)testAssignsSuggestedHeightDimension
{
[self _withShadowViewWithStyle:^(CSSNodeRef node) {
CSSNodeStyleSetPosition(node, CSSEdgeLeft, 0);
CSSNodeStyleSetPosition(node, CSSEdgeTop, 0);
CSSNodeStyleSetPosition(node, YGEdgeLeft, 0);
CSSNodeStyleSetPosition(node, YGEdgeTop, 0);
CSSNodeStyleSetWidth(node, 10);
}
assertRelativeLayout:CGRectMake(0, 0, 10, 4)
Expand All @@ -154,8 +154,8 @@ - (void)testAssignsSuggestedHeightDimension
- (void)testDoesNotOverrideDimensionStyleWithSuggestedDimensions
{
[self _withShadowViewWithStyle:^(CSSNodeRef node) {
CSSNodeStyleSetPosition(node, CSSEdgeLeft, 0);
CSSNodeStyleSetPosition(node, CSSEdgeTop, 0);
CSSNodeStyleSetPosition(node, YGEdgeLeft, 0);
CSSNodeStyleSetPosition(node, YGEdgeTop, 0);
CSSNodeStyleSetWidth(node, 10);
CSSNodeStyleSetHeight(node, 10);
}
Expand Down
14 changes: 7 additions & 7 deletions Libraries/Text/RCTShadowText.m
Expand Up @@ -39,7 +39,7 @@ @implementation RCTShadowText
CGFloat _effectiveLetterSpacing;
}

static CSSSize RCTMeasure(CSSNodeRef node, float width, CSSMeasureMode widthMode, float height, CSSMeasureMode heightMode)
static CSSSize RCTMeasure(CSSNodeRef node, float width, YGMeasureMode widthMode, float height, YGMeasureMode heightMode)
{
RCTShadowText *shadowText = (__bridge RCTShadowText *)CSSNodeGetContext(node);
NSTextStorage *textStorage = [shadowText buildTextStorageForWidth:width widthMode:widthMode];
Expand Down Expand Up @@ -114,7 +114,7 @@ - (void)contentSizeMultiplierDidChange:(NSNotification *)note


NSNumber *parentTag = [[self reactSuperview] reactTag];
NSTextStorage *textStorage = [self buildTextStorageForWidth:width widthMode:CSSMeasureModeExactly];
NSTextStorage *textStorage = [self buildTextStorageForWidth:width widthMode:YGMeasureModeExactly];
CGRect textFrame = [self calculateTextFrame:textStorage];
BOOL selectable = _selectable;
[applierBlocks addObject:^(NSDictionary<NSNumber *, UIView *> *viewRegistry) {
Expand Down Expand Up @@ -153,7 +153,7 @@ - (void)applyLayoutToChildren:(CSSNodeRef)node
absolutePosition:(CGPoint)absolutePosition
{
// Run layout on subviews.
NSTextStorage *textStorage = [self buildTextStorageForWidth:self.frame.size.width widthMode:CSSMeasureModeExactly];
NSTextStorage *textStorage = [self buildTextStorageForWidth:self.frame.size.width widthMode:YGMeasureModeExactly];
NSLayoutManager *layoutManager = textStorage.layoutManagers.firstObject;
NSTextContainer *textContainer = layoutManager.textContainers.firstObject;
NSRange glyphRange = [layoutManager glyphRangeForTextContainer:textContainer];
Expand Down Expand Up @@ -187,7 +187,7 @@ - (void)applyLayoutToChildren:(CSSNodeRef)node
}];
}

- (NSTextStorage *)buildTextStorageForWidth:(CGFloat)width widthMode:(CSSMeasureMode)widthMode
- (NSTextStorage *)buildTextStorageForWidth:(CGFloat)width widthMode:(YGMeasureMode)widthMode
{
if (_cachedTextStorage && width == _cachedTextStorageWidth && widthMode == _cachedTextStorageWidthMode) {
return _cachedTextStorage;
Expand All @@ -208,7 +208,7 @@ - (NSTextStorage *)buildTextStorageForWidth:(CGFloat)width widthMode:(CSSMeasure
}

textContainer.maximumNumberOfLines = _numberOfLines;
textContainer.size = (CGSize){widthMode == CSSMeasureModeUndefined ? CGFLOAT_MAX : width, CGFLOAT_MAX};
textContainer.size = (CGSize){widthMode == YGMeasureModeUndefined ? CGFLOAT_MAX : width, CGFLOAT_MAX};

[layoutManager addTextContainer:textContainer];
[layoutManager ensureLayoutForTextContainer:textContainer];
Expand Down Expand Up @@ -403,10 +403,10 @@ - (void)_setParagraphStyleOnAttributedString:(NSMutableAttributedString *)attrib
// We will climb up to the first node which style has been setted as non-inherit
if (newTextAlign == NSTextAlignmentRight || newTextAlign == NSTextAlignmentLeft) {
RCTShadowView *view = self;
while (view != nil && CSSNodeStyleGetDirection(view.cssNode) == CSSDirectionInherit) {
while (view != nil && CSSNodeStyleGetDirection(view.cssNode) == YGDirectionInherit) {
view = [view reactSuperview];
}
if (view != nil && CSSNodeStyleGetDirection(view.cssNode) == CSSDirectionRTL) {
if (view != nil && CSSNodeStyleGetDirection(view.cssNode) == YGDirectionRTL) {
if (newTextAlign == NSTextAlignmentRight) {
newTextAlign = NSTextAlignmentLeft;
} else if (newTextAlign == NSTextAlignmentLeft) {
Expand Down
2 changes: 1 addition & 1 deletion Libraries/Text/RCTTextManager.m
Expand Up @@ -35,7 +35,7 @@ static void collectDirtyNonTextDescendants(RCTShadowText *shadowView, NSMutableA

@interface RCTShadowText (Private)

- (NSTextStorage *)buildTextStorageForWidth:(CGFloat)width widthMode:(CSSMeasureMode)widthMode;
- (NSTextStorage *)buildTextStorageForWidth:(CGFloat)width widthMode:(YGMeasureMode)widthMode;

@end

Expand Down
12 changes: 6 additions & 6 deletions React/Base/RCTConvert.h
Expand Up @@ -109,13 +109,13 @@ typedef id NSPropertyList;
+ (NSPropertyList)NSPropertyList:(id)json;

typedef BOOL css_backface_visibility_t;
+ (CSSOverflow)CSSOverflow:(id)json;
+ (YGOverflow)YGOverflow:(id)json;
+ (css_backface_visibility_t)css_backface_visibility_t:(id)json;
+ (CSSFlexDirection)CSSFlexDirection:(id)json;
+ (CSSJustify)CSSJustify:(id)json;
+ (CSSAlign)CSSAlign:(id)json;
+ (CSSPositionType)CSSPositionType:(id)json;
+ (CSSWrap)CSSWrap:(id)json;
+ (YGFlexDirection)YGFlexDirection:(id)json;
+ (YGJustify)YGJustify:(id)json;
+ (YGAlign)YGAlign:(id)json;
+ (YGPositionType)YGPositionType:(id)json;
+ (YGWrap)YGWrap:(id)json;

+ (RCTPointerEvents)RCTPointerEvents:(id)json;
+ (RCTAnimationType)RCTAnimationType:(id)json;
Expand Down
76 changes: 38 additions & 38 deletions React/Base/RCTConvert.m
Expand Up @@ -614,44 +614,44 @@ + (NSPropertyList)NSPropertyList:(id)json
@"visible": @YES
}), YES, boolValue)

RCT_ENUM_CONVERTER(CSSOverflow, (@{
@"hidden": @(CSSOverflowHidden),
@"visible": @(CSSOverflowVisible),
@"scroll": @(CSSOverflowScroll),
}), CSSOverflowVisible, intValue)

RCT_ENUM_CONVERTER(CSSFlexDirection, (@{
@"row": @(CSSFlexDirectionRow),
@"row-reverse": @(CSSFlexDirectionRowReverse),
@"column": @(CSSFlexDirectionColumn),
@"column-reverse": @(CSSFlexDirectionColumnReverse)
}), CSSFlexDirectionColumn, intValue)

RCT_ENUM_CONVERTER(CSSJustify, (@{
@"flex-start": @(CSSJustifyFlexStart),
@"flex-end": @(CSSJustifyFlexEnd),
@"center": @(CSSJustifyCenter),
@"space-between": @(CSSJustifySpaceBetween),
@"space-around": @(CSSJustifySpaceAround)
}), CSSJustifyFlexStart, intValue)

RCT_ENUM_CONVERTER(CSSAlign, (@{
@"flex-start": @(CSSAlignFlexStart),
@"flex-end": @(CSSAlignFlexEnd),
@"center": @(CSSAlignCenter),
@"auto": @(CSSAlignAuto),
@"stretch": @(CSSAlignStretch)
}), CSSAlignFlexStart, intValue)

RCT_ENUM_CONVERTER(CSSPositionType, (@{
@"absolute": @(CSSPositionTypeAbsolute),
@"relative": @(CSSPositionTypeRelative)
}), CSSPositionTypeRelative, intValue)

RCT_ENUM_CONVERTER(CSSWrap, (@{
@"wrap": @(CSSWrapWrap),
@"nowrap": @(CSSWrapNoWrap)
}), CSSWrapNoWrap, intValue)
RCT_ENUM_CONVERTER(YGOverflow, (@{
@"hidden": @(YGOverflowHidden),
@"visible": @(YGOverflowVisible),
@"scroll": @(YGOverflowScroll),
}), YGOverflowVisible, intValue)

RCT_ENUM_CONVERTER(YGFlexDirection, (@{
@"row": @(YGFlexDirectionRow),
@"row-reverse": @(YGFlexDirectionRowReverse),
@"column": @(YGFlexDirectionColumn),
@"column-reverse": @(YGFlexDirectionColumnReverse)
}), YGFlexDirectionColumn, intValue)

RCT_ENUM_CONVERTER(YGJustify, (@{
@"flex-start": @(YGJustifyFlexStart),
@"flex-end": @(YGJustifyFlexEnd),
@"center": @(YGJustifyCenter),
@"space-between": @(YGJustifySpaceBetween),
@"space-around": @(YGJustifySpaceAround)
}), YGJustifyFlexStart, intValue)

RCT_ENUM_CONVERTER(YGAlign, (@{
@"flex-start": @(YGAlignFlexStart),
@"flex-end": @(YGAlignFlexEnd),
@"center": @(YGAlignCenter),
@"auto": @(YGAlignAuto),
@"stretch": @(YGAlignStretch)
}), YGAlignFlexStart, intValue)

RCT_ENUM_CONVERTER(YGPositionType, (@{
@"absolute": @(YGPositionTypeAbsolute),
@"relative": @(YGPositionTypeRelative)
}), YGPositionTypeRelative, intValue)

RCT_ENUM_CONVERTER(YGWrap, (@{
@"wrap": @(YGWrapWrap),
@"nowrap": @(YGWrapNoWrap)
}), YGWrapNoWrap, intValue)

RCT_ENUM_CONVERTER(RCTPointerEvents, (@{
@"none": @(RCTPointerEventsNone),
Expand Down
108 changes: 108 additions & 0 deletions React/CSSLayout/CSSEnums.h
@@ -0,0 +1,108 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

typedef enum YGFlexDirection {
YGFlexDirectionColumn,
YGFlexDirectionColumnReverse,
YGFlexDirectionRow,
YGFlexDirectionRowReverse,
YGFlexDirectionCount,
} YGFlexDirection;

typedef enum YGMeasureMode {
YGMeasureModeUndefined,
YGMeasureModeExactly,
YGMeasureModeAtMost,
YGMeasureModeCount,
} YGMeasureMode;

typedef enum YGPrintOptions {
YGPrintOptionsLayout = 1,
YGPrintOptionsStyle = 2,
YGPrintOptionsChildren = 4,
YGPrintOptionsCount,
} YGPrintOptions;

typedef enum YGEdge {
YGEdgeLeft,
YGEdgeTop,
YGEdgeRight,
YGEdgeBottom,
YGEdgeStart,
YGEdgeEnd,
YGEdgeHorizontal,
YGEdgeVertical,
YGEdgeAll,
YGEdgeCount,
} YGEdge;

typedef enum YGPositionType {
YGPositionTypeRelative,
YGPositionTypeAbsolute,
YGPositionTypeCount,
} YGPositionType;

typedef enum YGDimension {
YGDimensionWidth,
YGDimensionHeight,
YGDimensionCount,
} YGDimension;

typedef enum YGJustify {
YGJustifyFlexStart,
YGJustifyCenter,
YGJustifyFlexEnd,
YGJustifySpaceBetween,
YGJustifySpaceAround,
YGJustifyCount,
} YGJustify;

typedef enum YGDirection {
YGDirectionInherit,
YGDirectionLTR,
YGDirectionRTL,
YGDirectionCount,
} YGDirection;

typedef enum YGLogLevel {
YGLogLevelError,
YGLogLevelWarn,
YGLogLevelInfo,
YGLogLevelDebug,
YGLogLevelVerbose,
YGLogLevelCount,
} YGLogLevel;

typedef enum YGWrap {
YGWrapNoWrap,
YGWrapWrap,
YGWrapCount,
} YGWrap;

typedef enum YGOverflow {
YGOverflowVisible,
YGOverflowHidden,
YGOverflowScroll,
YGOverflowCount,
} YGOverflow;

typedef enum YGExperimentalFeature {
YGExperimentalFeatureRounding,
YGExperimentalFeatureWebFlexBasis,
YGExperimentalFeatureCount,
} YGExperimentalFeature;

typedef enum YGAlign {
YGAlignAuto,
YGAlignFlexStart,
YGAlignCenter,
YGAlignFlexEnd,
YGAlignStretch,
YGAlignCount,
} YGAlign;

0 comments on commit d414fdc

Please sign in to comment.