From b71b43abbf0252d61af507172fac284446d4174a Mon Sep 17 00:00:00 2001 From: David Vacca Date: Mon, 19 Dec 2022 01:35:40 -0800 Subject: [PATCH] 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 --- ReactAndroid/build.gradle | 5 +- ReactAndroid/src/main/jni/CMakeLists.txt | 1 - .../src/main/jni/react/cxxcomponents/BUCK | 44 ----------------- .../jni/react/cxxcomponents/CMakeLists.txt | 22 --------- .../main/jni/react/cxxcomponents/Component.h | 48 ------------------ .../react/cxxcomponents/ComponentManager.h | 24 --------- ReactAndroid/src/main/jni/react/fabric/BUCK | 1 - .../src/main/jni/react/fabric/CMakeLists.txt | 1 - .../fabric/ComponentRegistryResolver.cpp | 41 ---------------- .../react/fabric/ComponentRegistryResolver.h | 45 ----------------- .../jni/react/fabric/CppComponentRegistry.cpp | 46 ----------------- .../jni/react/fabric/CppComponentRegistry.h | 49 ------------------- 12 files changed, 1 insertion(+), 326 deletions(-) delete mode 100644 ReactAndroid/src/main/jni/react/cxxcomponents/BUCK delete mode 100644 ReactAndroid/src/main/jni/react/cxxcomponents/CMakeLists.txt delete mode 100644 ReactAndroid/src/main/jni/react/cxxcomponents/Component.h delete mode 100644 ReactAndroid/src/main/jni/react/cxxcomponents/ComponentManager.h delete mode 100644 ReactAndroid/src/main/jni/react/fabric/ComponentRegistryResolver.cpp delete mode 100644 ReactAndroid/src/main/jni/react/fabric/ComponentRegistryResolver.h delete mode 100644 ReactAndroid/src/main/jni/react/fabric/CppComponentRegistry.cpp delete mode 100644 ReactAndroid/src/main/jni/react/fabric/CppComponentRegistry.h diff --git a/ReactAndroid/build.gradle b/ReactAndroid/build.gradle index 35a9203f8bf..2f9e64bff5a 100644 --- a/ReactAndroid/build.gradle +++ b/ReactAndroid/build.gradle @@ -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", diff --git a/ReactAndroid/src/main/jni/CMakeLists.txt b/ReactAndroid/src/main/jni/CMakeLists.txt index 8dd054c16df..6d0789f930e 100644 --- a/ReactAndroid/src/main/jni/CMakeLists.txt +++ b/ReactAndroid/src/main/jni/CMakeLists.txt @@ -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) diff --git a/ReactAndroid/src/main/jni/react/cxxcomponents/BUCK b/ReactAndroid/src/main/jni/react/cxxcomponents/BUCK deleted file mode 100644 index 3c51f2f3f16..00000000000 --- a/ReactAndroid/src/main/jni/react/cxxcomponents/BUCK +++ /dev/null @@ -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"), - ], -) diff --git a/ReactAndroid/src/main/jni/react/cxxcomponents/CMakeLists.txt b/ReactAndroid/src/main/jni/react/cxxcomponents/CMakeLists.txt deleted file mode 100644 index b60af533acb..00000000000 --- a/ReactAndroid/src/main/jni/react/cxxcomponents/CMakeLists.txt +++ /dev/null @@ -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) diff --git a/ReactAndroid/src/main/jni/react/cxxcomponents/Component.h b/ReactAndroid/src/main/jni/react/cxxcomponents/Component.h deleted file mode 100644 index f0961a8b6a0..00000000000 --- a/ReactAndroid/src/main/jni/react/cxxcomponents/Component.h +++ /dev/null @@ -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 -#include -#include -#include - -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 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 diff --git a/ReactAndroid/src/main/jni/react/cxxcomponents/ComponentManager.h b/ReactAndroid/src/main/jni/react/cxxcomponents/ComponentManager.h deleted file mode 100644 index aae9290839a..00000000000 --- a/ReactAndroid/src/main/jni/react/cxxcomponents/ComponentManager.h +++ /dev/null @@ -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 -#include - -namespace facebook::react { - -class ComponentManager { - public: - ComponentManager() {} - - virtual std::shared_ptr createComponent(Tag tag) = 0; - - virtual ~ComponentManager() = default; -}; - -} // namespace facebook::react diff --git a/ReactAndroid/src/main/jni/react/fabric/BUCK b/ReactAndroid/src/main/jni/react/fabric/BUCK index b8e6516cb04..49de510dda3 100644 --- a/ReactAndroid/src/main/jni/react/fabric/BUCK +++ b/ReactAndroid/src/main/jni/react/fabric/BUCK @@ -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", diff --git a/ReactAndroid/src/main/jni/react/fabric/CMakeLists.txt b/ReactAndroid/src/main/jni/react/fabric/CMakeLists.txt index 920103e9cb8..c4d743cfa10 100644 --- a/ReactAndroid/src/main/jni/react/fabric/CMakeLists.txt +++ b/ReactAndroid/src/main/jni/react/fabric/CMakeLists.txt @@ -18,7 +18,6 @@ target_include_directories(fabricjni PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) target_link_libraries( fabricjni butter - cxxcomponents fb fbjni folly_runtime diff --git a/ReactAndroid/src/main/jni/react/fabric/ComponentRegistryResolver.cpp b/ReactAndroid/src/main/jni/react/fabric/ComponentRegistryResolver.cpp deleted file mode 100644 index b015943b248..00000000000 --- a/ReactAndroid/src/main/jni/react/fabric/ComponentRegistryResolver.cpp +++ /dev/null @@ -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 - -namespace facebook { -namespace react { - -void ComponentRegistryResolver::addComponentManager( - std::string name, - bool isRootComponent, - std::function( - 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 -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 diff --git a/ReactAndroid/src/main/jni/react/fabric/ComponentRegistryResolver.h b/ReactAndroid/src/main/jni/react/fabric/ComponentRegistryResolver.h deleted file mode 100644 index 662c7df9b2b..00000000000 --- a/ReactAndroid/src/main/jni/react/fabric/ComponentRegistryResolver.h +++ /dev/null @@ -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 -#include - -namespace facebook { -namespace react { - -struct ComponentResolverData { - bool isRootComponent; - std::function( - const std::string &name)> - getComponentManagerFunction; -}; - -using ComponentResolverMap = butter::map; - -class ComponentRegistryResolver { - public: - ComponentRegistryResolver(){}; - - void addComponentManager( - std::string name, - bool isRootComponent, - std::function( - const std::string &name)> f); - - bool containsComponentManager(std::string componentName) const; - - std::shared_ptr getComponentManager( - std::string name) const; - - private: - butter::map resolverMap_{}; -}; - -} // namespace react -} // namespace facebook diff --git a/ReactAndroid/src/main/jni/react/fabric/CppComponentRegistry.cpp b/ReactAndroid/src/main/jni/react/fabric/CppComponentRegistry.cpp deleted file mode 100644 index 35d3d5e3479..00000000000 --- a/ReactAndroid/src/main/jni/react/fabric/CppComponentRegistry.cpp +++ /dev/null @@ -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 -#include -#include - -using namespace facebook::jsi; - -namespace facebook { -namespace react { - -jni::local_ref -CppComponentRegistry::initHybrid(jni::alias_ref) { - return makeCxxInstance(); -} - -void CppComponentRegistry::registerNatives() { - registerHybrid( - {makeNativeMethod("initHybrid", CppComponentRegistry::initHybrid)}); -} - -void CppComponentRegistry::addComponentManager( - std::string name, - bool isRootComponent, - std::function( - const std::string &name)> f) { - componentManagerResolver_.addComponentManager(name, isRootComponent, f); -} - -bool CppComponentRegistry::containsComponentManager(std::string name) const { - return componentManagerResolver_.containsComponentManager(name); -} - -std::shared_ptr -CppComponentRegistry::getComponentManager(const std::string &name) const { - return componentManagerResolver_.getComponentManager(name); -} - -} // namespace react -} // namespace facebook diff --git a/ReactAndroid/src/main/jni/react/fabric/CppComponentRegistry.h b/ReactAndroid/src/main/jni/react/fabric/CppComponentRegistry.h deleted file mode 100644 index c5f84996351..00000000000 --- a/ReactAndroid/src/main/jni/react/fabric/CppComponentRegistry.h +++ /dev/null @@ -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 -#include -#include -#include -#include -#include - -#include -#include - -namespace facebook { -namespace react { - -class Instance; - -class CppComponentRegistry : public jni::HybridClass { - public: - constexpr static const char *const kJavaDescriptor = - "Lcom/facebook/react/fabric/CppComponentRegistry;"; - - static void registerNatives(); - - void addComponentManager( - std::string name, - bool isRootComponent, - std::function( - const std::string &name)> f); - - bool containsComponentManager(std::string name) const; - - std::shared_ptr getComponentManager( - const std::string &name) const; - - private: - static jni::local_ref initHybrid(jni::alias_ref); - ComponentRegistryResolver componentManagerResolver_{}; -}; - -} // namespace react -} // namespace facebook