Fix crash caused by <Modal> trying to present view controller twice
Summary: Changelog: [Internal] `_viewController` was being presented twice causing following exception ``` 'Application tried to present modally an active controller <FBReactRootViewController: 0x7fe741818b80; ``` Reviewed By: shergin Differential Revision: D20820395 fbshipit-source-id: 5c9489011e5f99d8bd37befbd544d2d55a650589
This commit is contained in:
Родитель
b145a82964
Коммит
2c3a6ab5b2
|
@ -102,6 +102,7 @@ static ModalHostViewEventEmitter::OnOrientationChange onOrientationChangeStruct(
|
|||
RCTFabricModalHostViewController *_viewController;
|
||||
ModalHostViewShadowNode::ConcreteState::Shared _state;
|
||||
BOOL _shouldAnimatePresentation;
|
||||
BOOL _isPresented;
|
||||
}
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame
|
||||
|
@ -113,21 +114,18 @@ static ModalHostViewEventEmitter::OnOrientationChange onOrientationChangeStruct(
|
|||
_viewController = [RCTFabricModalHostViewController new];
|
||||
_viewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
|
||||
_viewController.delegate = self;
|
||||
_isPresented = NO;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)isViewControllerPresented
|
||||
{
|
||||
return _viewController.presentingViewController != nil;
|
||||
}
|
||||
|
||||
- (void)ensurePresentedOnlyIfNeeded
|
||||
{
|
||||
BOOL shouldBePresented = !self.isViewControllerPresented && self.window;
|
||||
BOOL shouldBePresented = !_isPresented && self.window;
|
||||
if (shouldBePresented) {
|
||||
UIViewController *controller = [self reactViewController];
|
||||
_isPresented = YES;
|
||||
return [controller
|
||||
presentViewController:_viewController
|
||||
animated:_shouldAnimatePresentation
|
||||
|
@ -142,8 +140,9 @@ static ModalHostViewEventEmitter::OnOrientationChange onOrientationChangeStruct(
|
|||
}];
|
||||
}
|
||||
|
||||
BOOL shouldBeHidden = self.isViewControllerPresented && !self.superview;
|
||||
BOOL shouldBeHidden = _isPresented && !self.superview;
|
||||
if (shouldBeHidden) {
|
||||
_isPresented = NO;
|
||||
[_viewController dismissViewControllerAnimated:_shouldAnimatePresentation completion:nil];
|
||||
}
|
||||
}
|
||||
|
@ -184,6 +183,13 @@ static ModalHostViewEventEmitter::OnOrientationChange onOrientationChangeStruct(
|
|||
return concreteComponentDescriptorProvider<ModalHostViewComponentDescriptor>();
|
||||
}
|
||||
|
||||
- (void)prepareForRecycle
|
||||
{
|
||||
[super prepareForRecycle];
|
||||
_state.reset();
|
||||
_isPresented = NO;
|
||||
}
|
||||
|
||||
- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps
|
||||
{
|
||||
const auto &newProps = *std::static_pointer_cast<const ModalHostViewProps>(props);
|
||||
|
|
Загрузка…
Ссылка в новой задаче