From 60c8651e10924ddae9933d6ef513a96c9b477405 Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Wed, 27 Oct 2021 16:03:11 +0800 Subject: [PATCH] iOS: reset view node when reuse this node --- .../Pod/Classes/Shader/DoricFlowLayoutNode.m | 11 ++++++++ doric-iOS/Pod/Classes/Shader/DoricImageNode.m | 12 +++++++++ doric-iOS/Pod/Classes/Shader/DoricInputNode.m | 16 ++++++++++++ doric-iOS/Pod/Classes/Shader/DoricListNode.m | 12 +++++++++ .../Classes/Shader/DoricNestedSliderNode.m | 7 ++++++ .../Pod/Classes/Shader/DoricScrollerNode.m | 7 ++++++ .../Pod/Classes/Shader/DoricSliderNode.m | 8 ++++++ .../Pod/Classes/Shader/DoricSwitchNode.m | 6 +++++ doric-iOS/Pod/Classes/Shader/DoricTextNode.m | 13 ++++++++++ doric-iOS/Pod/Classes/Shader/DoricViewNode.h | 2 ++ doric-iOS/Pod/Classes/Shader/DoricViewNode.m | 25 +++++++++++++++++++ 11 files changed, 119 insertions(+) diff --git a/doric-iOS/Pod/Classes/Shader/DoricFlowLayoutNode.m b/doric-iOS/Pod/Classes/Shader/DoricFlowLayoutNode.m index 6f04844b..d19b1748 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricFlowLayoutNode.m +++ b/doric-iOS/Pod/Classes/Shader/DoricFlowLayoutNode.m @@ -526,4 +526,15 @@ - (NSArray *)findCompletelyVisibleItems { }]; } + +- (void)reset { + [super reset]; + self.view.scrollEnabled = YES; + self.renderItemFuncId = nil; + self.onLoadMoreFuncId = nil; + self.loadMoreViewId = nil; + self.onScrollFuncId = nil; + self.onScrollEndFuncId = nil; + self.loadMore = NO; +} @end diff --git a/doric-iOS/Pod/Classes/Shader/DoricImageNode.m b/doric-iOS/Pod/Classes/Shader/DoricImageNode.m index 683e0692..a0523d02 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricImageNode.m +++ b/doric-iOS/Pod/Classes/Shader/DoricImageNode.m @@ -625,4 +625,16 @@ - (void)startAnimating { - (void)stopAnimating { [self.view stopAnimating]; } + +- (void)reset { + [super reset]; + self.view.image = nil; + self.loadCallbackId = nil; + self.placeHolderColor = nil; + self.placeHolderImage = nil; + self.placeHolderImageBase64 = nil; + self.errorColor = nil; + self.errorImage = nil; + self.errorImageBase64 = nil; +} @end diff --git a/doric-iOS/Pod/Classes/Shader/DoricInputNode.m b/doric-iOS/Pod/Classes/Shader/DoricInputNode.m index 8f9a0f5d..c522481b 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricInputNode.m +++ b/doric-iOS/Pod/Classes/Shader/DoricInputNode.m @@ -659,4 +659,20 @@ - (BOOL)textFieldShouldReturn:(UITextField *)textField { } } +- (void)reset { + [super reset]; + self.view.multiline = NO; + self.view.text = nil; + self.view.font = nil; + self.view.secureTextEntry = NO; + self.view.textAlignment = NSTextAlignmentNatural; + self.view.hintText = nil; + self.view.hintTextColor = UIColor.grayColor; + self.view.hintFont = nil; + self.view.editable = YES; + self.onFocusChange = nil; + self.onSubmitEditing = nil; + self.onTextChange = nil; + self.maxLength = nil; +} @end diff --git a/doric-iOS/Pod/Classes/Shader/DoricListNode.m b/doric-iOS/Pod/Classes/Shader/DoricListNode.m index 249490d7..207784ef 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricListNode.m +++ b/doric-iOS/Pod/Classes/Shader/DoricListNode.m @@ -472,4 +472,16 @@ - (NSArray *)findCompletelyVisibleItems { return @([self.view indexPathForCell:obj].row); }]; } + +- (void)reset { + [super reset]; + self.view.scrollEnabled = YES; + self.renderItemFuncId = nil; + self.onLoadMoreFuncId = nil; + self.loadMoreViewId = nil; + self.onScrollFuncId = nil; + self.onScrollEndFuncId = nil; + self.loadMore = NO; +} + @end diff --git a/doric-iOS/Pod/Classes/Shader/DoricNestedSliderNode.m b/doric-iOS/Pod/Classes/Shader/DoricNestedSliderNode.m index 7e25534a..5c48dee5 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricNestedSliderNode.m +++ b/doric-iOS/Pod/Classes/Shader/DoricNestedSliderNode.m @@ -93,4 +93,11 @@ - (NSNumber *)getSlidedPage { NSUInteger pageIndex = (NSUInteger) (self.view.contentOffset.x / self.view.width); return @(pageIndex); } + +- (void)reset { + [super reset]; + self.view.scrollEnabled = YES; + self.onPageSelectedFuncId = nil; +} + @end diff --git a/doric-iOS/Pod/Classes/Shader/DoricScrollerNode.m b/doric-iOS/Pod/Classes/Shader/DoricScrollerNode.m index a3b2dedf..13a2f4d1 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricScrollerNode.m +++ b/doric-iOS/Pod/Classes/Shader/DoricScrollerNode.m @@ -231,4 +231,11 @@ - (void)removeDidScrollBlock:(__nonnull DoricDidScrollBlock)didScrollListener { [self.didScrollBlocks removeObject:didScrollListener]; } +- (void)reset { + [super reset]; + self.view.scrollEnabled = YES; + self.onScrollEndFuncId = nil; + self.onScrollFuncId = nil; + self.view.scrollEnabled = YES; +} @end diff --git a/doric-iOS/Pod/Classes/Shader/DoricSliderNode.m b/doric-iOS/Pod/Classes/Shader/DoricSliderNode.m index 4e8ae01e..034a5df1 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricSliderNode.m +++ b/doric-iOS/Pod/Classes/Shader/DoricSliderNode.m @@ -305,4 +305,12 @@ - (NSNumber *)getSlidedPage { } } +- (void)reset { + [super reset]; + self.view.scrollEnabled = YES; + self.onPageSelectedFuncId = nil; + self.view.scrollEnabled = YES; + self.propRenderPageFuncId = nil; + self.renderPageFuncId = nil; +} @end diff --git a/doric-iOS/Pod/Classes/Shader/DoricSwitchNode.m b/doric-iOS/Pod/Classes/Shader/DoricSwitchNode.m index 7883bb89..d1dc1999 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricSwitchNode.m +++ b/doric-iOS/Pod/Classes/Shader/DoricSwitchNode.m @@ -70,4 +70,10 @@ - (void)blendView:(UISwitch *)view forPropName:(NSString *)name propValue:(id)pr - (NSNumber *)getState { return @(self.view.isOn); } + +- (void)reset { + [super reset]; + self.view.on = NO; + self.onSwitchFuncId = nil; +} @end diff --git a/doric-iOS/Pod/Classes/Shader/DoricTextNode.m b/doric-iOS/Pod/Classes/Shader/DoricTextNode.m index 3a9bf44b..65825140 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricTextNode.m +++ b/doric-iOS/Pod/Classes/Shader/DoricTextNode.m @@ -344,4 +344,17 @@ - (UIImage *)gradientImageFromColors:(NSArray *)colors return image; } } + +- (void)reset { + [super reset]; + self.view.text = nil; + self.view.font = nil; + self.view.textColor = UIColor.blackColor; + self.view.textAlignment = NSTextAlignmentNatural; + self.view.numberOfLines = 1; + self.view.layer.shadowOpacity = 0; + self.view.layer.shadowRadius = 3; + self.view.layer.shadowOffset = CGSizeMake(0, -3); + self.view.lineBreakMode = NSLineBreakByTruncatingTail; +} @end diff --git a/doric-iOS/Pod/Classes/Shader/DoricViewNode.h b/doric-iOS/Pod/Classes/Shader/DoricViewNode.h index b89450a8..ab1b9758 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricViewNode.h +++ b/doric-iOS/Pod/Classes/Shader/DoricViewNode.h @@ -57,4 +57,6 @@ - (void)blendLayoutConfig:(NSDictionary *)params; - (void)afterBlended:(NSDictionary *)props; + +- (void)reset; @end diff --git a/doric-iOS/Pod/Classes/Shader/DoricViewNode.m b/doric-iOS/Pod/Classes/Shader/DoricViewNode.m index c39738b9..de96753c 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricViewNode.m +++ b/doric-iOS/Pod/Classes/Shader/DoricViewNode.m @@ -103,6 +103,9 @@ - (UIView *)build { } - (void)blend:(NSDictionary *)props { + if (self.superNode.reusable) { + [self reset]; + } for (NSString *key in props) { id value = props[key]; if (!value || [value isKindOfClass:[NSNull class]]) { @@ -928,4 +931,26 @@ - (CAMediaTimingFunction *)translateToTimingFunction:(NSNumber *)timingFunction } } +- (void)reset { + self.view.backgroundColor = UIColor.clearColor; + self.view.doricLayout = [[DoricLayout new] also:^(DoricLayout *it) { + it.view = self.view; + }]; + + self.view.alpha = 1.0f; + self.view.hidden = NO; + self.view.layer.transform = CATransform3DIdentity; + self.view.transform = CGAffineTransformIdentity; + + self.view.layer.cornerRadius = 0; + self.view.layer.mask = nil; + self.view.layer.borderWidth = 0; + self.view.layer.borderColor = UIColor.clearColor.CGColor; + for (UIGestureRecognizer *gestureRecognizer in self.view.gestureRecognizers) { + if ([gestureRecognizer isKindOfClass:UITapGestureRecognizer.class]) { + [self.view removeGestureRecognizer:gestureRecognizer]; + } + } +} + @end