LOTShapeRepeater.m 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. //
  2. // LOTShapeRepeater.m
  3. // Lottie
  4. //
  5. // Created by brandon_withrow on 7/28/17.
  6. // Copyright © 2017 Airbnb. All rights reserved.
  7. //
  8. #import "LOTShapeRepeater.h"
  9. #import "CGGeometry+LOTAdditions.h"
  10. @implementation LOTShapeRepeater
  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. NSDictionary *copies = jsonDictionary[@"c"];
  23. if (copies) {
  24. _copies = [[LOTKeyframeGroup alloc] initWithData:copies];
  25. }
  26. NSDictionary *offset = jsonDictionary[@"o"];
  27. if (offset) {
  28. _offset = [[LOTKeyframeGroup alloc] initWithData:offset];
  29. }
  30. NSDictionary *transform = jsonDictionary[@"tr"];
  31. NSDictionary *rotation = transform[@"r"];
  32. if (rotation) {
  33. _rotation = [[LOTKeyframeGroup alloc] initWithData:rotation];
  34. [_rotation remapKeyframesWithBlock:^CGFloat(CGFloat inValue) {
  35. return LOT_DegreesToRadians(inValue);
  36. }];
  37. }
  38. NSDictionary *startOpacity = transform[@"so"];
  39. if (startOpacity) {
  40. _startOpacity = [[LOTKeyframeGroup alloc] initWithData:startOpacity];
  41. [_startOpacity remapKeyframesWithBlock:^CGFloat(CGFloat inValue) {
  42. return LOT_RemapValue(inValue, 0, 100, 0, 1);
  43. }];
  44. }
  45. NSDictionary *endOpacity = transform[@"eo"];
  46. if (endOpacity) {
  47. _endOpacity = [[LOTKeyframeGroup alloc] initWithData:endOpacity];
  48. [_endOpacity remapKeyframesWithBlock:^CGFloat(CGFloat inValue) {
  49. return LOT_RemapValue(inValue, 0, 100, 0, 1);
  50. }];
  51. }
  52. NSDictionary *anchorPoint = transform[@"a"];
  53. if (anchorPoint) {
  54. _anchorPoint = [[LOTKeyframeGroup alloc] initWithData:anchorPoint];
  55. }
  56. NSDictionary *position = transform[@"p"];
  57. if (position) {
  58. _position = [[LOTKeyframeGroup alloc] initWithData:position];
  59. }
  60. NSDictionary *scale = transform[@"s"];
  61. if (scale) {
  62. _scale = [[LOTKeyframeGroup alloc] initWithData:scale];
  63. [_scale remapKeyframesWithBlock:^CGFloat(CGFloat inValue) {
  64. return LOT_RemapValue(inValue, -100, 100, -1, 1);
  65. }];
  66. }
  67. }
  68. @end