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/doric-demo/src/Counter.ts

64 lines
1.5 KiB
TypeScript
Raw Normal View History

import { text, vlayout, ViewHolder, VMPanel, ViewModel, Gravity, NativeCall, Text, Color, log, logw, loge, Group, LayoutSpec, layoutConfig, } from "doric"
2019-12-04 14:07:14 +08:00
interface CountModel {
count: number
}
2019-12-06 11:41:51 +08:00
class CounterView extends ViewHolder {
2019-12-04 14:07:14 +08:00
number!: Text
counter!: Text
build(root: Group) {
2020-01-06 10:43:18 +08:00
vlayout(
[
2020-07-04 10:04:40 +08:00
text({
textSize: 40,
tag:"tvNumber"
2020-01-06 10:43:18 +08:00
}),
2020-07-04 10:04:40 +08:00
text({
text: "Click To Count 1",
2020-01-06 10:43:18 +08:00
textSize: 20,
2020-07-04 10:04:40 +08:00
tag:"tvCounter"
2020-01-06 10:43:18 +08:00
}),
],
{
layoutConfig: layoutConfig().most(),
gravity: Gravity.Center,
space: 20,
}
).in(root)
2020-07-04 10:04:40 +08:00
this.number= root.findViewByTag("tvNumber")!
this.counter= root.findViewByTag("tvCounter")!
2019-12-04 14:07:14 +08:00
}
}
class CounterVM extends ViewModel<CountModel, CounterView> {
2019-12-06 11:41:51 +08:00
onAttached(s: CountModel, vh: CounterView) {
2019-12-04 14:07:14 +08:00
vh.counter.onClick = () => {
this.updateState(state => {
state.count++
})
}
}
2019-12-06 11:41:51 +08:00
onBind(s: CountModel, vh: CounterView) {
vh.number.text = `${s.count}`
}
2019-12-04 14:07:14 +08:00
}
@Entry
class MyPage extends VMPanel<CountModel, CounterView>{
getViewHolderClass() {
return CounterView
}
getViewModelClass() {
return CounterVM
}
getState(): CountModel {
return {
count: 0
}
}
}