Skip to content

Commit

Permalink
fix(ios): optimize creation time of lazy-load list items
Browse files Browse the repository at this point in the history
  • Loading branch information
wwwcg authored and hippy-actions[bot] committed Jan 5, 2024
1 parent d3bff26 commit f7b019f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 16 deletions.
38 changes: 22 additions & 16 deletions renderer/native/ios/renderer/HippyUIManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ - (UIView *)createViewFromShadowView:(HippyShadowView *)shadowView {
return view;
}
- (UIView *)createViewForShadowListItem:(HippyShadowView *)renderObject {
- (UIView *)createViewForShadowListItem:(HippyShadowView *)shadowView {
AssertMainQueue();
std::lock_guard<std::mutex> lock([self renderQueueLock]);
// There was a timing problem here:
Expand All @@ -519,13 +519,32 @@ - (UIView *)createViewForShadowListItem:(HippyShadowView *)renderObject {
// until the next `cellForItemAtIndexPath` call.
// we currently resolve this issue by setting the CreationType synchronously.
// TODO: CreationType's further optimization is needed in the future
[renderObject synchronousRecusivelySetCreationTypeToInstant];
return [self createViewRecursiveFromRenderObjectWithNOLock:renderObject];
[shadowView synchronousRecusivelySetCreationTypeToInstant];
UIView *listItemView = [self createViewRecursiveFromRenderObjectWithNOLock:shadowView];
[self.viewRegistry generateTempCacheBeforeAcquireAllStoredWeakComponents];
NSMutableSet<NativeRenderApplierBlock> *applierBlocks = [NSMutableSet set];
[shadowView amendLayoutBeforeMount:applierBlocks];
if (applierBlocks.count) {
for (NativeRenderApplierBlock block in applierBlocks) {
// Note: viewRegistry may be modified in the block, and it may be stored internally as NSMapTable
// so to ensure that it is up-to-date, it can only be retrieved each time.
NSDictionary<NSNumber *, UIView *> *viewRegistry = [self.viewRegistry componentsForRootTag:shadowView.rootTag];
block(viewRegistry, nil);
}
}
[self.viewRegistry clearTempCacheAfterAcquireAllStoredWeakComponents];
return listItemView;
}
- (UIView *)createViewRecursiveFromRenderObjectWithNOLock:(HippyShadowView *)shadowView {
UIView *view = [self createViewFromShadowView:shadowView];
if (view) {
// First of all, mark shadowView as dirty recursively,
// so that we can collect ui blocks to amend correctly.
[shadowView dirtyPropagation:NativeRenderUpdateLifecycleAllDirtied];
// Special handling of lazy list, which is a cellView
// because lazy loading list needs to be re-layout
if ([shadowView isKindOfClass:HippyShadowListView.class]) {
Expand Down Expand Up @@ -571,19 +590,6 @@ - (UIView *)createViewRecursiveFromRenderObjectWithNOLock:(HippyShadowView *)sha
[view clearSortedSubviews];
[view didUpdateHippySubviews];
NSMutableSet<NativeRenderApplierBlock> *applierBlocks = [NSMutableSet set];
[shadowView amendLayoutBeforeMount:applierBlocks];
if (applierBlocks.count) {
[self.viewRegistry generateTempCacheBeforeAcquireAllStoredWeakComponents];
for (NativeRenderApplierBlock block in applierBlocks) {
// Note: viewRegistry may be modified in the block, and it may be stored internally as NSMapTable
// so to ensure that it is up-to-date, it can only be retrieved each time.
NSDictionary<NSNumber *, UIView *> *viewRegistry = [self.viewRegistry componentsForRootTag:shadowView.rootTag];
block(viewRegistry, view);
}
[self.viewRegistry clearTempCacheAfterAcquireAllStoredWeakComponents];
}
}
return view;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,11 @@ - (void)contentSizeMultiplierDidChange:(__unused NSNotification *)note {
UIColor *color = self.color ?: [UIColor blackColor];
[applierBlocks addObject:^(NSDictionary<NSNumber *, UIView *> *viewRegistry, UIView * _Nullable lazyCreatedView) {
HippyText *view = (HippyText *)(lazyCreatedView ?: viewRegistry[self.hippyTag]);
if (!view) { return; }
if (![view isKindOfClass:HippyText.class]) {
// Going here indicates that there is a repeated refresh,
// Check the refresh logic to eliminate duplicates.
HippyLogError(@"Invalid View Type, Please Check!");
return;
}
view.textFrame = textFrame;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ - (void)setFrame:(CGRect)frame {
}

- (void)amendLayoutBeforeMount:(NSMutableSet<NativeRenderApplierBlock> *)blocks {
if (NativeRenderCreationTypeLazily == self.creationType) {
// If item has not yet been created, then no need to collect blocks.
return;
}
_layoutDirty = NO;
if (NativeRenderUpdateLifecycleComputed == _propagationLifecycle) {
return;
Expand Down

0 comments on commit f7b019f

Please sign in to comment.