diff --git a/Libraries/SurfaceBackedComponent/RCTSurfaceBackedComponent.mm b/Libraries/SurfaceBackedComponent/RCTSurfaceBackedComponent.mm index 74e03c5cf2ca88..d2875f2136f3f6 100644 --- a/Libraries/SurfaceBackedComponent/RCTSurfaceBackedComponent.mm +++ b/Libraries/SurfaceBackedComponent/RCTSurfaceBackedComponent.mm @@ -55,7 +55,7 @@ + (instancetype)newWithBridge:(RCTBridge *)bridge options:options]; CKComponent *component; - if (options.activityIndicatorComponentFactory == nil || state.surface.stage & RCTSurfaceStageSurfaceDidInitialLayout) { + if (options.activityIndicatorComponentFactory == nil || RCTSurfaceStageIsRunning(state.surface.stage)) { component = surfaceHostingComponent; } else { component = [CKOverlayLayoutComponent newWithComponent:surfaceHostingComponent diff --git a/React/Base/Surface/RCTSurface.mm b/React/Base/Surface/RCTSurface.mm index 4441822e414b7a..07c0521c774970 100644 --- a/React/Base/Surface/RCTSurface.mm +++ b/React/Base/Surface/RCTSurface.mm @@ -82,7 +82,7 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge _stage = RCTSurfaceStageSurfaceDidInitialize; if (!bridge.loading) { - _stage = (RCTSurfaceStage)(_stage | RCTSurfaceStageBridgeDidLoad); + _stage = _stage | RCTSurfaceStageBridgeDidLoad; } [self _registerRootViewTag]; diff --git a/React/Base/Surface/RCTSurfaceStage.h b/React/Base/Surface/RCTSurfaceStage.h index a02ebc36d80db8..3cf91ad4f6d062 100644 --- a/React/Base/Surface/RCTSurfaceStage.h +++ b/React/Base/Surface/RCTSurfaceStage.h @@ -9,6 +9,8 @@ #import +#import + /** * The stage of the Surface */ @@ -22,3 +24,13 @@ typedef NS_OPTIONS(NSInteger, RCTSurfaceStage) { RCTSurfaceStageSurfaceDidInitialMounting = 1 << 6, // UIManager completed the first mounting pass RCTSurfaceStageSurfaceDidInvalidate = 1 << 7, // Surface received `invalidate` message }; + +/** + * Returns `YES` if the stage is suitable for displaying normal React Native app. + */ +RCT_EXTERN BOOL RCTSurfaceStageIsRunning(RCTSurfaceStage stage); + +/** + * Returns `YES` if the stage is suitable for displaying activity indicator. + */ +RCT_EXTERN BOOL RCTSurfaceStageIsPreparing(RCTSurfaceStage stage); diff --git a/React/Base/Surface/RCTSurfaceStage.m b/React/Base/Surface/RCTSurfaceStage.m new file mode 100644 index 00000000000000..932d1906db1a61 --- /dev/null +++ b/React/Base/Surface/RCTSurfaceStage.m @@ -0,0 +1,22 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +#import "RCTSurfaceStage.h" + +BOOL RCTSurfaceStageIsRunning(RCTSurfaceStage stage) { + return + (stage & RCTSurfaceStageSurfaceDidInitialLayout) && + !(stage & RCTSurfaceStageSurfaceDidInvalidate); +} + +BOOL RCTSurfaceStageIsPreparing(RCTSurfaceStage stage) { + return + !(stage & RCTSurfaceStageSurfaceDidInitialLayout) && + !(stage & RCTSurfaceStageSurfaceDidInvalidate); +}