Extend Fabric iOS plugins to include Core components

Summary:
Changelog: [Internal]

Load components only if they are used. This way we avoid upfront cost associated with loading components that are not used.

Reviewed By: fkgozali

Differential Revision: D18504437

fbshipit-source-id: 815dd0799f87e254ce0b899ee52a9bec8da45451
This commit is contained in:
Samuel Susla 2019-11-21 04:43:42 -08:00 коммит произвёл Facebook Github Bot
Родитель 9c61693c9e
Коммит a59b33a286
4 изменённых файлов: 88 добавлений и 4 удалений

Просмотреть файл

@ -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 <React/FBRCTFabricComponentsPlugins.h>
#else
// OSS-compatibility layer
#import <Foundation/Foundation.h>
#import <React/RCTComponentViewProtocol.h>
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wreturn-type-c-linkage"
#ifdef __cplusplus
extern "C" {
#endif
Class<RCTComponentViewProtocol> RCTFabricComponentsProvider(const char *name);
// Lookup functions
Class<RCTComponentViewProtocol> RCTSafeAreaViewCls(void) __attribute__((used));
#ifdef __cplusplus
}
#endif
#pragma GCC diagnostic pop
#endif // RN_DISABLE_OSS_PLUGIN_HEADER

Просмотреть файл

@ -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 <string>
#import <unordered_map>
Class<RCTComponentViewProtocol> RCTFabricComponentsProvider(const char *name) {
static std::unordered_map<std::string, Class (*)(void)> 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

Просмотреть файл

@ -10,6 +10,7 @@
#import <react/components/safeareaview/SafeAreaViewComponentDescriptor.h>
#import <react/components/safeareaview/SafeAreaViewState.h>
#import "RCTConversions.h"
#import "RCTFabricComponentsPlugins.h"
using namespace facebook::react;
@ -65,3 +66,8 @@ using namespace facebook::react;
}
@end
Class<RCTComponentViewProtocol> RCTSafeAreaViewCls(void)
{
return RCTSafeAreaViewComponentView.class;
}

Просмотреть файл

@ -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<RCTComponentViewProtocol> 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<std::string const>(requestedComponentName);
auto componentName = ComponentName{flavor->c_str()};
@ -90,7 +96,7 @@ using namespace facebook::react;
return;
}
// Fallback 3: Finally use <UnimplementedView>.
// 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);