feat:fix subitem mixin of listitemnode in iOS
This commit is contained in:
@@ -52,6 +52,8 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
- (void)connectDevKit:(NSString *)url;
|
||||
|
||||
- (void)disconnectDevKit;
|
||||
|
||||
- (void)ensureSyncInMainQueue:(dispatch_block_t)block;
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
@@ -183,4 +183,11 @@ - (void)disconnectDevKit {
|
||||
}
|
||||
}
|
||||
|
||||
- (void)ensureSyncInMainQueue:(dispatch_block_t)block {
|
||||
if (strcmp(dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL), dispatch_queue_get_label(dispatch_get_main_queue())) == 0) {
|
||||
block();
|
||||
} else {
|
||||
dispatch_async(dispatch_get_main_queue(), block);
|
||||
}
|
||||
}
|
||||
@end
|
||||
|
@@ -129,15 +129,23 @@ - (NSDictionary *)itemModelAt:(NSUInteger)position {
|
||||
|
||||
- (void)blendSubNode:(NSDictionary *)subModel {
|
||||
NSString *viewId = subModel[@"id"];
|
||||
[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];
|
||||
}];
|
||||
}
|
||||
}];
|
||||
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 {
|
||||
@@ -154,7 +162,7 @@ - (void)callItem:(NSUInteger)position height:(CGFloat)height {
|
||||
|
||||
- (DoricViewNode *)subNodeWithViewId:(NSString *)viewId {
|
||||
__block DoricViewNode *ret = nil;
|
||||
dispatch_sync(dispatch_get_main_queue(), ^{
|
||||
[self.doricContext.driver ensureSyncInMainQueue:^{
|
||||
for (UITableViewCell *tableViewCell in self.view.visibleCells) {
|
||||
if ([tableViewCell isKindOfClass:[DoricTableViewCell class]]) {
|
||||
DoricListItemNode *node = ((DoricTableViewCell *) tableViewCell).doricListItemNode;
|
||||
@@ -164,7 +172,7 @@ - (DoricViewNode *)subNodeWithViewId:(NSString *)viewId {
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}];
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@@ -36,4 +36,6 @@
|
||||
- (void)clearSubModel;
|
||||
|
||||
- (DoricViewNode *)subNodeWithViewId:(NSString *)viewId;
|
||||
|
||||
- (void)recursiveMixin:(NSDictionary *)srcModel to:(NSMutableDictionary *)targetModel;
|
||||
@end
|
@@ -65,6 +65,36 @@ - (void)mixin:(NSDictionary *)srcModel to:(NSMutableDictionary *)targetModel {
|
||||
targetModel[@"props"] = [targetProp copy];
|
||||
}
|
||||
|
||||
- (void)recursiveMixin:(NSDictionary *)srcModel to:(NSMutableDictionary *)targetModel {
|
||||
NSDictionary *srcProp = srcModel[@"props"];
|
||||
NSMutableDictionary *targetProp = [targetModel[@"props"] mutableCopy];
|
||||
NSArray *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) {
|
||||
if ([viewId isEqualToString:obj[@"id"]]) {
|
||||
NSMutableDictionary *mutableDictionary = [obj mutableCopy];
|
||||
[self recursiveMixin:subview to:mutableDictionary];
|
||||
targetSubviews[idx] = [mutableDictionary copy];
|
||||
*stop = YES;
|
||||
}
|
||||
}];
|
||||
}
|
||||
targetProp[@"subviews"] = [targetSubviews copy];
|
||||
}
|
||||
} else {
|
||||
targetProp[key] = obj;
|
||||
}
|
||||
}];
|
||||
targetModel[@"props"] = [targetProp copy];
|
||||
}
|
||||
|
||||
- (void)blendSubNode:(DoricViewNode *)subNode layoutConfig:(NSDictionary *)layoutConfig {
|
||||
DoricLayoutConfig *params = subNode.layoutConfig;
|
||||
|
||||
|
Reference in New Issue
Block a user