Tweaking -[RCTSurface synchronouslyWaitForStage:]
Summary: Waiting for layout is now available on main thread. Reviewed By: mmmulani Differential Revision: D6719836 fbshipit-source-id: ef655095e999df5f77e69c5931459cce1aaeb1f0
This commit is contained in:
parent
d0f7d4d107
commit
193a2bd4cd
|
@ -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 @@
|
|||
|
||||
- (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 @@
|
|||
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.
|
||||
|
|
Loading…
Reference in New Issue