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
This commit is contained in:
Valentin Shergin 2018-06-15 11:25:30 -07:00 committed by Facebook Github Bot
parent 8df7d51600
commit 5bb538ab5c

View File

@ -7,7 +7,17 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import <fabric/graphics/Color.h>
#import <fabric/graphics/Geometry.h> #import <fabric/graphics/Geometry.h>
#import <fabric/view/primitives.h>
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) { inline CGPoint RCTCGPointFromPoint(facebook::react::Point point) {
return {point.x, point.y}; return {point.x, point.y};