forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "remove cxx TM autolinking (facebook#45967)"
This reverts commit 184646e.
- Loading branch information
Showing
4 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...ages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/CxxTurboModuleUtils.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#include "CxxTurboModuleUtils.h" | ||
|
||
namespace facebook::react { | ||
|
||
std::unordered_map< | ||
std::string, | ||
std::function< | ||
std::shared_ptr<TurboModule>(std::shared_ptr<CallInvoker> jsInvoker)>>& | ||
globalExportedCxxTurboModuleMap() { | ||
static std::unordered_map< | ||
std::string, | ||
std::function<std::shared_ptr<TurboModule>( | ||
std::shared_ptr<CallInvoker> jsInvoker)>> | ||
map; | ||
return map; | ||
} | ||
|
||
void registerCxxModuleToGlobalModuleMap( | ||
std::string name, | ||
std::function<std::shared_ptr<TurboModule>( | ||
std::shared_ptr<CallInvoker> jsInvoker)> moduleProviderFunc) { | ||
globalExportedCxxTurboModuleMap()[name] = moduleProviderFunc; | ||
} | ||
|
||
} // namespace facebook::react |
67 changes: 67 additions & 0 deletions
67
packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/CxxTurboModuleUtils.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <string> | ||
#include <unordered_map> | ||
|
||
#include <ReactCommon/CallInvoker.h> | ||
#include <ReactCommon/TurboModule.h> | ||
|
||
namespace facebook::react { | ||
|
||
std::unordered_map< | ||
std::string, | ||
std::function< | ||
std::shared_ptr<TurboModule>(std::shared_ptr<CallInvoker> jsInvoker)>>& | ||
globalExportedCxxTurboModuleMap(); | ||
|
||
void registerCxxModuleToGlobalModuleMap( | ||
std::string name, | ||
std::function<std::shared_ptr<TurboModule>( | ||
std::shared_ptr<CallInvoker> jsInvoker)> moduleProviderFunc); | ||
|
||
} // namespace facebook::react | ||
|
||
/* | ||
* You can use this macro to register your C++ TurboModule in your .cpp | ||
* implementation if you do not have access to getTurboModule:jsInvoker: | ||
* callback. This will register the module before main() is called, | ||
* so it will incur a startup cost. | ||
* | ||
* RCT_EXPORT_CXX_MODULE_EXPERIMENTAL(ModuleExample) becomes: | ||
* | ||
* #pragma clang diagnostic push | ||
* #pragma clang diagnostic ignored "-Wglobal-constructors" | ||
* struct ModuleExampleLoad { | ||
* ModuleExampleLoad() { | ||
* facebook::react::registerCxxModule(name, | ||
* [&](std::shared_ptr<facebook::react::CallInvoker> jsInvoker) { | ||
* return | ||
* std::make_shared<facebook::react::ModuleExample>(jsInvoker); | ||
* }); | ||
* } | ||
* }; | ||
* static ModuleExampleLoad moduleExampleLoad; | ||
* #pragma clang diagnostic pop | ||
* | ||
*/ | ||
#define RCT_EXPORT_CXX_MODULE_EXPERIMENTAL(name) \ | ||
_Pragma("clang diagnostic push") \ | ||
_Pragma("clang diagnostic ignored \"-Wglobal-constructors\"") struct \ | ||
name##Load { \ | ||
name##Load() { \ | ||
facebook::react::registerCxxModuleToGlobalModuleMap( \ | ||
#name, \ | ||
[&](std::shared_ptr<facebook::react::CallInvoker> jsInvoker) { \ | ||
return std::make_shared<facebook::react::name>(jsInvoker); \ | ||
}); \ | ||
} \ | ||
}; \ | ||
static name##Load _##name##Load; \ | ||
_Pragma("clang diagnostic pop") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters