mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Introduce toDynamic conversion for AttributedString class
Summary: This diff introduces a way to convert AttributedString object to dynamic objects Reviewed By: shergin Differential Revision: D9801438 fbshipit-source-id: b762f54917ae90bf53c7f9d07f63b876d1265ece
This commit is contained in:
committed by
Facebook Github Bot
parent
37e0f824f2
commit
c5276ef816
@@ -7,8 +7,40 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <fabric/attributedstring/TextAttributes.h>
|
||||
#include <fabric/attributedstring/conversions.h>
|
||||
#include <fabric/attributedstring/primitives.h>
|
||||
#include <fabric/graphics/conversions.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include <assert.h>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
TEST(AttributedStringTest, testSomething) {
|
||||
// TODO
|
||||
auto attString = new AttributedString();
|
||||
auto fragment = new AttributedString::Fragment();
|
||||
fragment->string = "test";
|
||||
|
||||
auto text = new TextAttributes();
|
||||
text->foregroundColor = {colorFromComponents({100/255.0, 153/255.0, 200/255.0, 1.0})};
|
||||
text->opacity = 0.5;
|
||||
text->fontStyle = FontStyle::Italic;
|
||||
text->fontWeight = FontWeight::Thin;
|
||||
text->fontVariant = FontVariant::TabularNums;
|
||||
fragment->textAttributes = *text;
|
||||
|
||||
attString->prependFragment(*fragment);
|
||||
|
||||
auto result = toDynamic(*attString);
|
||||
assert(result["string"] == fragment->string);
|
||||
auto textAttribute = result["fragments"][0]["textAttributes"];
|
||||
assert(textAttribute["foregroundColor"] == toDynamic(text->foregroundColor));
|
||||
assert(textAttribute["opacity"] == text->opacity);
|
||||
assert(textAttribute["fontStyle"] == toString(*text->fontStyle));
|
||||
assert(textAttribute["fontWeight"] == toString(*text->fontWeight));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user