diff --git a/React/Base/RCTRootContentView.h b/React/Base/RCTRootContentView.h index 28a0646cf..bd14cfb20 100644 --- a/React/Base/RCTRootContentView.h +++ b/React/Base/RCTRootContentView.h @@ -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 diff --git a/React/Base/RCTRootContentView.m b/React/Base/RCTRootContentView.m index 9de3f78e0..7782d06f0 100644 --- a/React/Base/RCTRootContentView.m +++ b/React/Base/RCTRootContentView.m @@ -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]; + } } } diff --git a/React/Base/RCTRootView.h b/React/Base/RCTRootView.h index 9c04c8222..41c21f672 100644 --- a/React/Base/RCTRootView.h +++ b/React/Base/RCTRootView.h @@ -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) diff --git a/React/Base/RCTRootView.m b/React/Base/RCTRootView.m index 204dd5871..8fabbd6e8 100644 --- a/React/Base/RCTRootView.m +++ b/React/Base/RCTRootView.m @@ -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; diff --git a/React/Base/Surface/RCTSurface.h b/React/Base/Surface/RCTSurface.h index 66f5cabbc..01d4896f9 100644 --- a/React/Base/Surface/RCTSurface.h +++ b/React/Base/Surface/RCTSurface.h @@ -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 diff --git a/React/Base/Surface/RCTSurface.mm b/React/Base/Surface/RCTSurface.mm index 3581ac1e7..eac4985e0 100644 --- a/React/Base/Surface/RCTSurface.mm +++ b/React/Base/Surface/RCTSurface.mm @@ -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];