Permalink
Browse files

Tweaking -[RCTSurface synchronouslyWaitForStage:]

Summary: Waiting for layout is now available on main thread.

Reviewed By: mmmulani

Differential Revision: D6719836

fbshipit-source-id: ef655095e999df5f77e69c5931459cce1aaeb1f0
  • Loading branch information...
shergin authored and facebook-github-bot committed Jan 16, 2018
1 parent d0f7d4d commit 193a2bd4cdffbbc79b69c067b31420663dc9b03a
Showing with 16 additions and 13 deletions.
  1. +6 −3 React/Base/Surface/RCTSurface.h
  2. +10 −10 React/Base/Surface/RCTSurface.mm
@@ -84,7 +84,6 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property (atomic, assign, readonly) CGSize maximumSize;
/**
* Simple shortcut to `-[RCTSurface setMinimumSize:size maximumSize:size]`.
*/
@@ -109,8 +108,12 @@ NS_ASSUME_NONNULL_BEGIN
/**
* Synchronously blocks the current thread up to given `timeout` until
* the Surface will not have given `stage`.
* Do nothing, if called from the main or `UIManager` queue.
* the Surface reaches `stage`.
* Limitations:
* - Do nothing, if called on `UIManager` queue.
* - Calling on the main queue with `RCTSurfaceStageSurfaceDidInitialMounting`
* stage temporary is not supported; in this case the stage will be
* downgraded to `RCTSurfaceStageSurfaceDidInitialLayout`.
*/
- (BOOL)synchronouslyWaitForStage:(RCTSurfaceStage)stage timeout:(NSTimeInterval)timeout;
@@ -435,6 +435,16 @@ - (CGSize)intrinsicSize
- (BOOL)synchronouslyWaitForStage:(RCTSurfaceStage)stage timeout:(NSTimeInterval)timeout
{
if (RCTIsMainQueue() && (stage == RCTSurfaceStageSurfaceDidInitialRendering)) {
// This case *temporary* does not supported.
stage = RCTSurfaceStageSurfaceDidInitialLayout;
}
if (RCTIsUIManagerQueue()) {
RCTLogInfo(@"Synchronous waiting is not supported on UIManager queue.");
return NO;
}
dispatch_semaphore_t semaphore;
switch (stage) {
case RCTSurfaceStageSurfaceDidInitialLayout:
@@ -447,16 +457,6 @@ - (BOOL)synchronouslyWaitForStage:(RCTSurfaceStage)stage timeout:(NSTimeInterval
RCTAssert(NO, @"Only waiting for `RCTSurfaceStageSurfaceDidInitialRendering` and `RCTSurfaceStageSurfaceDidInitialLayout` stages is supported.");
}
if (RCTIsMainQueue()) {
RCTLogInfo(@"Synchronous waiting is not supported on the main queue.");
return NO;
}
if (RCTIsUIManagerQueue()) {
RCTLogInfo(@"Synchronous waiting is not supported on UIManager queue.");
return NO;
}
BOOL timeoutOccured = dispatch_semaphore_wait(semaphore, dispatch_time(DISPATCH_TIME_NOW, timeout * NSEC_PER_SEC));
if (!timeoutOccured) {
// Balancing the semaphore.

0 comments on commit 193a2bd

Please sign in to comment.