Skip to content

Commit fb2b49d

Browse files
sammy-SCfacebook-github-bot
authored andcommittedJun 29, 2020
Remove integration between Paper and Fabric's UIManager
Summary: Changelog: [Internal] In D8552360 (facebook@48b9a6f) an experimental integration between old and new UIManager has been introduced. It isn't needed anymore. I did some measurements and it is the slowest part of `[RCTComponentViewDescriptor dequeueComponentViewWithComponentHandle]`. {F241943384} Reviewed By: shergin Differential Revision: D22274782 fbshipit-source-id: 799ba047f1c57f68f00b0b6fa7c58782874991bc
1 parent 6d44794 commit fb2b49d

5 files changed

+19
-63
lines changed
 

‎React/Fabric/Mounting/RCTComponentViewRegistry.mm

-62
Original file line numberDiff line numberDiff line change
@@ -18,60 +18,6 @@
1818

1919
using namespace facebook::react;
2020

21-
#define LEGACY_UIMANAGER_INTEGRATION_ENABLED 1
22-
23-
#ifdef LEGACY_UIMANAGER_INTEGRATION_ENABLED
24-
25-
#import <React/RCTBridge+Private.h>
26-
#import <React/RCTUIManager.h>
27-
28-
/**
29-
* Warning: This is a total hack and temporary solution.
30-
* Unless we have a pure Fabric-based implementation of UIManager commands
31-
* delivery pipeline, we have to leverage existing infra. This code tricks
32-
* legacy UIManager by registering all Fabric-managed views in it,
33-
* hence existing command-delivery infra can reach "foreign" views using
34-
* the old pipeline.
35-
*/
36-
@interface RCTUIManager ()
37-
- (NSMutableDictionary<NSNumber *, UIView *> *)viewRegistry;
38-
@end
39-
40-
@interface RCTUIManager (Hack)
41-
42-
+ (void)registerView:(UIView *)view;
43-
+ (void)unregisterView:(UIView *)view;
44-
45-
@end
46-
47-
@implementation RCTUIManager (Hack)
48-
49-
+ (void)registerView:(UIView *)view
50-
{
51-
if (!view) {
52-
return;
53-
}
54-
55-
RCTUIManager *uiManager = [[RCTBridge currentBridge] uiManager];
56-
view.reactTag = @(view.tag);
57-
[uiManager.viewRegistry setObject:view forKey:@(view.tag)];
58-
}
59-
60-
+ (void)unregisterView:(UIView *)view
61-
{
62-
if (!view) {
63-
return;
64-
}
65-
66-
RCTUIManager *uiManager = [[RCTBridge currentBridge] uiManager];
67-
view.reactTag = nil;
68-
[uiManager.viewRegistry removeObjectForKey:@(view.tag)];
69-
}
70-
71-
@end
72-
73-
#endif
74-
7521
const NSInteger RCTComponentViewRegistryRecyclePoolMaxSize = 1024;
7622

7723
@implementation RCTComponentViewRegistry {
@@ -133,10 +79,6 @@ - (RCTComponentViewDescriptor)dequeueComponentViewWithComponentHandle:(Component
13379

13480
_registry.insert({tag, componentViewDescriptor});
13581

136-
#ifdef LEGACY_UIMANAGER_INTEGRATION_ENABLED
137-
[RCTUIManager registerView:componentViewDescriptor.view];
138-
#endif
139-
14082
return componentViewDescriptor;
14183
}
14284

@@ -149,10 +91,6 @@ - (void)enqueueComponentViewWithComponentHandle:(ComponentHandle)componentHandle
14991
RCTAssert(
15092
_registry.find(tag) != _registry.end(), @"RCTComponentViewRegistry: Attempt to enqueue unregistered component.");
15193

152-
#ifdef LEGACY_UIMANAGER_INTEGRATION_ENABLED
153-
[RCTUIManager unregisterView:componentViewDescriptor.view];
154-
#endif
155-
15694
_registry.erase(tag);
15795
componentViewDescriptor.view.tag = 0;
15896
[self _enqueueComponentViewWithComponentHandle:componentHandle componentViewDescriptor:componentViewDescriptor];

‎React/Fabric/RCTSurfacePresenter.h

+5
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ NS_ASSUME_NONNULL_BEGIN
7575

7676
- (void)removeObserver:(id<RCTSurfacePresenterObserver>)observer;
7777

78+
/*
79+
* Please do not use this, this will be deleted soon.
80+
*/
81+
- (nullable UIView *)findComponentViewWithTag_DO_NOT_USE_DEPRECATED:(NSInteger)tag;
82+
7883
@end
7984

8085
NS_ASSUME_NONNULL_END

‎React/Fabric/RCTSurfacePresenter.mm

+7
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,13 @@ - (void)setMinimumSize:(CGSize)minimumSize maximumSize:(CGSize)maximumSize surfa
189189
surfaceId:surface.rootTag];
190190
}
191191

192+
- (UIView *)findComponentViewWithTag_DO_NOT_USE_DEPRECATED:(NSInteger)tag
193+
{
194+
UIView<RCTComponentViewProtocol> *componentView =
195+
[_mountingManager.componentViewRegistry findComponentViewWithTag:tag];
196+
return componentView;
197+
}
198+
192199
- (BOOL)synchronouslyUpdateViewOnUIThread:(NSNumber *)reactTag props:(NSDictionary *)props
193200
{
194201
RCTScheduler *scheduler = [self _scheduler];

‎React/Modules/RCTSurfacePresenterStub.h

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ NS_ASSUME_NONNULL_BEGIN
2626

2727
@protocol RCTSurfacePresenterStub <NSObject>
2828

29+
- (nullable UIView *)findComponentViewWithTag_DO_NOT_USE_DEPRECATED:(NSInteger)tag;
2930
- (BOOL)synchronouslyUpdateViewOnUIThread:(NSNumber *)reactTag props:(NSDictionary *)props;
3031
- (void)addObserver:(id<RCTSurfacePresenterObserver>)observer;
3132
- (void)removeObserver:(id<RCTSurfacePresenterObserver>)observer;

‎React/Modules/RCTUIManager.m

+6-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#import "RCTUIManager.h"
99

1010
#import <AVFoundation/AVFoundation.h>
11+
#import <React/RCTSurfacePresenterStub.h>
1112

1213
#import "RCTAssert.h"
1314
#import "RCTBridge+Private.h"
@@ -354,7 +355,11 @@ - (NSString *)viewNameForReactTag:(NSNumber *)reactTag
354355
- (UIView *)viewForReactTag:(NSNumber *)reactTag
355356
{
356357
RCTAssertMainQueue();
357-
return _viewRegistry[reactTag];
358+
UIView *view = [_bridge.surfacePresenter findComponentViewWithTag_DO_NOT_USE_DEPRECATED:reactTag.integerValue];
359+
if (!view) {
360+
view = _viewRegistry[reactTag];
361+
}
362+
return view;
358363
}
359364

360365
- (RCTShadowView *)shadowViewForReactTag:(NSNumber *)reactTag

0 commit comments

Comments
 (0)
Please sign in to comment.