feat:change animator api
This commit is contained in:
		| @@ -15,37 +15,50 @@ | |||||||
|  */ |  */ | ||||||
| import { Panel } from "../ui/panel" | import { Panel } from "../ui/panel" | ||||||
| import { takeLet } from "../pattern/candies" | import { takeLet } from "../pattern/candies" | ||||||
|  | import { BridgeContext } from "../runtime/global" | ||||||
| /** | /** | ||||||
|  * Only supports x,y,width,height,corner(just for four corners),rotation,bgColor, |  * Only supports x,y,width,height,corner(just for four corners),rotation,bgColor, | ||||||
|  * @param panel @see Panel |  * @param panel @see Panel | ||||||
|  */ |  */ | ||||||
| export function animate(panel: Panel) { | export function animate(context: BridgeContext) { | ||||||
|     return (args: { |     const entity = context.entity | ||||||
|         animations: () => void, |     if (entity instanceof Panel) { | ||||||
|         duration: number, |         let panel = entity | ||||||
|     }) => { |         return (args: { | ||||||
|         return takeLet(panel.context.animate)(it => { |             animations: () => void, | ||||||
|             return it.submit().then(() => { |             duration: number, | ||||||
|                 args.animations() |         }) => { | ||||||
|                 return takeLet(panel.getRootView())(root => { |             return takeLet(panel.context.animate)(it => { | ||||||
|                     if (root.isDirty()) { |                 return it.submit().then(() => { | ||||||
|                         const model = root.toModel(); |                     args.animations() | ||||||
|                         (model as any).duration = args.duration |                     return takeLet(panel.getRootView())(root => { | ||||||
|                         const ret = it.animateRender(model) |                         if (root.isDirty()) { | ||||||
|                         root.clean() |                             const model = root.toModel(); | ||||||
|                         return ret |                             (model as any).duration = args.duration | ||||||
|                     } |  | ||||||
|                     for (let v of panel.allHeadViews()) { |  | ||||||
|                         if (v.isDirty()) { |  | ||||||
|                             const model = v.toModel() |  | ||||||
|                             const ret = it.animateRender(model) |                             const ret = it.animateRender(model) | ||||||
|                             it.clean() |                             root.clean() | ||||||
|                             return ret |                             return ret | ||||||
|                         } |                         } | ||||||
|                     } |                         for (let v of panel.allHeadViews()) { | ||||||
|                     throw new Error('Cannot find any animated elements') |                             if (v.isDirty()) { | ||||||
|  |                                 const model = v.toModel() | ||||||
|  |                                 const ret = it.animateRender(model) | ||||||
|  |                                 it.clean() | ||||||
|  |                                 return ret | ||||||
|  |                             } | ||||||
|  |                         } | ||||||
|  |                         throw new Error('Cannot find any animated elements') | ||||||
|  |                     }) | ||||||
|                 }) |                 }) | ||||||
|             }) |             }) as Promise<any> | ||||||
|         }) as Promise<any> |         } | ||||||
|  |     } else { | ||||||
|  |         return (args: { | ||||||
|  |             animations: () => void, | ||||||
|  |             duration: number, | ||||||
|  |         }) => { | ||||||
|  |             return Promise.reject(`Cannot find panel in Context:${context.id}`) | ||||||
|  |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
| } | } | ||||||
| @@ -1,5 +1,3 @@ | |||||||
| import { Modeling, Model } from "../util/types" |  | ||||||
|  |  | ||||||
| /* | /* | ||||||
|  * Copyright [2019] [Doric.Pub] |  * Copyright [2019] [Doric.Pub] | ||||||
|  * |  * | ||||||
| @@ -16,6 +14,7 @@ import { Modeling, Model } from "../util/types" | |||||||
|  * limitations under the License. |  * limitations under the License. | ||||||
|  */ |  */ | ||||||
|  |  | ||||||
|  | import { Modeling, Model } from "../util/types" | ||||||
|  |  | ||||||
| export type AnimatedKey = "translationX" | "translationY" | "scaleX" | "scaleY" | "rotation" | "pivotX" | "pivotY" | export type AnimatedKey = "translationX" | "translationY" | "scaleX" | "scaleY" | "rotation" | "pivotX" | "pivotY" | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user