feat:add animator

This commit is contained in:
pengfei.zhou
2019-11-29 11:59:16 +08:00
parent 5a440e30f4
commit 30c913f640
5 changed files with 148 additions and 3 deletions

View File

@@ -1,3 +1,8 @@
import { Panel } from "./panel"
import { takeLet } from "../pattern/candies"
import { O_TRUNC } from "constants"
import { modal } from "../native/modal"
/*
* Copyright [2019] [Doric.Pub]
*
@@ -151,4 +156,39 @@ export class AnimationSet {
})
})
}
}
export function animator(panel: Panel) {
return (args: {
animations: () => void,
duration: number,
complete?: () => void
}) => {
takeLet(panel.context.shader)(it => {
it.animator().then(() => {
args.animations()
return takeLet(panel.getRootView())(root => {
if (root.isDirty()) {
const model = root.toModel();
(model as any).duration = args.duration
const ret = it.animateRender(model)
root.clean()
return ret
}
for (let v of panel.allHeadViews()) {
if (v.isDirty()) {
const model = v.toModel()
const ret = it.animateRender(model)
it.clean()
return ret
}
}
})
}).then(() => {
if (args.complete) {
args.complete()
}
})
})
}
}

View File

@@ -49,7 +49,9 @@ export abstract class Panel {
addHeadView(v: View) {
this.headviews.set(v.viewId, v)
}
allHeadViews() {
return this.headviews.values()
}
removeHeadView(v: View | string) {
if (v instanceof View) {
this.headviews.delete(v.viewId)