mirror of
https://github.com/status-im/react-native.git
synced 2025-01-13 19:15:05 +00:00
Fabric: New props treatment in graphics
module
Summary: Same as previous one. Adopting template-generated `convertRawProp` and `debugStringConvertibleItem` functions in `graphics` module. Note, to do so we have to change signatures of some conversions functions to make them more overloading-friendly. Reviewed By: fkgozali Differential Revision: D7958252 fbshipit-source-id: 0f33a2e6aad60befacee31486acdb9b6114d3e07
This commit is contained in:
parent
9d21e6661a
commit
9f85873c9f
@ -8,9 +8,8 @@
|
||||
#include "TextAttributes.h"
|
||||
|
||||
#include <fabric/attributedstring/conversions.h>
|
||||
#include <fabric/graphics/conversions.h>
|
||||
#include <fabric/core/debugStringConvertibleUtils.h>
|
||||
#include <fabric/graphics/debugStringConvertibleUtils.h>
|
||||
#include <fabric/graphics/graphicValuesConversions.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
@ -11,7 +11,7 @@
|
||||
#include <fabric/core/LayoutContext.h>
|
||||
#include <fabric/core/LayoutMetrics.h>
|
||||
#include <fabric/debug/DebugStringConvertibleItem.h>
|
||||
#include <fabric/graphics/graphicValuesConversions.h>
|
||||
#include <fabric/graphics/conversions.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
@ -110,14 +110,14 @@ SharedDebugStringConvertibleList LayoutableShadowNode::getDebugProps() const {
|
||||
LayoutMetrics layoutMetrics = getLayoutMetrics();
|
||||
LayoutMetrics defaultLayoutMetrics = LayoutMetrics();
|
||||
|
||||
list.push_back(std::make_shared<DebugStringConvertibleItem>("frame", stringFromRect(layoutMetrics.frame)));
|
||||
list.push_back(std::make_shared<DebugStringConvertibleItem>("frame", toString(layoutMetrics.frame)));
|
||||
|
||||
if (layoutMetrics.borderWidth != defaultLayoutMetrics.borderWidth) {
|
||||
list.push_back(std::make_shared<DebugStringConvertibleItem>("borderWidth", stringFromEdgeInsets(layoutMetrics.borderWidth)));
|
||||
list.push_back(std::make_shared<DebugStringConvertibleItem>("borderWidth", toString(layoutMetrics.borderWidth)));
|
||||
}
|
||||
|
||||
if (layoutMetrics.contentInsets != defaultLayoutMetrics.contentInsets) {
|
||||
list.push_back(std::make_shared<DebugStringConvertibleItem>("contentInsets", stringFromEdgeInsets(layoutMetrics.contentInsets)));
|
||||
list.push_back(std::make_shared<DebugStringConvertibleItem>("contentInsets", toString(layoutMetrics.contentInsets)));
|
||||
}
|
||||
|
||||
if (layoutMetrics.displayType == DisplayType::None) {
|
||||
|
@ -10,7 +10,7 @@
|
||||
#include <folly/dynamic.h>
|
||||
#include <fabric/graphics/Color.h>
|
||||
#include <fabric/graphics/Geometry.h>
|
||||
#include <fabric/graphics/graphicValuesConversions.h>
|
||||
#include <fabric/graphics/conversions.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
@ -44,17 +44,8 @@ inline static folly::Optional<type> convertRawProp(const RawProps &rawProps, con
|
||||
} \
|
||||
}
|
||||
|
||||
CONVERT_RAW_PROP_TEMPLATE(bool, boolFromDynamic)
|
||||
CONVERT_RAW_PROP_TEMPLATE(int, intFromDynamic)
|
||||
CONVERT_RAW_PROP_TEMPLATE(Float, floatFromDynamic)
|
||||
CONVERT_RAW_PROP_TEMPLATE(std::string, stringFromDynamic)
|
||||
CONVERT_RAW_PROP_TEMPLATE(SharedColor, colorFromDynamic)
|
||||
CONVERT_RAW_PROP_TEMPLATE(Point, pointFromDynamic)
|
||||
CONVERT_RAW_PROP_TEMPLATE(Size, sizeFromDynamic)
|
||||
|
||||
inline void fromDynamic(const folly::dynamic &value, bool &result) { result = value.getBool(); }
|
||||
inline void fromDynamic(const folly::dynamic &value, int &result) { result = value.getInt(); }
|
||||
inline void fromDynamic(const folly::dynamic &value, Float &result) { result = value.getDouble(); }
|
||||
inline void fromDynamic(const folly::dynamic &value, std::string &result) { result = value.getString(); }
|
||||
|
||||
template <typename T>
|
||||
|
@ -5,14 +5,18 @@
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#include "graphicValuesConversions.h"
|
||||
#pragma once
|
||||
|
||||
#include <folly/Conv.h>
|
||||
#include <folly/dynamic.h>
|
||||
#include <fabric/graphics/Color.h>
|
||||
#include <fabric/graphics/Geometry.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
SharedColor colorFromDynamic(const folly::dynamic &value) {
|
||||
#pragma mark - Color
|
||||
|
||||
inline void fromDynamic(const folly::dynamic &value, SharedColor &result) {
|
||||
float red;
|
||||
float green;
|
||||
float blue;
|
||||
@ -36,10 +40,10 @@ SharedColor colorFromDynamic(const folly::dynamic &value) {
|
||||
abort();
|
||||
}
|
||||
|
||||
return colorFromComponents({red, green, blue, alpha});
|
||||
result = colorFromComponents({red, green, blue, alpha});
|
||||
}
|
||||
|
||||
std::string colorNameFromColor(const SharedColor &value) {
|
||||
inline std::string toString(const SharedColor &value) {
|
||||
ColorComponents components = colorComponentsFromColor(value);
|
||||
const float ratio = 256;
|
||||
return "rgba(" +
|
||||
@ -49,19 +53,41 @@ std::string colorNameFromColor(const SharedColor &value) {
|
||||
folly::to<std::string>(round(components.alpha * ratio)) + ")";
|
||||
}
|
||||
|
||||
std::string stringFromPoint(const Point &point) {
|
||||
#pragma mark - Geometry
|
||||
|
||||
inline void fromDynamic(const folly::dynamic &value, Float &result) {
|
||||
result = value.asDouble();
|
||||
}
|
||||
|
||||
inline void fromDynamic(const folly::dynamic &value, Point &result) {
|
||||
if (value.isArray()) {
|
||||
result = Point {(Float)value[0].asDouble(), (Float)value[1].asDouble()};
|
||||
return;
|
||||
}
|
||||
abort();
|
||||
}
|
||||
|
||||
inline void fromDynamic(const folly::dynamic &value, Size &result) {
|
||||
if (value.isArray()) {
|
||||
result = Size {(Float)value[0].asDouble(), (Float)value[1].asDouble()};
|
||||
return;
|
||||
}
|
||||
abort();
|
||||
}
|
||||
|
||||
inline std::string toString(const Point &point) {
|
||||
return "{" + folly::to<std::string>(point.x) + ", " + folly::to<std::string>(point.y) + "}";
|
||||
}
|
||||
|
||||
std::string stringFromSize(const Size &size) {
|
||||
inline std::string toString(const Size &size) {
|
||||
return "{" + folly::to<std::string>(size.width) + ", " + folly::to<std::string>(size.height) + "}";
|
||||
}
|
||||
|
||||
std::string stringFromRect(const Rect &rect) {
|
||||
return "{" + stringFromPoint(rect.origin) + ", " + stringFromSize(rect.size) + "}";
|
||||
inline std::string toString(const Rect &rect) {
|
||||
return "{" + toString(rect.origin) + ", " + toString(rect.size) + "}";
|
||||
}
|
||||
|
||||
std::string stringFromEdgeInsets(const EdgeInsets &edgeInsets) {
|
||||
inline std::string toString(const EdgeInsets &edgeInsets) {
|
||||
return "{" +
|
||||
folly::to<std::string>(edgeInsets.left) + ", " +
|
||||
folly::to<std::string>(edgeInsets.top) + ", " +
|
||||
@ -69,23 +95,5 @@ std::string stringFromEdgeInsets(const EdgeInsets &edgeInsets) {
|
||||
folly::to<std::string>(edgeInsets.bottom) + "}";
|
||||
}
|
||||
|
||||
Float floatFromDynamic(const folly::dynamic &value) {
|
||||
return value.asDouble();
|
||||
}
|
||||
|
||||
Point pointFromDynamic(const folly::dynamic &value) {
|
||||
if (value.isArray()) {
|
||||
return Point {(Float)value[0].asDouble(), (Float)value[1].asDouble()};
|
||||
}
|
||||
abort();
|
||||
}
|
||||
|
||||
Size sizeFromDynamic(const folly::dynamic &value) {
|
||||
if (value.isArray()) {
|
||||
return Size {(Float)value[0].asDouble(), (Float)value[1].asDouble()};
|
||||
}
|
||||
abort();
|
||||
}
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
@ -1,22 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2015-present, Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <fabric/debug/debugStringConvertibleUtils.h>
|
||||
#include <fabric/graphics/graphicValuesConversions.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
DEBUG_STRING_CONVERTIBLE_TEMPLATE(Point, stringFromPoint)
|
||||
DEBUG_STRING_CONVERTIBLE_TEMPLATE(Size, stringFromSize)
|
||||
DEBUG_STRING_CONVERTIBLE_TEMPLATE(Rect, stringFromRect)
|
||||
DEBUG_STRING_CONVERTIBLE_TEMPLATE(SharedColor, colorNameFromColor)
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
@ -1,34 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2015-present, Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <folly/dynamic.h>
|
||||
#include <fabric/graphics/Color.h>
|
||||
#include <fabric/graphics/Geometry.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
#pragma mark - Color
|
||||
|
||||
SharedColor colorFromDynamic(const folly::dynamic &value);
|
||||
std::string colorNameFromColor(const SharedColor &value);
|
||||
|
||||
#pragma mark - Geometry
|
||||
|
||||
std::string stringFromPoint(const Point &point);
|
||||
std::string stringFromSize(const Size &size);
|
||||
std::string stringFromRect(const Rect &rect);
|
||||
std::string stringFromEdgeInsets(const EdgeInsets &edgeInsets);
|
||||
|
||||
Float floatFromDynamic(const folly::dynamic &value);
|
||||
Point pointFromDynamic(const folly::dynamic &value);
|
||||
Size sizeFromDynamic(const folly::dynamic &value);
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
@ -7,11 +7,8 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <fabric/graphics/graphicValuesConversions.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
using namespace facebook::react;
|
||||
|
||||
TEST(GraphicsTest, testSomething) {
|
||||
// TODO
|
||||
}
|
||||
|
@ -10,7 +10,7 @@
|
||||
#include <fabric/attributedstring/conversions.h>
|
||||
#include <fabric/core/propsConversions.h>
|
||||
#include <fabric/debug/DebugStringConvertibleItem.h>
|
||||
#include <fabric/graphics/graphicValuesConversions.h>
|
||||
#include <fabric/graphics/conversions.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
@ -8,7 +8,6 @@
|
||||
#include "RawTextProps.h"
|
||||
|
||||
#include <fabric/core/propsConversions.h>
|
||||
#include <fabric/debug/DebugStringConvertibleItem.h>
|
||||
#include <fabric/debug/debugStringConvertibleUtils.h>
|
||||
|
||||
namespace facebook {
|
||||
|
@ -9,8 +9,7 @@
|
||||
|
||||
#include <fabric/core/propsConversions.h>
|
||||
#include <fabric/debug/debugStringConvertibleUtils.h>
|
||||
#include <fabric/graphics/debugStringConvertibleUtils.h>
|
||||
#include <fabric/graphics/graphicValuesConversions.h>
|
||||
#include <fabric/graphics/conversions.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
Loading…
x
Reference in New Issue
Block a user