Skip to content

Commit 56e0309

Browse files
sammy-SCfacebook-github-bot
authored andcommitted
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
1 parent cdf3182 commit 56e0309

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

React/Fabric/Mounting/ComponentViews/Modal/RCTModalHostViewComponentView.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,9 @@
2727
*/
2828
- (void)dismissViewController:(UIViewController *)modalViewController animated:(BOOL)animated;
2929

30+
/**
31+
* Should be called by subclasses when ViewController is dismissed.
32+
*/
33+
- (void)didDismissViewController;
34+
3035
@end

React/Fabric/Mounting/ComponentViews/Modal/RCTModalHostViewComponentView.mm

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
#import "RCTModalHostViewComponentView.h"
99

10+
#import <React/RCTBridge+Private.h>
11+
#import <React/RCTModalManager.h>
1012
#import <React/UIView+React.h>
1113
#import <react/renderer/components/modal/ModalHostViewComponentDescriptor.h>
1214
#import <react/renderer/components/modal/ModalHostViewState.h>
@@ -137,7 +139,16 @@ - (void)presentViewController:(UIViewController *)modalViewController
137139

138140
- (void)dismissViewController:(UIViewController *)modalViewController animated:(BOOL)animated
139141
{
140-
[modalViewController dismissViewControllerAnimated:animated completion:nil];
142+
[modalViewController dismissViewControllerAnimated:animated
143+
completion:^{
144+
[self didDismissViewController];
145+
}];
146+
}
147+
148+
- (void)didDismissViewController
149+
{
150+
const auto &props = *std::static_pointer_cast<ModalHostViewProps const>(_props);
151+
[[RCTBridge currentBridge].modalManager modalDismissed:@(props.identifier)];
141152
}
142153

143154
- (void)ensurePresentedOnlyIfNeeded

React/Views/RCTModalManager.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#import <UIKit/UIKit.h>
99

10+
#import <React/RCTBridge.h>
1011
#import <React/RCTBridgeModule.h>
1112
#import <React/RCTEventEmitter.h>
1213

@@ -15,3 +16,9 @@
1516
- (void)modalDismissed:(NSNumber *)modalID;
1617

1718
@end
19+
20+
@interface RCTBridge (RCTModalManager)
21+
22+
@property (nonatomic, readonly) RCTModalManager *modalManager;
23+
24+
@end

React/Views/RCTModalManager.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,12 @@ - (void)modalDismissed:(NSNumber *)modalID
4040
}
4141

4242
@end
43+
44+
@implementation RCTBridge (RCTDevSettings)
45+
46+
- (RCTModalManager *)modalManager
47+
{
48+
return [self moduleForClass:[RCTModalManager class]];
49+
}
50+
51+
@end

0 commit comments

Comments
 (0)