From 91d1ba3f978a88c4e11b9a82482b6d72fb6a0ae1 Mon Sep 17 00:00:00 2001 From: Tsvetan Raikov Date: Thu, 4 Feb 2016 14:15:24 +0200 Subject: [PATCH] Modified animations to allow smooth transition when the previous animation is replaced with a new one --- ui/animation/animation.ios.ts | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/ui/animation/animation.ios.ts b/ui/animation/animation.ios.ts index aa28fb50a..0c174231a 100644 --- a/ui/animation/animation.ios.ts +++ b/ui/animation/animation.ios.ts @@ -143,47 +143,54 @@ export class Animation extends common.Animation implements definition.Animation finishedCallback(cancelled); return; } - var animation = propertyAnimations[index]; var nativeView = animation.target._nativeView; var propertyNameToAnimate = animation.property; var value = animation.value; var originalValue; + var presentationLayer = nativeView.layer.presentationLayer(); + var tempRotate = animation.target.rotate * Math.PI / 180; + var abs + switch (animation.property) { case common.Properties.backgroundColor: (animation)._originalValue = animation.target.backgroundColor; (animation)._propertyResetCallback = (value) => { animation.target.backgroundColor = value }; - originalValue = nativeView.layer.backgroundColor; + originalValue = presentationLayer.backgroundColor; value = value.CGColor; break; case common.Properties.opacity: (animation)._originalValue = animation.target.opacity; (animation)._propertyResetCallback = (value) => { animation.target.opacity = value }; - originalValue = nativeView.layer.opacity; + originalValue = presentationLayer.opacity; break; case common.Properties.rotate: (animation)._originalValue = animation.target.rotate; (animation)._propertyResetCallback = (value) => { animation.target.rotate = value }; propertyNameToAnimate = "transform.rotation"; - originalValue = animation.target.rotate * Math.PI / 180; + originalValue = presentationLayer.valueForKeyPath("transform.rotation"); value = value * Math.PI / 180; + abs = fabs(originalValue - value); + if (abs < 0.001 && originalValue !== tempRotate) { + originalValue = tempRotate; + } break; case common.Properties.translate: (animation)._originalValue = { x:animation.target.translateX, y:animation.target.translateY }; (animation)._propertyResetCallback = (value) => { animation.target.translateX = value.x; animation.target.translateY = value.y; }; propertyNameToAnimate = "transform" - originalValue = NSValue.valueWithCATransform3D(nativeView.layer.transform); + originalValue = NSValue.valueWithCATransform3D(presentationLayer.transform); value = NSValue.valueWithCATransform3D(CATransform3DTranslate(nativeView.layer.transform, value.x, value.y, 0)); break; case common.Properties.scale: (animation)._originalValue = { x:animation.target.scaleX, y:animation.target.scaleY }; (animation)._propertyResetCallback = (value) => { animation.target.scaleX = value.x; animation.target.scaleY = value.y; }; propertyNameToAnimate = "transform" - originalValue = NSValue.valueWithCATransform3D(nativeView.layer.transform); + originalValue = NSValue.valueWithCATransform3D(presentationLayer.transform); value = NSValue.valueWithCATransform3D(CATransform3DScale(nativeView.layer.transform, value.x, value.y, 1)); break; case _transform: - originalValue = NSValue.valueWithCATransform3D(nativeView.layer.transform); + originalValue = NSValue.valueWithCATransform3D(presentationLayer.transform); (animation)._originalValue = { xs:animation.target.scaleX, ys:animation.target.scaleY, xt:animation.target.translateX, yt:animation.target.translateY }; (animation)._propertyResetCallback = (value) => { @@ -228,7 +235,7 @@ export class Animation extends common.Animation implements definition.Animation var animationDelegate: AnimationDelegateImpl = AnimationDelegateImpl.initWithFinishedCallback(finishedCallback, animation); nativeAnimation.setValueForKey(animationDelegate, "delegate"); - nativeView.layer.addAnimationForKey(nativeAnimation, null); + nativeView.layer.addAnimationForKey(nativeAnimation, propertyNameToAnimate); var callback = undefined; if (index+1 < propertyAnimations.length) {