mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-03-29 07:48:17 +08:00
CamelCase
Reviewed By: majak Differential Revision: D3576069 fbshipit-source-id: cecda2cdb67f2f66ac92e336068d58731ccdb101
This commit is contained in:
committed by
Facebook Github Bot 2
parent
b7bf24bc7f
commit
1aa7ad0ab8
@@ -28,8 +28,8 @@
|
||||
{
|
||||
[super setUp];
|
||||
|
||||
self.parentView = [self _shadowViewWithStyle:^(css_style_t *style) {
|
||||
style->flex_direction = CSS_FLEX_DIRECTION_COLUMN;
|
||||
self.parentView = [self _shadowViewWithStyle:^(CSSStyle *style) {
|
||||
style->flexDirection = CSSFlexDirectionColumn;
|
||||
style->dimensions[0] = 440;
|
||||
style->dimensions[1] = 440;
|
||||
}];
|
||||
@@ -50,22 +50,22 @@
|
||||
//
|
||||
- (void)testApplyingLayoutRecursivelyToShadowView
|
||||
{
|
||||
RCTShadowView *leftView = [self _shadowViewWithStyle:^(css_style_t *style) {
|
||||
RCTShadowView *leftView = [self _shadowViewWithStyle:^(CSSStyle *style) {
|
||||
style->flex = 1;
|
||||
}];
|
||||
|
||||
RCTShadowView *centerView = [self _shadowViewWithStyle:^(css_style_t *style) {
|
||||
RCTShadowView *centerView = [self _shadowViewWithStyle:^(CSSStyle *style) {
|
||||
style->flex = 2;
|
||||
style->margin[0] = 10;
|
||||
style->margin[2] = 10;
|
||||
}];
|
||||
|
||||
RCTShadowView *rightView = [self _shadowViewWithStyle:^(css_style_t *style) {
|
||||
RCTShadowView *rightView = [self _shadowViewWithStyle:^(CSSStyle *style) {
|
||||
style->flex = 1;
|
||||
}];
|
||||
|
||||
RCTShadowView *mainView = [self _shadowViewWithStyle:^(css_style_t *style) {
|
||||
style->flex_direction = CSS_FLEX_DIRECTION_ROW;
|
||||
RCTShadowView *mainView = [self _shadowViewWithStyle:^(CSSStyle *style) {
|
||||
style->flexDirection = CSSFlexDirectionRow;
|
||||
style->flex = 2;
|
||||
style->margin[1] = 10;
|
||||
style->margin[3] = 10;
|
||||
@@ -75,11 +75,11 @@
|
||||
[mainView insertReactSubview:centerView atIndex:1];
|
||||
[mainView insertReactSubview:rightView atIndex:2];
|
||||
|
||||
RCTShadowView *headerView = [self _shadowViewWithStyle:^(css_style_t *style) {
|
||||
RCTShadowView *headerView = [self _shadowViewWithStyle:^(CSSStyle *style) {
|
||||
style->flex = 1;
|
||||
}];
|
||||
|
||||
RCTShadowView *footerView = [self _shadowViewWithStyle:^(css_style_t *style) {
|
||||
RCTShadowView *footerView = [self _shadowViewWithStyle:^(CSSStyle *style) {
|
||||
style->flex = 1;
|
||||
}];
|
||||
|
||||
@@ -108,10 +108,10 @@
|
||||
|
||||
- (void)testAssignsSuggestedWidthDimension
|
||||
{
|
||||
[self _withShadowViewWithStyle:^(css_style_t *style) {
|
||||
style->position[CSS_LEFT] = 0;
|
||||
style->position[CSS_TOP] = 0;
|
||||
style->dimensions[CSS_HEIGHT] = 10;
|
||||
[self _withShadowViewWithStyle:^(CSSStyle *style) {
|
||||
style->position[CSSPositionLeft] = 0;
|
||||
style->position[CSSPositionTop] = 0;
|
||||
style->dimensions[CSSDimensionHeight] = 10;
|
||||
}
|
||||
assertRelativeLayout:CGRectMake(0, 0, 3, 10)
|
||||
withIntrinsicContentSize:CGSizeMake(3, UIViewNoIntrinsicMetric)];
|
||||
@@ -119,10 +119,10 @@
|
||||
|
||||
- (void)testAssignsSuggestedHeightDimension
|
||||
{
|
||||
[self _withShadowViewWithStyle:^(css_style_t *style) {
|
||||
style->position[CSS_LEFT] = 0;
|
||||
style->position[CSS_TOP] = 0;
|
||||
style->dimensions[CSS_WIDTH] = 10;
|
||||
[self _withShadowViewWithStyle:^(CSSStyle *style) {
|
||||
style->position[CSSPositionLeft] = 0;
|
||||
style->position[CSSPositionTop] = 0;
|
||||
style->dimensions[CSSDimensionWidth] = 10;
|
||||
}
|
||||
assertRelativeLayout:CGRectMake(0, 0, 10, 4)
|
||||
withIntrinsicContentSize:CGSizeMake(UIViewNoIntrinsicMetric, 4)];
|
||||
@@ -130,11 +130,11 @@
|
||||
|
||||
- (void)testDoesNotOverrideDimensionStyleWithSuggestedDimensions
|
||||
{
|
||||
[self _withShadowViewWithStyle:^(css_style_t *style) {
|
||||
style->position[CSS_LEFT] = 0;
|
||||
style->position[CSS_TOP] = 0;
|
||||
style->dimensions[CSS_WIDTH] = 10;
|
||||
style->dimensions[CSS_HEIGHT] = 10;
|
||||
[self _withShadowViewWithStyle:^(CSSStyle *style) {
|
||||
style->position[CSSPositionLeft] = 0;
|
||||
style->position[CSSPositionTop] = 0;
|
||||
style->dimensions[CSSDimensionWidth] = 10;
|
||||
style->dimensions[CSSDimensionHeight] = 10;
|
||||
}
|
||||
assertRelativeLayout:CGRectMake(0, 0, 10, 10)
|
||||
withIntrinsicContentSize:CGSizeMake(3, 4)];
|
||||
@@ -142,16 +142,16 @@
|
||||
|
||||
- (void)testDoesNotAssignSuggestedDimensionsWhenStyledWithFlexAttribute
|
||||
{
|
||||
float parentWidth = self.parentView.cssNode->style.dimensions[CSS_WIDTH];
|
||||
float parentHeight = self.parentView.cssNode->style.dimensions[CSS_HEIGHT];
|
||||
[self _withShadowViewWithStyle:^(css_style_t *style) {
|
||||
float parentWidth = self.parentView.cssNode->style.dimensions[CSSDimensionWidth];
|
||||
float parentHeight = self.parentView.cssNode->style.dimensions[CSSDimensionHeight];
|
||||
[self _withShadowViewWithStyle:^(CSSStyle *style) {
|
||||
style->flex = 1;
|
||||
}
|
||||
assertRelativeLayout:CGRectMake(0, 0, parentWidth, parentHeight)
|
||||
withIntrinsicContentSize:CGSizeMake(3, 4)];
|
||||
}
|
||||
|
||||
- (void)_withShadowViewWithStyle:(void(^)(css_style_t *style))styleBlock
|
||||
- (void)_withShadowViewWithStyle:(void(^)(CSSStyle *style))styleBlock
|
||||
assertRelativeLayout:(CGRect)expectedRect
|
||||
withIntrinsicContentSize:(CGSize)contentSize
|
||||
{
|
||||
@@ -166,11 +166,11 @@
|
||||
NSStringFromCGRect(actualRect));
|
||||
}
|
||||
|
||||
- (RCTRootShadowView *)_shadowViewWithStyle:(void(^)(css_style_t *style))styleBlock
|
||||
- (RCTRootShadowView *)_shadowViewWithStyle:(void(^)(CSSStyle *style))styleBlock
|
||||
{
|
||||
RCTRootShadowView *shadowView = [RCTRootShadowView new];
|
||||
|
||||
css_style_t style = shadowView.cssNode->style;
|
||||
CSSStyle style = shadowView.cssNode->style;
|
||||
styleBlock(&style);
|
||||
shadowView.cssNode->style = style;
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ NSString *const RCTReactTagAttributeName = @"ReactTagAttributeName";
|
||||
CGFloat _effectiveLetterSpacing;
|
||||
}
|
||||
|
||||
static css_dim_t RCTMeasure(void *context, float width, css_measure_mode_t widthMode, float height, css_measure_mode_t heightMode)
|
||||
static CSSMeasureResult RCTMeasure(void *context, float width, CSSMeasureMode widthMode, float height, CSSMeasureMode heightMode)
|
||||
{
|
||||
RCTShadowText *shadowText = (__bridge RCTShadowText *)context;
|
||||
NSTextStorage *textStorage = [shadowText buildTextStorageForWidth:width widthMode:widthMode];
|
||||
@@ -41,12 +41,12 @@ static css_dim_t RCTMeasure(void *context, float width, css_measure_mode_t width
|
||||
NSTextContainer *textContainer = layoutManager.textContainers.firstObject;
|
||||
CGSize computedSize = [layoutManager usedRectForTextContainer:textContainer].size;
|
||||
|
||||
css_dim_t result;
|
||||
result.dimensions[CSS_WIDTH] = RCTCeilPixelValue(computedSize.width);
|
||||
CSSMeasureResult result;
|
||||
result.dimensions[CSSDimensionWidth] = RCTCeilPixelValue(computedSize.width);
|
||||
if (shadowText->_effectiveLetterSpacing < 0) {
|
||||
result.dimensions[CSS_WIDTH] -= shadowText->_effectiveLetterSpacing;
|
||||
result.dimensions[CSSDimensionWidth] -= shadowText->_effectiveLetterSpacing;
|
||||
}
|
||||
result.dimensions[CSS_HEIGHT] = RCTCeilPixelValue(computedSize.height);
|
||||
result.dimensions[CSSDimensionHeight] = RCTCeilPixelValue(computedSize.height);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ static css_dim_t RCTMeasure(void *context, float width, css_measure_mode_t width
|
||||
CGFloat width = self.frame.size.width - (padding.left + padding.right);
|
||||
|
||||
NSNumber *parentTag = [[self reactSuperview] reactTag];
|
||||
NSTextStorage *textStorage = [self buildTextStorageForWidth:width widthMode:CSS_MEASURE_MODE_EXACTLY];
|
||||
NSTextStorage *textStorage = [self buildTextStorageForWidth:width widthMode:CSSMeasureModeExactly];
|
||||
[applierBlocks addObject:^(NSDictionary<NSNumber *, UIView *> *viewRegistry) {
|
||||
RCTText *view = (RCTText *)viewRegistry[self.reactTag];
|
||||
view.textStorage = textStorage;
|
||||
@@ -128,7 +128,7 @@ static css_dim_t RCTMeasure(void *context, float width, css_measure_mode_t width
|
||||
return parentProperties;
|
||||
}
|
||||
|
||||
- (void)applyLayoutNode:(css_node_t *)node
|
||||
- (void)applyLayoutNode:(CSSNode *)node
|
||||
viewsWithNewFrame:(NSMutableSet<RCTShadowView *> *)viewsWithNewFrame
|
||||
absolutePosition:(CGPoint)absolutePosition
|
||||
{
|
||||
@@ -136,21 +136,21 @@ static css_dim_t RCTMeasure(void *context, float width, css_measure_mode_t width
|
||||
[self dirtyPropagation];
|
||||
}
|
||||
|
||||
- (void)applyLayoutToChildren:(css_node_t *)node
|
||||
- (void)applyLayoutToChildren:(CSSNode *)node
|
||||
viewsWithNewFrame:(NSMutableSet<RCTShadowView *> *)viewsWithNewFrame
|
||||
absolutePosition:(CGPoint)absolutePosition
|
||||
{
|
||||
// Run layout on subviews.
|
||||
NSTextStorage *textStorage = [self buildTextStorageForWidth:self.frame.size.width widthMode:CSS_MEASURE_MODE_EXACTLY];
|
||||
NSTextStorage *textStorage = [self buildTextStorageForWidth:self.frame.size.width widthMode:CSSMeasureModeExactly];
|
||||
NSLayoutManager *layoutManager = textStorage.layoutManagers.firstObject;
|
||||
NSTextContainer *textContainer = layoutManager.textContainers.firstObject;
|
||||
NSRange glyphRange = [layoutManager glyphRangeForTextContainer:textContainer];
|
||||
NSRange characterRange = [layoutManager characterRangeForGlyphRange:glyphRange actualGlyphRange:NULL];
|
||||
[layoutManager.textStorage enumerateAttribute:RCTShadowViewAttributeName inRange:characterRange options:0 usingBlock:^(RCTShadowView *child, NSRange range, BOOL *_) {
|
||||
if (child) {
|
||||
css_node_t *childNode = child.cssNode;
|
||||
float width = childNode->style.dimensions[CSS_WIDTH];
|
||||
float height = childNode->style.dimensions[CSS_HEIGHT];
|
||||
CSSNode *childNode = child.cssNode;
|
||||
float width = childNode->style.dimensions[CSSDimensionWidth];
|
||||
float height = childNode->style.dimensions[CSSDimensionHeight];
|
||||
if (isUndefined(width) || isUndefined(height)) {
|
||||
RCTLogError(@"Views nested within a <Text> must have a width and height");
|
||||
}
|
||||
@@ -175,7 +175,7 @@ static css_dim_t RCTMeasure(void *context, float width, css_measure_mode_t width
|
||||
}];
|
||||
}
|
||||
|
||||
- (NSTextStorage *)buildTextStorageForWidth:(CGFloat)width widthMode:(css_measure_mode_t)widthMode
|
||||
- (NSTextStorage *)buildTextStorageForWidth:(CGFloat)width widthMode:(CSSMeasureMode)widthMode
|
||||
{
|
||||
if (_cachedTextStorage && width == _cachedTextStorageWidth && widthMode == _cachedTextStorageWidthMode) {
|
||||
return _cachedTextStorage;
|
||||
@@ -196,7 +196,7 @@ static css_dim_t RCTMeasure(void *context, float width, css_measure_mode_t width
|
||||
}
|
||||
|
||||
textContainer.maximumNumberOfLines = _numberOfLines;
|
||||
textContainer.size = (CGSize){widthMode == CSS_MEASURE_MODE_UNDEFINED ? CGFLOAT_MAX : width, CGFLOAT_MAX};
|
||||
textContainer.size = (CGSize){widthMode == CSSMeasureModeUndefined ? CGFLOAT_MAX : width, CGFLOAT_MAX};
|
||||
|
||||
[layoutManager addTextContainer:textContainer];
|
||||
[layoutManager ensureLayoutForTextContainer:textContainer];
|
||||
@@ -291,8 +291,8 @@ static css_dim_t RCTMeasure(void *context, float width, css_measure_mode_t width
|
||||
[attributedString appendAttributedString:[[NSAttributedString alloc] initWithString:shadowRawText.text ?: @""]];
|
||||
[child setTextComputed];
|
||||
} else {
|
||||
float width = child.cssNode->style.dimensions[CSS_WIDTH];
|
||||
float height = child.cssNode->style.dimensions[CSS_HEIGHT];
|
||||
float width = child.cssNode->style.dimensions[CSSDimensionWidth];
|
||||
float height = child.cssNode->style.dimensions[CSSDimensionHeight];
|
||||
if (isUndefined(width) || isUndefined(height)) {
|
||||
RCTLogError(@"Views nested within a <Text> must have a width and height");
|
||||
}
|
||||
@@ -384,10 +384,10 @@ static css_dim_t RCTMeasure(void *context, float width, css_measure_mode_t width
|
||||
// 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 && view.cssNode->style.direction == CSS_DIRECTION_INHERIT) {
|
||||
while (view != nil && view.cssNode->style.direction == CSSDirectionInherit) {
|
||||
view = [view reactSuperview];
|
||||
}
|
||||
if (view != nil && view.cssNode->style.direction == CSS_DIRECTION_RTL) {
|
||||
if (view != nil && view.cssNode->style.direction == CSSDirectionRTL) {
|
||||
if (newTextAlign == NSTextAlignmentRight) {
|
||||
newTextAlign = NSTextAlignmentLeft;
|
||||
} else if (newTextAlign == NSTextAlignmentLeft) {
|
||||
|
||||
@@ -34,7 +34,7 @@ static void collectDirtyNonTextDescendants(RCTShadowText *shadowView, NSMutableA
|
||||
|
||||
@interface RCTShadowText (Private)
|
||||
|
||||
- (NSTextStorage *)buildTextStorageForWidth:(CGFloat)width widthMode:(css_measure_mode_t)widthMode;
|
||||
- (NSTextStorage *)buildTextStorageForWidth:(CGFloat)width widthMode:(CSSMeasureMode)widthMode;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@@ -116,11 +116,11 @@ typedef id NSPropertyList;
|
||||
typedef BOOL css_clip_t, css_backface_visibility_t;
|
||||
+ (css_clip_t)css_clip_t:(id)json;
|
||||
+ (css_backface_visibility_t)css_backface_visibility_t:(id)json;
|
||||
+ (css_flex_direction_t)css_flex_direction_t:(id)json;
|
||||
+ (css_justify_t)css_justify_t:(id)json;
|
||||
+ (css_align_t)css_align_t:(id)json;
|
||||
+ (css_position_type_t)css_position_type_t:(id)json;
|
||||
+ (css_wrap_type_t)css_wrap_type_t:(id)json;
|
||||
+ (CSSFlexDirection)CSSFlexDirection:(id)json;
|
||||
+ (CSSJustify)CSSJustify:(id)json;
|
||||
+ (CSSAlign)CSSAlign:(id)json;
|
||||
+ (CSSPositionType)CSSPositionType:(id)json;
|
||||
+ (CSSWrapType)CSSWrapType:(id)json;
|
||||
|
||||
+ (RCTPointerEvents)RCTPointerEvents:(id)json;
|
||||
+ (RCTAnimationType)RCTAnimationType:(id)json;
|
||||
|
||||
@@ -822,38 +822,38 @@ RCT_ENUM_CONVERTER(css_clip_t, (@{
|
||||
@"visible": @NO
|
||||
}), NO, boolValue)
|
||||
|
||||
RCT_ENUM_CONVERTER(css_flex_direction_t, (@{
|
||||
@"row": @(CSS_FLEX_DIRECTION_ROW),
|
||||
@"row-reverse": @(CSS_FLEX_DIRECTION_ROW_REVERSE),
|
||||
@"column": @(CSS_FLEX_DIRECTION_COLUMN),
|
||||
@"column-reverse": @(CSS_FLEX_DIRECTION_COLUMN_REVERSE)
|
||||
}), CSS_FLEX_DIRECTION_COLUMN, intValue)
|
||||
RCT_ENUM_CONVERTER(CSSFlexDirection, (@{
|
||||
@"row": @(CSSFlexDirectionRow),
|
||||
@"row-reverse": @(CSSFlexDirectionRowReverse),
|
||||
@"column": @(CSSFlexDirectionColumn),
|
||||
@"column-reverse": @(CSSFlexDirectionColumnReverse)
|
||||
}), CSSFlexDirectionColumn, intValue)
|
||||
|
||||
RCT_ENUM_CONVERTER(css_justify_t, (@{
|
||||
@"flex-start": @(CSS_JUSTIFY_FLEX_START),
|
||||
@"flex-end": @(CSS_JUSTIFY_FLEX_END),
|
||||
@"center": @(CSS_JUSTIFY_CENTER),
|
||||
@"space-between": @(CSS_JUSTIFY_SPACE_BETWEEN),
|
||||
@"space-around": @(CSS_JUSTIFY_SPACE_AROUND)
|
||||
}), CSS_JUSTIFY_FLEX_START, intValue)
|
||||
RCT_ENUM_CONVERTER(CSSJustify, (@{
|
||||
@"flex-start": @(CSSJustifyFlexStart),
|
||||
@"flex-end": @(CSSJustifyFlexEnd),
|
||||
@"center": @(CSSJustifyCenter),
|
||||
@"space-between": @(CSSJustifySpaceBetween),
|
||||
@"space-around": @(CSSJustifySpaceAround)
|
||||
}), CSSJustifyFlexStart, intValue)
|
||||
|
||||
RCT_ENUM_CONVERTER(css_align_t, (@{
|
||||
@"flex-start": @(CSS_ALIGN_FLEX_START),
|
||||
@"flex-end": @(CSS_ALIGN_FLEX_END),
|
||||
@"center": @(CSS_ALIGN_CENTER),
|
||||
@"auto": @(CSS_ALIGN_AUTO),
|
||||
@"stretch": @(CSS_ALIGN_STRETCH)
|
||||
}), CSS_ALIGN_FLEX_START, intValue)
|
||||
RCT_ENUM_CONVERTER(CSSAlign, (@{
|
||||
@"flex-start": @(CSSAlignFlexStart),
|
||||
@"flex-end": @(CSSAlignFlexEnd),
|
||||
@"center": @(CSSAlignCenter),
|
||||
@"auto": @(CSSAlignAuto),
|
||||
@"stretch": @(CSSAlignStretch)
|
||||
}), CSSAlignFlexStart, intValue)
|
||||
|
||||
RCT_ENUM_CONVERTER(css_position_type_t, (@{
|
||||
@"absolute": @(CSS_POSITION_ABSOLUTE),
|
||||
@"relative": @(CSS_POSITION_RELATIVE)
|
||||
}), CSS_POSITION_RELATIVE, intValue)
|
||||
RCT_ENUM_CONVERTER(CSSPositionType, (@{
|
||||
@"absolute": @(CSSPositionTypeAbsolute),
|
||||
@"relative": @(CSSPositionTypeRelative)
|
||||
}), CSSPositionTypeRelative, intValue)
|
||||
|
||||
RCT_ENUM_CONVERTER(css_wrap_type_t, (@{
|
||||
@"wrap": @(CSS_WRAP),
|
||||
@"nowrap": @(CSS_NOWRAP)
|
||||
}), CSS_NOWRAP, intValue)
|
||||
RCT_ENUM_CONVERTER(CSSWrapType, (@{
|
||||
@"wrap": @(CSSWrapTypeWrap),
|
||||
@"nowrap": @(CSSWrapTypeNoWrap)
|
||||
}), CSSWrapTypeNoWrap, intValue)
|
||||
|
||||
RCT_ENUM_CONVERTER(RCTPointerEvents, (@{
|
||||
@"none": @(RCTPointerEventsNone),
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -21,132 +21,132 @@ static const unsigned long __nan[2] = {0xffffffff, 0x7fffffff};
|
||||
#define NAN (*(const float *)__nan)
|
||||
#endif
|
||||
|
||||
#define CSS_UNDEFINED NAN
|
||||
#define CSSUndefined NAN
|
||||
|
||||
#include "CSSMacros.h"
|
||||
|
||||
CSS_EXTERN_C_BEGIN
|
||||
|
||||
typedef enum {
|
||||
CSS_DIRECTION_INHERIT = 0,
|
||||
CSS_DIRECTION_LTR,
|
||||
CSS_DIRECTION_RTL
|
||||
} css_direction_t;
|
||||
typedef enum CSSDirection {
|
||||
CSSDirectionInherit,
|
||||
CSSDirectionLTR,
|
||||
CSSDirectionRTL,
|
||||
} CSSDirection;
|
||||
|
||||
typedef enum {
|
||||
CSS_FLEX_DIRECTION_COLUMN = 0,
|
||||
CSS_FLEX_DIRECTION_COLUMN_REVERSE,
|
||||
CSS_FLEX_DIRECTION_ROW,
|
||||
CSS_FLEX_DIRECTION_ROW_REVERSE
|
||||
} css_flex_direction_t;
|
||||
typedef enum CSSFlexDirection {
|
||||
CSSFlexDirectionColumn,
|
||||
CSSFlexDirectionColumnReverse,
|
||||
CSSFlexDirectionRow,
|
||||
CSSFlexDirectionRowReverse,
|
||||
} CSSFlexDirection;
|
||||
|
||||
typedef enum {
|
||||
CSS_JUSTIFY_FLEX_START = 0,
|
||||
CSS_JUSTIFY_CENTER,
|
||||
CSS_JUSTIFY_FLEX_END,
|
||||
CSS_JUSTIFY_SPACE_BETWEEN,
|
||||
CSS_JUSTIFY_SPACE_AROUND
|
||||
} css_justify_t;
|
||||
typedef enum CSSJustify {
|
||||
CSSJustifyFlexStart,
|
||||
CSSJustifyCenter,
|
||||
CSSJustifyFlexEnd,
|
||||
CSSJustifySpaceBetween,
|
||||
CSSJustifySpaceAround,
|
||||
} CSSJustify;
|
||||
|
||||
typedef enum {
|
||||
CSS_OVERFLOW_VISIBLE = 0,
|
||||
CSS_OVERFLOW_HIDDEN
|
||||
} css_overflow_t;
|
||||
typedef enum CSSOverflow {
|
||||
CSSOverflowVisible,
|
||||
CSSOverflowHidden,
|
||||
} CSSOverflow;
|
||||
|
||||
// Note: auto is only a valid value for alignSelf. It is NOT a valid value for
|
||||
// alignItems.
|
||||
typedef enum {
|
||||
CSS_ALIGN_AUTO = 0,
|
||||
CSS_ALIGN_FLEX_START,
|
||||
CSS_ALIGN_CENTER,
|
||||
CSS_ALIGN_FLEX_END,
|
||||
CSS_ALIGN_STRETCH
|
||||
} css_align_t;
|
||||
typedef enum CSSAlign {
|
||||
CSSAlignAuto,
|
||||
CSSAlignFlexStart,
|
||||
CSSAlignCenter,
|
||||
CSSAlignFlexEnd,
|
||||
CSSAlignStretch,
|
||||
} CSSAlign;
|
||||
|
||||
typedef enum {
|
||||
CSS_POSITION_RELATIVE = 0,
|
||||
CSS_POSITION_ABSOLUTE
|
||||
} css_position_type_t;
|
||||
typedef enum CSSPositionType {
|
||||
CSSPositionTypeRelative,
|
||||
CSSPositionTypeAbsolute,
|
||||
} CSSPositionType;
|
||||
|
||||
typedef enum {
|
||||
CSS_NOWRAP = 0,
|
||||
CSS_WRAP
|
||||
} css_wrap_type_t;
|
||||
typedef enum CSSWrapType {
|
||||
CSSWrapTypeNoWrap,
|
||||
CSSWrapTypeWrap,
|
||||
} CSSWrapType;
|
||||
|
||||
// Note: left and top are shared between position[2] and position[4], so
|
||||
// they have to be before right and bottom.
|
||||
typedef enum {
|
||||
CSS_LEFT = 0,
|
||||
CSS_TOP,
|
||||
CSS_RIGHT,
|
||||
CSS_BOTTOM,
|
||||
CSS_START,
|
||||
CSS_END,
|
||||
CSS_POSITION_COUNT
|
||||
} css_position_t;
|
||||
typedef enum CSSPosition {
|
||||
CSSPositionLeft,
|
||||
CSSPositionTop,
|
||||
CSSPositionRight,
|
||||
CSSPositionBottom,
|
||||
CSSPositionStart,
|
||||
CSSPositionEnd,
|
||||
CSSPositionCount,
|
||||
} CSSPosition;
|
||||
|
||||
typedef enum {
|
||||
CSS_MEASURE_MODE_UNDEFINED = 0,
|
||||
CSS_MEASURE_MODE_EXACTLY,
|
||||
CSS_MEASURE_MODE_AT_MOST,
|
||||
CSS_MEASURE_MODE_COUNT
|
||||
} css_measure_mode_t;
|
||||
typedef enum CSSMeasureMode {
|
||||
CSSMeasureModeUndefined,
|
||||
CSSMeasureModeExactly,
|
||||
CSSMeasureModeAtMost,
|
||||
CSSMeasureModeCount,
|
||||
} CSSMeasureMode;
|
||||
|
||||
typedef enum {
|
||||
CSS_WIDTH = 0,
|
||||
CSS_HEIGHT
|
||||
} css_dimension_t;
|
||||
typedef enum CSSDimension {
|
||||
CSSDimensionWidth,
|
||||
CSSDimensionHeight,
|
||||
} CSSDimension;
|
||||
|
||||
typedef struct {
|
||||
float available_width;
|
||||
float available_height;
|
||||
css_measure_mode_t width_measure_mode;
|
||||
css_measure_mode_t height_measure_mode;
|
||||
typedef struct CSSCachedMeasurement {
|
||||
float availableWidth;
|
||||
float availableHeight;
|
||||
CSSMeasureMode widthMeasureMode;
|
||||
CSSMeasureMode heightMeasureMode;
|
||||
|
||||
float computed_width;
|
||||
float computed_height;
|
||||
} css_cached_measurement_t;
|
||||
float computedWidth;
|
||||
float computedHeight;
|
||||
} CSSCachedMeasurement;
|
||||
|
||||
// This value was chosen based on empiracle data. Even the most complicated
|
||||
// layouts should not require more than 16 entries to fit within the cache.
|
||||
enum {
|
||||
// This value was chosen based on empiracle data. Even the most complicated
|
||||
// layouts should not require more than 16 entries to fit within the cache.
|
||||
CSS_MAX_CACHED_RESULT_COUNT = 16
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
typedef struct CSSLayout {
|
||||
float position[4];
|
||||
float dimensions[2];
|
||||
css_direction_t direction;
|
||||
CSSDirection direction;
|
||||
|
||||
float flex_basis;
|
||||
float flexBasis;
|
||||
|
||||
// Instead of recomputing the entire layout every single time, we
|
||||
// cache some information to break early when nothing changed
|
||||
bool should_update;
|
||||
int generation_count;
|
||||
css_direction_t last_parent_direction;
|
||||
bool shouldUpdate;
|
||||
int generationCount;
|
||||
CSSDirection lastParentDirection;
|
||||
|
||||
int next_cached_measurements_index;
|
||||
css_cached_measurement_t cached_measurements[CSS_MAX_CACHED_RESULT_COUNT];
|
||||
float measured_dimensions[2];
|
||||
int nextCachedMeasurementsIndex;
|
||||
CSSCachedMeasurement cachedMeasurements[CSS_MAX_CACHED_RESULT_COUNT];
|
||||
float measuredDimensions[2];
|
||||
|
||||
css_cached_measurement_t cached_layout;
|
||||
} css_layout_t;
|
||||
CSSCachedMeasurement cached_layout;
|
||||
} CSSLayout;
|
||||
|
||||
typedef struct {
|
||||
typedef struct CSSMeasureResult {
|
||||
float dimensions[2];
|
||||
} css_dim_t;
|
||||
} CSSMeasureResult;
|
||||
|
||||
typedef struct {
|
||||
css_direction_t direction;
|
||||
css_flex_direction_t flex_direction;
|
||||
css_justify_t justify_content;
|
||||
css_align_t align_content;
|
||||
css_align_t align_items;
|
||||
css_align_t align_self;
|
||||
css_position_type_t position_type;
|
||||
css_wrap_type_t flex_wrap;
|
||||
css_overflow_t overflow;
|
||||
typedef struct CSSStyle {
|
||||
CSSDirection direction;
|
||||
CSSFlexDirection flexDirection;
|
||||
CSSJustify justifyContent;
|
||||
CSSAlign alignContent;
|
||||
CSSAlign alignItems;
|
||||
CSSAlign alignSelf;
|
||||
CSSPositionType positionType;
|
||||
CSSWrapType flexWrap;
|
||||
CSSOverflow overflow;
|
||||
float flex;
|
||||
float margin[6];
|
||||
float position[4];
|
||||
@@ -165,40 +165,40 @@ typedef struct {
|
||||
float dimensions[2];
|
||||
float minDimensions[2];
|
||||
float maxDimensions[2];
|
||||
} css_style_t;
|
||||
} CSSStyle;
|
||||
|
||||
typedef struct css_node css_node_t;
|
||||
struct css_node {
|
||||
css_style_t style;
|
||||
css_layout_t layout;
|
||||
int children_count;
|
||||
int line_index;
|
||||
typedef struct CSSNode {
|
||||
CSSStyle style;
|
||||
CSSLayout layout;
|
||||
int childCount;
|
||||
int lineIndex;
|
||||
|
||||
css_node_t* next_child;
|
||||
struct CSSNode* nextChild;
|
||||
|
||||
css_dim_t (*measure)(void *context, float width, css_measure_mode_t widthMode, float height, css_measure_mode_t heightMode);
|
||||
CSSMeasureResult (*measure)(void *context, float width, CSSMeasureMode widthMode, float height, CSSMeasureMode heightMode);
|
||||
void (*print)(void *context);
|
||||
struct css_node* (*get_child)(void *context, int i);
|
||||
bool (*is_dirty)(void *context);
|
||||
bool (*is_text_node)(void *context);
|
||||
struct CSSNode* (*getChild)(void *context, int i);
|
||||
bool (*isDirty)(void *context);
|
||||
bool (*isTextNode)(void *context);
|
||||
void *context;
|
||||
};
|
||||
} CSSNode;
|
||||
|
||||
// Lifecycle of nodes and children
|
||||
css_node_t *new_css_node(void);
|
||||
void init_css_node(css_node_t *node);
|
||||
void free_css_node(css_node_t *node);
|
||||
CSSNode *CSSNodeNew();
|
||||
void CSSNodeInit(CSSNode *node);
|
||||
void CSSNodeFree(CSSNode *node);
|
||||
|
||||
// Print utilities
|
||||
typedef enum {
|
||||
CSS_PRINT_LAYOUT = 1,
|
||||
CSS_PRINT_STYLE = 2,
|
||||
CSS_PRINT_CHILDREN = 4,
|
||||
} css_print_options_t;
|
||||
void print_css_node(css_node_t *node, css_print_options_t options);
|
||||
typedef enum CSSPrintOptions {
|
||||
CSSPrintOptionsLayout = 1,
|
||||
CSSPrintOptionsStyle = 2,
|
||||
CSSPrintOptionsChildren = 4,
|
||||
} CSSPrintOptions;
|
||||
|
||||
void CSSNodePrint(CSSNode *node, CSSPrintOptions options);
|
||||
|
||||
// Function that computes the layout!
|
||||
void layoutNode(css_node_t *node, float availableWidth, float availableHeight, css_direction_t parentDirection);
|
||||
void layoutNode(CSSNode *node, float availableWidth, float availableHeight, CSSDirection parentDirection);
|
||||
bool isUndefined(float value);
|
||||
|
||||
CSS_EXTERN_C_END
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
self = [super init];
|
||||
if (self) {
|
||||
if ([[RCTI18nUtil sharedInstance] isRTL]) {
|
||||
self.cssNode->style.direction = CSS_DIRECTION_RTL;
|
||||
self.cssNode->style.direction = CSSDirectionRTL;
|
||||
}
|
||||
}
|
||||
return self;
|
||||
@@ -33,14 +33,14 @@
|
||||
case RCTRootViewSizeFlexibilityNone:
|
||||
break;
|
||||
case RCTRootViewSizeFlexibilityWidth:
|
||||
self.cssNode->style.dimensions[CSS_WIDTH] = CSS_UNDEFINED;
|
||||
self.cssNode->style.dimensions[CSSDimensionWidth] = CSSUndefined;
|
||||
break;
|
||||
case RCTRootViewSizeFlexibilityHeight:
|
||||
self.cssNode->style.dimensions[CSS_HEIGHT] = CSS_UNDEFINED;
|
||||
self.cssNode->style.dimensions[CSSDimensionHeight] = CSSUndefined;
|
||||
break;
|
||||
case RCTRootViewSizeFlexibilityWidthAndHeight:
|
||||
self.cssNode->style.dimensions[CSS_WIDTH] = CSS_UNDEFINED;
|
||||
self.cssNode->style.dimensions[CSS_HEIGHT] = CSS_UNDEFINED;
|
||||
self.cssNode->style.dimensions[CSSDimensionWidth] = CSSUndefined;
|
||||
self.cssNode->style.dimensions[CSSDimensionHeight] = CSSUndefined;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -49,7 +49,7 @@
|
||||
{
|
||||
[self applySizeConstraints];
|
||||
|
||||
layoutNode(self.cssNode, CSS_UNDEFINED, CSS_UNDEFINED, CSS_DIRECTION_INHERIT);
|
||||
layoutNode(self.cssNode, CSSUndefined, CSSUndefined, CSSDirectionInherit);
|
||||
|
||||
NSMutableSet<RCTShadowView *> *viewsWithNewFrame = [NSMutableSet set];
|
||||
[self applyLayoutNode:self.cssNode viewsWithNewFrame:viewsWithNewFrame absolutePosition:CGPointZero];
|
||||
|
||||
@@ -44,7 +44,7 @@ typedef void (^RCTApplierBlock)(NSDictionary<NSNumber *, UIView *> *viewRegistry
|
||||
- (void)removeReactSubview:(RCTShadowView *)subview NS_REQUIRES_SUPER;
|
||||
|
||||
@property (nonatomic, weak, readonly) RCTShadowView *superview;
|
||||
@property (nonatomic, assign, readonly) css_node_t *cssNode;
|
||||
@property (nonatomic, assign, readonly) CSSNode *cssNode;
|
||||
@property (nonatomic, copy) NSString *viewName;
|
||||
@property (nonatomic, strong) UIColor *backgroundColor; // Used to propagate to children
|
||||
@property (nonatomic, assign) RCTUpdateLifecycle layoutLifecycle;
|
||||
@@ -127,12 +127,12 @@ typedef void (^RCTApplierBlock)(NSDictionary<NSNumber *, UIView *> *viewRegistry
|
||||
/**
|
||||
* Flexbox properties. All zero/disabled by default
|
||||
*/
|
||||
@property (nonatomic, assign) css_flex_direction_t flexDirection;
|
||||
@property (nonatomic, assign) css_justify_t justifyContent;
|
||||
@property (nonatomic, assign) css_align_t alignSelf;
|
||||
@property (nonatomic, assign) css_align_t alignItems;
|
||||
@property (nonatomic, assign) css_position_type_t position;
|
||||
@property (nonatomic, assign) css_wrap_type_t flexWrap;
|
||||
@property (nonatomic, assign) CSSFlexDirection flexDirection;
|
||||
@property (nonatomic, assign) CSSJustify justifyContent;
|
||||
@property (nonatomic, assign) CSSAlign alignSelf;
|
||||
@property (nonatomic, assign) CSSAlign alignItems;
|
||||
@property (nonatomic, assign) CSSPositionType position;
|
||||
@property (nonatomic, assign) CSSWrapType flexWrap;
|
||||
@property (nonatomic, assign) CGFloat flex;
|
||||
|
||||
/**
|
||||
@@ -172,14 +172,14 @@ typedef void (^RCTApplierBlock)(NSDictionary<NSNumber *, UIView *> *viewRegistry
|
||||
* is split into two methods so subclasses can override `applyLayoutToChildren:`
|
||||
* while using default implementation of `applyLayoutNode:`.
|
||||
*/
|
||||
- (void)applyLayoutNode:(css_node_t *)node
|
||||
- (void)applyLayoutNode:(CSSNode *)node
|
||||
viewsWithNewFrame:(NSMutableSet<RCTShadowView *> *)viewsWithNewFrame
|
||||
absolutePosition:(CGPoint)absolutePosition NS_REQUIRES_SUPER;
|
||||
|
||||
/**
|
||||
* Enumerate the child nodes and tell them to apply layout.
|
||||
*/
|
||||
- (void)applyLayoutToChildren:(css_node_t *)node
|
||||
- (void)applyLayoutToChildren:(CSSNode *)node
|
||||
viewsWithNewFrame:(NSMutableSet<RCTShadowView *> *)viewsWithNewFrame
|
||||
absolutePosition:(CGPoint)absolutePosition;
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ typedef NS_ENUM(unsigned int, meta_prop_t) {
|
||||
|
||||
@synthesize reactTag = _reactTag;
|
||||
|
||||
// css_node api
|
||||
// cssNode api
|
||||
|
||||
static void RCTPrint(void *context)
|
||||
{
|
||||
@@ -56,7 +56,7 @@ static void RCTPrint(void *context)
|
||||
printf("%s(%zd), ", shadowView.viewName.UTF8String, shadowView.reactTag.integerValue);
|
||||
}
|
||||
|
||||
static css_node_t *RCTGetChild(void *context, int i)
|
||||
static CSSNode *RCTGetChild(void *context, int i)
|
||||
{
|
||||
RCTShadowView *shadowView = (__bridge RCTShadowView *)context;
|
||||
RCTShadowView *child = [shadowView reactSubviews][i];
|
||||
@@ -70,20 +70,20 @@ static bool RCTIsDirty(void *context)
|
||||
}
|
||||
|
||||
// Enforces precedence rules, e.g. marginLeft > marginHorizontal > margin.
|
||||
static void RCTProcessMetaProps(const float metaProps[META_PROP_COUNT], float style[CSS_POSITION_COUNT]) {
|
||||
style[CSS_LEFT] = !isUndefined(metaProps[META_PROP_LEFT]) ? metaProps[META_PROP_LEFT]
|
||||
static void RCTProcessMetaProps(const float metaProps[META_PROP_COUNT], float style[CSSPositionCount]) {
|
||||
style[CSSPositionLeft] = !isUndefined(metaProps[META_PROP_LEFT]) ? metaProps[META_PROP_LEFT]
|
||||
: !isUndefined(metaProps[META_PROP_HORIZONTAL]) ? metaProps[META_PROP_HORIZONTAL]
|
||||
: !isUndefined(metaProps[META_PROP_ALL]) ? metaProps[META_PROP_ALL]
|
||||
: 0;
|
||||
style[CSS_RIGHT] = !isUndefined(metaProps[META_PROP_RIGHT]) ? metaProps[META_PROP_RIGHT]
|
||||
style[CSSPositionRight] = !isUndefined(metaProps[META_PROP_RIGHT]) ? metaProps[META_PROP_RIGHT]
|
||||
: !isUndefined(metaProps[META_PROP_HORIZONTAL]) ? metaProps[META_PROP_HORIZONTAL]
|
||||
: !isUndefined(metaProps[META_PROP_ALL]) ? metaProps[META_PROP_ALL]
|
||||
: 0;
|
||||
style[CSS_TOP] = !isUndefined(metaProps[META_PROP_TOP]) ? metaProps[META_PROP_TOP]
|
||||
style[CSSPositionTop] = !isUndefined(metaProps[META_PROP_TOP]) ? metaProps[META_PROP_TOP]
|
||||
: !isUndefined(metaProps[META_PROP_VERTICAL]) ? metaProps[META_PROP_VERTICAL]
|
||||
: !isUndefined(metaProps[META_PROP_ALL]) ? metaProps[META_PROP_ALL]
|
||||
: 0;
|
||||
style[CSS_BOTTOM] = !isUndefined(metaProps[META_PROP_BOTTOM]) ? metaProps[META_PROP_BOTTOM]
|
||||
style[CSSPositionBottom] = !isUndefined(metaProps[META_PROP_BOTTOM]) ? metaProps[META_PROP_BOTTOM]
|
||||
: !isUndefined(metaProps[META_PROP_VERTICAL]) ? metaProps[META_PROP_VERTICAL]
|
||||
: !isUndefined(metaProps[META_PROP_ALL]) ? metaProps[META_PROP_ALL]
|
||||
: 0;
|
||||
@@ -118,29 +118,29 @@ static void RCTProcessMetaProps(const float metaProps[META_PROP_COUNT], float st
|
||||
// width = 213.5 - 106.5 = 107
|
||||
// You'll notice that this is the same width we calculated for the parent view because we've taken its position into account.
|
||||
|
||||
- (void)applyLayoutNode:(css_node_t *)node
|
||||
- (void)applyLayoutNode:(CSSNode *)node
|
||||
viewsWithNewFrame:(NSMutableSet<RCTShadowView *> *)viewsWithNewFrame
|
||||
absolutePosition:(CGPoint)absolutePosition
|
||||
{
|
||||
if (!node->layout.should_update) {
|
||||
if (!node->layout.shouldUpdate) {
|
||||
return;
|
||||
}
|
||||
node->layout.should_update = false;
|
||||
node->layout.shouldUpdate = false;
|
||||
_layoutLifecycle = RCTUpdateLifecycleComputed;
|
||||
|
||||
CGPoint absoluteTopLeft = {
|
||||
absolutePosition.x + node->layout.position[CSS_LEFT],
|
||||
absolutePosition.y + node->layout.position[CSS_TOP]
|
||||
absolutePosition.x + node->layout.position[CSSPositionLeft],
|
||||
absolutePosition.y + node->layout.position[CSSPositionTop]
|
||||
};
|
||||
|
||||
CGPoint absoluteBottomRight = {
|
||||
absolutePosition.x + node->layout.position[CSS_LEFT] + node->layout.dimensions[CSS_WIDTH],
|
||||
absolutePosition.y + node->layout.position[CSS_TOP] + node->layout.dimensions[CSS_HEIGHT]
|
||||
absolutePosition.x + node->layout.position[CSSPositionLeft] + node->layout.dimensions[CSSDimensionWidth],
|
||||
absolutePosition.y + node->layout.position[CSSPositionTop] + node->layout.dimensions[CSSDimensionHeight]
|
||||
};
|
||||
|
||||
CGRect frame = {{
|
||||
RCTRoundPixelValue(node->layout.position[CSS_LEFT]),
|
||||
RCTRoundPixelValue(node->layout.position[CSS_TOP]),
|
||||
RCTRoundPixelValue(node->layout.position[CSSPositionLeft]),
|
||||
RCTRoundPixelValue(node->layout.position[CSSPositionTop]),
|
||||
}, {
|
||||
RCTRoundPixelValue(absoluteBottomRight.x - absoluteTopLeft.x),
|
||||
RCTRoundPixelValue(absoluteBottomRight.y - absoluteTopLeft.y)
|
||||
@@ -151,19 +151,19 @@ static void RCTProcessMetaProps(const float metaProps[META_PROP_COUNT], float st
|
||||
[viewsWithNewFrame addObject:self];
|
||||
}
|
||||
|
||||
absolutePosition.x += node->layout.position[CSS_LEFT];
|
||||
absolutePosition.y += node->layout.position[CSS_TOP];
|
||||
absolutePosition.x += node->layout.position[CSSPositionLeft];
|
||||
absolutePosition.y += node->layout.position[CSSPositionTop];
|
||||
|
||||
[self applyLayoutToChildren:node viewsWithNewFrame:viewsWithNewFrame absolutePosition:absolutePosition];
|
||||
}
|
||||
|
||||
- (void)applyLayoutToChildren:(css_node_t *)node
|
||||
- (void)applyLayoutToChildren:(CSSNode *)node
|
||||
viewsWithNewFrame:(NSMutableSet<RCTShadowView *> *)viewsWithNewFrame
|
||||
absolutePosition:(CGPoint)absolutePosition
|
||||
{
|
||||
for (int i = 0; i < node->children_count; ++i) {
|
||||
for (int i = 0; i < node->childCount; ++i) {
|
||||
RCTShadowView *child = (RCTShadowView *)_reactSubviews[i];
|
||||
[child applyLayoutNode:node->get_child(node->context, i)
|
||||
[child applyLayoutNode:node->getChild(node->context, i)
|
||||
viewsWithNewFrame:viewsWithNewFrame
|
||||
absolutePosition:absolutePosition];
|
||||
}
|
||||
@@ -237,18 +237,18 @@ static void RCTProcessMetaProps(const float metaProps[META_PROP_COUNT], float st
|
||||
}
|
||||
|
||||
if (!CGRectEqualToRect(frame, _frame)) {
|
||||
_cssNode->style.position_type = CSS_POSITION_ABSOLUTE;
|
||||
_cssNode->style.dimensions[CSS_WIDTH] = frame.size.width;
|
||||
_cssNode->style.dimensions[CSS_HEIGHT] = frame.size.height;
|
||||
_cssNode->style.position[CSS_LEFT] = frame.origin.x;
|
||||
_cssNode->style.position[CSS_TOP] = frame.origin.y;
|
||||
_cssNode->style.positionType = CSSPositionTypeAbsolute;
|
||||
_cssNode->style.dimensions[CSSDimensionWidth] = frame.size.width;
|
||||
_cssNode->style.dimensions[CSSDimensionHeight] = frame.size.height;
|
||||
_cssNode->style.position[CSSPositionLeft] = frame.origin.x;
|
||||
_cssNode->style.position[CSSPositionTop] = frame.origin.y;
|
||||
// Our parent has asked us to change our cssNode->styles. Dirty the layout
|
||||
// so that we can rerun layout on this node. The request came from our parent
|
||||
// so there's no need to dirty our ancestors by calling dirtyLayout.
|
||||
_layoutLifecycle = RCTUpdateLifecycleDirtied;
|
||||
}
|
||||
|
||||
layoutNode(_cssNode, frame.size.width, frame.size.height, CSS_DIRECTION_INHERIT);
|
||||
layoutNode(_cssNode, frame.size.width, frame.size.height, CSSDirectionInherit);
|
||||
[self applyLayoutNode:_cssNode viewsWithNewFrame:viewsWithNewFrame absolutePosition:absolutePosition];
|
||||
}
|
||||
|
||||
@@ -273,12 +273,12 @@ static void RCTProcessMetaProps(const float metaProps[META_PROP_COUNT], float st
|
||||
{
|
||||
if ((self = [super init])) {
|
||||
|
||||
_frame = CGRectMake(0, 0, CSS_UNDEFINED, CSS_UNDEFINED);
|
||||
_frame = CGRectMake(0, 0, CSSUndefined, CSSUndefined);
|
||||
|
||||
for (unsigned int ii = 0; ii < META_PROP_COUNT; ii++) {
|
||||
_paddingMetaProps[ii] = CSS_UNDEFINED;
|
||||
_marginMetaProps[ii] = CSS_UNDEFINED;
|
||||
_borderMetaProps[ii] = CSS_UNDEFINED;
|
||||
_paddingMetaProps[ii] = CSSUndefined;
|
||||
_marginMetaProps[ii] = CSSUndefined;
|
||||
_borderMetaProps[ii] = CSSUndefined;
|
||||
}
|
||||
|
||||
_newView = YES;
|
||||
@@ -288,11 +288,11 @@ static void RCTProcessMetaProps(const float metaProps[META_PROP_COUNT], float st
|
||||
|
||||
_reactSubviews = [NSMutableArray array];
|
||||
|
||||
_cssNode = new_css_node();
|
||||
_cssNode = CSSNodeNew();
|
||||
_cssNode->context = (__bridge void *)self;
|
||||
_cssNode->print = RCTPrint;
|
||||
_cssNode->get_child = RCTGetChild;
|
||||
_cssNode->is_dirty = RCTIsDirty;
|
||||
_cssNode->getChild = RCTGetChild;
|
||||
_cssNode->isDirty = RCTIsDirty;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
@@ -304,7 +304,7 @@ static void RCTProcessMetaProps(const float metaProps[META_PROP_COUNT], float st
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
free_css_node(_cssNode);
|
||||
CSSNodeFree(_cssNode);
|
||||
}
|
||||
|
||||
- (void)dirtyLayout
|
||||
@@ -359,7 +359,7 @@ static void RCTProcessMetaProps(const float metaProps[META_PROP_COUNT], float st
|
||||
- (void)insertReactSubview:(RCTShadowView *)subview atIndex:(NSInteger)atIndex
|
||||
{
|
||||
[_reactSubviews insertObject:subview atIndex:atIndex];
|
||||
_cssNode->children_count = [self isCSSLeafNode] ? 0 : (int)_reactSubviews.count;
|
||||
_cssNode->childCount = [self isCSSLeafNode] ? 0 : (int)_reactSubviews.count;
|
||||
subview->_superview = self;
|
||||
_didUpdateSubviews = YES;
|
||||
[self dirtyText];
|
||||
@@ -375,7 +375,7 @@ static void RCTProcessMetaProps(const float metaProps[META_PROP_COUNT], float st
|
||||
_didUpdateSubviews = YES;
|
||||
subview->_superview = nil;
|
||||
[_reactSubviews removeObject:subview];
|
||||
_cssNode->children_count = [self isCSSLeafNode] ? 0 : (int)_reactSubviews.count;
|
||||
_cssNode->childCount = [self isCSSLeafNode] ? 0 : (int)_reactSubviews.count;
|
||||
}
|
||||
|
||||
- (NSArray<RCTShadowView *> *)reactSubviews
|
||||
@@ -475,10 +475,10 @@ RCT_PADDING_PROPERTY(Right, RIGHT)
|
||||
- (UIEdgeInsets)paddingAsInsets
|
||||
{
|
||||
return (UIEdgeInsets){
|
||||
_cssNode->style.padding[CSS_TOP],
|
||||
_cssNode->style.padding[CSS_LEFT],
|
||||
_cssNode->style.padding[CSS_BOTTOM],
|
||||
_cssNode->style.padding[CSS_RIGHT]
|
||||
_cssNode->style.padding[CSSPositionTop],
|
||||
_cssNode->style.padding[CSSPositionLeft],
|
||||
_cssNode->style.padding[CSSPositionBottom],
|
||||
_cssNode->style.padding[CSSPositionRight]
|
||||
};
|
||||
}
|
||||
|
||||
@@ -507,47 +507,47 @@ RCT_BORDER_PROPERTY(Right, RIGHT)
|
||||
#define RCT_DIMENSION_PROPERTY(setProp, getProp, cssProp, category) \
|
||||
- (void)set##setProp:(CGFloat)value \
|
||||
{ \
|
||||
_cssNode->style.category[CSS_##cssProp] = value; \
|
||||
_cssNode->style.category[CSS##cssProp] = value; \
|
||||
[self dirtyLayout]; \
|
||||
[self dirtyText]; \
|
||||
} \
|
||||
- (CGFloat)getProp \
|
||||
{ \
|
||||
return _cssNode->style.category[CSS_##cssProp]; \
|
||||
return _cssNode->style.category[CSS##cssProp]; \
|
||||
}
|
||||
|
||||
RCT_DIMENSION_PROPERTY(Width, width, WIDTH, dimensions)
|
||||
RCT_DIMENSION_PROPERTY(Height, height, HEIGHT, dimensions)
|
||||
RCT_DIMENSION_PROPERTY(Width, width, DimensionWidth, dimensions)
|
||||
RCT_DIMENSION_PROPERTY(Height, height, DimensionHeight, dimensions)
|
||||
|
||||
RCT_DIMENSION_PROPERTY(MinWidth, minWidth, WIDTH, minDimensions)
|
||||
RCT_DIMENSION_PROPERTY(MaxWidth, maxWidth, WIDTH, maxDimensions)
|
||||
RCT_DIMENSION_PROPERTY(MinHeight, minHeight, HEIGHT, minDimensions)
|
||||
RCT_DIMENSION_PROPERTY(MaxHeight, maxHeight, HEIGHT, maxDimensions)
|
||||
RCT_DIMENSION_PROPERTY(MinWidth, minWidth, DimensionWidth, minDimensions)
|
||||
RCT_DIMENSION_PROPERTY(MaxWidth, maxWidth, DimensionWidth, maxDimensions)
|
||||
RCT_DIMENSION_PROPERTY(MinHeight, minHeight, DimensionHeight, minDimensions)
|
||||
RCT_DIMENSION_PROPERTY(MaxHeight, maxHeight, DimensionHeight, maxDimensions)
|
||||
|
||||
// Position
|
||||
|
||||
#define RCT_POSITION_PROPERTY(setProp, getProp, cssProp) \
|
||||
RCT_DIMENSION_PROPERTY(setProp, getProp, cssProp, position)
|
||||
|
||||
RCT_POSITION_PROPERTY(Top, top, TOP)
|
||||
RCT_POSITION_PROPERTY(Right, right, RIGHT)
|
||||
RCT_POSITION_PROPERTY(Bottom, bottom, BOTTOM)
|
||||
RCT_POSITION_PROPERTY(Left, left, LEFT)
|
||||
RCT_POSITION_PROPERTY(Top, top, PositionTop)
|
||||
RCT_POSITION_PROPERTY(Right, right, PositionRight)
|
||||
RCT_POSITION_PROPERTY(Bottom, bottom, PositionBottom)
|
||||
RCT_POSITION_PROPERTY(Left, left, PositionLeft)
|
||||
|
||||
- (void)setFrame:(CGRect)frame
|
||||
{
|
||||
_cssNode->style.position[CSS_LEFT] = CGRectGetMinX(frame);
|
||||
_cssNode->style.position[CSS_TOP] = CGRectGetMinY(frame);
|
||||
_cssNode->style.dimensions[CSS_WIDTH] = CGRectGetWidth(frame);
|
||||
_cssNode->style.dimensions[CSS_HEIGHT] = CGRectGetHeight(frame);
|
||||
_cssNode->style.position[CSSPositionLeft] = CGRectGetMinX(frame);
|
||||
_cssNode->style.position[CSSPositionTop] = CGRectGetMinY(frame);
|
||||
_cssNode->style.dimensions[CSSDimensionWidth] = CGRectGetWidth(frame);
|
||||
_cssNode->style.dimensions[CSSDimensionHeight] = CGRectGetHeight(frame);
|
||||
[self dirtyLayout];
|
||||
}
|
||||
|
||||
static inline BOOL RCTAssignSuggestedDimension(css_node_t *css_node, int dimension, CGFloat amount)
|
||||
static inline BOOL RCTAssignSuggestedDimension(CSSNode *cssNode, int dimension, CGFloat amount)
|
||||
{
|
||||
if (amount != UIViewNoIntrinsicMetric
|
||||
&& isnan(css_node->style.dimensions[dimension])) {
|
||||
css_node->style.dimensions[dimension] = amount;
|
||||
&& isnan(cssNode->style.dimensions[dimension])) {
|
||||
cssNode->style.dimensions[dimension] = amount;
|
||||
return YES;
|
||||
}
|
||||
return NO;
|
||||
@@ -557,8 +557,8 @@ static inline BOOL RCTAssignSuggestedDimension(css_node_t *css_node, int dimensi
|
||||
{
|
||||
if (_cssNode->style.flex == 0) {
|
||||
BOOL dirty = NO;
|
||||
dirty |= RCTAssignSuggestedDimension(_cssNode, CSS_HEIGHT, size.height);
|
||||
dirty |= RCTAssignSuggestedDimension(_cssNode, CSS_WIDTH, size.width);
|
||||
dirty |= RCTAssignSuggestedDimension(_cssNode, CSSDimensionHeight, size.height);
|
||||
dirty |= RCTAssignSuggestedDimension(_cssNode, CSSDimensionWidth, size.width);
|
||||
if (dirty) {
|
||||
[self dirtyLayout];
|
||||
}
|
||||
@@ -567,15 +567,15 @@ static inline BOOL RCTAssignSuggestedDimension(css_node_t *css_node, int dimensi
|
||||
|
||||
- (void)setTopLeft:(CGPoint)topLeft
|
||||
{
|
||||
_cssNode->style.position[CSS_LEFT] = topLeft.x;
|
||||
_cssNode->style.position[CSS_TOP] = topLeft.y;
|
||||
_cssNode->style.position[CSSPositionLeft] = topLeft.x;
|
||||
_cssNode->style.position[CSSPositionTop] = topLeft.y;
|
||||
[self dirtyLayout];
|
||||
}
|
||||
|
||||
- (void)setSize:(CGSize)size
|
||||
{
|
||||
_cssNode->style.dimensions[CSS_WIDTH] = size.width;
|
||||
_cssNode->style.dimensions[CSS_HEIGHT] = size.height;
|
||||
_cssNode->style.dimensions[CSSDimensionWidth] = size.width;
|
||||
_cssNode->style.dimensions[CSSDimensionHeight] = size.height;
|
||||
[self dirtyLayout];
|
||||
}
|
||||
|
||||
@@ -593,12 +593,12 @@ static inline BOOL RCTAssignSuggestedDimension(css_node_t *css_node, int dimensi
|
||||
}
|
||||
|
||||
RCT_STYLE_PROPERTY(Flex, flex, flex, CGFloat)
|
||||
RCT_STYLE_PROPERTY(FlexDirection, flexDirection, flex_direction, css_flex_direction_t)
|
||||
RCT_STYLE_PROPERTY(JustifyContent, justifyContent, justify_content, css_justify_t)
|
||||
RCT_STYLE_PROPERTY(AlignSelf, alignSelf, align_self, css_align_t)
|
||||
RCT_STYLE_PROPERTY(AlignItems, alignItems, align_items, css_align_t)
|
||||
RCT_STYLE_PROPERTY(Position, position, position_type, css_position_type_t)
|
||||
RCT_STYLE_PROPERTY(FlexWrap, flexWrap, flex_wrap, css_wrap_type_t)
|
||||
RCT_STYLE_PROPERTY(FlexDirection, flexDirection, flexDirection, CSSFlexDirection)
|
||||
RCT_STYLE_PROPERTY(JustifyContent, justifyContent, justifyContent, CSSJustify)
|
||||
RCT_STYLE_PROPERTY(AlignSelf, alignSelf, alignSelf, CSSAlign)
|
||||
RCT_STYLE_PROPERTY(AlignItems, alignItems, alignItems, CSSAlign)
|
||||
RCT_STYLE_PROPERTY(Position, position, positionType, CSSPositionType)
|
||||
RCT_STYLE_PROPERTY(FlexWrap, flexWrap, flexWrap, CSSWrapType)
|
||||
|
||||
- (void)setBackgroundColor:(UIColor *)color
|
||||
{
|
||||
|
||||
@@ -288,12 +288,12 @@ RCT_EXPORT_SHADOW_PROPERTY(paddingHorizontal, CGFloat)
|
||||
RCT_EXPORT_SHADOW_PROPERTY(padding, CGFloat)
|
||||
|
||||
RCT_EXPORT_SHADOW_PROPERTY(flex, CGFloat)
|
||||
RCT_EXPORT_SHADOW_PROPERTY(flexDirection, css_flex_direction_t)
|
||||
RCT_EXPORT_SHADOW_PROPERTY(flexWrap, css_wrap_type_t)
|
||||
RCT_EXPORT_SHADOW_PROPERTY(justifyContent, css_justify_t)
|
||||
RCT_EXPORT_SHADOW_PROPERTY(alignItems, css_align_t)
|
||||
RCT_EXPORT_SHADOW_PROPERTY(alignSelf, css_align_t)
|
||||
RCT_EXPORT_SHADOW_PROPERTY(position, css_position_type_t)
|
||||
RCT_EXPORT_SHADOW_PROPERTY(flexDirection, CSSFlexDirection)
|
||||
RCT_EXPORT_SHADOW_PROPERTY(flexWrap, CSSWrapType)
|
||||
RCT_EXPORT_SHADOW_PROPERTY(justifyContent, CSSJustify)
|
||||
RCT_EXPORT_SHADOW_PROPERTY(alignItems, CSSAlign)
|
||||
RCT_EXPORT_SHADOW_PROPERTY(alignSelf, CSSAlign)
|
||||
RCT_EXPORT_SHADOW_PROPERTY(position, CSSPositionType)
|
||||
|
||||
RCT_EXPORT_SHADOW_PROPERTY(onLayout, RCTDirectEventBlock)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user