mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
ab45509d75
Summary: In the full bridgeless, the following aren't allowed: * using legacy view manager interop layer (won't support long term, but still needed today, so just warn) * initializing any subclass of RCTViewManager (won't support long term, but still used by legacy interop layer) * initializing RCTUIManager (fabric UIManager should be the only one used) Changelog: [Internal] Reviewed By: mdvacca Differential Revision: D28111530 fbshipit-source-id: 4f5eab600c6c7896d51861545b7f878c25248e44
183 lines
6.1 KiB
Plaintext
183 lines
6.1 KiB
Plaintext
/*
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
#import "RCTLegacyViewManagerInteropComponentView.h"
|
|
|
|
#import <React/RCTAssert.h>
|
|
#import <React/UIView+React.h>
|
|
#import <react/renderer/components/legacyviewmanagerinterop/LegacyViewManagerInteropComponentDescriptor.h>
|
|
#import <react/renderer/components/legacyviewmanagerinterop/LegacyViewManagerInteropViewProps.h>
|
|
#import <react/utils/ManagedObjectWrapper.h>
|
|
#import "RCTLegacyViewManagerInteropCoordinatorAdapter.h"
|
|
|
|
using namespace facebook::react;
|
|
|
|
static NSString *const kRCTLegacyInteropChildComponentKey = @"childComponentView";
|
|
static NSString *const kRCTLegacyInteropChildIndexKey = @"index";
|
|
|
|
@implementation RCTLegacyViewManagerInteropComponentView {
|
|
NSMutableArray<NSDictionary *> *_viewsToBeMounted;
|
|
NSMutableArray<UIView *> *_viewsToBeUnmounted;
|
|
RCTLegacyViewManagerInteropCoordinatorAdapter *_adapter;
|
|
LegacyViewManagerInteropShadowNode::ConcreteState::Shared _state;
|
|
}
|
|
|
|
- (instancetype)initWithFrame:(CGRect)frame
|
|
{
|
|
if (self = [super initWithFrame:frame]) {
|
|
RCTWarnNotAllowedForNewArchitecture(
|
|
self, @"ViewManager with interop layer is not allowed in the new architecture.");
|
|
static const auto defaultProps = std::make_shared<const LegacyViewManagerInteropViewProps>();
|
|
_props = defaultProps;
|
|
_viewsToBeMounted = [NSMutableArray new];
|
|
_viewsToBeUnmounted = [NSMutableArray new];
|
|
}
|
|
|
|
return self;
|
|
}
|
|
|
|
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
|
|
{
|
|
UIView *result = [super hitTest:point withEvent:event];
|
|
|
|
if (result == _adapter.paperView) {
|
|
return self;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
+ (NSMutableSet<NSString *> *)supportedViewManagers
|
|
{
|
|
static NSMutableSet<NSString *> *supported = [NSMutableSet setWithObjects:@"DatePicker",
|
|
@"ProgressView",
|
|
@"SegmentedControl",
|
|
@"MaskedView",
|
|
@"ARTSurfaceView",
|
|
@"ARTText",
|
|
@"ARTShape",
|
|
@"ARTGroup",
|
|
nil];
|
|
return supported;
|
|
}
|
|
|
|
+ (BOOL)isSupported:(NSString *)componentName
|
|
{
|
|
return [[RCTLegacyViewManagerInteropComponentView supportedViewManagers] containsObject:componentName];
|
|
}
|
|
|
|
+ (void)supportLegacyViewManagerWithName:(NSString *)componentName
|
|
{
|
|
[[RCTLegacyViewManagerInteropComponentView supportedViewManagers] addObject:componentName];
|
|
}
|
|
|
|
- (RCTLegacyViewManagerInteropCoordinator *)coordinator
|
|
{
|
|
if (_state != nullptr) {
|
|
const auto &state = _state->getData();
|
|
return unwrapManagedObject(state.coordinator);
|
|
} else {
|
|
return nil;
|
|
}
|
|
}
|
|
|
|
- (NSString *)componentViewName_DO_NOT_USE_THIS_IS_BROKEN
|
|
{
|
|
const auto &state = _state->getData();
|
|
RCTLegacyViewManagerInteropCoordinator *coordinator = unwrapManagedObject(state.coordinator);
|
|
return coordinator.componentViewName;
|
|
}
|
|
|
|
#pragma mark - RCTComponentViewProtocol
|
|
|
|
- (void)prepareForRecycle
|
|
{
|
|
_adapter = nil;
|
|
[_viewsToBeMounted removeAllObjects];
|
|
[_viewsToBeUnmounted removeAllObjects];
|
|
_state.reset();
|
|
self.contentView = nil;
|
|
[super prepareForRecycle];
|
|
}
|
|
|
|
- (void)mountChildComponentView:(UIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index
|
|
{
|
|
[_viewsToBeMounted addObject:@{
|
|
kRCTLegacyInteropChildIndexKey : [NSNumber numberWithInteger:index],
|
|
kRCTLegacyInteropChildComponentKey : childComponentView
|
|
}];
|
|
}
|
|
|
|
- (void)unmountChildComponentView:(UIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index
|
|
{
|
|
if (_adapter) {
|
|
[_adapter.paperView removeReactSubview:childComponentView];
|
|
} else {
|
|
[_viewsToBeUnmounted addObject:childComponentView];
|
|
}
|
|
}
|
|
|
|
+ (ComponentDescriptorProvider)componentDescriptorProvider
|
|
{
|
|
return concreteComponentDescriptorProvider<LegacyViewManagerInteropComponentDescriptor>();
|
|
}
|
|
|
|
- (void)updateState:(State::Shared const &)state oldState:(State::Shared const &)oldState
|
|
{
|
|
_state = std::static_pointer_cast<LegacyViewManagerInteropShadowNode::ConcreteState const>(state);
|
|
}
|
|
|
|
- (void)finalizeUpdates:(RNComponentViewUpdateMask)updateMask
|
|
{
|
|
[super finalizeUpdates:updateMask];
|
|
|
|
if (!_adapter) {
|
|
_adapter = [[RCTLegacyViewManagerInteropCoordinatorAdapter alloc] initWithCoordinator:self.coordinator
|
|
reactTag:self.tag];
|
|
__weak __typeof(self) weakSelf = self;
|
|
_adapter.eventInterceptor = ^(std::string eventName, folly::dynamic event) {
|
|
if (weakSelf) {
|
|
__typeof(self) strongSelf = weakSelf;
|
|
auto eventEmitter =
|
|
std::static_pointer_cast<LegacyViewManagerInteropViewEventEmitter const>(strongSelf->_eventEmitter);
|
|
eventEmitter->dispatchEvent(eventName, event);
|
|
}
|
|
};
|
|
self.contentView = _adapter.paperView;
|
|
}
|
|
|
|
for (NSDictionary *mountInstruction in _viewsToBeMounted) {
|
|
NSNumber *index = mountInstruction[kRCTLegacyInteropChildIndexKey];
|
|
UIView *childView = mountInstruction[kRCTLegacyInteropChildComponentKey];
|
|
[_adapter.paperView insertReactSubview:childView atIndex:index.integerValue];
|
|
}
|
|
|
|
[_viewsToBeMounted removeAllObjects];
|
|
|
|
for (UIView *view in _viewsToBeUnmounted) {
|
|
[_adapter.paperView removeReactSubview:view];
|
|
}
|
|
|
|
[_viewsToBeUnmounted removeAllObjects];
|
|
|
|
[_adapter.paperView didUpdateReactSubviews];
|
|
|
|
if (updateMask & RNComponentViewUpdateMaskProps) {
|
|
const auto &newProps = *std::static_pointer_cast<const LegacyViewManagerInteropViewProps>(_props);
|
|
[_adapter setProps:newProps.otherProps];
|
|
}
|
|
}
|
|
|
|
#pragma mark - Native Commands
|
|
|
|
- (void)handleCommand:(const NSString *)commandName args:(const NSArray *)args
|
|
{
|
|
[_adapter handleCommand:(NSString *)commandName args:(NSArray *)args];
|
|
}
|
|
|
|
@end
|