Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ios): optimize cell creation time of listview and waterfall #3639

Merged
merged 2 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,6 @@ - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSe
- (void)collectionView:(UICollectionView *)collectionView
willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath {
HippyShadowView *cellRenderObjectView = [self.dataSource cellForIndexPath:indexPath];
[cellRenderObjectView recusivelySetCreationTypeToInstant];
[self itemViewForCollectionViewCell:cell indexPath:indexPath];
NSInteger index = [self.dataSource flatIndexForIndexPath:indexPath];
if (self.onRowWillDisplay) {
self.onRowWillDisplay(@{
Expand All @@ -284,26 +282,33 @@ - (void)collectionView:(UICollectionView *)collectionView
}
}

- (void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath {
- (void)collectionView:(UICollectionView *)collectionView
didEndDisplayingCell:(UICollectionViewCell *)cell
forItemAtIndexPath:(NSIndexPath *)indexPath {
if ([cell isKindOfClass:[NativeRenderBaseListViewCell class]]) {
NativeRenderBaseListViewCell *hpCell = (NativeRenderBaseListViewCell *)cell;
if (hpCell.cellView) {
[_cachedItems setObject:[hpCell.cellView hippyTag] forKey:indexPath];
hpCell.cellView = nil;
}
}
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
return [collectionView dequeueReusableCellWithReuseIdentifier:kCellIdentifier forIndexPath:indexPath];
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kCellIdentifier forIndexPath:indexPath];

// Create and Add real Hippy cell content
[self addCellViewToCollectionViewCell:cell atIndexPath:indexPath];
return cell;
}

- (void)itemViewForCollectionViewCell:(UICollectionViewCell *)cell indexPath:(NSIndexPath *)indexPath {
- (void)addCellViewToCollectionViewCell:(UICollectionViewCell *)cell atIndexPath:(NSIndexPath *)indexPath {
HippyAssert(self.renderImpl, @"no rendercontext detected");
if (!self.renderImpl) {
return;
}
HippyShadowView *cellRenderObject = [self.dataSource cellForIndexPath:indexPath];
[cellRenderObject recusivelySetCreationTypeToInstant];

NativeRenderBaseListViewCell *hpCell = (NativeRenderBaseListViewCell *)cell;
UIView *cellView = [self.renderImpl createViewRecursivelyFromRenderObject:cellRenderObject];
if (cellView) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ - (instancetype)initWithFrame:(CGRect)frame {
_scrollListeners = [NSHashTable weakObjectsHashTable];
_scrollEventThrottle = 100.f;
_weakItemMap = [NSMapTable strongToWeakObjectsMapTable];
_cachedItems = [NSMutableDictionary dictionaryWithCapacity:32];
_cachedItems = [NSMutableDictionary dictionary];
_dataSourcePool = [NSMutableArray array];
_dataSourceSem = dispatch_semaphore_create(1);
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveMemoryWarning) name:UIApplicationDidReceiveMemoryWarningNotification object:nil];
Expand Down Expand Up @@ -369,18 +369,14 @@ - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSe
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
return [self collectionView:collectionView itemViewForItemAtIndexPath:indexPath];
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView itemViewForItemAtIndexPath:(NSIndexPath *)indexPath {
NativeRenderWaterfallViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kCellIdentifier forIndexPath:indexPath];
[self addCellViewToCollectionViewCell:cell atIndexPath:indexPath];
return cell;
}

- (void)collectionView:(UICollectionView *)collectionView
willDisplayCell:(UICollectionViewCell *)cell
forItemAtIndexPath:(NSIndexPath *)indexPath {
[self itemViewForCollectionViewCell:cell indexPath:indexPath];
if (0 == [indexPath section] && _containBannerView) {
return;
}
Expand All @@ -400,17 +396,18 @@ - (void)collectionView:(UICollectionView *)collectionView
}
}

- (void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath {
- (void)collectionView:(UICollectionView *)collectionView
didEndDisplayingCell:(UICollectionViewCell *)cell
forItemAtIndexPath:(NSIndexPath *)indexPath {
if ([cell isKindOfClass:[NativeRenderWaterfallViewCell class]]) {
NativeRenderWaterfallViewCell *hpCell = (NativeRenderWaterfallViewCell *)cell;
if (hpCell.cellView) {
[_cachedItems setObject:[hpCell.cellView hippyTag] forKey:indexPath];
hpCell.cellView = nil;
}
}
}

- (void)itemViewForCollectionViewCell:(UICollectionViewCell *)cell indexPath:(NSIndexPath *)indexPath {
- (void)addCellViewToCollectionViewCell:(UICollectionViewCell *)cell atIndexPath:(NSIndexPath *)indexPath {
NativeRenderWaterfallViewCell *hpCell = (NativeRenderWaterfallViewCell *)cell;
HippyShadowView *renderObjectView = [_dataSource cellForIndexPath:indexPath];
[renderObjectView recusivelySetCreationTypeToInstant];
Expand Down
Loading