Skip to content

Commit da8dc9a

Browse files
committed
feat: support rn77
1 parent cd598e8 commit da8dc9a

4 files changed

Lines changed: 40 additions & 29 deletions

File tree

cpp/react/renderer/components/JBAnimatedText/BaseTextShadowNode.cpp

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,29 +38,37 @@ void CBaseTextShadowNode::buildAttributedString( // EDITED
3838
auto fragment = AttributedString::Fragment{};
3939
fragment.string = paragraphParentNode->getConcreteProps().text;
4040
fragment.textAttributes = baseTextAttributes;
41-
outAttributedString.appendFragment(fragment);
41+
outAttributedString.appendFragment(std::move(fragment));
4242
return;
4343
}
4444
// END ADDED
45-
45+
bool lastFragmentWasRawText = false;
4646
for (const auto& childNode : parentNode.getChildren()) {
4747
// RawShadowNode
4848
auto rawTextShadowNode =
4949
dynamic_cast<const RawTextShadowNode*>(childNode.get());
5050
if (rawTextShadowNode != nullptr) {
51-
auto fragment = AttributedString::Fragment{};
52-
fragment.string = rawTextShadowNode->getConcreteProps().text;
53-
fragment.textAttributes = baseTextAttributes;
51+
const auto& rawText = rawTextShadowNode->getConcreteProps().text;
52+
if (lastFragmentWasRawText) {
53+
outAttributedString.getFragments().back().string += rawText;
54+
} else {
55+
auto fragment = AttributedString::Fragment{};
56+
fragment.string = rawText;
57+
fragment.textAttributes = baseTextAttributes;
5458

55-
// Storing a retaining pointer to `ParagraphShadowNode` inside
56-
// `attributedString` causes a retain cycle (besides that fact that we
57-
// don't need it at all). Storing a `ShadowView` instance instead of
58-
// `ShadowNode` should properly fix this problem.
59-
fragment.parentShadowView = shadowViewFromShadowNode(parentNode);
60-
outAttributedString.appendFragment(fragment);
59+
// Storing a retaining pointer to `ParagraphShadowNode` inside
60+
// `attributedString` causes a retain cycle (besides that fact that we
61+
// don't need it at all). Storing a `ShadowView` instance instead of
62+
// `ShadowNode` should properly fix this problem.
63+
fragment.parentShadowView = shadowViewFromShadowNode(parentNode);
64+
outAttributedString.appendFragment(std::move(fragment));
65+
lastFragmentWasRawText = true;
66+
}
6167
continue;
6268
}
6369

70+
lastFragmentWasRawText = false;
71+
6472
// TextShadowNode
6573
auto textShadowNode = dynamic_cast<const TextShadowNode*>(childNode.get());
6674
if (textShadowNode != nullptr) {
@@ -80,7 +88,7 @@ void CBaseTextShadowNode::buildAttributedString( // EDITED
8088
fragment.string = AttributedString::Fragment::AttachmentCharacter();
8189
fragment.parentShadowView = shadowViewFromShadowNode(*childNode);
8290
fragment.textAttributes = baseTextAttributes;
83-
outAttributedString.appendFragment(fragment);
91+
outAttributedString.appendFragment(std::move(fragment));
8492
outAttachments.push_back(Attachment{
8593
childNode.get(), outAttributedString.getFragments().size() - 1});
8694
}

cpp/react/renderer/components/JBAnimatedText/ParagraphProps.cpp

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77

88
#include "ParagraphProps.h"
99

10+
#include <react/featureflags/ReactNativeFeatureFlags.h>
1011
#include <react/renderer/attributedstring/conversions.h>
1112
#include <react/renderer/attributedstring/primitives.h>
1213
#include <react/renderer/core/propsConversions.h>
1314
#include <react/renderer/debug/debugStringConvertibleUtils.h>
14-
#include <react/utils/CoreFeatures.h>
1515

1616
#include <glog/logging.h>
1717

@@ -24,7 +24,7 @@ CParagraphProps::CParagraphProps( // EDITED
2424
: ViewProps(context, sourceProps, rawProps),
2525
BaseTextProps(context, sourceProps, rawProps),
2626
paragraphAttributes(
27-
CoreFeatures::enablePropIteratorSetter
27+
ReactNativeFeatureFlags::enableCppPropsIteratorSetter()
2828
? sourceProps.paragraphAttributes
2929
: convertRawProp(
3030
context,
@@ -35,21 +35,23 @@ CParagraphProps::CParagraphProps( // EDITED
3535
text(convertRawProp(context, rawProps, "text", sourceProps.text, {})),
3636
// END ADDED
3737
isSelectable(
38-
CoreFeatures::enablePropIteratorSetter ? sourceProps.isSelectable
39-
: convertRawProp(
40-
context,
41-
rawProps,
42-
"selectable",
43-
sourceProps.isSelectable,
44-
false)),
38+
ReactNativeFeatureFlags::enableCppPropsIteratorSetter()
39+
? sourceProps.isSelectable
40+
: convertRawProp(
41+
context,
42+
rawProps,
43+
"selectable",
44+
sourceProps.isSelectable,
45+
false)),
4546
onTextLayout(
46-
CoreFeatures::enablePropIteratorSetter ? sourceProps.onTextLayout
47-
: convertRawProp(
48-
context,
49-
rawProps,
50-
"onTextLayout",
51-
sourceProps.onTextLayout,
52-
{})) {
47+
ReactNativeFeatureFlags::enableCppPropsIteratorSetter()
48+
? sourceProps.onTextLayout
49+
: convertRawProp(
50+
context,
51+
rawProps,
52+
"onTextLayout",
53+
sourceProps.onTextLayout,
54+
{})) {
5355
/*
5456
* These props are applied to `View`, therefore they must not be a part of
5557
* base text attributes.

cpp/react/renderer/components/JBAnimatedText/ParagraphShadowNode.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ const Content& CParagraphShadowNode::getContent( // EDITED
5858
auto attributedString = AttributedString{};
5959
auto attachments = Attachments{};
6060
buildAttributedString(textAttributes, *this, attributedString, attachments);
61+
attributedString.setBaseTextAttributes(textAttributes);
6162

6263
content_ = Content{
6364
attributedString, getConcreteProps().paragraphAttributes, attachments};

src/AnimateableText.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const React = require('react');
1313
const ReactNativeViewAttributes = require('react-native/Libraries/Components/View/ReactNativeViewAttributes');
1414
const Touchable = require('react-native/Libraries/Components/Touchable/Touchable');
1515

16-
const createReactNativeComponentClass = require('react-native/Libraries/Renderer/shims/createReactNativeComponentClass');
16+
const createReactNativeComponentClass = require('react-native/Libraries/Renderer/shims/createReactNativeComponentClass').default;
1717
const nullthrows = require('nullthrows');
1818
const processColor = require('react-native/Libraries/StyleSheet/processColor');
1919
import type {

0 commit comments

Comments
 (0)