Fabric: `bridge` prop was removed from RCTSurface interface

Summary:
@public
We are moving away from using `RCTBridge` instance in public APIs to enable us using more performance solutions in the future.
This change also fixes "SwipeBack issue" caused by RCTSurfaceHostingProxyRootView returning nil bridge.

Reviewed By: mdvacca

Differential Revision: D9094625

fbshipit-source-id: 6bde3c54773e75ca4c0b6fd908da9d7235b5c3be
This commit is contained in:
Valentin Shergin 2018-08-01 15:23:06 -07:00 committed by Facebook Github Bot
parent ed6a5ff4b4
commit 9042438975
7 changed files with 20 additions and 11 deletions

View File

@ -32,7 +32,7 @@
RCTSurfaceBackedComponentState *state = scope.state();
if (state.surface == nil || state.surface.bridge != bridge || ![state.surface.moduleName isEqualToString:moduleName]) {
if (state.surface == nil || ![state.surface.moduleName isEqualToString:moduleName]) {
RCTSurface *surface =
[[RCTSurface alloc] initWithBridge:bridge
moduleName:moduleName

View File

@ -34,7 +34,6 @@ NS_ASSUME_NONNULL_BEGIN
@interface RCTSurface : NSObject
@property (atomic, readonly) RCTSurfaceStage stage;
@property (atomic, readonly) RCTBridge *bridge;
@property (atomic, readonly) NSString *moduleName;
@property (atomic, readonly) NSNumber *rootViewTag;

View File

@ -57,6 +57,9 @@ static RCTRootViewSizeFlexibility convertToRootViewSizeFlexibility(RCTSurfaceSiz
RCTAssert(moduleName, @"A moduleName is required to create an RCTSurfaceHostingProxyRootView");
RCT_PROFILE_BEGIN_EVENT(RCTProfileTagAlways, @"-[RCTSurfaceHostingProxyRootView init]", nil);
_bridge = bridge;
if (!bridge.isLoading) {
[bridge.performanceLogger markStartForTag:RCTPLTTI];
}
@ -95,11 +98,6 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder)
return super.surface.moduleName;
}
- (RCTBridge *)bridge
{
return super.surface.bridge;
}
- (UIView *)contentView
{
return self;
@ -148,7 +146,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder)
{
[super surface:surface didChangeStage:stage];
if (RCTSurfaceStageIsRunning(stage)) {
[super.surface.bridge.performanceLogger markStopForTag:RCTPLTTI];
[_bridge.performanceLogger markStopForTag:RCTPLTTI];
dispatch_async(dispatch_get_main_queue(), ^{
[[NSNotificationCenter defaultCenter] postNotificationName:RCTContentDidAppearNotification
object:self];

View File

@ -63,6 +63,11 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (std::shared_ptr<facebook::react::FabricUIManager>)uiManager_DO_NOT_USE;
/**
* Returns a underlying bridge.
*/
- (RCTBridge *)bridge_DO_NOT_USE;
@end
@interface RCTBridge (RCTSurfacePresenter)

View File

@ -201,6 +201,11 @@ using namespace facebook::react;
return _scheduler.uiManager_DO_NOT_USE;
}
- (RCTBridge *)bridge_DO_NOT_USE
{
return _bridge;
}
@end
@implementation RCTBridge (RCTSurfacePresenter)

View File

@ -36,7 +36,6 @@ NS_ASSUME_NONNULL_BEGIN
@interface RCTFabricSurface : NSObject
@property (atomic, readonly) RCTSurfaceStage stage;
@property (atomic, readonly) RCTBridge *bridge;
@property (atomic, readonly) NSString *moduleName;
@property (atomic, readonly) ReactTag rootTag;

View File

@ -74,14 +74,17 @@
[self _run];
// TODO: This will be moved to RCTSurfacePresenter.
RCTBridge *bridge = surfacePresenter.bridge_DO_NOT_USE;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleJavaScriptWillStartLoadingNotification:)
name:RCTJavaScriptWillStartLoadingNotification
object:_bridge];
object:bridge];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleJavaScriptDidLoadNotification:)
name:RCTJavaScriptDidLoadNotification
object:_bridge];
object:bridge];
}
return self;