mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Introduce RCTFBModalComponentView
Summary: Changelog: [Internal] Reviewed By: shergin Differential Revision: D23155490 fbshipit-source-id: 2c83c2ec71ca4d842275b4db6aac7169d3d77955
This commit is contained in:
committed by
Facebook GitHub Bot
parent
e1a5bd6bd6
commit
e4cfbbad6d
@@ -12,4 +12,18 @@
|
||||
*/
|
||||
@interface RCTModalHostViewComponentView : RCTViewComponentView
|
||||
|
||||
/**
|
||||
* Subclasses may override this method and present the modal on different view controller.
|
||||
* Default implementation presents the modal on `[self reactViewController]`.
|
||||
*/
|
||||
- (void)presentViewController:(UIViewController *)modalViewController
|
||||
animated:(BOOL)animated
|
||||
completion:(void (^)(void))completion;
|
||||
|
||||
/**
|
||||
* Subclasses may override this method.
|
||||
* Default implementation calls `[UIViewController dismissViewControllerAnimated:completion:]`.
|
||||
*/
|
||||
- (void)dismissViewController:(UIViewController *)modalViewController animated:(BOOL)animated;
|
||||
|
||||
@end
|
||||
|
||||
@@ -13,8 +13,8 @@
|
||||
#import <react/renderer/components/rncore/EventEmitters.h>
|
||||
#import <react/renderer/components/rncore/Props.h>
|
||||
|
||||
#import "FBRCTFabricComponentsPlugins.h"
|
||||
#import "RCTConversions.h"
|
||||
|
||||
#import "RCTFabricModalHostViewController.h"
|
||||
|
||||
using namespace facebook::react;
|
||||
@@ -120,30 +120,42 @@ static ModalHostViewEventEmitter::OnOrientationChange onOrientationChangeStruct(
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)presentViewController:(UIViewController *)modalViewController
|
||||
animated:(BOOL)animated
|
||||
completion:(void (^)(void))completion
|
||||
{
|
||||
UIViewController *controller = [self reactViewController];
|
||||
[controller presentViewController:modalViewController animated:animated completion:completion];
|
||||
}
|
||||
|
||||
- (void)dismissViewController:(UIViewController *)modalViewController animated:(BOOL)animated
|
||||
{
|
||||
[modalViewController dismissViewControllerAnimated:animated completion:nil];
|
||||
}
|
||||
|
||||
- (void)ensurePresentedOnlyIfNeeded
|
||||
{
|
||||
BOOL shouldBePresented = !_isPresented && self.window;
|
||||
if (shouldBePresented) {
|
||||
UIViewController *controller = [self reactViewController];
|
||||
_isPresented = YES;
|
||||
return [controller
|
||||
presentViewController:_viewController
|
||||
animated:_shouldAnimatePresentation
|
||||
completion:^{
|
||||
if (!self->_eventEmitter) {
|
||||
return;
|
||||
}
|
||||
[self presentViewController:_viewController
|
||||
animated:_shouldAnimatePresentation
|
||||
completion:^{
|
||||
if (!self->_eventEmitter) {
|
||||
return;
|
||||
}
|
||||
|
||||
assert(std::dynamic_pointer_cast<ModalHostViewEventEmitter const>(self->_eventEmitter));
|
||||
auto eventEmitter = std::static_pointer_cast<ModalHostViewEventEmitter const>(self->_eventEmitter);
|
||||
eventEmitter->onShow(ModalHostViewEventEmitter::OnShow{});
|
||||
}];
|
||||
assert(std::dynamic_pointer_cast<ModalHostViewEventEmitter const>(self->_eventEmitter));
|
||||
auto eventEmitter =
|
||||
std::static_pointer_cast<ModalHostViewEventEmitter const>(self->_eventEmitter);
|
||||
eventEmitter->onShow(ModalHostViewEventEmitter::OnShow{});
|
||||
}];
|
||||
}
|
||||
|
||||
BOOL shouldBeHidden = _isPresented && !self.superview;
|
||||
if (shouldBeHidden) {
|
||||
_isPresented = NO;
|
||||
[_viewController dismissViewControllerAnimated:_shouldAnimatePresentation completion:nil];
|
||||
[self dismissViewController:_viewController animated:_shouldAnimatePresentation];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -224,8 +236,3 @@ static ModalHostViewEventEmitter::OnOrientationChange onOrientationChangeStruct(
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Class<RCTComponentViewProtocol> RCTModalHostViewCls(void)
|
||||
{
|
||||
return RCTModalHostViewComponentView.class;
|
||||
}
|
||||
|
||||
@@ -36,7 +36,6 @@ Class<RCTComponentViewProtocol> RCTActivityIndicatorViewCls(void) __attribute__(
|
||||
Class<RCTComponentViewProtocol> RCTSliderCls(void) __attribute__((used));
|
||||
Class<RCTComponentViewProtocol> RCTSwitchCls(void) __attribute__((used));
|
||||
Class<RCTComponentViewProtocol> RCTUnimplementedNativeViewCls(void) __attribute__((used));
|
||||
Class<RCTComponentViewProtocol> RCTModalHostViewCls(void) __attribute__((used));
|
||||
Class<RCTComponentViewProtocol> RCTImageCls(void) __attribute__((used));
|
||||
Class<RCTComponentViewProtocol> RCTParagraphCls(void) __attribute__((used));
|
||||
Class<RCTComponentViewProtocol> RCTTextInputCls(void) __attribute__((used));
|
||||
|
||||
@@ -25,7 +25,6 @@ Class<RCTComponentViewProtocol> RCTFabricComponentsProvider(const char *name) {
|
||||
{"Slider", RCTSliderCls},
|
||||
{"Switch", RCTSwitchCls},
|
||||
{"UnimplementedNativeView", RCTUnimplementedNativeViewCls},
|
||||
{"ModalHostView", RCTModalHostViewCls},
|
||||
{"Image", RCTImageCls},
|
||||
{"Paragraph", RCTParagraphCls},
|
||||
{"TextInput", RCTTextInputCls},
|
||||
|
||||
Reference in New Issue
Block a user