Fabric: Fixes Modal snapshot when closing it (#48252)

Summary:
Fixes https://github.com/facebook/react-native/issues/48245 . The reason is we reuse the modal component and also reuse the snapshot of previous modal.

## Changelog:

[IOS] [FIXED] - Fabric: Fixes Modal snapshot when closing it

Pull Request resolved: https://github.com/facebook/react-native/pull/48252

Test Plan: Repro repo please see Fixes https://github.com/facebook/react-native/issues/48245

Reviewed By: rshest

Differential Revision: D70629570

Pulled By: cipolleschi

fbshipit-source-id: fe97184d2f27283a9c7e6df09e9df35630429ff1
This commit is contained in:
zhongwuzw
2025-07-01 13:52:46 +00:00
committed by React Native Bot
parent 4ec5e99a72
commit 3e09e59912
@@ -104,7 +104,6 @@ static ModalHostViewEventEmitter::OnOrientationChange onOrientationChangeStruct(
BOOL _shouldAnimatePresentation;
BOOL _shouldPresent;
BOOL _isPresented;
UIView *_modalContentsSnapshot;
}
- (instancetype)initWithFrame:(CGRect)frame
@@ -141,7 +140,6 @@ static ModalHostViewEventEmitter::OnOrientationChange onOrientationChangeStruct(
animated:(BOOL)animated
completion:(void (^)(void))completion
{
_modalContentsSnapshot = [self.viewController.view snapshotViewAfterScreenUpdates:NO];
[modalViewController dismissViewControllerAnimated:animated completion:completion];
}
@@ -167,8 +165,7 @@ static ModalHostViewEventEmitter::OnOrientationChange onOrientationChangeStruct(
_isPresented = NO;
// To animate dismissal of view controller, snapshot of
// view hierarchy needs to be added to the UIViewController.
UIView *snapshot = _modalContentsSnapshot;
UIView *snapshot = [self.viewController.view snapshotViewAfterScreenUpdates:NO];
if (_shouldPresent) {
[self.viewController.view addSubview:snapshot];
}