diff --git a/React/Fabric/Mounting/ComponentViews/RCTFabricComponentsPlugins.h b/React/Fabric/Mounting/ComponentViews/RCTFabricComponentsPlugins.h new file mode 100644 index 00000000000..89e2f385a85 --- /dev/null +++ b/React/Fabric/Mounting/ComponentViews/RCTFabricComponentsPlugins.h @@ -0,0 +1,40 @@ +/** + * 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. + * + * @generated by an internal plugin build system + */ + +#ifdef RN_DISABLE_OSS_PLUGIN_HEADER + +// FB Internal: FBRCTFabricComponentsPlugins.h is autogenerated by the build system. +#import + +#else + +// OSS-compatibility layer + +#import +#import + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wreturn-type-c-linkage" + +#ifdef __cplusplus +extern "C" { +#endif + +Class RCTFabricComponentsProvider(const char *name); + +// Lookup functions +Class RCTSafeAreaViewCls(void) __attribute__((used)); + +#ifdef __cplusplus +} +#endif + +#pragma GCC diagnostic pop + +#endif // RN_DISABLE_OSS_PLUGIN_HEADER diff --git a/React/Fabric/Mounting/ComponentViews/RCTFabricComponentsPlugins.mm b/React/Fabric/Mounting/ComponentViews/RCTFabricComponentsPlugins.mm new file mode 100644 index 00000000000..a0cbf352773 --- /dev/null +++ b/React/Fabric/Mounting/ComponentViews/RCTFabricComponentsPlugins.mm @@ -0,0 +1,32 @@ +/** + * 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. + * + * @generated by an internal plugin build system + */ + +#ifndef RN_DISABLE_OSS_PLUGIN_HEADER + +// OSS-compatibility layer + +#import "RCTFabricComponentsPlugins.h" + +#import +#import + +Class RCTFabricComponentsProvider(const char *name) { + static std::unordered_map sFabricComponentsClassMap = { + {"SafeAreaView", RCTSafeAreaViewCls}, + }; + + auto p = sFabricComponentsClassMap.find(name); + if (p != sFabricComponentsClassMap.end()) { + auto classFunc = p->second; + return classFunc(); + } + return nil; +} + +#endif // RN_DISABLE_OSS_PLUGIN_HEADER diff --git a/React/Fabric/Mounting/ComponentViews/SafeAreaView/RCTSafeAreaViewComponentView.mm b/React/Fabric/Mounting/ComponentViews/SafeAreaView/RCTSafeAreaViewComponentView.mm index 57714d09037..42b0ac57933 100644 --- a/React/Fabric/Mounting/ComponentViews/SafeAreaView/RCTSafeAreaViewComponentView.mm +++ b/React/Fabric/Mounting/ComponentViews/SafeAreaView/RCTSafeAreaViewComponentView.mm @@ -10,6 +10,7 @@ #import #import #import "RCTConversions.h" +#import "RCTFabricComponentsPlugins.h" using namespace facebook::react; @@ -65,3 +66,8 @@ using namespace facebook::react; } @end + +Class RCTSafeAreaViewCls(void) +{ + return RCTSafeAreaViewComponentView.class; +} diff --git a/React/Fabric/Mounting/RCTComponentViewFactory.mm b/React/Fabric/Mounting/RCTComponentViewFactory.mm index e8a56045e7e..4881040a1d3 100644 --- a/React/Fabric/Mounting/RCTComponentViewFactory.mm +++ b/React/Fabric/Mounting/RCTComponentViewFactory.mm @@ -19,6 +19,7 @@ #import "RCTARTSurfaceViewComponentView.h" #import "RCTActivityIndicatorViewComponentView.h" #import "RCTComponentViewClassDescriptor.h" +#import "RCTFabricComponentsPlugins.h" #import "RCTImageComponentView.h" #import "RCTLegacyViewManagerInteropComponentView.h" #import "RCTModalHostViewComponentView.h" @@ -26,7 +27,6 @@ #import "RCTParagraphComponentView.h" #import "RCTPullToRefreshViewComponentView.h" #import "RCTRootComponentView.h" -#import "RCTSafeAreaViewComponentView.h" #import "RCTScrollViewComponentView.h" #import "RCTSliderComponentView.h" #import "RCTSwitchComponentView.h" @@ -60,7 +60,6 @@ using namespace facebook::react; [componentViewFactory registerComponentViewClass:[RCTUnimplementedNativeComponentView class]]; [componentViewFactory registerComponentViewClass:[RCTModalHostViewComponentView class]]; [componentViewFactory registerComponentViewClass:[RCTARTSurfaceViewComponentView class]]; - [componentViewFactory registerComponentViewClass:[RCTSafeAreaViewComponentView class]]; auto providerRegistry = &componentViewFactory->_providerRegistry; @@ -74,9 +73,16 @@ using namespace facebook::react; [componentViewFactory registerComponentViewClass:klass]; return; } + } else { + // Fallback 2: In case delegate isn't defined, look into core components. + Class klass = RCTFabricComponentsProvider(requestedComponentName); + if (klass) { + [componentViewFactory registerComponentViewClass:klass]; + return; + } } - // Fallback 2: Try to use Paper Interop. + // Fallback 3: Try to use Paper Interop. if ([RCTLegacyViewManagerInteropComponentView isSupported:RCTNSStringFromString(requestedComponentName)]) { auto flavor = std::make_shared(requestedComponentName); auto componentName = ComponentName{flavor->c_str()}; @@ -90,7 +96,7 @@ using namespace facebook::react; return; } - // Fallback 3: Finally use . + // Fallback 4: Finally use . auto flavor = std::make_shared(requestedComponentName); auto componentName = ComponentName{flavor->c_str()}; auto componentHandle = reinterpret_cast(componentName);