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
This commit is contained in:
Samuel Susla
2021-03-10 05:47:47 -08:00
committed by Facebook GitHub Bot
parent cdf3182793
commit 56e0309b78
4 changed files with 33 additions and 1 deletions
@@ -27,4 +27,9 @@
*/
- (void)dismissViewController:(UIViewController *)modalViewController animated:(BOOL)animated;
/**
* Should be called by subclasses when ViewController is dismissed.
*/
- (void)didDismissViewController;
@end
@@ -7,6 +7,8 @@
#import "RCTModalHostViewComponentView.h"
#import <React/RCTBridge+Private.h>
#import <React/RCTModalManager.h>
#import <React/UIView+React.h>
#import <react/renderer/components/modal/ModalHostViewComponentDescriptor.h>
#import <react/renderer/components/modal/ModalHostViewState.h>
@@ -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<ModalHostViewProps const>(_props);
[[RCTBridge currentBridge].modalManager modalDismissed:@(props.identifier)];
}
- (void)ensurePresentedOnlyIfNeeded
+7
View File
@@ -7,6 +7,7 @@
#import <UIKit/UIKit.h>
#import <React/RCTBridge.h>
#import <React/RCTBridgeModule.h>
#import <React/RCTEventEmitter.h>
@@ -15,3 +16,9 @@
- (void)modalDismissed:(NSNumber *)modalID;
@end
@interface RCTBridge (RCTModalManager)
@property (nonatomic, readonly) RCTModalManager *modalManager;
@end
+9
View File
@@ -40,3 +40,12 @@ RCT_EXPORT_MODULE();
}
@end
@implementation RCTBridge (RCTDevSettings)
- (RCTModalManager *)modalManager
{
return [self moduleForClass:[RCTModalManager class]];
}
@end