feat:add reusable in groupnode for iOS

This commit is contained in:
pengfei.zhou 2019-11-16 13:23:11 +08:00
parent e4b729b2fd
commit 1d5b312922
4 changed files with 60 additions and 33 deletions

View File

@ -25,6 +25,7 @@
NS_ASSUME_NONNULL_BEGIN
@interface DoricGroupNode <V:UIView *> : DoricSuperNode<V>
@property(nonatomic, assign) BOOL reusable;
@end
NS_ASSUME_NONNULL_END

View File

@ -34,6 +34,7 @@ - (instancetype)initWithContext:(DoricContext *)doricContext {
if (self = [super initWithContext:doricContext]) {
_childNodes = @[];
_childViewIds = @[];
_reusable = NO;
}
return self;
}
@ -72,6 +73,26 @@ - (void)configChildNodes {
DoricViewNode *oldNode = childNodes[idx];
if ([viewId isEqualToString:oldNode.viewId]) {
///Same,skip
} else {
if (self.reusable) {
if ([oldNode.type isEqualToString:type]) {
///Same type,can be reused
oldNode.viewId = viewId;
[oldNode blend:model[@"props"]];
} else {
///Replace this view
[childNodes removeObjectAtIndex:idx];
[oldNode.view removeFromSuperview];
DoricViewNode *viewNode = [DoricViewNode create:self.doricContext withType:type];
if ([viewNode isKindOfClass:[DoricGroupNode class]]) {
((DoricGroupNode *) viewNode).reusable = self.reusable;
}
viewNode.viewId = viewId;
[viewNode initWithSuperNode:self];
[viewNode blend:model[@"props"]];
[childNodes insertObject:viewNode atIndex:idx];
[self.view insertSubview:viewNode.view atIndex:idx];
}
} else {
///Find in remain nodes
NSInteger position = -1;
@ -105,11 +126,13 @@ - (void)configChildNodes {
[self.view insertSubview:viewNode.view atIndex:idx];
}
}
}
} else {
/// Insert
DoricViewNode *viewNode = [DoricViewNode create:self.doricContext withType:type];
if ([viewNode isKindOfClass:[DoricGroupNode class]]) {
((DoricGroupNode *) viewNode).reusable = self.reusable;
}
viewNode.viewId = viewId;
[viewNode initWithSuperNode:self];
[viewNode blend:model[@"props"]];

View File

@ -30,12 +30,13 @@ NS_ASSUME_NONNULL_BEGIN
@interface DoricViewNode <V:UIView *> : DoricContextHolder
@property(nonatomic, strong) V view;
@property(nonatomic, weak) DoricSuperNode *superNode;
@property(nonatomic) NSInteger index;
@property(nonatomic, copy) NSString *viewId;
@property(nonatomic, copy) NSString *type;
@property(nonatomic, readonly) DoricLayoutConfig *layoutConfig;
@property(nonatomic, readonly) NSArray<NSString *> *idList;

View File

@ -211,7 +211,9 @@ - (DoricAsyncResult *)callJSResponse:(NSString *)funcId, ... {
+ (__kindof DoricViewNode *)create:(DoricContext *)context withType:(NSString *)type {
DoricRegistry *registry = context.driver.registry;
Class clz = [registry acquireViewNode:type];
return [(DoricViewNode *) [clz alloc] initWithContext:context];
DoricViewNode *viewNode = [(DoricViewNode *) [clz alloc] initWithContext:context];
viewNode.type = type;
return viewNode;
}
- (void)requestLayout {