Skip to content

Commit 099b280

Browse files
sherginfacebook-github-bot
authored andcommitted
reactBridgeDidFinishTransaction was removed from RCTNavigator
Summary: We are removing `reactBridgeDidFinishTransaction`. Why? * It is a performance drain. Supporting this requires dispatching main-thread block on every single transaction complete; * It has "too broad" non-conceptual semantic which encouraged using this as a "band-aid solution" for poorly designed components; * It is conceptually incompatible with new approaches that we are trying to implement to optimize the render layer; * It was deprecated for very long time. This diff replaces usage of `reactBridgeDidFinishTransaction` with `uiManagerDidPerformMounting` which has very similar semantic except that fact that `uiManagerDidPerformMounting` is called asynchronously on the next run loop tick. And this should be okay because new React partial rendering does not guarantee synchronous execution anyways. Reviewed By: mmmulani Differential Revision: D6549217 fbshipit-source-id: 2649e943e82e6fbe02c7678583a97db3f5800201
1 parent b8e60a3 commit 099b280

File tree

3 files changed

+43
-3
lines changed

3 files changed

+43
-3
lines changed

Diff for: React/Views/RCTNavigator.h

+2
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,6 @@
3131
*/
3232
- (BOOL)requestSchedulingJavaScriptNavigation;
3333

34+
- (void)uiManagerDidPerformMounting;
35+
3436
@end

Diff for: React/Views/RCTNavigator.m

+2-2
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ - (void)insertReactSubview:(RCTNavItem *)view atIndex:(NSInteger)atIndex
466466

467467
- (void)didUpdateReactSubviews
468468
{
469-
// Do nothing, as subviews are managed by `reactBridgeDidFinishTransaction`
469+
// Do nothing, as subviews are managed by `uiManagerDidPerformMounting`
470470
}
471471

472472
- (void)layoutSubviews
@@ -510,7 +510,7 @@ - (UIView *)reactSuperview
510510
return superview ?: self.reactNavSuperviewLink;
511511
}
512512

513-
- (void)reactBridgeDidFinishTransaction
513+
- (void)uiManagerDidPerformMounting
514514
{
515515
// we can't hook up the VC hierarchy in 'init' because the subviews aren't
516516
// hooked up yet, so we do it on demand here

Diff for: React/Views/RCTNavigatorManager.m

+39-1
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,42 @@
1313
#import "RCTConvert.h"
1414
#import "RCTNavigator.h"
1515
#import "RCTUIManager.h"
16+
#import "RCTUIManagerObserverCoordinator.h"
1617
#import "UIView+React.h"
1718

19+
@interface RCTNavigatorManager () <RCTUIManagerObserver>
20+
21+
@end
22+
1823
@implementation RCTNavigatorManager
24+
{
25+
// The main thread only.
26+
NSHashTable<RCTNavigator *> *_viewRegistry;
27+
}
28+
29+
- (void)setBridge:(RCTBridge *)bridge
30+
{
31+
[super setBridge:bridge];
32+
33+
[self.bridge.uiManager.observerCoordinator addObserver:self];
34+
}
35+
36+
- (void)invalidate
37+
{
38+
[self.bridge.uiManager.observerCoordinator removeObserver:self];
39+
}
1940

2041
RCT_EXPORT_MODULE()
2142

2243
- (UIView *)view
2344
{
24-
return [[RCTNavigator alloc] initWithBridge:self.bridge];
45+
if (!_viewRegistry) {
46+
_viewRegistry = [NSHashTable hashTableWithOptions:NSPointerFunctionsWeakMemory];
47+
}
48+
49+
RCTNavigator *view = [[RCTNavigator alloc] initWithBridge:self.bridge];
50+
[_viewRegistry addObject:view];
51+
return view;
2552
}
2653

2754
RCT_EXPORT_VIEW_PROPERTY(requestedTopOfStack, NSInteger)
@@ -44,4 +71,15 @@ - (UIView *)view
4471
}];
4572
}
4673

74+
#pragma mark - RCTUIManagerObserver
75+
76+
- (void)uiManagerDidPerformMounting:(__unused RCTUIManager *)manager
77+
{
78+
RCTExecuteOnMainQueue(^{
79+
for (RCTNavigator *view in self->_viewRegistry) {
80+
[view uiManagerDidPerformMounting];
81+
}
82+
});
83+
}
84+
4785
@end

0 commit comments

Comments
 (0)