From 44fb60938a66e3f0774a86c92b7acfe3827f93a1 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Fri, 7 Sep 2018 11:12:23 -0700 Subject: [PATCH] Fabric: Fixed `colorComponentsFromColor` to able to accept empty color object Summary: @public Empty (nullptr) color should be treated as `Clear` color ({0, 0, 0, 0} - black, fully tranparent), so `colorComponentsFromColor()` was changed to accomodate this (previously it crashed). Reviewed By: rsnara Differential Revision: D9631865 fbshipit-source-id: e211f34a89e9f5f86d9fca2789c7163db4feaab1 --- ReactCommon/fabric/graphics/platform/ios/Color.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ReactCommon/fabric/graphics/platform/ios/Color.cpp b/ReactCommon/fabric/graphics/platform/ios/Color.cpp index db03a0f4a..0682a7938 100644 --- a/ReactCommon/fabric/graphics/platform/ios/Color.cpp +++ b/ReactCommon/fabric/graphics/platform/ios/Color.cpp @@ -27,6 +27,11 @@ SharedColor colorFromComponents(ColorComponents components) { } ColorComponents colorComponentsFromColor(SharedColor color) { + if (!color) { + // Empty color object can be considered as `clear` (black, fully transparent) color. + return ColorComponents {0, 0, 0, 0}; + } + int numberOfComponents = CGColorGetNumberOfComponents(color.get()); assert(numberOfComponents == 4); const CGFloat *components = CGColorGetComponents(color.get());