From eabb98cee9710a1318c29c124caf6346e023121a Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Mon, 22 Jun 2020 15:12:00 +0800 Subject: [PATCH] fix:iOS DoricListNode exception and DoricGroupNode exception --- doric-iOS/Pod/Classes/Shader/DoricGroupNode.m | 31 +++++++++++++++---- .../Pod/Classes/Shader/DoricListItemNode.m | 5 --- doric-iOS/Pod/Classes/Shader/DoricListNode.m | 3 +- 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/doric-iOS/Pod/Classes/Shader/DoricGroupNode.m b/doric-iOS/Pod/Classes/Shader/DoricGroupNode.m index ae38a5c3..f3e2839c 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricGroupNode.m +++ b/doric-iOS/Pod/Classes/Shader/DoricGroupNode.m @@ -77,7 +77,11 @@ - (void)configChildNodes { viewNode.viewId = viewId; [viewNode initWithSuperNode:self]; [viewNode blend:model[@"props"]]; - [childNodes insertObject:viewNode atIndex:idx]; + if (idx >= childNodes.count) { + [childNodes addObject:viewNode]; + } else { + [childNodes insertObject:viewNode atIndex:idx]; + } [self.view insertSubview:viewNode.view atIndex:idx]; } } else { @@ -95,9 +99,16 @@ - (void)configChildNodes { DoricViewNode *reused = childNodes[(NSUInteger) position]; [childNodes removeObjectAtIndex:(NSUInteger) position]; [childNodes removeObjectAtIndex:idx]; - [childNodes insertObject:reused atIndex:idx]; - [childNodes insertObject:oldNode atIndex:(NSUInteger) position]; - + if (idx >= childNodes.count) { + [childNodes addObject:reused]; + } else { + [childNodes insertObject:reused atIndex:idx]; + } + if (position >= childNodes.count) { + [childNodes addObject:oldNode]; + } else { + [childNodes insertObject:oldNode atIndex:(NSUInteger) position]; + } ///View swap index [reused.view removeFromSuperview]; [oldNode.view removeFromSuperview]; @@ -109,7 +120,11 @@ - (void)configChildNodes { viewNode.viewId = viewId; [viewNode initWithSuperNode:self]; [viewNode blend:model[@"props"]]; - [childNodes insertObject:viewNode atIndex:idx]; + if (idx >= childNodes.count) { + [childNodes addObject:viewNode]; + } else { + [childNodes insertObject:viewNode atIndex:idx]; + } [self.view insertSubview:viewNode.view atIndex:idx]; } } @@ -123,7 +138,11 @@ - (void)configChildNodes { viewNode.viewId = viewId; [viewNode initWithSuperNode:self]; [viewNode blend:model[@"props"]]; - [childNodes insertObject:viewNode atIndex:idx]; + if (idx >= childNodes.count) { + [childNodes addObject:viewNode]; + } else { + [childNodes insertObject:viewNode atIndex:idx]; + } [self.view insertSubview:viewNode.view atIndex:idx]; } } diff --git a/doric-iOS/Pod/Classes/Shader/DoricListItemNode.m b/doric-iOS/Pod/Classes/Shader/DoricListItemNode.m index 81eb3628..3f959540 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricListItemNode.m +++ b/doric-iOS/Pod/Classes/Shader/DoricListItemNode.m @@ -34,9 +34,4 @@ - (void)initWithSuperNode:(DoricSuperNode *)superNode { [super initWithSuperNode:superNode]; self.reusable = YES; } - -- (void)requestLayout { - [self.view.doricLayout apply]; - [super requestLayout]; -} @end diff --git a/doric-iOS/Pod/Classes/Shader/DoricListNode.m b/doric-iOS/Pod/Classes/Shader/DoricListNode.m index 33223005..c6ad8877 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricListNode.m +++ b/doric-iOS/Pod/Classes/Shader/DoricListNode.m @@ -145,6 +145,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N DoricListItemNode *node = cell.doricListItemNode; node.viewId = model[@"id"]; [node blend:props]; + [node.view.doricLayout apply:CGSizeMake(tableView.width, tableView.height)]; [node requestLayout]; [self callItem:position height:node.view.height]; return cell; @@ -220,7 +221,7 @@ - (void)blendSubNode:(NSDictionary *)subModel { - (void)callItem:(NSUInteger)position height:(CGFloat)height { NSNumber *old = self.itemHeights[@(position)]; - if (old && old.floatValue == height) { + if (old && [old isEqualToNumber:@(height)]) { return; } self.itemHeights[@(position)] = @(height);