doric group diff

This commit is contained in:
pengfei.zhou 2019-08-14 11:42:47 +08:00
parent 0fa9c86ef8
commit b2057a088c
2 changed files with 34 additions and 18 deletions

View File

@ -77,13 +77,14 @@ public abstract class GroupNode<F extends ViewGroup> extends ViewNode<F> {
mIndexInfo.put(i, child); mIndexInfo.put(i, child);
} }
} }
int count = mView.getChildCount();
while (i < mIndexInfo.size()) { while (i < count) {
ViewNode node = mIndexInfo.get(i); ViewNode node = mIndexInfo.get(i);
if (node != null) { if (node != null) {
mChildrenNode.remove(node.getId()); mChildrenNode.remove(node.getId());
mIndexInfo.remove(i); mIndexInfo.remove(i);
tobeRemoved.remove(node); tobeRemoved.remove(node);
mView.removeView(node.getView());
} }
i++; i++;
} }

View File

@ -26,6 +26,7 @@ - (void)blendView:(UIView *)view forPropName:(NSString *)name propValue:(id)prop
if([name isEqualToString:@"children"]) { if([name isEqualToString:@"children"]) {
NSArray *array = prop; NSArray *array = prop;
NSInteger i; NSInteger i;
NSMutableArray *tobeRemoved = [[NSMutableArray alloc] init];
for (i = 0; i< array.count; i++) { for (i = 0; i< array.count; i++) {
NSDictionary *val = array[i]; NSDictionary *val = array[i];
if (!val || (NSNull *)val == [NSNull null]) { if (!val || (NSNull *)val == [NSNull null]) {
@ -40,11 +41,21 @@ - (void)blendView:(UIView *)view forPropName:(NSString *)name propValue:(id)prop
node.parent = self; node.parent = self;
node.viewId = viewId; node.viewId = viewId;
[self.children setObject:node forKey:viewId]; [self.children setObject:node forKey:viewId];
} else if (i != node.index){ } else {
if (i != node.index) {
[self.indexedChildren removeObjectAtIndex:i]; [self.indexedChildren removeObjectAtIndex:i];
node.index = i; node.index = i;
[node.view removeFromSuperview]; [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; LayoutParams *params = node.layoutParams;
if (params == nil) { if (params == nil) {
params = [self generateDefaultLayoutParams]; params = [self generateDefaultLayoutParams];
@ -54,23 +65,27 @@ - (void)blendView:(UIView *)view forPropName:(NSString *)name propValue:(id)prop
if (self.indexedChildren.count <= i) { if (self.indexedChildren.count <= i) {
[self.view addSubview:node.view]; [self.view addSubview:node.view];
[self.indexedChildren addObject:node]; [self.indexedChildren addObject:node];
}else if ([self.indexedChildren objectAtIndex:i] == nil) { }else if ([self.indexedChildren objectAtIndex:i] == [NSNull null]) {
self.indexedChildren[i] = node; self.indexedChildren[i] = node;
[self.view insertSubview:node.view atIndex:i]; [self.view insertSubview:node.view atIndex:i];
} }
} }
NSUInteger start = i;
while (i < self.view.subviews.count) { while (start < self.indexedChildren.count) {
UIView *view = self.view.subviews[i]; DoricViewNode *node = [self.indexedChildren objectAtIndex:start];
if (i < self.indexedChildren.count) { if (node) {
DoricViewNode *node = [self.indexedChildren objectAtIndex:i];
if (node && node.view == view) {
[self.children removeObjectForKey: node.viewId]; [self.children removeObjectForKey: node.viewId];
[self.indexedChildren removeObjectAtIndex:i]; [node.view removeFromSuperview];
[view removeFromSuperview]; [tobeRemoved removeObject:node];
} }
start++;
} }
i++; 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 { } else {
[super blendView:view forPropName:name propValue:prop]; [super blendView:view forPropName:name propValue:prop];