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): onAttachedToWindow event not triggered #4027

Merged
merged 1 commit into from
Sep 12, 2024
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
13 changes: 13 additions & 0 deletions renderer/native/ios/renderer/HippyUIManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,19 @@ - (void)createRenderNodes:(std::vector<std::shared_ptr<DomNode>> &&)nodes
[uiManager->_componentTransactionListeners addObject:view];
}
[tempCreatedViews addObject:view];

// Note: Special logic, to be optimized
// The `onAttachedToWindow` event must be mounted in advance,
// because it will be called in `didUpdateHippySubviews` method.
// Other events are not mounted here.
static constexpr char onAttchedToWindowEventKey[] = "attachedtowindow";
const std::vector<std::string>& eventNames = [shadowView allEventNames];
auto it = std::find(eventNames.begin(), eventNames.end(), onAttchedToWindowEventKey);
if (it != eventNames.end()) {
[uiManager addEventNameInMainThread:onAttchedToWindowEventKey
forView:view
onRootNode:shadowView.rootNode];
}
}
}];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,11 +271,13 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cell
UIView *cachedVisibleCellView = [_cachedWeakCellViews objectForKey:shadowView.hippyTag];
if (cachedVisibleCellView) {
cellView = cachedVisibleCellView;
HippyLogTrace(@"🟢 use cached visible cellView at %@ for %@", indexPath, shadowView.hippyTag);
HippyLogTrace(@"%@ 🟢 use cached visible cellView at {%ld - %ld} for %@",
self.hippyTag, indexPath.section, indexPath.row, shadowView.hippyTag);
} else {
cellView = [self.uiManager createViewForShadowListItem:shadowView];
[_cachedWeakCellViews setObject:cellView forKey:shadowView.hippyTag];
HippyLogTrace(@"🟡 create cellView at %@ for %@", indexPath, shadowView.hippyTag);
HippyLogTrace(@"%@ 🟡 create cellView at {%ld - %ld} for %@",
self.hippyTag, indexPath.section, indexPath.row, shadowView.hippyTag);
}

HippyAssert([cellView conformsToProtocol:@protocol(ViewAppearStateProtocol)],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,7 @@ - (void)removeHippySubview:(UIView *)subview {
_contentView = nil;
}

- (void)didUpdateHippySubviews
{
- (void)didUpdateHippySubviews {
// Do nothing, as subviews are managed by `insertHippySubview:atIndex:`
}

Expand Down
Loading