From 72a4562885b87273443acd01f777a55483e66ae2 Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Wed, 20 Oct 2021 17:49:46 +0800 Subject: [PATCH] iOS: optimze when updating cell do not cause size change, do not reload --- doric-iOS/Pod/Classes/Shader/DoricFlowLayoutNode.m | 10 ++++++++++ doric-iOS/Pod/Classes/Shader/DoricInputNode.m | 5 +++++ doric-iOS/Pod/Classes/Shader/DoricListNode.m | 10 ++++++++++ doric-iOS/Pod/Classes/Shader/DoricSliderNode.m | 10 ++++++++++ 4 files changed, 35 insertions(+) diff --git a/doric-iOS/Pod/Classes/Shader/DoricFlowLayoutNode.m b/doric-iOS/Pod/Classes/Shader/DoricFlowLayoutNode.m index 6f10587d..6f04844b 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricFlowLayoutNode.m +++ b/doric-iOS/Pod/Classes/Shader/DoricFlowLayoutNode.m @@ -295,13 +295,23 @@ - (void)blendSubNode:(NSDictionary *)subModel { dispatch_async(dispatch_get_main_queue(), ^{ NSString *viewId = subModel[@"id"]; DoricViewNode *viewNode = [self subNodeWithViewId:viewId]; + BOOL skipReload = NO; if (viewNode) { + CGSize originSize = viewNode.view.frame.size; [viewNode blend:subModel[@"props"]]; + [viewNode.view.doricLayout apply]; + [viewNode requestLayout]; + if (CGSizeEqualToSize(originSize, viewNode.view.frame.size)) { + skipReload = YES; + } } else { NSMutableDictionary *model = [[self subModelOf:viewId] mutableCopy]; [self recursiveMixin:subModel to:model]; [self setSubModel:model in:viewId]; } + if (skipReload) { + return; + } [self.itemViewIds enumerateKeysAndObjectsUsingBlock:^(NSNumber *_Nonnull key, NSString *_Nonnull obj, BOOL *_Nonnull stop) { if ([viewId isEqualToString:obj]) { *stop = YES; diff --git a/doric-iOS/Pod/Classes/Shader/DoricInputNode.m b/doric-iOS/Pod/Classes/Shader/DoricInputNode.m index 2dc5a61b..8f9a0f5d 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricInputNode.m +++ b/doric-iOS/Pod/Classes/Shader/DoricInputNode.m @@ -63,6 +63,11 @@ - (instancetype)init { return self; } +- (void)setText:(NSString *)text { + [super setText:text]; + self.placeholderLabel.hidden = self.text.length > 0; +} + - (void)layoutSubviews { [super layoutSubviews]; self.placeholderLabel.hidden = self.text.length > 0; diff --git a/doric-iOS/Pod/Classes/Shader/DoricListNode.m b/doric-iOS/Pod/Classes/Shader/DoricListNode.m index b9b76ee1..249490d7 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricListNode.m +++ b/doric-iOS/Pod/Classes/Shader/DoricListNode.m @@ -279,13 +279,23 @@ - (void)blendSubNode:(NSDictionary *)subModel { dispatch_async(dispatch_get_main_queue(), ^{ NSString *viewId = subModel[@"id"]; DoricViewNode *viewNode = [self subNodeWithViewId:viewId]; + BOOL skipReload = NO; if (viewNode) { + CGSize originSize = viewNode.view.frame.size; [viewNode blend:subModel[@"props"]]; + [viewNode.view.doricLayout apply:CGSizeMake(self.view.width, self.view.height)]; + [viewNode requestLayout]; + if (CGSizeEqualToSize(originSize, viewNode.view.frame.size)) { + skipReload = YES; + } } else { NSMutableDictionary *model = [[self subModelOf:viewId] mutableCopy]; [self recursiveMixin:subModel to:model]; [self setSubModel:model in:viewId]; } + if (skipReload) { + return; + } [self.itemViewIds enumerateKeysAndObjectsUsingBlock:^(NSNumber *_Nonnull key, NSString *_Nonnull obj, BOOL *_Nonnull stop) { if ([viewId isEqualToString:obj]) { *stop = YES; diff --git a/doric-iOS/Pod/Classes/Shader/DoricSliderNode.m b/doric-iOS/Pod/Classes/Shader/DoricSliderNode.m index 2df8a692..4e8ae01e 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricSliderNode.m +++ b/doric-iOS/Pod/Classes/Shader/DoricSliderNode.m @@ -227,13 +227,23 @@ - (DoricViewNode *)subNodeWithViewId:(NSString *)viewId { - (void)blendSubNode:(NSDictionary *)subModel { NSString *viewId = subModel[@"id"]; DoricViewNode *viewNode = [self subNodeWithViewId:viewId]; + BOOL skipReload = NO; if (viewNode) { + CGSize originSize = viewNode.view.frame.size; [viewNode blend:subModel[@"props"]]; + [viewNode.view.doricLayout apply:CGSizeMake(self.view.width, self.view.height)]; + [viewNode requestLayout]; + if (CGSizeEqualToSize(originSize, viewNode.view.frame.size)) { + skipReload = YES; + } } else { NSMutableDictionary *model = [[self subModelOf:viewId] mutableCopy]; [self recursiveMixin:subModel to:model]; [self setSubModel:model in:viewId]; } + if (skipReload) { + return; + } [self.itemViewIds enumerateKeysAndObjectsUsingBlock:^(NSNumber *_Nonnull key, NSString *_Nonnull obj, BOOL *_Nonnull stop) { if ([viewId isEqualToString:obj]) { *stop = YES;