iOS:refact requestLayout logic

This commit is contained in:
pengfei.zhou
2020-04-08 11:57:38 +08:00
committed by osborn
parent 95d9158fac
commit b17ff48c59
11 changed files with 27 additions and 46 deletions

View File

@@ -161,4 +161,9 @@ - (DoricViewNode *)subNodeWithViewId:(NSString *)viewId {
return nil;
}
- (void)requestLayout {
for (DoricViewNode *node in self.childNodes) {
[node requestLayout];
}
}
@end

View File

@@ -92,6 +92,8 @@ typedef NS_ENUM(NSInteger, DoricGravity) {
@property(nonatomic, assign) CGFloat maxHeight;
@property(nonatomic, assign) BOOL resolved;
- (instancetype)init;
- (void)apply;

View File

@@ -55,7 +55,6 @@ @interface DoricLayout ()
@property(nonatomic, assign) CGFloat measuredHeight;
@property(nonatomic, assign) CGFloat measuredX;
@property(nonatomic, assign) CGFloat measuredY;
@property(nonatomic, assign) BOOL resolved;
@end
@implementation DoricLayout

View File

@@ -141,6 +141,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
DoricListItemNode *node = cell.doricListItemNode;
node.viewId = model[@"id"];
[node blend:props];
[node requestLayout];
[self callItem:position height:node.view.height];
return cell;
}

View File

@@ -61,5 +61,6 @@ - (void)setupRootView:(UIView *)view {
- (void)requestLayout {
[self.view.doricLayout apply];
[super requestLayout];
}
@end

View File

@@ -37,7 +37,9 @@ - (void)setContentView:(UIView *)contentView {
- (CGSize)sizeThatFits:(CGSize)size {
if (self.contentView) {
[self.contentView.doricLayout apply:self.frame.size];
if (!self.contentView.doricLayout.resolved) {
[self.contentView.doricLayout apply:self.frame.size];
}
return self.contentView.frame.size;
}
return CGSizeZero;
@@ -117,6 +119,10 @@ - (void)afterBlended:(NSDictionary *)props {
}
}
- (void)requestLayout {
[self.view.contentView.doricLayout apply:self.view.frame.size];
}
- (void)blendView:(DoricScrollView *)view forPropName:(NSString *)name propValue:(id)prop {
if ([@"content" isEqualToString:name]) {
self.childViewId = prop;

View File

@@ -127,8 +127,4 @@ - (DoricViewNode *)subNodeWithViewId:(NSString *)viewId {
NSStringFromSelector(_cmd));
return nil;
}
- (void)requestLayout {
[self.view setNeedsLayout];
}
@end

View File

@@ -139,8 +139,7 @@ - (void)blend:(NSDictionary *)props {
}
[self afterBlended:props];
[self transformProperties];
[self requestLayout];
[self.gradientLayer also:^(CAGradientLayer* it) {
[self.gradientLayer also:^(CAGradientLayer *it) {
dispatch_async(dispatch_get_main_queue(), ^{
it.frame = CGRectMake(0, 0, self.view.width, self.view.height);
});
@@ -349,7 +348,6 @@ + (__kindof DoricViewNode *)create:(DoricContext *)context withType:(NSString *)
}
- (void)requestLayout {
[self.superNode requestLayout];
}
- (NSNumber *)getWidth {