From c31e0698a1202176a225bebbf88ff9df37dfdd61 Mon Sep 17 00:00:00 2001 From: Riccardo Cipolleschi Date: Tue, 23 Jan 2024 07:51:26 -0800 Subject: [PATCH] [skip ci] Add a snapshot only if the Modal is visible (#42619) Summary: This is a workaround to prepare for the next diff in the stack and make sure that the modal works correctly ## Changelog [iOS][Changed] - Add the for the dismissal snapshot only when we need it. Differential Revision: D53003657 --- .../ComponentViews/Modal/RCTModalHostViewComponentView.mm | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/react-native/React/Fabric/Mounting/ComponentViews/Modal/RCTModalHostViewComponentView.mm b/packages/react-native/React/Fabric/Mounting/ComponentViews/Modal/RCTModalHostViewComponentView.mm index e20eee608a01c6..b0908cd98df32f 100644 --- a/packages/react-native/React/Fabric/Mounting/ComponentViews/Modal/RCTModalHostViewComponentView.mm +++ b/packages/react-native/React/Fabric/Mounting/ComponentViews/Modal/RCTModalHostViewComponentView.mm @@ -165,7 +165,10 @@ - (void)ensurePresentedOnlyIfNeeded // To animate dismissal of view controller, snapshot of // view hierarchy needs to be added to the UIViewController. UIView *snapshot = _modalContentsSnapshot; - [self.viewController.view addSubview:snapshot]; + + if (_shouldPresent) { + [self.viewController.view addSubview:snapshot]; + } [self dismissViewController:self.viewController animated:_shouldAnimatePresentation @@ -194,7 +197,7 @@ - (void)ensurePresentedOnlyIfNeeded - (void)mountingTransactionWillMount:(const MountingTransaction &)transaction withSurfaceTelemetry:(const facebook::react::SurfaceTelemetry &)surfaceTelemetry { - _modalContentsSnapshot = [self.viewController.view snapshotViewAfterScreenUpdates:NO]; + _modalContentsSnapshot = [self.viewController.view snapshotViewAfterScreenUpdates:YES]; } #pragma mark - UIView methods