Skip to content

Commit

Permalink
Merge pull request #345 from airbnb/btw/keypaths
Browse files Browse the repository at this point in the history
Added logging for keypaths
  • Loading branch information
buba447 committed Aug 4, 2017
2 parents bebfce5 + 8be9ea1 commit 1d136c4
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 4 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- [MacOS Sample App](#macos-sample-app)
- [Objective C Examples](#objective-c-examples)
- [Swift Examples](#swift-examples)
- [Debugging Lottie](#debugging)
- [iOS View Controller Transitioning](#ios-view-controller-transitioning)
- [Changing Animations At Runtime](#changing-animations-at-runtime)
- [Supported After Effects Features](#supported-after-effects-features)
Expand Down Expand Up @@ -208,6 +209,19 @@ return animationController;

```

## Debugging
Lottie has a couple of debugging features to know about.
When an animation is loaded unsupported features are logged out in the console with their function names.

If you checkout LOTHelpers.h you will see two debug flags. `ENABLE_DEBUG_LOGGING` and `ENABLE_DEBUG_SHAPES`.
`ENABLE_DEBUG_LOGGING` increases the verbosity of Lottie Logging. It logs anytime an animation node is set during animation. If your animation if not working, turn this on and play your animation. The console log might give you some clues as to whats going on.

`ENABLE_DEBUG_SHAPES` Draws a colored square for the anchor-point of every layer and shape. This is helpful to see if anything is on screen.

### Keypaths

LOTAnimationView provides `- (void)logHierarchyKeypaths` which will recursively log all settable keypaths for the animation. This is helpful for changing animationations at runtime.

## Changing Animations At Runtime

Lottie can do more than just play beautiful animations. Lottie allows you to **change** animations at runtime.
Expand Down Expand Up @@ -257,6 +271,7 @@ animationView3.setValue(UIColor.red, forKeypath: "BG-On.Group 1.Fill 1.Color", a
animationView4.setValue(UIColor.orange, forKeypath: "BG-On.Group 1.Fill 1.Color", atFrame: 0)
```
The keyPath is a dot separated path of layer and property names from After Effects.
LOTAnimationView provides `- (void)logHierarchyKeypaths` which will recursively log all settable keypaths for the animation.
![Key Path](_Gifs/aftereffectskeypath.png)
"BG-On.Group 1.Fill 1.Color"

Expand Down
10 changes: 10 additions & 0 deletions lottie-ios/Classes/AnimatableLayers/LOTCompositionContainer.m
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,14 @@ - (void)setViewportBounds:(CGRect)viewportBounds {
}
}

- (void)logHierarchyKeypathsWithParent:(NSString * _Nullable)parent {
NSString *keypath = parent;
if (parent && self.layerName) {
keypath = [NSString stringWithFormat:@"%@.%@", parent, self.layerName];
}
for (LOTLayerContainer *layer in _childLayers) {
[layer logHierarchyKeypathsWithParent:keypath];
}
}

@end
3 changes: 3 additions & 0 deletions lottie-ios/Classes/AnimatableLayers/LOTLayerContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,7 @@
- (BOOL)setValue:(nonnull id)value
forKeypath:(nonnull NSString *)keypath
atFrame:(nullable NSNumber *)frame;

- (void)logHierarchyKeypathsWithParent:(NSString * _Nullable)parent;

@end
5 changes: 5 additions & 0 deletions lottie-ios/Classes/AnimatableLayers/LOTLayerContainer.m
Original file line number Diff line number Diff line change
Expand Up @@ -260,4 +260,9 @@ - (void)setViewportBounds:(CGRect)viewportBounds {
}
}

- (void)logHierarchyKeypathsWithParent:(NSString * _Nullable)parent {
[_contentsGroup logHierarchyKeypathsWithParent:parent
];
}

@end
1 change: 0 additions & 1 deletion lottie-ios/Classes/Extensions/LOTHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#import "CGGeometry+LOTAdditions.h"
#import "LOTBezierPath.h"

#define DEBUG_USE_NEW_RENDERER YES
#define ENABLE_DEBUG_LOGGING NO
#define ENABLE_DEBUG_SHAPES NO

Expand Down
7 changes: 7 additions & 0 deletions lottie-ios/Classes/Private/LOTAnimationView.m
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ - (void)_setupWithSceneModel:(LOTComposition *)model {
[self.layer addSublayer:_compContainer];
_compContainer.currentFrame = @0;
[CATransaction commit];
if (ENABLE_DEBUG_LOGGING) {
[self logHierarchyKeypaths];
}
}

# pragma mark - External Methods
Expand Down Expand Up @@ -487,4 +490,8 @@ - (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)complete {
[self _callCompletionIfNecessary:complete];
}

- (void)logHierarchyKeypaths {
[_compContainer logHierarchyKeypathsWithParent:nil];
}

@end
3 changes: 3 additions & 0 deletions lottie-ios/Classes/PublicHeaders/LOTAnimationView.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ typedef void (^LOTAnimationCompletionBlock)(BOOL animationFinished);
forKeypath:(nonnull NSString *)keypath
atFrame:(nullable NSNumber *)frame;

/// Logs all child keypaths
- (void)logHierarchyKeypaths;

/**
* Adds a custom subview to the animation using a LayerName from After Effects
* as a reference point.
Expand Down
2 changes: 2 additions & 0 deletions lottie-ios/Classes/RenderSystem/LOTAnimatorNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,6 @@ extern NSInteger indentation_level;

- (void)logString:(NSString *_Nonnull)string;

- (void)logHierarchyKeypathsWithParent:(NSString * _Nullable)parent;

@end
20 changes: 17 additions & 3 deletions lottie-ios/Classes/RenderSystem/LOTAnimatorNode.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ - (BOOL)updateWithFrame:(NSNumber *_Nonnull)frame
return NO;
}
NSString *name = NSStringFromClass([self class]);
if (ENABLE_DEBUG_LOGGING) [self logString:[NSString stringWithFormat:@"%@ %lu Checking for update", name, (unsigned long)self.hash]];
if (ENABLE_DEBUG_LOGGING) [self logString:[NSString stringWithFormat:@"%@ %lu %@ Checking for update", name, (unsigned long)self.hash, self.keyname]];
BOOL localUpdate = [self needsUpdateForFrame:frame] || forceUpdate;
if (localUpdate && ENABLE_DEBUG_LOGGING) {
[self logString:[NSString stringWithFormat:@"%@ %lu Performing update", name, (unsigned long)self.hash]];
[self logString:[NSString stringWithFormat:@"%@ %lu %@ Performing update", name, (unsigned long)self.hash, self.keyname]];
}
BOOL inputUpdated = [_inputNode updateWithFrame:frame
withModifierBlock:modifier
Expand Down Expand Up @@ -105,7 +105,7 @@ - (BOOL)setValue:(nonnull id)value
forFrame:(nullable NSNumber *)frame {
NSArray *components = [keypath componentsSeparatedByString:@"."];
NSString *firstKey = components.firstObject;
if ([firstKey isEqualToString:self.keyname]) {
if ([firstKey isEqualToString:self.keyname] && components.count > 1) {
NSString *nextPath = [keypath stringByReplacingCharactersInRange:NSMakeRange(0, firstKey.length + 1) withString:@""];
return [self setInterpolatorValue:value forKey:nextPath forFrame:frame];
}
Expand All @@ -123,4 +123,18 @@ - (BOOL)setInterpolatorValue:(nonnull id)value
return NO;
}

- (void)logHierarchyKeypathsWithParent:(NSString *)parent {
NSString *keypath = self.keyname;
if (parent && self.keyname) {
keypath = [NSString stringWithFormat:@"%@.%@", parent, self.keyname];
}
if (keypath) {
for (NSString *interpolator in self.valueInterpolators.allKeys) {
[self logString:[NSString stringWithFormat:@"%@.%@", keypath, interpolator]];
}
}

[self.inputNode logHierarchyKeypathsWithParent:parent];
}

@end
15 changes: 15 additions & 0 deletions lottie-ios/Classes/RenderSystem/RenderNodes/LOTRenderGroup.m
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,19 @@ - (BOOL)setInterpolatorValue:(id)value
return [_rootNode setValue:value forKeyAtPath:key forFrame:frame];
}

- (void)logHierarchyKeypathsWithParent:(NSString * _Nullable)parent {
NSString *keypath = self.keyname;
if (parent && self.keyname) {
keypath = [NSString stringWithFormat:@"%@.%@", parent, self.keyname];
}
if (keypath) {
for (NSString *interpolator in self.valueInterpolators.allKeys) {
[self logString:[NSString stringWithFormat:@"%@.%@", keypath, interpolator]];
}
[_rootNode logHierarchyKeypathsWithParent:keypath];
}

[self.inputNode logHierarchyKeypathsWithParent:parent];
}

@end

0 comments on commit 1d136c4

Please sign in to comment.