Skip to content

Commit

Permalink
feat(ios): optimize cell reuse processes 2
Browse files Browse the repository at this point in the history
  • Loading branch information
wwwcg authored and hippy-actions[bot] committed Dec 22, 2023
1 parent 40e884f commit ebbb3f7
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ - (instancetype)initWithFrame:(CGRect)frame {
_scrollListeners = [NSHashTable weakObjectsHashTable];
_scrollEventThrottle = 100.f;
_cachedWeakCellViews = [NSMapTable strongToWeakObjectsMapTable];
_visibleCellViewsBeforeReload = [NSMutableArray array];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveMemoryWarning) name:UIApplicationDidReceiveMemoryWarningNotification object:nil];
[self initCollectionView];
if (@available(iOS 11.0, *)) {
Expand Down Expand Up @@ -655,17 +654,18 @@ - (void)cacheVisibleCellViewsForReuse {
// Before reload, cache the current visible cellViews temporarily,
// because cells can potentially be reused.
// And remove them when the reload is complete in `tableViewDidLayoutSubviews` method.
[_visibleCellViewsBeforeReload removeAllObjects];
NSArray<UICollectionViewCell *> *visibleCells = [self.collectionView visibleCells];
NSMutableArray *visibleCellViews = [NSMutableArray arrayWithCapacity:visibleCells.count];
for (UICollectionViewCell *cell in visibleCells) {
if ([cell isKindOfClass:NativeRenderWaterfallViewCell.class]) {
[_visibleCellViewsBeforeReload addObject:((NativeRenderWaterfallViewCell *)cell).cellView];
[visibleCellViews addObject:((NativeRenderWaterfallViewCell *)cell).cellView];
}
}
_visibleCellViewsBeforeReload = visibleCellViews;
}

- (void)clearVisibleCellViewsCacheBeforeReload {
[_visibleCellViewsBeforeReload removeAllObjects];
_visibleCellViewsBeforeReload = nil;
}

@end

0 comments on commit ebbb3f7

Please sign in to comment.