Skip to content

Commit b263560

Browse files
sherginfacebook-github-bot
authored andcommitted
reactBridgeDidFinishTransaction was removed from RCTTabBar
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: D6549586 fbshipit-source-id: 589b814f83b91ed8fabf7e638e7554ab3c9d286e
1 parent 099b280 commit b263560

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed

React/Views/RCTTabBar.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,6 @@
1919
@property (nonatomic, assign) UIBarStyle barStyle;
2020
#endif
2121

22+
- (void)uiManagerDidPerformMounting;
23+
2224
@end

React/Views/RCTTabBar.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ - (void)removeReactSubview:(RCTTabBarItem *)subview
7373

7474
- (void)didUpdateReactSubviews
7575
{
76-
// Do nothing, as subviews are managed by `reactBridgeDidFinishTransaction`
76+
// Do nothing, as subviews are managed by `uiManagerDidPerformMounting`
7777
}
7878

7979
- (void)layoutSubviews
@@ -83,7 +83,7 @@ - (void)layoutSubviews
8383
_tabController.view.frame = self.bounds;
8484
}
8585

86-
- (void)reactBridgeDidFinishTransaction
86+
- (void)uiManagerDidPerformMounting
8787
{
8888
// we can't hook up the VC hierarchy in 'init' because the subviews aren't
8989
// hooked up yet, so we do it on demand here whenever a transaction has finished

React/Views/RCTTabBarManager.m

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
#import "RCTBridge.h"
1313
#import "RCTTabBar.h"
14+
#import "RCTUIManager.h"
15+
#import "RCTUIManagerObserverCoordinator.h"
1416

1517
@implementation RCTConvert (UITabBar)
1618

@@ -22,13 +24,39 @@ @implementation RCTConvert (UITabBar)
2224

2325
@end
2426

27+
@interface RCTTabBarManager () <RCTUIManagerObserver>
28+
29+
@end
30+
2531
@implementation RCTTabBarManager
32+
{
33+
// The main thread only.
34+
NSHashTable<RCTTabBar *> *_viewRegistry;
35+
}
36+
37+
- (void)setBridge:(RCTBridge *)bridge
38+
{
39+
[super setBridge:bridge];
40+
41+
[self.bridge.uiManager.observerCoordinator addObserver:self];
42+
}
43+
44+
- (void)invalidate
45+
{
46+
[self.bridge.uiManager.observerCoordinator removeObserver:self];
47+
}
2648

2749
RCT_EXPORT_MODULE()
2850

2951
- (UIView *)view
3052
{
31-
return [RCTTabBar new];
53+
if (!_viewRegistry) {
54+
_viewRegistry = [NSHashTable hashTableWithOptions:NSPointerFunctionsWeakMemory];
55+
}
56+
57+
RCTTabBar *view = [RCTTabBar new];
58+
[_viewRegistry addObject:view];
59+
return view;
3260
}
3361

3462
RCT_EXPORT_VIEW_PROPERTY(unselectedTintColor, UIColor)
@@ -41,4 +69,15 @@ - (UIView *)view
4169
RCT_EXPORT_VIEW_PROPERTY(itemPositioning, UITabBarItemPositioning)
4270
RCT_EXPORT_VIEW_PROPERTY(unselectedItemTintColor, UIColor)
4371

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

0 commit comments

Comments
 (0)