Fabric: Using ColorComponents in colorFromComponents function

Summary: Trivial. We have a special data structure for it, why do not use it here?

Reviewed By: mdvacca

Differential Revision: D7738577

fbshipit-source-id: 750aa649b06f17d27906d44df07172a907cde2e5
This commit is contained in:
Valentin Shergin 2018-04-26 17:51:46 -07:00 committed by Facebook Github Bot
parent 139db66a3e
commit 9d08e2afae
3 changed files with 11 additions and 5 deletions

View File

@ -13,11 +13,17 @@
namespace facebook { namespace facebook {
namespace react { namespace react {
SharedColor colorFromComponents(float red, float green, float blue, float alpha) { SharedColor colorFromComponents(ColorComponents components) {
const CGFloat components[] = {red, green, blue, alpha}; const CGFloat componentsArray[] = {
components.red,
components.green,
components.blue,
components.alpha
};
CGColorRef color = CGColorCreate( CGColorRef color = CGColorCreate(
CGColorSpaceCreateDeviceRGB(), CGColorSpaceCreateDeviceRGB(),
components componentsArray
); );
return SharedColor(color, CFRelease); return SharedColor(color, CFRelease);

View File

@ -23,7 +23,7 @@ struct ColorComponents {
float alpha {0}; float alpha {0};
}; };
SharedColor colorFromComponents(float red, float green, float blue, float alpha); SharedColor colorFromComponents(ColorComponents components);
ColorComponents colorComponentsFromColor(SharedColor color); ColorComponents colorComponentsFromColor(SharedColor color);
} // namespace react } // namespace react

View File

@ -36,7 +36,7 @@ SharedColor colorFromDynamic(const folly::dynamic &value) {
abort(); abort();
} }
return colorFromComponents(red, green, blue, alpha); return colorFromComponents({red, green, blue, alpha});
} }
std::string colorNameFromColor(const SharedColor &value) { std::string colorNameFromColor(const SharedColor &value) {