Skip to content

Commit 0b95386

Browse files
committed
chore: update example using fabric arch
1 parent 6e1d889 commit 0b95386

File tree

2 files changed

+117
-0
lines changed

2 files changed

+117
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
THIS_DIR := $(call my-dir)
2+
3+
include $(REACT_ANDROID_DIR)/Android-prebuilt.mk
4+
5+
# If you wish to add a custom TurboModule or Fabric component in your app you
6+
# will have to include the following autogenerated makefile.
7+
# include $(GENERATED_SRC_DIR)/codegen/jni/Android.mk
8+
9+
# Includes the MK file for `react-native-fast-shadow`
10+
include $(NODE_MODULES_DIR)/../../android/build/generated/source/codegen/jni/Android.mk
11+
12+
include $(CLEAR_VARS)
13+
14+
LOCAL_PATH := $(THIS_DIR)
15+
16+
# You can customize the name of your application .so file here.
17+
LOCAL_MODULE := example_appmodules
18+
19+
LOCAL_C_INCLUDES := $(LOCAL_PATH)
20+
LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.cpp)
21+
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
22+
23+
# If you wish to add a custom TurboModule or Fabric component in your app you
24+
# will have to uncomment those lines to include the generated source
25+
# files from the codegen (placed in $(GENERATED_SRC_DIR)/codegen/jni)
26+
#
27+
# LOCAL_C_INCLUDES += $(GENERATED_SRC_DIR)/codegen/jni
28+
# LOCAL_SRC_FILES += $(wildcard $(GENERATED_SRC_DIR)/codegen/jni/*.cpp)
29+
# LOCAL_EXPORT_C_INCLUDES += $(GENERATED_SRC_DIR)/codegen/jni
30+
31+
# Here you should add any native library you wish to depend on.
32+
LOCAL_SHARED_LIBRARIES := \
33+
libfabricjni \
34+
libfbjni \
35+
libfolly_futures \
36+
libfolly_json \
37+
libglog \
38+
libjsi \
39+
libreact_codegen_rncore \
40+
libreact_codegen_FastShadowView \
41+
libreact_debug \
42+
libreact_nativemodule_core \
43+
libreact_render_componentregistry \
44+
libreact_render_core \
45+
libreact_render_debug \
46+
libreact_render_graphics \
47+
librrc_view \
48+
libruntimeexecutor \
49+
libturbomodulejsijni \
50+
libyoga
51+
52+
LOCAL_CFLAGS := -DLOG_TAG=\"ReactNative\" -fexceptions -frtti -std=c++17 -Wall
53+
54+
include $(BUILD_SHARED_LIBRARY)
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#include "MainComponentsRegistry.h"
2+
3+
#include <CoreComponentsRegistry.h>
4+
#include <fbjni/fbjni.h>
5+
#include <react/renderer/componentregistry/ComponentDescriptorProviderRegistry.h>
6+
#include <react/renderer/components/rncore/ComponentDescriptors.h>
7+
#include <react/renderer/components/FastShadowView/ComponentDescriptors.h>
8+
9+
namespace facebook {
10+
namespace react {
11+
12+
MainComponentsRegistry::MainComponentsRegistry(ComponentFactory *delegate) {}
13+
14+
std::shared_ptr<ComponentDescriptorProviderRegistry const>
15+
MainComponentsRegistry::sharedProviderRegistry() {
16+
auto providerRegistry = CoreComponentsRegistry::sharedProviderRegistry();
17+
18+
// Custom Fabric Components go here. You can register custom
19+
// components coming from your App or from 3rd party libraries here.
20+
//
21+
// providerRegistry->add(concreteComponentDescriptorProvider<
22+
// AocViewerComponentDescriptor>());
23+
providerRegistry->add(concreteComponentDescriptorProvider<FastShadowViewComponentDescriptor>());
24+
return providerRegistry;
25+
}
26+
27+
jni::local_ref<MainComponentsRegistry::jhybriddata>
28+
MainComponentsRegistry::initHybrid(
29+
jni::alias_ref<jclass>,
30+
ComponentFactory *delegate) {
31+
auto instance = makeCxxInstance(delegate);
32+
33+
auto buildRegistryFunction =
34+
[](EventDispatcher::Weak const &eventDispatcher,
35+
ContextContainer::Shared const &contextContainer)
36+
-> ComponentDescriptorRegistry::Shared {
37+
auto registry = MainComponentsRegistry::sharedProviderRegistry()
38+
->createComponentDescriptorRegistry(
39+
{eventDispatcher, contextContainer});
40+
41+
auto mutableRegistry =
42+
std::const_pointer_cast<ComponentDescriptorRegistry>(registry);
43+
44+
mutableRegistry->setFallbackComponentDescriptor(
45+
std::make_shared<UnimplementedNativeViewComponentDescriptor>(
46+
ComponentDescriptorParameters{
47+
eventDispatcher, contextContainer, nullptr}));
48+
49+
return registry;
50+
};
51+
52+
delegate->buildRegistryFunction = buildRegistryFunction;
53+
return instance;
54+
}
55+
56+
void MainComponentsRegistry::registerNatives() {
57+
registerHybrid({
58+
makeNativeMethod("initHybrid", MainComponentsRegistry::initHybrid),
59+
});
60+
}
61+
62+
} // namespace react
63+
} // namespace facebook

0 commit comments

Comments
 (0)