From 5bb538ab5c21a872c49181d3c450fa2165de2726 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Fri, 15 Jun 2018 11:25:30 -0700 Subject: [PATCH] Fabric: Color conversions function in RCTConversions Summary: This is quite interesting. In Fabric, on C++ layer we store `color` values as `SharedColor` objects which (on iOS) are `shared_ptr`s with custom deallocater (which calls CoreFramework's `CFRelease` function). All this means that we cannot directly transfer ovenership of this managed pointer to ARC (honestly, I am not 100% sure about that, but at least this "shared ownershipt between ARC and non-ARC worlds" concept is as dangerous as any "relying on implementation details" approach). To to so, we have to create a copy and transfer ownership of the copy to ARC (which we do in 1RCTCGColorRefFromSharedColor`). Reviewed By: fkgozali Differential Revision: D8344061 fbshipit-source-id: 8b6764e1539b1982b41f502bbd3307c7b6900fd9 --- React/Fabric/RCTConversions.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/React/Fabric/RCTConversions.h b/React/Fabric/RCTConversions.h index ba2b9cb1f..49ba41084 100644 --- a/React/Fabric/RCTConversions.h +++ b/React/Fabric/RCTConversions.h @@ -7,7 +7,17 @@ #import +#import #import +#import + +inline UIColor *_Nullable RCTUIColorFromSharedColor(const facebook::react::SharedColor &sharedColor) { + return sharedColor ? [UIColor colorWithCGColor:sharedColor.get()] : nil; +} + +inline CGColorRef RCTCGColorRefFromSharedColor(const facebook::react::SharedColor &sharedColor) { + return sharedColor ? CGColorCreateCopy(sharedColor.get()) : nil; +} inline CGPoint RCTCGPointFromPoint(facebook::react::Point point) { return {point.x, point.y};