mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Add equality operators to CSS data types (#48989)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/48989 tsia Also added a quick helper to CSSColor used later. Changelog: [Internal] Reviewed By: joevilches Differential Revision: D68741768 fbshipit-source-id: e0b4c75c15891e4957c7e05a7a89820c1bea72c3
This commit is contained in:
committed by
Facebook GitHub Bot
parent
8af482cc4d
commit
1e5cc693fc
@@ -20,6 +20,8 @@ namespace facebook::react {
|
||||
*/
|
||||
struct CSSAngle {
|
||||
float degrees{};
|
||||
|
||||
constexpr bool operator==(const CSSAngle& rhs) const = default;
|
||||
};
|
||||
|
||||
template <>
|
||||
|
||||
@@ -25,6 +25,12 @@ struct CSSColor {
|
||||
uint8_t g{};
|
||||
uint8_t b{};
|
||||
uint8_t a{};
|
||||
|
||||
constexpr bool operator==(const CSSColor& rhs) const = default;
|
||||
|
||||
static constexpr CSSColor black() {
|
||||
return {0, 0, 0, 255};
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
|
||||
@@ -73,10 +73,11 @@ concept CSSValidDataTypeParser = CSSFunctionBlockSink<T, ReturnT> ||
|
||||
CSSSimplePreservedTokenSink<T, ReturnT>;
|
||||
|
||||
/**
|
||||
* Concrete representation for a CSS data type, or keywords
|
||||
* Concrete representation for a CSS data type
|
||||
*/
|
||||
template <typename T>
|
||||
concept CSSDataType =
|
||||
CSSValidDataTypeParser<CSSDataTypeParser<T>, std::optional<T>>;
|
||||
CSSValidDataTypeParser<CSSDataTypeParser<T>, std::optional<T>> &&
|
||||
std::equality_comparable<T>;
|
||||
|
||||
} // namespace facebook::react
|
||||
|
||||
@@ -21,6 +21,8 @@ namespace facebook::react {
|
||||
struct CSSLength {
|
||||
float value{};
|
||||
CSSLengthUnit unit{CSSLengthUnit::Px};
|
||||
|
||||
constexpr bool operator==(const CSSLength& rhs) const = default;
|
||||
};
|
||||
|
||||
template <>
|
||||
|
||||
@@ -19,6 +19,8 @@ namespace facebook::react {
|
||||
*/
|
||||
struct CSSNumber {
|
||||
float value{};
|
||||
|
||||
constexpr bool operator==(const CSSNumber& rhs) const = default;
|
||||
};
|
||||
|
||||
template <>
|
||||
|
||||
@@ -19,6 +19,8 @@ namespace facebook::react {
|
||||
*/
|
||||
struct CSSPercentage {
|
||||
float value{};
|
||||
|
||||
constexpr bool operator==(const CSSPercentage& rhs) const = default;
|
||||
};
|
||||
|
||||
template <>
|
||||
|
||||
@@ -24,6 +24,8 @@ struct CSSRatio {
|
||||
float numerator{};
|
||||
float denominator{};
|
||||
|
||||
constexpr bool operator==(const CSSRatio& rhs) const = default;
|
||||
|
||||
constexpr bool isDegenerate() const {
|
||||
// If either number in the <ratio> is 0 or infinite, it represents a
|
||||
// degenerate ratio (and, generally, won’t do anything).
|
||||
|
||||
Reference in New Issue
Block a user