mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
6d00239e49
Summary:
Starting on iOS 13, a View Controller presented modally will have a "bottom sheet" style unless it's explicitly presented full screen.
Before this, modals on iOS were only being dismissed programatically by setting `visible={false}`. However, now that the dismissal can happen on the OS side, we need a callback to be able to update the state.
This PR reuses the `onRequestClose` prop already available for tvOS and Android, and makes it work on iOS for this use case.
Should fix https://github.com/facebook/react-native/issues/26892
## Changelog
[iOS] [Added] - Add support for onRequestClose prop to Modal on iOS 13+
Pull Request resolved: https://github.com/facebook/react-native/pull/27618
Test Plan:
I tested this using the RNTester app with the Modal example:
1. Select any presentation style other than the full screen ones
2. Tap Present and the modal is presented
3. Swipe down on the presented modal until dismissed
4. Tap Present again and a second modal should be presented

Differential Revision: D19235758
Pulled By: shergin
fbshipit-source-id: c0f1d946c77ce8d1baab209eaef7eb64697851df
114 lines
3.1 KiB
Objective-C
114 lines
3.1 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 "RCTShadowView.h"
|
|
#import "RCTUtils.h"
|
|
|
|
@implementation RCTConvert (RCTModalHostView)
|
|
|
|
RCT_ENUM_CONVERTER(UIModalPresentationStyle, (@{
|
|
@"fullScreen": @(UIModalPresentationFullScreen),
|
|
#if !TARGET_OS_TV
|
|
@"pageSheet": @(UIModalPresentationPageSheet),
|
|
@"formSheet": @(UIModalPresentationFormSheet),
|
|
#endif
|
|
@"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
|
|
{
|
|
if (_dismissalBlock) {
|
|
_dismissalBlock([modalHostView reactViewController], viewController, animated, nil);
|
|
} else {
|
|
[viewController.presentingViewController dismissViewControllerAnimated:animated completion:nil];
|
|
}
|
|
}
|
|
|
|
|
|
- (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)
|
|
RCT_EXPORT_VIEW_PROPERTY(onRequestClose, RCTDirectEventBlock)
|
|
|
|
@end
|