mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Introduce toDynamic conversion for ParagraphAttributes class
Summary: This diff introduces a way to convert ParagrapgAttributes object to dynamic objects Reviewed By: shergin Differential Revision: D9798895 fbshipit-source-id: 5b139a079c8681749c3e13938482b47e4153019d
This commit is contained in:
committed by
Facebook Github Bot
parent
5e7c3ca005
commit
f0f460556a
@@ -73,7 +73,7 @@ fb_xplat_cxx_test(
|
||||
"-Wall",
|
||||
],
|
||||
contacts = ["oncall+react_native@xmail.facebook.com"],
|
||||
platforms = APPLE,
|
||||
platforms = (ANDROID, APPLE),
|
||||
deps = [
|
||||
"xplat//folly:molly",
|
||||
"xplat//third-party/gmock:gtest",
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <fabric/attributedstring/ParagraphAttributes.h>
|
||||
#include <fabric/attributedstring/primitives.h>
|
||||
#include <fabric/graphics/Geometry.h>
|
||||
#include <folly/dynamic.h>
|
||||
@@ -188,5 +189,15 @@ inline std::string toString(const TextDecorationLinePattern &textDecorationLineP
|
||||
}
|
||||
}
|
||||
|
||||
inline folly::dynamic toDynamic(const ParagraphAttributes ¶graphAttributes) {
|
||||
auto values = folly::dynamic::object();
|
||||
values("maximumNumberOfLines", paragraphAttributes.maximumNumberOfLines);
|
||||
values("ellipsizeMode", toString(paragraphAttributes.ellipsizeMode));
|
||||
values("adjustsFontSizeToFit", paragraphAttributes.adjustsFontSizeToFit);
|
||||
values("minimumFontSize", paragraphAttributes.minimumFontSize);
|
||||
values("maximumFontSize", paragraphAttributes.maximumFontSize);
|
||||
return values;
|
||||
}
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <fabric/attributedstring/ParagraphAttributes.h>
|
||||
#include <fabric/attributedstring/conversions.h>
|
||||
#include <fabric/attributedstring/primitives.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include <assert.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
|
||||
TEST(ParagraphAttributesTest, testToDynamic) {
|
||||
auto paragraphAttributes = ParagraphAttributes();
|
||||
paragraphAttributes.maximumNumberOfLines = 2;
|
||||
paragraphAttributes.adjustsFontSizeToFit = false;
|
||||
paragraphAttributes.ellipsizeMode = EllipsizeMode::Middle;
|
||||
paragraphAttributes.minimumFontSize = 10;
|
||||
paragraphAttributes.maximumFontSize = 20;
|
||||
|
||||
auto result = toDynamic(paragraphAttributes);
|
||||
assert(result["maximumNumberOfLines"] == paragraphAttributes.maximumNumberOfLines);
|
||||
assert(result["adjustsFontSizeToFit"] == paragraphAttributes.adjustsFontSizeToFit);
|
||||
assert(result["ellipsizeMode"] == toString(paragraphAttributes.ellipsizeMode));
|
||||
assert(result["minimumFontSize"] == paragraphAttributes.minimumFontSize);
|
||||
assert(result["maximumFontSize"] == paragraphAttributes.maximumFontSize);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,6 @@ class LocalData:
|
||||
public Sealable,
|
||||
public DebugStringConvertible {
|
||||
|
||||
// Nothing.
|
||||
};
|
||||
|
||||
} // namespace react
|
||||
|
||||
Reference in New Issue
Block a user