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

128 lines
5.2 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([
title("Animator zDemo"),
2019-11-29 15:07:32 +08:00
vlayout(
[
hlayout([
thisLabel('Reset').apply({
onClick: () => {
animate(this)({
animations: () => {
view.width = view.height = 20
view.x = view.y = 0
view.rotation = 0
view.bgColor = colors[2]
2019-11-29 15:07:32 +08:00
},
duration: 1500,
2019-11-29 15:07:32 +08:00
}).then(() => {
modal(context).toast('Fininshed')
}).catch(e => {
modal(context).toast(`${e}`)
})
}
}),
thisLabel('Move X').apply({
onClick: () => {
animate(this)({
animations: () => {
view.x = view.x || 0
view.x += 100
},
duration: 1000,
})
}
}),
thisLabel('Move Y').apply({
onClick: () => {
animate(this)({
animations: () => {
view.y = view.y || 0
view.y += 100
},
duration: 1000,
})
}
}),
]).apply({ space: 10 } as IHLayout),
2019-11-29 15:07:32 +08:00
hlayout([
thisLabel('Width').apply({
onClick: () => {
animate(this)({
animations: () => {
view.width += 100
2019-11-29 15:07:32 +08:00
},
duration: 1000,
2019-11-29 15:07:32 +08:00
})
}
}),
thisLabel('Height').apply({
onClick: () => {
animate(this)({
animations: () => {
view.height += 100
2019-11-29 15:07:32 +08:00
},
duration: 1000,
2019-11-29 15:07:32 +08:00
})
}
}),
]).apply({ space: 10 } as IHLayout),
hlayout([
thisLabel('BgColor').apply({
onClick: () => {
animate(this)({
animations: () => {
view.bgColor = colors[(idx++) % colors.length]
},
duration: 1000,
2019-11-29 15:07:32 +08:00
});
}
}),
2019-11-29 15:16:15 +08:00
thisLabel('Rotation').apply({
onClick: () => {
animate(this)({
animations: () => {
if (view.rotation) {
view.rotation += 0.5
} else {
view.rotation = 0.5
}
2019-11-29 15:16:15 +08:00
},
duration: 1000,
2019-11-29 15:16:15 +08:00
});
}
}),
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
2019-11-29 11:59:16 +08:00
]).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
}
}