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) {
|
if (self.doricContext.rootNode.viewId == nil) {
|
||||||
self.doricContext.rootNode.viewId = viewId;
|
self.doricContext.rootNode.viewId = viewId;
|
||||||
[self.doricContext.rootNode blend:argument[@"props"]];
|
[self.doricContext.rootNode blend:argument[@"props"]];
|
||||||
|
[self.doricContext.rootNode requestLayout];
|
||||||
} else {
|
} else {
|
||||||
DoricViewNode *viewNode = [self.doricContext targetViewNode:viewId];
|
DoricViewNode *viewNode = [self.doricContext targetViewNode:viewId];
|
||||||
[viewNode blend:argument[@"props"]];
|
[viewNode blend:argument[@"props"]];
|
||||||
|
[viewNode requestLayout];
|
||||||
}
|
}
|
||||||
[promise resolve:nil];
|
[promise resolve:nil];
|
||||||
});
|
});
|
||||||
|
@ -31,7 +31,6 @@ @implementation DoricRefreshableNode
|
|||||||
- (DoricSwipeRefreshLayout *)build {
|
- (DoricSwipeRefreshLayout *)build {
|
||||||
return [[DoricSwipeRefreshLayout new] also:^(DoricSwipeRefreshLayout *it) {
|
return [[DoricSwipeRefreshLayout new] also:^(DoricSwipeRefreshLayout *it) {
|
||||||
it.swipePullingDelegate = self;
|
it.swipePullingDelegate = self;
|
||||||
|
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,8 +61,7 @@ - (DoricViewNode *)subNodeWithViewId:(NSString *)viewId {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)blend:(NSDictionary *)props {
|
- (void)afterBlended:(NSDictionary *)props {
|
||||||
[super blend:props];
|
|
||||||
[self blendContent];
|
[self blendContent];
|
||||||
[self blendHeader];
|
[self blendHeader];
|
||||||
}
|
}
|
||||||
@ -102,6 +100,7 @@ - (void)blendContent {
|
|||||||
self.view.contentView = it.view;
|
self.view.contentView = it.view;
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
[self.view.contentView.doricLayout apply:self.view.frame.size];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)blendHeader {
|
- (void)blendHeader {
|
||||||
@ -138,6 +137,7 @@ - (void)blendHeader {
|
|||||||
self.view.headerView = it.view;
|
self.view.headerView = it.view;
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
[self.view.headerView.doricLayout apply:self.view.frame.size];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)blendSubNode:(NSDictionary *)subModel {
|
- (void)blendSubNode:(NSDictionary *)subModel {
|
||||||
|
@ -20,7 +20,6 @@
|
|||||||
#import "DoricSwipeRefreshLayout.h"
|
#import "DoricSwipeRefreshLayout.h"
|
||||||
#import "UIView+Doric.h"
|
#import "UIView+Doric.h"
|
||||||
#import "DoricLayouts.h"
|
#import "DoricLayouts.h"
|
||||||
#import "Doric.h"
|
|
||||||
|
|
||||||
@interface DoricSwipeRefreshLayout () <UIScrollViewDelegate>
|
@interface DoricSwipeRefreshLayout () <UIScrollViewDelegate>
|
||||||
|
|
||||||
@ -54,41 +53,13 @@ - (instancetype)init {
|
|||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
//- (CGSize)sizeThatFits:(CGSize)size {
|
- (CGSize)sizeThatFits:(CGSize)size {
|
||||||
// if (self.contentView) {
|
if (self.contentView) {
|
||||||
// return [self.contentView measureSize:size];
|
return self.contentView.frame.size;
|
||||||
// }
|
}
|
||||||
// return CGSizeZero;
|
return CGSizeZero;
|
||||||
//}
|
|
||||||
//
|
|
||||||
//- (BOOL)requestFromSubview:(UIView *)subview {
|
|
||||||
// if (subview == self.headerView) {
|
|
||||||
// return NO;
|
|
||||||
// }
|
|
||||||
// return [super requestFromSubview:subview];
|
|
||||||
//}
|
|
||||||
|
|
||||||
- (void)layoutSubviews {
|
|
||||||
[super layoutSubviews];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//- (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 {
|
- (void)setContentView:(UIView *)contentView {
|
||||||
if (_contentView) {
|
if (_contentView) {
|
||||||
[_contentView removeFromSuperview];
|
[_contentView removeFromSuperview];
|
||||||
|
@ -161,4 +161,9 @@ - (DoricViewNode *)subNodeWithViewId:(NSString *)viewId {
|
|||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)requestLayout {
|
||||||
|
for (DoricViewNode *node in self.childNodes) {
|
||||||
|
[node requestLayout];
|
||||||
|
}
|
||||||
|
}
|
||||||
@end
|
@end
|
||||||
|
@ -92,6 +92,8 @@ typedef NS_ENUM(NSInteger, DoricGravity) {
|
|||||||
|
|
||||||
@property(nonatomic, assign) CGFloat maxHeight;
|
@property(nonatomic, assign) CGFloat maxHeight;
|
||||||
|
|
||||||
|
@property(nonatomic, assign) BOOL resolved;
|
||||||
|
|
||||||
- (instancetype)init;
|
- (instancetype)init;
|
||||||
|
|
||||||
- (void)apply;
|
- (void)apply;
|
||||||
|
@ -55,7 +55,6 @@ @interface DoricLayout ()
|
|||||||
@property(nonatomic, assign) CGFloat measuredHeight;
|
@property(nonatomic, assign) CGFloat measuredHeight;
|
||||||
@property(nonatomic, assign) CGFloat measuredX;
|
@property(nonatomic, assign) CGFloat measuredX;
|
||||||
@property(nonatomic, assign) CGFloat measuredY;
|
@property(nonatomic, assign) CGFloat measuredY;
|
||||||
@property(nonatomic, assign) BOOL resolved;
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation DoricLayout
|
@implementation DoricLayout
|
||||||
|
@ -141,6 +141,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
|
|||||||
DoricListItemNode *node = cell.doricListItemNode;
|
DoricListItemNode *node = cell.doricListItemNode;
|
||||||
node.viewId = model[@"id"];
|
node.viewId = model[@"id"];
|
||||||
[node blend:props];
|
[node blend:props];
|
||||||
|
[node requestLayout];
|
||||||
[self callItem:position height:node.view.height];
|
[self callItem:position height:node.view.height];
|
||||||
return cell;
|
return cell;
|
||||||
}
|
}
|
||||||
|
@ -61,5 +61,6 @@ - (void)setupRootView:(UIView *)view {
|
|||||||
|
|
||||||
- (void)requestLayout {
|
- (void)requestLayout {
|
||||||
[self.view.doricLayout apply];
|
[self.view.doricLayout apply];
|
||||||
|
[super requestLayout];
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
@ -37,7 +37,9 @@ - (void)setContentView:(UIView *)contentView {
|
|||||||
|
|
||||||
- (CGSize)sizeThatFits:(CGSize)size {
|
- (CGSize)sizeThatFits:(CGSize)size {
|
||||||
if (self.contentView) {
|
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 self.contentView.frame.size;
|
||||||
}
|
}
|
||||||
return CGSizeZero;
|
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 {
|
- (void)blendView:(DoricScrollView *)view forPropName:(NSString *)name propValue:(id)prop {
|
||||||
if ([@"content" isEqualToString:name]) {
|
if ([@"content" isEqualToString:name]) {
|
||||||
self.childViewId = prop;
|
self.childViewId = prop;
|
||||||
|
@ -127,8 +127,4 @@ - (DoricViewNode *)subNodeWithViewId:(NSString *)viewId {
|
|||||||
NSStringFromSelector(_cmd));
|
NSStringFromSelector(_cmd));
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)requestLayout {
|
|
||||||
[self.view setNeedsLayout];
|
|
||||||
}
|
|
||||||
@end
|
@end
|
||||||
|
@ -139,8 +139,7 @@ - (void)blend:(NSDictionary *)props {
|
|||||||
}
|
}
|
||||||
[self afterBlended:props];
|
[self afterBlended:props];
|
||||||
[self transformProperties];
|
[self transformProperties];
|
||||||
[self requestLayout];
|
[self.gradientLayer also:^(CAGradientLayer *it) {
|
||||||
[self.gradientLayer also:^(CAGradientLayer* it) {
|
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
it.frame = CGRectMake(0, 0, self.view.width, self.view.height);
|
it.frame = CGRectMake(0, 0, self.view.width, self.view.height);
|
||||||
});
|
});
|
||||||
@ -349,7 +348,6 @@ + (__kindof DoricViewNode *)create:(DoricContext *)context withType:(NSString *)
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)requestLayout {
|
- (void)requestLayout {
|
||||||
[self.superNode requestLayout];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSNumber *)getWidth {
|
- (NSNumber *)getWidth {
|
||||||
|
Reference in New Issue
Block a user