Description of the problem
Animating a view which has a border (set either borderRadius, borderWidth or borderColor) fails and the app crashes.
Steps to reproduce
Use the following code: clicking on a view, the animation does not run properly, and in the end it crashes. Note that you can comment out any of the border properties (one by one even) to see the error. Removing all of them works fine.
var win = Ti.UI.createWindow({
backgroundColor: 'black'
});
var view = Ti.UI.createView({
backgroundColor: 'red',
borderRadius: 20,
borderColor: 'white',
borderWidth: 10,
top: 10,
width: 100,
height: 100
});
view.addEventListener('click', function() {
view.animate({
top: 100,
duration: 3000
});
});
win.add(view);
win.open();
Log error
E/TiApplication( 3620): java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams cannot be cast to org.appcelerator.titanium.view.TiCompositeLayout$LayoutParams
E/TiApplication( 3620): at org.appcelerator.titanium.util.TiAnimationBuilder$AnimationListener.onAnimationEnd(TiAnimationBuilder.java:618)
E/TiApplication( 3620): at android.view.animation.Animation.fireAnimationEnd(Animation.java:920)
E/TiApplication( 3620): at android.view.animation.Animation.getTransformation(Animation.java:878)
E/TiApplication( 3620): at android.view.animation.Animation.getTransformation(Animation.java:940)
E/TiApplication( 3620): at android.view.animation.AnimationSet.getTransformation(AnimationSet.java:384)
E/TiApplication( 3620): at android.view.animation.Animation.getTransformation(Animation.java:940)
E/TiApplication( 3620): at android.view.View.drawAnimation(View.java:13205)
E/TiApplication( 3620): at android.view.View.draw(View.java:13344)
E/TiApplication( 3620): at android.view.ViewGroup.drawChild(ViewGroup.java:2928)
E/TiApplication( 3620): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2797)
E/TiApplication( 3620): at android.view.View.draw(View.java:13715)
E/TiApplication( 3620): at android.widget.FrameLayout.draw(FrameLayout.java:467)
E/TiApplication( 3620): at android.view.View.draw(View.java:13596)
E/TiApplication( 3620): at android.view.ViewGroup.drawChild(ViewGroup.java:2928)
E/TiApplication( 3620): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2797)
E/TiApplication( 3620): at org.appcelerator.titanium.view.TiCompositeLayout.dispatchDraw(TiCompositeLayout.java:688)
E/TiApplication( 3620): at android.view.View.draw(View.java:13715)
E/TiApplication( 3620): at android.view.View.draw(View.java:13596)
E/TiApplication( 3620): at android.view.ViewGroup.drawChild(ViewGroup.java:2928)
E/TiApplication( 3620): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2797)
E/TiApplication( 3620): at org.appcelerator.titanium.view.TiCompositeLayout.dispatchDraw(TiCompositeLayout.java:688)
E/TiApplication( 3620): at android.view.View.draw(View.java:13594)
E/TiApplication( 3620): at android.view.ViewGroup.drawChild(ViewGroup.java:2928)
E/TiApplication( 3620): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2797)
E/TiApplication( 3620): at android.view.View.draw(View.java:13594)
E/TiApplication( 3620): at android.view.ViewGroup.drawChild(ViewGroup.java:2928)
E/TiApplication( 3620): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2797)
E/TiApplication( 3620): at android.view.View.draw(View.java:13594)
E/TiApplication( 3620): at android.view.ViewGroup.drawChild(ViewGroup.java:2928)
E/TiApplication( 3620): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2797)
E/TiApplication( 3620): at android.view.View.draw(View.java:13715)
E/TiApplication( 3620): at android.widget.FrameLayout.draw(FrameLayout.java:467)
E/TiApplication( 3620): at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2211)
E/TiApplication( 3620): at android.view.ViewRootImpl.drawSoftware(ViewRootImpl.java:2281)
E/TiApplication( 3620): at android.view.ViewRootImpl.draw(ViewRootImpl.java:2177)
E/TiApplication( 3620): at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2045)
E/TiApplication( 3620): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1854)
E/TiApplication( 3620): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:989)
E/TiApplication( 3620): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4351)
E/TiApplication( 3620): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
E/TiApplication( 3620): at android.view.Choreographer.doCallbacks(Choreographer.java:562)
E/TiApplication( 3620): at android.view.Choreographer.doFrame(Choreographer.java:532)
E/TiApplication( 3620): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
E/TiApplication( 3620): at android.os.Handler.handleCallback(Handler.java:725)
E/TiApplication( 3620): at android.os.Handler.dispatchMessage(Handler.java:92)
E/TiApplication( 3620): at android.os.Looper.loop(Looper.java:137)
E/TiApplication( 3620): at android.app.ActivityThread.main(ActivityThread.java:5041)
E/TiApplication( 3620): at java.lang.reflect.Method.invokeNative(Native Method)
E/TiApplication( 3620): at java.lang.reflect.Method.invoke(Method.java:511)
E/TiApplication( 3620): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
E/TiApplication( 3620): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
E/TiApplication( 3620): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 3620): FATAL EXCEPTION: main
E/AndroidRuntime( 3620): java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams cannot be cast to org.appcelerator.titanium.view.TiCompositeLayout$LayoutParams
E/AndroidRuntime( 3620): at org.appcelerator.titanium.util.TiAnimationBuilder$AnimationListener.onAnimationEnd(TiAnimationBuilder.java:618)
E/AndroidRuntime( 3620): at android.view.animation.Animation.fireAnimationEnd(Animation.java:920)
E/AndroidRuntime( 3620): at android.view.animation.Animation.getTransformation(Animation.java:878)
E/AndroidRuntime( 3620): at android.view.animation.Animation.getTransformation(Animation.java:940)
E/AndroidRuntime( 3620): at android.view.animation.AnimationSet.getTransformation(AnimationSet.java:384)
E/AndroidRuntime( 3620): at android.view.animation.Animation.getTransformation(Animation.java:940)
E/AndroidRuntime( 3620): at android.view.View.drawAnimation(View.java:13205)
E/AndroidRuntime( 3620): at android.view.View.draw(View.java:13344)
E/AndroidRuntime( 3620): at android.view.ViewGroup.drawChild(ViewGroup.java:2928)
E/AndroidRuntime( 3620): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2797)
E/AndroidRuntime( 3620): at android.view.View.draw(View.java:13715)
E/AndroidRuntime( 3620): at android.widget.FrameLayout.draw(FrameLayout.java:467)
E/AndroidRuntime( 3620): at android.view.View.draw(View.java:13596)
E/AndroidRuntime( 3620): at android.view.ViewGroup.drawChild(ViewGroup.java:2928)
E/AndroidRuntime( 3620): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2797)
E/AndroidRuntime( 3620): at org.appcelerator.titanium.view.TiCompositeLayout.dispatchDraw(TiCompositeLayout.java:688)
E/AndroidRuntime( 3620): at android.view.View.draw(View.java:13715)
E/AndroidRuntime( 3620): at android.view.View.draw(View.java:13596)
E/AndroidRuntime( 3620): at android.view.ViewGroup.drawChild(ViewGroup.java:2928)
E/AndroidRuntime( 3620): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2797)
E/AndroidRuntime( 3620): at org.appcelerator.titanium.view.TiCompositeLayout.dispatchDraw(TiCompositeLayout.java:688)
E/AndroidRuntime( 3620): at android.view.View.draw(View.java:13594)
E/AndroidRuntime( 3620): at android.view.ViewGroup.drawChild(ViewGroup.java:2928)
E/AndroidRuntime( 3620): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2797)
E/AndroidRuntime( 3620): at android.view.View.draw(View.java:13594)
E/AndroidRuntime( 3620): at android.view.ViewGroup.drawChild(ViewGroup.java:2928)
E/AndroidRuntime( 3620): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2797)
E/AndroidRuntime( 3620): at android.view.View.draw(View.java:13594)
E/AndroidRuntime( 3620): at android.view.ViewGroup.drawChild(ViewGroup.java:2928)
E/AndroidRuntime( 3620): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2797)
E/AndroidRuntime( 3620): at android.view.View.draw(View.java:13715)
E/AndroidRuntime( 3620): at android.widget.FrameLayout.draw(FrameLayout.java:467)
E/AndroidRuntime( 3620): at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2211)
E/AndroidRuntime( 3620): at android.view.ViewRootImpl.drawSoftware(ViewRootImpl.java:2281)
E/AndroidRuntime( 3620): at android.view.ViewRootImpl.draw(ViewRootImpl.java:2177)
E/AndroidRuntime( 3620): at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2045)
E/AndroidRuntime( 3620): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1854)
E/AndroidRuntime( 3620): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:989)
E/AndroidRuntime( 3620): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4351)
E/AndroidRuntime( 3620): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
E/AndroidRuntime( 3620): at android.view.Choreographer.doCallbacks(Choreographer.java:562)
E/AndroidRuntime( 3620): at android.view.Choreographer.doFrame(Choreographer.java:532)
E/AndroidRuntime( 3620): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
E/AndroidRuntime( 3620): at android.os.Handler.handleCallback(Handler.java:725)
E/AndroidRuntime( 3620): at android.os.Handler.dispatchMessage(Handler.java:92)
E/AndroidRuntime( 3620): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime( 3620): at android.app.ActivityThread.main(ActivityThread.java:5041)
E/AndroidRuntime( 3620): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 3620): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime( 3620): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
E/AndroidRuntime( 3620): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
E/AndroidRuntime( 3620): at dalvik.system.NativeStart.main(Native Method)
same here with borderRadius
Related Q&A question: https://developer.appcelerator.com/question/152883/animate-view-with-borderradius
fixed the cast exception. https://github.com/appcelerator/titanium_mobile/pull/4382
This is not fixed in 3.1.2.GA (Samsung Galaxy S2, Android 4.1.2)
App does not crash with view which as border. Verified the fix on: Device : Google Nexus 7, Android Version: 4.3 SDK: 3.2.0.v20131013140318 CLI version : 3.2.0 OS : MAC OSX 10.8.4 Alloy : 1.2.2 Appcelerator Studio, build: 3.2.0.201310112258 XCode : 5