mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Do not store .cpp/.h files inside src/main/java - uimanager
Summary: Currently we expose native code (.h, .cpp) inside the src/main/java folder. This is making impossible for users on New Architecture to open the project inside Android Studio. The problem is that the src/main/java is reserved to Java/Kotlin sources only. AGP 7.2 also removed support for mixed source roots: https://developer.android.com/studio/releases/gradle-plugin#duplicate-content-roots This is essentially forcing users to write Java code without any autocompletion as all the React Native Java classes are considered C++ files. I'm addressing this issue folder by folder by moving them from ReactAndroid/src/main/java/com/facebook/... to ReactAndroid/src/main/jni/react/... This is the diff for uimanager Changelog: [Internal] [Changed] - Do not store .cpp/.h files inside src/main/java - uimanager Reviewed By: dmitryrykun Differential Revision: D38656400 fbshipit-source-id: f52487160fa6c05ec382842e2a6125a5c4cb1e86
This commit is contained in:
committed by
Facebook GitHub Bot
parent
b6aff1f1d1
commit
1246300e93
@@ -76,7 +76,6 @@ rn_android_library(
|
||||
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/common/mapbuffer:mapbuffer"),
|
||||
react_native_target("java/com/facebook/react/config:config"),
|
||||
@@ -86,6 +85,7 @@ rn_android_library(
|
||||
react_native_target("java/com/facebook/react/touch:touch"),
|
||||
react_native_target("java/com/facebook/react/uimanager/annotations:annotations"),
|
||||
react_native_target("java/com/facebook/react/uimanager/util:util"),
|
||||
react_native_target("jni/react/uimanager:jni"),
|
||||
react_native_target("res:uimanager"),
|
||||
],
|
||||
exported_deps = [
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
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",
|
||||
),
|
||||
fbandroid_allow_jni_merging = True,
|
||||
labels = [
|
||||
"pfh:ReactNative_CommonInfrastructurePlaceholder",
|
||||
"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/jsi:JSIDynamic",
|
||||
"//xplat/jsi:jsi",
|
||||
"//xplat/third-party/linker_lib:atomic",
|
||||
FBJNI_TARGET,
|
||||
],
|
||||
)
|
||||
@@ -1,26 +0,0 @@
|
||||
# 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.
|
||||
|
||||
cmake_minimum_required(VERSION 3.13)
|
||||
set(CMAKE_VERBOSE_MAKEFILE on)
|
||||
|
||||
add_compile_options(-fexceptions -frtti -std=c++17 -Wall -DLOG_TAG=\"ReactNative\")
|
||||
|
||||
file(GLOB uimanagerjni_SRC CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
|
||||
add_library(uimanagerjni SHARED ${uimanagerjni_SRC})
|
||||
|
||||
target_include_directories(uimanagerjni PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
target_link_libraries(uimanagerjni
|
||||
fb
|
||||
fbjni
|
||||
folly_runtime
|
||||
glog
|
||||
glog_init
|
||||
rrc_native
|
||||
yoga
|
||||
callinvokerholder
|
||||
reactnativejni
|
||||
react_render_componentregistry)
|
||||
-77
@@ -1,77 +0,0 @@
|
||||
/*
|
||||
* 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 <string>
|
||||
|
||||
#include <fbjni/fbjni.h>
|
||||
#include <jsi/jsi.h>
|
||||
|
||||
#include "ComponentNameResolverManager.h"
|
||||
|
||||
#include <react/renderer/componentregistry/native/NativeComponentRegistryBinding.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
using namespace facebook::jni;
|
||||
|
||||
ComponentNameResolverManager::ComponentNameResolverManager(
|
||||
jni::alias_ref<ComponentNameResolverManager::javaobject> jThis,
|
||||
RuntimeExecutor runtimeExecutor,
|
||||
jni::alias_ref<jobject> componentNameResolver)
|
||||
: javaPart_(jni::make_global(jThis)),
|
||||
runtimeExecutor_(runtimeExecutor),
|
||||
componentNameResolver_(jni::make_global(componentNameResolver)) {}
|
||||
|
||||
jni::local_ref<ComponentNameResolverManager::jhybriddata>
|
||||
ComponentNameResolverManager::initHybrid(
|
||||
jni::alias_ref<jhybridobject> jThis,
|
||||
jni::alias_ref<JRuntimeExecutor::javaobject> runtimeExecutor,
|
||||
jni::alias_ref<jobject> componentNameResolver) {
|
||||
return makeCxxInstance(
|
||||
jThis, runtimeExecutor->cthis()->get(), componentNameResolver);
|
||||
}
|
||||
|
||||
void ComponentNameResolverManager::registerNatives() {
|
||||
registerHybrid({
|
||||
makeNativeMethod("initHybrid", ComponentNameResolverManager::initHybrid),
|
||||
makeNativeMethod(
|
||||
"installJSIBindings",
|
||||
ComponentNameResolverManager::installJSIBindings),
|
||||
});
|
||||
}
|
||||
|
||||
void ComponentNameResolverManager::installJSIBindings() {
|
||||
runtimeExecutor_([thizz = this](jsi::Runtime &runtime) {
|
||||
auto viewManagerProvider = [thizz](const std::string &name) -> bool {
|
||||
if (thizz->componentNames_.size() == 0) {
|
||||
static auto getComponentNames =
|
||||
jni::findClassStatic(ComponentNameResolverManager::
|
||||
ComponentNameResolverJavaDescriptor)
|
||||
->getMethod<jni::alias_ref<jtypeArray<jstring>>()>(
|
||||
"getComponentNames");
|
||||
|
||||
auto componentNamesJArray =
|
||||
getComponentNames(thizz->componentNameResolver_.get());
|
||||
auto len = componentNamesJArray->size();
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
jni::local_ref<jstring> elem = (*componentNamesJArray)[i];
|
||||
auto componentName = elem->toStdString();
|
||||
thizz->componentNames_.insert(componentName);
|
||||
}
|
||||
}
|
||||
|
||||
return thizz->componentNames_.find(name) != thizz->componentNames_.end();
|
||||
};
|
||||
|
||||
react::NativeComponentRegistryBinding::install(
|
||||
runtime, std::move(viewManagerProvider));
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
-54
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
* 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 <ReactCommon/CallInvokerHolder.h>
|
||||
#include <ReactCommon/RuntimeExecutor.h>
|
||||
#include <fbjni/fbjni.h>
|
||||
#include <react/jni/JRuntimeExecutor.h>
|
||||
#include <set>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
class ComponentNameResolverManager
|
||||
: public facebook::jni::HybridClass<ComponentNameResolverManager> {
|
||||
public:
|
||||
static auto constexpr kJavaDescriptor =
|
||||
"Lcom/facebook/react/uimanager/ComponentNameResolverManager;";
|
||||
|
||||
constexpr static auto ComponentNameResolverJavaDescriptor =
|
||||
"com/facebook/react/uimanager/ComponentNameResolver";
|
||||
|
||||
static facebook::jni::local_ref<jhybriddata> initHybrid(
|
||||
facebook::jni::alias_ref<jhybridobject> jThis,
|
||||
facebook::jni::alias_ref<JRuntimeExecutor::javaobject> runtimeExecutor,
|
||||
facebook::jni::alias_ref<jobject> componentNameResolver);
|
||||
|
||||
static void registerNatives();
|
||||
|
||||
private:
|
||||
friend HybridBase;
|
||||
facebook::jni::global_ref<ComponentNameResolverManager::javaobject> javaPart_;
|
||||
RuntimeExecutor runtimeExecutor_;
|
||||
|
||||
facebook::jni::global_ref<jobject> componentNameResolver_;
|
||||
|
||||
std::set<std::string> componentNames_;
|
||||
|
||||
void installJSIBindings();
|
||||
|
||||
explicit ComponentNameResolverManager(
|
||||
facebook::jni::alias_ref<ComponentNameResolverManager::jhybridobject>
|
||||
jThis,
|
||||
RuntimeExecutor runtimeExecutor,
|
||||
facebook::jni::alias_ref<jobject> componentNameResolver);
|
||||
};
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
@@ -1,16 +0,0 @@
|
||||
/*
|
||||
* 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 <fbjni/fbjni.h>
|
||||
|
||||
#include "ComponentNameResolverManager.h"
|
||||
|
||||
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *) {
|
||||
return facebook::jni::initialize(vm, [] {
|
||||
facebook::react::ComponentNameResolverManager::registerNatives();
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user