diff --git a/ios/Library/RNTModalShadowView/RNTModalShadowView.h b/ios/Library/RNTModalShadowView/RNTModalShadowView.h deleted file mode 100644 index 864439d..0000000 --- a/ios/Library/RNTModalShadowView/RNTModalShadowView.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef RNTModalShadowView_h -#define RNTModalShadowView_h - -#import - -@interface RNTModalShadowView : RCTShadowView -@end - -#endif /* RNTModalShadowView_h */ diff --git a/ios/Library/RNTModalShadowView/RNTModalShadowView.mm b/ios/Library/RNTModalShadowView/RNTModalShadowView.mm deleted file mode 100644 index 5730986..0000000 --- a/ios/Library/RNTModalShadowView/RNTModalShadowView.mm +++ /dev/null @@ -1,13 +0,0 @@ -#import "RNTModalShadowView.h" -#import - -@implementation RNTModalShadowView - -- (void)insertReactSubview:(id)subview atIndex:(NSInteger)atIndex { - [super insertReactSubview:subview atIndex:atIndex]; - if ([subview isKindOfClass:[RCTShadowView class]]) { - ((RCTShadowView *)subview).size = RCTScreenSize(); - } -} - -@end diff --git a/ios/RNTModalVIew.h b/ios/RNTModalVIew.h index ccd1cb5..ae713c6 100644 --- a/ios/RNTModalVIew.h +++ b/ios/RNTModalVIew.h @@ -9,22 +9,27 @@ #ifdef RCT_NEW_ARCH_ENABLED #import +#import NS_ASSUME_NONNULL_BEGIN @interface RNTModalView : RCTViewComponentView +@property (nonatomic, strong) RCTSurfaceTouchHandler *touchHandler; + #else @interface RNTModalView : UIView +@property (nonatomic, strong) RCTTouchHandler *touchHandler; + +- (instancetype)initWithBridge:(RCTBridge *)bridge; + #endif @property (nonatomic, strong) RCTUIManager *uiManager; -@property (nonatomic, strong) RCTTouchHandler *touchHandler; @property (nonatomic, strong) RNTModalViewController *modalViewController; @property (nonatomic, assign) BOOL isMounted; -- (instancetype)initWithBridge:(RCTBridge *)bridge; - (void)setupIfNeeded; - (void)mount; - (void)unmount; diff --git a/ios/RNTModalView.mm b/ios/RNTModalView.mm index 1f323fa..67ec4e7 100644 --- a/ios/RNTModalView.mm +++ b/ios/RNTModalView.mm @@ -12,6 +12,7 @@ #import #import #import "RCTFabricComponentsPlugins.h" +#import using namespace facebook::react; @@ -31,13 +32,36 @@ + (ComponentDescriptorProvider)componentDescriptorProvider return concreteComponentDescriptorProvider(); } +- (instancetype)initWithFrame:(CGRect)frame { + self = [super initWithFrame:CGRectZero]; + if (self) { + _touchHandler = [RCTSurfaceTouchHandler new]; + _modalViewController = [[RNTModalViewController alloc] init]; + _isMounted = NO; + } + return self; +} + +- (void)mountChildComponentView:(UIView *)childComponentView index:(NSInteger)index +{ + [self insertReactSubview:childComponentView atIndex:index]; + [self setupIfNeeded]; +} + +- (void)unmountChildComponentView:(UIView *)childComponentView index:(NSInteger)index +{ + [self removeReactSubview:childComponentView]; + [self unmount]; +} + +- (void)didMoveToSuperview { + [self setupIfNeeded]; +} #else @implementation RNTModalView -#endif - - (instancetype)initWithBridge:(RCTBridge *)bridge { self = [super initWithFrame:CGRectZero]; if (self) { @@ -49,11 +73,20 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge { return self; } +#endif + +RCT_NOT_IMPLEMENTED(-(instancetype)initWithCoder : coder) + + - (void)layoutSubviews { [super layoutSubviews]; [self setupIfNeeded]; } +- (void)addSubview:(UIView *)view { + [super addSubview:view]; +} + - (void)insertReactSubview:(UIView *)subview atIndex:(NSInteger)atIndex { [super insertReactSubview:subview atIndex:atIndex]; dispatch_async(dispatch_get_main_queue(), ^{ @@ -65,8 +98,10 @@ - (void)insertReactSubview:(UIView *)subview atIndex:(NSInteger)atIndex { - (void)removeReactSubview:(UIView *)subview { [super removeReactSubview:subview]; - [_touchHandler detachFromView:subview]; - [subview removeFromSuperview]; + dispatch_async(dispatch_get_main_queue(), ^{ + [self.touchHandler detachFromView:subview]; + [subview removeFromSuperview]; + }); } - (void)setupIfNeeded { @@ -84,13 +119,15 @@ - (void)mount { return; } - [self.modalViewController presentOn:rvc onView:rvc.view]; + dispatch_async(dispatch_get_main_queue(), ^{ + [self.modalViewController presentOn:rvc onView:rvc.view]; + }); + self.isMounted = YES; } - (void)unmount { [self.modalViewController dismiss]; - self.modalViewController = nil; self.isMounted = NO; } diff --git a/ios/RNTModalViewManager.mm b/ios/RNTModalViewManager.mm index a82edd5..22684fd 100644 --- a/ios/RNTModalViewManager.mm +++ b/ios/RNTModalViewManager.mm @@ -1,7 +1,6 @@ #import #import #import "RCTBridge.h" -#import "RNTModalShadowView.h" #import "RNTModalView.h" @interface RNTModalViewManager : RCTViewManager @@ -9,17 +8,15 @@ @interface RNTModalViewManager : RCTViewManager @implementation RNTModalViewManager -RCT_EXPORT_MODULE(RNTModalViewManager) +RCT_EXPORT_MODULE(RNTModalView) -- (RNTModalView *)view +#ifdef RCT_NEW_ARCH_ENABLED +#else +- (UIView *)view { return [[RNTModalView alloc] initWithBridge:self.bridge]; } - -- (RNTModalShadowView *)shadowView -{ - return [[RNTModalShadowView alloc] init]; -} +#endif + (BOOL)requiresMainQueueSetup {