Skip to content

Commit e9e0cd7

Browse files
sherginfacebook-github-bot
authored andcommitted
RCTSurface: Couple helper functions for Stage
Summary: We need this trivial funcs to unify spinner appearance logic. Reviewed By: rsnara Differential Revision: D6367072 fbshipit-source-id: 70e288bc1fed5911828a5f6deaa829597bf8ebff
1 parent da17b23 commit e9e0cd7

File tree

4 files changed

+36
-2
lines changed

4 files changed

+36
-2
lines changed

Libraries/SurfaceBackedComponent/RCTSurfaceBackedComponent.mm

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ + (instancetype)newWithBridge:(RCTBridge *)bridge
5555
options:options];
5656

5757
CKComponent *component;
58-
if (options.activityIndicatorComponentFactory == nil || state.surface.stage & RCTSurfaceStageSurfaceDidInitialLayout) {
58+
if (options.activityIndicatorComponentFactory == nil || RCTSurfaceStageIsRunning(state.surface.stage)) {
5959
component = surfaceHostingComponent;
6060
} else {
6161
component = [CKOverlayLayoutComponent newWithComponent:surfaceHostingComponent

React/Base/Surface/RCTSurface.mm

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge
8282
_stage = RCTSurfaceStageSurfaceDidInitialize;
8383

8484
if (!bridge.loading) {
85-
_stage = (RCTSurfaceStage)(_stage | RCTSurfaceStageBridgeDidLoad);
85+
_stage = _stage | RCTSurfaceStageBridgeDidLoad;
8686
}
8787

8888
[self _registerRootViewTag];

React/Base/Surface/RCTSurfaceStage.h

+12
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
#import <UIKit/UIKit.h>
1111

12+
#import <React/RCTDefines.h>
13+
1214
/**
1315
* The stage of the Surface
1416
*/
@@ -22,3 +24,13 @@ typedef NS_OPTIONS(NSInteger, RCTSurfaceStage) {
2224
RCTSurfaceStageSurfaceDidInitialMounting = 1 << 6, // UIManager completed the first mounting pass
2325
RCTSurfaceStageSurfaceDidInvalidate = 1 << 7, // Surface received `invalidate` message
2426
};
27+
28+
/**
29+
* Returns `YES` if the stage is suitable for displaying normal React Native app.
30+
*/
31+
RCT_EXTERN BOOL RCTSurfaceStageIsRunning(RCTSurfaceStage stage);
32+
33+
/**
34+
* Returns `YES` if the stage is suitable for displaying activity indicator.
35+
*/
36+
RCT_EXTERN BOOL RCTSurfaceStageIsPreparing(RCTSurfaceStage stage);

React/Base/Surface/RCTSurfaceStage.m

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
#import "RCTSurfaceStage.h"
11+
12+
BOOL RCTSurfaceStageIsRunning(RCTSurfaceStage stage) {
13+
return
14+
(stage & RCTSurfaceStageSurfaceDidInitialLayout) &&
15+
!(stage & RCTSurfaceStageSurfaceDidInvalidate);
16+
}
17+
18+
BOOL RCTSurfaceStageIsPreparing(RCTSurfaceStage stage) {
19+
return
20+
!(stage & RCTSurfaceStageSurfaceDidInitialLayout) &&
21+
!(stage & RCTSurfaceStageSurfaceDidInvalidate);
22+
}

0 commit comments

Comments
 (0)