Skip to content

Commit

Permalink
fix(ios): remove the diff-update code of waterfall and listview
Browse files Browse the repository at this point in the history
  • Loading branch information
wwwcg authored and zealotchen0 committed Nov 23, 2023
1 parent d073aa9 commit 944e737
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 465 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,115 +162,7 @@ - (void)applyDiff:(NativeRenderBaseListViewDataSource *)another
[view reloadData];
completion(YES);
return;

// 注意,如下原增量刷新逻辑存在BUG,会导致系统UICollectionView出现运行异常,临时删除,后续重构
// FIXME: 需重构
// https://bugly.woa.com/v2/exception/crash/issues/detail?productId=d591c6d8f7&pid=2&feature=073EF7E1204E4EAEB2F02B726D0FACBF

if (!another ||
!context ||
![[another cellRenderObjectViews] count]) {
[view reloadData];
completion(YES);
return;
}

// Attention, we do partial reload only when 1 item change!
// because differential refreshing causes the display event of the cell to not trigger,
// So we limit this to when only one cell is updated
if (context.allChangedItems.count > 1) {
[view reloadData];
completion(YES);
return;
}

// The following logic is not perfect and needs to be further refined
NSMutableArray<NSInvocation *> *batchUpdate = [NSMutableArray arrayWithCapacity:8];
[self cellDiffFromAnother:another
sectionStartAt:0
frameChangedItems:context.frameChangedItems
result:^(NSArray<NSIndexPath *> *reloadedItemIndexPath,
NSArray<NSIndexPath *> *InsertedIndexPath,
NSArray<NSIndexPath *> *deletedIndexPath,
NSIndexSet *insertedSecionIndexSet,
NSIndexSet *deletedSectionIndexSet) {
if ([insertedSecionIndexSet count]) {
NSInvocation *invocation = InvocationFromSelector(view, @selector(insertSections:), insertedSecionIndexSet);
if (invocation) {
[batchUpdate addObject:invocation];
}
}
if ([deletedSectionIndexSet count]) {
NSInvocation *invocation = InvocationFromSelector(view, @selector(deleteSections:), deletedSectionIndexSet);
if (invocation) {
[batchUpdate addObject:invocation];
}
}
if ([reloadedItemIndexPath count]) {
NSInvocation *invocation = InvocationFromSelector(view, @selector(reloadItemsAtIndexPaths:), reloadedItemIndexPath);
if (invocation) {
[batchUpdate addObject:invocation];
}
}
if ([InsertedIndexPath count]) {
NSInvocation *invocation = InvocationFromSelector(view, @selector(insertItemsAtIndexPaths:), InsertedIndexPath);
if (invocation) {
[batchUpdate addObject:invocation];
}
}
if ([deletedIndexPath count]) {
NSInvocation *invocation = InvocationFromSelector(view, @selector(deleteItemsAtIndexPaths:), deletedIndexPath);
if (invocation) {
[batchUpdate addObject:invocation];
}
}
}];

BOOL success = YES;
if ([batchUpdate count]) {
[CATransaction begin];
[CATransaction setDisableActions:YES];
@try {
[view performBatchUpdates:^{
for (NSInvocation *invocation in batchUpdate) {
[invocation invoke];
}
} completion:nil];
} @catch (NSException *exception) {
[view reloadData];
success = NO;
}
[CATransaction commit];
}
completion(success);
}

static NSInvocation *InvocationFromSelector(id object, SEL selector, id param) {
if (!selector || !object) {
return nil;
}
NSMethodSignature *methodSignature = [UICollectionView instanceMethodSignatureForSelector:selector];
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:methodSignature];
[invocation setTarget:object];
[invocation setSelector:selector];
if (param) {
[invocation setArgument:&param atIndex:2];
}
if (![invocation argumentsRetained]) {
[invocation retainArguments];
}
return invocation;
}

static inline void EnumCellRenderObjects(NSArray<NSArray<__kindof HippyShadowView *> *> *objects,
void (^ _Nonnull block)(__kindof HippyShadowView * object, NSUInteger section, NSUInteger row)) {
for (NSUInteger section = 0; section < [objects count]; section ++) {
NSArray<__kindof HippyShadowView *> *sectionObjects = [objects objectAtIndex:section];
for (NSUInteger row = 0; row < [sectionObjects count]; row++) {
__kindof HippyShadowView *object = [sectionObjects objectAtIndex:row];
block(object, section, row);
}
}
// Note:原增量刷新代码存在大量问题,已删除
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,6 @@ NS_ASSUME_NONNULL_BEGIN
forWaterfallView:(UICollectionView *)view
completion:(void(^)(BOOL success))completion;

- (void)cellDiffFromAnother:(NativeRenderWaterfallViewDataSource *)another
sectionStartAt:(NSUInteger)startSection
frameChangedItems:(NSHashTable<__kindof HippyShadowView *> *)frameChangedItems
result:(void(^)(NSArray<NSIndexPath *> *reloadedItemIndexPath,
NSArray<NSIndexPath *> *InsertedIndexPath,
NSArray<NSIndexPath *> *deletedIndexPath,
NSIndexSet *insertedSecionIndexSet,
NSIndexSet *deletedSectionIndexSet))result;

@end

NS_ASSUME_NONNULL_END
Loading

0 comments on commit 944e737

Please sign in to comment.