feat:fix transform and layoutcontainer conflict

This commit is contained in:
pengfei.zhou 2019-11-27 11:55:49 +08:00
parent 3c04e7cde1
commit a41036c91d
7 changed files with 113 additions and 71 deletions

View File

@ -1,6 +1,5 @@
import { Group, Panel, List, text, gravity, Color, Stack, LayoutSpec, list, NativeCall, listItem, log, vlayout, Gravity, hlayout, Text, refreshable, Refreshable, ListItem } from "doric"; import { Group, Panel, List, text, gravity, Color, Stack, LayoutSpec, list, NativeCall, listItem, log, vlayout, Gravity, hlayout, Text, refreshable, Refreshable, ListItem } from "doric";
import { rotatedArrow, colors } from "./utils"; import { rotatedArrow, colors } from "./utils";
import { isObject } from "util";
@Entry @Entry
class ListPanel extends Panel { class ListPanel extends Panel {
build(rootView: Group): void { build(rootView: Group): void {

View File

@ -20,18 +20,21 @@ class RefreshableDemo extends Panel {
width: 30, width: 30,
height: 30, height: 30,
imageBase64: icon_refresh, imageBase64: icon_refresh,
}).also(v => refreshImage = v), }).also(v => {
]), { refreshImage = v
startAnimation: () => { }),
log('startAnimation') ]),
}, {
stopAnimation: () => { startAnimation: () => {
log('stopAnimation') log('startAnimation')
}, },
setProgressRotation: (rotation: number) => { stopAnimation: () => {
refreshImage.setRotation(context, rotation) log('stopAnimation')
}, },
}), setProgressRotation: (rotation: number) => {
refreshImage.setRotation(context, rotation)
},
}),
content: scroller(vlayout([ content: scroller(vlayout([
title("Refreshable Demo"), title("Refreshable Demo"),
label('start Refresh').apply({ label('start Refresh').apply({

File diff suppressed because one or more lines are too long

View File

@ -5,7 +5,7 @@
#import "DoricRefreshableNode.h" #import "DoricRefreshableNode.h"
#import "Doric.h" #import "Doric.h"
@interface DoricRefreshableNode () @interface DoricRefreshableNode () <DoricSwipePullingDelegate>
@property(nonatomic, strong) DoricViewNode *contentNode; @property(nonatomic, strong) DoricViewNode *contentNode;
@property(nonatomic, copy) NSString *contentViewId; @property(nonatomic, copy) NSString *contentViewId;
@property(nonatomic, strong) DoricViewNode *headerNode; @property(nonatomic, strong) DoricViewNode *headerNode;
@ -14,7 +14,10 @@ @interface DoricRefreshableNode ()
@implementation DoricRefreshableNode @implementation DoricRefreshableNode
- (DoricSwipeRefreshLayout *)build { - (DoricSwipeRefreshLayout *)build {
return [DoricSwipeRefreshLayout new]; return [[DoricSwipeRefreshLayout new] also:^(DoricSwipeRefreshLayout *it) {
it.swipePullingDelegate = self;
}];
} }
- (void)blendView:(DoricSwipeRefreshLayout *)view forPropName:(NSString *)name propValue:(id)prop { - (void)blendView:(DoricSwipeRefreshLayout *)view forPropName:(NSString *)name propValue:(id)prop {
@ -138,4 +141,17 @@ - (void)blendHeader {
- (void)blendSubNode:(NSDictionary *)subModel { - (void)blendSubNode:(NSDictionary *)subModel {
[[self subNodeWithViewId:subModel[@"id"]] blend:subModel[@"props"]]; [[self subNodeWithViewId:subModel[@"id"]] blend:subModel[@"props"]];
} }
- (void)startAnimation {
[self.headerNode callJSResponse:@"startAnimation", nil];
}
- (void)stopAnimation {
[self.headerNode callJSResponse:@"stopAnimation", nil];
}
- (void)setProgressRotation:(CGFloat)rotation {
[self.headerNode callJSResponse:@"setProgressRotation", @(rotation), nil];
}
@end @end

View File

@ -129,28 +129,33 @@ - (CGSize)sizeContent:(CGSize)size {
if (child.isHidden) { if (child.isHidden) {
continue; continue;
} }
DoricLayoutConfig *childConfig = child.layoutConfig; DoricLayoutConfig *childConfig = child.layoutConfig;
if (!childConfig) { if (!childConfig) {
childConfig = [DoricLayoutConfig new]; childConfig = [DoricLayoutConfig new];
} }
CGSize childSize = CGSizeMake(child.width, child.height); CGSize childSize = CGSizeMake(child.width, child.height);
if ([child isKindOfClass:[DoricLayoutContainer class]] if (CGAffineTransformEqualToTransform(child.transform, CGAffineTransformIdentity)) {
|| childConfig.widthSpec == DoricLayoutWrapContent if ([child isKindOfClass:[DoricLayoutContainer class]]
|| childConfig.heightSpec == DoricLayoutWrapContent) { || childConfig.widthSpec == DoricLayoutWrapContent
childSize = [child sizeThatFits:CGSizeMake(size.width, size.height - contentHeight)]; || childConfig.heightSpec == DoricLayoutWrapContent) {
} childSize = [child sizeThatFits:CGSizeMake(size.width, size.height - contentHeight)];
if (childConfig.widthSpec == DoricLayoutExact) { }
childSize.width = child.width; if (childConfig.widthSpec == DoricLayoutExact) {
} else if (childConfig.widthSpec == DoricLayoutAtMost) { childSize.width = child.width;
childSize.width = size.width; } else if (childConfig.widthSpec == DoricLayoutAtMost) {
} childSize.width = size.width;
if (childConfig.heightSpec == DoricLayoutExact) { }
childSize.height = child.height; if (childConfig.heightSpec == DoricLayoutExact) {
} else if (childConfig.heightSpec == DoricLayoutAtMost) { childSize.height = child.height;
childSize.height = size.height - contentHeight; } else if (childConfig.heightSpec == DoricLayoutAtMost) {
} childSize.height = size.height - contentHeight;
if (childConfig.weight) { }
childSize.height = child.height; if (childConfig.weight) {
childSize.height = child.height;
}
} else {
childSize = child.bounds.size;
} }
contentWidth = MAX(contentWidth, childSize.width + childConfig.margin.left + childConfig.margin.right); contentWidth = MAX(contentWidth, childSize.width + childConfig.margin.left + childConfig.margin.right);
contentHeight = MAX(contentHeight, childSize.height + childConfig.margin.top + childConfig.margin.bottom); contentHeight = MAX(contentHeight, childSize.height + childConfig.margin.top + childConfig.margin.bottom);
@ -167,6 +172,9 @@ - (void)layout:(CGSize)targetSize {
if (child.isHidden) { if (child.isHidden) {
continue; continue;
} }
if (!CGAffineTransformEqualToTransform(child.transform, CGAffineTransformIdentity)) {
continue;
}
DoricLayoutConfig *childConfig = child.layoutConfig; DoricLayoutConfig *childConfig = child.layoutConfig;
if (!childConfig) { if (!childConfig) {
childConfig = [DoricLayoutConfig new]; childConfig = [DoricLayoutConfig new];
@ -246,23 +254,27 @@ - (CGSize)sizeContent:(CGSize)size {
childConfig = [DoricLayoutConfig new]; childConfig = [DoricLayoutConfig new];
} }
CGSize childSize = CGSizeMake(child.width, child.height); CGSize childSize = CGSizeMake(child.width, child.height);
if ([child isKindOfClass:[DoricLayoutContainer class]] if (CGAffineTransformEqualToTransform(child.transform, CGAffineTransformIdentity)) {
|| childConfig.widthSpec == DoricLayoutWrapContent if ([child isKindOfClass:[DoricLayoutContainer class]]
|| childConfig.heightSpec == DoricLayoutWrapContent) { || childConfig.widthSpec == DoricLayoutWrapContent
childSize = [child sizeThatFits:CGSizeMake(size.width, size.height - contentHeight)]; || childConfig.heightSpec == DoricLayoutWrapContent) {
} childSize = [child sizeThatFits:CGSizeMake(size.width, size.height - contentHeight)];
if (childConfig.widthSpec == DoricLayoutExact) { }
childSize.width = child.width; if (childConfig.widthSpec == DoricLayoutExact) {
} else if (childConfig.widthSpec == DoricLayoutAtMost) { childSize.width = child.width;
childSize.width = size.width; } else if (childConfig.widthSpec == DoricLayoutAtMost) {
} childSize.width = size.width;
if (childConfig.heightSpec == DoricLayoutExact) { }
childSize.height = child.height; if (childConfig.heightSpec == DoricLayoutExact) {
} else if (childConfig.heightSpec == DoricLayoutAtMost) { childSize.height = child.height;
childSize.height = size.height - contentHeight; } else if (childConfig.heightSpec == DoricLayoutAtMost) {
} childSize.height = size.height - contentHeight;
if (childConfig.weight) { }
childSize.height = child.height; if (childConfig.weight) {
childSize.height = child.height;
}
} else {
childSize = child.bounds.size;
} }
contentWidth = MAX(contentWidth, childSize.width + childConfig.margin.left + childConfig.margin.right); contentWidth = MAX(contentWidth, childSize.width + childConfig.margin.left + childConfig.margin.right);
contentHeight += childSize.height + self.space + childConfig.margin.top + childConfig.margin.bottom; contentHeight += childSize.height + self.space + childConfig.margin.top + childConfig.margin.bottom;
@ -294,6 +306,9 @@ - (void)layout:(CGSize)targetSize {
if (child.isHidden) { if (child.isHidden) {
continue; continue;
} }
if (!CGAffineTransformEqualToTransform(child.transform, CGAffineTransformIdentity)) {
continue;
}
DoricLayoutConfig *childConfig = child.layoutConfig; DoricLayoutConfig *childConfig = child.layoutConfig;
if (!childConfig) { if (!childConfig) {
childConfig = [DoricLayoutConfig new]; childConfig = [DoricLayoutConfig new];
@ -371,24 +386,29 @@ - (CGSize)sizeContent:(CGSize)size {
childConfig = [DoricLayoutConfig new]; childConfig = [DoricLayoutConfig new];
} }
CGSize childSize = CGSizeMake(child.width, child.height); CGSize childSize = CGSizeMake(child.width, child.height);
if ([child isKindOfClass:[DoricLayoutContainer class]] if (CGAffineTransformEqualToTransform(child.transform, CGAffineTransformIdentity)) {
|| childConfig.widthSpec == DoricLayoutWrapContent if ([child isKindOfClass:[DoricLayoutContainer class]]
|| childConfig.heightSpec == DoricLayoutWrapContent) { || childConfig.widthSpec == DoricLayoutWrapContent
childSize = [child sizeThatFits:CGSizeMake(size.width - contentWidth, size.height)]; || childConfig.heightSpec == DoricLayoutWrapContent) {
} childSize = [child sizeThatFits:CGSizeMake(size.width - contentWidth, size.height)];
if (childConfig.widthSpec == DoricLayoutExact) { }
childSize.width = child.width; if (childConfig.widthSpec == DoricLayoutExact) {
} else if (childConfig.widthSpec == DoricLayoutAtMost) { childSize.width = child.width;
childSize.width = size.width - contentWidth; } else if (childConfig.widthSpec == DoricLayoutAtMost) {
} childSize.width = size.width - contentWidth;
if (childConfig.heightSpec == DoricLayoutExact) { }
childSize.height = child.height; if (childConfig.heightSpec == DoricLayoutExact) {
} else if (childConfig.heightSpec == DoricLayoutAtMost) { childSize.height = child.height;
childSize.height = size.height; } else if (childConfig.heightSpec == DoricLayoutAtMost) {
} childSize.height = size.height;
if (childConfig.weight) { }
childSize.width = child.width; if (childConfig.weight) {
childSize.width = child.width;
}
} else {
childSize = child.bounds.size;
} }
contentWidth += childSize.width + self.space + childConfig.margin.left + childConfig.margin.right; contentWidth += childSize.width + self.space + childConfig.margin.left + childConfig.margin.right;
contentHeight = MAX(contentHeight, childSize.height + childConfig.margin.top + childConfig.margin.bottom); contentHeight = MAX(contentHeight, childSize.height + childConfig.margin.top + childConfig.margin.bottom);
contentWeight += childConfig.weight; contentWeight += childConfig.weight;
@ -421,6 +441,9 @@ - (void)layout:(CGSize)targetSize {
if (child.isHidden) { if (child.isHidden) {
continue; continue;
} }
if (!CGAffineTransformEqualToTransform(child.transform, CGAffineTransformIdentity)) {
continue;
}
DoricLayoutConfig *childConfig = child.layoutConfig; DoricLayoutConfig *childConfig = child.layoutConfig;
if (!childConfig) { if (!childConfig) {
childConfig = [DoricLayoutConfig new]; childConfig = [DoricLayoutConfig new];

View File

@ -233,7 +233,11 @@ - (NSNumber *)getHeight {
} }
- (void)setRotation:(NSNumber *)rotation { - (void)setRotation:(NSNumber *)rotation {
self.view.transform = CGAffineTransformRotate(self.view.transform, M_PI * rotation.floatValue * 2); if (rotation.floatValue == 0) {
self.view.transform = CGAffineTransformIdentity;
} else {
self.view.transform = CGAffineTransformMakeRotation(M_PI * rotation.floatValue * 2);
}
} }
- (NSNumber *)getRotation { - (NSNumber *)getRotation {

View File

@ -3,7 +3,6 @@ import { List } from "./list";
import { Scroller } from "./scroller"; import { Scroller } from "./scroller";
import { BridgeContext } from "../runtime/global"; import { BridgeContext } from "../runtime/global";
import { layoutConfig } from "./declarative"; import { layoutConfig } from "./declarative";
import { Image } from "./widgets";
export interface IRefreshable extends IView { export interface IRefreshable extends IView {
content: List | Scroller content: List | Scroller