Skip to content

Commit 7d4fe67

Browse files
committed
rn 0.54 ios compatibility
1 parent c842705 commit 7d4fe67

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+872
-562
lines changed

android/src/main/java/iyegoroff/RNTextGradient/Linear/RNShadowLinearTextGradient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class RNShadowLinearTextGradient extends RNShadowTextGradient {
1919
private float[] mStart;
2020
private float[] mEnd;
2121

22-
@ReactProp(name = "start")
22+
@ReactProp(name = "gradientStart")
2323
public void setStart(ReadableArray start) {
2424
if (start != null) {
2525
mStart = new float[] {
@@ -31,7 +31,7 @@ public void setStart(ReadableArray start) {
3131
}
3232
}
3333

34-
@ReactProp(name = "end")
34+
@ReactProp(name = "gradientEnd")
3535
public void setEnd(ReadableArray end) {
3636
if (end != null) {
3737
mEnd = new float[] {

ios/RNGradientValue.h

Lines changed: 0 additions & 15 deletions
This file was deleted.

ios/RNLinearGradientUtils.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#import "RNLinearTextGradientShadowViewDelegate.h"
2+
#import "RCTBaseTextShadowView.h"
3+
4+
@interface RNLinearGradientUtils : NSObject
5+
6+
+ (UIColor *)gradientWithFrame:(CGRect)frame
7+
shadowView:(RCTBaseTextShadowView <RNLinearTextGradientShadowViewDelegate> *)shadowView;
8+
9+
+ (NSDictionary *)gradientComparisonKey:(CGRect)frame
10+
shadowView:(RCTBaseTextShadowView <RNLinearTextGradientShadowViewDelegate> *)shadowView;
11+
12+
@end

ios/RNLinearGradientUtils.m

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#import "RNLinearGradientUtils.h"
2+
3+
// based on this: https://github.com/ViccAlexander/Chameleon/blob/master/Pod/Classes/Objective-C/UIColor%2BChameleon.m
4+
5+
@implementation RNLinearGradientUtils
6+
7+
+ (UIColor *)gradientWithFrame:(CGRect)frame
8+
shadowView:(RCTBaseTextShadowView <RNLinearTextGradientShadowViewDelegate> *)shadowView
9+
{
10+
NSMutableArray *cgColors = [[NSMutableArray alloc] init];
11+
for (UIColor *color in [shadowView colors]) {
12+
[cgColors addObject:(id)[color CGColor]];
13+
}
14+
15+
CGSize contextSize = CGSizeMake(frame.size.width + frame.origin.x,
16+
frame.size.height + frame.origin.y);
17+
UIGraphicsBeginImageContextWithOptions(contextSize, NO, [UIScreen mainScreen].scale);
18+
19+
//Default to the RGB Colorspace
20+
CGColorSpaceRef myColorspace = CGColorSpaceCreateDeviceRGB();
21+
CFArrayRef arrayRef = (__bridge CFArrayRef)cgColors;
22+
23+
NSUInteger locationsCount = [[shadowView locations] count];
24+
CGFloat locations[locationsCount];
25+
for (int i = 0; i < locationsCount; ++i) {
26+
locations[i] = [[shadowView locations] objectAtIndex:i].floatValue;
27+
}
28+
29+
//Create our Fradient
30+
CGGradientRef myGradient = CGGradientCreateWithColors(myColorspace, arrayRef, locations);
31+
32+
CGPoint start = CGPointMake([shadowView gradientStart].x * frame.size.width + frame.origin.x,
33+
[shadowView gradientStart].y * frame.size.height + frame.origin.y);
34+
CGPoint end = CGPointMake([shadowView gradientEnd].x * frame.size.width + frame.origin.x,
35+
[shadowView gradientEnd].y * frame.size.height + frame.origin.y);
36+
37+
// Draw our Gradient
38+
CGContextDrawLinearGradient(UIGraphicsGetCurrentContext(),
39+
myGradient,
40+
start,
41+
end,
42+
kCGGradientDrawsAfterEndLocation);
43+
// Grab it as an Image
44+
UIImage *backgroundColorImage = UIGraphicsGetImageFromCurrentImageContext();
45+
46+
// Clean up
47+
CGColorSpaceRelease(myColorspace); // Necessary?
48+
CGGradientRelease(myGradient); // Necessary?
49+
UIGraphicsEndImageContext();
50+
return [UIColor colorWithPatternImage:backgroundColorImage];
51+
}
52+
53+
+ (NSDictionary *)gradientComparisonKey:(CGRect)frame
54+
shadowView:(RCTBaseTextShadowView <RNLinearTextGradientShadowViewDelegate> *)shadowView
55+
{
56+
return @{@"locations": [shadowView locations] ?: @[],
57+
@"colors": [shadowView colors] ?: @[],
58+
@"start": [NSValue valueWithCGPoint:[shadowView gradientStart]],
59+
@"end": [NSValue valueWithCGPoint:[shadowView gradientEnd]],
60+
@"frame": [NSValue valueWithCGRect:frame]};
61+
}
62+
63+
@end

ios/RNLinearTextGradientManager.h

Lines changed: 0 additions & 5 deletions
This file was deleted.

ios/RNLinearTextGradientManager.m

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#import "RNLinearTextGradientShadowViewDelegate.h"
2+
#import "RNTextGradientShadowView.h"
3+
4+
@interface RNLinearTextGradientShadowView : RNTextGradientShadowView <RNLinearTextGradientShadowViewDelegate>
5+
6+
@property (nonatomic, assign) CGPoint gradientStart;
7+
@property (nonatomic, assign) CGPoint gradientEnd;
8+
9+
@end
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#import "RNLinearGradientUtils.h"
2+
#import "RNLinearTextGradientShadowView.h"
3+
4+
@implementation RNLinearTextGradientShadowView
5+
6+
- (UIColor *)gradientWithFrame:(CGRect)frame
7+
{
8+
return [RNLinearGradientUtils gradientWithFrame:frame shadowView:self];
9+
}
10+
11+
- (NSDictionary *)gradientComparisonKey:(CGRect)frame
12+
{
13+
return [RNLinearGradientUtils gradientComparisonKey:frame shadowView:self];
14+
}
15+
16+
@end
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#import "RNTextGradientShadowViewDelegate.h"
2+
3+
#ifndef RNLinearTextGradientShadowViewDelegate_h
4+
#define RNLinearTextGradientShadowViewDelegate_h
5+
6+
@protocol RNLinearTextGradientShadowViewDelegate <RNTextGradientShadowViewDelegate>
7+
8+
- (CGPoint)gradientStart;
9+
- (CGPoint)gradientEnd;
10+
11+
@end
12+
13+
#endif /* RNLinearTextGradientShadowViewDelegate_h */
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#import "RNTextGradientViewManager.h"
2+
3+
@interface RNLinearTextGradientViewManager : RNTextGradientViewManager
4+
5+
@end

0 commit comments

Comments
 (0)