From 5babfb4c9c0e22473f14ecc737affff9d5091f82 Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Wed, 8 Apr 2020 15:20:38 +0800 Subject: [PATCH] iOS:fix Refreshable --- .../Classes/Refresh/DoricRefreshableNode.m | 7 +++- .../Classes/Refresh/DoricSwipeRefreshLayout.m | 8 +++++ doric-iOS/Pod/Classes/Shader/DoricLayouts.m | 35 +++++++++++++------ 3 files changed, 38 insertions(+), 12 deletions(-) diff --git a/doric-iOS/Pod/Classes/Refresh/DoricRefreshableNode.m b/doric-iOS/Pod/Classes/Refresh/DoricRefreshableNode.m index c49a12c6..39bbcc81 100644 --- a/doric-iOS/Pod/Classes/Refresh/DoricRefreshableNode.m +++ b/doric-iOS/Pod/Classes/Refresh/DoricRefreshableNode.m @@ -100,7 +100,6 @@ - (void)blendContent { self.view.contentView = it.view; }]; } - [self.view.contentView.doricLayout apply:self.view.frame.size]; } - (void)blendHeader { @@ -137,7 +136,13 @@ - (void)blendHeader { self.view.headerView = it.view; }]; } +} + +- (void)requestLayout { [self.view.headerView.doricLayout apply:self.view.frame.size]; + self.view.headerView.bottom = 0; + self.view.headerView.centerX = self.view.width / 2; + [self.view.contentView.doricLayout apply:self.view.frame.size]; } - (void)blendSubNode:(NSDictionary *)subModel { diff --git a/doric-iOS/Pod/Classes/Refresh/DoricSwipeRefreshLayout.m b/doric-iOS/Pod/Classes/Refresh/DoricSwipeRefreshLayout.m index c0bf7d61..9ee8941d 100644 --- a/doric-iOS/Pod/Classes/Refresh/DoricSwipeRefreshLayout.m +++ b/doric-iOS/Pod/Classes/Refresh/DoricSwipeRefreshLayout.m @@ -77,6 +77,14 @@ - (void)setHeaderView:(UIView *)headerView { self.refreshable = YES; } +- (void)layoutSubviews { + [super layoutSubviews]; + if (self.contentOffset.y != 0) { + return; + } + self.contentSize = self.frame.size; +} + - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate { if (-scrollView.contentOffset.y >= self.headerView.height) { dispatch_async(dispatch_get_main_queue(), ^{ diff --git a/doric-iOS/Pod/Classes/Shader/DoricLayouts.m b/doric-iOS/Pod/Classes/Shader/DoricLayouts.m index 6ed67e58..18496fde 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricLayouts.m +++ b/doric-iOS/Pod/Classes/Shader/DoricLayouts.m @@ -83,19 +83,25 @@ - (void)apply { } - (void)measure:(CGSize)targetSize { + CGFloat width; + CGFloat height; if (self.widthSpec == DoricLayoutMost) { - self.measuredWidth = targetSize.width; + width = self.measuredWidth = targetSize.width; + } else if (self.widthSpec == DoricLayoutJust) { + width = self.measuredWidth = self.width; } else { - self.measuredWidth = self.width; + width = targetSize.width; } if (self.heightSpec == DoricLayoutMost) { - self.measuredHeight = targetSize.height; + height = self.measuredHeight = targetSize.height; + } else if (self.heightSpec == DoricLayoutJust) { + height = self.measuredHeight = self.height; } else { - self.measuredHeight = self.height; + height = targetSize.height; } [self measureContent:CGSizeMake( - self.measuredWidth - self.paddingLeft - self.paddingRight, - self.measuredHeight - self.paddingTop - self.paddingBottom)]; + width - self.paddingLeft - self.paddingRight, + height - self.paddingTop - self.paddingBottom)]; BOOL needRemeasure = NO; if (self.maxWidth >= 0) { @@ -168,10 +174,18 @@ - (void)setFrame { [obj.doricLayout setFrame]; }]; } - self.view.width = self.measuredWidth; - self.view.height = self.measuredHeight; - self.view.x = self.measuredX; - self.view.y = self.measuredY; + if (self.view.width != self.measuredWidth) { + self.view.width = self.measuredWidth; + } + if (self.view.height != self.measuredHeight) { + self.view.height = self.measuredHeight; + } + if (self.view.x != self.measuredX) { + self.view.x = self.measuredX; + } + if (self.view.y != self.measuredY) { + self.view.y = self.measuredY; + } } - (void)measureUndefinedContent:(CGSize)targetSize { @@ -193,7 +207,6 @@ - (void)measureUndefinedContent:(CGSize)targetSize { } else { self.measuredHeight = measuredSize.height + self.paddingTop + self.paddingBottom; } - } }