This commit is contained in:
Yamozha
2021-04-02 02:24:13 +03:00
parent c23950b545
commit 7256d79e2c
31493 changed files with 3036630 additions and 0 deletions

View File

@ -0,0 +1,21 @@
require 'json'
package = JSON.parse(File.read(File.join(__dir__, '..', 'package.json')))
Pod::Spec.new do |s|
s.name = 'EXLinearGradient'
s.version = package['version']
s.summary = package['description']
s.description = package['description']
s.license = package['license']
s.author = package['author']
s.homepage = package['homepage']
s.platform = :ios, '10.0'
s.source = { git: 'https://github.com/expo/expo.git' }
s.source_files = 'EXLinearGradient/**/*.{h,m}'
s.preserve_paths = 'EXLinearGradient/**/*.{h,m}'
s.requires_arc = true
s.dependency 'UMCore'
end

View File

@ -0,0 +1,14 @@
// Copyright 2015-present 650 Industries. All rights reserved.
#import <UIKit/UIKit.h>
#import <UMCore/UMModuleRegistry.h>
#import <UMCore/UMAppLifecycleListener.h>
@interface EXLinearGradient : UIView
- (void)setColors:(NSArray *)colorStrings;
- (void)setLocations:(NSArray *)locations;
- (void)setStartPoint:(CGPoint)start;
- (void)setEndPoint:(CGPoint)end;
@end

View File

@ -0,0 +1,53 @@
// Copyright 2015-present 650 Industries. All rights reserved.
#import <EXLinearGradient/EXLinearGradient.h>
#import <EXLinearGradient/EXLinearGradientLayer.h>
#import <UIKit/UIKit.h>
#import <UMCore/UMModuleRegistry.h>
#import <UMCore/UMAppLifecycleListener.h>
#import <UMCore/UMUtilities.h>
@interface EXLinearGradient ()
@end
@implementation EXLinearGradient
+ (Class)layerClass
{
return [EXLinearGradientLayer class];
}
- (EXLinearGradientLayer *)gradientLayer
{
return (EXLinearGradientLayer *)self.layer;
}
- (void)setColors:(NSArray *)colorStrings
{
NSMutableArray *colors = [NSMutableArray arrayWithCapacity:colorStrings.count];
for (NSString *colorString in colorStrings) {
UIColor *convertedColor = [UMUtilities UIColor:colorString];
if (convertedColor) {
[colors addObject:convertedColor];
}
}
self.gradientLayer.colors = colors;
}
- (void)setStartPoint:(CGPoint)start
{
self.gradientLayer.startPoint = start;
}
- (void)setEndPoint:(CGPoint)end
{
self.gradientLayer.endPoint = end;
}
- (void)setLocations:(NSArray *)locations
{
self.gradientLayer.locations = locations;
}
@end

View File

@ -0,0 +1,14 @@
// Copyright 2018-present 650 Industries. All rights reserved.
#import <Foundation/Foundation.h>
#import <QuartzCore/QuartzCore.h>
#import <UIKit/UIKit.h>
@interface EXLinearGradientLayer : CALayer
@property (nullable, nonatomic, copy) NSArray<UIColor *> *colors;
@property (nullable, nonatomic, copy) NSArray<NSNumber *> *locations;
@property (nonatomic) CGPoint startPoint;
@property (nonatomic) CGPoint endPoint;
@end

View File

@ -0,0 +1,110 @@
// Copyright 2018-present 650 Industries. All rights reserved.
#import <EXLinearGradient/EXLinearGradientLayer.h>
@implementation EXLinearGradientLayer
- (instancetype)init
{
self = [super init];
if (self) {
self.needsDisplayOnBoundsChange = YES;
self.masksToBounds = YES;
_startPoint = CGPointMake(0.5, 0.0);
_endPoint = CGPointMake(0.5, 1.0);
}
return self;
}
- (void)setColors:(NSArray<id> *)colors
{
_colors = colors;
[self setNeedsDisplay];
}
- (void)setLocations:(NSArray<NSNumber *> *)locations
{
_locations = locations;
[self setNeedsDisplay];
}
- (void)setStartPoint:(CGPoint)startPoint
{
_startPoint = startPoint;
[self setNeedsDisplay];
}
- (void)setEndPoint:(CGPoint)endPoint
{
_endPoint = endPoint;
[self setNeedsDisplay];
}
- (void)display {
[super display];
BOOL hasAlpha = NO;
for (NSInteger i = 0; i < self.colors.count; i++) {
hasAlpha = hasAlpha || CGColorGetAlpha(self.colors[i].CGColor) < 1.0;
}
UIGraphicsBeginImageContextWithOptions(self.bounds.size, !hasAlpha, 0.0);
CGContextRef ref = UIGraphicsGetCurrentContext();
[self drawInContext:ref];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
self.contents = (__bridge id _Nullable)(image.CGImage);
self.contentsScale = image.scale;
UIGraphicsEndImageContext();
}
- (void)drawInContext:(CGContextRef)ctx
{
[super drawInContext:ctx];
CGContextSaveGState(ctx);
CGSize size = self.bounds.size;
if (!self.colors || self.colors.count == 0 || size.width == 0.0 || size.height == 0.0)
return;
CGFloat *locations = nil;
locations = malloc(sizeof(CGFloat) * self.colors.count);
for (NSInteger i = 0; i < self.colors.count; i++) {
if (self.locations.count > i) {
locations[i] = self.locations[i].floatValue;
} else {
locations[i] = (1.0 / (self.colors.count - 1)) * i;
}
}
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
NSMutableArray *colors = [[NSMutableArray alloc] initWithCapacity:self.colors.count];
for (UIColor *color in self.colors) {
[colors addObject:(id)color.CGColor];
}
CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, (CFArrayRef)colors, locations);
free(locations);
CGPoint start = self.startPoint, end = self.endPoint;
CGContextDrawLinearGradient(ctx, gradient,
CGPointMake(start.x * size.width, start.y * size.height),
CGPointMake(end.x * size.width, end.y * size.height),
kCGGradientDrawsBeforeStartLocation | kCGGradientDrawsAfterEndLocation);
CGGradientRelease(gradient);
CGColorSpaceRelease(colorSpace);
CGContextRestoreGState(ctx);
}
@end

View File

@ -0,0 +1,8 @@
// Copyright 2015-present 650 Industries. All rights reserved.
#import <UMCore/UMViewManager.h>
#import <UMCore/UMExportedModule.h>
@interface EXLinearGradientManager : UMViewManager
@end

View File

@ -0,0 +1,45 @@
// Copyright 2015-present 650 Industries. All rights reserved.
#import <EXLinearGradient/EXLinearGradientManager.h>
#import <EXLinearGradient/EXLinearGradient.h>
#import <UMCore/UMUIManager.h>
@interface EXLinearGradientManager ()
@end
@implementation EXLinearGradientManager
UM_EXPORT_MODULE(ExpoLinearGradientManager);
- (NSString *)viewName
{
return @"ExpoLinearGradient";
}
- (UIView *)view
{
return [[EXLinearGradient alloc] init];
}
UM_VIEW_PROPERTY(colors, NSArray *, EXLinearGradient) {
[view setColors:value];
}
// NOTE: startPoint and endPoint assume that the value is an array with exactly two floats
UM_VIEW_PROPERTY(startPoint, NSArray *, EXLinearGradient) {
CGPoint point = CGPointMake([[value objectAtIndex:0] floatValue], [[value objectAtIndex:1] floatValue]);
[view setStartPoint:point];
}
UM_VIEW_PROPERTY(endPoint, NSArray *, EXLinearGradient) {
CGPoint point = CGPointMake([[value objectAtIndex:0] floatValue], [[value objectAtIndex:1] floatValue]);
[view setEndPoint:point];
}
UM_VIEW_PROPERTY(locations, NSArray *, EXLinearGradient) {
[view setLocations:value];
}
@end