Skip to content

Commit 01a3edc

Browse files
sammy-SCfacebook-github-bot
authored andcommitted
Reland: [RN][iOS] Extend Fabric iOS plugins to include Core components
Summary: Changelog: [Internal] Reviewed By: shergin Differential Revision: D18638769 fbshipit-source-id: bc27de0ebfd3689aa427f3aef7e194f3938d893c
1 parent bb1f9b2 commit 01a3edc

File tree

4 files changed

+88
-4
lines changed

4 files changed

+88
-4
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @generated by an internal plugin build system
8+
*/
9+
10+
#ifdef RN_DISABLE_OSS_PLUGIN_HEADER
11+
12+
// FB Internal: FBRCTFabricComponentsPlugins.h is autogenerated by the build system.
13+
#import <React/FBRCTFabricComponentsPlugins.h>
14+
15+
#else
16+
17+
// OSS-compatibility layer
18+
19+
#import <Foundation/Foundation.h>
20+
#import <React/RCTComponentViewProtocol.h>
21+
22+
#pragma GCC diagnostic push
23+
#pragma GCC diagnostic ignored "-Wreturn-type-c-linkage"
24+
25+
#ifdef __cplusplus
26+
extern "C" {
27+
#endif
28+
29+
Class<RCTComponentViewProtocol> RCTFabricComponentsProvider(const char *name);
30+
31+
// Lookup functions
32+
Class<RCTComponentViewProtocol> RCTSafeAreaViewCls(void) __attribute__((used));
33+
34+
#ifdef __cplusplus
35+
}
36+
#endif
37+
38+
#pragma GCC diagnostic pop
39+
40+
#endif // RN_DISABLE_OSS_PLUGIN_HEADER
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @generated by an internal plugin build system
8+
*/
9+
10+
#ifndef RN_DISABLE_OSS_PLUGIN_HEADER
11+
12+
// OSS-compatibility layer
13+
14+
#import "RCTFabricComponentsPlugins.h"
15+
16+
#import <string>
17+
#import <unordered_map>
18+
19+
Class<RCTComponentViewProtocol> RCTFabricComponentsProvider(const char *name) {
20+
static std::unordered_map<std::string, Class (*)(void)> sFabricComponentsClassMap = {
21+
{"SafeAreaView", RCTSafeAreaViewCls},
22+
};
23+
24+
auto p = sFabricComponentsClassMap.find(name);
25+
if (p != sFabricComponentsClassMap.end()) {
26+
auto classFunc = p->second;
27+
return classFunc();
28+
}
29+
return nil;
30+
}
31+
32+
#endif // RN_DISABLE_OSS_PLUGIN_HEADER

React/Fabric/Mounting/ComponentViews/SafeAreaView/RCTSafeAreaViewComponentView.mm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#import <react/components/safeareaview/SafeAreaViewComponentDescriptor.h>
1111
#import <react/components/safeareaview/SafeAreaViewState.h>
1212
#import "RCTConversions.h"
13+
#import "RCTFabricComponentsPlugins.h"
1314

1415
using namespace facebook::react;
1516

@@ -65,3 +66,8 @@ + (ComponentDescriptorProvider)componentDescriptorProvider
6566
}
6667

6768
@end
69+
70+
Class<RCTComponentViewProtocol> RCTSafeAreaViewCls(void)
71+
{
72+
return RCTSafeAreaViewComponentView.class;
73+
}

React/Fabric/Mounting/RCTComponentViewFactory.mm

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
#import "RCTARTSurfaceViewComponentView.h"
2020
#import "RCTActivityIndicatorViewComponentView.h"
2121
#import "RCTComponentViewClassDescriptor.h"
22+
#import "RCTFabricComponentsPlugins.h"
2223
#import "RCTImageComponentView.h"
2324
#import "RCTLegacyViewManagerInteropComponentView.h"
2425
#import "RCTModalHostViewComponentView.h"
2526
#import "RCTMountingTransactionObserving.h"
2627
#import "RCTParagraphComponentView.h"
2728
#import "RCTPullToRefreshViewComponentView.h"
2829
#import "RCTRootComponentView.h"
29-
#import "RCTSafeAreaViewComponentView.h"
3030
#import "RCTScrollViewComponentView.h"
3131
#import "RCTSliderComponentView.h"
3232
#import "RCTSwitchComponentView.h"
@@ -60,7 +60,6 @@ + (RCTComponentViewFactory *)standardComponentViewFactory
6060
[componentViewFactory registerComponentViewClass:[RCTUnimplementedNativeComponentView class]];
6161
[componentViewFactory registerComponentViewClass:[RCTModalHostViewComponentView class]];
6262
[componentViewFactory registerComponentViewClass:[RCTARTSurfaceViewComponentView class]];
63-
[componentViewFactory registerComponentViewClass:[RCTSafeAreaViewComponentView class]];
6463

6564
auto providerRegistry = &componentViewFactory->_providerRegistry;
6665

@@ -74,9 +73,16 @@ + (RCTComponentViewFactory *)standardComponentViewFactory
7473
[componentViewFactory registerComponentViewClass:klass];
7574
return;
7675
}
76+
} else {
77+
// Fallback 2: In case delegate isn't defined, look into core components.
78+
Class<RCTComponentViewProtocol> klass = RCTFabricComponentsProvider(requestedComponentName);
79+
if (klass) {
80+
[componentViewFactory registerComponentViewClass:klass];
81+
return;
82+
}
7783
}
7884

79-
// Fallback 2: Try to use Paper Interop.
85+
// Fallback 3: Try to use Paper Interop.
8086
if ([RCTLegacyViewManagerInteropComponentView isSupported:RCTNSStringFromString(requestedComponentName)]) {
8187
auto flavor = std::make_shared<std::string const>(requestedComponentName);
8288
auto componentName = ComponentName{flavor->c_str()};
@@ -90,7 +96,7 @@ + (RCTComponentViewFactory *)standardComponentViewFactory
9096
return;
9197
}
9298

93-
// Fallback 3: Finally use <UnimplementedView>.
99+
// Fallback 4: Finally use <UnimplementedView>.
94100
auto flavor = std::make_shared<std::string const>(requestedComponentName);
95101
auto componentName = ComponentName{flavor->c_str()};
96102
auto componentHandle = reinterpret_cast<ComponentHandle>(componentName);

0 commit comments

Comments
 (0)