Skip to content

Commit 193a2bd

Browse files
sherginfacebook-github-bot
authored andcommitted
Tweaking -[RCTSurface synchronouslyWaitForStage:]
Summary: Waiting for layout is now available on main thread. Reviewed By: mmmulani Differential Revision: D6719836 fbshipit-source-id: ef655095e999df5f77e69c5931459cce1aaeb1f0
1 parent d0f7d4d commit 193a2bd

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

React/Base/Surface/RCTSurface.h

+6-3
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ NS_ASSUME_NONNULL_BEGIN
8484
*/
8585
@property (atomic, assign, readonly) CGSize maximumSize;
8686

87-
8887
/**
8988
* Simple shortcut to `-[RCTSurface setMinimumSize:size maximumSize:size]`.
9089
*/
@@ -109,8 +108,12 @@ NS_ASSUME_NONNULL_BEGIN
109108

110109
/**
111110
* Synchronously blocks the current thread up to given `timeout` until
112-
* the Surface will not have given `stage`.
113-
* Do nothing, if called from the main or `UIManager` queue.
111+
* the Surface reaches `stage`.
112+
* Limitations:
113+
* - Do nothing, if called on `UIManager` queue.
114+
* - Calling on the main queue with `RCTSurfaceStageSurfaceDidInitialMounting`
115+
* stage temporary is not supported; in this case the stage will be
116+
* downgraded to `RCTSurfaceStageSurfaceDidInitialLayout`.
114117
*/
115118
- (BOOL)synchronouslyWaitForStage:(RCTSurfaceStage)stage timeout:(NSTimeInterval)timeout;
116119

React/Base/Surface/RCTSurface.mm

+10-10
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,16 @@ - (CGSize)intrinsicSize
435435

436436
- (BOOL)synchronouslyWaitForStage:(RCTSurfaceStage)stage timeout:(NSTimeInterval)timeout
437437
{
438+
if (RCTIsMainQueue() && (stage == RCTSurfaceStageSurfaceDidInitialRendering)) {
439+
// This case *temporary* does not supported.
440+
stage = RCTSurfaceStageSurfaceDidInitialLayout;
441+
}
442+
443+
if (RCTIsUIManagerQueue()) {
444+
RCTLogInfo(@"Synchronous waiting is not supported on UIManager queue.");
445+
return NO;
446+
}
447+
438448
dispatch_semaphore_t semaphore;
439449
switch (stage) {
440450
case RCTSurfaceStageSurfaceDidInitialLayout:
@@ -447,16 +457,6 @@ - (BOOL)synchronouslyWaitForStage:(RCTSurfaceStage)stage timeout:(NSTimeInterval
447457
RCTAssert(NO, @"Only waiting for `RCTSurfaceStageSurfaceDidInitialRendering` and `RCTSurfaceStageSurfaceDidInitialLayout` stages is supported.");
448458
}
449459

450-
if (RCTIsMainQueue()) {
451-
RCTLogInfo(@"Synchronous waiting is not supported on the main queue.");
452-
return NO;
453-
}
454-
455-
if (RCTIsUIManagerQueue()) {
456-
RCTLogInfo(@"Synchronous waiting is not supported on UIManager queue.");
457-
return NO;
458-
}
459-
460460
BOOL timeoutOccured = dispatch_semaphore_wait(semaphore, dispatch_time(DISPATCH_TIME_NOW, timeout * NSEC_PER_SEC));
461461
if (!timeoutOccured) {
462462
// Balancing the semaphore.

0 commit comments

Comments
 (0)