-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Bring back Cxx TurboModule autolinking via `registerCxxModuleToG…
…lobalModuleMap` (#46360) Summary: Reverts the PR #45967 from philIip to bring back the `registerCxxModuleToGlobalModuleMap(..)` function, which I use in Nitro Modules and MMKV. Ontop of that, this also removes the "experimental" `RCT_EXPORT_CXX_MODULE_EXPERIMENTAL` macro, which I think was the original intent of this PR as this macro is a bit unsafe. I also added some small docs to `registerCxxModuleToGlobalModuleMap` while I'm at it. ## Changelog: <!-- Help reviewers and the release process by writing your own changelog entry. Pick one each for the category and type tags: [GENERAL] [CHANGED] - Bring back CxxTurboModule autolinking function, but remove `RCT_EXPORT_CXX_MODULE_EXPERIMENTAL` macro [ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message For more details, see: https://reactnative.dev/contributing/changelogs-in-pull-requests Pull Request resolved: #46360 Test Plan: Build Nitro Modules. Worked for me! :) Reviewed By: realsoelynn Differential Revision: D62310637 Pulled By: philIip fbshipit-source-id: 2caa2b8ea094dda5e13c81431a9a645cbcf8f807
- Loading branch information
1 parent
1bd4a11
commit e629a85
Showing
4 changed files
with
85 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 |
35 changes: 35 additions & 0 deletions
35
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,35 @@ | ||
/* | ||
* 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(); | ||
|
||
/** | ||
* Registers the given C++ TurboModule initializer function | ||
* in the global module map. | ||
* This needs to be called before the TurboModule is requested from JS, | ||
* for example in a `+ load`, your AppDelegate's start, or from Java init. | ||
*/ | ||
void registerCxxModuleToGlobalModuleMap( | ||
std::string name, | ||
std::function<std::shared_ptr<TurboModule>( | ||
std::shared_ptr<CallInvoker> jsInvoker)> moduleProviderFunc); | ||
|
||
} // namespace facebook::react |
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