mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
e948c79bda
Summary: `react-native-screens` has a bug about `UIViewControllerHierarchyInconsistency` when dismissing a `react-native` `<Modal>`. Here is the bug https://github.com/software-mansion/react-native-screens/issues/944 After adding `dispatch_async` block, it solves the issue. But I do not know if this is right. Here is the example repo https://github.com/wood1986/react-native-modal-crash You can revert my last commit https://github.com/wood1986/react-native-modal-crash/commit/86e7bc1adf444c1645c0d6078b0d6d427cdf6a36 to reproduce the issue ## Changelog <!-- Help reviewers and the release process by writing your own changelog entry. Pick one each for the category and type tags: [ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message For more details, see: https://reactnative.dev/contributing/changelogs-in-pull-requests --> [IOS] [FIXED] - fixed the potential race condition when dismissing and presentating modal Pull Request resolved: https://github.com/facebook/react-native/pull/35705 Reviewed By: cipolleschi Differential Revision: D42253488 Pulled By: makovkastar fbshipit-source-id: 3e98fa9e719ecdeddeb2a367b0cd364e15136d56
137 lines
3.9 KiB
Objective-C
137 lines
3.9 KiB
Objective-C
/*
|
|
* Copyright (c) Meta Platforms, Inc. and 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);
|
|
}
|
|
};
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
if (self->_presentationBlock) {
|
|
self->_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];
|
|
}
|
|
};
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
if (self->_dismissalBlock) {
|
|
self->_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(statusBarTranslucent, BOOL)
|
|
RCT_EXPORT_VIEW_PROPERTY(hardwareAccelerated, BOOL)
|
|
RCT_EXPORT_VIEW_PROPERTY(animated, 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(visible, BOOL)
|
|
RCT_EXPORT_VIEW_PROPERTY(onRequestClose, RCTDirectEventBlock)
|
|
|
|
// Fabric only
|
|
RCT_EXPORT_VIEW_PROPERTY(onDismiss, RCTDirectEventBlock)
|
|
|
|
@end
|