-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c7aec30
commit f50e591
Showing
12 changed files
with
302 additions
and
57 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
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
android/app/src/main/jni/MainApplicationModuleProvider.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 @@ | ||
#include "MainApplicationModuleProvider.h" | ||
|
||
#include <rncli.h> | ||
#include <rncore.h> | ||
|
||
namespace facebook { | ||
namespace react { | ||
|
||
std::shared_ptr<TurboModule> MainApplicationModuleProvider( | ||
const std::string &moduleName, | ||
const JavaTurboModule::InitParams ¶ms) { | ||
// Here you can provide your own module provider for TurboModules coming from | ||
// either your application or from external libraries. The approach to follow | ||
// is similar to the following (for a library called `samplelibrary`: | ||
// | ||
// auto module = samplelibrary_ModuleProvider(moduleName, params); | ||
// if (module != nullptr) { | ||
// return module; | ||
// } | ||
// return rncore_ModuleProvider(moduleName, params); | ||
|
||
// Module providers autolinked by RN CLI | ||
auto rncli_module = rncli_ModuleProvider(moduleName, params); | ||
if (rncli_module != nullptr) { | ||
return rncli_module; | ||
} | ||
|
||
return rncore_ModuleProvider(moduleName, params); | ||
} | ||
|
||
} // namespace react | ||
} // namespace facebook |
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,16 @@ | ||
#pragma once | ||
|
||
#include <memory> | ||
#include <string> | ||
|
||
#include <ReactCommon/JavaTurboModule.h> | ||
|
||
namespace facebook { | ||
namespace react { | ||
|
||
std::shared_ptr<TurboModule> MainApplicationModuleProvider( | ||
const std::string &moduleName, | ||
const JavaTurboModule::InitParams ¶ms); | ||
|
||
} // namespace react | ||
} // namespace facebook |
45 changes: 45 additions & 0 deletions
45
android/app/src/main/jni/MainApplicationTurboModuleManagerDelegate.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,45 @@ | ||
#include "MainApplicationTurboModuleManagerDelegate.h" | ||
#include "MainApplicationModuleProvider.h" | ||
|
||
namespace facebook { | ||
namespace react { | ||
|
||
jni::local_ref<MainApplicationTurboModuleManagerDelegate::jhybriddata> | ||
MainApplicationTurboModuleManagerDelegate::initHybrid( | ||
jni::alias_ref<jhybridobject>) { | ||
return makeCxxInstance(); | ||
} | ||
|
||
void MainApplicationTurboModuleManagerDelegate::registerNatives() { | ||
registerHybrid({ | ||
makeNativeMethod( | ||
"initHybrid", MainApplicationTurboModuleManagerDelegate::initHybrid), | ||
makeNativeMethod( | ||
"canCreateTurboModule", | ||
MainApplicationTurboModuleManagerDelegate::canCreateTurboModule), | ||
}); | ||
} | ||
|
||
std::shared_ptr<TurboModule> | ||
MainApplicationTurboModuleManagerDelegate::getTurboModule( | ||
const std::string &name, | ||
const std::shared_ptr<CallInvoker> &jsInvoker) { | ||
// Not implemented yet: provide pure-C++ NativeModules here. | ||
return nullptr; | ||
} | ||
|
||
std::shared_ptr<TurboModule> | ||
MainApplicationTurboModuleManagerDelegate::getTurboModule( | ||
const std::string &name, | ||
const JavaTurboModule::InitParams ¶ms) { | ||
return MainApplicationModuleProvider(name, params); | ||
} | ||
|
||
bool MainApplicationTurboModuleManagerDelegate::canCreateTurboModule( | ||
const std::string &name) { | ||
return getTurboModule(name, nullptr) != nullptr || | ||
getTurboModule(name, {.moduleName = name}) != nullptr; | ||
} | ||
|
||
} // namespace react | ||
} // namespace facebook |
38 changes: 38 additions & 0 deletions
38
android/app/src/main/jni/MainApplicationTurboModuleManagerDelegate.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,38 @@ | ||
#include <memory> | ||
#include <string> | ||
|
||
#include <ReactCommon/TurboModuleManagerDelegate.h> | ||
#include <fbjni/fbjni.h> | ||
|
||
namespace facebook { | ||
namespace react { | ||
|
||
class MainApplicationTurboModuleManagerDelegate | ||
: public jni::HybridClass< | ||
MainApplicationTurboModuleManagerDelegate, | ||
TurboModuleManagerDelegate> { | ||
public: | ||
// Adapt it to the package you used for your Java class. | ||
static constexpr auto kJavaDescriptor = | ||
"Lcom/rndiffapp/newarchitecture/modules/MainApplicationTurboModuleManagerDelegate;"; | ||
|
||
static jni::local_ref<jhybriddata> initHybrid(jni::alias_ref<jhybridobject>); | ||
|
||
static void registerNatives(); | ||
|
||
std::shared_ptr<TurboModule> getTurboModule( | ||
const std::string &name, | ||
const std::shared_ptr<CallInvoker> &jsInvoker) override; | ||
std::shared_ptr<TurboModule> getTurboModule( | ||
const std::string &name, | ||
const JavaTurboModule::InitParams ¶ms) override; | ||
|
||
/** | ||
* Test-only method. Allows user to verify whether a TurboModule can be | ||
* created by instances of this class. | ||
*/ | ||
bool canCreateTurboModule(const std::string &name); | ||
}; | ||
|
||
} // namespace react | ||
} // namespace facebook |
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,65 @@ | ||
#include "MainComponentsRegistry.h" | ||
|
||
#include <CoreComponentsRegistry.h> | ||
#include <fbjni/fbjni.h> | ||
#include <react/renderer/componentregistry/ComponentDescriptorProviderRegistry.h> | ||
#include <react/renderer/components/rncore/ComponentDescriptors.h> | ||
#include <rncli.h> | ||
|
||
namespace facebook { | ||
namespace react { | ||
|
||
MainComponentsRegistry::MainComponentsRegistry(ComponentFactory *delegate) {} | ||
|
||
std::shared_ptr<ComponentDescriptorProviderRegistry const> | ||
MainComponentsRegistry::sharedProviderRegistry() { | ||
auto providerRegistry = CoreComponentsRegistry::sharedProviderRegistry(); | ||
|
||
// Autolinked providers registered by RN CLI | ||
rncli_registerProviders(providerRegistry); | ||
|
||
// Custom Fabric Components go here. You can register custom | ||
// components coming from your App or from 3rd party libraries here. | ||
// | ||
// providerRegistry->add(concreteComponentDescriptorProvider< | ||
// AocViewerComponentDescriptor>()); | ||
return providerRegistry; | ||
} | ||
|
||
jni::local_ref<MainComponentsRegistry::jhybriddata> | ||
MainComponentsRegistry::initHybrid( | ||
jni::alias_ref<jclass>, | ||
ComponentFactory *delegate) { | ||
auto instance = makeCxxInstance(delegate); | ||
|
||
auto buildRegistryFunction = | ||
[](EventDispatcher::Weak const &eventDispatcher, | ||
ContextContainer::Shared const &contextContainer) | ||
-> ComponentDescriptorRegistry::Shared { | ||
auto registry = MainComponentsRegistry::sharedProviderRegistry() | ||
->createComponentDescriptorRegistry( | ||
{eventDispatcher, contextContainer}); | ||
|
||
auto mutableRegistry = | ||
std::const_pointer_cast<ComponentDescriptorRegistry>(registry); | ||
|
||
mutableRegistry->setFallbackComponentDescriptor( | ||
std::make_shared<UnimplementedNativeViewComponentDescriptor>( | ||
ComponentDescriptorParameters{ | ||
eventDispatcher, contextContainer, nullptr})); | ||
|
||
return registry; | ||
}; | ||
|
||
delegate->buildRegistryFunction = buildRegistryFunction; | ||
return instance; | ||
} | ||
|
||
void MainComponentsRegistry::registerNatives() { | ||
registerHybrid({ | ||
makeNativeMethod("initHybrid", MainComponentsRegistry::initHybrid), | ||
}); | ||
} | ||
|
||
} // namespace react | ||
} // namespace facebook |
Oops, something went wrong.