Skip to content

Commit

Permalink
-[RCTUIManagerObserver uiManagerDidPerformMounting]
Browse files Browse the repository at this point in the history
Reviewed By: rsnara

Differential Revision: D6434461

fbshipit-source-id: a66407936cec3582cb27c57eb8e36dc225149c45
  • Loading branch information
shergin authored and facebook-github-bot committed Dec 12, 2017
1 parent 0a8721c commit 60dc9be
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 21 deletions.
49 changes: 28 additions & 21 deletions React/Modules/RCTUIManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ - (void)setBackgroundColor:(UIColor *)color forView:(UIView *)view

shadowView.backgroundColor = color;
[self _amendPendingUIBlocksWithStylePropagationUpdateForShadowView:shadowView];
[self flushUIBlocks];
[self flushUIBlocksWithCompletion:^{}];
} forTag:view.reactTag];
}

Expand Down Expand Up @@ -1128,10 +1128,12 @@ - (void)_layoutAndMount

[_observerCoordinator uiManagerWillPerformMounting:self];

[self flushUIBlocks];
[self flushUIBlocksWithCompletion:^{
[self->_observerCoordinator uiManagerDidPerformMounting:self];
}];
}

- (void)flushUIBlocks
- (void)flushUIBlocksWithCompletion:(void (^)(void))completion;
{
RCTAssertUIManagerQueue();

Expand All @@ -1141,25 +1143,30 @@ - (void)flushUIBlocks
NSArray<RCTViewManagerUIBlock> *previousPendingUIBlocks = _pendingUIBlocks;
_pendingUIBlocks = [NSMutableArray new];

if (previousPendingUIBlocks.count) {
// Execute the previously queued UI blocks
RCTProfileBeginFlowEvent();
RCTExecuteOnMainQueue(^{
RCTProfileEndFlowEvent();
RCT_PROFILE_BEGIN_EVENT(RCTProfileTagAlways, @"-[UIManager flushUIBlocks]", (@{
@"count": [@(previousPendingUIBlocks.count) stringValue],
}));
@try {
for (RCTViewManagerUIBlock block in previousPendingUIBlocks) {
block(self, self->_viewRegistry);
}
}
@catch (NSException *exception) {
RCTLogError(@"Exception thrown while executing UI block: %@", exception);
}
RCT_PROFILE_END_EVENT(RCTProfileTagAlways, @"");
});
if (previousPendingUIBlocks.count == 0) {
completion();
return;
}

// Execute the previously queued UI blocks
RCTProfileBeginFlowEvent();
RCTExecuteOnMainQueue(^{
RCTProfileEndFlowEvent();
RCT_PROFILE_BEGIN_EVENT(RCTProfileTagAlways, @"-[UIManager flushUIBlocks]", (@{
@"count": [@(previousPendingUIBlocks.count) stringValue],
}));
@try {
for (RCTViewManagerUIBlock block in previousPendingUIBlocks) {
block(self, self->_viewRegistry);
}
}
@catch (NSException *exception) {
RCTLogError(@"Exception thrown while executing UI block: %@", exception);
}
RCT_PROFILE_END_EVENT(RCTProfileTagAlways, @"");

RCTExecuteOnUIManagerQueue(completion);
});
}

- (void)setNeedsLayout
Expand Down
6 changes: 6 additions & 0 deletions React/Modules/RCTUIManagerObserverCoordinator.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@
*/
- (void)uiManagerWillPerformMounting:(RCTUIManager *)manager;

/**
* Called just after flushing UI blocks.
* This is called from the UIManager queue.
*/
- (void)uiManagerDidPerformMounting:(RCTUIManager *)manager;

@end

/**
Expand Down
12 changes: 12 additions & 0 deletions React/Modules/RCTUIManagerObserverCoordinator.mm
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,16 @@ - (void)uiManagerWillPerformMounting:(RCTUIManager *)manager
}
}

- (void)uiManagerDidPerformMounting:(RCTUIManager *)manager
{
std::lock_guard<std::mutex> lock(_mutex);

for (id<RCTUIManagerObserver> observer in _observers) {
if ([observer respondsToSelector:@selector(uiManagerDidPerformMounting:)]) {
[observer uiManagerDidPerformMounting:manager];
}
}
}


@end

0 comments on commit 60dc9be

Please sign in to comment.