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

refactor(iOS): update view controller once per transaction when adding header subviews #2623

Merged
merged 1 commit into from
Jan 21, 2025
Merged
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
11 changes: 6 additions & 5 deletions ios/RNSScreenStackHeaderConfig.mm
Original file line number Diff line number Diff line change
Expand Up @@ -883,9 +883,6 @@ - (void)mountChildComponentView:(UIView<RCTComponentViewProtocol> *)childCompone
[self insertReactSubview:(RNSScreenStackHeaderSubview *)childComponentView atIndex:index];

_addedReactSubviewsInCurrentTransaction = true;

// TODO: This could be called only once per transaction.
[self updateViewControllerIfNeeded];
}

- (void)unmountChildComponentView:(UIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index
Expand All @@ -909,15 +906,19 @@ - (void)unmountChildComponentView:(UIView<RCTComponentViewProtocol> *)childCompo
- (void)mountingTransactionDidMount:(const facebook::react::MountingTransaction &)transaction
withSurfaceTelemetry:(const facebook::react::SurfaceTelemetry &)surfaceTelemetry
{
if (_addedReactSubviewsInCurrentTransaction && self.shouldHeaderBeVisible) {
if (_addedReactSubviewsInCurrentTransaction) {
[self updateViewControllerIfNeeded];

// This call is made for the sake of https://github.com/software-mansion/react-native-screens/pull/2466.
// In case header subview is added **after initial screen render** the system positions it correctly,
// however `viewDidLayoutSubviews` is not called on `RNSNavigationController` and updated frame sizes of the
// subviews are not sent to ShadowTree leading to issues with pressables.
// Sending state update to ShadowTree from here is not enough, because native layout has not yet
// happened after the child had been added. Requesting layout on navigation bar does not trigger layout callbacks
// either, however doing so on main view of navigation controller does the trick.
[self layoutNavigationControllerView];
if (self.shouldHeaderBeVisible) {
[self layoutNavigationControllerView];
}
}
_addedReactSubviewsInCurrentTransaction = false;
}
Expand Down
Loading