mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-22 19:48:56 +08:00
Revamp API
Reviewed By: majak Differential Revision: D3579423 fbshipit-source-id: 040ecab2f20216aa136ccb8a9e7e15ffa882b313
This commit is contained in:
committed by
Facebook Github Bot 6
parent
12ec213c0d
commit
1af9270e45
@@ -28,10 +28,10 @@
|
||||
{
|
||||
[super setUp];
|
||||
|
||||
self.parentView = [self _shadowViewWithStyle:^(CSSStyle *style) {
|
||||
style->flexDirection = CSSFlexDirectionColumn;
|
||||
style->dimensions[0] = 440;
|
||||
style->dimensions[1] = 440;
|
||||
self.parentView = [self _shadowViewWithConfig:^(CSSNodeRef node) {
|
||||
CSSNodeStyleSetFlexDirection(node, CSSFlexDirectionColumn);
|
||||
CSSNodeStyleSetWidth(node, 440);
|
||||
CSSNodeStyleSetHeight(node, 440);
|
||||
}];
|
||||
self.parentView.reactTag = @1; // must be valid rootView tag
|
||||
}
|
||||
@@ -50,43 +50,43 @@
|
||||
//
|
||||
- (void)testApplyingLayoutRecursivelyToShadowView
|
||||
{
|
||||
RCTShadowView *leftView = [self _shadowViewWithStyle:^(CSSStyle *style) {
|
||||
style->flex = 1;
|
||||
RCTShadowView *leftView = [self _shadowViewWithConfig:^(CSSNodeRef node) {
|
||||
CSSNodeStyleSetFlex(node, 1);
|
||||
}];
|
||||
|
||||
RCTShadowView *centerView = [self _shadowViewWithStyle:^(CSSStyle *style) {
|
||||
style->flex = 2;
|
||||
style->margin[0] = 10;
|
||||
style->margin[2] = 10;
|
||||
RCTShadowView *centerView = [self _shadowViewWithConfig:^(CSSNodeRef node) {
|
||||
CSSNodeStyleSetFlex(node, 2);
|
||||
CSSNodeStyleSetMarginLeft(node, 10);
|
||||
CSSNodeStyleSetMarginRight(node, 10);
|
||||
}];
|
||||
|
||||
RCTShadowView *rightView = [self _shadowViewWithStyle:^(CSSStyle *style) {
|
||||
style->flex = 1;
|
||||
RCTShadowView *rightView = [self _shadowViewWithConfig:^(CSSNodeRef node) {
|
||||
CSSNodeStyleSetFlex(node, 1);
|
||||
}];
|
||||
|
||||
RCTShadowView *mainView = [self _shadowViewWithStyle:^(CSSStyle *style) {
|
||||
style->flexDirection = CSSFlexDirectionRow;
|
||||
style->flex = 2;
|
||||
style->margin[1] = 10;
|
||||
style->margin[3] = 10;
|
||||
RCTShadowView *mainView = [self _shadowViewWithConfig:^(CSSNodeRef node) {
|
||||
CSSNodeStyleSetFlexDirection(node, CSSFlexDirectionRow);
|
||||
CSSNodeStyleSetFlex(node, 2);
|
||||
CSSNodeStyleSetMarginTop(node, 10);
|
||||
CSSNodeStyleSetMarginBottom(node, 10);
|
||||
}];
|
||||
|
||||
[mainView insertReactSubview:leftView atIndex:0];
|
||||
[mainView insertReactSubview:centerView atIndex:1];
|
||||
[mainView insertReactSubview:rightView atIndex:2];
|
||||
|
||||
RCTShadowView *headerView = [self _shadowViewWithStyle:^(CSSStyle *style) {
|
||||
style->flex = 1;
|
||||
RCTShadowView *headerView = [self _shadowViewWithConfig:^(CSSNodeRef node) {
|
||||
CSSNodeStyleSetFlex(node, 1);
|
||||
}];
|
||||
|
||||
RCTShadowView *footerView = [self _shadowViewWithStyle:^(CSSStyle *style) {
|
||||
style->flex = 1;
|
||||
RCTShadowView *footerView = [self _shadowViewWithConfig:^(CSSNodeRef node) {
|
||||
CSSNodeStyleSetFlex(node, 1);
|
||||
}];
|
||||
|
||||
self.parentView.cssNode->style.padding[0] = 10;
|
||||
self.parentView.cssNode->style.padding[1] = 10;
|
||||
self.parentView.cssNode->style.padding[2] = 10;
|
||||
self.parentView.cssNode->style.padding[3] = 10;
|
||||
CSSNodeStyleSetPaddingLeft(self.parentView.cssNode, 10);
|
||||
CSSNodeStyleSetPaddingTop(self.parentView.cssNode, 10);
|
||||
CSSNodeStyleSetPaddingRight(self.parentView.cssNode, 10);
|
||||
CSSNodeStyleSetPaddingBottom(self.parentView.cssNode, 10);
|
||||
|
||||
[self.parentView insertReactSubview:headerView atIndex:0];
|
||||
[self.parentView insertReactSubview:mainView atIndex:1];
|
||||
@@ -108,10 +108,10 @@
|
||||
|
||||
- (void)testAssignsSuggestedWidthDimension
|
||||
{
|
||||
[self _withShadowViewWithStyle:^(CSSStyle *style) {
|
||||
style->position[CSSPositionLeft] = 0;
|
||||
style->position[CSSPositionTop] = 0;
|
||||
style->dimensions[CSSDimensionHeight] = 10;
|
||||
[self _withShadowViewWithStyle:^(CSSNodeRef node) {
|
||||
CSSNodeStyleSetPositionLeft(node, 0);
|
||||
CSSNodeStyleSetPositionTop(node, 0);
|
||||
CSSNodeStyleSetHeight(node, 10);
|
||||
}
|
||||
assertRelativeLayout:CGRectMake(0, 0, 3, 10)
|
||||
withIntrinsicContentSize:CGSizeMake(3, UIViewNoIntrinsicMetric)];
|
||||
@@ -119,10 +119,10 @@
|
||||
|
||||
- (void)testAssignsSuggestedHeightDimension
|
||||
{
|
||||
[self _withShadowViewWithStyle:^(CSSStyle *style) {
|
||||
style->position[CSSPositionLeft] = 0;
|
||||
style->position[CSSPositionTop] = 0;
|
||||
style->dimensions[CSSDimensionWidth] = 10;
|
||||
[self _withShadowViewWithStyle:^(CSSNodeRef node) {
|
||||
CSSNodeStyleSetPositionLeft(node, 0);
|
||||
CSSNodeStyleSetPositionTop(node, 0);
|
||||
CSSNodeStyleSetWidth(node, 10);
|
||||
}
|
||||
assertRelativeLayout:CGRectMake(0, 0, 10, 4)
|
||||
withIntrinsicContentSize:CGSizeMake(UIViewNoIntrinsicMetric, 4)];
|
||||
@@ -130,11 +130,11 @@
|
||||
|
||||
- (void)testDoesNotOverrideDimensionStyleWithSuggestedDimensions
|
||||
{
|
||||
[self _withShadowViewWithStyle:^(CSSStyle *style) {
|
||||
style->position[CSSPositionLeft] = 0;
|
||||
style->position[CSSPositionTop] = 0;
|
||||
style->dimensions[CSSDimensionWidth] = 10;
|
||||
style->dimensions[CSSDimensionHeight] = 10;
|
||||
[self _withShadowViewWithStyle:^(CSSNodeRef node) {
|
||||
CSSNodeStyleSetPositionLeft(node, 0);
|
||||
CSSNodeStyleSetPositionTop(node, 0);
|
||||
CSSNodeStyleSetWidth(node, 10);
|
||||
CSSNodeStyleSetHeight(node, 10);
|
||||
}
|
||||
assertRelativeLayout:CGRectMake(0, 0, 10, 10)
|
||||
withIntrinsicContentSize:CGSizeMake(3, 4)];
|
||||
@@ -142,20 +142,20 @@
|
||||
|
||||
- (void)testDoesNotAssignSuggestedDimensionsWhenStyledWithFlexAttribute
|
||||
{
|
||||
float parentWidth = self.parentView.cssNode->style.dimensions[CSSDimensionWidth];
|
||||
float parentHeight = self.parentView.cssNode->style.dimensions[CSSDimensionHeight];
|
||||
[self _withShadowViewWithStyle:^(CSSStyle *style) {
|
||||
style->flex = 1;
|
||||
float parentWidth = CSSNodeStyleGetWidth(self.parentView.cssNode);
|
||||
float parentHeight = CSSNodeStyleGetHeight(self.parentView.cssNode);
|
||||
[self _withShadowViewWithStyle:^(CSSNodeRef node) {
|
||||
CSSNodeStyleSetFlex(node, 1);
|
||||
}
|
||||
assertRelativeLayout:CGRectMake(0, 0, parentWidth, parentHeight)
|
||||
withIntrinsicContentSize:CGSizeMake(3, 4)];
|
||||
}
|
||||
|
||||
- (void)_withShadowViewWithStyle:(void(^)(CSSStyle *style))styleBlock
|
||||
- (void)_withShadowViewWithStyle:(void(^)(CSSNodeRef node))configBlock
|
||||
assertRelativeLayout:(CGRect)expectedRect
|
||||
withIntrinsicContentSize:(CGSize)contentSize
|
||||
{
|
||||
RCTShadowView *view = [self _shadowViewWithStyle:styleBlock];
|
||||
RCTShadowView *view = [self _shadowViewWithConfig:configBlock];
|
||||
[self.parentView insertReactSubview:view atIndex:0];
|
||||
view.intrinsicContentSize = contentSize;
|
||||
[self.parentView collectViewsWithUpdatedFrames];
|
||||
@@ -166,14 +166,10 @@
|
||||
NSStringFromCGRect(actualRect));
|
||||
}
|
||||
|
||||
- (RCTRootShadowView *)_shadowViewWithStyle:(void(^)(CSSStyle *style))styleBlock
|
||||
- (RCTRootShadowView *)_shadowViewWithConfig:(void(^)(CSSNodeRef node))configBlock
|
||||
{
|
||||
RCTRootShadowView *shadowView = [RCTRootShadowView new];
|
||||
|
||||
CSSStyle style = shadowView.cssNode->style;
|
||||
styleBlock(&style);
|
||||
shadowView.cssNode->style = style;
|
||||
|
||||
configBlock(shadowView.cssNode);
|
||||
return shadowView;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user