From de6a094afad5484044eb75da492d01474a1972bb Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Tue, 19 Nov 2019 19:48:20 +0800 Subject: [PATCH] feat:Do not use mutable copy or copy to avoid change data pointer --- iOS/Pod/Classes/Shader/DoricListNode.m | 18 +++++++++--------- iOS/Pod/Classes/Shader/DoricSliderNode.m | 18 +++++++++--------- iOS/Pod/Classes/Shader/DoricSuperNode.m | 21 +++++++++------------ 3 files changed, 27 insertions(+), 30 deletions(-) diff --git a/iOS/Pod/Classes/Shader/DoricListNode.m b/iOS/Pod/Classes/Shader/DoricListNode.m index 10792b9b..b1aa6eb4 100644 --- a/iOS/Pod/Classes/Shader/DoricListNode.m +++ b/iOS/Pod/Classes/Shader/DoricListNode.m @@ -153,16 +153,16 @@ - (void)blendSubNode:(NSDictionary *)subModel { 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]; - }]; - } - }]; } + [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 { diff --git a/iOS/Pod/Classes/Shader/DoricSliderNode.m b/iOS/Pod/Classes/Shader/DoricSliderNode.m index 540d457c..e409dcd4 100644 --- a/iOS/Pod/Classes/Shader/DoricSliderNode.m +++ b/iOS/Pod/Classes/Shader/DoricSliderNode.m @@ -171,16 +171,16 @@ - (void)blendSubNode:(NSDictionary *)subModel { 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 reloadItemsAtIndexPaths:@[indexPath]]; - }]; - } - }]; } + [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 reloadItemsAtIndexPaths:@[indexPath]]; + }]; + } + }]; } - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { diff --git a/iOS/Pod/Classes/Shader/DoricSuperNode.m b/iOS/Pod/Classes/Shader/DoricSuperNode.m index 029d38c3..4f4b73d8 100644 --- a/iOS/Pod/Classes/Shader/DoricSuperNode.m +++ b/iOS/Pod/Classes/Shader/DoricSuperNode.m @@ -35,7 +35,7 @@ - (instancetype)initWithContext:(DoricContext *)doricContext { - (void)blendView:(UIView *)view forPropName:(NSString *)name propValue:(id)prop { if ([@"subviews" isEqualToString:name]) { NSArray *subviews = prop; - for (NSDictionary *subModel in subviews) { + for (NSMutableDictionary *subModel in subviews) { [self mixinSubNode:subModel]; [self blendSubNode:subModel]; } @@ -44,55 +44,52 @@ - (void)blendView:(UIView *)view forPropName:(NSString *)name propValue:(id)prop } } -- (void)mixinSubNode:(NSDictionary *)dictionary { +- (void)mixinSubNode:(NSMutableDictionary *)dictionary { NSString *viewId = dictionary[@"id"]; NSMutableDictionary *oldModel = self.subNodes[viewId]; if (oldModel) { [self mixin:dictionary to:oldModel]; } else { - self.subNodes[viewId] = [dictionary mutableCopy]; + self.subNodes[viewId] = dictionary; } } - (void)mixin:(NSDictionary *)srcModel to:(NSMutableDictionary *)targetModel { NSDictionary *srcProp = srcModel[@"props"]; - NSMutableDictionary *targetProp = [targetModel[@"props"] mutableCopy]; + NSMutableDictionary *targetProp = targetModel[@"props"]; [srcProp enumerateKeysAndObjectsUsingBlock:^(NSString *key, id obj, BOOL *stop) { if (![@"subviews" isEqualToString:key]) { targetProp[key] = obj; } }]; - targetModel[@"props"] = [targetProp copy]; + targetModel[@"props"] = targetProp; } - (void)recursiveMixin:(NSDictionary *)srcModel to:(NSMutableDictionary *)targetModel { NSDictionary *srcProp = srcModel[@"props"]; - NSMutableDictionary *targetProp = [targetModel[@"props"] mutableCopy]; - NSArray *targetOri = targetProp[@"subviews"]; + NSMutableDictionary *targetProp = targetModel[@"props"]; + NSMutableArray *targetOri = targetProp[@"subviews"]; [srcProp enumerateKeysAndObjectsUsingBlock:^(NSString *key, id obj, BOOL *stop) { if ([@"subviews" isEqualToString:key]) { NSArray *subviews = obj; - NSMutableArray *targetSubviews = [targetOri mutableCopy]; if (subviews) { for (NSDictionary *subview in subviews) { NSString *viewId = subview[@"id"]; - [targetSubviews enumerateObjectsUsingBlock:^(NSDictionary *obj, NSUInteger idx, BOOL *stop) { + [targetOri enumerateObjectsUsingBlock:^(NSDictionary *obj, NSUInteger idx, BOOL *stop) { if ([viewId isEqualToString:obj[@"id"]]) { NSMutableDictionary *mutableDictionary = [obj mutableCopy]; [self recursiveMixin:subview to:mutableDictionary]; - targetSubviews[idx] = [mutableDictionary copy]; + targetOri[idx] = [mutableDictionary copy]; *stop = YES; } }]; } - targetProp[@"subviews"] = [targetSubviews copy]; } } else { targetProp[key] = obj; } }]; - targetModel[@"props"] = [targetProp copy]; } - (void)blendSubNode:(DoricViewNode *)subNode layoutConfig:(NSDictionary *)layoutConfig {