diff --git a/packages/react-native/React/React-RCTFabric.podspec b/packages/react-native/React/React-RCTFabric.podspec index ee49b6f2098..ea8c3f5e545 100644 --- a/packages/react-native/React/React-RCTFabric.podspec +++ b/packages/react-native/React/React-RCTFabric.podspec @@ -71,6 +71,7 @@ Pod::Spec.new do |s| ]) add_dependency(s, "React-FabricComponents", :additional_framework_paths => [ "react/renderer/textlayoutmanager/platform/ios", + "react/renderer/components/text/platform/cxx", "react/renderer/components/textinput/platform/ios", ]); diff --git a/packages/react-native/ReactCommon/React-Fabric.podspec b/packages/react-native/ReactCommon/React-Fabric.podspec index 0015b7d5ec4..ea5b902d163 100644 --- a/packages/react-native/ReactCommon/React-Fabric.podspec +++ b/packages/react-native/ReactCommon/React-Fabric.podspec @@ -78,6 +78,7 @@ Pod::Spec.new do |s| if ENV['USE_FRAMEWORKS'] header_search_path = header_search_path + [ "\"$(PODS_TARGET_SRCROOT)/react/renderer/textlayoutmanager/platform/ios\"", + "\"$(PODS_TARGET_SRCROOT)/react/renderer/components/text/platform/cxx\"", "\"$(PODS_TARGET_SRCROOT)/react/renderer/components/textinput/platform/ios\"", "\"$(PODS_TARGET_SRCROOT)/react/renderer/components/view/platform/cxx\"", ] diff --git a/packages/react-native/ReactCommon/React-FabricComponents.podspec b/packages/react-native/ReactCommon/React-FabricComponents.podspec index 392693894d7..a1da066e4bf 100644 --- a/packages/react-native/ReactCommon/React-FabricComponents.podspec +++ b/packages/react-native/ReactCommon/React-FabricComponents.podspec @@ -30,6 +30,7 @@ Pod::Spec.new do |s| header_search_path = header_search_path + [ "\"$(PODS_TARGET_SRCROOT)/react/renderer/textlayoutmanager/platform/ios\"", "\"$(PODS_TARGET_SRCROOT)/react/renderer/components/textinput/platform/ios\"", + "\"$(PODS_TARGET_SRCROOT)/react/renderer/components/text/platform/cxx\"", "\"$(PODS_TARGET_SRCROOT)/react/renderer/components/view/platform/cxx\"", ] end @@ -111,8 +112,8 @@ Pod::Spec.new do |s| end ss.subspec "text" do |sss| - sss.source_files = "react/renderer/components/text/**/*.{m,mm,cpp,h}" - sss.exclude_files = "react/renderer/components/text/tests" + sss.source_files = "react/renderer/components/text/*.{m,mm,cpp,h}", + "react/renderer/components/text/platform/cxx/**/*.{m,mm,cpp,h}" sss.header_dir = "react/renderer/components/text" end diff --git a/packages/react-native/ReactCommon/React-FabricImage.podspec b/packages/react-native/ReactCommon/React-FabricImage.podspec index cb71d7a2eee..610a9a7ad2e 100644 --- a/packages/react-native/ReactCommon/React-FabricImage.podspec +++ b/packages/react-native/ReactCommon/React-FabricImage.podspec @@ -27,6 +27,7 @@ if ENV['USE_FRAMEWORKS'] header_search_path = header_search_path + [ "\"$(PODS_TARGET_SRCROOT)\"", "\"$(PODS_TARGET_SRCROOT)/react/renderer/textlayoutmanager/platform/ios\"", + "\"$(PODS_TARGET_SRCROOT)/react/renderer/components/text/platform/cxx\"", "\"$(PODS_TARGET_SRCROOT)/react/renderer/components/textinput/platform/ios\"", # "\"$(PODS_CONFIGURATION_BUILD_DIR)/ReactCodegen/ReactCodegen.framework/Headers\"", ] diff --git a/packages/react-native/ReactCommon/react/renderer/components/text/CMakeLists.txt b/packages/react-native/ReactCommon/react/renderer/components/text/CMakeLists.txt index 1ad6066ea35..506d781264c 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/text/CMakeLists.txt +++ b/packages/react-native/ReactCommon/react/renderer/components/text/CMakeLists.txt @@ -8,10 +8,18 @@ set(CMAKE_VERBOSE_MAKEFILE on) include(${REACT_COMMON_DIR}/cmake-utils/react-native-flags.cmake) -file(GLOB rrc_text_SRC CONFIGURE_DEPENDS *.cpp) +file(GLOB rrc_text_SRC CONFIGURE_DEPENDS + *.cpp + platform/android/react/renderer/components/text/*.cpp) + add_library(rrc_text OBJECT ${rrc_text_SRC}) -target_include_directories(rrc_text PUBLIC ${REACT_COMMON_DIR}) +target_include_directories(rrc_text PUBLIC + ${REACT_COMMON_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/platform/android/) + +target_include_directories(rrc_text PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/platform/android/react/renderer/components/text/) target_link_libraries(rrc_text glog diff --git a/packages/react-native/ReactCommon/react/renderer/components/text/ParagraphState.cpp b/packages/react-native/ReactCommon/react/renderer/components/text/platform/android/react/renderer/components/text/ParagraphState.cpp similarity index 96% rename from packages/react-native/ReactCommon/react/renderer/components/text/ParagraphState.cpp rename to packages/react-native/ReactCommon/react/renderer/components/text/platform/android/react/renderer/components/text/ParagraphState.cpp index 63b4fb45873..eacc4b27c91 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/text/ParagraphState.cpp +++ b/packages/react-native/ReactCommon/react/renderer/components/text/platform/android/react/renderer/components/text/ParagraphState.cpp @@ -12,7 +12,6 @@ namespace facebook::react { -#ifdef ANDROID folly::dynamic ParagraphState::getDynamic() const { LOG(FATAL) << "ParagraphState may only be serialized to MapBuffer"; } @@ -20,6 +19,5 @@ folly::dynamic ParagraphState::getDynamic() const { MapBuffer ParagraphState::getMapBuffer() const { return toMapBuffer(*this); } -#endif } // namespace facebook::react diff --git a/packages/react-native/ReactCommon/react/renderer/components/text/ParagraphState.h b/packages/react-native/ReactCommon/react/renderer/components/text/platform/android/react/renderer/components/text/ParagraphState.h similarity index 80% rename from packages/react-native/ReactCommon/react/renderer/components/text/ParagraphState.h rename to packages/react-native/ReactCommon/react/renderer/components/text/platform/android/react/renderer/components/text/ParagraphState.h index f80448ed25a..ec720b5c67d 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/text/ParagraphState.h +++ b/packages/react-native/ReactCommon/react/renderer/components/text/platform/android/react/renderer/components/text/ParagraphState.h @@ -12,21 +12,19 @@ #include #include -#ifdef ANDROID #include #include -#endif + +#include namespace facebook::react { -#ifdef ANDROID // constants for Text State serialization constexpr static MapBuffer::Key TX_STATE_KEY_ATTRIBUTED_STRING = 0; constexpr static MapBuffer::Key TX_STATE_KEY_PARAGRAPH_ATTRIBUTES = 1; // Used for TextInput only constexpr static MapBuffer::Key TX_STATE_KEY_HASH = 2; constexpr static MapBuffer::Key TX_STATE_KEY_MOST_RECENT_EVENT_COUNT = 3; -#endif /* * State for component. @@ -49,28 +47,25 @@ class ParagraphState final { * `TextLayoutManager` provides a connection to platform-specific * text rendering infrastructure which is capable to render the * `AttributedString`. - * This is not on every platform. This is not used on Android, but is - * used on the iOS mounting layer. */ std::weak_ptr layoutManager; -#ifdef ANDROID ParagraphState( - const AttributedString& attributedString, - const ParagraphAttributes& paragraphAttributes, + AttributedString attributedString, + ParagraphAttributes paragraphAttributes, const std::weak_ptr& layoutManager) - : attributedString(attributedString), - paragraphAttributes(paragraphAttributes), + : attributedString(std::move(attributedString)), + paragraphAttributes(std::move(paragraphAttributes)), layoutManager(layoutManager) {} ParagraphState() = default; ParagraphState( - const ParagraphState& previousState, - const folly::dynamic& data) { + const ParagraphState& /*previousState*/, + const folly::dynamic& /*data*/) { react_native_assert(false && "Not supported"); }; + folly::dynamic getDynamic() const; MapBuffer getMapBuffer() const; -#endif }; } // namespace facebook::react diff --git a/packages/react-native/ReactCommon/react/renderer/components/text/platform/cxx/react/renderer/components/text/ParagraphState.h b/packages/react-native/ReactCommon/react/renderer/components/text/platform/cxx/react/renderer/components/text/ParagraphState.h new file mode 100644 index 00000000000..9d0fa0dae8a --- /dev/null +++ b/packages/react-native/ReactCommon/react/renderer/components/text/platform/cxx/react/renderer/components/text/ParagraphState.h @@ -0,0 +1,42 @@ +/* + * 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 { + +/* + * State for component. + * Represents what to render and how to render. + */ +class ParagraphState final { + public: + /* + * All content of component represented as an `AttributedString`. + */ + AttributedString attributedString; + + /* + * Represents all visual attributes of a paragraph of text represented as + * a ParagraphAttributes. + */ + ParagraphAttributes paragraphAttributes; + + /* + * `TextLayoutManager` provides a connection to platform-specific + * text rendering infrastructure which is capable to render the + * `AttributedString`. + */ + std::weak_ptr layoutManager; +}; + +} // namespace facebook::react