Skip to content

Commit d91a3d4

Browse files
NickGerlemanfacebook-github-bot
authored andcommitted
Platform specific headers for PargraphState
Summary: With Facsimile, we are introducing some new concept of `PreparedText`, where platform TextLayoutManager which implement, can lead to additional optimizations. `#ifdef ANDROID` is not a workable pattern for this. Apart from react-native-cxx getting hooked into it, and all of the existing bugs there, it is bad for editor environment, and hard to reason about. This splits up `ParagraphState`, so that we can control platform specific bits more easily. We do not split `ParagraphShadowNode`, which will use concepts (e.g. `TextLayoutManagerWithPreparedText`) to control which paths it takes, based on platform capaibilities. Changelog: [internal] Differential Revision: D73555441
1 parent 15bdf41 commit d91a3d4

File tree

5 files changed

+64
-20
lines changed

5 files changed

+64
-20
lines changed

packages/react-native/ReactCommon/React-FabricComponents.podspec

+3-2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Pod::Spec.new do |s|
3030
header_search_path = header_search_path + [
3131
"\"$(PODS_TARGET_SRCROOT)/react/renderer/textlayoutmanager/platform/ios\"",
3232
"\"$(PODS_TARGET_SRCROOT)/react/renderer/components/textinput/platform/ios\"",
33+
"\"$(PODS_TARGET_SRCROOT)/react/renderer/components/text/platform/cxx\"",
3334
"\"$(PODS_TARGET_SRCROOT)/react/renderer/components/view/platform/cxx\"",
3435
]
3536
end
@@ -111,8 +112,8 @@ Pod::Spec.new do |s|
111112
end
112113

113114
ss.subspec "text" do |sss|
114-
sss.source_files = "react/renderer/components/text/**/*.{m,mm,cpp,h}"
115-
sss.exclude_files = "react/renderer/components/text/tests"
115+
sss.source_files = "react/renderer/components/text/*.{m,mm,cpp,h}",
116+
"react/renderer/components/text/platform/cxx/**/*.{m,mm,cpp,h}"
116117
sss.header_dir = "react/renderer/components/text"
117118

118119
end

packages/react-native/ReactCommon/react/renderer/components/text/CMakeLists.txt

+10-2
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,18 @@ set(CMAKE_VERBOSE_MAKEFILE on)
88

99
include(${REACT_COMMON_DIR}/cmake-utils/react-native-flags.cmake)
1010

11-
file(GLOB rrc_text_SRC CONFIGURE_DEPENDS *.cpp)
11+
file(GLOB rrc_text_SRC CONFIGURE_DEPENDS
12+
*.cpp
13+
platform/android/react/renderer/components/text/*.cpp)
14+
1215
add_library(rrc_text OBJECT ${rrc_text_SRC})
1316

14-
target_include_directories(rrc_text PUBLIC ${REACT_COMMON_DIR})
17+
target_include_directories(rrc_text PUBLIC
18+
${REACT_COMMON_DIR}
19+
${CMAKE_CURRENT_SOURCE_DIR}/platform/android/)
20+
21+
target_include_directories(rrc_text PRIVATE
22+
${CMAKE_CURRENT_SOURCE_DIR}/platform/android/react/renderer/components/text/)
1523

1624
target_link_libraries(rrc_text
1725
glog

packages/react-native/ReactCommon/react/renderer/components/text/ParagraphState.cpp renamed to packages/react-native/ReactCommon/react/renderer/components/text/platform/android/react/renderer/components/text/ParagraphState.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,12 @@
1212

1313
namespace facebook::react {
1414

15-
#ifdef ANDROID
1615
folly::dynamic ParagraphState::getDynamic() const {
1716
LOG(FATAL) << "ParagraphState may only be serialized to MapBuffer";
1817
}
1918

2019
MapBuffer ParagraphState::getMapBuffer() const {
2120
return toMapBuffer(*this);
2221
}
23-
#endif
2422

2523
} // namespace facebook::react

packages/react-native/ReactCommon/react/renderer/components/text/ParagraphState.h renamed to packages/react-native/ReactCommon/react/renderer/components/text/platform/android/react/renderer/components/text/ParagraphState.h

+9-14
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,19 @@
1212
#include <react/renderer/attributedstring/ParagraphAttributes.h>
1313
#include <react/renderer/textlayoutmanager/TextLayoutManager.h>
1414

15-
#ifdef ANDROID
1615
#include <folly/dynamic.h>
1716
#include <react/renderer/mapbuffer/MapBuffer.h>
18-
#endif
17+
18+
#include <utility>
1919

2020
namespace facebook::react {
2121

22-
#ifdef ANDROID
2322
// constants for Text State serialization
2423
constexpr static MapBuffer::Key TX_STATE_KEY_ATTRIBUTED_STRING = 0;
2524
constexpr static MapBuffer::Key TX_STATE_KEY_PARAGRAPH_ATTRIBUTES = 1;
2625
// Used for TextInput only
2726
constexpr static MapBuffer::Key TX_STATE_KEY_HASH = 2;
2827
constexpr static MapBuffer::Key TX_STATE_KEY_MOST_RECENT_EVENT_COUNT = 3;
29-
#endif
3028

3129
/*
3230
* State for <Paragraph> component.
@@ -49,28 +47,25 @@ class ParagraphState final {
4947
* `TextLayoutManager` provides a connection to platform-specific
5048
* text rendering infrastructure which is capable to render the
5149
* `AttributedString`.
52-
* This is not on every platform. This is not used on Android, but is
53-
* used on the iOS mounting layer.
5450
*/
5551
std::weak_ptr<const TextLayoutManager> layoutManager;
5652

57-
#ifdef ANDROID
5853
ParagraphState(
59-
const AttributedString& attributedString,
60-
const ParagraphAttributes& paragraphAttributes,
54+
AttributedString attributedString,
55+
ParagraphAttributes paragraphAttributes,
6156
const std::weak_ptr<const TextLayoutManager>& layoutManager)
62-
: attributedString(attributedString),
63-
paragraphAttributes(paragraphAttributes),
57+
: attributedString(std::move(attributedString)),
58+
paragraphAttributes(std::move(paragraphAttributes)),
6459
layoutManager(layoutManager) {}
6560
ParagraphState() = default;
6661
ParagraphState(
67-
const ParagraphState& previousState,
68-
const folly::dynamic& data) {
62+
const ParagraphState& /*previousState*/,
63+
const folly::dynamic& /*data*/) {
6964
react_native_assert(false && "Not supported");
7065
};
66+
7167
folly::dynamic getDynamic() const;
7268
MapBuffer getMapBuffer() const;
73-
#endif
7469
};
7570

7671
} // namespace facebook::react
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#pragma once
9+
10+
#include <react/debug/react_native_assert.h>
11+
#include <react/renderer/attributedstring/AttributedString.h>
12+
#include <react/renderer/attributedstring/ParagraphAttributes.h>
13+
#include <react/renderer/textlayoutmanager/TextLayoutManager.h>
14+
15+
namespace facebook::react {
16+
17+
/*
18+
* State for <Paragraph> component.
19+
* Represents what to render and how to render.
20+
*/
21+
class ParagraphState final {
22+
public:
23+
/*
24+
* All content of <Paragraph> component represented as an `AttributedString`.
25+
*/
26+
AttributedString attributedString;
27+
28+
/*
29+
* Represents all visual attributes of a paragraph of text represented as
30+
* a ParagraphAttributes.
31+
*/
32+
ParagraphAttributes paragraphAttributes;
33+
34+
/*
35+
* `TextLayoutManager` provides a connection to platform-specific
36+
* text rendering infrastructure which is capable to render the
37+
* `AttributedString`.
38+
*/
39+
std::weak_ptr<const TextLayoutManager> layoutManager;
40+
};
41+
42+
} // namespace facebook::react

0 commit comments

Comments
 (0)