LOTShapeGradientFill.m 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. //
  2. // LOTShapeGradientFill.m
  3. // Lottie
  4. //
  5. // Created by brandon_withrow on 7/26/17.
  6. // Copyright © 2017 Airbnb. All rights reserved.
  7. //
  8. #import "LOTShapeGradientFill.h"
  9. #import "CGGeometry+LOTAdditions.h"
  10. @implementation LOTShapeGradientFill
  11. - (instancetype)initWithJSON:(NSDictionary *)jsonDictionary {
  12. self = [super init];
  13. if (self) {
  14. [self _mapFromJSON:jsonDictionary];
  15. }
  16. return self;
  17. }
  18. - (void)_mapFromJSON:(NSDictionary *)jsonDictionary {
  19. if (jsonDictionary[@"nm"] ) {
  20. _keyname = [jsonDictionary[@"nm"] copy];
  21. }
  22. NSNumber *type = jsonDictionary[@"t"];
  23. if (type.integerValue != 1) {
  24. _type = LOTGradientTypeRadial;
  25. } else {
  26. _type = LOTGradientTypeLinear;
  27. }
  28. NSDictionary *start = jsonDictionary[@"s"];
  29. if (start) {
  30. _startPoint = [[LOTKeyframeGroup alloc] initWithData:start];
  31. }
  32. NSDictionary *end = jsonDictionary[@"e"];
  33. if (end) {
  34. _endPoint = [[LOTKeyframeGroup alloc] initWithData:end];
  35. }
  36. NSDictionary *gradient = jsonDictionary[@"g"];
  37. if (gradient) {
  38. NSDictionary *unwrappedGradient = gradient[@"k"];
  39. _numberOfColors = gradient[@"p"];
  40. _gradient = [[LOTKeyframeGroup alloc] initWithData:unwrappedGradient];
  41. }
  42. NSDictionary *opacity = jsonDictionary[@"o"];
  43. if (opacity) {
  44. _opacity = [[LOTKeyframeGroup alloc] initWithData:opacity];
  45. [_opacity remapKeyframesWithBlock:^CGFloat(CGFloat inValue) {
  46. return LOT_RemapValue(inValue, 0, 100, 0, 1);
  47. }];
  48. }
  49. NSNumber *evenOdd = jsonDictionary[@"r"];
  50. if (evenOdd.integerValue == 2) {
  51. _evenOddFillRule = YES;
  52. } else {
  53. _evenOddFillRule = NO;
  54. }
  55. }
  56. @end