iOS:refact requestLayout logic
This commit is contained in:
parent
95d9158fac
commit
b17ff48c59
@ -41,9 +41,11 @@ - (void)render:(NSDictionary *)argument withPromise:(DoricPromise *)promise {
|
||||
if (self.doricContext.rootNode.viewId == nil) {
|
||||
self.doricContext.rootNode.viewId = viewId;
|
||||
[self.doricContext.rootNode blend:argument[@"props"]];
|
||||
[self.doricContext.rootNode requestLayout];
|
||||
} else {
|
||||
DoricViewNode *viewNode = [self.doricContext targetViewNode:viewId];
|
||||
[viewNode blend:argument[@"props"]];
|
||||
[viewNode requestLayout];
|
||||
}
|
||||
[promise resolve:nil];
|
||||
});
|
||||
|
@ -31,7 +31,6 @@ @implementation DoricRefreshableNode
|
||||
- (DoricSwipeRefreshLayout *)build {
|
||||
return [[DoricSwipeRefreshLayout new] also:^(DoricSwipeRefreshLayout *it) {
|
||||
it.swipePullingDelegate = self;
|
||||
|
||||
}];
|
||||
}
|
||||
|
||||
@ -62,8 +61,7 @@ - (DoricViewNode *)subNodeWithViewId:(NSString *)viewId {
|
||||
}
|
||||
}
|
||||
|
||||
- (void)blend:(NSDictionary *)props {
|
||||
[super blend:props];
|
||||
- (void)afterBlended:(NSDictionary *)props {
|
||||
[self blendContent];
|
||||
[self blendHeader];
|
||||
}
|
||||
@ -102,6 +100,7 @@ - (void)blendContent {
|
||||
self.view.contentView = it.view;
|
||||
}];
|
||||
}
|
||||
[self.view.contentView.doricLayout apply:self.view.frame.size];
|
||||
}
|
||||
|
||||
- (void)blendHeader {
|
||||
@ -138,6 +137,7 @@ - (void)blendHeader {
|
||||
self.view.headerView = it.view;
|
||||
}];
|
||||
}
|
||||
[self.view.headerView.doricLayout apply:self.view.frame.size];
|
||||
}
|
||||
|
||||
- (void)blendSubNode:(NSDictionary *)subModel {
|
||||
|
@ -20,7 +20,6 @@
|
||||
#import "DoricSwipeRefreshLayout.h"
|
||||
#import "UIView+Doric.h"
|
||||
#import "DoricLayouts.h"
|
||||
#import "Doric.h"
|
||||
|
||||
@interface DoricSwipeRefreshLayout () <UIScrollViewDelegate>
|
||||
|
||||
@ -54,41 +53,13 @@ - (instancetype)init {
|
||||
return self;
|
||||
}
|
||||
|
||||
//- (CGSize)sizeThatFits:(CGSize)size {
|
||||
// if (self.contentView) {
|
||||
// return [self.contentView measureSize:size];
|
||||
// }
|
||||
// return CGSizeZero;
|
||||
//}
|
||||
//
|
||||
//- (BOOL)requestFromSubview:(UIView *)subview {
|
||||
// if (subview == self.headerView) {
|
||||
// return NO;
|
||||
// }
|
||||
// return [super requestFromSubview:subview];
|
||||
//}
|
||||
|
||||
- (void)layoutSubviews {
|
||||
[super layoutSubviews];
|
||||
- (CGSize)sizeThatFits:(CGSize)size {
|
||||
if (self.contentView) {
|
||||
return self.contentView.frame.size;
|
||||
}
|
||||
return CGSizeZero;
|
||||
}
|
||||
|
||||
//- (void)layoutSelf:(CGSize)targetSize {
|
||||
// if (self.contentOffset.y != 0) {
|
||||
// return;
|
||||
// }
|
||||
// self.width = targetSize.width;
|
||||
// self.height = targetSize.height;
|
||||
// [self.headerView also:^(UIView *it) {
|
||||
// [it layoutSelf:[it measureSize:targetSize]];
|
||||
// it.bottom = 0;
|
||||
// it.centerX = self.centerX;
|
||||
// }];
|
||||
// [self.contentView also:^(UIView *it) {
|
||||
// [it layoutSelf:targetSize];
|
||||
// }];
|
||||
// self.contentSize = self.frame.size;
|
||||
//}
|
||||
|
||||
- (void)setContentView:(UIView *)contentView {
|
||||
if (_contentView) {
|
||||
[_contentView removeFromSuperview];
|
||||
|
@ -161,4 +161,9 @@ - (DoricViewNode *)subNodeWithViewId:(NSString *)viewId {
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void)requestLayout {
|
||||
for (DoricViewNode *node in self.childNodes) {
|
||||
[node requestLayout];
|
||||
}
|
||||
}
|
||||
@end
|
||||
|
@ -92,6 +92,8 @@ typedef NS_ENUM(NSInteger, DoricGravity) {
|
||||
|
||||
@property(nonatomic, assign) CGFloat maxHeight;
|
||||
|
||||
@property(nonatomic, assign) BOOL resolved;
|
||||
|
||||
- (instancetype)init;
|
||||
|
||||
- (void)apply;
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -61,5 +61,6 @@ - (void)setupRootView:(UIView *)view {
|
||||
|
||||
- (void)requestLayout {
|
||||
[self.view.doricLayout apply];
|
||||
[super requestLayout];
|
||||
}
|
||||
@end
|
||||
|
@ -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;
|
||||
|
@ -127,8 +127,4 @@ - (DoricViewNode *)subNodeWithViewId:(NSString *)viewId {
|
||||
NSStringFromSelector(_cmd));
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void)requestLayout {
|
||||
[self.view setNeedsLayout];
|
||||
}
|
||||
@end
|
||||
|
@ -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 {
|
||||
|
Reference in New Issue
Block a user