iOS: add gradient background for view node
This commit is contained in:
parent
5728b852cd
commit
c1f4805444
@ -103,6 +103,8 @@ @interface DoricViewNode ()
|
|||||||
@property(nonatomic, copy) NSNumber *rotation;
|
@property(nonatomic, copy) NSNumber *rotation;
|
||||||
@property(nonatomic, copy) NSNumber *pivotX;
|
@property(nonatomic, copy) NSNumber *pivotX;
|
||||||
@property(nonatomic, copy) NSNumber *pivotY;
|
@property(nonatomic, copy) NSNumber *pivotY;
|
||||||
|
|
||||||
|
@property(nonatomic, strong) CAGradientLayer *gradientLayer;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation DoricViewNode
|
@implementation DoricViewNode
|
||||||
@ -168,18 +170,59 @@ - (void)blendView:(UIView *)view forPropName:(NSString *)name propValue:(id)prop
|
|||||||
NSNumber *width = (NSNumber *) prop;
|
NSNumber *width = (NSNumber *) prop;
|
||||||
if ([width floatValue] >= 0) {
|
if ([width floatValue] >= 0) {
|
||||||
view.width = [width floatValue];
|
view.width = [width floatValue];
|
||||||
|
self.gradientLayer.frame = view.bounds;
|
||||||
}
|
}
|
||||||
} else if ([name isEqualToString:@"height"]) {
|
} else if ([name isEqualToString:@"height"]) {
|
||||||
NSNumber *height = (NSNumber *) prop;
|
NSNumber *height = (NSNumber *) prop;
|
||||||
if ([height floatValue] >= 0) {
|
if ([height floatValue] >= 0) {
|
||||||
view.height = [height floatValue];
|
view.height = [height floatValue];
|
||||||
|
self.gradientLayer.frame = view.bounds;
|
||||||
}
|
}
|
||||||
} else if ([name isEqualToString:@"x"]) {
|
} else if ([name isEqualToString:@"x"]) {
|
||||||
view.x = [(NSNumber *) prop floatValue];
|
view.x = [(NSNumber *) prop floatValue];
|
||||||
} else if ([name isEqualToString:@"y"]) {
|
} else if ([name isEqualToString:@"y"]) {
|
||||||
view.y = [(NSNumber *) prop floatValue];
|
view.y = [(NSNumber *) prop floatValue];
|
||||||
} else if ([name isEqualToString:@"backgroundColor"]) {
|
} else if ([name isEqualToString:@"backgroundColor"]) {
|
||||||
|
if ([prop isKindOfClass:[NSNumber class]]) {
|
||||||
view.backgroundColor = DoricColor(prop);
|
view.backgroundColor = DoricColor(prop);
|
||||||
|
} else if ([prop isKindOfClass:[NSDictionary class]]) {
|
||||||
|
if (_gradientLayer == nil) {
|
||||||
|
_gradientLayer = [[CAGradientLayer alloc] init];
|
||||||
|
[view.layer addSublayer:self.gradientLayer];
|
||||||
|
}
|
||||||
|
|
||||||
|
NSDictionary *dict = prop;
|
||||||
|
UIColor *start = DoricColor(dict[@"start"]);
|
||||||
|
UIColor *end = DoricColor(dict[@"end"]);
|
||||||
|
int orientation = [dict[@"orientation"] intValue];
|
||||||
|
|
||||||
|
if (orientation == 0) {
|
||||||
|
self.gradientLayer.startPoint = CGPointMake(0, 0);
|
||||||
|
self.gradientLayer.endPoint = CGPointMake(0, 1);
|
||||||
|
} else if (orientation == 1) {
|
||||||
|
self.gradientLayer.startPoint = CGPointMake(1, 0);
|
||||||
|
self.gradientLayer.endPoint = CGPointMake(0, 1);
|
||||||
|
} else if (orientation == 2) {
|
||||||
|
self.gradientLayer.startPoint = CGPointMake(1, 0);
|
||||||
|
self.gradientLayer.endPoint = CGPointMake(0, 0);
|
||||||
|
} else if (orientation == 3) {
|
||||||
|
self.gradientLayer.startPoint = CGPointMake(1, 1);
|
||||||
|
self.gradientLayer.endPoint = CGPointMake(0, 0);
|
||||||
|
} else if (orientation == 4) {
|
||||||
|
self.gradientLayer.startPoint = CGPointMake(0, 1);
|
||||||
|
self.gradientLayer.endPoint = CGPointMake(0, 0);
|
||||||
|
} else if (orientation == 5) {
|
||||||
|
self.gradientLayer.startPoint = CGPointMake(0, 1);
|
||||||
|
self.gradientLayer.endPoint = CGPointMake(1, 0);
|
||||||
|
} else if (orientation == 6) {
|
||||||
|
self.gradientLayer.startPoint = CGPointMake(0, 0);
|
||||||
|
self.gradientLayer.endPoint = CGPointMake(1, 0);
|
||||||
|
} else if (orientation == 7) {
|
||||||
|
self.gradientLayer.startPoint = CGPointMake(0, 0);
|
||||||
|
self.gradientLayer.endPoint = CGPointMake(1, 1);
|
||||||
|
}
|
||||||
|
self.gradientLayer.colors = @[(__bridge id)start.CGColor, (__bridge id)end.CGColor];
|
||||||
|
}
|
||||||
} else if ([name isEqualToString:@"alpha"]) {
|
} else if ([name isEqualToString:@"alpha"]) {
|
||||||
view.alpha = [prop floatValue];
|
view.alpha = [prop floatValue];
|
||||||
} else if ([name isEqualToString:@"layoutConfig"]) {
|
} else if ([name isEqualToString:@"layoutConfig"]) {
|
||||||
|
Reference in New Issue
Block a user