feat:fix subitem mixin of listitemnode in iOS

This commit is contained in:
pengfei.zhou 2019-11-19 16:15:54 +08:00
parent d7d2af8065
commit c3b656d539
7 changed files with 67 additions and 12 deletions

View File

@ -157,12 +157,12 @@ public abstract class SuperNode<V extends View> extends ViewNode<V> {
protected void recursiveMixin(JSObject src, JSObject target) { protected void recursiveMixin(JSObject src, JSObject target) {
JSObject srcProps = src.getProperty("props").asObject(); JSObject srcProps = src.getProperty("props").asObject();
JSObject targetProps = target.getProperty("props").asObject(); JSObject targetProps = target.getProperty("props").asObject();
JSValue oriSubviews = targetProps.getProperty("subviews");
for (String key : srcProps.propertySet()) { for (String key : srcProps.propertySet()) {
JSValue jsValue = srcProps.getProperty(key); JSValue jsValue = srcProps.getProperty(key);
if ("subviews".equals(key) && jsValue.isArray()) { if ("subviews".equals(key) && jsValue.isArray()) {
JSValue[] subviews = jsValue.asArray().toArray(); JSValue[] subviews = jsValue.asArray().toArray();
for (JSValue subview : subviews) { for (JSValue subview : subviews) {
JSValue oriSubviews = targetProps.getProperty("subviews");
if (oriSubviews.isArray()) { if (oriSubviews.isArray()) {
for (JSValue targetSubview : oriSubviews.asArray().toArray()) { for (JSValue targetSubview : oriSubviews.asArray().toArray()) {
if (viewIdIsEqual(subview.asObject(), targetSubview.asObject())) { if (viewIdIsEqual(subview.asObject(), targetSubview.asObject())) {

View File

@ -54,6 +54,12 @@ class ListPanel extends Panel {
textSize: 20, textSize: 20,
height: 50, height: 50,
bgColor: Color.parse('#00ffff'), bgColor: Color.parse('#00ffff'),
}).also(it => {
let start = 0
it.onClick = () => {
log(`clicked text:${start}`)
it.text = `${start++}`
}
}), }),
]).also(it => { ]).also(it => {
it.layoutConfig = { it.layoutConfig = {

View File

@ -52,6 +52,8 @@ NS_ASSUME_NONNULL_BEGIN
- (void)connectDevKit:(NSString *)url; - (void)connectDevKit:(NSString *)url;
- (void)disconnectDevKit; - (void)disconnectDevKit;
- (void)ensureSyncInMainQueue:(dispatch_block_t)block;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

View File

@ -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 @end

View File

@ -129,6 +129,13 @@ - (NSDictionary *)itemModelAt:(NSUInteger)position {
- (void)blendSubNode:(NSDictionary *)subModel { - (void)blendSubNode:(NSDictionary *)subModel {
NSString *viewId = subModel[@"id"]; 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) { [self.itemViewIds enumerateKeysAndObjectsUsingBlock:^(NSNumber *_Nonnull key, NSString *_Nonnull obj, BOOL *_Nonnull stop) {
if ([viewId isEqualToString:obj]) { if ([viewId isEqualToString:obj]) {
*stop = YES; *stop = YES;
@ -138,6 +145,7 @@ - (void)blendSubNode:(NSDictionary *)subModel {
}]; }];
} }
}]; }];
}
} }
- (void)callItem:(NSUInteger)position height:(CGFloat)height { - (void)callItem:(NSUInteger)position height:(CGFloat)height {
@ -154,7 +162,7 @@ - (void)callItem:(NSUInteger)position height:(CGFloat)height {
- (DoricViewNode *)subNodeWithViewId:(NSString *)viewId { - (DoricViewNode *)subNodeWithViewId:(NSString *)viewId {
__block DoricViewNode *ret = nil; __block DoricViewNode *ret = nil;
dispatch_sync(dispatch_get_main_queue(), ^{ [self.doricContext.driver ensureSyncInMainQueue:^{
for (UITableViewCell *tableViewCell in self.view.visibleCells) { for (UITableViewCell *tableViewCell in self.view.visibleCells) {
if ([tableViewCell isKindOfClass:[DoricTableViewCell class]]) { if ([tableViewCell isKindOfClass:[DoricTableViewCell class]]) {
DoricListItemNode *node = ((DoricTableViewCell *) tableViewCell).doricListItemNode; DoricListItemNode *node = ((DoricTableViewCell *) tableViewCell).doricListItemNode;
@ -164,7 +172,7 @@ - (DoricViewNode *)subNodeWithViewId:(NSString *)viewId {
} }
} }
} }
}); }];
return ret; return ret;
} }

View File

@ -36,4 +36,6 @@
- (void)clearSubModel; - (void)clearSubModel;
- (DoricViewNode *)subNodeWithViewId:(NSString *)viewId; - (DoricViewNode *)subNodeWithViewId:(NSString *)viewId;
- (void)recursiveMixin:(NSDictionary *)srcModel to:(NSMutableDictionary *)targetModel;
@end @end

View File

@ -65,6 +65,36 @@ - (void)mixin:(NSDictionary *)srcModel to:(NSMutableDictionary *)targetModel {
targetModel[@"props"] = [targetProp copy]; 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 { - (void)blendSubNode:(DoricViewNode *)subNode layoutConfig:(NSDictionary *)layoutConfig {
DoricLayoutConfig *params = subNode.layoutConfig; DoricLayoutConfig *params = subNode.layoutConfig;