Skip to content

Commit

Permalink
Extract ComponentNameRegistry out of Fabric modules
Browse files Browse the repository at this point in the history
Summary:
This diff extracts ComponentNameRegistry out of Fabric modules

This is necessary to avoid depending on Fabric and regressing APK size for other RN apps (e.g. IG)

changelog: [internal] internal

Reviewed By: JoshuaGross

Differential Revision: D26765328

fbshipit-source-id: 0a22c4279146f5243473c74a84e78fad7f08f956
  • Loading branch information
mdvacca authored and facebook-github-bot committed Mar 3, 2021
1 parent 056f1fd commit fca0442
Show file tree
Hide file tree
Showing 14 changed files with 196 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@
import com.facebook.react.devsupport.interfaces.DevBundleDownloadListener;
import com.facebook.react.devsupport.interfaces.DevSupportManager;
import com.facebook.react.devsupport.interfaces.PackagerStatusCallback;
import com.facebook.react.fabric.ComponentNameResolver;
import com.facebook.react.fabric.ComponentNameResolverManager;
import com.facebook.react.modules.appearance.AppearanceModule;
import com.facebook.react.modules.appregistry.AppRegistry;
import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
Expand All @@ -97,6 +95,8 @@
import com.facebook.react.turbomodule.core.TurboModuleManager;
import com.facebook.react.turbomodule.core.TurboModuleManagerDelegate;
import com.facebook.react.turbomodule.core.interfaces.TurboModuleRegistry;
import com.facebook.react.uimanager.ComponentNameResolver;
import com.facebook.react.uimanager.ComponentNameResolverManager;
import com.facebook.react.uimanager.DisplayMetricsHolder;
import com.facebook.react.uimanager.ReactRoot;
import com.facebook.react.uimanager.UIImplementationProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

#include "Binding.h"
#include "ComponentFactory.h"
#include "ComponentNameResolverManager.h"
#include "CoreComponentsRegistry.h"
#include "EventBeatManager.h"
#include "EventEmitterWrapper.h"
Expand All @@ -22,7 +21,6 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *) {
facebook::react::EventEmitterWrapper::registerNatives();
facebook::react::StateWrapperImpl::registerNatives();
facebook::react::ComponentFactory::registerNatives();
facebook::react::ComponentNameResolverManager::registerNatives();
facebook::react::CoreComponentsRegistry::registerNatives();
});
}
2 changes: 2 additions & 0 deletions ReactAndroid/src/main/java/com/facebook/react/uimanager/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ rn_android_library(
":DisplayMetrics",
react_native_dep("java/com/facebook/systrace:systrace"),
react_native_dep("libraries/fbcore/src/main/java/com/facebook/common/logging:logging"),
react_native_dep("libraries/soloader/java/com/facebook/soloader:soloader"),
react_native_dep("third-party/java/infer-annotations:infer-annotations"),
react_native_target("java/com/facebook/debug/tags:tags"),
react_native_target("java/com/facebook/debug/holder:holder"),
react_native_target("java/com/facebook/react/bridge:bridge"),
react_native_target("java/com/facebook/react/uimanager/jni:jni"),
react_native_target("java/com/facebook/react/common:common"),
react_native_target("java/com/facebook/react/config:config"),
react_native_target("java/com/facebook/react/module/annotations:annotations"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.react.fabric;
package com.facebook.react.uimanager;

import com.facebook.proguard.annotations.DoNotStrip;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.react.fabric;
package com.facebook.react.uimanager;

import com.facebook.jni.HybridData;
import com.facebook.proguard.annotations.DoNotStrip;
import com.facebook.react.bridge.RuntimeExecutor;
import com.facebook.soloader.SoLoader;

public class ComponentNameResolverManager {

static {
FabricSoLoader.staticInit();
staticInit();
}

@DoNotStrip
Expand All @@ -31,4 +32,8 @@ private native HybridData initHybrid(
RuntimeExecutor runtimeExecutor, Object componentNameResolver);

private native void installJSIBindings();

private static void staticInit() {
SoLoader.loadLibrary("uimanagerjni");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := uimanagerjni

LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.cpp)

LOCAL_SHARED_LIBRARIES := libyoga libglog libfb libfbjni libglog_init libfolly_json libfolly_futures react_render_componentregistry librrc_native

LOCAL_STATIC_LIBRARIES :=

LOCAL_C_INCLUDES := $(LOCAL_PATH)/

LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/

LOCAL_CFLAGS := \
-DLOG_TAG=\"ReacTNative\"

LOCAL_CFLAGS += -fexceptions -frtti -std=c++14 -Wall

include $(BUILD_SHARED_LIBRARY)

$(call import-module,fbgloginit)
$(call import-module,folly)
$(call import-module,fb)
$(call import-module,fbjni)
$(call import-module,yogajni)
$(call import-module,glog)

$(call import-module,react/renderer/componentregistry)
$(call import-module,react/renderer/componentregistry/native)
41 changes: 41 additions & 0 deletions ReactAndroid/src/main/java/com/facebook/react/uimanager/jni/BUCK
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
load("//tools/build_defs/oss:rn_defs.bzl", "ANDROID", "FBJNI_TARGET", "react_native_target", "react_native_xplat_target", "rn_xplat_cxx_library", "subdir_glob")

rn_xplat_cxx_library(
name = "jni",
srcs = glob(["*.cpp"]),
headers = glob(["*.h"]),
header_namespace = "",
exported_headers = subdir_glob(
[
("", "**/*.h"),
],
prefix = "react/uimanager/jni",
),
compiler_flags = [
"-fexceptions",
"-frtti",
"-std=c++14",
"-Wall",
],
fbandroid_allow_jni_merging = True,
labels = ["supermodule:xplat/default/public.react_native.infra"],
platforms = (ANDROID),
preprocessor_flags = [
"-DLOG_TAG=\"ReactNative\"",
"-DWITH_FBSYSTRACE=1",
],
soname = "libuimanagerjni.$(ext)",
visibility = ["PUBLIC"],
deps = [
react_native_xplat_target("runtimeexecutor:runtimeexecutor"),
react_native_xplat_target("react/renderer/componentregistry:componentregistry"),
react_native_xplat_target("react/renderer/componentregistry/native:native"),
react_native_target("jni/react/jni:jni"),
"//xplat/fbsystrace:fbsystrace",
"//xplat/folly:molly",
"//xplat/jsi:JSIDynamic",
"//xplat/jsi:jsi",
"//xplat/third-party/linker_lib:atomic",
FBJNI_TARGET,
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

#include "ComponentNameResolverManager.h"

#include <react/renderer/componentregistry/NativeComponentRegistryBinding.h>
#include <react/renderer/componentregistry/native/NativeComponentRegistryBinding.h>

namespace facebook {
namespace react {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ class ComponentNameResolverManager
: public jni::HybridClass<ComponentNameResolverManager> {
public:
static auto constexpr kJavaDescriptor =
"Lcom/facebook/react/fabric/ComponentNameResolverManager;";
"Lcom/facebook/react/uimanager/ComponentNameResolverManager;";

constexpr static auto ComponentNameResolverJavaDescriptor =
"com/facebook/react/fabric/ComponentNameResolver";
"com/facebook/react/uimanager/ComponentNameResolver";

static jni::local_ref<jhybriddata> initHybrid(
jni::alias_ref<jhybridobject> jThis,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

#include <fbjni/fbjni.h>

#include "ComponentNameResolverManager.h"

JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *) {
return facebook::jni::initialize(vm, [] {
facebook::react::ComponentNameResolverManager::registerNatives();
});
}
29 changes: 29 additions & 0 deletions ReactCommon/react/renderer/componentregistry/native/Android.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := rrc_native

LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../../

LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.cpp)

LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../../../../

LOCAL_SHARED_LIBRARIES := libjsi libfolly_futures libfolly_json libreact_render_core libreact_render_debug libreact_utils libglog_init libreact_debug

LOCAL_CFLAGS := \
-DLOG_TAG=\"Fabric\"

LOCAL_CFLAGS += -fexceptions -frtti -std=c++14 -Wall

include $(BUILD_SHARED_LIBRARY)

$(call import-module,fbgloginit)
$(call import-module,folly)
$(call import-module,jsi)
58 changes: 58 additions & 0 deletions ReactCommon/react/renderer/componentregistry/native/BUCK
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
load(
"//tools/build_defs/oss:rn_defs.bzl",
"ANDROID",
"APPLE",
"CXX",
"get_apple_compiler_flags",
"get_apple_inspector_flags",
"get_preprocessor_flags_for_build_mode",
"rn_xplat_cxx_library",
"subdir_glob",
)

APPLE_COMPILER_FLAGS = get_apple_compiler_flags()

rn_xplat_cxx_library(
name = "native",
srcs = glob(
["**/*.cpp"],
exclude = glob(["tests/**/*.cpp"]),
),
headers = glob(
["**/*.h"],
exclude = glob(["tests/**/*.h"]),
),
header_namespace = "",
exported_headers = subdir_glob(
[
("", "*.h"),
],
prefix = "react/renderer/componentregistry/native",
),
compiler_flags = [
"-fexceptions",
"-frtti",
"-std=c++14",
"-Wall",
],
fbobjc_compiler_flags = APPLE_COMPILER_FLAGS,
fbobjc_preprocessor_flags = get_preprocessor_flags_for_build_mode() + get_apple_inspector_flags(),
force_static = True,
labels = ["supermodule:xplat/default/public.react_native.infra"],
macosx_tests_override = [],
platforms = (ANDROID, APPLE, CXX),
preprocessor_flags = [
"-DLOG_TAG=\"ReactNative\"",
"-DWITH_FBSYSTRACE=1",
],
visibility = ["PUBLIC"],
deps = [
"//third-party/glog:glog",
"//xplat/fbsystrace:fbsystrace",
"//xplat/folly:headers_only",
"//xplat/folly:memory",
"//xplat/folly:molly",
"//xplat/jsi:JSIDynamic",
"//xplat/jsi:jsi",
],
)

0 comments on commit fca0442

Please sign in to comment.