Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions ios/Library/RNTModalShadowView/RNTModalShadowView.h

This file was deleted.

13 changes: 0 additions & 13 deletions ios/Library/RNTModalShadowView/RNTModalShadowView.mm

This file was deleted.

9 changes: 7 additions & 2 deletions ios/RNTModalVIew.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,27 @@

#ifdef RCT_NEW_ARCH_ENABLED
#import <React/RCTViewComponentView.h>
#import <React/RCTSurfaceTouchHandler.h>
NS_ASSUME_NONNULL_BEGIN

@interface RNTModalView : RCTViewComponentView <RCTInvalidating>

@property (nonatomic, strong) RCTSurfaceTouchHandler *touchHandler;

#else

@interface RNTModalView : UIView <RCTInvalidating>

@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;
Expand Down
49 changes: 43 additions & 6 deletions ios/RNTModalView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#import <react/renderer/components/RNTModalViewSpec/Props.h>
#import <react/renderer/components/RNTModalViewSpec/RCTComponentViewHelpers.h>
#import "RCTFabricComponentsPlugins.h"
#import <React/RCTSurfaceTouchHandler.h>

using namespace facebook::react;

Expand All @@ -31,13 +32,36 @@ + (ComponentDescriptorProvider)componentDescriptorProvider
return concreteComponentDescriptorProvider<RNTModalViewComponentDescriptor>();
}

- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:CGRectZero];
if (self) {
_touchHandler = [RCTSurfaceTouchHandler new];
_modalViewController = [[RNTModalViewController alloc] init];
_isMounted = NO;
}
return self;
}

- (void)mountChildComponentView:(UIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index
{
[self insertReactSubview:childComponentView atIndex:index];
[self setupIfNeeded];
}

- (void)unmountChildComponentView:(UIView<RCTComponentViewProtocol> *)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) {
Expand All @@ -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(), ^{
Expand All @@ -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 {
Expand All @@ -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;
}

Expand Down
13 changes: 5 additions & 8 deletions ios/RNTModalViewManager.mm
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
#import <React/RCTViewManager.h>
#import <React/RCTUIManager.h>
#import "RCTBridge.h"
#import "RNTModalShadowView.h"
#import "RNTModalView.h"

@interface RNTModalViewManager : RCTViewManager
@end

@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
{
Expand Down