mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Extract fragment conversions to separate functions (#42597)
Summary: Extract fragment conversions to separate functions to make refactoring easier and simplify reasoning about the code. This code is being modified later. This is a minor improvement in the context of my multi-PR work on https://github.com/react-native-community/discussions-and-proposals/issues/695. ## Changelog: <!-- Help reviewers and the release process by writing your own changelog entry. Pick one each for the category and type tags: [ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message For more details, see: https://reactnative.dev/contributing/changelogs-in-pull-requests --> [INTERNAL] [CHANGE] - Extract fragment conversions to separate functions Pull Request resolved: https://github.com/facebook/react-native/pull/42597 Reviewed By: NickGerleman Differential Revision: D52960655 Pulled By: robhogan fbshipit-source-id: 0df62b9980c06a1c2fc113d645ba8b6b668fa394
This commit is contained in:
committed by
Facebook GitHub Bot
parent
e27452a670
commit
2722f95720
@@ -896,24 +896,28 @@ inline folly::dynamic toDynamic(const TextAttributes& textAttributes) {
|
||||
return _textAttributes;
|
||||
}
|
||||
|
||||
inline folly::dynamic toDynamic(const AttributedString::Fragment& fragment) {
|
||||
folly::dynamic value = folly::dynamic::object();
|
||||
|
||||
value["string"] = fragment.string;
|
||||
if (fragment.parentShadowView.componentHandle) {
|
||||
value["reactTag"] = fragment.parentShadowView.tag;
|
||||
}
|
||||
if (fragment.isAttachment()) {
|
||||
value["isAttachment"] = true;
|
||||
value["width"] = fragment.parentShadowView.layoutMetrics.frame.size.width;
|
||||
value["height"] = fragment.parentShadowView.layoutMetrics.frame.size.height;
|
||||
}
|
||||
value["textAttributes"] = toDynamic(fragment.textAttributes);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
inline folly::dynamic toDynamic(const AttributedString& attributedString) {
|
||||
auto value = folly::dynamic::object();
|
||||
auto fragments = folly::dynamic::array();
|
||||
for (auto fragment : attributedString.getFragments()) {
|
||||
folly::dynamic dynamicFragment = folly::dynamic::object();
|
||||
dynamicFragment["string"] = fragment.string;
|
||||
if (fragment.parentShadowView.componentHandle) {
|
||||
dynamicFragment["reactTag"] = fragment.parentShadowView.tag;
|
||||
}
|
||||
if (fragment.isAttachment()) {
|
||||
dynamicFragment["isAttachment"] = true;
|
||||
dynamicFragment["width"] =
|
||||
fragment.parentShadowView.layoutMetrics.frame.size.width;
|
||||
dynamicFragment["height"] =
|
||||
fragment.parentShadowView.layoutMetrics.frame.size.height;
|
||||
}
|
||||
dynamicFragment["textAttributes"] = toDynamic(fragment.textAttributes);
|
||||
fragments.push_back(dynamicFragment);
|
||||
fragments.push_back(toDynamic(fragment));
|
||||
}
|
||||
value("fragments", fragments);
|
||||
value(
|
||||
@@ -1134,31 +1138,33 @@ inline MapBuffer toMapBuffer(const TextAttributes& textAttributes) {
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
inline MapBuffer toMapBuffer(const AttributedString::Fragment& fragment) {
|
||||
auto builder = MapBufferBuilder();
|
||||
|
||||
builder.putString(FR_KEY_STRING, fragment.string);
|
||||
if (fragment.parentShadowView.componentHandle) {
|
||||
builder.putInt(FR_KEY_REACT_TAG, fragment.parentShadowView.tag);
|
||||
}
|
||||
if (fragment.isAttachment()) {
|
||||
builder.putBool(FR_KEY_IS_ATTACHMENT, true);
|
||||
builder.putDouble(
|
||||
FR_KEY_WIDTH, fragment.parentShadowView.layoutMetrics.frame.size.width);
|
||||
builder.putDouble(
|
||||
FR_KEY_HEIGHT,
|
||||
fragment.parentShadowView.layoutMetrics.frame.size.height);
|
||||
}
|
||||
auto textAttributesMap = toMapBuffer(fragment.textAttributes);
|
||||
builder.putMapBuffer(FR_KEY_TEXT_ATTRIBUTES, textAttributesMap);
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
inline MapBuffer toMapBuffer(const AttributedString& attributedString) {
|
||||
auto fragmentsBuilder = MapBufferBuilder();
|
||||
|
||||
int index = 0;
|
||||
for (auto fragment : attributedString.getFragments()) {
|
||||
auto dynamicFragmentBuilder = MapBufferBuilder();
|
||||
dynamicFragmentBuilder.putString(FR_KEY_STRING, fragment.string);
|
||||
if (fragment.parentShadowView.componentHandle) {
|
||||
dynamicFragmentBuilder.putInt(
|
||||
FR_KEY_REACT_TAG, fragment.parentShadowView.tag);
|
||||
}
|
||||
if (fragment.isAttachment()) {
|
||||
dynamicFragmentBuilder.putBool(FR_KEY_IS_ATTACHMENT, true);
|
||||
dynamicFragmentBuilder.putDouble(
|
||||
FR_KEY_WIDTH,
|
||||
fragment.parentShadowView.layoutMetrics.frame.size.width);
|
||||
dynamicFragmentBuilder.putDouble(
|
||||
FR_KEY_HEIGHT,
|
||||
fragment.parentShadowView.layoutMetrics.frame.size.height);
|
||||
}
|
||||
auto textAttributesMap = toMapBuffer(fragment.textAttributes);
|
||||
dynamicFragmentBuilder.putMapBuffer(
|
||||
FR_KEY_TEXT_ATTRIBUTES, textAttributesMap);
|
||||
auto dynamicFragmentMap = dynamicFragmentBuilder.build();
|
||||
fragmentsBuilder.putMapBuffer(index++, dynamicFragmentMap);
|
||||
fragmentsBuilder.putMapBuffer(index++, toMapBuffer(fragment));
|
||||
}
|
||||
|
||||
auto builder = MapBufferBuilder();
|
||||
|
||||
Reference in New Issue
Block a user