-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fabric] Add a MainComponentsRegistry for the application
- Loading branch information
Showing
4 changed files
with
127 additions
and
0 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
android/app/src/main/java/com/rnnewarchitectureapp/components/MainComponentsRegistry.java
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,28 @@ | ||
package com.rnnewarchitectureapp.components; | ||
|
||
import com.facebook.common.internal.DoNotStrip; | ||
import com.facebook.jni.HybridData; | ||
import com.facebook.react.fabric.ComponentFactory; | ||
import com.facebook.soloader.SoLoader; | ||
|
||
@DoNotStrip | ||
public class MainComponentsRegistry { | ||
static { | ||
SoLoader.loadLibrary("fabricjni"); | ||
} | ||
|
||
@DoNotStrip private final HybridData mHybridData; | ||
|
||
@DoNotStrip | ||
private native HybridData initHybrid(ComponentFactory componentFactory); | ||
|
||
@DoNotStrip | ||
private MainComponentsRegistry(ComponentFactory componentFactory) { | ||
mHybridData = initHybrid(componentFactory); | ||
} | ||
|
||
@DoNotStrip | ||
public static MainComponentsRegistry register(ComponentFactory componentFactory) { | ||
return new MainComponentsRegistry(componentFactory); | ||
} | ||
} |
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,62 @@ | ||
#include "MainComponentsRegistry.h" | ||
|
||
#include <CoreComponentsRegistry.h> | ||
#include <fbjni/fbjni.h> | ||
#include <react/renderer/componentregistry/ComponentDescriptorProviderRegistry.h> | ||
#include <react/renderer/components/answersolver/ComponentDescriptors.h> | ||
#include <react/renderer/components/rncore/ComponentDescriptors.h> | ||
|
||
namespace facebook { | ||
namespace react { | ||
|
||
MainComponentsRegistry::MainComponentsRegistry( | ||
ComponentFactory *delegate) | ||
: delegate_(delegate) {} | ||
|
||
std::shared_ptr<ComponentDescriptorProviderRegistry const> | ||
MainComponentsRegistry::sharedProviderRegistry() { | ||
auto providerRegistry = CoreComponentsRegistry::sharedProviderRegistry(); | ||
|
||
providerRegistry->add(concreteComponentDescriptorProvider< | ||
AnswerViewerComponentDescriptor>()); | ||
|
||
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 |
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 @@ | ||
#pragma once | ||
|
||
#include <ComponentFactory.h> | ||
#include <fbjni/fbjni.h> | ||
#include <react/renderer/componentregistry/ComponentDescriptorProviderRegistry.h> | ||
#include <react/renderer/componentregistry/ComponentDescriptorRegistry.h> | ||
|
||
namespace facebook { | ||
namespace react { | ||
|
||
class MainComponentsRegistry | ||
: public facebook::jni::HybridClass<MainComponentsRegistry> { | ||
public: | ||
constexpr static auto kJavaDescriptor = | ||
"Lcom/rnnewarchitectureapp/components/MainComponentsRegistry;"; | ||
|
||
static void registerNatives(); | ||
|
||
MainComponentsRegistry(ComponentFactory *delegate); | ||
|
||
private: | ||
friend HybridBase; | ||
|
||
static std::shared_ptr<ComponentDescriptorProviderRegistry const> | ||
sharedProviderRegistry(); | ||
|
||
const ComponentFactory *delegate_; | ||
|
||
static jni::local_ref<jhybriddata> initHybrid( | ||
jni::alias_ref<jclass>, | ||
ComponentFactory *delegate); | ||
}; | ||
|
||
} // 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 |
---|---|---|
@@ -1,8 +1,10 @@ | ||
#include <fbjni/fbjni.h> | ||
#include "MainApplicationTurboModuleManagerDelegate.h" | ||
#include "MainComponentsRegistry.h" | ||
|
||
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *) { | ||
return facebook::jni::initialize(vm, [] { | ||
facebook::react::MainApplicationTurboModuleManagerDelegate::registerNatives(); | ||
facebook::react::MainComponentsRegistry::registerNatives(); | ||
}); | ||
} |