From 7c4afa1006ac07e07345682d91fd36ac0025b8a9 Mon Sep 17 00:00:00 2001 From: Riccardo Cipolleschi Date: Wed, 24 Jan 2024 05:54:15 -0800 Subject: [PATCH] Add a snapshot only if the Modal is visible (#42619) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/42619 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. Reviewed By: sammy-SC Differential Revision: D53003657 fbshipit-source-id: 6d6cc85946b1beb8e784e08a650d1247cf780228 --- .../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