Merge branch 'feature/animation' into 'master'
feat:Android support corners animation See merge request !36
This commit is contained in:
		| @@ -151,4 +151,11 @@ public class DoricLayer extends FrameLayout { | |||||||
|         }; |         }; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     public float getCornerRadius() { | ||||||
|  |         if (mCornerRadii != null) { | ||||||
|  |             return mCornerRadii[0]; | ||||||
|  |         } | ||||||
|  |         return 0; | ||||||
|  |     } | ||||||
|  |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -215,7 +215,15 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder { | |||||||
|                 break; |                 break; | ||||||
|             case "corners": |             case "corners": | ||||||
|                 if (prop.isNumber()) { |                 if (prop.isNumber()) { | ||||||
|                     requireDoricLayer().setCornerRadius(DoricUtils.dp2px(prop.asNumber().toFloat())); |                     if (isAnimating()) { | ||||||
|  |                         addAnimator(ObjectAnimator.ofFloat( | ||||||
|  |                                 this, | ||||||
|  |                                 name, | ||||||
|  |                                 getCorners(), | ||||||
|  |                                 prop.asNumber().toFloat())); | ||||||
|  |                     } else { | ||||||
|  |                         setCorners(prop.asNumber().toFloat()); | ||||||
|  |                     } | ||||||
|                 } else if (prop.isObject()) { |                 } else if (prop.isObject()) { | ||||||
|                     JSValue lt = prop.asObject().getProperty("leftTop"); |                     JSValue lt = prop.asObject().getProperty("leftTop"); | ||||||
|                     JSValue rt = prop.asObject().getProperty("rightTop"); |                     JSValue rt = prop.asObject().getProperty("rightTop"); | ||||||
| @@ -454,4 +462,15 @@ public abstract class ViewNode<T extends View> extends DoricContextHolder { | |||||||
|     public void setBgColor(int color) { |     public void setBgColor(int color) { | ||||||
|         mView.setBackgroundColor(color); |         mView.setBackgroundColor(color); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @DoricMethod | ||||||
|  |     public void setCorners(float corner) { | ||||||
|  |         requireDoricLayer().setCornerRadius(DoricUtils.dp2px(corner)); | ||||||
|  |         getNodeView().invalidate(); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     @DoricMethod | ||||||
|  |     public float getCorners() { | ||||||
|  |         return DoricUtils.px2dp((int) requireDoricLayer().getCornerRadius()); | ||||||
|  |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -4,10 +4,10 @@ import { title, colors, box } from "./utils"; | |||||||
| function thisLabel(str: string) { | function thisLabel(str: string) { | ||||||
|     return text({ |     return text({ | ||||||
|         text: str, |         text: str, | ||||||
|         width: 100, |         width: 60, | ||||||
|         height: 50, |         height: 50, | ||||||
|         bgColor: colors[4], |         bgColor: colors[0], | ||||||
|         textSize: 20, |         textSize: 15, | ||||||
|         textColor: Color.WHITE, |         textColor: Color.WHITE, | ||||||
|         layoutConfig: layoutConfig().exactly(), |         layoutConfig: layoutConfig().exactly(), | ||||||
|     }) |     }) | ||||||
| @@ -31,6 +31,7 @@ class AnimatorDemo extends Panel { | |||||||
|                                         view.x = view.y = 0 |                                         view.x = view.y = 0 | ||||||
|                                         view.rotation = 0 |                                         view.rotation = 0 | ||||||
|                                         view.bgColor = colors[2] |                                         view.bgColor = colors[2] | ||||||
|  |                                         view.corners = 0 | ||||||
|                                     }, |                                     }, | ||||||
|                                     duration: 1500, |                                     duration: 1500, | ||||||
|                                 }).then(() => { |                                 }).then(() => { | ||||||
| @@ -40,7 +41,9 @@ class AnimatorDemo extends Panel { | |||||||
|                                 }) |                                 }) | ||||||
|                             } |                             } | ||||||
|                         }), |                         }), | ||||||
|                         thisLabel('Move X').apply({ |                     ]).apply({ space: 10 } as IHLayout), | ||||||
|  |                     hlayout([ | ||||||
|  |                         thisLabel('X').apply({ | ||||||
|                             onClick: () => { |                             onClick: () => { | ||||||
|                                 animate(this)({ |                                 animate(this)({ | ||||||
|                                     animations: () => { |                                     animations: () => { | ||||||
| @@ -51,7 +54,7 @@ class AnimatorDemo extends Panel { | |||||||
|                                 }) |                                 }) | ||||||
|                             } |                             } | ||||||
|                         }), |                         }), | ||||||
|                         thisLabel('Move Y').apply({ |                         thisLabel('Y').apply({ | ||||||
|                             onClick: () => { |                             onClick: () => { | ||||||
|                                 animate(this)({ |                                 animate(this)({ | ||||||
|                                     animations: () => { |                                     animations: () => { | ||||||
| @@ -62,8 +65,6 @@ class AnimatorDemo extends Panel { | |||||||
|                                 }) |                                 }) | ||||||
|                             } |                             } | ||||||
|                         }), |                         }), | ||||||
|                     ]).apply({ space: 10 } as IHLayout), |  | ||||||
|                     hlayout([ |  | ||||||
|                         thisLabel('Width').apply({ |                         thisLabel('Width').apply({ | ||||||
|                             onClick: () => { |                             onClick: () => { | ||||||
|                                 animate(this)({ |                                 animate(this)({ | ||||||
| @@ -110,6 +111,20 @@ class AnimatorDemo extends Panel { | |||||||
|                                 }); |                                 }); | ||||||
|                             } |                             } | ||||||
|                         }), |                         }), | ||||||
|  |                         thisLabel('Corner').apply({ | ||||||
|  |                             onClick: () => { | ||||||
|  |                                 animate(this)({ | ||||||
|  |                                     animations: () => { | ||||||
|  |                                         if (typeof view.corners === 'number') { | ||||||
|  |                                             view.corners += 10 | ||||||
|  |                                         } else { | ||||||
|  |                                             view.corners = 10 | ||||||
|  |                                         } | ||||||
|  |                                     }, | ||||||
|  |                                     duration: 1000, | ||||||
|  |                                 }); | ||||||
|  |                             } | ||||||
|  |                         }), | ||||||
|                     ]).apply({ space: 10 } as IHLayout), |                     ]).apply({ space: 10 } as IHLayout), | ||||||
|                 ] |                 ] | ||||||
|             ).apply({ space: 10 } as IVLayout), |             ).apply({ space: 10 } as IVLayout), | ||||||
|   | |||||||
| @@ -15,7 +15,10 @@ | |||||||
|  */ |  */ | ||||||
| import { Panel } from "../ui/panel" | import { Panel } from "../ui/panel" | ||||||
| import { takeLet } from "../pattern/candies" | import { takeLet } from "../pattern/candies" | ||||||
|  | /** | ||||||
|  |  * Only supports x,y,width,height,corner(just for four corners),rotation,bgColor, | ||||||
|  |  * @param panel @see Panel | ||||||
|  |  */ | ||||||
| export function animate(panel: Panel) { | export function animate(panel: Panel) { | ||||||
|     return (args: { |     return (args: { | ||||||
|         animations: () => void, |         animations: () => void, | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user