mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Refactor CXX Component classes
Summary: This diff is moving all relevant cxx component classes out of react-native-github, this is necessary to make it easy to iterate on their APIs We will move them back again to OSS once we make the API stable changelog: [internal] internal Reviewed By: arhelmus Differential Revision: D42018363 fbshipit-source-id: bacf0c667e2e8df57b4b57e257bf937586b8e6f7
This commit is contained in:
committed by
Facebook GitHub Bot
parent
e193d1c08c
commit
b71b43abbf
@@ -121,10 +121,7 @@ final def preparePrefab = tasks.register("preparePrefab", PreparePrefabHeadersTa
|
||||
),
|
||||
new PrefabPreprocessingEntry(
|
||||
"fabricjni",
|
||||
[
|
||||
new Pair("src/main/jni/react/fabric", "react/fabric/"),
|
||||
new Pair("src/main/jni/react/cxxcomponents", "react/cxxcomponents/")
|
||||
]
|
||||
new Pair("src/main/jni/react/fabric", "react/fabric/")
|
||||
),
|
||||
new PrefabPreprocessingEntry(
|
||||
"react_render_mapbuffer",
|
||||
|
||||
@@ -102,7 +102,6 @@ add_react_build_subdir(generated/source/codegen/jni)
|
||||
add_react_android_subdir(src/main/jni/first-party/fb)
|
||||
add_react_android_subdir(src/main/jni/first-party/fbgloginit)
|
||||
add_react_android_subdir(src/main/jni/first-party/yogajni)
|
||||
add_react_android_subdir(src/main/jni/react/cxxcomponents)
|
||||
add_react_android_subdir(src/main/jni/react/jni)
|
||||
add_react_android_subdir(src/main/jni/react/reactperflogger)
|
||||
add_react_android_subdir(src/main/jni/react/jscexecutor)
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
load(
|
||||
"//tools/build_defs/oss:rn_defs.bzl",
|
||||
"ANDROID",
|
||||
"APPLE",
|
||||
"CXX",
|
||||
"react_native_xplat_target",
|
||||
"rn_xplat_cxx_library",
|
||||
"subdir_glob",
|
||||
)
|
||||
|
||||
rn_xplat_cxx_library(
|
||||
name = "components",
|
||||
srcs = glob(
|
||||
["**/*.cpp"],
|
||||
),
|
||||
headers = glob(
|
||||
["**/*.h"],
|
||||
),
|
||||
header_namespace = "",
|
||||
exported_headers = subdir_glob(
|
||||
[
|
||||
("", "**/*.h"),
|
||||
],
|
||||
prefix = "react/cxxcomponents",
|
||||
),
|
||||
force_static = True,
|
||||
labels = [
|
||||
"pfh:ReactNative_CommonInfrastructurePlaceholder",
|
||||
],
|
||||
platforms = (APPLE, ANDROID, CXX),
|
||||
preprocessor_flags = [
|
||||
"-DLOG_TAG=\"ReactNative\"",
|
||||
"-DWITH_FBSYSTRACE=1",
|
||||
],
|
||||
soname = "libcxxcomponents.$(ext)",
|
||||
visibility = ["PUBLIC"],
|
||||
deps = [
|
||||
"//third-party/glog:glog",
|
||||
"//xplat/fbsystrace:fbsystrace",
|
||||
"//xplat/folly:memory",
|
||||
"//xplat/folly:molly",
|
||||
react_native_xplat_target("react/renderer/core:core"),
|
||||
],
|
||||
)
|
||||
@@ -1,22 +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
|
||||
-Wpedantic
|
||||
-Wno-gnu-zero-variadic-macro-arguments)
|
||||
|
||||
file(GLOB_RECURSE cxxcomponents_SRC CONFIGURE_DEPENDS *.cpp *.h)
|
||||
|
||||
add_library(cxxcomponents SHARED ${cxxcomponents_SRC})
|
||||
|
||||
target_include_directories(cxxcomponents PUBLIC .)
|
||||
set_target_properties(cxxcomponents PROPERTIES LINKER_LANGUAGE CXX)
|
||||
@@ -1,48 +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 <react/renderer/core/Props.h>
|
||||
#include <react/renderer/core/ReactPrimitives.h>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace facebook::react {
|
||||
|
||||
class Component {
|
||||
public:
|
||||
Component(Tag tag) : tag_(tag) {}
|
||||
|
||||
virtual ~Component() = default;
|
||||
|
||||
// Updates the prop with name and float value received as a parameter in the
|
||||
// component
|
||||
virtual void updateFloatProp(const std::string &propName, float value){};
|
||||
|
||||
// Updates the prop with name and string value received as a parameter in the
|
||||
// component
|
||||
virtual void updateStringProp(
|
||||
const std::string &propName,
|
||||
const std::string &value){};
|
||||
|
||||
// Mounts the child component into the children index received as parameter
|
||||
virtual void mountChildComponent(
|
||||
std::shared_ptr<facebook::react::Component> component,
|
||||
int index) = 0;
|
||||
|
||||
// Unmounts the child component from the index received as a parameter
|
||||
virtual void unmountChildComponent(int index) = 0;
|
||||
|
||||
// Draw the component
|
||||
virtual void draw() = 0;
|
||||
|
||||
protected:
|
||||
Tag tag_ = -1;
|
||||
};
|
||||
|
||||
} // namespace facebook::react
|
||||
@@ -1,24 +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 <react/cxxcomponents/Component.h>
|
||||
#include <react/renderer/core/Props.h>
|
||||
|
||||
namespace facebook::react {
|
||||
|
||||
class ComponentManager {
|
||||
public:
|
||||
ComponentManager() {}
|
||||
|
||||
virtual std::shared_ptr<Component> createComponent(Tag tag) = 0;
|
||||
|
||||
virtual ~ComponentManager() = default;
|
||||
};
|
||||
|
||||
} // namespace facebook::react
|
||||
@@ -34,7 +34,6 @@ rn_xplat_cxx_library(
|
||||
react_native_xplat_target("react/renderer/componentregistry:componentregistry"),
|
||||
react_native_xplat_target("react/renderer/components/scrollview:scrollview"),
|
||||
react_native_xplat_target("runtimeexecutor:runtimeexecutor"),
|
||||
"//xplat/js/react-native-github/ReactAndroid/src/main/jni/react/cxxcomponents:components",
|
||||
react_native_target("jni/react/jni:jni"),
|
||||
"//xplat/fbsystrace:fbsystrace",
|
||||
"//xplat/jsi:JSIDynamic",
|
||||
|
||||
@@ -18,7 +18,6 @@ target_include_directories(fabricjni PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
target_link_libraries(
|
||||
fabricjni
|
||||
butter
|
||||
cxxcomponents
|
||||
fb
|
||||
fbjni
|
||||
folly_runtime
|
||||
|
||||
@@ -1,41 +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 "ComponentRegistryResolver.h"
|
||||
|
||||
#include <android/log.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
void ComponentRegistryResolver::addComponentManager(
|
||||
std::string name,
|
||||
bool isRootComponent,
|
||||
std::function<std::shared_ptr<facebook::react::ComponentManager>(
|
||||
const std::string &name)> f) {
|
||||
ComponentResolverData data = {isRootComponent, std::move(f)};
|
||||
resolverMap_.insert({name, data});
|
||||
}
|
||||
|
||||
bool ComponentRegistryResolver::containsComponentManager(
|
||||
std::string componentName) const {
|
||||
return resolverMap_.contains(componentName);
|
||||
}
|
||||
|
||||
std::shared_ptr<facebook::react::ComponentManager>
|
||||
ComponentRegistryResolver::getComponentManager(
|
||||
std::string componentName) const {
|
||||
auto iterator = resolverMap_.find(componentName);
|
||||
if (iterator != resolverMap_.end()) {
|
||||
return iterator->second.getComponentManagerFunction(componentName);
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
@@ -1,45 +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 <fbjni/fbjni.h>
|
||||
#include <react/cxxcomponents/ComponentManager.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
struct ComponentResolverData {
|
||||
bool isRootComponent;
|
||||
std::function<std::shared_ptr<facebook::react::ComponentManager>(
|
||||
const std::string &name)>
|
||||
getComponentManagerFunction;
|
||||
};
|
||||
|
||||
using ComponentResolverMap = butter::map<std::string, ComponentResolverData>;
|
||||
|
||||
class ComponentRegistryResolver {
|
||||
public:
|
||||
ComponentRegistryResolver(){};
|
||||
|
||||
void addComponentManager(
|
||||
std::string name,
|
||||
bool isRootComponent,
|
||||
std::function<std::shared_ptr<facebook::react::ComponentManager>(
|
||||
const std::string &name)> f);
|
||||
|
||||
bool containsComponentManager(std::string componentName) const;
|
||||
|
||||
std::shared_ptr<facebook::react::ComponentManager> getComponentManager(
|
||||
std::string name) const;
|
||||
|
||||
private:
|
||||
butter::map<std::string, ComponentResolverData> resolverMap_{};
|
||||
};
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
@@ -1,46 +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 "CppComponentRegistry.h"
|
||||
#include <fbjni/fbjni.h>
|
||||
#include <jsi/jsi.h>
|
||||
#include <react/renderer/componentregistry/ComponentDescriptorRegistry.h>
|
||||
|
||||
using namespace facebook::jsi;
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
jni::local_ref<CppComponentRegistry::jhybriddata>
|
||||
CppComponentRegistry::initHybrid(jni::alias_ref<jclass>) {
|
||||
return makeCxxInstance();
|
||||
}
|
||||
|
||||
void CppComponentRegistry::registerNatives() {
|
||||
registerHybrid(
|
||||
{makeNativeMethod("initHybrid", CppComponentRegistry::initHybrid)});
|
||||
}
|
||||
|
||||
void CppComponentRegistry::addComponentManager(
|
||||
std::string name,
|
||||
bool isRootComponent,
|
||||
std::function<std::shared_ptr<facebook::react::ComponentManager>(
|
||||
const std::string &name)> f) {
|
||||
componentManagerResolver_.addComponentManager(name, isRootComponent, f);
|
||||
}
|
||||
|
||||
bool CppComponentRegistry::containsComponentManager(std::string name) const {
|
||||
return componentManagerResolver_.containsComponentManager(name);
|
||||
}
|
||||
|
||||
std::shared_ptr<facebook::react::ComponentManager>
|
||||
CppComponentRegistry::getComponentManager(const std::string &name) const {
|
||||
return componentManagerResolver_.getComponentManager(name);
|
||||
}
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
@@ -1,49 +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 <fbjni/fbjni.h>
|
||||
#include <glog/logging.h>
|
||||
#include <jsi/jsi.h>
|
||||
#include <react/utils/ContextContainer.h>
|
||||
#include <mutex>
|
||||
#include <unordered_set>
|
||||
|
||||
#include <react/cxxcomponents/ComponentManager.h>
|
||||
#include <react/fabric/ComponentRegistryResolver.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
class Instance;
|
||||
|
||||
class CppComponentRegistry : public jni::HybridClass<CppComponentRegistry> {
|
||||
public:
|
||||
constexpr static const char *const kJavaDescriptor =
|
||||
"Lcom/facebook/react/fabric/CppComponentRegistry;";
|
||||
|
||||
static void registerNatives();
|
||||
|
||||
void addComponentManager(
|
||||
std::string name,
|
||||
bool isRootComponent,
|
||||
std::function<std::shared_ptr<facebook::react::ComponentManager>(
|
||||
const std::string &name)> f);
|
||||
|
||||
bool containsComponentManager(std::string name) const;
|
||||
|
||||
std::shared_ptr<facebook::react::ComponentManager> getComponentManager(
|
||||
const std::string &name) const;
|
||||
|
||||
private:
|
||||
static jni::local_ref<jhybriddata> initHybrid(jni::alias_ref<jclass>);
|
||||
ComponentRegistryResolver componentManagerResolver_{};
|
||||
};
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
Reference in New Issue
Block a user