Reorganized Project Changed Namescape

This commit is contained in:
Brandon Withrow 2017-02-07 15:14:48 -08:00
parent c5ee28dedd
commit b79d34bd40
106 changed files with 2147 additions and 2055 deletions

1
.gitignore vendored
View File

@ -8,4 +8,5 @@ UserInterfaceState.xcuserstate
xample/lottie-ios.xcodeproj/xcuserdata xample/lottie-ios.xcodeproj/xcuserdata
Lottie.xcodeproj/xcuserdata/ Lottie.xcodeproj/xcuserdata/
Example/lottie-ios.xcworkspace/xcuserdata/ Example/lottie-ios.xcworkspace/xcuserdata/
Example/lottie-ios.xcodeproj/xcuserdata/
.idea/ .idea/

View File

@ -11,7 +11,7 @@
@interface ViewController () @interface ViewController ()
@property (nonatomic, strong) LAAnimationView *lottieLogo; @property (nonatomic, strong) LOTAnimationView *lottieLogo;
@end @end
@ -20,8 +20,8 @@
- (void)viewDidLoad { - (void)viewDidLoad {
[super viewDidLoad]; [super viewDidLoad];
self.lottieLogo = [LAAnimationView animationNamed:@"LottieLogo1"]; self.lottieLogo = [LOTAnimationView animationNamed:@"LottieLogo1"];
self.lottieLogo.contentMode = LAViewContentModeScaleAspectFill; self.lottieLogo.contentMode = LOTViewContentModeScaleAspectFill;
self.lottieLogo.frame = self.view.bounds; self.lottieLogo.frame = self.view.bounds;
self.lottieLogo.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable; self.lottieLogo.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;

File diff suppressed because it is too large Load Diff

View File

@ -10,9 +10,9 @@
#endif #endif
#endif #endif
#import "LAAnimationTransitionController.h" #import "LOTAnimationTransitionController.h"
#import "LAAnimationView.h" #import "LOTAnimationView.h"
#import "LAAnimationView_Compat.h" #import "LOTAnimationView_Compat.h"
#import "Lottie.h" #import "Lottie.h"
FOUNDATION_EXPORT double LottieVersionNumber; FOUNDATION_EXPORT double LottieVersionNumber;

View File

@ -10,9 +10,9 @@
#endif #endif
#endif #endif
#import "LAAnimationTransitionController.h" #import "LOTAnimationTransitionController.h"
#import "LAAnimationView.h" #import "LOTAnimationView.h"
#import "LAAnimationView_Compat.h" #import "LOTAnimationView_Compat.h"
#import "Lottie.h" #import "Lottie.h"
FOUNDATION_EXPORT double LottieVersionNumber; FOUNDATION_EXPORT double LottieVersionNumber;

View File

@ -1,27 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>lottie-ios-Example.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
<key>6003F589195388D20070C39A</key>
<dict>
<key>primary</key>
<true/>
</dict>
<key>6003F5AD195388D20070C39A</key>
<dict>
<key>primary</key>
<true/>
</dict>
</dict>
</dict>
</plist>

View File

@ -18,7 +18,7 @@
@end @end
@implementation LACharacterCell { @implementation LACharacterCell {
LAAnimationView *animationView_; LOTAnimationView *animationView_;
NSString *character_; NSString *character_;
} }
@ -74,7 +74,7 @@
return; return;
} }
character_ = sanitizedCharacter; character_ = sanitizedCharacter;
LAAnimationView *animationView = [LAAnimationView animationNamed:sanitizedCharacter]; LOTAnimationView *animationView = [LOTAnimationView animationNamed:sanitizedCharacter];
animationView_ = animationView; animationView_ = animationView;
animationView_.contentMode = UIViewContentModeScaleAspectFit; animationView_.contentMode = UIViewContentModeScaleAspectFit;
[self.contentView addSubview:animationView_]; [self.contentView addSubview:animationView_];

View File

@ -22,7 +22,7 @@ typedef enum : NSUInteger {
@property (nonatomic, assign) ViewBackgroundColor currentBGColor; @property (nonatomic, assign) ViewBackgroundColor currentBGColor;
@property (nonatomic, strong) UIToolbar *toolbar; @property (nonatomic, strong) UIToolbar *toolbar;
@property (nonatomic, strong) UISlider *slider; @property (nonatomic, strong) UISlider *slider;
@property (nonatomic, strong) LAAnimationView *laAnimation; @property (nonatomic, strong) LOTAnimationView *laAnimation;
@end @end
@ -186,7 +186,7 @@ typedef enum : NSUInteger {
self.laAnimation = nil; self.laAnimation = nil;
[self resetAllButtons]; [self resetAllButtons];
self.laAnimation = [[LAAnimationView alloc] initWithContentsOfURL:[NSURL URLWithString:URL]]; self.laAnimation = [[LOTAnimationView alloc] initWithContentsOfURL:[NSURL URLWithString:URL]];
self.laAnimation.contentMode = UIViewContentModeScaleAspectFit; self.laAnimation.contentMode = UIViewContentModeScaleAspectFit;
[self.view addSubview:self.laAnimation]; [self.view addSubview:self.laAnimation];
[self.view setNeedsLayout]; [self.view setNeedsLayout];
@ -197,7 +197,7 @@ typedef enum : NSUInteger {
self.laAnimation = nil; self.laAnimation = nil;
[self resetAllButtons]; [self resetAllButtons];
self.laAnimation = [LAAnimationView animationNamed:named]; self.laAnimation = [LOTAnimationView animationNamed:named];
self.laAnimation.contentMode = UIViewContentModeScaleAspectFit; self.laAnimation.contentMode = UIViewContentModeScaleAspectFit;
[self.view addSubview:self.laAnimation]; [self.view addSubview:self.laAnimation];
[self.view setNeedsLayout]; [self.view setNeedsLayout];

View File

@ -129,14 +129,14 @@
- (id<UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented - (id<UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented
presentingController:(UIViewController *)presenting presentingController:(UIViewController *)presenting
sourceController:(UIViewController *)source { sourceController:(UIViewController *)source {
LAAnimationTransitionController *animationController = [[LAAnimationTransitionController alloc] initWithAnimationNamed:@"vcTransition1" LOTAnimationTransitionController *animationController = [[LOTAnimationTransitionController alloc] initWithAnimationNamed:@"vcTransition1"
fromLayerNamed:@"outLayer" fromLayerNamed:@"outLayer"
toLayerNamed:@"inLayer"]; toLayerNamed:@"inLayer"];
return animationController; return animationController;
} }
- (id<UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed { - (id<UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed {
LAAnimationTransitionController *animationController = [[LAAnimationTransitionController alloc] initWithAnimationNamed:@"vcTransition2" LOTAnimationTransitionController *animationController = [[LOTAnimationTransitionController alloc] initWithAnimationNamed:@"vcTransition2"
fromLayerNamed:@"outLayer" fromLayerNamed:@"outLayer"
toLayerNamed:@"inLayer"]; toLayerNamed:@"inLayer"];
return animationController; return animationController;

View File

@ -11,7 +11,7 @@
@interface LottieRootViewController () <UITableViewDelegate, UITableViewDataSource> @interface LottieRootViewController () <UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) LAAnimationView *lottieLogo; @property (nonatomic, strong) LOTAnimationView *lottieLogo;
@property (nonatomic, strong) UIButton *lottieButton; @property (nonatomic, strong) UIButton *lottieButton;
@property (nonatomic, strong) UITableView *tableView; @property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSArray *tableViewItems; @property (nonatomic, strong) NSArray *tableViewItems;
@ -23,7 +23,7 @@
- (void)viewDidLoad { - (void)viewDidLoad {
[super viewDidLoad]; [super viewDidLoad];
[self _buildDataSource]; [self _buildDataSource];
self.lottieLogo = [LAAnimationView animationNamed:@"LottieLogo1"]; self.lottieLogo = [LOTAnimationView animationNamed:@"LottieLogo1"];
self.lottieLogo.contentMode = UIViewContentModeScaleAspectFill; self.lottieLogo.contentMode = UIViewContentModeScaleAspectFill;
[self.view addSubview:self.lottieLogo]; [self.view addSubview:self.lottieLogo];

File diff suppressed because it is too large Load Diff

View File

@ -16,7 +16,7 @@
BuildableIdentifier = "primary" BuildableIdentifier = "primary"
BlueprintIdentifier = "62CA59B71E3C173B002D7188" BlueprintIdentifier = "62CA59B71E3C173B002D7188"
BuildableName = "Lottie.framework" BuildableName = "Lottie.framework"
BlueprintName = "Lottie" BlueprintName = "Lottie_iOS"
ReferencedContainer = "container:Lottie.xcodeproj"> ReferencedContainer = "container:Lottie.xcodeproj">
</BuildableReference> </BuildableReference>
</BuildActionEntry> </BuildActionEntry>
@ -47,7 +47,7 @@
BuildableIdentifier = "primary" BuildableIdentifier = "primary"
BlueprintIdentifier = "62CA59B71E3C173B002D7188" BlueprintIdentifier = "62CA59B71E3C173B002D7188"
BuildableName = "Lottie.framework" BuildableName = "Lottie.framework"
BlueprintName = "Lottie" BlueprintName = "Lottie_iOS"
ReferencedContainer = "container:Lottie.xcodeproj"> ReferencedContainer = "container:Lottie.xcodeproj">
</BuildableReference> </BuildableReference>
</MacroExpansion> </MacroExpansion>
@ -65,7 +65,7 @@
BuildableIdentifier = "primary" BuildableIdentifier = "primary"
BlueprintIdentifier = "62CA59B71E3C173B002D7188" BlueprintIdentifier = "62CA59B71E3C173B002D7188"
BuildableName = "Lottie.framework" BuildableName = "Lottie.framework"
BlueprintName = "Lottie" BlueprintName = "Lottie_iOS"
ReferencedContainer = "container:Lottie.xcodeproj"> ReferencedContainer = "container:Lottie.xcodeproj">
</BuildableReference> </BuildableReference>
</MacroExpansion> </MacroExpansion>

View File

@ -1,5 +1,5 @@
// //
// LAAnimatableLayer.h // LOTAnimatableLayer.h
// LottieAnimator // LottieAnimator
// //
// Created by brandon_withrow on 7/21/16. // Created by brandon_withrow on 7/21/16.
@ -8,7 +8,7 @@
#import <QuartzCore/QuartzCore.h> #import <QuartzCore/QuartzCore.h>
@interface LAAnimatableLayer : CALayer @interface LOTAnimatableLayer : CALayer
- (instancetype)initWithDuration:(NSTimeInterval)duration NS_DESIGNATED_INITIALIZER; - (instancetype)initWithDuration:(NSTimeInterval)duration NS_DESIGNATED_INITIALIZER;

View File

@ -1,14 +1,14 @@
// //
// LAAnimatableLayer.m // LOTAnimatableLayer.m
// LottieAnimator // LottieAnimator
// //
// Created by brandon_withrow on 7/21/16. // Created by brandon_withrow on 7/21/16.
// Copyright © 2016 Brandon Withrow. All rights reserved. // Copyright © 2016 Brandon Withrow. All rights reserved.
// //
#import "LAAnimatableLayer.h" #import "LOTAnimatableLayer.h"
@implementation LAAnimatableLayer @implementation LOTAnimatableLayer
- (instancetype)initWithDuration:(NSTimeInterval)duration { - (instancetype)initWithDuration:(NSTimeInterval)duration {
self = [super init]; self = [super init];

View File

@ -0,0 +1,21 @@
//
// LOTEllipseShapeLayer.h
// LottieAnimator
//
// Created by brandon_withrow on 7/26/16.
// Copyright © 2016 Brandon Withrow. All rights reserved.
//
#import "LOTAnimatableLayer.h"
#import "LOTModels.h"
@interface LOTEllipseShapeLayer : LOTAnimatableLayer
- (instancetype)initWithEllipseShape:(LOTShapeCircle *)circleShape
fill:(LOTShapeFill *)fill
stroke:(LOTShapeStroke *)stroke
trim:(LOTShapeTrimPath *)trim
transform:(LOTShapeTransform *)transform
withDuration:(NSTimeInterval)duration;
@end

View File

@ -1,33 +1,33 @@
// //
// LAEllipseShapeLayer.m // LOTEllipseShapeLayer.m
// LottieAnimator // LottieAnimator
// //
// Created by brandon_withrow on 7/26/16. // Created by brandon_withrow on 7/26/16.
// Copyright © 2016 Brandon Withrow. All rights reserved. // Copyright © 2016 Brandon Withrow. All rights reserved.
// //
#import "LAEllipseShapeLayer.h" #import "LOTEllipseShapeLayer.h"
#import "CAAnimationGroup+LAAnimatableGroup.h" #import "CAAnimationGroup+LOTAnimatableGroup.h"
const CGFloat kEllipseControlPointPercentage = 0.55228; const CGFloat kEllipseControlPointPercentage = 0.55228;
@interface LACircleShapeLayer : CAShapeLayer @interface LOTCircleShapeLayer : CAShapeLayer
@property (nonatomic) CGPoint circlePosition; @property (nonatomic) CGPoint circlePosition;
@property (nonatomic) CGPoint circleSize; @property (nonatomic) CGPoint circleSize;
@end @end
@implementation LACircleShapeLayer @implementation LOTCircleShapeLayer
@dynamic circleSize; @dynamic circleSize;
@dynamic circlePosition; @dynamic circlePosition;
-(id)initWithLayer:(id)layer { -(id)initWithLayer:(id)layer {
if( ( self = [super initWithLayer:layer] ) ) { if( ( self = [super initWithLayer:layer] ) ) {
if ([layer isKindOfClass:[LACircleShapeLayer class]]) { if ([layer isKindOfClass:[LOTCircleShapeLayer class]]) {
self.circleSize = ((LACircleShapeLayer *)layer).circleSize; self.circleSize = ((LOTCircleShapeLayer *)layer).circleSize;
self.circlePosition = ((LACircleShapeLayer *)layer).circlePosition; self.circlePosition = ((LOTCircleShapeLayer *)layer).circlePosition;
} }
} }
return self; return self;
@ -54,7 +54,7 @@ const CGFloat kEllipseControlPointPercentage = 0.55228;
} }
- (void)_setPath { - (void)_setPath {
LACircleShapeLayer *presentationCircle = (LACircleShapeLayer *)self.presentationLayer; LOTCircleShapeLayer *presentationCircle = (LOTCircleShapeLayer *)self.presentationLayer;
if (presentationCircle == nil) { if (presentationCircle == nil) {
presentationCircle = self; presentationCircle = self;
} }
@ -88,26 +88,26 @@ const CGFloat kEllipseControlPointPercentage = 0.55228;
@end @end
@implementation LAEllipseShapeLayer { @implementation LOTEllipseShapeLayer {
LAShapeTransform *_transform; LOTShapeTransform *_transform;
LAShapeStroke *_stroke; LOTShapeStroke *_stroke;
LAShapeFill *_fill; LOTShapeFill *_fill;
LAShapeCircle *_circle; LOTShapeCircle *_circle;
LAShapeTrimPath *_trim; LOTShapeTrimPath *_trim;
LACircleShapeLayer *_fillLayer; LOTCircleShapeLayer *_fillLayer;
LACircleShapeLayer *_strokeLayer; LOTCircleShapeLayer *_strokeLayer;
CAAnimationGroup *_animation; CAAnimationGroup *_animation;
CAAnimationGroup *_strokeAnimation; CAAnimationGroup *_strokeAnimation;
CAAnimationGroup *_fillAnimation; CAAnimationGroup *_fillAnimation;
} }
- (instancetype)initWithEllipseShape:(LAShapeCircle *)circleShape - (instancetype)initWithEllipseShape:(LOTShapeCircle *)circleShape
fill:(LAShapeFill *)fill fill:(LOTShapeFill *)fill
stroke:(LAShapeStroke *)stroke stroke:(LOTShapeStroke *)stroke
trim:(LAShapeTrimPath *)trim trim:(LOTShapeTrimPath *)trim
transform:(LAShapeTransform *)transform transform:(LOTShapeTransform *)transform
withDuration:(NSTimeInterval)duration { withDuration:(NSTimeInterval)duration {
self = [super initWithDuration:duration]; self = [super initWithDuration:duration];
if (self) { if (self) {
@ -126,7 +126,7 @@ const CGFloat kEllipseControlPointPercentage = 0.55228;
self.sublayerTransform = CATransform3DMakeRotation(_transform.rotation.initialValue.floatValue, 0, 0, 1); self.sublayerTransform = CATransform3DMakeRotation(_transform.rotation.initialValue.floatValue, 0, 0, 1);
if (fill) { if (fill) {
_fillLayer = [LACircleShapeLayer new]; _fillLayer = [LOTCircleShapeLayer new];
_fillLayer.allowsEdgeAntialiasing = YES; _fillLayer.allowsEdgeAntialiasing = YES;
_fillLayer.fillColor = _fill.color.initialColor.CGColor; _fillLayer.fillColor = _fill.color.initialColor.CGColor;
_fillLayer.opacity = _fill.opacity.initialValue.floatValue; _fillLayer.opacity = _fill.opacity.initialValue.floatValue;
@ -136,7 +136,7 @@ const CGFloat kEllipseControlPointPercentage = 0.55228;
} }
if (stroke) { if (stroke) {
_strokeLayer = [LACircleShapeLayer new]; _strokeLayer = [LOTCircleShapeLayer new];
_strokeLayer.allowsEdgeAntialiasing = YES; _strokeLayer.allowsEdgeAntialiasing = YES;
_strokeLayer.strokeColor = _stroke.color.initialColor.CGColor; _strokeLayer.strokeColor = _stroke.color.initialColor.CGColor;
_strokeLayer.opacity = _stroke.opacity.initialValue.floatValue; _strokeLayer.opacity = _stroke.opacity.initialValue.floatValue;
@ -144,17 +144,17 @@ const CGFloat kEllipseControlPointPercentage = 0.55228;
_strokeLayer.fillColor = nil; _strokeLayer.fillColor = nil;
_strokeLayer.backgroundColor = nil; _strokeLayer.backgroundColor = nil;
_strokeLayer.lineDashPattern = _stroke.lineDashPattern; _strokeLayer.lineDashPattern = _stroke.lineDashPattern;
_strokeLayer.lineCap = _stroke.capType == LALineCapTypeRound ? kCALineCapRound : kCALineCapButt; _strokeLayer.lineCap = _stroke.capType == LOTLineCapTypeRound ? kCALineCapRound : kCALineCapButt;
_strokeLayer.circlePosition = circleShape.position.initialPoint; _strokeLayer.circlePosition = circleShape.position.initialPoint;
_strokeLayer.circleSize = circleShape.size.initialPoint; _strokeLayer.circleSize = circleShape.size.initialPoint;
switch (_stroke.joinType) { switch (_stroke.joinType) {
case LALineJoinTypeBevel: case LOTLineJoinTypeBevel:
_strokeLayer.lineJoin = kCALineJoinBevel; _strokeLayer.lineJoin = kCALineJoinBevel;
break; break;
case LALineJoinTypeMiter: case LOTLineJoinTypeMiter:
_strokeLayer.lineJoin = kCALineJoinMiter; _strokeLayer.lineJoin = kCALineJoinMiter;
break; break;
case LALineJoinTypeRound: case LOTLineJoinTypeRound:
_strokeLayer.lineJoin = kCALineJoinRound; _strokeLayer.lineJoin = kCALineJoinRound;
break; break;
default: default:
@ -175,7 +175,7 @@ const CGFloat kEllipseControlPointPercentage = 0.55228;
- (void)_buildAnimation { - (void)_buildAnimation {
if (_transform) { if (_transform) {
_animation = [CAAnimationGroup animationGroupForAnimatablePropertiesWithKeyPaths:@{@"opacity" : _transform.opacity, _animation = [CAAnimationGroup LOT_animationGroupForAnimatablePropertiesWithKeyPaths:@{@"opacity" : _transform.opacity,
@"position" : _transform.position, @"position" : _transform.position,
@"anchorPoint" : _transform.anchor, @"anchorPoint" : _transform.anchor,
@"transform" : _transform.scale, @"transform" : _transform.scale,
@ -193,13 +193,13 @@ const CGFloat kEllipseControlPointPercentage = 0.55228;
properties[@"strokeStart"] = _trim.start; properties[@"strokeStart"] = _trim.start;
properties[@"strokeEnd"] = _trim.end; properties[@"strokeEnd"] = _trim.end;
} }
_strokeAnimation = [CAAnimationGroup animationGroupForAnimatablePropertiesWithKeyPaths:properties]; _strokeAnimation = [CAAnimationGroup LOT_animationGroupForAnimatablePropertiesWithKeyPaths:properties];
[_strokeLayer addAnimation:_strokeAnimation forKey:@""]; [_strokeLayer addAnimation:_strokeAnimation forKey:@""];
} }
if (_fill) { if (_fill) {
_fillAnimation = [CAAnimationGroup animationGroupForAnimatablePropertiesWithKeyPaths:@{@"fillColor" : _fill.color, _fillAnimation = [CAAnimationGroup LOT_animationGroupForAnimatablePropertiesWithKeyPaths:@{@"fillColor" : _fill.color,
@"opacity" : _fill.opacity, @"opacity" : _fill.opacity,
@"circlePosition" : _circle.position, @"circlePosition" : _circle.position,
@"circleSize" : _circle.size}]; @"circleSize" : _circle.size}];

View File

@ -0,0 +1,31 @@
//
// LOTGroupLayerView.h
// LottieAnimator
//
// Created by brandon_withrow on 7/14/16.
// Copyright © 2016 Brandon Withrow. All rights reserved.
//
#import <QuartzCore/QuartzCore.h>
#import "LOTAnimatableLayer.h"
@class LOTShapeGroup;
@class LOTShapeTransform;
@class LOTShapeFill;
@class LOTShapeStroke;
@class LOTShapeTrimPath;
@interface LOTGroupLayerView : LOTAnimatableLayer
- (instancetype)initWithShapeGroup:(LOTShapeGroup *)shapeGroup
transform:(LOTShapeTransform *)previousTransform
fill:(LOTShapeFill *)previousFill
stroke:(LOTShapeStroke *)previousStroke
trimPath:(LOTShapeTrimPath *)previousTrimPath
withDuration:(NSTimeInterval)duration;
@property (nonatomic, readonly) LOTShapeGroup *shapeGroup;
@property (nonatomic, readonly) LOTShapeTransform *shapeTransform;
@property (nonatomic, assign) BOOL debugModeOn;
@end

View File

@ -1,29 +1,29 @@
// //
// LAGroupLayerView.m // LOTGroupLayerView.m
// LottieAnimator // LottieAnimator
// //
// Created by brandon_withrow on 7/14/16. // Created by brandon_withrow on 7/14/16.
// Copyright © 2016 Brandon Withrow. All rights reserved. // Copyright © 2016 Brandon Withrow. All rights reserved.
// //
#import "LAGroupLayerView.h" #import "LOTGroupLayerView.h"
#import "LAShapeLayerView.h" #import "LOTShapeLayerView.h"
#import "LARectShapeLayer.h" #import "LOTRectShapeLayer.h"
#import "LAEllipseShapeLayer.h" #import "LOTEllipseShapeLayer.h"
#import "CAAnimationGroup+LAAnimatableGroup.h" #import "CAAnimationGroup+LOTAnimatableGroup.h"
@implementation LAGroupLayerView { @implementation LOTGroupLayerView {
NSArray<LAGroupLayerView *> *_groupLayers; NSArray<LOTGroupLayerView *> *_groupLayers;
NSArray<LAShapeLayerView *> *_shapeLayers; NSArray<LOTShapeLayerView *> *_shapeLayers;
CAAnimationGroup *_animation; CAAnimationGroup *_animation;
} }
- (instancetype)initWithShapeGroup:(LAShapeGroup *)shapeGroup - (instancetype)initWithShapeGroup:(LOTShapeGroup *)shapeGroup
transform:(LAShapeTransform *)previousTransform transform:(LOTShapeTransform *)previousTransform
fill:(LAShapeFill *)previousFill fill:(LOTShapeFill *)previousFill
stroke:(LAShapeStroke *)previousStroke stroke:(LOTShapeStroke *)previousStroke
trimPath:(LAShapeTrimPath *)previousTrimPath trimPath:(LOTShapeTrimPath *)previousTrimPath
withDuration:(NSTimeInterval)duration { withDuration:(NSTimeInterval)duration {
self = [super initWithDuration:duration]; self = [super initWithDuration:duration];
if (self) { if (self) {
@ -34,9 +34,9 @@
return self; return self;
} }
- (void)_setupShapeGroupWithFill:(LAShapeFill *)previousFill - (void)_setupShapeGroupWithFill:(LOTShapeFill *)previousFill
stroke:(LAShapeStroke *)previousStroke stroke:(LOTShapeStroke *)previousStroke
trimPath:(LAShapeTrimPath *)previousTrimPath { trimPath:(LOTShapeTrimPath *)previousTrimPath {
if (_shapeTransform) { if (_shapeTransform) {
self.frame = _shapeTransform.compBounds; self.frame = _shapeTransform.compBounds;
self.anchorPoint = _shapeTransform.anchor.initialPoint; self.anchorPoint = _shapeTransform.anchor.initialPoint;
@ -49,26 +49,26 @@
NSArray *groupItems = _shapeGroup.items; NSArray *groupItems = _shapeGroup.items;
NSArray *reversedItems = [[groupItems reverseObjectEnumerator] allObjects]; NSArray *reversedItems = [[groupItems reverseObjectEnumerator] allObjects];
LAShapeFill *currentFill = previousFill; LOTShapeFill *currentFill = previousFill;
LAShapeStroke *currentStroke = previousStroke; LOTShapeStroke *currentStroke = previousStroke;
LAShapeTransform *currentTransform; LOTShapeTransform *currentTransform;
LAShapeTrimPath *currentTrim = previousTrimPath; LOTShapeTrimPath *currentTrim = previousTrimPath;
NSMutableArray *shapeLayers = [NSMutableArray array]; NSMutableArray *shapeLayers = [NSMutableArray array];
NSMutableArray *groupLayers = [NSMutableArray array]; NSMutableArray *groupLayers = [NSMutableArray array];
for (id item in reversedItems) { for (id item in reversedItems) {
if ([item isKindOfClass:[LAShapeTransform class]]) { if ([item isKindOfClass:[LOTShapeTransform class]]) {
currentTransform = item; currentTransform = item;
} else if ([item isKindOfClass:[LAShapeStroke class]]) { } else if ([item isKindOfClass:[LOTShapeStroke class]]) {
currentStroke = item; currentStroke = item;
} else if ([item isKindOfClass:[LAShapeFill class]]) { } else if ([item isKindOfClass:[LOTShapeFill class]]) {
currentFill = item; currentFill = item;
} else if ([item isKindOfClass:[LAShapeTrimPath class]]) { } else if ([item isKindOfClass:[LOTShapeTrimPath class]]) {
currentTrim = item; currentTrim = item;
} else if ([item isKindOfClass:[LAShapePath class]]) { } else if ([item isKindOfClass:[LOTShapePath class]]) {
LAShapePath *shapePath = (LAShapePath *)item; LOTShapePath *shapePath = (LOTShapePath *)item;
LAShapeLayerView *shapeLayer = [[LAShapeLayerView alloc] initWithShape:shapePath LOTShapeLayerView *shapeLayer = [[LOTShapeLayerView alloc] initWithShape:shapePath
fill:currentFill fill:currentFill
stroke:currentStroke stroke:currentStroke
trim:currentTrim trim:currentTrim
@ -76,18 +76,18 @@
withDuration:self.laAnimationDuration]; withDuration:self.laAnimationDuration];
[shapeLayers addObject:shapeLayer]; [shapeLayers addObject:shapeLayer];
[self addSublayer:shapeLayer]; [self addSublayer:shapeLayer];
} else if ([item isKindOfClass:[LAShapeRectangle class]]) { } else if ([item isKindOfClass:[LOTShapeRectangle class]]) {
LAShapeRectangle *shapeRect = (LAShapeRectangle *)item; LOTShapeRectangle *shapeRect = (LOTShapeRectangle *)item;
LARectShapeLayer *shapeLayer = [[LARectShapeLayer alloc] initWithRectShape:shapeRect LOTRectShapeLayer *shapeLayer = [[LOTRectShapeLayer alloc] initWithRectShape:shapeRect
fill:currentFill fill:currentFill
stroke:currentStroke stroke:currentStroke
transform:currentTransform transform:currentTransform
withDuration:self.laAnimationDuration]; withDuration:self.laAnimationDuration];
[shapeLayers addObject:shapeLayer]; [shapeLayers addObject:shapeLayer];
[self addSublayer:shapeLayer]; [self addSublayer:shapeLayer];
} else if ([item isKindOfClass:[LAShapeCircle class]]) { } else if ([item isKindOfClass:[LOTShapeCircle class]]) {
LAShapeCircle *shapeCircle = (LAShapeCircle *)item; LOTShapeCircle *shapeCircle = (LOTShapeCircle *)item;
LAEllipseShapeLayer *shapeLayer = [[LAEllipseShapeLayer alloc] initWithEllipseShape:shapeCircle LOTEllipseShapeLayer *shapeLayer = [[LOTEllipseShapeLayer alloc] initWithEllipseShape:shapeCircle
fill:currentFill fill:currentFill
stroke:currentStroke stroke:currentStroke
trim:currentTrim trim:currentTrim
@ -95,9 +95,9 @@
withDuration:self.laAnimationDuration]; withDuration:self.laAnimationDuration];
[shapeLayers addObject:shapeLayer]; [shapeLayers addObject:shapeLayer];
[self addSublayer:shapeLayer]; [self addSublayer:shapeLayer];
} else if ([item isKindOfClass:[LAShapeGroup class]]) { } else if ([item isKindOfClass:[LOTShapeGroup class]]) {
LAShapeGroup *shapeGroup = (LAShapeGroup *)item; LOTShapeGroup *shapeGroup = (LOTShapeGroup *)item;
LAGroupLayerView *groupLayer = [[LAGroupLayerView alloc] initWithShapeGroup:shapeGroup LOTGroupLayerView *groupLayer = [[LOTGroupLayerView alloc] initWithShapeGroup:shapeGroup
transform:currentTransform transform:currentTransform
fill:currentFill fill:currentFill
stroke:currentStroke stroke:currentStroke
@ -115,7 +115,7 @@
- (void)_buildAnimation { - (void)_buildAnimation {
if (_shapeTransform) { if (_shapeTransform) {
_animation = [CAAnimationGroup animationGroupForAnimatablePropertiesWithKeyPaths:@{@"opacity" : _shapeTransform.opacity, _animation = [CAAnimationGroup LOT_animationGroupForAnimatablePropertiesWithKeyPaths:@{@"opacity" : _shapeTransform.opacity,
@"position" : _shapeTransform.position, @"position" : _shapeTransform.position,
@"anchorPoint" : _shapeTransform.anchor, @"anchorPoint" : _shapeTransform.anchor,
@"transform" : _shapeTransform.scale, @"transform" : _shapeTransform.scale,

View File

@ -0,0 +1,21 @@
//
// LOTLayerView.h
// LottieAnimator
//
// Created by Brandon Withrow on 12/14/15.
// Copyright © 2015 Brandon Withrow. All rights reserved.
//
#import "LOTPlatformCompat.h"
#import "LOTAnimatableLayer.h"
#import "LOTModels.h"
@interface LOTLayerView : LOTAnimatableLayer
- (instancetype)initWithModel:(LOTLayer *)model inComposition:(LOTComposition *)comp;
@property (nonatomic, readonly) LOTLayer *layerModel;
@property (nonatomic, assign) BOOL debugModeOn;
@end

View File

@ -1,32 +1,32 @@
// //
// LALayerView.m // LOTLayerView.m
// LottieAnimator // LottieAnimator
// //
// Created by Brandon Withrow on 12/14/15. // Created by Brandon Withrow on 12/14/15.
// Copyright © 2015 Brandon Withrow. All rights reserved. // Copyright © 2015 Brandon Withrow. All rights reserved.
// //
#import "LALayerView.h" #import "LOTLayerView.h"
#import "LAShapeLayerView.h" #import "LOTShapeLayerView.h"
#import "LARectShapeLayer.h" #import "LOTRectShapeLayer.h"
#import "LAEllipseShapeLayer.h" #import "LOTEllipseShapeLayer.h"
#import "LAGroupLayerView.h" #import "LOTGroupLayerView.h"
#import "CAAnimationGroup+LAAnimatableGroup.h" #import "CAAnimationGroup+LOTAnimatableGroup.h"
#import "LAMaskLayer.h" #import "LOTMaskLayer.h"
#import "CGGeometryAdditions.h" #import "CGGeometryAdditions.h"
@interface LAParentLayer : LAAnimatableLayer @interface LOTParentLayer : LOTAnimatableLayer
- (instancetype)initWithParentModel:(LALayer *)parent inComposition:(LAComposition *)comp; - (instancetype)initWithParentModel:(LOTLayer *)parent inComposition:(LOTComposition *)comp;
@end @end
@implementation LAParentLayer { @implementation LOTParentLayer {
LALayer *_parentModel; LOTLayer *_parentModel;
CAAnimationGroup *_animation; CAAnimationGroup *_animation;
} }
- (instancetype)initWithParentModel:(LALayer *)parent inComposition:(LAComposition *)comp { - (instancetype)initWithParentModel:(LOTLayer *)parent inComposition:(LOTComposition *)comp {
self = [super initWithDuration:comp.timeDuration]; self = [super initWithDuration:comp.timeDuration];
if (self) { if (self) {
self.bounds = parent.compBounds; self.bounds = parent.compBounds;
@ -45,7 +45,7 @@
} }
- (void)_buildAnimations { - (void)_buildAnimations {
_animation = [CAAnimationGroup animationGroupForAnimatablePropertiesWithKeyPaths:@{@"position" : _parentModel.position, _animation = [CAAnimationGroup LOT_animationGroupForAnimatablePropertiesWithKeyPaths:@{@"position" : _parentModel.position,
@"anchorPoint" : _parentModel.anchor, @"anchorPoint" : _parentModel.anchor,
@"transform" : _parentModel.scale, @"transform" : _parentModel.scale,
@"sublayerTransform.rotation" : _parentModel.rotation}]; @"sublayerTransform.rotation" : _parentModel.rotation}];
@ -54,18 +54,18 @@
@end @end
@implementation LALayerView { @implementation LOTLayerView {
NSArray<LAGroupLayerView *> *_shapeLayers; NSArray<LOTGroupLayerView *> *_shapeLayers;
CALayer *_childContainerLayer; CALayer *_childContainerLayer;
CALayer *_rotationLayer; CALayer *_rotationLayer;
CAAnimationGroup *_animation; CAAnimationGroup *_animation;
CAKeyframeAnimation *_inOutAnimation; CAKeyframeAnimation *_inOutAnimation;
NSArray<LAParentLayer *> *_parentLayers; NSArray<LOTParentLayer *> *_parentLayers;
LAComposition *_composition; LOTComposition *_composition;
LAMaskLayer *_maskLayer; LOTMaskLayer *_maskLayer;
} }
- (instancetype)initWithModel:(LALayer *)model inComposition:(LAComposition *)comp { - (instancetype)initWithModel:(LOTLayer *)model inComposition:(LOTComposition *)comp {
self = [super initWithDuration:comp.timeDuration]; self = [super initWithDuration:comp.timeDuration];
if (self) { if (self) {
_layerModel = model; _layerModel = model;
@ -84,7 +84,7 @@
_childContainerLayer.bounds = self.bounds; _childContainerLayer.bounds = self.bounds;
_childContainerLayer.backgroundColor = _layerModel.solidColor.CGColor; _childContainerLayer.backgroundColor = _layerModel.solidColor.CGColor;
if (_layerModel.layerType == LALayerTypeSolid) { if (_layerModel.layerType == LOTLayerTypeSolid) {
_childContainerLayer.bounds = CGRectMake(0, 0, _layerModel.solidWidth.floatValue, _layerModel.solidHeight.floatValue); _childContainerLayer.bounds = CGRectMake(0, 0, _layerModel.solidWidth.floatValue, _layerModel.solidHeight.floatValue);
_childContainerLayer.backgroundColor = nil; _childContainerLayer.backgroundColor = nil;
_childContainerLayer.masksToBounds = NO; _childContainerLayer.masksToBounds = NO;
@ -101,8 +101,8 @@
NSMutableArray *parentLayers = [NSMutableArray array]; NSMutableArray *parentLayers = [NSMutableArray array];
if (parentID) { if (parentID) {
while (parentID != nil) { while (parentID != nil) {
LALayer *parentModel = [_composition layerModelForID:parentID]; LOTLayer *parentModel = [_composition layerModelForID:parentID];
LAParentLayer *parentLayer = [[LAParentLayer alloc] initWithParentModel:parentModel inComposition:_composition]; LOTParentLayer *parentLayer = [[LOTParentLayer alloc] initWithParentModel:parentModel inComposition:_composition];
[parentLayer addSublayer:currentChild]; [parentLayer addSublayer:currentChild];
[parentLayers addObject:parentLayer]; [parentLayers addObject:parentLayer];
currentChild = parentLayer; currentChild = parentLayer;
@ -123,16 +123,16 @@
NSArray *groupItems = _layerModel.shapes; NSArray *groupItems = _layerModel.shapes;
NSArray *reversedItems = [[groupItems reverseObjectEnumerator] allObjects]; NSArray *reversedItems = [[groupItems reverseObjectEnumerator] allObjects];
LAShapeTransform *currentTransform = [LAShapeTransform transformIdentityWithCompBounds:_composition.compBounds]; LOTShapeTransform *currentTransform = [LOTShapeTransform transformIdentityWithCompBounds:_composition.compBounds];
LAShapeTrimPath *currentTrimPath = nil; LOTShapeTrimPath *currentTrimPath = nil;
LAShapeFill *currentFill = nil; LOTShapeFill *currentFill = nil;
LAShapeStroke *currentStroke = nil; LOTShapeStroke *currentStroke = nil;
NSMutableArray *shapeLayers = [NSMutableArray array]; NSMutableArray *shapeLayers = [NSMutableArray array];
for (id item in reversedItems) { for (id item in reversedItems) {
if ([item isKindOfClass:[LAShapeGroup class]]) { if ([item isKindOfClass:[LOTShapeGroup class]]) {
LAGroupLayerView *groupLayer = [[LAGroupLayerView alloc] initWithShapeGroup:(LAShapeGroup *)item LOTGroupLayerView *groupLayer = [[LOTGroupLayerView alloc] initWithShapeGroup:(LOTShapeGroup *)item
transform:currentTransform transform:currentTransform
fill:currentFill fill:currentFill
stroke:currentStroke stroke:currentStroke
@ -140,9 +140,9 @@
withDuration:self.laAnimationDuration]; withDuration:self.laAnimationDuration];
[_childContainerLayer addSublayer:groupLayer]; [_childContainerLayer addSublayer:groupLayer];
[shapeLayers addObject:groupLayer]; [shapeLayers addObject:groupLayer];
} else if ([item isKindOfClass:[LAShapePath class]]) { } else if ([item isKindOfClass:[LOTShapePath class]]) {
LAShapePath *shapePath = (LAShapePath *)item; LOTShapePath *shapePath = (LOTShapePath *)item;
LAShapeLayerView *shapeLayer = [[LAShapeLayerView alloc] initWithShape:shapePath LOTShapeLayerView *shapeLayer = [[LOTShapeLayerView alloc] initWithShape:shapePath
fill:currentFill fill:currentFill
stroke:currentStroke stroke:currentStroke
trim:currentTrimPath trim:currentTrimPath
@ -150,18 +150,18 @@
withDuration:self.laAnimationDuration]; withDuration:self.laAnimationDuration];
[shapeLayers addObject:shapeLayer]; [shapeLayers addObject:shapeLayer];
[_childContainerLayer addSublayer:shapeLayer]; [_childContainerLayer addSublayer:shapeLayer];
} else if ([item isKindOfClass:[LAShapeRectangle class]]) { } else if ([item isKindOfClass:[LOTShapeRectangle class]]) {
LAShapeRectangle *shapeRect = (LAShapeRectangle *)item; LOTShapeRectangle *shapeRect = (LOTShapeRectangle *)item;
LARectShapeLayer *shapeLayer = [[LARectShapeLayer alloc] initWithRectShape:shapeRect LOTRectShapeLayer *shapeLayer = [[LOTRectShapeLayer alloc] initWithRectShape:shapeRect
fill:currentFill fill:currentFill
stroke:currentStroke stroke:currentStroke
transform:currentTransform transform:currentTransform
withDuration:self.laAnimationDuration]; withDuration:self.laAnimationDuration];
[shapeLayers addObject:shapeLayer]; [shapeLayers addObject:shapeLayer];
[_childContainerLayer addSublayer:shapeLayer]; [_childContainerLayer addSublayer:shapeLayer];
} else if ([item isKindOfClass:[LAShapeCircle class]]) { } else if ([item isKindOfClass:[LOTShapeCircle class]]) {
LAShapeCircle *shapeCircle = (LAShapeCircle *)item; LOTShapeCircle *shapeCircle = (LOTShapeCircle *)item;
LAEllipseShapeLayer *shapeLayer = [[LAEllipseShapeLayer alloc] initWithEllipseShape:shapeCircle LOTEllipseShapeLayer *shapeLayer = [[LOTEllipseShapeLayer alloc] initWithEllipseShape:shapeCircle
fill:currentFill fill:currentFill
stroke:currentStroke stroke:currentStroke
trim:currentTrimPath trim:currentTrimPath
@ -169,21 +169,21 @@
withDuration:self.laAnimationDuration]; withDuration:self.laAnimationDuration];
[shapeLayers addObject:shapeLayer]; [shapeLayers addObject:shapeLayer];
[_childContainerLayer addSublayer:shapeLayer]; [_childContainerLayer addSublayer:shapeLayer];
} else if ([item isKindOfClass:[LAShapeTransform class]]) { } else if ([item isKindOfClass:[LOTShapeTransform class]]) {
currentTransform = (LAShapeTransform *)item; currentTransform = (LOTShapeTransform *)item;
} else if ([item isKindOfClass:[LAShapeFill class]]) { } else if ([item isKindOfClass:[LOTShapeFill class]]) {
currentFill = (LAShapeFill *)item; currentFill = (LOTShapeFill *)item;
} else if ([item isKindOfClass:[LAShapeTrimPath class]]) { } else if ([item isKindOfClass:[LOTShapeTrimPath class]]) {
currentTrimPath = (LAShapeTrimPath *)item; currentTrimPath = (LOTShapeTrimPath *)item;
} else if ([item isKindOfClass:[LAShapeStroke class]]) { } else if ([item isKindOfClass:[LOTShapeStroke class]]) {
currentStroke = (LAShapeStroke *)item; currentStroke = (LOTShapeStroke *)item;
} }
} }
_shapeLayers = shapeLayers; _shapeLayers = shapeLayers;
if (_layerModel.masks) { if (_layerModel.masks) {
_maskLayer = [[LAMaskLayer alloc] initWithMasks:_layerModel.masks inComposition:_composition]; _maskLayer = [[LOTMaskLayer alloc] initWithMasks:_layerModel.masks inComposition:_composition];
_childContainerLayer.mask = _maskLayer; _childContainerLayer.mask = _maskLayer;
} }
@ -222,7 +222,7 @@
} }
_animation = [CAAnimationGroup animationGroupForAnimatablePropertiesWithKeyPaths:keypaths]; _animation = [CAAnimationGroup LOT_animationGroupForAnimatablePropertiesWithKeyPaths:keypaths];
if (_animation) { if (_animation) {
[_childContainerLayer addAnimation:_animation forKey:@"LottieAnimation"]; [_childContainerLayer addAnimation:_animation forKey:@"LottieAnimation"];
@ -249,7 +249,7 @@
self.borderWidth = debugModeOn ? 2 : 0; self.borderWidth = debugModeOn ? 2 : 0;
self.backgroundColor = debugModeOn ? [[UIColor blueColor] colorWithAlphaComponent:0.2].CGColor : [UIColor clearColor].CGColor; self.backgroundColor = debugModeOn ? [[UIColor blueColor] colorWithAlphaComponent:0.2].CGColor : [UIColor clearColor].CGColor;
for (LAGroupLayerView *group in _shapeLayers) { for (LOTGroupLayerView *group in _shapeLayers) {
group.debugModeOn = debugModeOn; group.debugModeOn = debugModeOn;
} }
} }

View File

@ -0,0 +1,19 @@
//
// LOTMaskLayer.h
// LottieAnimator
//
// Created by brandon_withrow on 7/22/16.
// Copyright © 2016 Brandon Withrow. All rights reserved.
//
#import "LOTAnimatableLayer.h"
#import "LOTModels.h"
@interface LOTMaskLayer : LOTAnimatableLayer
- (instancetype)initWithMasks:(NSArray<LOTMask *> *)masks inComposition:(LOTComposition *)comp;
@property (nonatomic, readonly) NSArray<LOTMask *> *masks;
@end

View File

@ -1,20 +1,20 @@
// //
// LAMaskLayer.m // LOTMaskLayer.m
// LottieAnimator // LottieAnimator
// //
// Created by brandon_withrow on 7/22/16. // Created by brandon_withrow on 7/22/16.
// Copyright © 2016 Brandon Withrow. All rights reserved. // Copyright © 2016 Brandon Withrow. All rights reserved.
// //
#import "LAMaskLayer.h" #import "LOTMaskLayer.h"
#import "CAAnimationGroup+LAAnimatableGroup.h" #import "CAAnimationGroup+LOTAnimatableGroup.h"
@implementation LAMaskLayer { @implementation LOTMaskLayer {
LAComposition *_composition; LOTComposition *_composition;
NSArray *_maskLayers; NSArray *_maskLayers;
} }
- (instancetype)initWithMasks:(NSArray<LAMask *> *)masks inComposition:(LAComposition *)comp { - (instancetype)initWithMasks:(NSArray<LOTMask *> *)masks inComposition:(LOTComposition *)comp {
self = [super initWithDuration:comp.timeDuration]; self = [super initWithDuration:comp.timeDuration];
if (self) { if (self) {
_masks = masks; _masks = masks;
@ -27,13 +27,13 @@
- (void)_setupViewFromModel { - (void)_setupViewFromModel {
NSMutableArray *maskLayers = [NSMutableArray array]; NSMutableArray *maskLayers = [NSMutableArray array];
for (LAMask *mask in _masks) { for (LOTMask *mask in _masks) {
CAShapeLayer *maskLayer = [CAShapeLayer new]; CAShapeLayer *maskLayer = [CAShapeLayer new];
maskLayer.path = mask.maskPath.initialShape.CGPath; maskLayer.path = mask.maskPath.initialShape.CGPath;
maskLayer.fillColor = [UIColor whiteColor].CGColor; maskLayer.fillColor = [UIColor whiteColor].CGColor;
maskLayer.opacity = mask.opacity.initialValue.floatValue; maskLayer.opacity = mask.opacity.initialValue.floatValue;
[self addSublayer:maskLayer]; [self addSublayer:maskLayer];
CAAnimationGroup *animGroup = [CAAnimationGroup animationGroupForAnimatablePropertiesWithKeyPaths:@{@"opacity" : mask.opacity, CAAnimationGroup *animGroup = [CAAnimationGroup LOT_animationGroupForAnimatablePropertiesWithKeyPaths:@{@"opacity" : mask.opacity,
@"path" : mask.maskPath}]; @"path" : mask.maskPath}];
if (animGroup) { if (animGroup) {
[maskLayer addAnimation:animGroup forKey:@""]; [maskLayer addAnimation:animGroup forKey:@""];

View File

@ -0,0 +1,21 @@
//
// LOTRectShapeLayer.h
// LottieAnimator
//
// Created by brandon_withrow on 7/20/16.
// Copyright © 2016 Brandon Withrow. All rights reserved.
//
#import <QuartzCore/QuartzCore.h>
#import "LOTModels.h"
#import "LOTAnimatableLayer.h"
@interface LOTRectShapeLayer : LOTAnimatableLayer
- (instancetype)initWithRectShape:(LOTShapeRectangle *)rectShape
fill:(LOTShapeFill *)fill
stroke:(LOTShapeStroke *)stroke
transform:(LOTShapeTransform *)transform
withDuration:(NSTimeInterval)duration;
@end

View File

@ -1,16 +1,16 @@
// //
// LARectShapeLayer.m // LOTRectShapeLayer.m
// LottieAnimator // LottieAnimator
// //
// Created by brandon_withrow on 7/20/16. // Created by brandon_withrow on 7/20/16.
// Copyright © 2016 Brandon Withrow. All rights reserved. // Copyright © 2016 Brandon Withrow. All rights reserved.
// //
#import "LARectShapeLayer.h" #import "LOTRectShapeLayer.h"
#import "LAPlatformCompat.h" #import "LOTPlatformCompat.h"
#import "CAAnimationGroup+LAAnimatableGroup.h" #import "CAAnimationGroup+LOTAnimatableGroup.h"
@interface LARoundRectLayer : CAShapeLayer @interface LOTRoundRectLayer : CAShapeLayer
@property (nonatomic) CGPoint rectPosition; @property (nonatomic) CGPoint rectPosition;
@property (nonatomic) CGPoint rectSize; @property (nonatomic) CGPoint rectSize;
@ -18,7 +18,7 @@
@end @end
@implementation LARoundRectLayer @implementation LOTRoundRectLayer
@dynamic rectPosition; @dynamic rectPosition;
@dynamic rectSize; @dynamic rectSize;
@ -26,10 +26,10 @@
-(id)initWithLayer:(id)layer { -(id)initWithLayer:(id)layer {
if( ( self = [super initWithLayer:layer] ) ) { if( ( self = [super initWithLayer:layer] ) ) {
if ([layer isKindOfClass:[LARoundRectLayer class]]) { if ([layer isKindOfClass:[LOTRoundRectLayer class]]) {
self.rectSize = ((LARoundRectLayer *)layer).rectSize; self.rectSize = ((LOTRoundRectLayer *)layer).rectSize;
self.rectPosition = ((LARoundRectLayer *)layer).rectPosition; self.rectPosition = ((LOTRoundRectLayer *)layer).rectPosition;
self.rectCornerRadius = ((LARoundRectLayer *)layer).rectCornerRadius; self.rectCornerRadius = ((LOTRoundRectLayer *)layer).rectCornerRadius;
} }
} }
return self; return self;
@ -56,7 +56,7 @@
} }
- (void)_setPath { - (void)_setPath {
LARoundRectLayer *presentationRect = (LARoundRectLayer *)self.presentationLayer; LOTRoundRectLayer *presentationRect = (LOTRoundRectLayer *)self.presentationLayer;
if (presentationRect == nil) { if (presentationRect == nil) {
presentationRect = self; presentationRect = self;
} }
@ -75,24 +75,24 @@
@end @end
@implementation LARectShapeLayer { @implementation LOTRectShapeLayer {
LAShapeTransform *_transform; LOTShapeTransform *_transform;
LAShapeStroke *_stroke; LOTShapeStroke *_stroke;
LAShapeFill *_fill; LOTShapeFill *_fill;
LAShapeRectangle *_rectangle; LOTShapeRectangle *_rectangle;
LARoundRectLayer *_fillLayer; LOTRoundRectLayer *_fillLayer;
LARoundRectLayer *_strokeLayer; LOTRoundRectLayer *_strokeLayer;
CAAnimationGroup *_animation; CAAnimationGroup *_animation;
CAAnimationGroup *_strokeAnimation; CAAnimationGroup *_strokeAnimation;
CAAnimationGroup *_fillAnimation; CAAnimationGroup *_fillAnimation;
} }
- (instancetype)initWithRectShape:(LAShapeRectangle *)rectShape - (instancetype)initWithRectShape:(LOTShapeRectangle *)rectShape
fill:(LAShapeFill *)fill fill:(LOTShapeFill *)fill
stroke:(LAShapeStroke *)stroke stroke:(LOTShapeStroke *)stroke
transform:(LAShapeTransform *)transform transform:(LOTShapeTransform *)transform
withDuration:(NSTimeInterval)duration { withDuration:(NSTimeInterval)duration {
self = [super initWithDuration:duration]; self = [super initWithDuration:duration];
if (self) { if (self) {
@ -110,7 +110,7 @@
self.sublayerTransform = CATransform3DMakeRotation(_transform.rotation.initialValue.floatValue, 0, 0, 1); self.sublayerTransform = CATransform3DMakeRotation(_transform.rotation.initialValue.floatValue, 0, 0, 1);
if (fill) { if (fill) {
_fillLayer = [LARoundRectLayer layer]; _fillLayer = [LOTRoundRectLayer layer];
_fillLayer.allowsEdgeAntialiasing = YES; _fillLayer.allowsEdgeAntialiasing = YES;
_fillLayer.fillColor = _fill.color.initialColor.CGColor; _fillLayer.fillColor = _fill.color.initialColor.CGColor;
_fillLayer.opacity = _fill.opacity.initialValue.floatValue; _fillLayer.opacity = _fill.opacity.initialValue.floatValue;
@ -121,7 +121,7 @@
} }
if (stroke) { if (stroke) {
_strokeLayer = [LARoundRectLayer layer]; _strokeLayer = [LOTRoundRectLayer layer];
_strokeLayer.allowsEdgeAntialiasing = YES; _strokeLayer.allowsEdgeAntialiasing = YES;
_strokeLayer.strokeColor = _stroke.color.initialColor.CGColor; _strokeLayer.strokeColor = _stroke.color.initialColor.CGColor;
_strokeLayer.opacity = _stroke.opacity.initialValue.floatValue; _strokeLayer.opacity = _stroke.opacity.initialValue.floatValue;
@ -129,18 +129,18 @@
_strokeLayer.fillColor = nil; _strokeLayer.fillColor = nil;
_strokeLayer.backgroundColor = nil; _strokeLayer.backgroundColor = nil;
_strokeLayer.lineDashPattern = _stroke.lineDashPattern; _strokeLayer.lineDashPattern = _stroke.lineDashPattern;
_strokeLayer.lineCap = _stroke.capType == LALineCapTypeRound ? kCALineCapRound : kCALineCapButt; _strokeLayer.lineCap = _stroke.capType == LOTLineCapTypeRound ? kCALineCapRound : kCALineCapButt;
_strokeLayer.rectCornerRadius = rectShape.cornerRadius.initialValue.floatValue; _strokeLayer.rectCornerRadius = rectShape.cornerRadius.initialValue.floatValue;
_strokeLayer.rectSize = rectShape.size.initialPoint; _strokeLayer.rectSize = rectShape.size.initialPoint;
_strokeLayer.rectPosition = rectShape.position.initialPoint; _strokeLayer.rectPosition = rectShape.position.initialPoint;
switch (_stroke.joinType) { switch (_stroke.joinType) {
case LALineJoinTypeBevel: case LOTLineJoinTypeBevel:
_strokeLayer.lineJoin = kCALineJoinBevel; _strokeLayer.lineJoin = kCALineJoinBevel;
break; break;
case LALineJoinTypeMiter: case LOTLineJoinTypeMiter:
_strokeLayer.lineJoin = kCALineJoinMiter; _strokeLayer.lineJoin = kCALineJoinMiter;
break; break;
case LALineJoinTypeRound: case LOTLineJoinTypeRound:
_strokeLayer.lineJoin = kCALineJoinRound; _strokeLayer.lineJoin = kCALineJoinRound;
break; break;
default: default:
@ -161,7 +161,7 @@
- (void)_buildAnimation { - (void)_buildAnimation {
if (_transform) { if (_transform) {
_animation = [CAAnimationGroup animationGroupForAnimatablePropertiesWithKeyPaths:@{@"opacity" : _transform.opacity, _animation = [CAAnimationGroup LOT_animationGroupForAnimatablePropertiesWithKeyPaths:@{@"opacity" : _transform.opacity,
@"position" : _transform.position, @"position" : _transform.position,
@"anchorPoint" : _transform.anchor, @"anchorPoint" : _transform.anchor,
@"transform" : _transform.scale, @"transform" : _transform.scale,
@ -170,7 +170,7 @@
} }
if (_stroke) { if (_stroke) {
_strokeAnimation = [CAAnimationGroup animationGroupForAnimatablePropertiesWithKeyPaths:@{@"strokeColor" : _stroke.color, _strokeAnimation = [CAAnimationGroup LOT_animationGroupForAnimatablePropertiesWithKeyPaths:@{@"strokeColor" : _stroke.color,
@"opacity" : _stroke.opacity, @"opacity" : _stroke.opacity,
@"lineWidth" : _stroke.width, @"lineWidth" : _stroke.width,
@"rectSize" : _rectangle.size, @"rectSize" : _rectangle.size,
@ -181,7 +181,7 @@
} }
if (_fill) { if (_fill) {
_fillAnimation = [CAAnimationGroup animationGroupForAnimatablePropertiesWithKeyPaths:@{@"fillColor" : _fill.color, _fillAnimation = [CAAnimationGroup LOT_animationGroupForAnimatablePropertiesWithKeyPaths:@{@"fillColor" : _fill.color,
@"opacity" : _fill.opacity, @"opacity" : _fill.opacity,
@"rectSize" : _rectangle.size, @"rectSize" : _rectangle.size,
@"rectPosition" : _rectangle.position, @"rectPosition" : _rectangle.position,

View File

@ -0,0 +1,21 @@
//
// LOTShapeLayerView.h
// LottieAnimator
//
// Created by Brandon Withrow on 7/13/16.
// Copyright © 2016 Brandon Withrow. All rights reserved.
//
#import "LOTAnimatableLayer.h"
#import "LOTModels.h"
@interface LOTShapeLayerView : LOTAnimatableLayer
- (instancetype)initWithShape:(LOTShapePath *)shape
fill:(LOTShapeFill *)fill
stroke:(LOTShapeStroke *)stroke
trim:(LOTShapeTrimPath *)trim
transform:(LOTShapeTransform *)transform
withDuration:(NSTimeInterval)duration;
@end

View File

@ -1,20 +1,20 @@
// //
// LAShapeLayerView.m // LOTShapeLayerView.m
// LottieAnimator // LottieAnimator
// //
// Created by Brandon Withrow on 7/13/16. // Created by Brandon Withrow on 7/13/16.
// Copyright © 2016 Brandon Withrow. All rights reserved. // Copyright © 2016 Brandon Withrow. All rights reserved.
// //
#import "LAShapeLayerView.h" #import "LOTShapeLayerView.h"
#import "CAAnimationGroup+LAAnimatableGroup.h" #import "CAAnimationGroup+LOTAnimatableGroup.h"
@implementation LAShapeLayerView { @implementation LOTShapeLayerView {
LAShapeTransform *_transform; LOTShapeTransform *_transform;
LAShapeStroke *_stroke; LOTShapeStroke *_stroke;
LAShapeFill *_fill; LOTShapeFill *_fill;
LAShapePath *_path; LOTShapePath *_path;
LAShapeTrimPath *_trim; LOTShapeTrimPath *_trim;
CAShapeLayer *_fillLayer; CAShapeLayer *_fillLayer;
CAShapeLayer *_strokeLayer; CAShapeLayer *_strokeLayer;
@ -24,11 +24,11 @@
CAAnimationGroup *_fillAnimation; CAAnimationGroup *_fillAnimation;
} }
- (instancetype)initWithShape:(LAShapePath *)shape - (instancetype)initWithShape:(LOTShapePath *)shape
fill:(LAShapeFill *)fill fill:(LOTShapeFill *)fill
stroke:(LAShapeStroke *)stroke stroke:(LOTShapeStroke *)stroke
trim:(LAShapeTrimPath *)trim trim:(LOTShapeTrimPath *)trim
transform:(LAShapeTransform *)transform transform:(LOTShapeTransform *)transform
withDuration:(NSTimeInterval)duration { withDuration:(NSTimeInterval)duration {
self = [super initWithDuration:duration]; self = [super initWithDuration:duration];
if (self) { if (self) {
@ -63,15 +63,15 @@
_strokeLayer.opacity = _stroke.opacity.initialValue.floatValue; _strokeLayer.opacity = _stroke.opacity.initialValue.floatValue;
_strokeLayer.lineWidth = _stroke.width.initialValue.floatValue; _strokeLayer.lineWidth = _stroke.width.initialValue.floatValue;
_strokeLayer.lineDashPattern = _stroke.lineDashPattern; _strokeLayer.lineDashPattern = _stroke.lineDashPattern;
_strokeLayer.lineCap = _stroke.capType == LALineCapTypeRound ? kCALineCapRound : kCALineCapButt; _strokeLayer.lineCap = _stroke.capType == LOTLineCapTypeRound ? kCALineCapRound : kCALineCapButt;
switch (_stroke.joinType) { switch (_stroke.joinType) {
case LALineJoinTypeBevel: case LOTLineJoinTypeBevel:
_strokeLayer.lineJoin = kCALineJoinBevel; _strokeLayer.lineJoin = kCALineJoinBevel;
break; break;
case LALineJoinTypeMiter: case LOTLineJoinTypeMiter:
_strokeLayer.lineJoin = kCALineJoinMiter; _strokeLayer.lineJoin = kCALineJoinMiter;
break; break;
case LALineJoinTypeRound: case LOTLineJoinTypeRound:
_strokeLayer.lineJoin = kCALineJoinRound; _strokeLayer.lineJoin = kCALineJoinRound;
break; break;
default: default:
@ -93,7 +93,7 @@
- (void)_buildAnimation { - (void)_buildAnimation {
if (_transform) { if (_transform) {
_animation = [CAAnimationGroup animationGroupForAnimatablePropertiesWithKeyPaths:@{@"opacity" : _transform.opacity, _animation = [CAAnimationGroup LOT_animationGroupForAnimatablePropertiesWithKeyPaths:@{@"opacity" : _transform.opacity,
@"position" : _transform.position, @"position" : _transform.position,
@"anchorPoint" : _transform.anchor, @"anchorPoint" : _transform.anchor,
@"transform" : _transform.scale, @"transform" : _transform.scale,
@ -110,12 +110,12 @@
properties[@"strokeStart"] = _trim.start; properties[@"strokeStart"] = _trim.start;
properties[@"strokeEnd"] = _trim.end; properties[@"strokeEnd"] = _trim.end;
} }
_strokeAnimation = [CAAnimationGroup animationGroupForAnimatablePropertiesWithKeyPaths:properties]; _strokeAnimation = [CAAnimationGroup LOT_animationGroupForAnimatablePropertiesWithKeyPaths:properties];
[_strokeLayer addAnimation:_strokeAnimation forKey:@""]; [_strokeLayer addAnimation:_strokeAnimation forKey:@""];
} }
if (_fill) { if (_fill) {
_fillAnimation = [CAAnimationGroup animationGroupForAnimatablePropertiesWithKeyPaths:@{@"fillColor" : _fill.color, _fillAnimation = [CAAnimationGroup LOT_animationGroupForAnimatablePropertiesWithKeyPaths:@{@"fillColor" : _fill.color,
@"opacity" : _fill.opacity, @"opacity" : _fill.opacity,
@"path" : _path.shapePath}]; @"path" : _path.shapePath}];
[_fillLayer addAnimation:_fillAnimation forKey:@""]; [_fillLayer addAnimation:_fillAnimation forKey:@""];

View File

@ -1,5 +1,5 @@
// //
// LAAnimatableBoundsValue.h // LOTAnimatableBoundsValue.h
// LottieAnimator // LottieAnimator
// //
// Created by brandon_withrow on 7/20/16. // Created by brandon_withrow on 7/20/16.
@ -8,9 +8,9 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import <QuartzCore/QuartzCore.h> #import <QuartzCore/QuartzCore.h>
#import "LAAnimatableValue.h" #import "LOTAnimatableValue.h"
@interface LAAnimatableBoundsValue : NSObject <LAAnimatableValue> @interface LOTAnimatableBoundsValue : NSObject <LOTAnimatableValue>
- (instancetype)initWithSizeValues:(NSDictionary *)sizeValue frameRate:(NSNumber *)frameRate; - (instancetype)initWithSizeValues:(NSDictionary *)sizeValue frameRate:(NSNumber *)frameRate;

View File

@ -1,15 +1,15 @@
// //
// LAAnimatableBoundsValue.m // LOTAnimatableBoundsValue.m
// LottieAnimator // LottieAnimator
// //
// Created by brandon_withrow on 7/20/16. // Created by brandon_withrow on 7/20/16.
// Copyright © 2016 Brandon Withrow. All rights reserved. // Copyright © 2016 Brandon Withrow. All rights reserved.
// //
#import "LAPlatformCompat.h" #import "LOTPlatformCompat.h"
#import "LAAnimatableBoundsValue.h" #import "LOTAnimatableBoundsValue.h"
@interface LAAnimatableBoundsValue () @interface LOTAnimatableBoundsValue ()
@property (nonatomic, readonly) NSArray *boundsKeyframes; @property (nonatomic, readonly) NSArray *boundsKeyframes;
@property (nonatomic, readonly) NSArray<NSNumber *> *keyTimes; @property (nonatomic, readonly) NSArray<NSNumber *> *keyTimes;
@ -22,7 +22,7 @@
@end @end
@implementation LAAnimatableBoundsValue @implementation LOTAnimatableBoundsValue
- (instancetype)initWithSizeValues:(NSDictionary *)sizeValue frameRate:(NSNumber *)frameRate { - (instancetype)initWithSizeValues:(NSDictionary *)sizeValue frameRate:(NSNumber *)frameRate {
self = [super init]; self = [super init];

View File

@ -1,5 +1,5 @@
// //
// LAAnimatableColorValue.h // LOTAnimatableColorValue.h
// LottieAnimator // LottieAnimator
// //
// Created by brandon_withrow on 6/23/16. // Created by brandon_withrow on 6/23/16.
@ -8,10 +8,10 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import <QuartzCore/QuartzCore.h> #import <QuartzCore/QuartzCore.h>
#import "LAAnimatableValue.h" #import "LOTAnimatableValue.h"
#import "LAPlatformCompat.h" #import "LOTPlatformCompat.h"
@interface LAAnimatableColorValue : NSObject <LAAnimatableValue> @interface LOTAnimatableColorValue : NSObject <LOTAnimatableValue>
- (instancetype)initWithColorValues:(NSDictionary *)colorValues frameRate:(NSNumber *)frameRate; - (instancetype)initWithColorValues:(NSDictionary *)colorValues frameRate:(NSNumber *)frameRate;

View File

@ -1,14 +1,14 @@
// //
// LAAnimatableColorValue.m // LOTAnimatableColorValue.m
// LottieAnimator // LottieAnimator
// //
// Created by brandon_withrow on 6/23/16. // Created by brandon_withrow on 6/23/16.
// Copyright © 2016 Brandon Withrow. All rights reserved. // Copyright © 2016 Brandon Withrow. All rights reserved.
// //
#import "LAAnimatableColorValue.h" #import "LOTAnimatableColorValue.h"
@interface LAAnimatableColorValue () @interface LOTAnimatableColorValue ()
@property (nonatomic, readonly) NSArray *colorKeyframes; @property (nonatomic, readonly) NSArray *colorKeyframes;
@property (nonatomic, readonly) NSArray<NSNumber *> *keyTimes; @property (nonatomic, readonly) NSArray<NSNumber *> *keyTimes;
@ -22,7 +22,7 @@
@end @end
@implementation LAAnimatableColorValue @implementation LOTAnimatableColorValue
- (instancetype)initWithColorValues:(NSDictionary *)colorValues frameRate:(NSNumber *)frameRate { - (instancetype)initWithColorValues:(NSDictionary *)colorValues frameRate:(NSNumber *)frameRate {
self = [super init]; self = [super init];

View File

@ -1,5 +1,5 @@
// //
// LAAnimatableNumberValue.h // LOTAnimatableNumberValue.h
// LottieAnimator // LottieAnimator
// //
// Created by brandon_withrow on 6/23/16. // Created by brandon_withrow on 6/23/16.
@ -8,9 +8,9 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import <CoreGraphics/CoreGraphics.h> #import <CoreGraphics/CoreGraphics.h>
#import "LAAnimatableValue.h" #import "LOTAnimatableValue.h"
@interface LAAnimatableNumberValue : NSObject <LAAnimatableValue> @interface LOTAnimatableNumberValue : NSObject <LOTAnimatableValue>
- (instancetype)initWithNumberValues:(NSDictionary *)numberValues frameRate:(NSNumber *)frameRate; - (instancetype)initWithNumberValues:(NSDictionary *)numberValues frameRate:(NSNumber *)frameRate;
- (void)remapValuesFromMin:(NSNumber *)fromMin - (void)remapValuesFromMin:(NSNumber *)fromMin

View File

@ -1,15 +1,15 @@
// //
// LAAnimatableNumberValue.m // LOTAnimatableNumberValue.m
// LottieAnimator // LottieAnimator
// //
// Created by brandon_withrow on 6/23/16. // Created by brandon_withrow on 6/23/16.
// Copyright © 2016 Brandon Withrow. All rights reserved. // Copyright © 2016 Brandon Withrow. All rights reserved.
// //
#import "LAAnimatableNumberValue.h" #import "LOTAnimatableNumberValue.h"
#import "LAHelpers.h" #import "LOTHelpers.h"
@interface LAAnimatableNumberValue () @interface LOTAnimatableNumberValue ()
@property (nonatomic, readonly) NSArray<NSNumber *> *valueKeyframes; @property (nonatomic, readonly) NSArray<NSNumber *> *valueKeyframes;
@property (nonatomic, readonly) NSArray<NSNumber *> *keyTimes; @property (nonatomic, readonly) NSArray<NSNumber *> *keyTimes;
@ -22,7 +22,7 @@
@end @end
@implementation LAAnimatableNumberValue @implementation LOTAnimatableNumberValue
- (instancetype)initWithNumberValues:(NSDictionary *)numberValues frameRate:(NSNumber *)frameRate { - (instancetype)initWithNumberValues:(NSDictionary *)numberValues frameRate:(NSNumber *)frameRate {
self = [super init]; self = [super init];

View File

@ -1,5 +1,5 @@
// //
// LAAnimatablePointValue.h // LOTAnimatablePointValue.h
// LottieAnimator // LottieAnimator
// //
// Created by brandon_withrow on 6/23/16. // Created by brandon_withrow on 6/23/16.
@ -8,9 +8,9 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import <CoreGraphics/CoreGraphics.h> #import <CoreGraphics/CoreGraphics.h>
#import "LAAnimatableValue.h" #import "LOTAnimatableValue.h"
@interface LAAnimatablePointValue : NSObject <LAAnimatableValue> @interface LOTAnimatablePointValue : NSObject <LOTAnimatableValue>
- (instancetype)initWithPointValues:(NSDictionary *)pointValues frameRate:(NSNumber *)frameRate; - (instancetype)initWithPointValues:(NSDictionary *)pointValues frameRate:(NSNumber *)frameRate;
- (void)remapPointsFromBounds:(CGRect)frombounds toBounds:(CGRect)toBounds; - (void)remapPointsFromBounds:(CGRect)frombounds toBounds:(CGRect)toBounds;

View File

@ -1,16 +1,16 @@
// //
// LAAnimatablePointValue.m // LOTAnimatablePointValue.m
// LottieAnimator // LottieAnimator
// //
// Created by brandon_withrow on 6/23/16. // Created by brandon_withrow on 6/23/16.
// Copyright © 2016 Brandon Withrow. All rights reserved. // Copyright © 2016 Brandon Withrow. All rights reserved.
// //
#import "LAPlatformCompat.h" #import "LOTPlatformCompat.h"
#import "LAAnimatablePointValue.h" #import "LOTAnimatablePointValue.h"
#import "CGGeometryAdditions.h" #import "CGGeometryAdditions.h"
@interface LAAnimatablePointValue () @interface LOTAnimatablePointValue ()
@property (nonatomic, readonly) UIBezierPath *animationPath; @property (nonatomic, readonly) UIBezierPath *animationPath;
@property (nonatomic, readonly) NSArray<NSValue *> *pointKeyframes; @property (nonatomic, readonly) NSArray<NSValue *> *pointKeyframes;
@ -24,7 +24,7 @@
@end @end
@implementation LAAnimatablePointValue @implementation LOTAnimatablePointValue
- (instancetype)initWithPointValues:(NSDictionary *)pointValues frameRate:(NSNumber *)frameRate { - (instancetype)initWithPointValues:(NSDictionary *)pointValues frameRate:(NSNumber *)frameRate {
self = [super init]; self = [super init];

View File

@ -1,5 +1,5 @@
// //
// LAAnimatableScaleValue.h // LOTAnimatableScaleValue.h
// LottieAnimator // LottieAnimator
// //
// Created by brandon_withrow on 7/11/16. // Created by brandon_withrow on 7/11/16.
@ -7,9 +7,9 @@
// //
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import "LAAnimatableValue.h" #import "LOTAnimatableValue.h"
@interface LAAnimatableScaleValue : NSObject <LAAnimatableValue> @interface LOTAnimatableScaleValue : NSObject <LOTAnimatableValue>
- (instancetype)initWithScaleValues:(NSDictionary *)scaleValues frameRate:(NSNumber *)frameRate; - (instancetype)initWithScaleValues:(NSDictionary *)scaleValues frameRate:(NSNumber *)frameRate;

View File

@ -1,14 +1,14 @@
// //
// LAAnimatableScaleValue.m // LOTAnimatableScaleValue.m
// LottieAnimator // LottieAnimator
// //
// Created by brandon_withrow on 7/11/16. // Created by brandon_withrow on 7/11/16.
// Copyright © 2016 Brandon Withrow. All rights reserved. // Copyright © 2016 Brandon Withrow. All rights reserved.
// //
#import "LAAnimatableScaleValue.h" #import "LOTAnimatableScaleValue.h"
@interface LAAnimatableScaleValue () @interface LOTAnimatableScaleValue ()
@property (nonatomic, readonly) NSArray<NSValue *> *scaleKeyframes; @property (nonatomic, readonly) NSArray<NSValue *> *scaleKeyframes;
@property (nonatomic, readonly) NSArray<NSNumber *> *keyTimes; @property (nonatomic, readonly) NSArray<NSNumber *> *keyTimes;
@ -22,7 +22,7 @@
@end @end
@implementation LAAnimatableScaleValue @implementation LOTAnimatableScaleValue
- (instancetype)initWithScaleValues:(NSDictionary *)scaleValues frameRate:(NSNumber *)frameRate { - (instancetype)initWithScaleValues:(NSDictionary *)scaleValues frameRate:(NSNumber *)frameRate {
self = [super init]; self = [super init];

View File

@ -1,5 +1,5 @@
// //
// LAAnimatableShapeValue.h // LOTAnimatableShapeValue.h
// LottieAnimator // LottieAnimator
// //
// Created by brandon_withrow on 6/23/16. // Created by brandon_withrow on 6/23/16.
@ -7,10 +7,10 @@
// //
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import "LAPlatformCompat.h" #import "LOTPlatformCompat.h"
#import "LAAnimatableValue.h" #import "LOTAnimatableValue.h"
@interface LAAnimatableShapeValue : NSObject <LAAnimatableValue> @interface LOTAnimatableShapeValue : NSObject <LOTAnimatableValue>
- (instancetype)initWithShapeValues:(NSDictionary *)shapeValues frameRate:(NSNumber *)frameRate closed:(BOOL)closed; - (instancetype)initWithShapeValues:(NSDictionary *)shapeValues frameRate:(NSNumber *)frameRate closed:(BOOL)closed;

View File

@ -1,14 +1,14 @@
// //
// LAAnimatableShapeValue.m // LOTAnimatableShapeValue.m
// LottieAnimator // LottieAnimator
// //
// Created by brandon_withrow on 6/23/16. // Created by brandon_withrow on 6/23/16.
// Copyright © 2016 Brandon Withrow. All rights reserved. // Copyright © 2016 Brandon Withrow. All rights reserved.
// //
#import "LAAnimatableShapeValue.h" #import "LOTAnimatableShapeValue.h"
#import "CGGeometryAdditions.h" #import "CGGeometryAdditions.h"
@interface LAAnimatableShapeValue () @interface LOTAnimatableShapeValue ()
@property (nonatomic, readonly) NSArray *shapeKeyframes; @property (nonatomic, readonly) NSArray *shapeKeyframes;
@property (nonatomic, readonly) NSArray<NSNumber *> *keyTimes; @property (nonatomic, readonly) NSArray<NSNumber *> *keyTimes;
@ -21,7 +21,7 @@
@end @end
@implementation LAAnimatableShapeValue @implementation LOTAnimatableShapeValue
- (instancetype)initWithShapeValues:(NSDictionary *)shapeValues frameRate:(NSNumber *)frameRate closed:(BOOL)closed { - (instancetype)initWithShapeValues:(NSDictionary *)shapeValues frameRate:(NSNumber *)frameRate closed:(BOOL)closed {
self = [super init]; self = [super init];

View File

@ -1,5 +1,5 @@
// //
// LAAnimatableValue.h // LOTAnimatableValue.h
// LottieAnimator // LottieAnimator
// //
// Created by brandon_withrow on 7/19/16. // Created by brandon_withrow on 7/19/16.
@ -9,7 +9,7 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import <QuartzCore/QuartzCore.h> #import <QuartzCore/QuartzCore.h>
@protocol LAAnimatableValue <NSObject> @protocol LOTAnimatableValue <NSObject>
- (CAKeyframeAnimation *)animationForKeyPath:(NSString *)keypath; - (CAKeyframeAnimation *)animationForKeyPath:(NSString *)keypath;
- (BOOL)hasAnimation; - (BOOL)hasAnimation;

View File

@ -0,0 +1,20 @@
//
// LOTAnimationCache.h
// Lottie
//
// Created by Brandon Withrow on 1/9/17.
// Copyright © 2017 Brandon Withrow. All rights reserved.
//
#import <Foundation/Foundation.h>
@class LOTComposition;
@interface LOTAnimationCache : NSObject
+ (instancetype)sharedCache;
- (void)addAnimation:(LOTComposition *)animation forKey:(NSString *)key;
- (LOTComposition *)animationForKey:(NSString *)key;
@end

View File

@ -1,22 +1,22 @@
// //
// LAAnimationCache.m // LOTAnimationCache.m
// Lottie // Lottie
// //
// Created by Brandon Withrow on 1/9/17. // Created by Brandon Withrow on 1/9/17.
// Copyright © 2017 Brandon Withrow. All rights reserved. // Copyright © 2017 Brandon Withrow. All rights reserved.
// //
#import "LAAnimationCache.h" #import "LOTAnimationCache.h"
const NSInteger kLACacheSize = 50; const NSInteger kLOTCacheSize = 50;
@implementation LAAnimationCache { @implementation LOTAnimationCache {
NSMutableDictionary *animationsCache_; NSMutableDictionary *animationsCache_;
NSMutableArray *lruOrderArray_; NSMutableArray *lruOrderArray_;
} }
+ (instancetype)sharedCache { + (instancetype)sharedCache {
static LAAnimationCache *sharedCache = nil; static LOTAnimationCache *sharedCache = nil;
static dispatch_once_t onceToken; static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{ dispatch_once(&onceToken, ^{
sharedCache = [[self alloc] init]; sharedCache = [[self alloc] init];
@ -33,8 +33,8 @@ const NSInteger kLACacheSize = 50;
return self; return self;
} }
- (void)addAnimation:(LAComposition *)animation forKey:(NSString *)key { - (void)addAnimation:(LOTComposition *)animation forKey:(NSString *)key {
if (lruOrderArray_.count >= kLACacheSize) { if (lruOrderArray_.count >= kLOTCacheSize) {
NSString *oldKey = lruOrderArray_[0]; NSString *oldKey = lruOrderArray_[0];
[animationsCache_ removeObjectForKey:oldKey]; [animationsCache_ removeObjectForKey:oldKey];
[lruOrderArray_ removeObject:oldKey]; [lruOrderArray_ removeObject:oldKey];
@ -44,8 +44,8 @@ const NSInteger kLACacheSize = 50;
[animationsCache_ setObject:animation forKey:key]; [animationsCache_ setObject:animation forKey:key];
} }
- (LAComposition *)animationForKey:(NSString *)key { - (LOTComposition *)animationForKey:(NSString *)key {
LAComposition *animation = [animationsCache_ objectForKey:key]; LOTComposition *animation = [animationsCache_ objectForKey:key];
[lruOrderArray_ removeObject:key]; [lruOrderArray_ removeObject:key];
[lruOrderArray_ addObject:key]; [lruOrderArray_ addObject:key];
return animation; return animation;

View File

@ -1,16 +0,0 @@
//
// CAAnimationGroup+LAAnimatableGroup.h
// LottieAnimator
//
// Created by brandon_withrow on 7/19/16.
// Copyright © 2016 Brandon Withrow. All rights reserved.
//
#import <QuartzCore/QuartzCore.h>
#import "LAAnimatableValue.h"
@interface CAAnimationGroup (LAAnimatableGroup)
+ (nullable CAAnimationGroup *)animationGroupForAnimatablePropertiesWithKeyPaths:(nonnull NSDictionary<NSString *, id<LAAnimatableValue>> *)properties;
@end

View File

@ -0,0 +1,16 @@
//
// CAAnimationGroup+LOTAnimatableGroup.h
// LottieAnimator
//
// Created by brandon_withrow on 7/19/16.
// Copyright © 2016 Brandon Withrow. All rights reserved.
//
#import <QuartzCore/QuartzCore.h>
#import "LOTAnimatableValue.h"
@interface CAAnimationGroup (LOTAnimatableGroup)
+ (nullable CAAnimationGroup *)LOT_animationGroupForAnimatablePropertiesWithKeyPaths:(nonnull NSDictionary<NSString *, id<LOTAnimatableValue>> *)properties;
@end

View File

@ -1,20 +1,20 @@
// //
// CAAnimationGroup+LAAnimatableGroup.m // CAAnimationGroup+LOTAnimatableGroup.m
// LottieAnimator // LottieAnimator
// //
// Created by brandon_withrow on 7/19/16. // Created by brandon_withrow on 7/19/16.
// Copyright © 2016 Brandon Withrow. All rights reserved. // Copyright © 2016 Brandon Withrow. All rights reserved.
// //
#import "CAAnimationGroup+LAAnimatableGroup.h" #import "CAAnimationGroup+LOTAnimatableGroup.h"
@implementation CAAnimationGroup (LAAnimatableGroup) @implementation CAAnimationGroup (LOTAnimatableGroup)
+ (nullable CAAnimationGroup *)animationGroupForAnimatablePropertiesWithKeyPaths:(nonnull NSDictionary<NSString *, id<LAAnimatableValue>> *)properties { + (nullable CAAnimationGroup *)LOT_animationGroupForAnimatablePropertiesWithKeyPaths:(nonnull NSDictionary<NSString *, id<LOTAnimatableValue>> *)properties {
NSMutableArray *animations = [NSMutableArray array]; NSMutableArray *animations = [NSMutableArray array];
NSTimeInterval animduration = 0; NSTimeInterval animduration = 0;
for (NSString *keyPath in properties.allKeys) { for (NSString *keyPath in properties.allKeys) {
id <LAAnimatableValue>property = properties[keyPath]; id <LOTAnimatableValue>property = properties[keyPath];
if ([property hasAnimation]) { if ([property hasAnimation]) {
CAKeyframeAnimation *animation = [property animationForKeyPath:keyPath]; CAKeyframeAnimation *animation = [property animationForKeyPath:keyPath];
[animations addObject:animation]; [animations addObject:animation];

View File

@ -1,5 +1,5 @@
#import "LAPlatformCompat.h" #import "LOTPlatformCompat.h"
#import <CoreGraphics/CoreGraphics.h> #import <CoreGraphics/CoreGraphics.h>
#import <GLKit/GLKMathTypes.h> #import <GLKit/GLKMathTypes.h>
#import <GLKit/GLKit.h> #import <GLKit/GLKit.h>

View File

@ -1,15 +1,15 @@
// //
// LAHelpers.h // LOTHelpers.h
// Lottie // Lottie
// //
// Created by Brandon Withrow on 7/28/16. // Created by Brandon Withrow on 7/28/16.
// Copyright © 2016 Brandon Withrow. All rights reserved. // Copyright © 2016 Brandon Withrow. All rights reserved.
// //
#ifndef LAHelpers_h #ifndef LOTHelpers_h
#define LAHelpers_h #define LOTHelpers_h
#import "UIColor+Expanded.h" #import "UIColor+Expanded.h"
#import "CGGeometryAdditions.h" #import "CGGeometryAdditions.h"
#endif /* LAHelpers_h */ #endif /* LOTHelpers_h */

View File

@ -0,0 +1,51 @@
#import "LOTPlatformCompat.h"
// From http://github.com/ars/uicolor-utilities
#define CLAMP(val,min,max) MIN(MAX(val,min),max)
@interface UIColor (UIColor_Expanded)
@property (nonatomic, readonly) CGColorSpaceModel colorSpaceModel;
@property (nonatomic, readonly) BOOL canProvideRGBComponents;
@property (nonatomic, readonly) CGFloat red; // Only valid if canProvideRGBComponents is YES
@property (nonatomic, readonly) CGFloat green; // Only valid if canProvideRGBComponents is YES
@property (nonatomic, readonly) CGFloat blue; // Only valid if canProvideRGBComponents is YES
@property (nonatomic, readonly) CGFloat white; // Only valid if colorSpaceModel == kCGColorSpaceModelMonochrome
@property (nonatomic, readonly) CGFloat alpha;
@property (nonatomic, readonly) UInt32 rgbHex;
- (NSString *)LOT_colorSpaceString;
- (NSArray *)LOT_arrayFromRGBAComponents;
- (BOOL)LOT_red:(CGFloat *)r green:(CGFloat *)g blue:(CGFloat *)b alpha:(CGFloat *)a;
- (UIColor *)LOT_colorByLuminanceMapping;
- (UIColor *)LOT_colorByMultiplyingByRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha;
- (UIColor *) LOT_colorByAddingRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha;
- (UIColor *) LOT_colorByLighteningToRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha;
- (UIColor *) LOT_colorByDarkeningToRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha;
- (UIColor *)LOT_colorByMultiplyingBy:(CGFloat)f;
- (UIColor *) LOT_colorByAdding:(CGFloat)f;
- (UIColor *) LOT_colorByLighteningTo:(CGFloat)f;
- (UIColor *) LOT_colorByDarkeningTo:(CGFloat)f;
- (UIColor *)LOT_colorByMultiplyingByColor:(UIColor *)color;
- (UIColor *) LOT_colorByAddingColor:(UIColor *)color;
- (UIColor *) LOT_colorByLighteningToColor:(UIColor *)color;
- (UIColor *) LOT_colorByDarkeningToColor:(UIColor *)color;
- (NSString *)LOT_stringFromColor;
- (NSString *)LOT_hexStringValue;
+ (UIColor *)LOT_randomColor;
+ (UIColor *)LOT_colorWithString:(NSString *)stringToConvert;
+ (UIColor *)LOT_colorWithRGBHex:(UInt32)hex;
+ (UIColor *)LOT_colorWithHexString:(NSString *)stringToConvert;
+ (UIColor *)LOT_colorWithName:(NSString *)cssColorName;
+ (UIColor *)LOT_colorByLerpingFromColor:(UIColor *)fromColor toColor:(UIColor *)toColor amount:(CGFloat)amount;
@end

View File

@ -31,7 +31,7 @@
}; };
*/ */
// Static cache of looked up color names. Used with +colorWithName: // Static cache of looked up color names. Used with +LOT_colorWithName:
static NSMutableDictionary *colorNameCache = nil; static NSMutableDictionary *colorNameCache = nil;
@interface UIColor (UIColor_Expanded_Support) @interface UIColor (UIColor_Expanded_Support)
@ -46,7 +46,7 @@ static NSMutableDictionary *colorNameCache = nil;
return CGColorSpaceGetModel(CGColorGetColorSpace(self.CGColor)); return CGColorSpaceGetModel(CGColorGetColorSpace(self.CGColor));
} }
- (NSString *)colorSpaceString { - (NSString *)LOT_colorSpaceString {
switch (self.colorSpaceModel) { switch (self.colorSpaceModel) {
case kCGColorSpaceModelUnknown: case kCGColorSpaceModelUnknown:
return @"kCGColorSpaceModelUnknown"; return @"kCGColorSpaceModelUnknown";
@ -79,11 +79,11 @@ static NSMutableDictionary *colorNameCache = nil;
} }
} }
- (NSArray *)arrayFromRGBAComponents { - (NSArray *)LOT_arrayFromRGBAComponents {
NSAssert(self.canProvideRGBComponents, @"Must be an RGB color to use -arrayFromRGBAComponents"); NSAssert(self.canProvideRGBComponents, @"Must be an RGB color to use -LOT_arrayFromRGBAComponents");
CGFloat r,g,b,a; CGFloat r,g,b,a;
if (![self red:&r green:&g blue:&b alpha:&a]) return nil; if (![self LOT_red:&r green:&g blue:&b alpha:&a]) return nil;
return [NSArray arrayWithObjects: return [NSArray arrayWithObjects:
[NSNumber numberWithFloat:r], [NSNumber numberWithFloat:r],
@ -93,7 +93,7 @@ static NSMutableDictionary *colorNameCache = nil;
nil]; nil];
} }
- (BOOL)red:(CGFloat *)red green:(CGFloat *)green blue:(CGFloat *)blue alpha:(CGFloat *)alpha { - (BOOL)LOT_red:(CGFloat *)red green:(CGFloat *)green blue:(CGFloat *)blue alpha:(CGFloat *)alpha {
const CGFloat *components = CGColorGetComponents(self.CGColor); const CGFloat *components = CGColorGetComponents(self.CGColor);
CGFloat r,g,b,a; CGFloat r,g,b,a;
@ -155,7 +155,7 @@ static NSMutableDictionary *colorNameCache = nil;
NSAssert(self.canProvideRGBComponents, @"Must be a RGB color to use rgbHex"); NSAssert(self.canProvideRGBComponents, @"Must be a RGB color to use rgbHex");
CGFloat r,g,b,a; CGFloat r,g,b,a;
if (![self red:&r green:&g blue:&b alpha:&a]) return 0; if (![self LOT_red:&r green:&g blue:&b alpha:&a]) return 0;
r = MIN(MAX(self.red, 0.0f), 1.0f); r = MIN(MAX(self.red, 0.0f), 1.0f);
g = MIN(MAX(self.green, 0.0f), 1.0f); g = MIN(MAX(self.green, 0.0f), 1.0f);
@ -168,11 +168,11 @@ static NSMutableDictionary *colorNameCache = nil;
#pragma mark Arithmetic operations #pragma mark Arithmetic operations
- (UIColor *)colorByLuminanceMapping { - (UIColor *)LOT_colorByLuminanceMapping {
NSAssert(self.canProvideRGBComponents, @"Must be a RGB color to use arithmatic operations"); NSAssert(self.canProvideRGBComponents, @"Must be a RGB color to use arithmatic operations");
CGFloat r,g,b,a; CGFloat r,g,b,a;
if (![self red:&r green:&g blue:&b alpha:&a]) return nil; if (![self LOT_red:&r green:&g blue:&b alpha:&a]) return nil;
// http://en.wikipedia.org/wiki/Luma_(video) // http://en.wikipedia.org/wiki/Luma_(video)
// Y = 0.2126 R + 0.7152 G + 0.0722 B // Y = 0.2126 R + 0.7152 G + 0.0722 B
@ -181,11 +181,11 @@ static NSMutableDictionary *colorNameCache = nil;
} }
- (UIColor *)colorByMultiplyingByRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha { - (UIColor *)LOT_colorByMultiplyingByRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha {
NSAssert(self.canProvideRGBComponents, @"Must be a RGB color to use arithmatic operations"); NSAssert(self.canProvideRGBComponents, @"Must be a RGB color to use arithmatic operations");
CGFloat r,g,b,a; CGFloat r,g,b,a;
if (![self red:&r green:&g blue:&b alpha:&a]) return nil; if (![self LOT_red:&r green:&g blue:&b alpha:&a]) return nil;
return [UIColor colorWithRed:MAX(0.0, MIN(1.0, r * red)) return [UIColor colorWithRed:MAX(0.0, MIN(1.0, r * red))
green:MAX(0.0, MIN(1.0, g * green)) green:MAX(0.0, MIN(1.0, g * green))
@ -193,11 +193,11 @@ static NSMutableDictionary *colorNameCache = nil;
alpha:MAX(0.0, MIN(1.0, a * alpha))]; alpha:MAX(0.0, MIN(1.0, a * alpha))];
} }
- (UIColor *)colorByAddingRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha { - (UIColor *)LOT_colorByAddingRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha {
NSAssert(self.canProvideRGBComponents, @"Must be a RGB color to use arithmatic operations"); NSAssert(self.canProvideRGBComponents, @"Must be a RGB color to use arithmatic operations");
CGFloat r,g,b,a; CGFloat r,g,b,a;
if (![self red:&r green:&g blue:&b alpha:&a]) return nil; if (![self LOT_red:&r green:&g blue:&b alpha:&a]) return nil;
return [UIColor colorWithRed:MAX(0.0, MIN(1.0, r + red)) return [UIColor colorWithRed:MAX(0.0, MIN(1.0, r + red))
green:MAX(0.0, MIN(1.0, g + green)) green:MAX(0.0, MIN(1.0, g + green))
@ -205,11 +205,11 @@ static NSMutableDictionary *colorNameCache = nil;
alpha:MAX(0.0, MIN(1.0, a + alpha))]; alpha:MAX(0.0, MIN(1.0, a + alpha))];
} }
- (UIColor *)colorByLighteningToRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha { - (UIColor *)LOT_colorByLighteningToRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha {
NSAssert(self.canProvideRGBComponents, @"Must be a RGB color to use arithmatic operations"); NSAssert(self.canProvideRGBComponents, @"Must be a RGB color to use arithmatic operations");
CGFloat r,g,b,a; CGFloat r,g,b,a;
if (![self red:&r green:&g blue:&b alpha:&a]) return nil; if (![self LOT_red:&r green:&g blue:&b alpha:&a]) return nil;
return [UIColor colorWithRed:MAX(r, red) return [UIColor colorWithRed:MAX(r, red)
green:MAX(g, green) green:MAX(g, green)
@ -217,11 +217,11 @@ static NSMutableDictionary *colorNameCache = nil;
alpha:MAX(a, alpha)]; alpha:MAX(a, alpha)];
} }
- (UIColor *)colorByDarkeningToRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha { - (UIColor *)LOT_colorByDarkeningToRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha {
NSAssert(self.canProvideRGBComponents, @"Must be a RGB color to use arithmatic operations"); NSAssert(self.canProvideRGBComponents, @"Must be a RGB color to use arithmatic operations");
CGFloat r,g,b,a; CGFloat r,g,b,a;
if (![self red:&r green:&g blue:&b alpha:&a]) return nil; if (![self LOT_red:&r green:&g blue:&b alpha:&a]) return nil;
return [UIColor colorWithRed:MIN(r, red) return [UIColor colorWithRed:MIN(r, red)
green:MIN(g, green) green:MIN(g, green)
@ -229,62 +229,62 @@ static NSMutableDictionary *colorNameCache = nil;
alpha:MIN(a, alpha)]; alpha:MIN(a, alpha)];
} }
- (UIColor *)colorByMultiplyingBy:(CGFloat)f { - (UIColor *)LOT_colorByMultiplyingBy:(CGFloat)f {
return [self colorByMultiplyingByRed:f green:f blue:f alpha:1.0f]; return [self LOT_colorByMultiplyingByRed:f green:f blue:f alpha:1.0f];
} }
- (UIColor *)colorByAdding:(CGFloat)f { - (UIColor *)LOT_colorByAdding:(CGFloat)f {
return [self colorByMultiplyingByRed:f green:f blue:f alpha:0.0f]; return [self LOT_colorByMultiplyingByRed:f green:f blue:f alpha:0.0f];
} }
- (UIColor *)colorByLighteningTo:(CGFloat)f { - (UIColor *)LOT_colorByLighteningTo:(CGFloat)f {
return [self colorByLighteningToRed:f green:f blue:f alpha:0.0f]; return [self LOT_colorByLighteningToRed:f green:f blue:f alpha:0.0f];
} }
- (UIColor *)colorByDarkeningTo:(CGFloat)f { - (UIColor *)LOT_colorByDarkeningTo:(CGFloat)f {
return [self colorByDarkeningToRed:f green:f blue:f alpha:1.0f]; return [self LOT_colorByDarkeningToRed:f green:f blue:f alpha:1.0f];
} }
- (UIColor *)colorByMultiplyingByColor:(UIColor *)color { - (UIColor *)LOT_colorByMultiplyingByColor:(UIColor *)color {
NSAssert(self.canProvideRGBComponents, @"Must be a RGB color to use arithmatic operations"); NSAssert(self.canProvideRGBComponents, @"Must be a RGB color to use arithmatic operations");
CGFloat r,g,b,a; CGFloat r,g,b,a;
if (![self red:&r green:&g blue:&b alpha:&a]) return nil; if (![self LOT_red:&r green:&g blue:&b alpha:&a]) return nil;
return [self colorByMultiplyingByRed:r green:g blue:b alpha:1.0f]; return [self LOT_colorByMultiplyingByRed:r green:g blue:b alpha:1.0f];
} }
- (UIColor *)colorByAddingColor:(UIColor *)color { - (UIColor *)LOT_colorByAddingColor:(UIColor *)color {
NSAssert(self.canProvideRGBComponents, @"Must be a RGB color to use arithmatic operations"); NSAssert(self.canProvideRGBComponents, @"Must be a RGB color to use arithmatic operations");
CGFloat r,g,b,a; CGFloat r,g,b,a;
if (![self red:&r green:&g blue:&b alpha:&a]) return nil; if (![self LOT_red:&r green:&g blue:&b alpha:&a]) return nil;
return [self colorByAddingRed:r green:g blue:b alpha:0.0f]; return [self LOT_colorByAddingRed:r green:g blue:b alpha:0.0f];
} }
- (UIColor *)colorByLighteningToColor:(UIColor *)color { - (UIColor *)LOT_colorByLighteningToColor:(UIColor *)color {
NSAssert(self.canProvideRGBComponents, @"Must be a RGB color to use arithmatic operations"); NSAssert(self.canProvideRGBComponents, @"Must be a RGB color to use arithmatic operations");
CGFloat r,g,b,a; CGFloat r,g,b,a;
if (![self red:&r green:&g blue:&b alpha:&a]) return nil; if (![self LOT_red:&r green:&g blue:&b alpha:&a]) return nil;
return [self colorByLighteningToRed:r green:g blue:b alpha:0.0f]; return [self LOT_colorByLighteningToRed:r green:g blue:b alpha:0.0f];
} }
- (UIColor *)colorByDarkeningToColor:(UIColor *)color { - (UIColor *)LOT_colorByDarkeningToColor:(UIColor *)color {
NSAssert(self.canProvideRGBComponents, @"Must be a RGB color to use arithmatic operations"); NSAssert(self.canProvideRGBComponents, @"Must be a RGB color to use arithmatic operations");
CGFloat r,g,b,a; CGFloat r,g,b,a;
if (![self red:&r green:&g blue:&b alpha:&a]) return nil; if (![self LOT_red:&r green:&g blue:&b alpha:&a]) return nil;
return [self colorByDarkeningToRed:r green:g blue:b alpha:1.0f]; return [self LOT_colorByDarkeningToRed:r green:g blue:b alpha:1.0f];
} }
#pragma mark String utilities #pragma mark String utilities
- (NSString *)stringFromColor { - (NSString *)LOT_stringFromColor {
NSAssert(self.canProvideRGBComponents, @"Must be an RGB color to use -stringFromColor"); NSAssert(self.canProvideRGBComponents, @"Must be an RGB color to use -LOT_stringFromColor");
NSString *result; NSString *result;
switch (self.colorSpaceModel) { switch (self.colorSpaceModel) {
case kCGColorSpaceModelRGB: case kCGColorSpaceModelRGB:
@ -299,11 +299,11 @@ static NSMutableDictionary *colorNameCache = nil;
return result; return result;
} }
- (NSString *)hexStringValue { - (NSString *)LOT_hexStringValue {
return [NSString stringWithFormat:@"%0.6X", (unsigned int)self.rgbHex]; return [NSString stringWithFormat:@"%0.6X", (unsigned int)self.rgbHex];
} }
+ (UIColor *)colorWithString:(NSString *)stringToConvert { + (UIColor *)LOT_colorWithString:(NSString *)stringToConvert {
NSScanner *scanner = [NSScanner scannerWithString:stringToConvert]; NSScanner *scanner = [NSScanner scannerWithString:stringToConvert];
if (![scanner scanString:@"{" intoString:NULL]) return nil; if (![scanner scanString:@"{" intoString:NULL]) return nil;
const NSUInteger kMaxComponents = 4; const NSUInteger kMaxComponents = 4;
@ -338,14 +338,14 @@ static NSMutableDictionary *colorNameCache = nil;
#pragma mark Class methods #pragma mark Class methods
+ (UIColor *)randomColor { + (UIColor *)LOT_randomColor {
return [UIColor colorWithRed:(CGFloat)random() / (CGFloat)RAND_MAX return [UIColor colorWithRed:(CGFloat)random() / (CGFloat)RAND_MAX
green:(CGFloat)random() / (CGFloat)RAND_MAX green:(CGFloat)random() / (CGFloat)RAND_MAX
blue:(CGFloat)random() / (CGFloat)RAND_MAX blue:(CGFloat)random() / (CGFloat)RAND_MAX
alpha:1.0f]; alpha:1.0f];
} }
+ (UIColor *)colorWithRGBHex:(UInt32)hex { + (UIColor *)LOT_colorWithRGBHex:(UInt32)hex {
int r = (hex >> 16) & 0xFF; int r = (hex >> 16) & 0xFF;
int g = (hex >> 8) & 0xFF; int g = (hex >> 8) & 0xFF;
int b = (hex) & 0xFF; int b = (hex) & 0xFF;
@ -356,18 +356,18 @@ static NSMutableDictionary *colorNameCache = nil;
alpha:1.0f]; alpha:1.0f];
} }
// Returns a UIColor by scanning the string for a hex number and passing that to +[UIColor colorWithRGBHex:] // Returns a UIColor by scanning the string for a hex number and passing that to +[UIColor LOT_colorWithRGBHex:]
// Skips any leading whitespace and ignores any trailing characters // Skips any leading whitespace and ignores any trailing characters
+ (UIColor *)colorWithHexString:(NSString *)stringToConvert { + (UIColor *)LOT_colorWithHexString:(NSString *)stringToConvert {
NSString *strippedString = [stringToConvert stringByReplacingOccurrencesOfString:@"#" withString:@""]; NSString *strippedString = [stringToConvert stringByReplacingOccurrencesOfString:@"#" withString:@""];
NSScanner *scanner = [NSScanner scannerWithString:strippedString]; NSScanner *scanner = [NSScanner scannerWithString:strippedString];
unsigned hexNum; unsigned hexNum;
if (![scanner scanHexInt:&hexNum]) return nil; if (![scanner scanHexInt:&hexNum]) return nil;
return [UIColor colorWithRGBHex:hexNum]; return [UIColor LOT_colorWithRGBHex:hexNum];
} }
// Lookup a color using css 3/svg color name // Lookup a color using css 3/svg color name
+ (UIColor *)colorWithName:(NSString *)cssColorName { + (UIColor *)LOT_colorWithName:(NSString *)cssColorName {
UIColor *color; UIColor *color;
@synchronized(colorNameCache) { @synchronized(colorNameCache) {
// Look for the color in the cache // Look for the color in the cache
@ -389,7 +389,7 @@ static NSMutableDictionary *colorNameCache = nil;
return color; return color;
} }
+ (UIColor *)colorByLerpingFromColor:(UIColor *)fromColor toColor:(UIColor *)toColor amount:(CGFloat)amount { + (UIColor *)LOT_colorByLerpingFromColor:(UIColor *)fromColor toColor:(UIColor *)toColor amount:(CGFloat)amount {
NSAssert((toColor != nil && fromColor != nil), @"Passing Nil Color"); NSAssert((toColor != nil && fromColor != nil), @"Passing Nil Color");
amount = CLAMP(amount, 0.f, 1.f); amount = CLAMP(amount, 0.f, 1.f);
const CGFloat *fromComponents = CGColorGetComponents(fromColor.CGColor); const CGFloat *fromComponents = CGColorGetComponents(fromColor.CGColor);
@ -474,10 +474,10 @@ static const char *colorNameDB = ","
const char *after = found + strlen(searchString); const char *after = found + strlen(searchString);
int hex; int hex;
if (sscanf(after, "%x", &hex) == 1) { if (sscanf(after, "%x", &hex) == 1) {
result = [self colorWithRGBHex:hex]; result = [self LOT_colorWithRGBHex:hex];
} }
} }
return result; return result;
} }
@end @end

View File

@ -1,20 +0,0 @@
//
// LAAnimationCache.h
// Lottie
//
// Created by Brandon Withrow on 1/9/17.
// Copyright © 2017 Brandon Withrow. All rights reserved.
//
#import <Foundation/Foundation.h>
@class LAComposition;
@interface LAAnimationCache : NSObject
+ (instancetype)sharedCache;
- (void)addAnimation:(LAComposition *)animation forKey:(NSString *)key;
- (LAComposition *)animationForKey:(NSString *)key;
@end

View File

@ -1,21 +0,0 @@
//
// LAEllipseShapeLayer.h
// LottieAnimator
//
// Created by brandon_withrow on 7/26/16.
// Copyright © 2016 Brandon Withrow. All rights reserved.
//
#import "LAAnimatableLayer.h"
#import "LAModels.h"
@interface LAEllipseShapeLayer : LAAnimatableLayer
- (instancetype)initWithEllipseShape:(LAShapeCircle *)circleShape
fill:(LAShapeFill *)fill
stroke:(LAShapeStroke *)stroke
trim:(LAShapeTrimPath *)trim
transform:(LAShapeTransform *)transform
withDuration:(NSTimeInterval)duration;
@end

View File

@ -1,31 +0,0 @@
//
// LAGroupLayerView.h
// LottieAnimator
//
// Created by brandon_withrow on 7/14/16.
// Copyright © 2016 Brandon Withrow. All rights reserved.
//
#import <QuartzCore/QuartzCore.h>
#import "LAAnimatableLayer.h"
@class LAShapeGroup;
@class LAShapeTransform;
@class LAShapeFill;
@class LAShapeStroke;
@class LAShapeTrimPath;
@interface LAGroupLayerView : LAAnimatableLayer
- (instancetype)initWithShapeGroup:(LAShapeGroup *)shapeGroup
transform:(LAShapeTransform *)previousTransform
fill:(LAShapeFill *)previousFill
stroke:(LAShapeStroke *)previousStroke
trimPath:(LAShapeTrimPath *)previousTrimPath
withDuration:(NSTimeInterval)duration;
@property (nonatomic, readonly) LAShapeGroup *shapeGroup;
@property (nonatomic, readonly) LAShapeTransform *shapeTransform;
@property (nonatomic, assign) BOOL debugModeOn;
@end

View File

@ -1,74 +0,0 @@
//
// LALayer.h
// LottieAnimator
//
// Created by Brandon Withrow on 12/14/15.
// Copyright © 2015 Brandon Withrow. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "LAPlatformCompat.h"
@class LAShapeGroup;
@class LAMask;
@class LAAnimatableColorValue;
@class LAAnimatablePointValue;
@class LAAnimatableNumberValue;
@class LAAnimatableScaleValue;
@class LAComposition;
typedef enum : NSInteger {
LALayerTypeNone,
LALayerTypeSolid,
LALayerTypeUnknown,
LALayerTypeNull,
LALayerTypeShape
} LALayerType;
typedef enum : NSInteger {
LAMatteTypeNone,
LAMatteTypeAdd,
LAMatteTypeInvert,
LALayerTypeUknown
} LAMatteType;
@interface LALayer : NSObject
- (instancetype)initWithJSON:(NSDictionary *)jsonDictionary fromComposition:(LAComposition *)composition;
@property (nonatomic, readonly) NSString *layerName;
@property (nonatomic, readonly) NSNumber *layerID;
@property (nonatomic, readonly) LALayerType layerType;
@property (nonatomic, readonly) NSNumber *parentID;
@property (nonatomic, readonly) NSNumber *inFrame;
@property (nonatomic, readonly) NSNumber *outFrame;
@property (nonatomic, readonly) CGRect compBounds;
@property (nonatomic, readonly) NSNumber *framerate;
@property (nonatomic, readonly) NSArray<LAShapeGroup *> *shapes;
@property (nonatomic, readonly) NSArray<LAMask *> *masks;
@property (nonatomic, readonly) NSNumber *solidWidth;
@property (nonatomic, readonly) NSNumber *solidHeight;
@property (nonatomic, readonly) UIColor *solidColor;
@property (nonatomic, readonly) LAAnimatableNumberValue *opacity;
@property (nonatomic, readonly) LAAnimatableNumberValue *rotation;
@property (nonatomic, readonly) LAAnimatablePointValue *position;
@property (nonatomic, readonly) LAAnimatableNumberValue *positionX;
@property (nonatomic, readonly) LAAnimatableNumberValue *positionY;
@property (nonatomic, readonly) LAAnimatablePointValue *anchor;
@property (nonatomic, readonly) LAAnimatableScaleValue *scale;
@property (nonatomic, readonly) BOOL hasOutAnimation;
@property (nonatomic, readonly) BOOL hasInAnimation;
@property (nonatomic, readonly) BOOL hasInOutAnimation;
@property (nonatomic, readonly) NSArray *inOutKeyframes;
@property (nonatomic, readonly) NSArray *inOutKeyTimes;
@property (nonatomic, readonly) NSTimeInterval compDuration;
@property (nonatomic, readonly) LAMatteType matteType;
@end

View File

@ -1,21 +0,0 @@
//
// LALayerView.h
// LottieAnimator
//
// Created by Brandon Withrow on 12/14/15.
// Copyright © 2015 Brandon Withrow. All rights reserved.
//
#import "LAPlatformCompat.h"
#import "LAAnimatableLayer.h"
#import "LAModels.h"
@interface LALayerView : LAAnimatableLayer
- (instancetype)initWithModel:(LALayer *)model inComposition:(LAComposition *)comp;
@property (nonatomic, readonly) LALayer *layerModel;
@property (nonatomic, assign) BOOL debugModeOn;
@end

View File

@ -1,30 +0,0 @@
//
// LAMask.h
// LottieAnimator
//
// Created by Brandon Withrow on 12/14/15.
// Copyright © 2015 Brandon Withrow. All rights reserved.
//
#import <Foundation/Foundation.h>
@class LAAnimatableShapeValue;
@class LAAnimatableNumberValue;
typedef enum : NSUInteger {
LAMaskModeAdd,
LAMaskModeSubtract,
LAMaskModeIntersect,
LAMaskModeUnknown
} LAMaskMode;
@interface LAMask : NSObject
- (instancetype)initWithJSON:(NSDictionary *)jsonDictionary frameRate:(NSNumber *)frameRate;
@property (nonatomic, readonly) BOOL closed;
@property (nonatomic, readonly) BOOL inverted;
@property (nonatomic, readonly) LAMaskMode maskMode;
@property (nonatomic, readonly) LAAnimatableShapeValue *maskPath;
@property (nonatomic, readonly) LAAnimatableNumberValue *opacity;
@end

View File

@ -1,19 +0,0 @@
//
// LAMaskLayer.h
// LottieAnimator
//
// Created by brandon_withrow on 7/22/16.
// Copyright © 2016 Brandon Withrow. All rights reserved.
//
#import "LAAnimatableLayer.h"
#import "LAModels.h"
@interface LAMaskLayer : LAAnimatableLayer
- (instancetype)initWithMasks:(NSArray<LAMask *> *)masks inComposition:(LAComposition *)comp;
@property (nonatomic, readonly) NSArray<LAMask *> *masks;
@end

View File

@ -1,32 +0,0 @@
//
// LAModels.h
// LottieAnimator
//
// Created by Brandon Withrow on 12/15/15.
// Copyright © 2015 Brandon Withrow. All rights reserved.
//
#ifndef LAModels_h
#define LAModels_h
#import "CAAnimationGroup+LAAnimatableGroup.h"
#import "LAAnimatableBoundsValue.h"
#import "LAAnimatableColorValue.h"
#import "LAAnimatableNumberValue.h"
#import "LAAnimatablePointValue.h"
#import "LAAnimatableScaleValue.h"
#import "LAAnimatableShapeValue.h"
#import "LAAnimatableValue.h"
#import "LAComposition.h"
#import "LALayer.h"
#import "LAMask.h"
#import "LAShapeCircle.h"
#import "LAShapeFill.h"
#import "LAShapeGroup.h"
#import "LAShapePath.h"
#import "LAShapeRectangle.h"
#import "LAShapeStroke.h"
#import "LAShapeTransform.h"
#import "LAShapeTrimPath.h"
#endif /* LAModels_h */

View File

@ -1,21 +0,0 @@
//
// LARectShapeLayer.h
// LottieAnimator
//
// Created by brandon_withrow on 7/20/16.
// Copyright © 2016 Brandon Withrow. All rights reserved.
//
#import <QuartzCore/QuartzCore.h>
#import "LAModels.h"
#import "LAAnimatableLayer.h"
@interface LARectShapeLayer : LAAnimatableLayer
- (instancetype)initWithRectShape:(LAShapeRectangle *)rectShape
fill:(LAShapeFill *)fill
stroke:(LAShapeStroke *)stroke
transform:(LAShapeTransform *)transform
withDuration:(NSTimeInterval)duration;
@end

View File

@ -1,21 +0,0 @@
//
// LAShapeLayerView.h
// LottieAnimator
//
// Created by Brandon Withrow on 7/13/16.
// Copyright © 2016 Brandon Withrow. All rights reserved.
//
#import "LAAnimatableLayer.h"
#import "LAModels.h"
@interface LAShapeLayerView : LAAnimatableLayer
- (instancetype)initWithShape:(LAShapePath *)shape
fill:(LAShapeFill *)fill
stroke:(LAShapeStroke *)stroke
trim:(LAShapeTrimPath *)trim
transform:(LAShapeTransform *)transform
withDuration:(NSTimeInterval)duration;
@end

View File

@ -1,22 +0,0 @@
//
// LAShapeRectangle.h
// LottieAnimator
//
// Created by Brandon Withrow on 12/15/15.
// Copyright © 2015 Brandon Withrow. All rights reserved.
//
#import <Foundation/Foundation.h>
@class LAAnimatableBoundsValue;
@class LAAnimatablePointValue;
@class LAAnimatableNumberValue;
@interface LAShapeRectangle : NSObject
- (instancetype)initWithJSON:(NSDictionary *)jsonDictionary frameRate:(NSNumber *)frameRate;
@property (nonatomic, readonly) LAAnimatablePointValue *position;
@property (nonatomic, readonly) LAAnimatablePointValue *size;
@property (nonatomic, readonly) LAAnimatableNumberValue *cornerRadius;
@end

View File

@ -1,39 +0,0 @@
//
// LAShapeStroke.h
// LottieAnimator
//
// Created by Brandon Withrow on 12/15/15.
// Copyright © 2015 Brandon Withrow. All rights reserved.
//
#import <Foundation/Foundation.h>
@class LAAnimatableColorValue;
@class LAAnimatableNumberValue;
typedef enum : NSUInteger {
LALineCapTypeButt,
LALineCapTypeRound,
LALineCapTypeUnknown
} LALineCapType;
typedef enum : NSUInteger {
LALineJoinTypeMiter,
LALineJoinTypeRound,
LALineJoinTypeBevel
} LALineJoinType;
@interface LAShapeStroke : NSObject
- (instancetype)initWithJSON:(NSDictionary *)jsonDictionary frameRate:(NSNumber *)frameRate;
@property (nonatomic, readonly) BOOL fillEnabled;
@property (nonatomic, readonly) LAAnimatableColorValue *color;
@property (nonatomic, readonly) LAAnimatableNumberValue *opacity;
@property (nonatomic, readonly) LAAnimatableNumberValue *width;
@property (nonatomic, readonly) LALineCapType capType;
@property (nonatomic, readonly) LALineJoinType joinType;
@property (nonatomic, readonly) NSArray *lineDashPattern;
@end

View File

@ -1,29 +0,0 @@
//
// LAShapeTransform.h
// LottieAnimator
//
// Created by Brandon Withrow on 12/15/15.
// Copyright © 2015 Brandon Withrow. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <CoreGraphics/CoreGraphics.h>
@class LAAnimatableNumberValue;
@class LAAnimatablePointValue;
@class LAAnimatableScaleValue;
@interface LAShapeTransform : NSObject
+ (instancetype)transformIdentityWithCompBounds:(CGRect)compBounds;
- (instancetype)initWithJSON:(NSDictionary *)jsonDictionary frameRate:(NSNumber *)frameRate compBounds:(CGRect)compBounds;
@property (nonatomic, readonly) CGRect compBounds;
@property (nonatomic, readonly) LAAnimatablePointValue *position;
@property (nonatomic, readonly) LAAnimatablePointValue *anchor;
@property (nonatomic, readonly) LAAnimatableScaleValue *scale;
@property (nonatomic, readonly) LAAnimatableNumberValue *rotation;
@property (nonatomic, readonly) LAAnimatableNumberValue *opacity;
@end

View File

@ -1,19 +0,0 @@
//
// LAShapeTrimPath.h
// LottieAnimator
//
// Created by brandon_withrow on 7/26/16.
// Copyright © 2016 Brandon Withrow. All rights reserved.
//
#import <Foundation/Foundation.h>
@class LAAnimatableNumberValue;
@interface LAShapeTrimPath : NSObject
- (instancetype)initWithJSON:(NSDictionary *)jsonDictionary frameRate:(NSNumber *)frameRate;
@property (nonatomic, readonly) LAAnimatableNumberValue *start;
@property (nonatomic, readonly) LAAnimatableNumberValue *end;
@property (nonatomic, readonly) LAAnimatableNumberValue *offset;
@end

View File

@ -1,5 +1,5 @@
// //
// LAScene.h // LOTScene.h
// LottieAnimator // LottieAnimator
// //
// Created by Brandon Withrow on 12/14/15. // Created by Brandon Withrow on 12/14/15.
@ -9,19 +9,19 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import <CoreGraphics/CoreGraphics.h> #import <CoreGraphics/CoreGraphics.h>
@class LALayer; @class LOTLayer;
@interface LAComposition : NSObject @interface LOTComposition : NSObject
- (instancetype)initWithJSON:(NSDictionary *)jsonDictionary; - (instancetype)initWithJSON:(NSDictionary *)jsonDictionary;
@property (nonatomic, readonly) NSArray <LALayer *> *layers; @property (nonatomic, readonly) NSArray <LOTLayer *> *layers;
@property (nonatomic, readonly) CGRect compBounds; @property (nonatomic, readonly) CGRect compBounds;
@property (nonatomic, readonly) NSNumber *startFrame; @property (nonatomic, readonly) NSNumber *startFrame;
@property (nonatomic, readonly) NSNumber *endFrame; @property (nonatomic, readonly) NSNumber *endFrame;
@property (nonatomic, readonly) NSNumber *framerate; @property (nonatomic, readonly) NSNumber *framerate;
@property (nonatomic, readonly) NSTimeInterval timeDuration; @property (nonatomic, readonly) NSTimeInterval timeDuration;
- (LALayer *)layerModelForID:(NSNumber *)layerID; - (LOTLayer *)layerModelForID:(NSNumber *)layerID;
@end @end

View File

@ -1,15 +1,15 @@
// //
// LAScene.m // LOTScene.m
// LottieAnimator // LottieAnimator
// //
// Created by Brandon Withrow on 12/14/15. // Created by Brandon Withrow on 12/14/15.
// Copyright © 2015 Brandon Withrow. All rights reserved. // Copyright © 2015 Brandon Withrow. All rights reserved.
// //
#import "LAComposition.h" #import "LOTComposition.h"
#import "LALayer.h" #import "LOTLayer.h"
@implementation LAComposition { @implementation LOTComposition {
NSDictionary *_modelMap; NSDictionary *_modelMap;
} }
@ -44,7 +44,7 @@
NSMutableDictionary *modelMap = [NSMutableDictionary dictionary]; NSMutableDictionary *modelMap = [NSMutableDictionary dictionary];
for (NSDictionary *layerJSON in layersJSON) { for (NSDictionary *layerJSON in layersJSON) {
LALayer *layer = [[LALayer alloc] initWithJSON:layerJSON fromComposition:self]; LOTLayer *layer = [[LOTLayer alloc] initWithJSON:layerJSON fromComposition:self];
[layers addObject:layer]; [layers addObject:layer];
modelMap[layer.layerID] = layer; modelMap[layer.layerID] = layer;
} }
@ -53,7 +53,7 @@
_layers = layers; _layers = layers;
} }
- (LALayer *)layerModelForID:(NSNumber *)layerID { - (LOTLayer *)layerModelForID:(NSNumber *)layerID {
return _modelMap[layerID]; return _modelMap[layerID];
} }

View File

@ -0,0 +1,74 @@
//
// LOTLayer.h
// LottieAnimator
//
// Created by Brandon Withrow on 12/14/15.
// Copyright © 2015 Brandon Withrow. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "LOTPlatformCompat.h"
@class LOTShapeGroup;
@class LOTMask;
@class LOTAnimatableColorValue;
@class LOTAnimatablePointValue;
@class LOTAnimatableNumberValue;
@class LOTAnimatableScaleValue;
@class LOTComposition;
typedef enum : NSInteger {
LOTLayerTypeNone,
LOTLayerTypeSolid,
LOTLayerTypeUnknown,
LOTLayerTypeNull,
LOTLayerTypeShape
} LOTLayerType;
typedef enum : NSInteger {
LOTMatteTypeNone,
LOTMatteTypeAdd,
LOTMatteTypeInvert,
LOTLayerTypeUknown
} LOTMatteType;
@interface LOTLayer : NSObject
- (instancetype)initWithJSON:(NSDictionary *)jsonDictionary fromComposition:(LOTComposition *)composition;
@property (nonatomic, readonly) NSString *layerName;
@property (nonatomic, readonly) NSNumber *layerID;
@property (nonatomic, readonly) LOTLayerType layerType;
@property (nonatomic, readonly) NSNumber *parentID;
@property (nonatomic, readonly) NSNumber *inFrame;
@property (nonatomic, readonly) NSNumber *outFrame;
@property (nonatomic, readonly) CGRect compBounds;
@property (nonatomic, readonly) NSNumber *framerate;
@property (nonatomic, readonly) NSArray<LOTShapeGroup *> *shapes;
@property (nonatomic, readonly) NSArray<LOTMask *> *masks;
@property (nonatomic, readonly) NSNumber *solidWidth;
@property (nonatomic, readonly) NSNumber *solidHeight;
@property (nonatomic, readonly) UIColor *solidColor;
@property (nonatomic, readonly) LOTAnimatableNumberValue *opacity;
@property (nonatomic, readonly) LOTAnimatableNumberValue *rotation;
@property (nonatomic, readonly) LOTAnimatablePointValue *position;
@property (nonatomic, readonly) LOTAnimatableNumberValue *positionX;
@property (nonatomic, readonly) LOTAnimatableNumberValue *positionY;
@property (nonatomic, readonly) LOTAnimatablePointValue *anchor;
@property (nonatomic, readonly) LOTAnimatableScaleValue *scale;
@property (nonatomic, readonly) BOOL hasOutAnimation;
@property (nonatomic, readonly) BOOL hasInAnimation;
@property (nonatomic, readonly) BOOL hasInOutAnimation;
@property (nonatomic, readonly) NSArray *inOutKeyframes;
@property (nonatomic, readonly) NSArray *inOutKeyTimes;
@property (nonatomic, readonly) NSTimeInterval compDuration;
@property (nonatomic, readonly) LOTMatteType matteType;
@end

View File

@ -1,24 +1,24 @@
// //
// LALayer.m // LOTLayer.m
// LottieAnimator // LottieAnimator
// //
// Created by Brandon Withrow on 12/14/15. // Created by Brandon Withrow on 12/14/15.
// Copyright © 2015 Brandon Withrow. All rights reserved. // Copyright © 2015 Brandon Withrow. All rights reserved.
// //
#import "LALayer.h" #import "LOTLayer.h"
#import "LAAnimatableColorValue.h" #import "LOTAnimatableColorValue.h"
#import "LAAnimatablePointValue.h" #import "LOTAnimatablePointValue.h"
#import "LAAnimatableNumberValue.h" #import "LOTAnimatableNumberValue.h"
#import "LAAnimatableScaleValue.h" #import "LOTAnimatableScaleValue.h"
#import "LAShapeGroup.h" #import "LOTShapeGroup.h"
#import "LAComposition.h" #import "LOTComposition.h"
#import "LAHelpers.h" #import "LOTHelpers.h"
#import "LAMask.h" #import "LOTMask.h"
@implementation LALayer @implementation LOTLayer
- (instancetype)initWithJSON:(NSDictionary *)jsonDictionary fromComposition:(LAComposition *)composition { - (instancetype)initWithJSON:(NSDictionary *)jsonDictionary fromComposition:(LOTComposition *)composition {
self = [super init]; self = [super init];
if (self) { if (self) {
[self _mapFromJSON:jsonDictionary fromComposition:composition]; [self _mapFromJSON:jsonDictionary fromComposition:composition];
@ -26,35 +26,35 @@
return self; return self;
} }
- (void)_mapFromJSON:(NSDictionary *)jsonDictionary fromComposition:(LAComposition *)composition { - (void)_mapFromJSON:(NSDictionary *)jsonDictionary fromComposition:(LOTComposition *)composition {
_layerName = [jsonDictionary[@"nm"] copy]; _layerName = [jsonDictionary[@"nm"] copy];
_layerID = [jsonDictionary[@"ind"] copy]; _layerID = [jsonDictionary[@"ind"] copy];
_compBounds = composition.compBounds; _compBounds = composition.compBounds;
_framerate = composition.framerate; _framerate = composition.framerate;
NSNumber *layerType = jsonDictionary[@"ty"]; NSNumber *layerType = jsonDictionary[@"ty"];
if (layerType.integerValue <= LALayerTypeShape) { if (layerType.integerValue <= LOTLayerTypeShape) {
_layerType = layerType.integerValue; _layerType = layerType.integerValue;
} else { } else {
_layerType = LALayerTypeUnknown; _layerType = LOTLayerTypeUnknown;
} }
_parentID = [jsonDictionary[@"parent"] copy]; _parentID = [jsonDictionary[@"parent"] copy];
_inFrame = [jsonDictionary[@"ip"] copy]; _inFrame = [jsonDictionary[@"ip"] copy];
_outFrame = [jsonDictionary[@"op"] copy]; _outFrame = [jsonDictionary[@"op"] copy];
if (_layerType == LALayerTypeSolid) { if (_layerType == LOTLayerTypeSolid) {
_solidWidth = jsonDictionary[@"sw"]; _solidWidth = jsonDictionary[@"sw"];
_solidHeight = jsonDictionary[@"sh"]; _solidHeight = jsonDictionary[@"sh"];
_compBounds = CGRectMake(0, 0, _solidWidth.floatValue, _solidHeight.floatValue); _compBounds = CGRectMake(0, 0, _solidWidth.floatValue, _solidHeight.floatValue);
NSString *solidColor = jsonDictionary[@"sc"]; NSString *solidColor = jsonDictionary[@"sc"];
_solidColor = [UIColor colorWithHexString:solidColor]; _solidColor = [UIColor LOT_colorWithHexString:solidColor];
} }
NSDictionary *ks = jsonDictionary[@"ks"]; NSDictionary *ks = jsonDictionary[@"ks"];
NSDictionary *opacity = ks[@"o"]; NSDictionary *opacity = ks[@"o"];
if (opacity) { if (opacity) {
_opacity = [[LAAnimatableNumberValue alloc] initWithNumberValues:opacity frameRate:_framerate]; _opacity = [[LOTAnimatableNumberValue alloc] initWithNumberValues:opacity frameRate:_framerate];
[_opacity remapValuesFromMin:@0 fromMax:@100 toMin:@0 toMax:@1]; [_opacity remapValuesFromMin:@0 fromMax:@100 toMin:@0 toMax:@1];
} }
@ -63,7 +63,7 @@
rotation = ks[@"rz"]; rotation = ks[@"rz"];
} }
if (rotation) { if (rotation) {
_rotation = [[LAAnimatableNumberValue alloc] initWithNumberValues:rotation frameRate:_framerate]; _rotation = [[LOTAnimatableNumberValue alloc] initWithNumberValues:rotation frameRate:_framerate];
[_rotation remapValueWithBlock:^CGFloat(CGFloat inValue) { [_rotation remapValueWithBlock:^CGFloat(CGFloat inValue) {
return DegreesToRadians(inValue); return DegreesToRadians(inValue);
}]; }];
@ -72,22 +72,22 @@
NSDictionary *position = ks[@"p"]; NSDictionary *position = ks[@"p"];
if ([position[@"s"] boolValue]) { if ([position[@"s"] boolValue]) {
// Seperate dimensions // Seperate dimensions
_positionX = [[LAAnimatableNumberValue alloc] initWithNumberValues:position[@"x"] frameRate:_framerate]; _positionX = [[LOTAnimatableNumberValue alloc] initWithNumberValues:position[@"x"] frameRate:_framerate];
_positionY = [[LAAnimatableNumberValue alloc] initWithNumberValues:position[@"y"] frameRate:_framerate]; _positionY = [[LOTAnimatableNumberValue alloc] initWithNumberValues:position[@"y"] frameRate:_framerate];
} else { } else {
_position = [[LAAnimatablePointValue alloc] initWithPointValues:position frameRate:_framerate]; _position = [[LOTAnimatablePointValue alloc] initWithPointValues:position frameRate:_framerate];
} }
NSDictionary *anchor = ks[@"a"]; NSDictionary *anchor = ks[@"a"];
if (anchor) { if (anchor) {
_anchor = [[LAAnimatablePointValue alloc] initWithPointValues:anchor frameRate:_framerate]; _anchor = [[LOTAnimatablePointValue alloc] initWithPointValues:anchor frameRate:_framerate];
[_anchor remapPointsFromBounds:_compBounds toBounds:CGRectMake(0, 0, 1, 1)]; [_anchor remapPointsFromBounds:_compBounds toBounds:CGRectMake(0, 0, 1, 1)];
_anchor.usePathAnimation = NO; _anchor.usePathAnimation = NO;
} }
NSDictionary *scale = ks[@"s"]; NSDictionary *scale = ks[@"s"];
if (scale) { if (scale) {
_scale = [[LAAnimatableScaleValue alloc] initWithScaleValues:scale frameRate:_framerate]; _scale = [[LOTAnimatableScaleValue alloc] initWithScaleValues:scale frameRate:_framerate];
} }
_matteType = [jsonDictionary[@"tt"] integerValue]; _matteType = [jsonDictionary[@"tt"] integerValue];
@ -95,14 +95,14 @@
NSMutableArray *masks = [NSMutableArray array]; NSMutableArray *masks = [NSMutableArray array];
for (NSDictionary *maskJSON in jsonDictionary[@"masksProperties"]) { for (NSDictionary *maskJSON in jsonDictionary[@"masksProperties"]) {
LAMask *mask = [[LAMask alloc] initWithJSON:maskJSON frameRate:_framerate]; LOTMask *mask = [[LOTMask alloc] initWithJSON:maskJSON frameRate:_framerate];
[masks addObject:mask]; [masks addObject:mask];
} }
_masks = masks.count ? masks : nil; _masks = masks.count ? masks : nil;
NSMutableArray *shapes = [NSMutableArray array]; NSMutableArray *shapes = [NSMutableArray array];
for (NSDictionary *shapeJSON in jsonDictionary[@"shapes"]) { for (NSDictionary *shapeJSON in jsonDictionary[@"shapes"]) {
id shapeItem = [LAShapeGroup shapeItemWithJSON:shapeJSON frameRate:_framerate compBounds:_compBounds]; id shapeItem = [LOTShapeGroup shapeItemWithJSON:shapeJSON frameRate:_framerate compBounds:_compBounds];
if (shapeItem) { if (shapeItem) {
[shapes addObject:shapeItem]; [shapes addObject:shapeItem];
} }

View File

@ -0,0 +1,30 @@
//
// LOTMask.h
// LottieAnimator
//
// Created by Brandon Withrow on 12/14/15.
// Copyright © 2015 Brandon Withrow. All rights reserved.
//
#import <Foundation/Foundation.h>
@class LOTAnimatableShapeValue;
@class LOTAnimatableNumberValue;
typedef enum : NSUInteger {
LOTMaskModeAdd,
LOTMaskModeSubtract,
LOTMaskModeIntersect,
LOTMaskModeUnknown
} LOTMaskMode;
@interface LOTMask : NSObject
- (instancetype)initWithJSON:(NSDictionary *)jsonDictionary frameRate:(NSNumber *)frameRate;
@property (nonatomic, readonly) BOOL closed;
@property (nonatomic, readonly) BOOL inverted;
@property (nonatomic, readonly) LOTMaskMode maskMode;
@property (nonatomic, readonly) LOTAnimatableShapeValue *maskPath;
@property (nonatomic, readonly) LOTAnimatableNumberValue *opacity;
@end

View File

@ -1,16 +1,16 @@
// //
// LAMask.m // LOTMask.m
// LottieAnimator // LottieAnimator
// //
// Created by Brandon Withrow on 12/14/15. // Created by Brandon Withrow on 12/14/15.
// Copyright © 2015 Brandon Withrow. All rights reserved. // Copyright © 2015 Brandon Withrow. All rights reserved.
// //
#import "LAMask.h" #import "LOTMask.h"
#import "LAAnimatableShapeValue.h" #import "LOTAnimatableShapeValue.h"
#import "LAAnimatableNumberValue.h" #import "LOTAnimatableNumberValue.h"
@implementation LAMask @implementation LOTMask
- (instancetype)initWithJSON:(NSDictionary *)jsonDictionary frameRate:(NSNumber *)frameRate { - (instancetype)initWithJSON:(NSDictionary *)jsonDictionary frameRate:(NSNumber *)frameRate {
self = [super init]; self = [super init];
@ -29,23 +29,23 @@
NSString *mode = jsonDictionary[@"mode"]; NSString *mode = jsonDictionary[@"mode"];
if ([mode isEqualToString:@"a"]) { if ([mode isEqualToString:@"a"]) {
_maskMode = LAMaskModeAdd; _maskMode = LOTMaskModeAdd;
} else if ([mode isEqualToString:@"s"]) { } else if ([mode isEqualToString:@"s"]) {
_maskMode = LAMaskModeSubtract; _maskMode = LOTMaskModeSubtract;
} else if ([mode isEqualToString:@"i"]) { } else if ([mode isEqualToString:@"i"]) {
_maskMode = LAMaskModeIntersect; _maskMode = LOTMaskModeIntersect;
} else { } else {
_maskMode = LAMaskModeUnknown; _maskMode = LOTMaskModeUnknown;
} }
NSDictionary *maskshape = jsonDictionary[@"pt"]; NSDictionary *maskshape = jsonDictionary[@"pt"];
if (maskshape) { if (maskshape) {
_maskPath = [[LAAnimatableShapeValue alloc] initWithShapeValues:maskshape frameRate:frameRate closed:_closed]; _maskPath = [[LOTAnimatableShapeValue alloc] initWithShapeValues:maskshape frameRate:frameRate closed:_closed];
} }
NSDictionary *opacity = jsonDictionary[@"o"]; NSDictionary *opacity = jsonDictionary[@"o"];
if (opacity) { if (opacity) {
_opacity = [[LAAnimatableNumberValue alloc] initWithNumberValues:opacity frameRate:frameRate]; _opacity = [[LOTAnimatableNumberValue alloc] initWithNumberValues:opacity frameRate:frameRate];
[_opacity remapValuesFromMin:@0 fromMax:@100 toMin:@0 toMax:@1]; [_opacity remapValuesFromMin:@0 fromMax:@100 toMin:@0 toMax:@1];
} }
} }

View File

@ -0,0 +1,32 @@
//
// LOTModels.h
// LottieAnimator
//
// Created by Brandon Withrow on 12/15/15.
// Copyright © 2015 Brandon Withrow. All rights reserved.
//
#ifndef LOTModels_h
#define LOTModels_h
#import "CAAnimationGroup+LOTAnimatableGroup.h"
#import "LOTAnimatableBoundsValue.h"
#import "LOTAnimatableColorValue.h"
#import "LOTAnimatableNumberValue.h"
#import "LOTAnimatablePointValue.h"
#import "LOTAnimatableScaleValue.h"
#import "LOTAnimatableShapeValue.h"
#import "LOTAnimatableValue.h"
#import "LOTComposition.h"
#import "LOTLayer.h"
#import "LOTMask.h"
#import "LOTShapeCircle.h"
#import "LOTShapeFill.h"
#import "LOTShapeGroup.h"
#import "LOTShapePath.h"
#import "LOTShapeRectangle.h"
#import "LOTShapeStroke.h"
#import "LOTShapeTransform.h"
#import "LOTShapeTrimPath.h"
#endif /* LOTModels_h */

View File

@ -1,5 +1,5 @@
// //
// LAShapeCircle.h // LOTShapeCircle.h
// LottieAnimator // LottieAnimator
// //
// Created by Brandon Withrow on 12/15/15. // Created by Brandon Withrow on 12/15/15.
@ -7,14 +7,14 @@
// //
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
@class LAAnimatablePointValue; @class LOTAnimatablePointValue;
@class LAAnimatableScaleValue; @class LOTAnimatableScaleValue;
@interface LAShapeCircle : NSObject @interface LOTShapeCircle : NSObject
- (instancetype)initWithJSON:(NSDictionary *)jsonDictionary frameRate:(NSNumber *)frameRate; - (instancetype)initWithJSON:(NSDictionary *)jsonDictionary frameRate:(NSNumber *)frameRate;
@property (nonatomic, readonly) LAAnimatablePointValue *position; @property (nonatomic, readonly) LOTAnimatablePointValue *position;
@property (nonatomic, readonly) LAAnimatablePointValue *size; @property (nonatomic, readonly) LOTAnimatablePointValue *size;
@end @end

View File

@ -1,16 +1,16 @@
// //
// LAShapeCircle.m // LOTShapeCircle.m
// LottieAnimator // LottieAnimator
// //
// Created by Brandon Withrow on 12/15/15. // Created by Brandon Withrow on 12/15/15.
// Copyright © 2015 Brandon Withrow. All rights reserved. // Copyright © 2015 Brandon Withrow. All rights reserved.
// //
#import "LAShapeCircle.h" #import "LOTShapeCircle.h"
#import "LAAnimatablePointValue.h" #import "LOTAnimatablePointValue.h"
#import "LAAnimatableScaleValue.h" #import "LOTAnimatableScaleValue.h"
@implementation LAShapeCircle @implementation LOTShapeCircle
- (instancetype)initWithJSON:(NSDictionary *)jsonDictionary frameRate:(NSNumber *)frameRate { - (instancetype)initWithJSON:(NSDictionary *)jsonDictionary frameRate:(NSNumber *)frameRate {
self = [super init]; self = [super init];
@ -23,13 +23,13 @@
- (void)_mapFromJSON:(NSDictionary *)jsonDictionary frameRate:(NSNumber *)frameRate { - (void)_mapFromJSON:(NSDictionary *)jsonDictionary frameRate:(NSNumber *)frameRate {
NSDictionary *position = jsonDictionary[@"p"]; NSDictionary *position = jsonDictionary[@"p"];
if (position) { if (position) {
_position = [[LAAnimatablePointValue alloc] initWithPointValues:position frameRate:frameRate]; _position = [[LOTAnimatablePointValue alloc] initWithPointValues:position frameRate:frameRate];
_position.usePathAnimation = NO; _position.usePathAnimation = NO;
} }
NSDictionary *size= jsonDictionary[@"s"]; NSDictionary *size= jsonDictionary[@"s"];
if (size) { if (size) {
_size = [[LAAnimatablePointValue alloc] initWithPointValues:size frameRate:frameRate]; _size = [[LOTAnimatablePointValue alloc] initWithPointValues:size frameRate:frameRate];
_size.usePathAnimation = NO; _size.usePathAnimation = NO;
} }
} }

View File

@ -1,5 +1,5 @@
// //
// LAShapeFill.h // LOTShapeFill.h
// LottieAnimator // LottieAnimator
// //
// Created by Brandon Withrow on 12/15/15. // Created by Brandon Withrow on 12/15/15.
@ -8,15 +8,15 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
@class LAAnimatableColorValue; @class LOTAnimatableColorValue;
@class LAAnimatableNumberValue; @class LOTAnimatableNumberValue;
@interface LAShapeFill : NSObject @interface LOTShapeFill : NSObject
- (instancetype)initWithJSON:(NSDictionary *)jsonDictionary frameRate:(NSNumber *)frameRate; - (instancetype)initWithJSON:(NSDictionary *)jsonDictionary frameRate:(NSNumber *)frameRate;
@property (nonatomic, readonly) BOOL fillEnabled; @property (nonatomic, readonly) BOOL fillEnabled;
@property (nonatomic, readonly) LAAnimatableColorValue *color; @property (nonatomic, readonly) LOTAnimatableColorValue *color;
@property (nonatomic, readonly) LAAnimatableNumberValue *opacity; @property (nonatomic, readonly) LOTAnimatableNumberValue *opacity;
@end @end

View File

@ -1,16 +1,16 @@
// //
// LAShapeFill.m // LOTShapeFill.m
// LottieAnimator // LottieAnimator
// //
// Created by Brandon Withrow on 12/15/15. // Created by Brandon Withrow on 12/15/15.
// Copyright © 2015 Brandon Withrow. All rights reserved. // Copyright © 2015 Brandon Withrow. All rights reserved.
// //
#import "LAShapeFill.h" #import "LOTShapeFill.h"
#import "LAAnimatableNumberValue.h" #import "LOTAnimatableNumberValue.h"
#import "LAAnimatableColorValue.h" #import "LOTAnimatableColorValue.h"
@implementation LAShapeFill @implementation LOTShapeFill
- (instancetype)initWithJSON:(NSDictionary *)jsonDictionary frameRate:(NSNumber *)frameRate { - (instancetype)initWithJSON:(NSDictionary *)jsonDictionary frameRate:(NSNumber *)frameRate {
self = [super init]; self = [super init];
@ -23,12 +23,12 @@
- (void)_mapFromJSON:(NSDictionary *)jsonDictionary frameRate:(NSNumber *)frameRate { - (void)_mapFromJSON:(NSDictionary *)jsonDictionary frameRate:(NSNumber *)frameRate {
NSDictionary *color = jsonDictionary[@"c"]; NSDictionary *color = jsonDictionary[@"c"];
if (color) { if (color) {
_color = [[LAAnimatableColorValue alloc] initWithColorValues:color frameRate:frameRate]; _color = [[LOTAnimatableColorValue alloc] initWithColorValues:color frameRate:frameRate];
} }
NSDictionary *opacity = jsonDictionary[@"o"]; NSDictionary *opacity = jsonDictionary[@"o"];
if (opacity) { if (opacity) {
_opacity = [[LAAnimatableNumberValue alloc] initWithNumberValues:opacity frameRate:frameRate]; _opacity = [[LOTAnimatableNumberValue alloc] initWithNumberValues:opacity frameRate:frameRate];
[_opacity remapValuesFromMin:@0 fromMax:@100 toMin:@0 toMax:@1]; [_opacity remapValuesFromMin:@0 fromMax:@100 toMin:@0 toMax:@1];
} }

View File

@ -1,5 +1,5 @@
// //
// LAShape.h // LOTShape.h
// LottieAnimator // LottieAnimator
// //
// Created by Brandon Withrow on 12/14/15. // Created by Brandon Withrow on 12/14/15.
@ -9,7 +9,7 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import <CoreGraphics/CoreGraphics.h> #import <CoreGraphics/CoreGraphics.h>
@interface LAShapeGroup : NSObject @interface LOTShapeGroup : NSObject
- (instancetype)initWithJSON:(NSDictionary *)jsonDictionary frameRate:(NSNumber *)frameRate compBounds:(CGRect)compBounds; - (instancetype)initWithJSON:(NSDictionary *)jsonDictionary frameRate:(NSNumber *)frameRate compBounds:(CGRect)compBounds;

View File

@ -1,21 +1,21 @@
// //
// LAShape.m // LOTShape.m
// LottieAnimator // LottieAnimator
// //
// Created by Brandon Withrow on 12/14/15. // Created by Brandon Withrow on 12/14/15.
// Copyright © 2015 Brandon Withrow. All rights reserved. // Copyright © 2015 Brandon Withrow. All rights reserved.
// //
#import "LAShapeGroup.h" #import "LOTShapeGroup.h"
#import "LAShapeFill.h" #import "LOTShapeFill.h"
#import "LAShapePath.h" #import "LOTShapePath.h"
#import "LAShapeCircle.h" #import "LOTShapeCircle.h"
#import "LAShapeStroke.h" #import "LOTShapeStroke.h"
#import "LAShapeTransform.h" #import "LOTShapeTransform.h"
#import "LAShapeRectangle.h" #import "LOTShapeRectangle.h"
#import "LAShapeTrimPath.h" #import "LOTShapeTrimPath.h"
@implementation LAShapeGroup @implementation LOTShapeGroup
- (instancetype)initWithJSON:(NSDictionary *)jsonDictionary frameRate:(NSNumber *)frameRate compBounds:(CGRect)compBounds { - (instancetype)initWithJSON:(NSDictionary *)jsonDictionary frameRate:(NSNumber *)frameRate compBounds:(CGRect)compBounds {
self = [super init]; self = [super init];
@ -29,7 +29,7 @@
NSArray *itemsJSON = jsonDictionary[@"it"]; NSArray *itemsJSON = jsonDictionary[@"it"];
NSMutableArray *items = [NSMutableArray array]; NSMutableArray *items = [NSMutableArray array];
for (NSDictionary *itemJSON in itemsJSON) { for (NSDictionary *itemJSON in itemsJSON) {
id newItem = [LAShapeGroup shapeItemWithJSON:itemJSON frameRate:frameRate compBounds:compBounds]; id newItem = [LOTShapeGroup shapeItemWithJSON:itemJSON frameRate:frameRate compBounds:compBounds];
if (newItem) { if (newItem) {
[items addObject:newItem]; [items addObject:newItem];
} }
@ -40,28 +40,28 @@
+ (id)shapeItemWithJSON:(NSDictionary *)itemJSON frameRate:(NSNumber *)frameRate compBounds:(CGRect)compBounds { + (id)shapeItemWithJSON:(NSDictionary *)itemJSON frameRate:(NSNumber *)frameRate compBounds:(CGRect)compBounds {
NSString *type = itemJSON[@"ty"]; NSString *type = itemJSON[@"ty"];
if ([type isEqualToString:@"gr"]) { if ([type isEqualToString:@"gr"]) {
LAShapeGroup *group = [[LAShapeGroup alloc] initWithJSON:itemJSON frameRate:frameRate compBounds:compBounds]; LOTShapeGroup *group = [[LOTShapeGroup alloc] initWithJSON:itemJSON frameRate:frameRate compBounds:compBounds];
return group; return group;
} else if ([type isEqualToString:@"st"]) { } else if ([type isEqualToString:@"st"]) {
LAShapeStroke *stroke = [[LAShapeStroke alloc] initWithJSON:itemJSON frameRate:frameRate]; LOTShapeStroke *stroke = [[LOTShapeStroke alloc] initWithJSON:itemJSON frameRate:frameRate];
return stroke; return stroke;
} else if ([type isEqualToString:@"fl"]) { } else if ([type isEqualToString:@"fl"]) {
LAShapeFill *fill = [[LAShapeFill alloc] initWithJSON:itemJSON frameRate:frameRate]; LOTShapeFill *fill = [[LOTShapeFill alloc] initWithJSON:itemJSON frameRate:frameRate];
return fill; return fill;
} else if ([type isEqualToString:@"tr"]) { } else if ([type isEqualToString:@"tr"]) {
LAShapeTransform *transform = [[LAShapeTransform alloc] initWithJSON:itemJSON frameRate:frameRate compBounds:compBounds]; LOTShapeTransform *transform = [[LOTShapeTransform alloc] initWithJSON:itemJSON frameRate:frameRate compBounds:compBounds];
return transform; return transform;
} else if ([type isEqualToString:@"sh"]) { } else if ([type isEqualToString:@"sh"]) {
LAShapePath *path = [[LAShapePath alloc] initWithJSON:itemJSON frameRate:frameRate]; LOTShapePath *path = [[LOTShapePath alloc] initWithJSON:itemJSON frameRate:frameRate];
return path; return path;
} else if ([type isEqualToString:@"el"]) { } else if ([type isEqualToString:@"el"]) {
LAShapeCircle *circle = [[LAShapeCircle alloc] initWithJSON:itemJSON frameRate:frameRate]; LOTShapeCircle *circle = [[LOTShapeCircle alloc] initWithJSON:itemJSON frameRate:frameRate];
return circle; return circle;
} else if ([type isEqualToString:@"rc"]) { } else if ([type isEqualToString:@"rc"]) {
LAShapeRectangle *rectangle = [[LAShapeRectangle alloc] initWithJSON:itemJSON frameRate:frameRate]; LOTShapeRectangle *rectangle = [[LOTShapeRectangle alloc] initWithJSON:itemJSON frameRate:frameRate];
return rectangle; return rectangle;
} else if ([type isEqualToString:@"tm"]) { } else if ([type isEqualToString:@"tm"]) {
LAShapeTrimPath *trim = [[LAShapeTrimPath alloc] initWithJSON:itemJSON frameRate:frameRate]; LOTShapeTrimPath *trim = [[LOTShapeTrimPath alloc] initWithJSON:itemJSON frameRate:frameRate];
return trim; return trim;
} }
return nil; return nil;

View File

@ -1,5 +1,5 @@
// //
// LAShapePath.h // LOTShapePath.h
// LottieAnimator // LottieAnimator
// //
// Created by Brandon Withrow on 12/15/15. // Created by Brandon Withrow on 12/15/15.
@ -8,14 +8,14 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
@class LAAnimatableShapeValue; @class LOTAnimatableShapeValue;
@interface LAShapePath : NSObject @interface LOTShapePath : NSObject
- (instancetype)initWithJSON:(NSDictionary *)jsonDictionary frameRate:(NSNumber *)frameRate; - (instancetype)initWithJSON:(NSDictionary *)jsonDictionary frameRate:(NSNumber *)frameRate;
@property (nonatomic, readonly) BOOL closed; @property (nonatomic, readonly) BOOL closed;
@property (nonatomic, readonly) NSNumber *index; @property (nonatomic, readonly) NSNumber *index;
@property (nonatomic, readonly) LAAnimatableShapeValue *shapePath; @property (nonatomic, readonly) LOTAnimatableShapeValue *shapePath;
@end @end

View File

@ -1,15 +1,15 @@
// //
// LAShapePath.m // LOTShapePath.m
// LottieAnimator // LottieAnimator
// //
// Created by Brandon Withrow on 12/15/15. // Created by Brandon Withrow on 12/15/15.
// Copyright © 2015 Brandon Withrow. All rights reserved. // Copyright © 2015 Brandon Withrow. All rights reserved.
// //
#import "LAShapePath.h" #import "LOTShapePath.h"
#import "LAAnimatableShapeValue.h" #import "LOTAnimatableShapeValue.h"
@implementation LAShapePath @implementation LOTShapePath
- (instancetype)initWithJSON:(NSDictionary *)jsonDictionary frameRate:(NSNumber *)frameRate { - (instancetype)initWithJSON:(NSDictionary *)jsonDictionary frameRate:(NSNumber *)frameRate {
self = [super init]; self = [super init];
@ -24,7 +24,7 @@
_closed = [jsonDictionary[@"closed"] boolValue]; _closed = [jsonDictionary[@"closed"] boolValue];
NSDictionary *shape = jsonDictionary[@"ks"]; NSDictionary *shape = jsonDictionary[@"ks"];
if (shape) { if (shape) {
_shapePath = [[LAAnimatableShapeValue alloc] initWithShapeValues:shape frameRate:frameRate closed:_closed]; _shapePath = [[LOTAnimatableShapeValue alloc] initWithShapeValues:shape frameRate:frameRate closed:_closed];
} }
} }

View File

@ -0,0 +1,22 @@
//
// LOTShapeRectangle.h
// LottieAnimator
//
// Created by Brandon Withrow on 12/15/15.
// Copyright © 2015 Brandon Withrow. All rights reserved.
//
#import <Foundation/Foundation.h>
@class LOTAnimatableBoundsValue;
@class LOTAnimatablePointValue;
@class LOTAnimatableNumberValue;
@interface LOTShapeRectangle : NSObject
- (instancetype)initWithJSON:(NSDictionary *)jsonDictionary frameRate:(NSNumber *)frameRate;
@property (nonatomic, readonly) LOTAnimatablePointValue *position;
@property (nonatomic, readonly) LOTAnimatablePointValue *size;
@property (nonatomic, readonly) LOTAnimatableNumberValue *cornerRadius;
@end

View File

@ -1,17 +1,17 @@
// //
// LAShapeRectangle.m // LOTShapeRectangle.m
// LottieAnimator // LottieAnimator
// //
// Created by Brandon Withrow on 12/15/15. // Created by Brandon Withrow on 12/15/15.
// Copyright © 2015 Brandon Withrow. All rights reserved. // Copyright © 2015 Brandon Withrow. All rights reserved.
// //
#import "LAShapeRectangle.h" #import "LOTShapeRectangle.h"
#import "LAAnimatableBoundsValue.h" #import "LOTAnimatableBoundsValue.h"
#import "LAAnimatablePointValue.h" #import "LOTAnimatablePointValue.h"
#import "LAAnimatableNumberValue.h" #import "LOTAnimatableNumberValue.h"
@implementation LAShapeRectangle @implementation LOTShapeRectangle
- (instancetype)initWithJSON:(NSDictionary *)jsonDictionary frameRate:(NSNumber *)frameRate { - (instancetype)initWithJSON:(NSDictionary *)jsonDictionary frameRate:(NSNumber *)frameRate {
self = [super init]; self = [super init];
@ -24,18 +24,18 @@
- (void)_mapFromJSON:(NSDictionary *)jsonDictionary frameRate:(NSNumber *)frameRate { - (void)_mapFromJSON:(NSDictionary *)jsonDictionary frameRate:(NSNumber *)frameRate {
NSDictionary *position = jsonDictionary[@"p"]; NSDictionary *position = jsonDictionary[@"p"];
if (position) { if (position) {
_position = [[LAAnimatablePointValue alloc] initWithPointValues:position frameRate:frameRate]; _position = [[LOTAnimatablePointValue alloc] initWithPointValues:position frameRate:frameRate];
_position.usePathAnimation = NO; _position.usePathAnimation = NO;
} }
NSDictionary *cornerRadius = jsonDictionary[@"r"]; NSDictionary *cornerRadius = jsonDictionary[@"r"];
if (cornerRadius) { if (cornerRadius) {
_cornerRadius = [[LAAnimatableNumberValue alloc] initWithNumberValues:cornerRadius frameRate:frameRate]; _cornerRadius = [[LOTAnimatableNumberValue alloc] initWithNumberValues:cornerRadius frameRate:frameRate];
} }
NSDictionary *size = jsonDictionary[@"s"]; NSDictionary *size = jsonDictionary[@"s"];
if (size) { if (size) {
_size = [[LAAnimatablePointValue alloc] initWithPointValues:size frameRate:frameRate]; _size = [[LOTAnimatablePointValue alloc] initWithPointValues:size frameRate:frameRate];
} }
} }

View File

@ -0,0 +1,39 @@
//
// LOTShapeStroke.h
// LottieAnimator
//
// Created by Brandon Withrow on 12/15/15.
// Copyright © 2015 Brandon Withrow. All rights reserved.
//
#import <Foundation/Foundation.h>
@class LOTAnimatableColorValue;
@class LOTAnimatableNumberValue;
typedef enum : NSUInteger {
LOTLineCapTypeButt,
LOTLineCapTypeRound,
LOTLineCapTypeUnknown
} LOTLineCapType;
typedef enum : NSUInteger {
LOTLineJoinTypeMiter,
LOTLineJoinTypeRound,
LOTLineJoinTypeBevel
} LOTLineJoinType;
@interface LOTShapeStroke : NSObject
- (instancetype)initWithJSON:(NSDictionary *)jsonDictionary frameRate:(NSNumber *)frameRate;
@property (nonatomic, readonly) BOOL fillEnabled;
@property (nonatomic, readonly) LOTAnimatableColorValue *color;
@property (nonatomic, readonly) LOTAnimatableNumberValue *opacity;
@property (nonatomic, readonly) LOTAnimatableNumberValue *width;
@property (nonatomic, readonly) LOTLineCapType capType;
@property (nonatomic, readonly) LOTLineJoinType joinType;
@property (nonatomic, readonly) NSArray *lineDashPattern;
@end

View File

@ -1,16 +1,16 @@
// //
// LAShapeStroke.m // LOTShapeStroke.m
// LottieAnimator // LottieAnimator
// //
// Created by Brandon Withrow on 12/15/15. // Created by Brandon Withrow on 12/15/15.
// Copyright © 2015 Brandon Withrow. All rights reserved. // Copyright © 2015 Brandon Withrow. All rights reserved.
// //
#import "LAShapeStroke.h" #import "LOTShapeStroke.h"
#import "LAAnimatableNumberValue.h" #import "LOTAnimatableNumberValue.h"
#import "LAAnimatableColorValue.h" #import "LOTAnimatableColorValue.h"
@implementation LAShapeStroke @implementation LOTShapeStroke
- (instancetype)initWithJSON:(NSDictionary *)jsonDictionary frameRate:(NSNumber *)frameRate { - (instancetype)initWithJSON:(NSDictionary *)jsonDictionary frameRate:(NSNumber *)frameRate {
self = [super init]; self = [super init];
@ -23,17 +23,17 @@
- (void)_mapFromJSON:(NSDictionary *)jsonDictionary frameRate:(NSNumber *)frameRate { - (void)_mapFromJSON:(NSDictionary *)jsonDictionary frameRate:(NSNumber *)frameRate {
NSDictionary *color = jsonDictionary[@"c"]; NSDictionary *color = jsonDictionary[@"c"];
if (color) { if (color) {
_color = [[LAAnimatableColorValue alloc] initWithColorValues:color frameRate:frameRate]; _color = [[LOTAnimatableColorValue alloc] initWithColorValues:color frameRate:frameRate];
} }
NSDictionary *width = jsonDictionary[@"w"]; NSDictionary *width = jsonDictionary[@"w"];
if (width) { if (width) {
_width = [[LAAnimatableNumberValue alloc] initWithNumberValues:width frameRate:frameRate]; _width = [[LOTAnimatableNumberValue alloc] initWithNumberValues:width frameRate:frameRate];
} }
NSDictionary *opacity = jsonDictionary[@"o"]; NSDictionary *opacity = jsonDictionary[@"o"];
if (opacity) { if (opacity) {
_opacity = [[LAAnimatableNumberValue alloc] initWithNumberValues:opacity frameRate:frameRate]; _opacity = [[LOTAnimatableNumberValue alloc] initWithNumberValues:opacity frameRate:frameRate];
[_opacity remapValuesFromMin:@0 fromMax:@100 toMin:@0 toMax:@1]; [_opacity remapValuesFromMin:@0 fromMax:@100 toMin:@0 toMax:@1];
} }
@ -51,7 +51,7 @@
continue; continue;
} }
NSDictionary *value = dash[@"v"]; NSDictionary *value = dash[@"v"];
LAAnimatableNumberValue *numberValue = [[LAAnimatableNumberValue alloc] initWithNumberValues:value frameRate:frameRate]; LOTAnimatableNumberValue *numberValue = [[LOTAnimatableNumberValue alloc] initWithNumberValues:value frameRate:frameRate];
[dashPattern addObject:[numberValue.initialValue copy]]; [dashPattern addObject:[numberValue.initialValue copy]];
} }
_lineDashPattern = dashPattern; _lineDashPattern = dashPattern;

View File

@ -0,0 +1,29 @@
//
// LOTShapeTransform.h
// LottieAnimator
//
// Created by Brandon Withrow on 12/15/15.
// Copyright © 2015 Brandon Withrow. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <CoreGraphics/CoreGraphics.h>
@class LOTAnimatableNumberValue;
@class LOTAnimatablePointValue;
@class LOTAnimatableScaleValue;
@interface LOTShapeTransform : NSObject
+ (instancetype)transformIdentityWithCompBounds:(CGRect)compBounds;
- (instancetype)initWithJSON:(NSDictionary *)jsonDictionary frameRate:(NSNumber *)frameRate compBounds:(CGRect)compBounds;
@property (nonatomic, readonly) CGRect compBounds;
@property (nonatomic, readonly) LOTAnimatablePointValue *position;
@property (nonatomic, readonly) LOTAnimatablePointValue *anchor;
@property (nonatomic, readonly) LOTAnimatableScaleValue *scale;
@property (nonatomic, readonly) LOTAnimatableNumberValue *rotation;
@property (nonatomic, readonly) LOTAnimatableNumberValue *opacity;
@end

View File

@ -1,18 +1,18 @@
// //
// LAShapeTransform.m // LOTShapeTransform.m
// LottieAnimator // LottieAnimator
// //
// Created by Brandon Withrow on 12/15/15. // Created by Brandon Withrow on 12/15/15.
// Copyright © 2015 Brandon Withrow. All rights reserved. // Copyright © 2015 Brandon Withrow. All rights reserved.
// //
#import "LAShapeTransform.h" #import "LOTShapeTransform.h"
#import "LAAnimatableNumberValue.h" #import "LOTAnimatableNumberValue.h"
#import "LAAnimatablePointValue.h" #import "LOTAnimatablePointValue.h"
#import "LAAnimatableScaleValue.h" #import "LOTAnimatableScaleValue.h"
#import "LAHelpers.h" #import "LOTHelpers.h"
@implementation LAShapeTransform @implementation LOTShapeTransform
+ (instancetype)transformIdentityWithCompBounds:(CGRect)compBounds { + (instancetype)transformIdentityWithCompBounds:(CGRect)compBounds {
NSDictionary *transformIdentity = @{@"p" : @{@"k" : @[@0, @0]}, NSDictionary *transformIdentity = @{@"p" : @{@"k" : @[@0, @0]},
@ -22,7 +22,7 @@
@"o" : @{@"k" : @[@100]}}; @"o" : @{@"k" : @[@100]}};
return [[LAShapeTransform alloc] initWithJSON:transformIdentity frameRate:@60 compBounds:compBounds]; return [[LOTShapeTransform alloc] initWithJSON:transformIdentity frameRate:@60 compBounds:compBounds];
} }
- (instancetype)initWithJSON:(NSDictionary *)jsonDictionary frameRate:(NSNumber *)frameRate compBounds:(CGRect)compBounds { - (instancetype)initWithJSON:(NSDictionary *)jsonDictionary frameRate:(NSNumber *)frameRate compBounds:(CGRect)compBounds {
@ -38,24 +38,24 @@
NSDictionary *position = jsonDictionary[@"p"]; NSDictionary *position = jsonDictionary[@"p"];
if (position) { if (position) {
_position = [[LAAnimatablePointValue alloc] initWithPointValues:position frameRate:frameRate]; _position = [[LOTAnimatablePointValue alloc] initWithPointValues:position frameRate:frameRate];
} }
NSDictionary *anchor = jsonDictionary[@"a"]; NSDictionary *anchor = jsonDictionary[@"a"];
if (anchor) { if (anchor) {
_anchor = [[LAAnimatablePointValue alloc] initWithPointValues:anchor frameRate:frameRate]; _anchor = [[LOTAnimatablePointValue alloc] initWithPointValues:anchor frameRate:frameRate];
[_anchor remapPointsFromBounds:compBounds toBounds:CGRectMake(0, 0, 1, 1)]; [_anchor remapPointsFromBounds:compBounds toBounds:CGRectMake(0, 0, 1, 1)];
_anchor.usePathAnimation = NO; _anchor.usePathAnimation = NO;
} }
NSDictionary *scale = jsonDictionary[@"s"]; NSDictionary *scale = jsonDictionary[@"s"];
if (scale) { if (scale) {
_scale = [[LAAnimatableScaleValue alloc] initWithScaleValues:scale frameRate:frameRate]; _scale = [[LOTAnimatableScaleValue alloc] initWithScaleValues:scale frameRate:frameRate];
} }
NSDictionary *rotation = jsonDictionary[@"r"]; NSDictionary *rotation = jsonDictionary[@"r"];
if (rotation) { if (rotation) {
_rotation = [[LAAnimatableNumberValue alloc] initWithNumberValues:rotation frameRate:frameRate]; _rotation = [[LOTAnimatableNumberValue alloc] initWithNumberValues:rotation frameRate:frameRate];
[_rotation remapValueWithBlock:^CGFloat(CGFloat inValue) { [_rotation remapValueWithBlock:^CGFloat(CGFloat inValue) {
return DegreesToRadians(inValue); return DegreesToRadians(inValue);
}]; }];
@ -63,13 +63,13 @@
NSDictionary *opacity = jsonDictionary[@"o"]; NSDictionary *opacity = jsonDictionary[@"o"];
if (opacity) { if (opacity) {
_opacity = [[LAAnimatableNumberValue alloc] initWithNumberValues:opacity frameRate:frameRate]; _opacity = [[LOTAnimatableNumberValue alloc] initWithNumberValues:opacity frameRate:frameRate];
[_opacity remapValuesFromMin:@0 fromMax:@100 toMin:@0 toMax:@1]; [_opacity remapValuesFromMin:@0 fromMax:@100 toMin:@0 toMax:@1];
} }
} }
- (NSString *)description { - (NSString *)description {
return [NSString stringWithFormat:@"LAShapeTransform \"Position: %@ Anchor: %@ Scale: %@ Rotation: %@ Opacity: %@\"", _position.description, _anchor.description, _scale.description, _rotation.description, _opacity.description]; return [NSString stringWithFormat:@"LOTShapeTransform \"Position: %@ Anchor: %@ Scale: %@ Rotation: %@ Opacity: %@\"", _position.description, _anchor.description, _scale.description, _rotation.description, _opacity.description];
} }
@end @end

View File

@ -0,0 +1,19 @@
//
// LOTShapeTrimPath.h
// LottieAnimator
//
// Created by brandon_withrow on 7/26/16.
// Copyright © 2016 Brandon Withrow. All rights reserved.
//
#import <Foundation/Foundation.h>
@class LOTAnimatableNumberValue;
@interface LOTShapeTrimPath : NSObject
- (instancetype)initWithJSON:(NSDictionary *)jsonDictionary frameRate:(NSNumber *)frameRate;
@property (nonatomic, readonly) LOTAnimatableNumberValue *start;
@property (nonatomic, readonly) LOTAnimatableNumberValue *end;
@property (nonatomic, readonly) LOTAnimatableNumberValue *offset;
@end

View File

@ -1,15 +1,15 @@
// //
// LAShapeTrimPath.m // LOTShapeTrimPath.m
// LottieAnimator // LottieAnimator
// //
// Created by brandon_withrow on 7/26/16. // Created by brandon_withrow on 7/26/16.
// Copyright © 2016 Brandon Withrow. All rights reserved. // Copyright © 2016 Brandon Withrow. All rights reserved.
// //
#import "LAShapeTrimPath.h" #import "LOTShapeTrimPath.h"
#import "LAAnimatableNumberValue.h" #import "LOTAnimatableNumberValue.h"
@implementation LAShapeTrimPath @implementation LOTShapeTrimPath
- (instancetype)initWithJSON:(NSDictionary *)jsonDictionary frameRate:(NSNumber *)frameRate { - (instancetype)initWithJSON:(NSDictionary *)jsonDictionary frameRate:(NSNumber *)frameRate {
self = [super init]; self = [super init];
@ -22,19 +22,19 @@
- (void)_mapFromJSON:(NSDictionary *)jsonDictionary frameRate:(NSNumber *)frameRate { - (void)_mapFromJSON:(NSDictionary *)jsonDictionary frameRate:(NSNumber *)frameRate {
NSDictionary *start = jsonDictionary[@"s"]; NSDictionary *start = jsonDictionary[@"s"];
if (start) { if (start) {
_start = [[LAAnimatableNumberValue alloc] initWithNumberValues:start frameRate:frameRate]; _start = [[LOTAnimatableNumberValue alloc] initWithNumberValues:start frameRate:frameRate];
[_start remapValuesFromMin:@0 fromMax:@100 toMin:@0 toMax:@1]; [_start remapValuesFromMin:@0 fromMax:@100 toMin:@0 toMax:@1];
} }
NSDictionary *end = jsonDictionary[@"e"]; NSDictionary *end = jsonDictionary[@"e"];
if (end) { if (end) {
_end = [[LAAnimatableNumberValue alloc] initWithNumberValues:end frameRate:frameRate]; _end = [[LOTAnimatableNumberValue alloc] initWithNumberValues:end frameRate:frameRate];
[_end remapValuesFromMin:@0 fromMax:@100 toMin:@0 toMax:@1]; [_end remapValuesFromMin:@0 fromMax:@100 toMin:@0 toMax:@1];
} }
NSDictionary *offset = jsonDictionary[@"o"]; NSDictionary *offset = jsonDictionary[@"o"];
if (offset) { if (offset) {
_offset = [[LAAnimatableNumberValue alloc] initWithNumberValues:offset frameRate:frameRate]; _offset = [[LOTAnimatableNumberValue alloc] initWithNumberValues:offset frameRate:frameRate];
} }
} }

View File

@ -1,13 +1,13 @@
// //
// LAPlatformCompat.h // LOTPlatformCompat.h
// Lottie // Lottie
// //
// Created by Oleksii Pavlovskyi on 2/2/17. // Created by Oleksii Pavlovskyi on 2/2/17.
// Copyright (c) 2017 Airbnb. All rights reserved. // Copyright (c) 2017 Airbnb. All rights reserved.
// //
#ifndef LAPlatformCompat_h #ifndef LOTPlatformCompat_h
#define LAPlatformCompat_h #define LOTPlatformCompat_h
#import "TargetConditionals.h" #import "TargetConditionals.h"

View File

@ -1,5 +1,5 @@
// //
// LAAnimationTransitionController.m // LOTAnimationTransitionController.m
// Lottie // Lottie
// //
// Created by Brandon Withrow on 1/18/17. // Created by Brandon Withrow on 1/18/17.
@ -8,11 +8,11 @@
#if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR #if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
#import "LAAnimationTransitionController.h" #import "LOTAnimationTransitionController.h"
#import "LAAnimationView.h" #import "LOTAnimationView.h"
@implementation LAAnimationTransitionController { @implementation LOTAnimationTransitionController {
LAAnimationView *tranistionAnimationView_; LOTAnimationView *tranistionAnimationView_;
NSString *fromLayerName_; NSString *fromLayerName_;
NSString *toLayerName_; NSString *toLayerName_;
} }
@ -22,7 +22,7 @@
toLayerNamed:(NSString *)toLayer { toLayerNamed:(NSString *)toLayer {
self = [super init]; self = [super init];
if (self) { if (self) {
tranistionAnimationView_ = [LAAnimationView animationNamed:animation]; tranistionAnimationView_ = [LOTAnimationView animationNamed:animation];
fromLayerName_ = fromLayer; fromLayerName_ = fromLayer;
toLayerName_ = toLayer; toLayerName_ = toLayer;
} }
@ -92,4 +92,4 @@
@end @end
#endif #endif

View File

@ -1,22 +1,22 @@
// //
// LAAnimationView // LOTAnimationView
// LottieAnimator // LottieAnimator
// //
// Created by Brandon Withrow on 12/14/15. // Created by Brandon Withrow on 12/14/15.
// Copyright © 2015 Brandon Withrow. All rights reserved. // Copyright © 2015 Brandon Withrow. All rights reserved.
// //
#import "LAAnimationView.h" #import "LOTAnimationView.h"
#import "LAPlatformCompat.h" #import "LOTPlatformCompat.h"
#import "LALayerView.h" #import "LOTLayerView.h"
#import "LAModels.h" #import "LOTModels.h"
#import "LAHelpers.h" #import "LOTHelpers.h"
#import "LAAnimationView_Internal.h" #import "LOTAnimationView_Internal.h"
#import "LAAnimationCache.h" #import "LOTAnimationCache.h"
const NSTimeInterval singleFrameTimeValue = 1.0 / 60.0; const NSTimeInterval singleFrameTimeValue = 1.0 / 60.0;
@implementation LAAnimationState { @implementation LOTAnimationState {
BOOL _animationIsPlaying; BOOL _animationIsPlaying;
BOOL _playFromBeginning; BOOL _playFromBeginning;
CFTimeInterval _previousLocalTime; CFTimeInterval _previousLocalTime;
@ -147,25 +147,25 @@ const NSTimeInterval singleFrameTimeValue = 1.0 / 60.0;
- (void)logStats:(NSString *)logName { - (void)logStats:(NSString *)logName {
CFTimeInterval localTime = [_layer convertTime:CACurrentMediaTime() fromLayer:nil]; CFTimeInterval localTime = [_layer convertTime:CACurrentMediaTime() fromLayer:nil];
NSLog(@"LAAnimationState %@ || Is Playing %@ || Duration %f || Speed %lf || Progress %lf || Local Time %lf || ", NSLog(@"LOTAnimationState %@ || Is Playing %@ || Duration %f || Speed %lf || Progress %lf || Local Time %lf || ",
logName, (_animationIsPlaying ? @"YES" : @"NO"), self.animationDuration, _layer.speed, self.animatedProgress, localTime); logName, (_animationIsPlaying ? @"YES" : @"NO"), self.animationDuration, _layer.speed, self.animatedProgress, localTime);
} }
@end @end
@interface LACustomChild : NSObject @interface LOTCustomChild : NSObject
@property (nonatomic, strong) LAView *childView; @property (nonatomic, strong) LOTView *childView;
@property (nonatomic, weak) LALayerView *layer; @property (nonatomic, weak) LOTLayerView *layer;
@property (nonatomic, assign) LAConstraintType constraint; @property (nonatomic, assign) LOTConstraintType constraint;
@end @end
@implementation LACustomChild @implementation LOTCustomChild
@end @end
@implementation LAAnimationView { @implementation LOTAnimationView {
NSDictionary *_layerMap; NSDictionary *_layerMap;
NSDictionary *_layerNameMap; NSDictionary *_layerNameMap;
NSMutableArray *_customLayers; NSMutableArray *_customLayers;
@ -180,9 +180,9 @@ const NSTimeInterval singleFrameTimeValue = 1.0 / 60.0;
NSArray *components = [animationName componentsSeparatedByString:@"."]; NSArray *components = [animationName componentsSeparatedByString:@"."];
animationName = components.firstObject; animationName = components.firstObject;
LAComposition *comp = [[LAAnimationCache sharedCache] animationForKey:animationName]; LOTComposition *comp = [[LOTAnimationCache sharedCache] animationForKey:animationName];
if (comp) { if (comp) {
return [[LAAnimationView alloc] initWithModel:comp]; return [[LOTAnimationView alloc] initWithModel:comp];
} }
NSError *error; NSError *error;
@ -191,28 +191,28 @@ const NSTimeInterval singleFrameTimeValue = 1.0 / 60.0;
NSDictionary *JSONObject = jsonData ? [NSJSONSerialization JSONObjectWithData:jsonData NSDictionary *JSONObject = jsonData ? [NSJSONSerialization JSONObjectWithData:jsonData
options:0 error:&error] : nil; options:0 error:&error] : nil;
if (JSONObject && !error) { if (JSONObject && !error) {
LAComposition *laScene = [[LAComposition alloc] initWithJSON:JSONObject]; LOTComposition *laScene = [[LOTComposition alloc] initWithJSON:JSONObject];
[[LAAnimationCache sharedCache] addAnimation:laScene forKey:animationName]; [[LOTAnimationCache sharedCache] addAnimation:laScene forKey:animationName];
return [[LAAnimationView alloc] initWithModel:laScene]; return [[LOTAnimationView alloc] initWithModel:laScene];
} }
return [[LAAnimationView alloc] initWithModel:nil]; return [[LOTAnimationView alloc] initWithModel:nil];
} }
+ (instancetype)animationFromJSON:(NSDictionary *)animationJSON { + (instancetype)animationFromJSON:(NSDictionary *)animationJSON {
LAComposition *laScene = [[LAComposition alloc] initWithJSON:animationJSON]; LOTComposition *laScene = [[LOTComposition alloc] initWithJSON:animationJSON];
return [[LAAnimationView alloc] initWithModel:laScene]; return [[LOTAnimationView alloc] initWithModel:laScene];
} }
- (instancetype)initWithContentsOfURL:(NSURL *)url { - (instancetype)initWithContentsOfURL:(NSURL *)url {
self = [super initWithFrame:CGRectZero]; self = [super initWithFrame:CGRectZero];
if (self) { if (self) {
LAComposition *laScene = [[LAAnimationCache sharedCache] animationForKey:url.absoluteString]; LOTComposition *laScene = [[LOTAnimationCache sharedCache] animationForKey:url.absoluteString];
if (laScene) { if (laScene) {
[self _initializeAnimationContainer]; [self _initializeAnimationContainer];
[self _setupWithSceneModel:laScene restoreAnimationState:NO]; [self _setupWithSceneModel:laScene restoreAnimationState:NO];
} else { } else {
_animationState = [[LAAnimationState alloc] initWithDuration:singleFrameTimeValue layer:nil]; _animationState = [[LOTAnimationState alloc] initWithDuration:singleFrameTimeValue layer:nil];
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){ dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){
NSData *animationData = [NSData dataWithContentsOfURL:url]; NSData *animationData = [NSData dataWithContentsOfURL:url];
if (!animationData) { if (!animationData) {
@ -225,9 +225,9 @@ const NSTimeInterval singleFrameTimeValue = 1.0 / 60.0;
return; return;
} }
LAComposition *laScene = [[LAComposition alloc] initWithJSON:animationJSON]; LOTComposition *laScene = [[LOTComposition alloc] initWithJSON:animationJSON];
dispatch_async(dispatch_get_main_queue(), ^(void){ dispatch_async(dispatch_get_main_queue(), ^(void){
[[LAAnimationCache sharedCache] addAnimation:laScene forKey:url.absoluteString]; [[LOTAnimationCache sharedCache] addAnimation:laScene forKey:url.absoluteString];
[self _initializeAnimationContainer]; [self _initializeAnimationContainer];
[self _setupWithSceneModel:laScene restoreAnimationState:YES]; [self _setupWithSceneModel:laScene restoreAnimationState:YES];
}); });
@ -237,7 +237,7 @@ const NSTimeInterval singleFrameTimeValue = 1.0 / 60.0;
return self; return self;
} }
- (instancetype)initWithModel:(LAComposition *)model { - (instancetype)initWithModel:(LOTComposition *)model {
self = [super initWithFrame:model.compBounds]; self = [super initWithFrame:model.compBounds];
if (self) { if (self) {
[self _initializeAnimationContainer]; [self _initializeAnimationContainer];
@ -268,11 +268,11 @@ const NSTimeInterval singleFrameTimeValue = 1.0 / 60.0;
#endif #endif
- (void)_setupWithSceneModel:(LAComposition *)model restoreAnimationState:(BOOL)restoreAnimation { - (void)_setupWithSceneModel:(LOTComposition *)model restoreAnimationState:(BOOL)restoreAnimation {
_sceneModel = model; _sceneModel = model;
[self _buildSubviewsFromModel]; [self _buildSubviewsFromModel];
LAAnimationState *oldState = _animationState; LOTAnimationState *oldState = _animationState;
_animationState = [[LAAnimationState alloc] initWithDuration:_sceneModel.timeDuration layer:_animationContainer]; _animationState = [[LOTAnimationState alloc] initWithDuration:_sceneModel.timeDuration layer:_animationContainer];
if (restoreAnimation && oldState) { if (restoreAnimation && oldState) {
[self setLoopAnimation:oldState.loopAnimation]; [self setLoopAnimation:oldState.loopAnimation];
@ -290,7 +290,7 @@ const NSTimeInterval singleFrameTimeValue = 1.0 / 60.0;
- (void)_buildSubviewsFromModel { - (void)_buildSubviewsFromModel {
if (_customLayers) { if (_customLayers) {
for (LACustomChild *child in _customLayers) { for (LOTCustomChild *child in _customLayers) {
[child.childView.layer removeFromSuperlayer]; [child.childView.layer removeFromSuperlayer];
} }
_customLayers = nil; _customLayers = nil;
@ -314,16 +314,16 @@ const NSTimeInterval singleFrameTimeValue = 1.0 / 60.0;
NSArray *reversedItems = [[_sceneModel.layers reverseObjectEnumerator] allObjects]; NSArray *reversedItems = [[_sceneModel.layers reverseObjectEnumerator] allObjects];
LALayerView *maskedLayer = nil; LOTLayerView *maskedLayer = nil;
for (LALayer *layer in reversedItems) { for (LOTLayer *layer in reversedItems) {
LALayerView *layerView = [[LALayerView alloc] initWithModel:layer inComposition:_sceneModel]; LOTLayerView *layerView = [[LOTLayerView alloc] initWithModel:layer inComposition:_sceneModel];
layerMap[layer.layerID] = layerView; layerMap[layer.layerID] = layerView;
layerNameMap[layer.layerName] = layerView; layerNameMap[layer.layerName] = layerView;
if (maskedLayer) { if (maskedLayer) {
maskedLayer.mask = layerView; maskedLayer.mask = layerView;
maskedLayer = nil; maskedLayer = nil;
} else { } else {
if (layer.matteType == LAMatteTypeAdd) { if (layer.matteType == LOTMatteTypeAdd) {
maskedLayer = layerView; maskedLayer = layerView;
} }
[_animationContainer addSublayer:layerView]; [_animationContainer addSublayer:layerView];
@ -338,12 +338,12 @@ const NSTimeInterval singleFrameTimeValue = 1.0 / 60.0;
return; return;
} }
for (LACustomChild *child in _customLayers) { for (LOTCustomChild *child in _customLayers) {
switch (child.constraint) { switch (child.constraint) {
case LAConstraintTypeAlignToLayer: case LOTConstraintTypeAlignToLayer:
child.childView.frame = child.layer.bounds; child.childView.frame = child.layer.bounds;
break; break;
case LAConstraintTypeAlignToBounds: { case LOTConstraintTypeAlignToBounds: {
CGRect selfBounds = _animationContainer.frame; CGRect selfBounds = _animationContainer.frame;
CGRect convertedBounds = [child.childView.layer.superlayer convertRect:selfBounds fromLayer:self.layer]; CGRect convertedBounds = [child.childView.layer.superlayer convertRect:selfBounds fromLayer:self.layer];
child.childView.layer.frame = convertedBounds; child.childView.layer.frame = convertedBounds;
@ -360,7 +360,7 @@ const NSTimeInterval singleFrameTimeValue = 1.0 / 60.0;
[self playWithCompletion:nil]; [self playWithCompletion:nil];
} }
- (void)playWithCompletion:(LAAnimationCompletionBlock)completion { - (void)playWithCompletion:(LOTAnimationCompletionBlock)completion {
if (completion) { if (completion) {
self.completionBlock = completion; self.completionBlock = completion;
} }
@ -390,11 +390,11 @@ const NSTimeInterval singleFrameTimeValue = 1.0 / 60.0;
} }
} }
- (void)addSubview:(LAView *)view - (void)addSubview:(LOTView *)view
toLayerNamed:(NSString *)layer { toLayerNamed:(NSString *)layer {
LAConstraintType constraint = LAConstraintTypeAlignToBounds; LOTConstraintType constraint = LOTConstraintTypeAlignToBounds;
LALayerView *layerObject = _layerNameMap[layer]; LOTLayerView *layerObject = _layerNameMap[layer];
LACustomChild *newChild = [[LACustomChild alloc] init]; LOTCustomChild *newChild = [[LOTCustomChild alloc] init];
newChild.constraint = constraint; newChild.constraint = constraint;
newChild.childView = view; newChild.childView = view;
@ -502,22 +502,22 @@ const NSTimeInterval singleFrameTimeValue = 1.0 / 60.0;
#if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR #if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
#define LAViewContentMode UIViewContentMode #define LOTViewContentMode UIViewContentMode
#define LAViewContentModeScaleToFill UIViewContentModeScaleToFill #define LOTViewContentModeScaleToFill UIViewContentModeScaleToFill
#define LAViewContentModeScaleAspectFit UIViewContentModeScaleAspectFit #define LOTViewContentModeScaleAspectFit UIViewContentModeScaleAspectFit
#define LAViewContentModeScaleAspectFill UIViewContentModeScaleAspectFill #define LOTViewContentModeScaleAspectFill UIViewContentModeScaleAspectFill
#define LAViewContentModeRedraw UIViewContentModeRedraw #define LOTViewContentModeRedraw UIViewContentModeRedraw
#define LAViewContentModeCenter UIViewContentModeCenter #define LOTViewContentModeCenter UIViewContentModeCenter
#define LAViewContentModeTop UIViewContentModeTop #define LOTViewContentModeTop UIViewContentModeTop
#define LAViewContentModeBottom UIViewContentModeBottom #define LOTViewContentModeBottom UIViewContentModeBottom
#define LAViewContentModeLeft UIViewContentModeLeft #define LOTViewContentModeLeft UIViewContentModeLeft
#define LAViewContentModeRight UIViewContentModeRight #define LOTViewContentModeRight UIViewContentModeRight
#define LAViewContentModeTopLeft UIViewContentModeTopLeft #define LOTViewContentModeTopLeft UIViewContentModeTopLeft
#define LAViewContentModeTopRight UIViewContentModeTopRight #define LOTViewContentModeTopRight UIViewContentModeTopRight
#define LAViewContentModeBottomLeft UIViewContentModeBottomLeft #define LOTViewContentModeBottomLeft UIViewContentModeBottomLeft
#define LAViewContentModeBottomRight UIViewContentModeBottomRight #define LOTViewContentModeBottomRight UIViewContentModeBottomRight
- (void)setContentMode:(LAViewContentMode)contentMode { - (void)setContentMode:(LOTViewContentMode)contentMode {
[super setContentMode:contentMode]; [super setContentMode:contentMode];
[self setNeedsLayout]; [self setNeedsLayout];
} }
@ -529,7 +529,7 @@ const NSTimeInterval singleFrameTimeValue = 1.0 / 60.0;
#else #else
- (void)setContentMode:(LAViewContentMode)contentMode { - (void)setContentMode:(LOTViewContentMode)contentMode {
_contentMode = contentMode; _contentMode = contentMode;
[self setNeedsLayout]; [self setNeedsLayout];
} }
@ -562,11 +562,11 @@ const NSTimeInterval singleFrameTimeValue = 1.0 / 60.0;
CGPoint centerPoint = CGRectGetCenterPoint(self.bounds); CGPoint centerPoint = CGRectGetCenterPoint(self.bounds);
CATransform3D xform; CATransform3D xform;
if (self.contentMode == LAViewContentModeScaleToFill) { if (self.contentMode == LOTViewContentModeScaleToFill) {
CGSize scaleSize = CGSizeMake(self.bounds.size.width / self.sceneModel.compBounds.size.width, CGSize scaleSize = CGSizeMake(self.bounds.size.width / self.sceneModel.compBounds.size.width,
self.bounds.size.height / self.sceneModel.compBounds.size.height); self.bounds.size.height / self.sceneModel.compBounds.size.height);
xform = CATransform3DMakeScale(scaleSize.width, scaleSize.height, 1); xform = CATransform3DMakeScale(scaleSize.width, scaleSize.height, 1);
} else if (self.contentMode == LAViewContentModeScaleAspectFit) { } else if (self.contentMode == LOTViewContentModeScaleAspectFit) {
CGFloat compAspect = self.sceneModel.compBounds.size.width / self.sceneModel.compBounds.size.height; CGFloat compAspect = self.sceneModel.compBounds.size.width / self.sceneModel.compBounds.size.height;
CGFloat viewAspect = self.bounds.size.width / self.bounds.size.height; CGFloat viewAspect = self.bounds.size.width / self.bounds.size.height;
BOOL scaleWidth = compAspect > viewAspect; BOOL scaleWidth = compAspect > viewAspect;
@ -574,7 +574,7 @@ const NSTimeInterval singleFrameTimeValue = 1.0 / 60.0;
CGFloat compDimension = scaleWidth ? self.sceneModel.compBounds.size.width : self.sceneModel.compBounds.size.height; CGFloat compDimension = scaleWidth ? self.sceneModel.compBounds.size.width : self.sceneModel.compBounds.size.height;
CGFloat scale = dominantDimension / compDimension; CGFloat scale = dominantDimension / compDimension;
xform = CATransform3DMakeScale(scale, scale, 1); xform = CATransform3DMakeScale(scale, scale, 1);
} else if (self.contentMode == LAViewContentModeScaleAspectFill) { } else if (self.contentMode == LOTViewContentModeScaleAspectFill) {
CGFloat compAspect = self.sceneModel.compBounds.size.width / self.sceneModel.compBounds.size.height; CGFloat compAspect = self.sceneModel.compBounds.size.width / self.sceneModel.compBounds.size.height;
CGFloat viewAspect = self.bounds.size.width / self.bounds.size.height; CGFloat viewAspect = self.bounds.size.width / self.bounds.size.height;
BOOL scaleWidth = compAspect < viewAspect; BOOL scaleWidth = compAspect < viewAspect;

View File

@ -1,5 +1,5 @@
// //
// LAAnimationView_Internal.h // LOTAnimationView_Internal.h
// Lottie // Lottie
// //
// Created by Brandon Withrow on 12/7/16. // Created by Brandon Withrow on 12/7/16.
@ -7,12 +7,12 @@
// //
typedef enum : NSUInteger { typedef enum : NSUInteger {
LAConstraintTypeAlignToBounds, LOTConstraintTypeAlignToBounds,
LAConstraintTypeAlignToLayer, LOTConstraintTypeAlignToLayer,
LAConstraintTypeNone LOTConstraintTypeNone
} LAConstraintType; } LOTConstraintType;
@interface LAAnimationState : NSObject @interface LOTAnimationState : NSObject
- (_Nonnull instancetype)initWithDuration:(CGFloat)duration layer:( CALayer * _Nullable)layer; - (_Nonnull instancetype)initWithDuration:(CGFloat)duration layer:( CALayer * _Nullable)layer;
@ -33,10 +33,10 @@ typedef enum : NSUInteger {
@end @end
@interface LAAnimationView () @interface LOTAnimationView ()
@property (nonatomic, readonly) LAComposition * _Nonnull sceneModel; @property (nonatomic, readonly) LOTComposition * _Nonnull sceneModel;
@property (nonatomic, strong) LAAnimationState *_Nonnull animationState; @property (nonatomic, strong) LOTAnimationState *_Nonnull animationState;
@property (nonatomic, copy, nullable) LAAnimationCompletionBlock completionBlock; @property (nonatomic, copy, nullable) LOTAnimationCompletionBlock completionBlock;
@end @end

Some files were not shown because too many files have changed in this diff Show More