From b2057a088c6de916daad68e38cf5410678979e2d Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Wed, 14 Aug 2019 11:42:47 +0800 Subject: [PATCH] doric group diff --- .../penfeizhou/doric/shader/GroupNode.java | 5 +- iOS/Pod/Classes/Shader/DoricGroupNode.m | 47 ++++++++++++------- 2 files changed, 34 insertions(+), 18 deletions(-) diff --git a/Android/doric/src/main/java/com/github/penfeizhou/doric/shader/GroupNode.java b/Android/doric/src/main/java/com/github/penfeizhou/doric/shader/GroupNode.java index b0655ea4..12a5109f 100644 --- a/Android/doric/src/main/java/com/github/penfeizhou/doric/shader/GroupNode.java +++ b/Android/doric/src/main/java/com/github/penfeizhou/doric/shader/GroupNode.java @@ -77,13 +77,14 @@ public abstract class GroupNode extends ViewNode { mIndexInfo.put(i, child); } } - - while (i < mIndexInfo.size()) { + int count = mView.getChildCount(); + while (i < count) { ViewNode node = mIndexInfo.get(i); if (node != null) { mChildrenNode.remove(node.getId()); mIndexInfo.remove(i); tobeRemoved.remove(node); + mView.removeView(node.getView()); } i++; } diff --git a/iOS/Pod/Classes/Shader/DoricGroupNode.m b/iOS/Pod/Classes/Shader/DoricGroupNode.m index 798324c1..4c9c035f 100644 --- a/iOS/Pod/Classes/Shader/DoricGroupNode.m +++ b/iOS/Pod/Classes/Shader/DoricGroupNode.m @@ -26,6 +26,7 @@ - (void)blendView:(UIView *)view forPropName:(NSString *)name propValue:(id)prop if([name isEqualToString:@"children"]) { NSArray *array = prop; NSInteger i; + NSMutableArray *tobeRemoved = [[NSMutableArray alloc] init]; for (i = 0; i< array.count; i++) { NSDictionary *val = array[i]; if (!val || (NSNull *)val == [NSNull null]) { @@ -40,11 +41,21 @@ - (void)blendView:(UIView *)view forPropName:(NSString *)name propValue:(id)prop node.parent = self; node.viewId = viewId; [self.children setObject:node forKey:viewId]; - } else if (i != node.index){ - [self.indexedChildren removeObjectAtIndex:i]; - node.index = i; - [node.view removeFromSuperview]; + } else { + if (i != node.index) { + [self.indexedChildren removeObjectAtIndex:i]; + node.index = i; + [node.view removeFromSuperview]; + } + [tobeRemoved removeObject:node]; } + DoricViewNode *old = i >= self.indexedChildren.count ? nil :[self.indexedChildren objectAtIndex:i]; + if (old && old != node) { + [old.view removeFromSuperview]; + self.indexedChildren[i] = [NSNull null]; + [tobeRemoved addObject:old]; + } + LayoutParams *params = node.layoutParams; if (params == nil) { params = [self generateDefaultLayoutParams]; @@ -54,23 +65,27 @@ - (void)blendView:(UIView *)view forPropName:(NSString *)name propValue:(id)prop if (self.indexedChildren.count <= i) { [self.view addSubview:node.view]; [self.indexedChildren addObject:node]; - }else if ([self.indexedChildren objectAtIndex:i] == nil) { + }else if ([self.indexedChildren objectAtIndex:i] == [NSNull null]) { self.indexedChildren[i] = node; [self.view insertSubview:node.view atIndex:i]; } } - - while (i < self.view.subviews.count) { - UIView *view = self.view.subviews[i]; - if (i < self.indexedChildren.count) { - DoricViewNode *node = [self.indexedChildren objectAtIndex:i]; - if (node && node.view == view) { - [self.children removeObjectForKey: node.viewId]; - [self.indexedChildren removeObjectAtIndex:i]; - [view removeFromSuperview]; - } + NSUInteger start = i; + while (start < self.indexedChildren.count) { + DoricViewNode *node = [self.indexedChildren objectAtIndex:start]; + if (node) { + [self.children removeObjectForKey: node.viewId]; + [node.view removeFromSuperview]; + [tobeRemoved removeObject:node]; } - i++; + start++; + } + if (i < self.indexedChildren.count) { + [self.indexedChildren removeObjectsInRange:NSMakeRange(i, self.indexedChildren.count - i)]; + } + + for (DoricViewNode *node in tobeRemoved) { + [self.children removeObjectForKey:node.viewId]; } } else { [super blendView:view forPropName:name propValue:prop];