Skip to content

Commit

Permalink
Initial work on interactive props
Browse files Browse the repository at this point in the history
  • Loading branch information
brandon_withrow committed Dec 18, 2017
1 parent e42812f commit a2275e9
Show file tree
Hide file tree
Showing 41 changed files with 2,289 additions and 1,104 deletions.
1,918 changes: 971 additions & 947 deletions Example/Pods/Pods.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Example/Tests/GeometryTransformTest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"v":"4.12.0","fr":23.9759979248047,"ip":0,"op":48.9999957589018,"w":300,"h":300,"nm":"Comp 2","ddd":0,"assets":[],"layers":[{"ddd":0,"ind":1,"ty":4,"nm":"Scaled","sr":1,"ks":{"o":{"a":0,"k":100,"ix":11},"r":{"a":0,"k":0,"ix":10},"p":{"a":0,"k":[150,150,0],"ix":2},"a":{"a":0,"k":[0,0,0],"ix":1},"s":{"a":0,"k":[100,100,100],"ix":6}},"ao":0,"shapes":[{"ty":"gr","it":[{"d":1,"ty":"el","s":{"a":0,"k":[68.52,68.52],"ix":2},"p":{"a":0,"k":[0,0],"ix":3},"nm":"Ellipse Path 1","mn":"ADBE Vector Shape - Ellipse","hd":false},{"ty":"st","c":{"a":0,"k":[1,1,1,1],"ix":3},"o":{"a":0,"k":100,"ix":4},"w":{"a":0,"k":2,"ix":5},"lc":1,"lj":1,"ml":4,"nm":"Stroke 1","mn":"ADBE Vector Graphic - Stroke","hd":false},{"ty":"fl","c":{"a":0,"k":[0.431255026425,0,0.902665022308,1],"ix":4},"o":{"a":0,"k":100,"ix":5},"r":1,"nm":"Fill 1","mn":"ADBE Vector Graphic - Fill","hd":false},{"ty":"tr","p":{"a":0,"k":[0,0],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[200,200],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Ellipse 1","np":3,"cix":2,"ix":1,"mn":"ADBE Vector Group","hd":false}],"ip":0,"op":48.9999957589018,"st":0,"bm":0},{"ddd":0,"ind":2,"ty":4,"nm":"TopLeft","sr":1,"ks":{"o":{"a":0,"k":100,"ix":11},"r":{"a":0,"k":0,"ix":10},"p":{"a":0,"k":[150,150,0],"ix":2},"a":{"a":0,"k":[0,0,0],"ix":1},"s":{"a":0,"k":[100,100,100],"ix":6}},"ao":0,"shapes":[{"ty":"gr","it":[{"d":1,"ty":"el","s":{"a":0,"k":[68.52,68.52],"ix":2},"p":{"a":0,"k":[0,0],"ix":3},"nm":"Ellipse Path 1","mn":"ADBE Vector Shape - Ellipse","hd":false},{"ty":"st","c":{"a":0,"k":[1,1,1,1],"ix":3},"o":{"a":0,"k":100,"ix":4},"w":{"a":0,"k":2,"ix":5},"lc":1,"lj":1,"ml":4,"nm":"Stroke 1","mn":"ADBE Vector Graphic - Stroke","hd":false},{"ty":"fl","c":{"a":0,"k":[0.431255026425,0,0.902665022308,1],"ix":4},"o":{"a":0,"k":100,"ix":5},"r":1,"nm":"Fill 1","mn":"ADBE Vector Graphic - Fill","hd":false},{"ty":"tr","p":{"a":0,"k":[-150,-150],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Ellipse 1","np":3,"cix":2,"ix":1,"mn":"ADBE Vector Group","hd":false}],"ip":0,"op":48.9999957589018,"st":0,"bm":0},{"ddd":0,"ind":3,"ty":4,"nm":"BottomRight","sr":1,"ks":{"o":{"a":0,"k":100,"ix":11},"r":{"a":0,"k":0,"ix":10},"p":{"a":0,"k":[150,150,0],"ix":2},"a":{"a":0,"k":[0,0,0],"ix":1},"s":{"a":0,"k":[100,100,100],"ix":6}},"ao":0,"shapes":[{"ty":"gr","it":[{"d":1,"ty":"el","s":{"a":0,"k":[68.52,68.52],"ix":2},"p":{"a":0,"k":[0,0],"ix":3},"nm":"Ellipse Path 1","mn":"ADBE Vector Shape - Ellipse","hd":false},{"ty":"st","c":{"a":0,"k":[1,1,1,1],"ix":3},"o":{"a":0,"k":100,"ix":4},"w":{"a":0,"k":2,"ix":5},"lc":1,"lj":1,"ml":4,"nm":"Stroke 1","mn":"ADBE Vector Graphic - Stroke","hd":false},{"ty":"fl","c":{"a":0,"k":[0.431255026425,0,0.902665022308,1],"ix":4},"o":{"a":0,"k":100,"ix":5},"r":1,"nm":"Fill 1","mn":"ADBE Vector Graphic - Fill","hd":false},{"ty":"tr","p":{"a":0,"k":[150,150],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Ellipse 1","np":3,"cix":2,"ix":1,"mn":"ADBE Vector Group","hd":false}],"ip":0,"op":48.9999957589018,"st":0,"bm":0},{"ddd":0,"ind":4,"ty":4,"nm":"Center","sr":1,"ks":{"o":{"a":0,"k":100,"ix":11},"r":{"a":0,"k":0,"ix":10},"p":{"a":0,"k":[150,150,0],"ix":2},"a":{"a":0,"k":[0,0,0],"ix":1},"s":{"a":0,"k":[100,100,100],"ix":6}},"ao":0,"shapes":[{"ty":"gr","it":[{"d":1,"ty":"el","s":{"a":0,"k":[68.52,68.52],"ix":2},"p":{"a":0,"k":[0,0],"ix":3},"nm":"Ellipse Path 1","mn":"ADBE Vector Shape - Ellipse","hd":false},{"ty":"st","c":{"a":0,"k":[1,1,1,1],"ix":3},"o":{"a":0,"k":100,"ix":4},"w":{"a":0,"k":2,"ix":5},"lc":1,"lj":1,"ml":4,"nm":"Stroke 1","mn":"ADBE Vector Graphic - Stroke","hd":false},{"ty":"fl","c":{"a":0,"k":[0.431255026425,0,0.902665022308,1],"ix":4},"o":{"a":0,"k":100,"ix":5},"r":1,"nm":"Fill 1","mn":"ADBE Vector Graphic - Fill","hd":false},{"ty":"tr","p":{"a":0,"k":[0,0],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Ellipse 1","np":3,"cix":2,"ix":1,"mn":"ADBE Vector Group","hd":false}],"ip":0,"op":48.9999957589018,"st":0,"bm":0}]}
62 changes: 62 additions & 0 deletions Example/Tests/LAGeometryTest.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//
// LAGeometryTest.m
// lottie-ios_Tests
//
// Created by brandon_withrow on 12/18/17.
// Copyright © 2017 Brandon Withrow. All rights reserved.
//

#import <XCTest/XCTest.h>
#import <Lottie/Lottie.h>

@interface LAGeometryTest : XCTestCase

@property (nonatomic, strong) LOTAnimationView *animationView;

@end

@implementation LAGeometryTest

- (void)setUp {
[super setUp];
self.animationView = [LOTAnimationView animationNamed:@"GeometryTransformTest"];
}

- (void)tearDown {
// Put teardown code here. This method is called after the invocation of each test method in the class.
[super tearDown];
}

- (void)testAnimationLoaded {
XCTAssertNotNil(self.animationView.sceneModel, @"Animation Composition is nil");
}

- (void)testGeometryCenter {
LOTKeypath *keypath = [LOTKeypath keypathWithKeys:@"Center", @"Ellipse 1", nil];
CGPoint midPoint = CGPointMake(CGRectGetMidX(self.animationView.bounds), CGRectGetMidY(self.animationView.bounds));
CGPoint midPointInChildSpace = [self.animationView convertPoint:midPoint toKeypathLayer:keypath];
CGPoint midPointInParentSpace = [self.animationView convertPoint:CGPointZero fromKeypathLayer:keypath];
XCTAssertTrue((CGPointEqualToPoint(midPointInChildSpace, CGPointZero)), @"Convert to point incorrect");
XCTAssertTrue((CGPointEqualToPoint(midPointInParentSpace, midPoint)), @"Convert from point incorrect");
}

- (void)testGeometryBottomRight {
LOTKeypath *keypath = [LOTKeypath keypathWithKeys:@"BottomRight", @"Ellipse 1", nil];
CGPoint midPoint = CGPointMake(CGRectGetMidX(self.animationView.bounds), CGRectGetMidY(self.animationView.bounds));
CGPoint bottomRightPoint = CGPointMake(CGRectGetMaxX(self.animationView.bounds), CGRectGetMaxY(self.animationView.bounds));
CGPoint midPointInChildSpace = [self.animationView convertPoint:midPoint toKeypathLayer:keypath];
CGPoint midPointInParentSpace = [self.animationView convertPoint:CGPointZero fromKeypathLayer:keypath];
XCTAssertTrue((CGPointEqualToPoint(midPointInChildSpace, CGPointMake(-midPoint.x, -midPoint.y))), @"Convert to point incorrect");
XCTAssertTrue((CGPointEqualToPoint(midPointInParentSpace, bottomRightPoint)), @"Convert from point incorrect");
}

- (void)testGeometryScaled {
LOTKeypath *keypath = [LOTKeypath keypathWithKeys:@"Scaled", @"Ellipse 1", nil];
CGPoint bottomRightPoint = CGPointMake(CGRectGetMaxX(self.animationView.bounds), CGRectGetMaxY(self.animationView.bounds));
CGPoint topLeftInChildSpace = [self.animationView convertPoint:CGPointZero toKeypathLayer:keypath];
CGPoint bottomRightInParentSpace = [self.animationView convertPoint:CGPointMake(75, 75) fromKeypathLayer:keypath];
XCTAssertTrue((CGPointEqualToPoint(bottomRightInParentSpace, bottomRightPoint)), @"Convert to point incorrect");
XCTAssertTrue((CGPointEqualToPoint(topLeftInChildSpace, CGPointMake(-75, -75))), @"Convert from point incorrect");
}

@end
127 changes: 127 additions & 0 deletions Example/Tests/LAKeypathTest.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
//
// LAKeypathTest.m
// lottie-ios_Tests
//
// Created by brandon_withrow on 12/14/17.
// Copyright © 2017 Brandon Withrow. All rights reserved.
//

#import <XCTest/XCTest.h>
#import <Lottie/Lottie.h>

@interface LAKeypathTest : XCTestCase

@property (nonatomic, strong) LOTAnimationView *animationView;


@end

@implementation LAKeypathTest

- (void)setUp {
[super setUp];
self.animationView = [LOTAnimationView animationNamed:@"keypathTest"];
}

- (void)tearDown {
// Put teardown code here. This method is called after the invocation of each test method in the class.
[super tearDown];
}

- (void)testAnimationLoaded {
XCTAssertNotNil(self.animationView.sceneModel, @"Animation Composition is nil");
}

- (void)testExplicitSearch {
NSString *searchTerm = @"Shape Layer 1.Shape 1.Path 1";
NSArray *results = [self.animationView keysForKeyPath:[LOTKeypath keypathWithString:searchTerm]];
XCTAssertTrue((results.count == 1), @"Wrong number of results");
NSString *firstObject = results.firstObject;
XCTAssertTrue([searchTerm isEqualToString:firstObject], @"Wrong keypath found");
}

- (void)testFuzzyKeySearch_Shape1 {
NSArray *results = [self.animationView keysForKeyPath:[LOTKeypath keypathWithKeys:@"**", @"Shape 1", nil]];
NSArray *expectedResults = @[@"Shape Layer 1.Shape 1",
@"WiggleLayer.Shape 1",
@"GroupShapeLayer.Group 1.Shape 1",
@"TwoShapeLayer.Shape 1",
@"Precomp.DoubleGroupShape.TopGroup.Group 2.Group 1.Shape 1",
@"Precomp.GroupShape.Group 1.Shape 1",
@"Precomp.SingleShape.Shape 1",
@"Precomp.DoubleGroupShape.TopGroup.Group 1.Group 1.Shape 1"];

NSSet *set1 = [NSSet setWithArray:results];
NSSet *set2 = [NSSet setWithArray:expectedResults];
XCTAssertTrue([set1 isEqualToSet:set2], @"Wrong keypath found");
}

- (void)testFuzzyKeySearch_Shape1_Path1 {
NSArray *results = [self.animationView keysForKeyPath:[LOTKeypath keypathWithKeys:@"**", @"Shape 1", @"Path 1", nil]];
NSArray *expectedResults = @[@"GroupShapeLayer.Group 1.Shape 1.Path 1",
@"Shape Layer 1.Shape 1.Path 1",
@"TwoShapeLayer.Shape 1.Path 1",
@"Precomp.DoubleGroupShape.TopGroup.Group 2.Group 1.Shape 1.Path 1",
@"Precomp.GroupShape.Group 1.Shape 1.Path 1",
@"Precomp.SingleShape.Shape 1.Path 1",
@"Precomp.DoubleGroupShape.TopGroup.Group 1.Group 1.Shape 1.Path 1"];

NSSet *set1 = [NSSet setWithArray:results];
NSSet *set2 = [NSSet setWithArray:expectedResults];
XCTAssertTrue([set1 isEqualToSet:set2], @"Wrong keypath found");
}

- (void)testWildcardKeySearch_Shape1 {
NSArray *results = [self.animationView keysForKeyPath:[LOTKeypath keypathWithKeys:@"*", @"Shape 1", nil]];
NSArray *expectedResults = @[@"Shape Layer 1.Shape 1",
@"WiggleLayer.Shape 1",
@"TwoShapeLayer.Shape 1"];

NSSet *set1 = [NSSet setWithArray:results];
NSSet *set2 = [NSSet setWithArray:expectedResults];
XCTAssertTrue([set1 isEqualToSet:set2], @"Wrong keypath found");
}

- (void)testCompoundFuzzyKeySearch_Shape1 {
NSArray *results = [self.animationView keysForKeyPath:[LOTKeypath keypathWithKeys:@"**", @"Shape 1", @"*", @"Stroke Width", nil]];
NSArray *expectedResults = @[@"Shape Layer 1.Shape 1.Stroke 1.Stroke Width",
@"WiggleLayer.Shape 1.Stroke 1.Stroke Width",
@"GroupShapeLayer.Group 1.Shape 1.Stroke 1.Stroke Width",
@"TwoShapeLayer.Shape 1.Stroke 1.Stroke Width"];

NSSet *set1 = [NSSet setWithArray:results];
NSSet *set2 = [NSSet setWithArray:expectedResults];
XCTAssertTrue([set1 isEqualToSet:set2], @"Wrong keypath found");
}

- (void)testDoubleFuzzyKeySearch_Shape1 {
NSArray *results = [self.animationView keysForKeyPath:[LOTKeypath keypathWithKeys:@"**", @"Group 1", @"**", @"Path 1", nil]];
NSArray *expectedResults = @[@"Precomp.DoubleGroupShape.TopGroup.Group 2.Group 1.Shape 1.Path 1",
@"Precomp.GroupShape.Group 1.Shape 2.Path 1",
@"Precomp.GroupShape.Group 1.Shape 1.Path 1",
@"GroupShapeLayer.Group 1.Shape 2.Path 1",
@"GroupShapeLayer.Group 1.Shape 1.Path 1",
@"Precomp.DoubleGroupShape.TopGroup.Group 1.Group 1.Shape 2.Path 1",
@"Precomp.DoubleGroupShape.TopGroup.Group 1.Group 1.Shape 1.Path 1",
@"Precomp.DoubleGroupShape.TopGroup.Group 2.Group 1.Shape 2.Path 1"];

NSSet *set1 = [NSSet setWithArray:results];
NSSet *set2 = [NSSet setWithArray:expectedResults];
XCTAssertTrue([set1 isEqualToSet:set2], @"Wrong keypath found");
}

- (void)testKeySearch_Precomp {
NSArray *results = [self.animationView keysForKeyPath:[LOTKeypath keypathWithKeys:@"Precomp", nil]];
NSArray *expectedResults = @[@"Precomp"];

NSSet *set1 = [NSSet setWithArray:results];
NSSet *set2 = [NSSet setWithArray:expectedResults];
XCTAssertTrue([set1 isEqualToSet:set2], @"Wrong keypath found");
}

- (void)testFuzzyKeySearch_Precomp {
NSArray *results = [self.animationView keysForKeyPath:[LOTKeypath keypathWithKeys:@"Precomp", @"**", nil]];
XCTAssertTrue((results.count == 33), @"Wrong number of results");
}

@end
1 change: 1 addition & 0 deletions Example/Tests/keypathTest.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Example/Tests/setValueTest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"v":"4.12.0","fr":23.9759979248047,"ip":0,"op":48.9999957589018,"w":300,"h":300,"nm":"Comp 1","ddd":0,"assets":[],"layers":[{"ddd":0,"ind":1,"ty":4,"nm":"Shape Layer 1","sr":1,"ks":{"o":{"a":0,"k":100,"ix":11},"r":{"a":0,"k":0,"ix":10},"p":{"a":0,"k":[150,150,0],"ix":2},"a":{"a":0,"k":[0,0,0],"ix":1},"s":{"a":0,"k":[100,100,100],"ix":6}},"ao":0,"shapes":[{"ty":"gr","it":[{"ind":0,"ty":"sh","ix":1,"ks":{"a":0,"k":{"i":[[0,-51],[0,79]],"o":[[0,51],[0,-79]],"v":[[-52.182,-74.182],[32.818,-38.182]],"c":true},"ix":2},"nm":"Path 1","mn":"ADBE Vector Shape - Group","hd":false},{"ty":"st","c":{"a":0,"k":[1,1,1,1],"ix":3},"o":{"a":0,"k":100,"ix":4},"w":{"a":0,"k":2,"ix":5},"lc":1,"lj":1,"ml":4,"nm":"Stroke 1","mn":"ADBE Vector Graphic - Stroke","hd":false},{"ty":"fl","c":{"a":0,"k":[0.431255026425,0,0.902665022308,1],"ix":4},"o":{"a":0,"k":100,"ix":5},"r":1,"nm":"Fill 1","mn":"ADBE Vector Graphic - Fill","hd":false},{"ty":"tr","p":{"a":1,"k":[{"i":{"x":0.833,"y":0.833},"o":{"x":0.333,"y":0},"n":"0p833_0p833_0p333_0","t":0,"s":[58.182,-52.818],"e":[58.182,102.182],"to":[0,25.8333339691162],"ti":[0,0]},{"i":{"x":0.667,"y":1},"o":{"x":0.167,"y":0.167},"n":"0p667_1_0p167_0p167","t":29,"s":[58.182,102.182],"e":[58.182,-52.818],"to":[0,0],"ti":[0,25.8333339691162]},{"t":47.9999958454548}],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Ellipse 1","np":3,"cix":2,"ix":1,"mn":"ADBE Vector Group","hd":false},{"ty":"gr","it":[{"ty":"rc","d":1,"s":{"a":0,"k":[69.723,69.723],"ix":2},"p":{"a":0,"k":[0,0],"ix":3},"r":{"a":0,"k":0,"ix":4},"nm":"Rectangle Path 1","mn":"ADBE Vector Shape - Rect","hd":false},{"ty":"st","c":{"a":0,"k":[1,1,1,1],"ix":3},"o":{"a":0,"k":100,"ix":4},"w":{"a":0,"k":2,"ix":5},"lc":1,"lj":1,"ml":4,"nm":"Stroke 1","mn":"ADBE Vector Graphic - Stroke","hd":false},{"ty":"fl","c":{"a":0,"k":[0.431255026425,0,0.902665022308,1],"ix":4},"o":{"a":0,"k":100,"ix":5},"r":1,"nm":"Fill 1","mn":"ADBE Vector Graphic - Fill","hd":false},{"ty":"tr","p":{"a":1,"k":[{"i":{"x":0.833,"y":0.833},"o":{"x":0.333,"y":0},"n":"0p833_0p833_0p333_0","t":0,"s":[-82.139,-74.139],"e":[-82.139,115.861],"to":[0,0],"ti":[0,0]},{"i":{"x":0.667,"y":1},"o":{"x":0.167,"y":0.167},"n":"0p667_1_0p167_0p167","t":28,"s":[-82.139,115.861],"e":[-82.139,-74.139],"to":[0,0],"ti":[0,0]},{"t":47.9999958454548}],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":1,"k":[{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.333],"y":[0]},"n":["0p833_0p833_0p333_0"],"t":0,"s":[45],"e":[0]},{"i":{"x":[0.667],"y":[1]},"o":{"x":[0.167],"y":[0.167]},"n":["0p667_1_0p167_0p167"],"t":28,"s":[0],"e":[-45]},{"t":47.9999958454548}],"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Rectangle 1","np":3,"cix":2,"ix":2,"mn":"ADBE Vector Group","hd":false}],"ip":0,"op":48.9999957589018,"st":0,"bm":0}]}
Loading

0 comments on commit a2275e9

Please sign in to comment.