Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make DefaultComponentsRegistry the default behaviour for ComponentFactory #45245

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ target_link_libraries(
react_utils
rrc_image
rrc_view
turbomodulejsijni
yoga
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ target_link_libraries(
react_utils
rrc_image
rrc_view
turbomodulejsijni
yoga
)

Expand Down Expand Up @@ -157,7 +156,6 @@ target_link_libraries(
react_utils
rrc_image
rrc_view
turbomodulejsijni
yoga
)

Expand Down Expand Up @@ -237,7 +235,6 @@ target_link_libraries(
react_utils
rrc_image
rrc_view
turbomodulejsijni
yoga
)

Expand Down Expand Up @@ -324,7 +321,6 @@ target_link_libraries(
react_utils
rrc_image
rrc_view
turbomodulejsijni
yoga
)

Expand Down Expand Up @@ -497,7 +493,6 @@ target_link_libraries(
react_utils
rrc_image
rrc_view
turbomodulejsijni
yoga
)

Expand Down Expand Up @@ -592,7 +587,6 @@ target_link_libraries(
react_utils
rrc_image
rrc_view
turbomodulejsijni
yoga
)

Expand Down Expand Up @@ -679,7 +673,6 @@ target_link_libraries(
react_utils
rrc_image
rrc_view
turbomodulejsijni
yoga
)

Expand Down Expand Up @@ -774,7 +767,6 @@ target_link_libraries(
react_utils
rrc_image
rrc_view
turbomodulejsijni
yoga
)

Expand Down
5 changes: 0 additions & 5 deletions packages/react-native/ReactAndroid/api/ReactAndroid.api
Original file line number Diff line number Diff line change
Expand Up @@ -1978,11 +1978,6 @@ public class com/facebook/react/config/ReactFeatureFlags {
public fun <init> ()V
}

public final class com/facebook/react/defaults/DefaultComponentsRegistry {
public static final field INSTANCE Lcom/facebook/react/defaults/DefaultComponentsRegistry;
public static final fun register (Lcom/facebook/react/fabric/ComponentFactory;)V
}

public final class com/facebook/react/defaults/DefaultNewArchitectureEntryPoint {
public static final field INSTANCE Lcom/facebook/react/defaults/DefaultNewArchitectureEntryPoint;
public static final fun getBridgelessEnabled ()Z
Expand Down
12 changes: 5 additions & 7 deletions packages/react-native/ReactAndroid/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ val preparePrefab by
Pair(
"../ReactCommon/react/renderer/componentregistry/",
"react/renderer/componentregistry/")),
PrefabPreprocessingEntry(
"react_newarchdefaults", Pair("src/main/jni/react/newarchdefaults", "")),
PrefabPreprocessingEntry(
"react_render_animations",
Pair("../ReactCommon/react/renderer/animations/", "react/renderer/animations/")),
Expand Down Expand Up @@ -152,7 +150,11 @@ val preparePrefab by
PrefabPreprocessingEntry(
"glog", Pair(File(buildDir, "third-party-ndk/glog/exported/").absolutePath, "")),
PrefabPreprocessingEntry(
"fabricjni", Pair("src/main/jni/react/fabric", "react/fabric/")),
"fabricjni",
listOf(
Pair("src/main/jni/react/fabric/DefaultComponentsRegistry.h", ""),
Pair("src/main/jni/react/fabric", "react/fabric/"),
)),
PrefabPreprocessingEntry(
"mapbufferjni", Pair("src/main/jni/react/mapbuffer", "react/mapbuffer/")),
PrefabPreprocessingEntry(
Expand Down Expand Up @@ -561,7 +563,6 @@ android {
"react_performance_timeline",
"react_utils",
"react_render_componentregistry",
"react_newarchdefaults",
"react_render_animations",
"react_render_core",
"react_render_consistency",
Expand Down Expand Up @@ -682,9 +683,6 @@ android {
create("react_render_componentregistry") {
headers = File(prefabHeadersDir, "react_render_componentregistry").absolutePath
}
create("react_newarchdefaults") {
headers = File(prefabHeadersDir, "react_newarchdefaults").absolutePath
}
create("react_render_animations") {
headers = File(prefabHeadersDir, "react_render_animations").absolutePath
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ add_library(react_codegen_rncore ALIAS ReactAndroid::react_codegen_rncore)
add_library(react_debug ALIAS ReactAndroid::react_debug)
add_library(react_utils ALIAS ReactAndroid::react_utils)
add_library(react_render_componentregistry ALIAS ReactAndroid::react_render_componentregistry)
add_library(react_newarchdefaults ALIAS ReactAndroid::react_newarchdefaults)
add_library(react_render_core ALIAS ReactAndroid::react_render_core)
add_library(react_render_graphics ALIAS ReactAndroid::react_render_graphics)
add_library(rrc_view ALIAS ReactAndroid::rrc_view)
Expand Down Expand Up @@ -102,7 +101,6 @@ target_link_libraries(${CMAKE_PROJECT_NAME}
react_debug # prefab ready
react_utils # prefab ready
react_nativemodule_core # prefab ready
react_newarchdefaults # prefab ready
react_render_componentregistry # prefab ready
react_render_core # prefab ready
react_render_debug # prefab ready
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ package com.facebook.react.defaults

import com.facebook.soloader.SoLoader

internal class DefaultSoLoader {
internal class AppModulesSoLoader {
companion object {
@Synchronized
@JvmStatic
fun maybeLoadSoLibrary() {
SoLoader.loadLibrary("react_newarchdefaults")
try {
SoLoader.loadLibrary("appmodules")
} catch (e: UnsatisfiedLinkError) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

package com.facebook.react.defaults

import com.facebook.proguard.annotations.DoNotStrip
import com.facebook.react.common.annotations.UnstableReactNativeAPI
import com.facebook.react.fabric.ComponentFactory

/**
Expand All @@ -16,14 +16,18 @@ import com.facebook.react.fabric.ComponentFactory
*
* This class works together with the [DefaultNewArchitectureEntryPoint] and it's C++ implementation
* is hosted inside the React Native framework
*
* TODO(T186951312): Should this be @UnstableReactNativeAPI?
*/
@DoNotStrip
@Suppress("UNUSED_PARAMETER")
@UnstableReactNativeAPI
public object DefaultComponentsRegistry {
init {
DefaultSoLoader.maybeLoadSoLibrary()
AppModulesSoLoader.maybeLoadSoLibrary()
}

@JvmStatic @DoNotStrip public external fun register(componentFactory: ComponentFactory): Unit
@JvmStatic
@Deprecated(
"This call is no longer necessary. registerComponentDescriptorsFromEntryPoint will be used by default.")
public fun register(componentFactory: ComponentFactory): Unit {
// No-op
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public object DefaultNewArchitectureEntryPoint {
privateConcurrentReactEnabled = fabricEnabled
privateBridgelessEnabled = bridgelessEnabled

DefaultSoLoader.maybeLoadSoLibrary()
AppModulesSoLoader.maybeLoadSoLibrary()
loaded = true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,12 @@ public object DefaultReactHost {
reactPackages = packageList,
jsRuntimeFactory = jsRuntimeFactory,
turboModuleManagerDelegateBuilder = defaultTmmDelegateBuilder)
val componentFactory = ComponentFactory()
DefaultComponentsRegistry.register(componentFactory)
// TODO: T164788699 find alternative of accessing ReactHostImpl for initialising reactHost
reactHost =
ReactHostImpl(
context,
defaultReactHostDelegate,
componentFactory,
ComponentFactory(),
true /* allowPackagerServerAccess */,
useDevSupport,
)
Expand Down Expand Up @@ -129,4 +127,8 @@ public object DefaultReactHost {
}
return reactNativeHost.toReactHost(context)
}

init {
AppModulesSoLoader.maybeLoadSoLibrary()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ protected constructor(
override fun getUIManagerProvider(): UIManagerProvider? =
if (isNewArchEnabled) {
UIManagerProvider { reactApplicationContext: ReactApplicationContext ->
val componentFactory = ComponentFactory()
DefaultComponentsRegistry.register(componentFactory)

val viewManagerRegistry =
if (lazyViewManagersEnabled) {
ViewManagerRegistry(
Expand All @@ -62,9 +59,8 @@ protected constructor(
ViewManagerRegistry(
reactInstanceManager.getOrCreateViewManagers(reactApplicationContext))
}

FabricUIManagerProviderImpl(
componentFactory, ReactNativeConfig.DEFAULT_CONFIG, viewManagerRegistry)
ComponentFactory(), ReactNativeConfig.DEFAULT_CONFIG, viewManagerRegistry)
.createUIManager(reactApplicationContext)
}
} else {
Expand Down Expand Up @@ -115,4 +111,8 @@ protected constructor(
isHermesEnabled ?: true,
useDeveloperSupport,
)

init {
AppModulesSoLoader.maybeLoadSoLibrary()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.facebook.react.ReactPackage
import com.facebook.react.ReactPackageTurboModuleManagerDelegate
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.common.annotations.UnstableReactNativeAPI
import com.facebook.react.internal.turbomodule.core.NativeModuleSoLoader
import com.facebook.react.runtime.cxxreactpackage.CxxReactPackage

/**
Expand Down Expand Up @@ -69,7 +70,8 @@ private constructor(

private companion object {
init {
DefaultSoLoader.maybeLoadSoLibrary()
NativeModuleSoLoader.maybeLoadSoLibrary()
AppModulesSoLoader.maybeLoadSoLibrary()
}

@DoNotStrip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ add_react_android_subdir(src/main/jni/react/mapbuffer)
add_react_android_subdir(src/main/jni/react/reactnativeblob)
add_react_android_subdir(src/main/jni/react/fabric)
add_react_android_subdir(src/main/jni/react/featureflags)
add_react_android_subdir(src/main/jni/react/newarchdefaults)
add_react_android_subdir(src/main/jni/react/hermes/reactexecutor)
add_react_android_subdir(src/main/jni/react/hermes/instrumentation/)
add_react_android_subdir(src/main/jni/react/runtime/cxxreactpackage)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
*/

#include "ComponentFactory.h"
#include <android/log.h>
#include <fbjni/fbjni.h>
#include <jsi/jsi.h>

#include <react/renderer/componentregistry/ComponentDescriptorProviderRegistry.h>
#include <react/renderer/componentregistry/ComponentDescriptorRegistry.h>
#include <react/renderer/components/rncore/ComponentDescriptors.h>

#include "CoreComponentsRegistry.h"
#include "DefaultComponentsRegistry.h"

using namespace facebook::jsi;

Expand All @@ -20,6 +23,31 @@ jni::local_ref<ComponentFactory::jhybriddata> ComponentFactory::initHybrid(
return makeCxxInstance();
}

SharedComponentDescriptorRegistry ComponentFactory::defaultBuildRegistry(
const EventDispatcher::Weak& eventDispatcher,
const ContextContainer::Shared& contextContainer) {
ComponentDescriptorParameters params{
.eventDispatcher = eventDispatcher,
.contextContainer = contextContainer,
.flavor = nullptr};

auto providerRegistry = CoreComponentsRegistry::sharedProviderRegistry();
if (DefaultComponentsRegistry::registerComponentDescriptorsFromEntryPoint) {
DefaultComponentsRegistry::registerComponentDescriptorsFromEntryPoint(
providerRegistry);
} else {
LOG(WARNING)
<< "Custom component descriptors were not configured from JNI_OnLoad";
}

auto registry = providerRegistry->createComponentDescriptorRegistry(params);
auto& mutableRegistry = const_cast<ComponentDescriptorRegistry&>(*registry);
mutableRegistry.setFallbackComponentDescriptor(
std::make_shared<UnimplementedNativeViewComponentDescriptor>(params));

return registry;
}

void ComponentFactory::registerNatives() {
registerHybrid({
makeNativeMethod("initHybrid", ComponentFactory::initHybrid),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@ class ComponentFactory : public jni::HybridClass<ComponentFactory> {

static void registerNatives();

ComponentRegistryFactory buildRegistryFunction;
ComponentRegistryFactory buildRegistryFunction = defaultBuildRegistry;

private:
static SharedComponentDescriptorRegistry defaultBuildRegistry(
const EventDispatcher::Weak& eventDispatcher,
const ContextContainer::Shared& contextContainer);

static jni::local_ref<jhybriddata> initHybrid(jni::alias_ref<jclass>);
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* 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 "DefaultComponentsRegistry.h"

namespace facebook::react::DefaultComponentsRegistry {

std::function<void(std::shared_ptr<const ComponentDescriptorProviderRegistry>)>
registerComponentDescriptorsFromEntryPoint;

} // namespace facebook::react::DefaultComponentsRegistry
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* 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 <react/renderer/componentregistry/ComponentDescriptorProviderRegistry.h>

namespace facebook::react::DefaultComponentsRegistry {

extern std::function<void(
std::shared_ptr<const ComponentDescriptorProviderRegistry>)>
registerComponentDescriptorsFromEntryPoint;

} // namespace facebook::react::DefaultComponentsRegistry
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void*) {
return facebook::jni::initialize(vm, [] {
facebook::react::Binding::registerNatives();
facebook::react::ComponentFactory::registerNatives();
facebook::react::EventBeatManager::registerNatives();
facebook::react::EventEmitterWrapper::registerNatives();
facebook::react::StateWrapperImpl::registerNatives();
facebook::react::ComponentFactory::registerNatives();
facebook::react::SurfaceHandlerBinding::registerNatives();
facebook::react::JEmptyReactNativeConfig::registerNatives();
});
Expand Down
Loading
Loading