iOS: branch out Fabric handling into a separate RCTSurface-compatible class.

Reviewed By: mmmulani

Differential Revision: D7158824

fbshipit-source-id: 80eb61835181fa3f522b788e2861470cba88890a
This commit is contained in:
Kevin Gozali 2018-03-05 18:29:39 -08:00 коммит произвёл Facebook Github Bot
Родитель 9366ce416f
Коммит b4ce4277af
16 изменённых файлов: 165 добавлений и 156 удалений

Просмотреть файл

@ -24,17 +24,9 @@
@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
fabric:(BOOL)fabric NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithFrame:(CGRect)frame
bridge:(RCTBridge *)bridge
reactTag:(NSNumber *)reactTag
sizeFlexiblity:(RCTRootViewSizeFlexibility)sizeFlexibility;
sizeFlexiblity:(RCTRootViewSizeFlexibility)sizeFlexibility NS_DESIGNATED_INITIALIZER;
@end

Просмотреть файл

@ -21,10 +21,8 @@
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;
@ -35,14 +33,6 @@
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)
@ -109,17 +99,10 @@ RCT_NOT_IMPLEMENTED(-(instancetype)initWithCoder:(nonnull NSCoder *)aDecoder)
self.userInteractionEnabled = NO;
[(RCTRootView *)self.superview contentViewInvalidated];
if (_fabric) {
[_bridge enqueueJSCall:@"ReactFabric"
method:@"unmountComponentAtNodeAndRemoveContainer"
args:@[self.reactTag]
completion:NULL];
} else {
[_bridge enqueueJSCall:@"AppRegistry"
method:@"unmountApplicationComponentAtRootTag"
args:@[self.reactTag]
completion:NULL];
}
[_bridge enqueueJSCall:@"AppRegistry"
method:@"unmountApplicationComponentAtRootTag"
args:@[self.reactTag]
completion:NULL];
}
}

Просмотреть файл

@ -44,16 +44,7 @@ extern NSString *const RCTContentDidAppearNotification;
*/
- (instancetype)initWithBridge:(RCTBridge *)bridge
moduleName:(NSString *)moduleName
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;
initialProperties:(NSDictionary *)initialProperties NS_DESIGNATED_INITIALIZER;
/**
* - Convenience initializer -
@ -67,15 +58,6 @@ 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
@ -165,11 +147,6 @@ 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)

Просмотреть файл

@ -52,7 +52,6 @@ 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");
@ -66,7 +65,6 @@ NSString *const RCTContentDidAppearNotification = @"RCTContentDidAppearNotificat
if (self = [super initWithFrame:CGRectZero]) {
self.backgroundColor = [UIColor whiteColor];
_fabric = fabric;
_bridge = bridge;
_moduleName = moduleName;
_appProperties = [initialProperties copy];
@ -108,32 +106,16 @@ 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 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];
return [self initWithBridge:bridge moduleName:moduleName initialProperties:initialProperties];
}
RCT_NOT_IMPLEMENTED(- (instancetype)initWithFrame:(CGRect)frame)
@ -289,8 +271,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder)
_contentView = [[RCTRootContentView alloc] initWithFrame:self.bounds
bridge:bridge
reactTag:self.reactTag
sizeFlexiblity:_sizeFlexibility
fabric:self.fabric];
sizeFlexiblity:_sizeFlexibility];
[self runApplication:bridge];
_contentView.passThroughTouches = _passThroughTouches;

Просмотреть файл

@ -42,16 +42,9 @@ 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
fabric:(BOOL)fabric NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithBridge:(RCTBridge *)bridge
moduleName:(NSString *)moduleName
initialProperties:(NSDictionary *)initialProperties;
initialProperties:(NSDictionary *)initialProperties NS_DESIGNATED_INITIALIZER;
#pragma mark - Dealing with UIView representation, the Main thread only access
@ -122,6 +115,19 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (BOOL)synchronouslyWaitForStage:(RCTSurfaceStage)stage timeout:(NSTimeInterval)timeout;
#pragma mark - Mounting/Unmounting of React components
/**
* Mount the React component specified by the given moduleName. This is typically
* calling runApplication.js from the native side.
*/
- (void)mountReactComponentWithBridge:(RCTBridge *)bridge moduleName:(NSString *)moduleName params:(NSDictionary *)params;
/**
* Unmount the React component specified by the given rootViewTag, called from native.
*/
- (void)unmountReactComponentWithBridge:(RCTBridge *)bridge rootViewTag:(NSNumber *)rootViewTag;
@end
NS_ASSUME_NONNULL_END

Просмотреть файл

@ -61,12 +61,10 @@
- (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;
@ -105,13 +103,6 @@
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];
@ -310,21 +301,14 @@
RCTLogInfo(@"Running surface %@ (%@)", _moduleName, applicationParameters);
[batchedBridge enqueueJSCall:@"AppRegistry"
method:@"runApplication"
args:@[_moduleName, applicationParameters]
completion:NULL];
[self mountReactComponentWithBridge:batchedBridge moduleName:_moduleName params:applicationParameters];
[self _setStage:RCTSurfaceStageSurfaceDidRun];
}
- (void)_stop
{
RCTBridge *batchedBridge = self._batchedBridge;
[batchedBridge enqueueJSCall:@"AppRegistry"
method:@"unmountApplicationComponentAtRootTag"
args:@[self->_rootViewTag]
completion:NULL];
[self unmountReactComponentWithBridge:self._batchedBridge rootViewTag:self->_rootViewTag];
}
- (void)_registerRootView
@ -571,4 +555,16 @@
}
}
#pragma mark - Mounting/Unmounting of React components
- (void)mountReactComponentWithBridge:(RCTBridge *)bridge moduleName:(NSString *)moduleName params:(NSDictionary *)params
{
[bridge enqueueJSCall:@"AppRegistry" method:@"runApplication" args:@[moduleName, params] completion:NULL];
}
- (void)unmountReactComponentWithBridge:(RCTBridge *)bridge rootViewTag:(NSNumber *)rootViewTag
{
[bridge enqueueJSCall:@"AppRegistry" method:@"unmountApplicationComponentAtRootTag" args:@[rootViewTag] completion:NULL];
}
@end

Просмотреть файл

@ -35,28 +35,16 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, assign) BOOL passThroughTouches;
@property (nonatomic, assign) NSTimeInterval loadingViewFadeDelay;
@property (nonatomic, assign) NSTimeInterval loadingViewFadeDuration;
@property (nonatomic, assign) BOOL fabric;
- (instancetype)initWithBridge:(RCTBridge *)bridge
moduleName:(NSString *)moduleName
initialProperties:(NSDictionary *)initialProperties
fabric:(BOOL)fabric NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithBridge:(RCTBridge *)bridge
moduleName:(NSString *)moduleName
initialProperties:(NSDictionary *)initialProperties;
initialProperties:(NSDictionary *)initialProperties NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithBundleURL:(NSURL *)bundleURL
moduleName:(NSString *)moduleName
initialProperties:(NSDictionary *)initialProperties
launchOptions:(NSDictionary *)launchOptions;
- (instancetype)initWithBundleURL:(NSURL *)bundleURL
moduleName:(NSString *)moduleName
initialProperties:(NSDictionary *)initialProperties
launchOptions:(NSDictionary *)launchOptions
fabric:(BOOL)fabric;
- (void)cancelTouches;
@end

Просмотреть файл

@ -51,7 +51,6 @@ static RCTRootViewSizeFlexibility convertToRootViewSizeFlexibility(RCTSurfaceSiz
- (instancetype)initWithBridge:(RCTBridge *)bridge
moduleName:(NSString *)moduleName
initialProperties:(NSDictionary *)initialProperties
fabric:(BOOL)fabric
{
RCTAssertMainQueue();
RCTAssert(bridge, @"A bridge instance is required to create an RCTSurfaceHostingProxyRootView");
@ -62,7 +61,7 @@ static RCTRootViewSizeFlexibility convertToRootViewSizeFlexibility(RCTSurfaceSiz
[bridge.performanceLogger markStartForTag:RCTPLTTI];
}
if (self = [super initWithBridge:bridge moduleName:moduleName initialProperties:initialProperties fabric:fabric]) {
if (self = [super initWithBridge:bridge moduleName:moduleName initialProperties:initialProperties]) {
self.backgroundColor = [UIColor whiteColor];
}
@ -71,32 +70,16 @@ static RCTRootViewSizeFlexibility convertToRootViewSizeFlexibility(RCTSurfaceSiz
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 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];
return [self initWithBridge:bridge moduleName:moduleName initialProperties:initialProperties];
}
RCT_NOT_IMPLEMENTED(- (instancetype)initWithFrame:(CGRect)frame)
@ -114,11 +97,6 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder)
return super.surface.bridge;
}
- (BOOL)fabric
{
return super.surface.fabric;
}
- (UIView *)contentView
{
return self;

Просмотреть файл

@ -43,13 +43,11 @@ NS_ASSUME_NONNULL_BEGIN
initialProperties:(NSDictionary *)initialProperties;
/**
* Convenience initializer.
* To control toggle Fabric for the Surface.
* Create an instance of RCTSurface to be hosted.
*/
- (instancetype)initWithBridge:(RCTBridge *)bridge
moduleName:(NSString *)moduleName
initialProperties:(NSDictionary *)initialProperties
fabric:(BOOL)fabric;
- (RCTSurface *)createSurfaceWithBridge:(RCTBridge *)bridge
moduleName:(NSString *)moduleName
initialProperties:(NSDictionary *)initialProperties;
/**
* Surface object which is currently using to power the view.

Просмотреть файл

@ -33,23 +33,12 @@ RCT_NOT_IMPLEMENTED(- (nullable instancetype)initWithCoder:(NSCoder *)coder)
- (instancetype)initWithBridge:(RCTBridge *)bridge
moduleName:(NSString *)moduleName
initialProperties:(NSDictionary *)initialProperties
fabric:(BOOL)fabric
{
RCTSurface *surface = [[RCTSurface alloc] initWithBridge:bridge
moduleName:moduleName
initialProperties:initialProperties
fabric:fabric];
RCTSurface *surface = [self createSurfaceWithBridge:bridge moduleName:moduleName initialProperties:initialProperties];
return [self initWithSurface:surface];
}
- (instancetype)initWithBridge:(RCTBridge *)bridge
moduleName:(NSString *)moduleName
initialProperties:(NSDictionary *)initialProperties
{
return [self initWithBridge:bridge moduleName:moduleName initialProperties:initialProperties fabric:NO];
}
- (instancetype)initWithSurface:(RCTSurface *)surface
{
if (self = [super initWithFrame:CGRectZero]) {
@ -67,6 +56,13 @@ RCT_NOT_IMPLEMENTED(- (nullable instancetype)initWithCoder:(NSCoder *)coder)
return self;
}
- (RCTSurface *)createSurfaceWithBridge:(RCTBridge *)bridge
moduleName:(NSString *)moduleName
initialProperties:(NSDictionary *)initialProperties
{
return [[RCTSurface alloc] initWithBridge:bridge moduleName:moduleName initialProperties:initialProperties];
}
- (void)setFrame:(CGRect)frame
{
[super setFrame:frame];

Просмотреть файл

@ -0,0 +1,16 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <React/RCTSurface.h>
/**
* Fabric-compatible RCTSurface implementation.
* It may not continue extending from RCTSurface in the future.
*/
@interface RCTFabricSurface : RCTSurface
@end

Просмотреть файл

@ -0,0 +1,22 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "RCTFabricSurface.h"
#import <React/RCTBridge.h>
@implementation RCTFabricSurface
- (void)unmountReactComponentWithBridge:(RCTBridge *)bridge rootViewTag:(NSNumber *)rootViewTag
{
[bridge enqueueJSCall:@"ReactFabric"
method:@"unmountComponentAtNodeAndRemoveContainer"
args:@[rootViewTag]
completion:NULL];
}
@end

Просмотреть файл

@ -0,0 +1,16 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <React/RCTSurfaceHostingProxyRootView.h>
/**
* Fabric-compatible RCTSurfaceHostingProxyRootView implementation.
*/
@interface RCTFabricSurfaceHostingProxyRootView : RCTSurfaceHostingProxyRootView
@end

Просмотреть файл

@ -0,0 +1,19 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "RCTFabricSurfaceHostingProxyRootView.h"
#import "RCTFabricSurface.h"
@implementation RCTFabricSurfaceHostingProxyRootView
- (RCTSurface *)createSurfaceWithBridge:(RCTBridge *)bridge moduleName:(NSString *)moduleName initialProperties:(NSDictionary *)initialProperties
{
return [[RCTFabricSurface alloc] initWithBridge:bridge moduleName:moduleName initialProperties:initialProperties];
}
@end

Просмотреть файл

@ -0,0 +1,16 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <React/RCTSurfaceHostingView.h>
/**
* Fabric-compatible RCTSurfaceHostingView implementation.
*/
@interface RCTFabricSurfaceHostingView : RCTSurfaceHostingView
@end

Просмотреть файл

@ -0,0 +1,25 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "RCTFabricSurfaceHostingView.h"
#import "RCTFabricSurface.h"
@implementation RCTFabricSurfaceHostingView
- (instancetype)initWithBridge:(RCTBridge *)bridge
moduleName:(NSString *)moduleName
initialProperties:(NSDictionary *)initialProperties
{
RCTFabricSurface *surface = [[RCTFabricSurface alloc] initWithBridge:bridge
moduleName:moduleName
initialProperties:initialProperties];
return [self initWithSurface:surface];
}
@end