Skip to content

Commit

Permalink
fix(ios): onAttachedToWindow event not triggered
Browse files Browse the repository at this point in the history
  • Loading branch information
wwwcg committed Sep 12, 2024
1 parent 24e5439 commit b4f02e2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
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

0 comments on commit b4f02e2

Please sign in to comment.