iOS: reset view node when reuse this node

This commit is contained in:
pengfei.zhou 2021-10-27 16:03:11 +08:00 committed by osborn
parent 986d32a8e0
commit 60c8651e10
11 changed files with 119 additions and 0 deletions

View File

@ -526,4 +526,15 @@ - (NSArray *)findCompletelyVisibleItems {
}];
}
- (void)reset {
[super reset];
self.view.scrollEnabled = YES;
self.renderItemFuncId = nil;
self.onLoadMoreFuncId = nil;
self.loadMoreViewId = nil;
self.onScrollFuncId = nil;
self.onScrollEndFuncId = nil;
self.loadMore = NO;
}
@end

View File

@ -625,4 +625,16 @@ - (void)startAnimating {
- (void)stopAnimating {
[self.view stopAnimating];
}
- (void)reset {
[super reset];
self.view.image = nil;
self.loadCallbackId = nil;
self.placeHolderColor = nil;
self.placeHolderImage = nil;
self.placeHolderImageBase64 = nil;
self.errorColor = nil;
self.errorImage = nil;
self.errorImageBase64 = nil;
}
@end

View File

@ -659,4 +659,20 @@ - (BOOL)textFieldShouldReturn:(UITextField *)textField {
}
}
- (void)reset {
[super reset];
self.view.multiline = NO;
self.view.text = nil;
self.view.font = nil;
self.view.secureTextEntry = NO;
self.view.textAlignment = NSTextAlignmentNatural;
self.view.hintText = nil;
self.view.hintTextColor = UIColor.grayColor;
self.view.hintFont = nil;
self.view.editable = YES;
self.onFocusChange = nil;
self.onSubmitEditing = nil;
self.onTextChange = nil;
self.maxLength = nil;
}
@end

View File

@ -472,4 +472,16 @@ - (NSArray *)findCompletelyVisibleItems {
return @([self.view indexPathForCell:obj].row);
}];
}
- (void)reset {
[super reset];
self.view.scrollEnabled = YES;
self.renderItemFuncId = nil;
self.onLoadMoreFuncId = nil;
self.loadMoreViewId = nil;
self.onScrollFuncId = nil;
self.onScrollEndFuncId = nil;
self.loadMore = NO;
}
@end

View File

@ -93,4 +93,11 @@ - (NSNumber *)getSlidedPage {
NSUInteger pageIndex = (NSUInteger) (self.view.contentOffset.x / self.view.width);
return @(pageIndex);
}
- (void)reset {
[super reset];
self.view.scrollEnabled = YES;
self.onPageSelectedFuncId = nil;
}
@end

View File

@ -231,4 +231,11 @@ - (void)removeDidScrollBlock:(__nonnull DoricDidScrollBlock)didScrollListener {
[self.didScrollBlocks removeObject:didScrollListener];
}
- (void)reset {
[super reset];
self.view.scrollEnabled = YES;
self.onScrollEndFuncId = nil;
self.onScrollFuncId = nil;
self.view.scrollEnabled = YES;
}
@end

View File

@ -305,4 +305,12 @@ - (NSNumber *)getSlidedPage {
}
}
- (void)reset {
[super reset];
self.view.scrollEnabled = YES;
self.onPageSelectedFuncId = nil;
self.view.scrollEnabled = YES;
self.propRenderPageFuncId = nil;
self.renderPageFuncId = nil;
}
@end

View File

@ -70,4 +70,10 @@ - (void)blendView:(UISwitch *)view forPropName:(NSString *)name propValue:(id)pr
- (NSNumber *)getState {
return @(self.view.isOn);
}
- (void)reset {
[super reset];
self.view.on = NO;
self.onSwitchFuncId = nil;
}
@end

View File

@ -344,4 +344,17 @@ - (UIImage *)gradientImageFromColors:(NSArray *)colors
return image;
}
}
- (void)reset {
[super reset];
self.view.text = nil;
self.view.font = nil;
self.view.textColor = UIColor.blackColor;
self.view.textAlignment = NSTextAlignmentNatural;
self.view.numberOfLines = 1;
self.view.layer.shadowOpacity = 0;
self.view.layer.shadowRadius = 3;
self.view.layer.shadowOffset = CGSizeMake(0, -3);
self.view.lineBreakMode = NSLineBreakByTruncatingTail;
}
@end

View File

@ -57,4 +57,6 @@
- (void)blendLayoutConfig:(NSDictionary *)params;
- (void)afterBlended:(NSDictionary *)props;
- (void)reset;
@end

View File

@ -103,6 +103,9 @@ - (UIView *)build {
}
- (void)blend:(NSDictionary *)props {
if (self.superNode.reusable) {
[self reset];
}
for (NSString *key in props) {
id value = props[key];
if (!value || [value isKindOfClass:[NSNull class]]) {
@ -928,4 +931,26 @@ - (CAMediaTimingFunction *)translateToTimingFunction:(NSNumber *)timingFunction
}
}
- (void)reset {
self.view.backgroundColor = UIColor.clearColor;
self.view.doricLayout = [[DoricLayout new] also:^(DoricLayout *it) {
it.view = self.view;
}];
self.view.alpha = 1.0f;
self.view.hidden = NO;
self.view.layer.transform = CATransform3DIdentity;
self.view.transform = CGAffineTransformIdentity;
self.view.layer.cornerRadius = 0;
self.view.layer.mask = nil;
self.view.layer.borderWidth = 0;
self.view.layer.borderColor = UIColor.clearColor.CGColor;
for (UIGestureRecognizer *gestureRecognizer in self.view.gestureRecognizers) {
if ([gestureRecognizer isKindOfClass:UITapGestureRecognizer.class]) {
[self.view removeGestureRecognizer:gestureRecognizer];
}
}
}
@end