Skip to content

Commit

Permalink
Remove integration between Paper and Fabric's UIManager
Browse files Browse the repository at this point in the history
Summary:
Changelog: [Internal]

In D8552360 (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
  • Loading branch information
sammy-SC authored and facebook-github-bot committed Jun 29, 2020
1 parent 6d44794 commit fb2b49d
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 63 deletions.
62 changes: 0 additions & 62 deletions React/Fabric/Mounting/RCTComponentViewRegistry.mm
Original file line number Diff line number Diff line change
Expand Up @@ -18,60 +18,6 @@

using namespace facebook::react;

#define LEGACY_UIMANAGER_INTEGRATION_ENABLED 1

#ifdef LEGACY_UIMANAGER_INTEGRATION_ENABLED

#import <React/RCTBridge+Private.h>
#import <React/RCTUIManager.h>

/**
* Warning: This is a total hack and temporary solution.
* Unless we have a pure Fabric-based implementation of UIManager commands
* delivery pipeline, we have to leverage existing infra. This code tricks
* legacy UIManager by registering all Fabric-managed views in it,
* hence existing command-delivery infra can reach "foreign" views using
* the old pipeline.
*/
@interface RCTUIManager ()
- (NSMutableDictionary<NSNumber *, UIView *> *)viewRegistry;
@end

@interface RCTUIManager (Hack)

+ (void)registerView:(UIView *)view;
+ (void)unregisterView:(UIView *)view;

@end

@implementation RCTUIManager (Hack)

+ (void)registerView:(UIView *)view
{
if (!view) {
return;
}

RCTUIManager *uiManager = [[RCTBridge currentBridge] uiManager];
view.reactTag = @(view.tag);
[uiManager.viewRegistry setObject:view forKey:@(view.tag)];
}

+ (void)unregisterView:(UIView *)view
{
if (!view) {
return;
}

RCTUIManager *uiManager = [[RCTBridge currentBridge] uiManager];
view.reactTag = nil;
[uiManager.viewRegistry removeObjectForKey:@(view.tag)];
}

@end

#endif

const NSInteger RCTComponentViewRegistryRecyclePoolMaxSize = 1024;

@implementation RCTComponentViewRegistry {
Expand Down Expand Up @@ -133,10 +79,6 @@ - (RCTComponentViewDescriptor)dequeueComponentViewWithComponentHandle:(Component

_registry.insert({tag, componentViewDescriptor});

#ifdef LEGACY_UIMANAGER_INTEGRATION_ENABLED
[RCTUIManager registerView:componentViewDescriptor.view];
#endif

return componentViewDescriptor;
}

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

#ifdef LEGACY_UIMANAGER_INTEGRATION_ENABLED
[RCTUIManager unregisterView:componentViewDescriptor.view];
#endif

_registry.erase(tag);
componentViewDescriptor.view.tag = 0;
[self _enqueueComponentViewWithComponentHandle:componentHandle componentViewDescriptor:componentViewDescriptor];
Expand Down
5 changes: 5 additions & 0 deletions React/Fabric/RCTSurfacePresenter.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ NS_ASSUME_NONNULL_BEGIN

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

/*
* Please do not use this, this will be deleted soon.
*/
- (nullable UIView *)findComponentViewWithTag_DO_NOT_USE_DEPRECATED:(NSInteger)tag;

@end

NS_ASSUME_NONNULL_END
7 changes: 7 additions & 0 deletions React/Fabric/RCTSurfacePresenter.mm
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,13 @@ - (void)setMinimumSize:(CGSize)minimumSize maximumSize:(CGSize)maximumSize surfa
surfaceId:surface.rootTag];
}

- (UIView *)findComponentViewWithTag_DO_NOT_USE_DEPRECATED:(NSInteger)tag
{
UIView<RCTComponentViewProtocol> *componentView =
[_mountingManager.componentViewRegistry findComponentViewWithTag:tag];
return componentView;
}

- (BOOL)synchronouslyUpdateViewOnUIThread:(NSNumber *)reactTag props:(NSDictionary *)props
{
RCTScheduler *scheduler = [self _scheduler];
Expand Down
1 change: 1 addition & 0 deletions React/Modules/RCTSurfacePresenterStub.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ NS_ASSUME_NONNULL_BEGIN

@protocol RCTSurfacePresenterStub <NSObject>

- (nullable UIView *)findComponentViewWithTag_DO_NOT_USE_DEPRECATED:(NSInteger)tag;
- (BOOL)synchronouslyUpdateViewOnUIThread:(NSNumber *)reactTag props:(NSDictionary *)props;
- (void)addObserver:(id<RCTSurfacePresenterObserver>)observer;
- (void)removeObserver:(id<RCTSurfacePresenterObserver>)observer;
Expand Down
7 changes: 6 additions & 1 deletion React/Modules/RCTUIManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#import "RCTUIManager.h"

#import <AVFoundation/AVFoundation.h>
#import <React/RCTSurfacePresenterStub.h>

#import "RCTAssert.h"
#import "RCTBridge+Private.h"
Expand Down Expand Up @@ -354,7 +355,11 @@ - (NSString *)viewNameForReactTag:(NSNumber *)reactTag
- (UIView *)viewForReactTag:(NSNumber *)reactTag
{
RCTAssertMainQueue();
return _viewRegistry[reactTag];
UIView *view = [_bridge.surfacePresenter findComponentViewWithTag_DO_NOT_USE_DEPRECATED:reactTag.integerValue];
if (!view) {
view = _viewRegistry[reactTag];
}
return view;
}

- (RCTShadowView *)shadowViewForReactTag:(NSNumber *)reactTag
Expand Down

0 comments on commit fb2b49d

Please sign in to comment.