This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
Doric/demo/src/AnimatorDemo.ts

101 lines
3.8 KiB
TypeScript
Raw Normal View History

2019-11-29 15:07:32 +08:00
import { animate, Group, Panel, gravity, Color, LayoutSpec, vlayout, scroller, layoutConfig, IVLayout, modal, IText, network, View, stack, IHLayout, hlayout, IView, text } from "doric";
import { title, colors, box } from "./utils";
function thisLabel(str: string) {
return text({
text: str,
width: 100,
height: 50,
bgColor: colors[4],
textSize: 20,
textColor: Color.WHITE,
layoutConfig: layoutConfig().exactly(),
})
}
2019-11-29 11:59:16 +08:00
@Entry
class AnimatorDemo extends Panel {
build(rootView: Group): void {
const view = box(2)
2019-11-29 15:07:32 +08:00
let idx = 0
vlayout([
2019-11-29 11:59:16 +08:00
title("Animator Demo"),
2019-11-29 15:07:32 +08:00
vlayout(
[
hlayout([
thisLabel('Reset').apply({
onClick: () => {
animate(this)({
animations: () => {
view.width = view.height = 20
},
duration: 3000,
}).then(() => {
modal(context).toast('Fininshed')
}).catch(e => {
modal(context).toast(`${e}`)
})
}
}),
]),
hlayout([
thisLabel('Width').apply({
onClick: () => {
animate(this)({
animations: () => {
view.width = 200
},
duration: 3000,
})
}
}),
thisLabel('Height').apply({
onClick: () => {
animate(this)({
animations: () => {
view.height = 200
},
duration: 3000,
})
}
}),
]).apply({ space: 10 } as IHLayout),
hlayout([
thisLabel('BgColor').apply({
onClick: () => {
animate(this)({
animations: () => {
view.bgColor = colors[(idx++) % colors.length]
},
duration: 3000,
});
}
}),
2019-11-29 15:16:15 +08:00
thisLabel('Rotation').apply({
onClick: () => {
animate(this)({
animations: () => {
view.rotation = view.rotation || 0 + 0.5
},
duration: 3000,
});
}
}),
2019-11-29 15:07:32 +08:00
]).apply({ space: 10 } as IHLayout),
]
).apply({ space: 10 } as IVLayout),
2019-11-29 11:59:16 +08:00
stack([
view.also(v => {
v.left = 20
})
]).apply({
layoutConfig: layoutConfig().atmost(),
2019-11-29 13:10:00 +08:00
bgColor: colors[1].alpha(0.3 * 255),
2019-11-29 11:59:16 +08:00
}),
]).apply({
layoutConfig: layoutConfig().atmost(),
2019-11-29 11:59:16 +08:00
gravity: gravity().center(),
space: 10,
} as IVLayout).in(rootView)
2019-11-29 11:59:16 +08:00
}
}