From 0889a57a680a69d9e38a259d87374e4e5a980bbf Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Tue, 10 Dec 2019 19:54:53 +0800 Subject: [PATCH] feat:async blend sub node of list --- Pod/Classes/Shader/DoricListNode.m | 44 ++++++++++++++++++------------ 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/Pod/Classes/Shader/DoricListNode.m b/Pod/Classes/Shader/DoricListNode.m index a5ff7277..668fad3a 100644 --- a/Pod/Classes/Shader/DoricListNode.m +++ b/Pod/Classes/Shader/DoricListNode.m @@ -182,29 +182,37 @@ - (NSDictionary *)itemModelAt:(NSUInteger)position { NSUInteger pos = position + idx; self.itemViewIds[@(pos)] = thisViewId; }]; - return array[0]; + if (array.count > 0) { + return array[0]; + } else { + return nil; + } } } - (void)blendSubNode:(NSDictionary *)subModel { - NSString *viewId = subModel[@"id"]; - DoricViewNode *viewNode = [self subNodeWithViewId:viewId]; - if (viewNode) { - [viewNode blend:subModel[@"props"]]; - } else { - NSMutableDictionary *model = [[self subModelOf:viewId] mutableCopy]; - [self recursiveMixin:subModel to:model]; - [self setSubModel:model in:viewId]; - } - [self.itemViewIds enumerateKeysAndObjectsUsingBlock:^(NSNumber *_Nonnull key, NSString *_Nonnull obj, BOOL *_Nonnull stop) { - if ([viewId isEqualToString:obj]) { - *stop = YES; - NSIndexPath *indexPath = [NSIndexPath indexPathForRow:[key integerValue] inSection:0]; - [UIView performWithoutAnimation:^{ - [self.view reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone]; - }]; + ///Here async blend sub node because the item count need to be applied first. + dispatch_async(dispatch_get_main_queue(), ^{ + NSString *viewId = subModel[@"id"]; + DoricViewNode *viewNode = [self subNodeWithViewId:viewId]; + if (viewNode) { + [viewNode blend:subModel[@"props"]]; + } else { + NSMutableDictionary *model = [[self subModelOf:viewId] mutableCopy]; + [self recursiveMixin:subModel to:model]; + [self setSubModel:model in:viewId]; } - }]; + [self.itemViewIds enumerateKeysAndObjectsUsingBlock:^(NSNumber *_Nonnull key, NSString *_Nonnull obj, BOOL *_Nonnull stop) { + if ([viewId isEqualToString:obj]) { + *stop = YES; + NSIndexPath *indexPath = [NSIndexPath indexPathForRow:[key integerValue] inSection:0]; + [UIView performWithoutAnimation:^{ + [self.view reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone]; + }]; + } + }]; + }); + } - (void)callItem:(NSUInteger)position height:(CGFloat)height {