iOS: pass fabric flag down to RCTRootView/RCTSurface for proper unmounting

Reviewed By: shergin

Differential Revision: D7119220

fbshipit-source-id: 7a822036e29e0d92f53a164acba2ab75e883b5c4
This commit is contained in:
Kevin Gozali 2018-02-28 19:41:29 -08:00 committed by Facebook Github Bot
parent c20e0f94fe
commit 006b77f1ae
6 changed files with 95 additions and 9 deletions

View File

@ -24,9 +24,17 @@
@property (nonatomic, assign) BOOL passThroughTouches;
@property (nonatomic, assign) RCTRootViewSizeFlexibility sizeFlexibility;
@property (nonatomic, assign) BOOL fabric;
- (instancetype)initWithFrame:(CGRect)frame
bridge:(RCTBridge *)bridge
reactTag:(NSNumber *)reactTag
sizeFlexiblity:(RCTRootViewSizeFlexibility)sizeFlexibility NS_DESIGNATED_INITIALIZER;
sizeFlexiblity:(RCTRootViewSizeFlexibility)sizeFlexibility
fabric:(BOOL)fabric NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithFrame:(CGRect)frame
bridge:(RCTBridge *)bridge
reactTag:(NSNumber *)reactTag
sizeFlexiblity:(RCTRootViewSizeFlexibility)sizeFlexibility;
@end

View File

@ -21,8 +21,10 @@
bridge:(RCTBridge *)bridge
reactTag:(NSNumber *)reactTag
sizeFlexiblity:(RCTRootViewSizeFlexibility)sizeFlexibility
fabric:(BOOL)fabric
{
if ((self = [super initWithFrame:frame])) {
_fabric = fabric;
_bridge = bridge;
self.reactTag = reactTag;
_sizeFlexibility = sizeFlexibility;
@ -33,6 +35,14 @@
return self;
}
- (instancetype)initWithFrame:(CGRect)frame
bridge:(RCTBridge *)bridge
reactTag:(NSNumber *)reactTag
sizeFlexiblity:(RCTRootViewSizeFlexibility)sizeFlexibility
{
return [self initWithFrame:frame bridge:bridge reactTag:reactTag sizeFlexiblity:sizeFlexibility fabric:NO];
}
RCT_NOT_IMPLEMENTED(-(instancetype)initWithFrame:(CGRect)frame)
RCT_NOT_IMPLEMENTED(-(instancetype)initWithCoder:(nonnull NSCoder *)aDecoder)
@ -98,10 +108,18 @@ RCT_NOT_IMPLEMENTED(-(instancetype)initWithCoder:(nonnull NSCoder *)aDecoder)
if (self.userInteractionEnabled) {
self.userInteractionEnabled = NO;
[(RCTRootView *)self.superview contentViewInvalidated];
[_bridge enqueueJSCall:@"AppRegistry"
method:@"unmountApplicationComponentAtRootTag"
args:@[self.reactTag]
completion:NULL];
if (_fabric) {
[_bridge enqueueJSCall:@"ReactFabric"
method:@"unmountComponentAtNodeAndRemoveContainer"
args:@[self.reactTag]
completion:NULL];
} else {
[_bridge enqueueJSCall:@"AppRegistry"
method:@"unmountApplicationComponentAtRootTag"
args:@[self.reactTag]
completion:NULL];
}
}
}

View File

@ -44,7 +44,16 @@ extern NSString *const RCTContentDidAppearNotification;
*/
- (instancetype)initWithBridge:(RCTBridge *)bridge
moduleName:(NSString *)moduleName
initialProperties:(NSDictionary *)initialProperties NS_DESIGNATED_INITIALIZER;
initialProperties:(NSDictionary *)initialProperties
fabric:(BOOL)fabric NS_DESIGNATED_INITIALIZER;
/**
* - Convenience initializer -
* Initialize without using FabricUIManager.
*/
- (instancetype)initWithBridge:(RCTBridge *)bridge
moduleName:(NSString *)moduleName
initialProperties:(NSDictionary *)initialProperties;
/**
* - Convenience initializer -
@ -58,6 +67,16 @@ extern NSString *const RCTContentDidAppearNotification;
initialProperties:(NSDictionary *)initialProperties
launchOptions:(NSDictionary *)launchOptions;
/**
* - Convenience initializer -
*/
- (instancetype)initWithBundleURL:(NSURL *)bundleURL
moduleName:(NSString *)moduleName
initialProperties:(NSDictionary *)initialProperties
launchOptions:(NSDictionary *)launchOptions
fabric:(BOOL)fabric;
/**
* The name of the JavaScript module to execute within the
* specified scriptURL (required). Setting this will not have
@ -146,6 +165,11 @@ extern NSString *const RCTContentDidAppearNotification;
@property (nonatomic, assign) NSTimeInterval loadingViewFadeDelay;
@property (nonatomic, assign) NSTimeInterval loadingViewFadeDuration;
/**
* Indicates whether this view is managed by FabricUIManager or the traditional UIManager.
*/
@property (nonatomic, assign) BOOL fabric;
@end
@interface RCTRootView (Deprecated)

View File

@ -52,6 +52,7 @@ NSString *const RCTContentDidAppearNotification = @"RCTContentDidAppearNotificat
- (instancetype)initWithBridge:(RCTBridge *)bridge
moduleName:(NSString *)moduleName
initialProperties:(NSDictionary *)initialProperties
fabric:(BOOL)fabric
{
RCTAssertMainQueue();
RCTAssert(bridge, @"A bridge instance is required to create an RCTRootView");
@ -65,6 +66,7 @@ NSString *const RCTContentDidAppearNotification = @"RCTContentDidAppearNotificat
if (self = [super initWithFrame:CGRectZero]) {
self.backgroundColor = [UIColor whiteColor];
_fabric = fabric;
_bridge = bridge;
_moduleName = moduleName;
_appProperties = [initialProperties copy];
@ -106,16 +108,32 @@ NSString *const RCTContentDidAppearNotification = @"RCTContentDidAppearNotificat
return self;
}
- (instancetype)initWithBridge:(RCTBridge *)bridge
moduleName:(NSString *)moduleName
initialProperties:(NSDictionary *)initialProperties
{
return [self initWithBridge:bridge moduleName:moduleName initialProperties:initialProperties fabric:NO];
}
- (instancetype)initWithBundleURL:(NSURL *)bundleURL
moduleName:(NSString *)moduleName
initialProperties:(NSDictionary *)initialProperties
launchOptions:(NSDictionary *)launchOptions
fabric:(BOOL)fabric
{
RCTBridge *bridge = [[RCTBridge alloc] initWithBundleURL:bundleURL
moduleProvider:nil
launchOptions:launchOptions];
return [self initWithBridge:bridge moduleName:moduleName initialProperties:initialProperties];
return [self initWithBridge:bridge moduleName:moduleName initialProperties:initialProperties fabric:fabric];
}
- (instancetype)initWithBundleURL:(NSURL *)bundleURL
moduleName:(NSString *)moduleName
initialProperties:(NSDictionary *)initialProperties
launchOptions:(NSDictionary *)launchOptions
{
return [self initWithBundleURL:bundleURL moduleName:moduleName initialProperties:initialProperties launchOptions:launchOptions fabric:NO];
}
RCT_NOT_IMPLEMENTED(- (instancetype)initWithFrame:(CGRect)frame)
@ -271,7 +289,8 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder)
_contentView = [[RCTRootContentView alloc] initWithFrame:self.bounds
bridge:bridge
reactTag:self.reactTag
sizeFlexiblity:_sizeFlexibility];
sizeFlexiblity:_sizeFlexibility
fabric:self.fabric];
[self runApplication:bridge];
_contentView.passThroughTouches = _passThroughTouches;

View File

@ -42,9 +42,16 @@ NS_ASSUME_NONNULL_BEGIN
@property (atomic, copy, readwrite) NSDictionary *properties;
@property (nonatomic, assign, readonly) BOOL fabric;
- (instancetype)initWithBridge:(RCTBridge *)bridge
moduleName:(NSString *)moduleName
initialProperties:(NSDictionary *)initialProperties NS_DESIGNATED_INITIALIZER;
initialProperties:(NSDictionary *)initialProperties
fabric:(BOOL)fabric NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithBridge:(RCTBridge *)bridge
moduleName:(NSString *)moduleName
initialProperties:(NSDictionary *)initialProperties;
#pragma mark - Dealing with UIView representation, the Main thread only access

View File

@ -57,13 +57,16 @@
atomic_bool _waitingForMountingStageOnMainQueue;
}
- (instancetype)initWithBridge:(RCTBridge *)bridge
moduleName:(NSString *)moduleName
initialProperties:(NSDictionary *)initialProperties
fabric:(BOOL)fabric
{
RCTAssert(bridge.valid, @"Valid bridge is required to instanciate `RCTSurface`.");
if (self = [super init]) {
_fabric = fabric;
_bridge = bridge;
_batchedBridge = [_bridge batchedBridge] ?: _bridge;
_moduleName = moduleName;
@ -102,6 +105,13 @@
return self;
}
- (instancetype)initWithBridge:(RCTBridge *)bridge
moduleName:(NSString *)moduleName
initialProperties:(NSDictionary *)initialProperties
{
return [self initWithBridge:bridge moduleName:moduleName initialProperties:initialProperties fabric:NO];
}
- (void)dealloc
{
[self _stop];