Skip to content

Commit 9c56be2

Browse files
fkgozalifacebook-github-bot
authored andcommitted
TM iOS: Introduce OSS-compatible RCTCoreModulesClassProvider()
Summary: To look up TurboModule Class based on its name, this new function `RCTCoreModulesClassProvider()` can be used to find a TurboModule impl in the app. For now this is manually maintained and sync'ed with FB internal version. Only modules that live under React/CoreModules/ should be handled here. Reviewed By: PeteTheHeat Differential Revision: D16100291 fbshipit-source-id: 6b7556dec1fa83d1e081c7e8c0fe295187934274
1 parent 5275f15 commit 9c56be2

File tree

3 files changed

+38
-7
lines changed

3 files changed

+38
-7
lines changed

RNTester/RNTester/RNTesterTurboModuleProvider.mm

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010

1111
#import "RNTesterTurboModuleProvider.h"
1212

13-
#import <React/RCTPlatform.h>
14-
13+
#import <React/CoreModulesPlugins.h>
1514
#import <jsireact/SampleTurboCxxModule.h>
1615
#import <jsireact/RCTSampleTurboModule.h>
1716

@@ -21,10 +20,7 @@
2120
namespace react {
2221

2322
Class RNTesterTurboModuleClassProvider(const char *name) {
24-
if (strcmp(name, "PlatformConstants") == 0) {
25-
return RCTPlatform.class;
26-
}
27-
return nil;
23+
return RCTCoreModulesClassProvider(name);
2824
}
2925

3026
std::shared_ptr<TurboModule> RNTesterTurboModuleProvider(const std::string &name, std::shared_ptr<JSCallInvoker> jsInvoker) {

React/CoreModules/CoreModulesPlugins.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
#else
1414

15-
//OSS-compatibility layer: manually define these for github.
15+
// OSS-compatibility layer: manually define these for github.
1616

1717
#import <Foundation/Foundation.h>
1818

@@ -23,6 +23,9 @@
2323
extern "C" {
2424
#endif
2525

26+
// RCTTurboModuleManagerDelegate should call this to resolve module classes.
27+
Class RCTCoreModulesClassProvider(const char *name);
28+
2629
// NOTE: Sync these with FB internal version.
2730

2831
Class RCTPlatformCls(void);
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+
8+
#ifndef RN_DISABLE_OSS_PLUGIN_HEADER
9+
10+
// OSS-compatibility layer: manually define these for github.
11+
// TODO: This should be codegen'ed
12+
13+
#import "CoreModulesPlugins.h"
14+
15+
#import <string>
16+
#import <unordered_map>
17+
18+
static std::unordered_map<std::string, Class (*)(void)> sCoreModuleClassMap = {
19+
// NOTE: Sync these with FB internal plugin definitions.
20+
{"PlatformConstants", RCTPlatformCls},
21+
};
22+
23+
Class RCTCoreModulesClassProvider(const char *name) {
24+
auto p = sCoreModuleClassMap.find(name);
25+
if (p != sCoreModuleClassMap.end()) {
26+
auto classFunc = p->second;
27+
return classFunc();
28+
}
29+
return nil;
30+
}
31+
32+
#endif // RN_DISABLE_OSS_PLUGIN_HEADER

0 commit comments

Comments
 (0)