From 56e0309b78939fe2a160f5f2aea18bad8fed87ea Mon Sep 17 00:00:00 2001 From: Samuel Susla Date: Wed, 10 Mar 2021 05:44:52 -0800 Subject: [PATCH] Send onDismiss event when Modal is dismissed Summary: Changelog: [internal] "onDismiss" event wasn't called in Fabric. This diff adds it. Paper implementation of Modal uses `RCTEventEmitter` instead of callback to deliver the event. To align better with Paper, Fabric will follow this pattern. Reviewed By: shergin Differential Revision: D26911312 fbshipit-source-id: b0de619c5a02c3378d1f7ac3ce1b705bb5fb634d --- .../Modal/RCTModalHostViewComponentView.h | 5 +++++ .../Modal/RCTModalHostViewComponentView.mm | 13 ++++++++++++- React/Views/RCTModalManager.h | 7 +++++++ React/Views/RCTModalManager.m | 9 +++++++++ 4 files changed, 33 insertions(+), 1 deletion(-) diff --git a/React/Fabric/Mounting/ComponentViews/Modal/RCTModalHostViewComponentView.h b/React/Fabric/Mounting/ComponentViews/Modal/RCTModalHostViewComponentView.h index b61196c4c57..823ac45486e 100644 --- a/React/Fabric/Mounting/ComponentViews/Modal/RCTModalHostViewComponentView.h +++ b/React/Fabric/Mounting/ComponentViews/Modal/RCTModalHostViewComponentView.h @@ -27,4 +27,9 @@ */ - (void)dismissViewController:(UIViewController *)modalViewController animated:(BOOL)animated; +/** + * Should be called by subclasses when ViewController is dismissed. + */ +- (void)didDismissViewController; + @end diff --git a/React/Fabric/Mounting/ComponentViews/Modal/RCTModalHostViewComponentView.mm b/React/Fabric/Mounting/ComponentViews/Modal/RCTModalHostViewComponentView.mm index 6e24d39105e..3e3624acbf4 100644 --- a/React/Fabric/Mounting/ComponentViews/Modal/RCTModalHostViewComponentView.mm +++ b/React/Fabric/Mounting/ComponentViews/Modal/RCTModalHostViewComponentView.mm @@ -7,6 +7,8 @@ #import "RCTModalHostViewComponentView.h" +#import +#import #import #import #import @@ -137,7 +139,16 @@ static ModalHostViewEventEmitter::OnOrientationChange onOrientationChangeStruct( - (void)dismissViewController:(UIViewController *)modalViewController animated:(BOOL)animated { - [modalViewController dismissViewControllerAnimated:animated completion:nil]; + [modalViewController dismissViewControllerAnimated:animated + completion:^{ + [self didDismissViewController]; + }]; +} + +- (void)didDismissViewController +{ + const auto &props = *std::static_pointer_cast(_props); + [[RCTBridge currentBridge].modalManager modalDismissed:@(props.identifier)]; } - (void)ensurePresentedOnlyIfNeeded diff --git a/React/Views/RCTModalManager.h b/React/Views/RCTModalManager.h index 4fbe6dfbd01..a34d801448c 100644 --- a/React/Views/RCTModalManager.h +++ b/React/Views/RCTModalManager.h @@ -7,6 +7,7 @@ #import +#import #import #import @@ -15,3 +16,9 @@ - (void)modalDismissed:(NSNumber *)modalID; @end + +@interface RCTBridge (RCTModalManager) + +@property (nonatomic, readonly) RCTModalManager *modalManager; + +@end diff --git a/React/Views/RCTModalManager.m b/React/Views/RCTModalManager.m index 992b73c62db..399c025a161 100644 --- a/React/Views/RCTModalManager.m +++ b/React/Views/RCTModalManager.m @@ -40,3 +40,12 @@ RCT_EXPORT_MODULE(); } @end + +@implementation RCTBridge (RCTDevSettings) + +- (RCTModalManager *)modalManager +{ + return [self moduleForClass:[RCTModalManager class]]; +} + +@end