From d1f0826f2cd824f674c8d4d6782bfd3684bc1df4 Mon Sep 17 00:00:00 2001 From: Samuel Susla Date: Mon, 18 Nov 2019 06:57:23 -0800 Subject: [PATCH] Lay groundwork for Fabric iOS plugins Summary: Changelog: [Internal] Reviewed By: fkgozali Differential Revision: D18397243 fbshipit-source-id: bae51800e93259e50db51dac2d9d7b4b52d8ef23 --- React/Fabric/Mounting/RCTComponentViewFactory.h | 12 ++++++++++++ React/Fabric/Mounting/RCTComponentViewFactory.mm | 11 +++++++++-- React/Fabric/RCTSurfacePresenter.h | 2 +- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/React/Fabric/Mounting/RCTComponentViewFactory.h b/React/Fabric/Mounting/RCTComponentViewFactory.h index ee347d9cf75..b846634678b 100644 --- a/React/Fabric/Mounting/RCTComponentViewFactory.h +++ b/React/Fabric/Mounting/RCTComponentViewFactory.h @@ -14,6 +14,16 @@ NS_ASSUME_NONNULL_BEGIN +@protocol RCTComponentViewFactoryDelegate + +/** + * Given a component name, return its actual class. If component with doesn't exist, nil is returned. + * Can be called on any thread. + */ +- (Class)componentViewClassWithName:(facebook::react::ComponentName)name; + +@end + /** * Registry of supported component view classes that can instantiate * view component instances by given component handle. @@ -42,6 +52,8 @@ NS_ASSUME_NONNULL_BEGIN - (facebook::react::ComponentDescriptorRegistry::Shared)createComponentDescriptorRegistryWithParameters: (facebook::react::ComponentDescriptorParameters)parameters; +@property (atomic, weak, nullable) id delegate; + @end NS_ASSUME_NONNULL_END diff --git a/React/Fabric/Mounting/RCTComponentViewFactory.mm b/React/Fabric/Mounting/RCTComponentViewFactory.mm index fe50f502f88..e8a56045e7e 100644 --- a/React/Fabric/Mounting/RCTComponentViewFactory.mm +++ b/React/Fabric/Mounting/RCTComponentViewFactory.mm @@ -66,8 +66,15 @@ using namespace facebook::react; providerRegistry->setComponentDescriptorProviderRequest([providerRegistry, componentViewFactory](ComponentName requestedComponentName) { - // Fallback 1: Call the delegate. - // To be implemented. + // Fallback 1: Call delegate for component view class. + if (componentViewFactory.delegate) { + Class klass = + [componentViewFactory.delegate componentViewClassWithName:requestedComponentName]; + if (klass) { + [componentViewFactory registerComponentViewClass:klass]; + return; + } + } // Fallback 2: Try to use Paper Interop. if ([RCTLegacyViewManagerInteropComponentView isSupported:RCTNSStringFromString(requestedComponentName)]) { diff --git a/React/Fabric/RCTSurfacePresenter.h b/React/Fabric/RCTSurfacePresenter.h index 5234c113e43..c4d2d5f1371 100644 --- a/React/Fabric/RCTSurfacePresenter.h +++ b/React/Fabric/RCTSurfacePresenter.h @@ -10,6 +10,7 @@ #import #import +#import #import #import @@ -18,7 +19,6 @@ NS_ASSUME_NONNULL_BEGIN @class RCTFabricSurface; @class RCTImageLoader; @class RCTMountingManager; -@class RCTComponentViewFactory; /** * Coordinates presenting of React Native Surfaces and represents application