2015-04-29 22:28:18 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2015-04-29 22:28:18 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#import "ARTLinearGradient.h"
|
|
|
|
|
2016-12-05 18:28:37 +00:00
|
|
|
#import <React/RCTLog.h>
|
|
|
|
|
2015-04-29 22:28:18 +00:00
|
|
|
#import "RCTConvert+ART.h"
|
|
|
|
|
|
|
|
@implementation ARTLinearGradient
|
|
|
|
{
|
|
|
|
CGGradientRef _gradient;
|
|
|
|
CGPoint _startPoint;
|
|
|
|
CGPoint _endPoint;
|
|
|
|
}
|
|
|
|
|
2015-11-03 22:45:46 +00:00
|
|
|
- (instancetype)initWithArray:(NSArray<NSNumber *> *)array
|
2015-04-29 22:28:18 +00:00
|
|
|
{
|
|
|
|
if ((self = [super initWithArray:array])) {
|
|
|
|
if (array.count < 5) {
|
|
|
|
RCTLogError(@"-[%@ %@] expects 5 elements, received %@",
|
|
|
|
self.class, NSStringFromSelector(_cmd), array);
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
_startPoint = [RCTConvert CGPoint:array offset:1];
|
|
|
|
_endPoint = [RCTConvert CGPoint:array offset:3];
|
|
|
|
_gradient = CGGradientRetain([RCTConvert CGGradient:array offset:5]);
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)dealloc
|
|
|
|
{
|
|
|
|
CGGradientRelease(_gradient);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)paint:(CGContextRef)context
|
|
|
|
{
|
|
|
|
CGGradientDrawingOptions extendOptions =
|
|
|
|
kCGGradientDrawsBeforeStartLocation | kCGGradientDrawsAfterEndLocation;
|
|
|
|
CGContextDrawLinearGradient(context, _gradient, _startPoint, _endPoint, extendOptions);
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|