mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Component views are now loaded through C function rather than delegate
Summary: I moved towards C function to return component class instead of delegate. We need this in order to register components that are optimistically registered, such as View, Image and Text. In D19088558, we need this in order to register Image. Changelog: [Internal] Reviewed By: shergin Differential Revision: D19088559 fbshipit-source-id: 061f3ba15dfb44b9acce7be2dc6828b9afbecbfa
This commit is contained in:
1 parent
3ed67ab26f
commit
e33b276084
4 files changed
+35
-52
No files matched your search
@@ -14,15 +14,11 @@
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@protocol RCTComponentViewFactoryDelegate <NSObject>
|
||||
|
||||
/**
|
||||
* Given a component name, return its actual class. If component with doesn't exist, nil is returned.
|
||||
* Can be called on any thread.
|
||||
*/
|
||||
- (Class<RCTComponentViewProtocol>)componentViewClassWithName:(facebook::react::ComponentName)name;
|
||||
|
||||
@end
|
||||
extern "C" Class<RCTComponentViewProtocol> RCTComponentViewClassWithName(const char *componentName);
|
||||
|
||||
/**
|
||||
* Registry of supported component view classes that can instantiate
|
||||
@@ -52,8 +48,6 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
- (facebook::react::ComponentDescriptorRegistry::Shared)createComponentDescriptorRegistryWithParameters:
|
||||
(facebook::react::ComponentDescriptorParameters)parameters;
|
||||
|
||||
@property (atomic, weak, nullable) id<RCTComponentViewFactoryDelegate> delegate;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -48,43 +48,40 @@ using namespace facebook::react;
|
||||
|
||||
auto providerRegistry = &componentViewFactory->_providerRegistry;
|
||||
|
||||
providerRegistry->setComponentDescriptorProviderRequest([providerRegistry,
|
||||
componentViewFactory](ComponentName requestedComponentName) {
|
||||
// Fallback 1: Call delegate for component view class.
|
||||
if (componentViewFactory.delegate) {
|
||||
Class<RCTComponentViewProtocol> klass =
|
||||
[componentViewFactory.delegate componentViewClassWithName:requestedComponentName];
|
||||
if (klass) {
|
||||
[componentViewFactory registerComponentViewClass:klass];
|
||||
return;
|
||||
}
|
||||
}
|
||||
providerRegistry->setComponentDescriptorProviderRequest(
|
||||
[providerRegistry, componentViewFactory](ComponentName requestedComponentName) {
|
||||
// Fallback 1: Call provider function for component view class.
|
||||
Class<RCTComponentViewProtocol> klass = RCTComponentViewClassWithName(requestedComponentName);
|
||||
if (klass) {
|
||||
[componentViewFactory registerComponentViewClass:klass];
|
||||
return;
|
||||
}
|
||||
|
||||
// Fallback 3: Try to use Paper Interop.
|
||||
if ([RCTLegacyViewManagerInteropComponentView isSupported:RCTNSStringFromString(requestedComponentName)]) {
|
||||
auto flavor = std::make_shared<std::string const>(requestedComponentName);
|
||||
auto componentName = ComponentName{flavor->c_str()};
|
||||
auto componentHandle = reinterpret_cast<ComponentHandle>(componentName);
|
||||
auto constructor = [RCTLegacyViewManagerInteropComponentView componentDescriptorProvider].constructor;
|
||||
// Fallback 2: Try to use Paper Interop.
|
||||
if ([RCTLegacyViewManagerInteropComponentView isSupported:RCTNSStringFromString(requestedComponentName)]) {
|
||||
auto flavor = std::make_shared<std::string const>(requestedComponentName);
|
||||
auto componentName = ComponentName{flavor->c_str()};
|
||||
auto componentHandle = reinterpret_cast<ComponentHandle>(componentName);
|
||||
auto constructor = [RCTLegacyViewManagerInteropComponentView componentDescriptorProvider].constructor;
|
||||
|
||||
providerRegistry->add(ComponentDescriptorProvider{componentHandle, componentName, flavor, constructor});
|
||||
providerRegistry->add(ComponentDescriptorProvider{componentHandle, componentName, flavor, constructor});
|
||||
|
||||
componentViewFactory->_componentViewClasses[componentHandle] = [componentViewFactory
|
||||
_componentViewClassDescriptorFromClass:[RCTLegacyViewManagerInteropComponentView class]];
|
||||
return;
|
||||
}
|
||||
componentViewFactory->_componentViewClasses[componentHandle] = [componentViewFactory
|
||||
_componentViewClassDescriptorFromClass:[RCTLegacyViewManagerInteropComponentView class]];
|
||||
return;
|
||||
}
|
||||
|
||||
// Fallback 4: Finally use <UnimplementedView>.
|
||||
auto flavor = std::make_shared<std::string const>(requestedComponentName);
|
||||
auto componentName = ComponentName{flavor->c_str()};
|
||||
auto componentHandle = reinterpret_cast<ComponentHandle>(componentName);
|
||||
auto constructor = [RCTUnimplementedViewComponentView componentDescriptorProvider].constructor;
|
||||
// Fallback 3: Finally use <UnimplementedView>.
|
||||
auto flavor = std::make_shared<std::string const>(requestedComponentName);
|
||||
auto componentName = ComponentName{flavor->c_str()};
|
||||
auto componentHandle = reinterpret_cast<ComponentHandle>(componentName);
|
||||
auto constructor = [RCTUnimplementedViewComponentView componentDescriptorProvider].constructor;
|
||||
|
||||
providerRegistry->add(ComponentDescriptorProvider{componentHandle, componentName, flavor, constructor});
|
||||
providerRegistry->add(ComponentDescriptorProvider{componentHandle, componentName, flavor, constructor});
|
||||
|
||||
componentViewFactory->_componentViewClasses[componentHandle] =
|
||||
[componentViewFactory _componentViewClassDescriptorFromClass:[RCTUnimplementedViewComponentView class]];
|
||||
});
|
||||
componentViewFactory->_componentViewClasses[componentHandle] =
|
||||
[componentViewFactory _componentViewClassDescriptorFromClass:[RCTUnimplementedViewComponentView class]];
|
||||
});
|
||||
|
||||
return componentViewFactory;
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
#import <React/RCTPrimitives.h>
|
||||
#import <React/RCTSurfacePresenterStub.h>
|
||||
|
||||
#import <React/RCTComponentViewFactory.h>
|
||||
#import <react/utils/ContextContainer.h>
|
||||
#import <react/utils/RuntimeExecutor.h>
|
||||
|
||||
@@ -29,8 +28,6 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
- (instancetype)initWithContextContainer:(facebook::react::ContextContainer::Shared)contextContainer
|
||||
runtimeExecutor:(facebook::react::RuntimeExecutor)runtimeExecutor;
|
||||
|
||||
@property (nonatomic, readonly) RCTComponentViewFactory *componentViewFactory;
|
||||
|
||||
@property (nonatomic) facebook::react::ContextContainer::Shared contextContainer;
|
||||
@property (nonatomic) facebook::react::RuntimeExecutor runtimeExecutor;
|
||||
|
||||
|
||||
@@ -72,11 +72,6 @@ using namespace facebook::react;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (RCTComponentViewFactory *)componentViewFactory
|
||||
{
|
||||
return _mountingManager.componentViewRegistry.componentViewFactory;
|
||||
}
|
||||
|
||||
- (ContextContainer::Shared)contextContainer
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_schedulerMutex);
|
||||
@@ -210,12 +205,12 @@ using namespace facebook::react;
|
||||
|
||||
- (RCTScheduler *)_createScheduler
|
||||
{
|
||||
auto componentRegistryFactory = [factory = wrapManagedObject(self.componentViewFactory)](
|
||||
EventDispatcher::Weak const &eventDispatcher,
|
||||
ContextContainer::Shared const &contextContainer) {
|
||||
return [(RCTComponentViewFactory *)unwrapManagedObject(factory)
|
||||
createComponentDescriptorRegistryWithParameters:{eventDispatcher, contextContainer}];
|
||||
};
|
||||
auto componentRegistryFactory =
|
||||
[factory = wrapManagedObject(_mountingManager.componentViewRegistry.componentViewFactory)](
|
||||
EventDispatcher::Weak const &eventDispatcher, ContextContainer::Shared const &contextContainer) {
|
||||
return [(RCTComponentViewFactory *)unwrapManagedObject(factory)
|
||||
createComponentDescriptorRegistryWithParameters:{eventDispatcher, contextContainer}];
|
||||
};
|
||||
|
||||
auto runtimeExecutor = _runtimeExecutor;
|
||||
|
||||
|
||||
Reference in new issue
Block a user