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,8 +20,11 @@ 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: () => { startAnimation: () => {
log('startAnimation') log('startAnimation')
}, },

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,11 +129,13 @@ - (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 (CGAffineTransformEqualToTransform(child.transform, CGAffineTransformIdentity)) {
if ([child isKindOfClass:[DoricLayoutContainer class]] if ([child isKindOfClass:[DoricLayoutContainer class]]
|| childConfig.widthSpec == DoricLayoutWrapContent || childConfig.widthSpec == DoricLayoutWrapContent
|| childConfig.heightSpec == DoricLayoutWrapContent) { || childConfig.heightSpec == DoricLayoutWrapContent) {
@ -152,6 +154,9 @@ - (CGSize)sizeContent:(CGSize)size {
if (childConfig.weight) { if (childConfig.weight) {
childSize.height = child.height; 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,6 +254,7 @@ - (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 (CGAffineTransformEqualToTransform(child.transform, CGAffineTransformIdentity)) {
if ([child isKindOfClass:[DoricLayoutContainer class]] if ([child isKindOfClass:[DoricLayoutContainer class]]
|| childConfig.widthSpec == DoricLayoutWrapContent || childConfig.widthSpec == DoricLayoutWrapContent
|| childConfig.heightSpec == DoricLayoutWrapContent) { || childConfig.heightSpec == DoricLayoutWrapContent) {
@ -264,6 +273,9 @@ - (CGSize)sizeContent:(CGSize)size {
if (childConfig.weight) { if (childConfig.weight) {
childSize.height = child.height; 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;
contentWeight += childConfig.weight; contentWeight += childConfig.weight;
@ -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,6 +386,7 @@ - (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 (CGAffineTransformEqualToTransform(child.transform, CGAffineTransformIdentity)) {
if ([child isKindOfClass:[DoricLayoutContainer class]] if ([child isKindOfClass:[DoricLayoutContainer class]]
|| childConfig.widthSpec == DoricLayoutWrapContent || childConfig.widthSpec == DoricLayoutWrapContent
|| childConfig.heightSpec == DoricLayoutWrapContent) { || childConfig.heightSpec == DoricLayoutWrapContent) {
@ -389,6 +405,10 @@ - (CGSize)sizeContent:(CGSize)size {
if (childConfig.weight) { if (childConfig.weight) {
childSize.width = child.width; 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