web:compat animate API for x5
This commit is contained in:
parent
03e3630d02
commit
11f004d974
@ -20,7 +20,10 @@ export class DoricContext {
|
||||
pluginInstances: Map<string, DoricPlugin> = new Map
|
||||
rootNode: DoricStackNode
|
||||
headNodes: Map<string, Map<string, DoricViewNode>> = new Map
|
||||
animationSet?: { viewNode: DoricViewNode, keyFrame: Partial<CSSStyleDeclaration> }[]
|
||||
animationSet?: {
|
||||
viewNode: DoricViewNode,
|
||||
keyFrame: Partial<CSSStyleDeclaration>,
|
||||
}[]
|
||||
|
||||
constructor(content: string) {
|
||||
createContext(this.contextId, content)
|
||||
@ -93,7 +96,7 @@ export class DoricContext {
|
||||
addAnimation(viewNode: DoricViewNode, keyFrame: Partial<CSSStyleDeclaration>) {
|
||||
this.animationSet?.push({
|
||||
viewNode,
|
||||
keyFrame
|
||||
keyFrame,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -24,15 +24,41 @@ export class AnimatePlugin extends DoricPlugin {
|
||||
Promise.all(
|
||||
this.context.animationSet?.map(e => {
|
||||
return new Promise(resolve => {
|
||||
const keyFrame: Keyframe = {}
|
||||
const ensureNonString = (key: string, value: any) => {
|
||||
if (!!value && value !== "") {
|
||||
return value
|
||||
}
|
||||
switch ((key)) {
|
||||
case "backgroundColor":
|
||||
return "transparent"
|
||||
case "transform":
|
||||
return "none"
|
||||
default:
|
||||
return "none"
|
||||
}
|
||||
}
|
||||
for (let k in e.keyFrame) {
|
||||
keyFrame[k] = ensureNonString(k, e.viewNode.view.style[k])
|
||||
e.keyFrame[k] = ensureNonString(k, e.keyFrame[k])
|
||||
}
|
||||
try {
|
||||
const animation = e.viewNode.view.animate(
|
||||
[e.keyFrame as Keyframe],
|
||||
[keyFrame, e.keyFrame as Keyframe],
|
||||
{
|
||||
duration: args.duration,
|
||||
fill: "forwards"
|
||||
})
|
||||
animation.onfinish = () => {
|
||||
Object.entries(e.keyFrame).forEach(entry => {
|
||||
Reflect.set(e.viewNode.view.style, entry[0], entry[1])
|
||||
})
|
||||
resolve(true)
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
alert(e.stack)
|
||||
}
|
||||
})
|
||||
}) || [])
|
||||
.then(() => {
|
||||
|
Reference in New Issue
Block a user