mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
d85d5d2e19
Summary: Fixes: https://github.com/facebook/react-native/issues/29455 Modal's onDismiss is not called on iOS. This issue occurred the commit https://github.com/facebook/react-native/commit/bd2b7d6c0366b5f19de56b71cb706a0af4b0be43 and was fixed the commit https://github.com/facebook/react-native/commit/27a3248a3b37410b5ee6dda421ae00fa485b525c. However, the master and stable-0.63 branches do not have this modified commit applied to them. ## Changelog <!-- Help reviewers and the release process by writing your own changelog entry. For an example, see: https://github.com/facebook/react-native/wiki/Changelog --> [iOS] [Fixed] - Modal's onDismiss prop will now be called successfully. Pull Request resolved: https://github.com/facebook/react-native/pull/29882 Test Plan: Tested on iOS with this change: 1. Set function Modal's onDismiss prop. 1. Set Modal's visible props is true. (show Modal) 1. Set Modal's visible props is false. (close Modal) 1. The set function in onDismiss is called. Reviewed By: shergin Differential Revision: D24648412 Pulled By: hramos fbshipit-source-id: acf28fef21420117c845d3aed97e47b5dd4e9390
125 lines
3.4 KiB
Objective-C
125 lines
3.4 KiB
Objective-C
/*
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
#import "RCTModalHostViewManager.h"
|
|
|
|
#import "RCTBridge.h"
|
|
#import "RCTModalHostView.h"
|
|
#import "RCTModalHostViewController.h"
|
|
#import "RCTModalManager.h"
|
|
#import "RCTShadowView.h"
|
|
#import "RCTUtils.h"
|
|
|
|
@implementation RCTConvert (RCTModalHostView)
|
|
|
|
RCT_ENUM_CONVERTER(
|
|
UIModalPresentationStyle,
|
|
(@{
|
|
@"fullScreen" : @(UIModalPresentationFullScreen),
|
|
@"pageSheet" : @(UIModalPresentationPageSheet),
|
|
@"formSheet" : @(UIModalPresentationFormSheet),
|
|
@"overFullScreen" : @(UIModalPresentationOverFullScreen),
|
|
}),
|
|
UIModalPresentationFullScreen,
|
|
integerValue)
|
|
|
|
@end
|
|
|
|
@interface RCTModalHostShadowView : RCTShadowView
|
|
|
|
@end
|
|
|
|
@implementation RCTModalHostShadowView
|
|
|
|
- (void)insertReactSubview:(id<RCTComponent>)subview atIndex:(NSInteger)atIndex
|
|
{
|
|
[super insertReactSubview:subview atIndex:atIndex];
|
|
if ([subview isKindOfClass:[RCTShadowView class]]) {
|
|
((RCTShadowView *)subview).size = RCTScreenSize();
|
|
}
|
|
}
|
|
|
|
@end
|
|
|
|
@interface RCTModalHostViewManager () <RCTModalHostViewInteractor>
|
|
|
|
@end
|
|
|
|
@implementation RCTModalHostViewManager {
|
|
NSPointerArray *_hostViews;
|
|
}
|
|
|
|
RCT_EXPORT_MODULE()
|
|
|
|
- (UIView *)view
|
|
{
|
|
RCTModalHostView *view = [[RCTModalHostView alloc] initWithBridge:self.bridge];
|
|
view.delegate = self;
|
|
if (!_hostViews) {
|
|
_hostViews = [NSPointerArray weakObjectsPointerArray];
|
|
}
|
|
[_hostViews addPointer:(__bridge void *)view];
|
|
return view;
|
|
}
|
|
|
|
- (void)presentModalHostView:(RCTModalHostView *)modalHostView
|
|
withViewController:(RCTModalHostViewController *)viewController
|
|
animated:(BOOL)animated
|
|
{
|
|
dispatch_block_t completionBlock = ^{
|
|
if (modalHostView.onShow) {
|
|
modalHostView.onShow(nil);
|
|
}
|
|
};
|
|
if (_presentationBlock) {
|
|
_presentationBlock([modalHostView reactViewController], viewController, animated, completionBlock);
|
|
} else {
|
|
[[modalHostView reactViewController] presentViewController:viewController
|
|
animated:animated
|
|
completion:completionBlock];
|
|
}
|
|
}
|
|
|
|
- (void)dismissModalHostView:(RCTModalHostView *)modalHostView
|
|
withViewController:(RCTModalHostViewController *)viewController
|
|
animated:(BOOL)animated
|
|
{
|
|
dispatch_block_t completionBlock = ^{
|
|
if (modalHostView.identifier) {
|
|
[[self.bridge moduleForClass:[RCTModalManager class]] modalDismissed:modalHostView.identifier];
|
|
}
|
|
};
|
|
if (_dismissalBlock) {
|
|
_dismissalBlock([modalHostView reactViewController], viewController, animated, completionBlock);
|
|
} else {
|
|
[viewController.presentingViewController dismissViewControllerAnimated:animated completion:completionBlock];
|
|
}
|
|
}
|
|
|
|
- (RCTShadowView *)shadowView
|
|
{
|
|
return [RCTModalHostShadowView new];
|
|
}
|
|
|
|
- (void)invalidate
|
|
{
|
|
for (RCTModalHostView *hostView in _hostViews) {
|
|
[hostView invalidate];
|
|
}
|
|
_hostViews = nil;
|
|
}
|
|
|
|
RCT_EXPORT_VIEW_PROPERTY(animationType, NSString)
|
|
RCT_EXPORT_VIEW_PROPERTY(presentationStyle, UIModalPresentationStyle)
|
|
RCT_EXPORT_VIEW_PROPERTY(transparent, BOOL)
|
|
RCT_EXPORT_VIEW_PROPERTY(onShow, RCTDirectEventBlock)
|
|
RCT_EXPORT_VIEW_PROPERTY(identifier, NSNumber)
|
|
RCT_EXPORT_VIEW_PROPERTY(supportedOrientations, NSArray)
|
|
RCT_EXPORT_VIEW_PROPERTY(onOrientationChange, RCTDirectEventBlock)
|
|
|
|
@end
|