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

refact(iOS, Fabric): take snapshot in unmountChildComponent:index: #2261

Merged
merged 3 commits into from
Jul 23, 2024
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
21 changes: 3 additions & 18 deletions ios/RNSScreenStack.mm
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,7 @@ @interface RNSScreenStackView () <
UINavigationControllerDelegate,
UIAdaptivePresentationControllerDelegate,
UIGestureRecognizerDelegate,
UIViewControllerTransitioningDelegate
#ifdef RCT_NEW_ARCH_ENABLED
,
RCTMountingTransactionObserving
#endif
>
UIViewControllerTransitioningDelegate>

@property (nonatomic) NSMutableArray<UIViewController *> *presentedModals;
@property (nonatomic) BOOL updatingModals;
Expand Down Expand Up @@ -1125,13 +1120,15 @@ - (void)mountChildComponentView:(UIView<RCTComponentViewProtocol> *)childCompone
- (void)unmountChildComponentView:(UIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index
{
RNSScreenView *screenChildComponent = (RNSScreenView *)childComponentView;

// We should only do a snapshot of a screen that is on the top.
// We also check `_presentedModals` since if you push 2 modals, second one is not a "child" of _controller.
// Also, when dissmised with a gesture, the screen already is not under the window, so we don't need to apply
// snapshot.
if (screenChildComponent.window != nil &&
((screenChildComponent == _controller.visibleViewController.view && _presentedModals.count < 2) ||
screenChildComponent == [_presentedModals.lastObject view])) {
[self takeSnapshot];
[screenChildComponent.controller setViewToSnapshot:_snapshot];
}

Expand Down Expand Up @@ -1166,18 +1163,6 @@ - (void)takeSnapshot
}
}

- (void)mountingTransactionWillMount:(react::MountingTransaction const &)transaction
withSurfaceTelemetry:(react::SurfaceTelemetry const &)surfaceTelemetry
{
for (auto &mutation : transaction.getMutations()) {
if (mutation.type == react::ShadowViewMutation::Type::Remove && mutation.parentShadowView.componentName != nil &&
strcmp(mutation.parentShadowView.componentName, "RNSScreenStack") == 0) {
[self takeSnapshot];
return;
}
}
}

- (void)prepareForRecycle
{
[super prepareForRecycle];
Expand Down
Loading