From 90424389753c8290dffd3981436a1543f461dcde Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Wed, 1 Aug 2018 15:23:06 -0700 Subject: [PATCH] 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 --- .../RCTSurfaceBackedComponent.mm | 2 +- React/Base/Surface/RCTSurface.h | 1 - .../RCTSurfaceHostingProxyRootView.mm | 10 ++++------ React/Fabric/RCTSurfacePresenter.h | 5 +++++ React/Fabric/RCTSurfacePresenter.mm | 5 +++++ React/Fabric/Surface/RCTFabricSurface.h | 1 - React/Fabric/Surface/RCTFabricSurface.mm | 7 +++++-- 7 files changed, 20 insertions(+), 11 deletions(-) diff --git a/Libraries/SurfaceBackedComponent/RCTSurfaceBackedComponent.mm b/Libraries/SurfaceBackedComponent/RCTSurfaceBackedComponent.mm index 6cbdbd8a9..47b176524 100644 --- a/Libraries/SurfaceBackedComponent/RCTSurfaceBackedComponent.mm +++ b/Libraries/SurfaceBackedComponent/RCTSurfaceBackedComponent.mm @@ -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 diff --git a/React/Base/Surface/RCTSurface.h b/React/Base/Surface/RCTSurface.h index 5c3566725..955affd18 100644 --- a/React/Base/Surface/RCTSurface.h +++ b/React/Base/Surface/RCTSurface.h @@ -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; diff --git a/React/Base/Surface/SurfaceHostingView/RCTSurfaceHostingProxyRootView.mm b/React/Base/Surface/SurfaceHostingView/RCTSurfaceHostingProxyRootView.mm index 144662974..a54a1ab5f 100644 --- a/React/Base/Surface/SurfaceHostingView/RCTSurfaceHostingProxyRootView.mm +++ b/React/Base/Surface/SurfaceHostingView/RCTSurfaceHostingProxyRootView.mm @@ -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]; diff --git a/React/Fabric/RCTSurfacePresenter.h b/React/Fabric/RCTSurfacePresenter.h index 65e86b128..793295d0a 100644 --- a/React/Fabric/RCTSurfacePresenter.h +++ b/React/Fabric/RCTSurfacePresenter.h @@ -63,6 +63,11 @@ NS_ASSUME_NONNULL_BEGIN */ - (std::shared_ptr)uiManager_DO_NOT_USE; +/** + * Returns a underlying bridge. + */ +- (RCTBridge *)bridge_DO_NOT_USE; + @end @interface RCTBridge (RCTSurfacePresenter) diff --git a/React/Fabric/RCTSurfacePresenter.mm b/React/Fabric/RCTSurfacePresenter.mm index e3223804d..aedcd7ae8 100644 --- a/React/Fabric/RCTSurfacePresenter.mm +++ b/React/Fabric/RCTSurfacePresenter.mm @@ -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) diff --git a/React/Fabric/Surface/RCTFabricSurface.h b/React/Fabric/Surface/RCTFabricSurface.h index c0a88c072..6669cc35f 100644 --- a/React/Fabric/Surface/RCTFabricSurface.h +++ b/React/Fabric/Surface/RCTFabricSurface.h @@ -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; diff --git a/React/Fabric/Surface/RCTFabricSurface.mm b/React/Fabric/Surface/RCTFabricSurface.mm index d0b93710f..243f38c3d 100644 --- a/React/Fabric/Surface/RCTFabricSurface.mm +++ b/React/Fabric/Surface/RCTFabricSurface.mm @@ -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;