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
|
pluginInstances: Map<string, DoricPlugin> = new Map
|
||||||
rootNode: DoricStackNode
|
rootNode: DoricStackNode
|
||||||
headNodes: Map<string, Map<string, DoricViewNode>> = new Map
|
headNodes: Map<string, Map<string, DoricViewNode>> = new Map
|
||||||
animationSet?: { viewNode: DoricViewNode, keyFrame: Partial<CSSStyleDeclaration> }[]
|
animationSet?: {
|
||||||
|
viewNode: DoricViewNode,
|
||||||
|
keyFrame: Partial<CSSStyleDeclaration>,
|
||||||
|
}[]
|
||||||
|
|
||||||
constructor(content: string) {
|
constructor(content: string) {
|
||||||
createContext(this.contextId, content)
|
createContext(this.contextId, content)
|
||||||
@ -93,7 +96,7 @@ export class DoricContext {
|
|||||||
addAnimation(viewNode: DoricViewNode, keyFrame: Partial<CSSStyleDeclaration>) {
|
addAnimation(viewNode: DoricViewNode, keyFrame: Partial<CSSStyleDeclaration>) {
|
||||||
this.animationSet?.push({
|
this.animationSet?.push({
|
||||||
viewNode,
|
viewNode,
|
||||||
keyFrame
|
keyFrame,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,14 +24,40 @@ export class AnimatePlugin extends DoricPlugin {
|
|||||||
Promise.all(
|
Promise.all(
|
||||||
this.context.animationSet?.map(e => {
|
this.context.animationSet?.map(e => {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
const animation = e.viewNode.view.animate(
|
const keyFrame: Keyframe = {}
|
||||||
[e.keyFrame as Keyframe],
|
const ensureNonString = (key: string, value: any) => {
|
||||||
{
|
if (!!value && value !== "") {
|
||||||
duration: args.duration,
|
return value
|
||||||
fill: "forwards"
|
}
|
||||||
})
|
switch ((key)) {
|
||||||
animation.onfinish = () => {
|
case "backgroundColor":
|
||||||
resolve(true)
|
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(
|
||||||
|
[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)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}) || [])
|
}) || [])
|
||||||
|
Reference in New Issue
Block a user