feat:add reusable in groupnode for iOS
This commit is contained in:
parent
e4b729b2fd
commit
1d5b312922
@ -25,6 +25,7 @@
|
|||||||
NS_ASSUME_NONNULL_BEGIN
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
@interface DoricGroupNode <V:UIView *> : DoricSuperNode<V>
|
@interface DoricGroupNode <V:UIView *> : DoricSuperNode<V>
|
||||||
|
@property(nonatomic, assign) BOOL reusable;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_END
|
NS_ASSUME_NONNULL_END
|
||||||
|
@ -34,6 +34,7 @@ - (instancetype)initWithContext:(DoricContext *)doricContext {
|
|||||||
if (self = [super initWithContext:doricContext]) {
|
if (self = [super initWithContext:doricContext]) {
|
||||||
_childNodes = @[];
|
_childNodes = @[];
|
||||||
_childViewIds = @[];
|
_childViewIds = @[];
|
||||||
|
_reusable = NO;
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
@ -72,6 +73,26 @@ - (void)configChildNodes {
|
|||||||
DoricViewNode *oldNode = childNodes[idx];
|
DoricViewNode *oldNode = childNodes[idx];
|
||||||
if ([viewId isEqualToString:oldNode.viewId]) {
|
if ([viewId isEqualToString:oldNode.viewId]) {
|
||||||
///Same,skip
|
///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 {
|
} else {
|
||||||
///Find in remain nodes
|
///Find in remain nodes
|
||||||
NSInteger position = -1;
|
NSInteger position = -1;
|
||||||
@ -105,11 +126,13 @@ - (void)configChildNodes {
|
|||||||
[self.view insertSubview:viewNode.view atIndex:idx];
|
[self.view insertSubview:viewNode.view atIndex:idx];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
/// Insert
|
/// Insert
|
||||||
DoricViewNode *viewNode = [DoricViewNode create:self.doricContext withType:type];
|
DoricViewNode *viewNode = [DoricViewNode create:self.doricContext withType:type];
|
||||||
|
if ([viewNode isKindOfClass:[DoricGroupNode class]]) {
|
||||||
|
((DoricGroupNode *) viewNode).reusable = self.reusable;
|
||||||
|
}
|
||||||
viewNode.viewId = viewId;
|
viewNode.viewId = viewId;
|
||||||
[viewNode initWithSuperNode:self];
|
[viewNode initWithSuperNode:self];
|
||||||
[viewNode blend:model[@"props"]];
|
[viewNode blend:model[@"props"]];
|
||||||
|
@ -30,12 +30,13 @@ NS_ASSUME_NONNULL_BEGIN
|
|||||||
@interface DoricViewNode <V:UIView *> : DoricContextHolder
|
@interface DoricViewNode <V:UIView *> : DoricContextHolder
|
||||||
|
|
||||||
@property(nonatomic, strong) V view;
|
@property(nonatomic, strong) V view;
|
||||||
|
|
||||||
@property(nonatomic, weak) DoricSuperNode *superNode;
|
@property(nonatomic, weak) DoricSuperNode *superNode;
|
||||||
@property(nonatomic) NSInteger index;
|
@property(nonatomic) NSInteger index;
|
||||||
|
|
||||||
@property(nonatomic, copy) NSString *viewId;
|
@property(nonatomic, copy) NSString *viewId;
|
||||||
|
|
||||||
|
@property(nonatomic, copy) NSString *type;
|
||||||
|
|
||||||
@property(nonatomic, readonly) DoricLayoutConfig *layoutConfig;
|
@property(nonatomic, readonly) DoricLayoutConfig *layoutConfig;
|
||||||
|
|
||||||
@property(nonatomic, readonly) NSArray<NSString *> *idList;
|
@property(nonatomic, readonly) NSArray<NSString *> *idList;
|
||||||
|
@ -211,7 +211,9 @@ - (DoricAsyncResult *)callJSResponse:(NSString *)funcId, ... {
|
|||||||
+ (__kindof DoricViewNode *)create:(DoricContext *)context withType:(NSString *)type {
|
+ (__kindof DoricViewNode *)create:(DoricContext *)context withType:(NSString *)type {
|
||||||
DoricRegistry *registry = context.driver.registry;
|
DoricRegistry *registry = context.driver.registry;
|
||||||
Class clz = [registry acquireViewNode:type];
|
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 {
|
- (void)requestLayout {
|
||||||
|
Reference in New Issue
Block a user