From 8be9ea150c125361535c2080d7e5d2bf6765d1c9 Mon Sep 17 00:00:00 2001 From: brandon_withrow Date: Fri, 4 Aug 2017 13:36:23 -0700 Subject: [PATCH] Added logging for keypaths --- README.md | 15 ++++++++++++++ .../LOTCompositionContainer.m | 10 ++++++++++ .../AnimatableLayers/LOTLayerContainer.h | 3 +++ .../AnimatableLayers/LOTLayerContainer.m | 5 +++++ lottie-ios/Classes/Extensions/LOTHelpers.h | 1 - lottie-ios/Classes/Private/LOTAnimationView.m | 7 +++++++ .../Classes/PublicHeaders/LOTAnimationView.h | 3 +++ .../Classes/RenderSystem/LOTAnimatorNode.h | 2 ++ .../Classes/RenderSystem/LOTAnimatorNode.m | 20 ++++++++++++++++--- .../RenderSystem/RenderNodes/LOTRenderGroup.m | 15 ++++++++++++++ 10 files changed, 77 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index acea7b9c87..1b5c800836 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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. @@ -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" diff --git a/lottie-ios/Classes/AnimatableLayers/LOTCompositionContainer.m b/lottie-ios/Classes/AnimatableLayers/LOTCompositionContainer.m index 5234d2e908..a489f4ee98 100644 --- a/lottie-ios/Classes/AnimatableLayers/LOTCompositionContainer.m +++ b/lottie-ios/Classes/AnimatableLayers/LOTCompositionContainer.m @@ -144,4 +144,14 @@ } } +- (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 diff --git a/lottie-ios/Classes/AnimatableLayers/LOTLayerContainer.h b/lottie-ios/Classes/AnimatableLayers/LOTLayerContainer.h index fe0ccfc105..f906e2e378 100644 --- a/lottie-ios/Classes/AnimatableLayers/LOTLayerContainer.h +++ b/lottie-ios/Classes/AnimatableLayers/LOTLayerContainer.h @@ -27,4 +27,7 @@ - (BOOL)setValue:(nonnull id)value forKeypath:(nonnull NSString *)keypath atFrame:(nullable NSNumber *)frame; + +- (void)logHierarchyKeypathsWithParent:(NSString * _Nullable)parent; + @end diff --git a/lottie-ios/Classes/AnimatableLayers/LOTLayerContainer.m b/lottie-ios/Classes/AnimatableLayers/LOTLayerContainer.m index 641c246a0f..444e5d71f3 100644 --- a/lottie-ios/Classes/AnimatableLayers/LOTLayerContainer.m +++ b/lottie-ios/Classes/AnimatableLayers/LOTLayerContainer.m @@ -260,4 +260,9 @@ } } +- (void)logHierarchyKeypathsWithParent:(NSString * _Nullable)parent { + [_contentsGroup logHierarchyKeypathsWithParent:parent + ]; +} + @end diff --git a/lottie-ios/Classes/Extensions/LOTHelpers.h b/lottie-ios/Classes/Extensions/LOTHelpers.h index 21e7a9d016..420b0a0c5c 100644 --- a/lottie-ios/Classes/Extensions/LOTHelpers.h +++ b/lottie-ios/Classes/Extensions/LOTHelpers.h @@ -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 diff --git a/lottie-ios/Classes/Private/LOTAnimationView.m b/lottie-ios/Classes/Private/LOTAnimationView.m index 9328997505..55b2fa1c10 100644 --- a/lottie-ios/Classes/Private/LOTAnimationView.m +++ b/lottie-ios/Classes/Private/LOTAnimationView.m @@ -155,6 +155,9 @@ [self.layer addSublayer:_compContainer]; _compContainer.currentFrame = @0; [CATransaction commit]; + if (ENABLE_DEBUG_LOGGING) { + [self logHierarchyKeypaths]; + } } # pragma mark - External Methods @@ -487,4 +490,8 @@ [self _callCompletionIfNecessary:complete]; } +- (void)logHierarchyKeypaths { + [_compContainer logHierarchyKeypathsWithParent:nil]; +} + @end diff --git a/lottie-ios/Classes/PublicHeaders/LOTAnimationView.h b/lottie-ios/Classes/PublicHeaders/LOTAnimationView.h index 82341603c2..a647704916 100644 --- a/lottie-ios/Classes/PublicHeaders/LOTAnimationView.h +++ b/lottie-ios/Classes/PublicHeaders/LOTAnimationView.h @@ -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. diff --git a/lottie-ios/Classes/RenderSystem/LOTAnimatorNode.h b/lottie-ios/Classes/RenderSystem/LOTAnimatorNode.h index 39d029c60c..e8e98d696c 100644 --- a/lottie-ios/Classes/RenderSystem/LOTAnimatorNode.h +++ b/lottie-ios/Classes/RenderSystem/LOTAnimatorNode.h @@ -63,4 +63,6 @@ extern NSInteger indentation_level; - (void)logString:(NSString *_Nonnull)string; +- (void)logHierarchyKeypathsWithParent:(NSString * _Nullable)parent; + @end diff --git a/lottie-ios/Classes/RenderSystem/LOTAnimatorNode.m b/lottie-ios/Classes/RenderSystem/LOTAnimatorNode.m index 8ce5ce3405..fd31d7c416 100644 --- a/lottie-ios/Classes/RenderSystem/LOTAnimatorNode.m +++ b/lottie-ios/Classes/RenderSystem/LOTAnimatorNode.m @@ -42,10 +42,10 @@ NSInteger indentation_level = 0; 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 @@ -105,7 +105,7 @@ NSInteger indentation_level = 0; 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]; } @@ -123,4 +123,18 @@ NSInteger indentation_level = 0; 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 diff --git a/lottie-ios/Classes/RenderSystem/RenderNodes/LOTRenderGroup.m b/lottie-ios/Classes/RenderSystem/RenderNodes/LOTRenderGroup.m index aae98e26eb..330a132988 100644 --- a/lottie-ios/Classes/RenderSystem/RenderNodes/LOTRenderGroup.m +++ b/lottie-ios/Classes/RenderSystem/RenderNodes/LOTRenderGroup.m @@ -186,4 +186,19 @@ 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