From b79ec10b7891fd668de08a9fecddf710a96c6c7d Mon Sep 17 00:00:00 2001 From: zhongwuzw Date: Mon, 2 Dec 2024 04:06:40 -0800 Subject: [PATCH] Fabric: Fixes Modal onRequestClose not called (#48037) Summary: Fixes https://github.com/facebook/react-native/issues/48030 . ## Changelog: [IOS] [FIXED] - Fabric: Fixes Modal onRequestClose not called Pull Request resolved: https://github.com/facebook/react-native/pull/48037 Test Plan: Repro please see https://github.com/facebook/react-native/issues/48030. Reviewed By: cortinico Differential Revision: D66647232 Pulled By: cipolleschi fbshipit-source-id: 773517dfe45f6f2e6348cda225e972fbac05edc2 --- .../Modal/RCTModalHostViewComponentView.h | 2 +- .../Modal/RCTModalHostViewComponentView.mm | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/react-native/React/Fabric/Mounting/ComponentViews/Modal/RCTModalHostViewComponentView.h b/packages/react-native/React/Fabric/Mounting/ComponentViews/Modal/RCTModalHostViewComponentView.h index 27ee3d6305b..a869b9ad714 100644 --- a/packages/react-native/React/Fabric/Mounting/ComponentViews/Modal/RCTModalHostViewComponentView.h +++ b/packages/react-native/React/Fabric/Mounting/ComponentViews/Modal/RCTModalHostViewComponentView.h @@ -10,7 +10,7 @@ /** * UIView class for root component. */ -@interface RCTModalHostViewComponentView : RCTViewComponentView +@interface RCTModalHostViewComponentView : RCTViewComponentView /** * Subclasses may override this method and present the modal on different view controller. 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 350439a7810..9205fa3d211 100644 --- a/packages/react-native/React/Fabric/Mounting/ComponentViews/Modal/RCTModalHostViewComponentView.mm +++ b/packages/react-native/React/Fabric/Mounting/ComponentViews/Modal/RCTModalHostViewComponentView.mm @@ -149,6 +149,8 @@ static ModalHostViewEventEmitter::OnOrientationChange onOrientationChangeStruct( { BOOL shouldBePresented = !_isPresented && _shouldPresent && self.window; if (shouldBePresented) { + self.viewController.presentationController.delegate = self; + _isPresented = YES; [self presentViewController:self.viewController animated:_shouldAnimatePresentation @@ -274,6 +276,16 @@ static ModalHostViewEventEmitter::OnOrientationChange onOrientationChangeStruct( [childComponentView removeFromSuperview]; } +#pragma mark - UIAdaptivePresentationControllerDelegate + +- (void)presentationControllerDidAttemptToDismiss:(UIPresentationController *)controller +{ + auto eventEmitter = [self modalEventEmitter]; + if (eventEmitter) { + eventEmitter->onRequestClose({}); + } +} + @end #ifdef __cplusplus