2020-04-16 19:21:24 +08:00
|
|
|
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-09-04 18:51:08 +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-09-04 18:51:08 +08:00
|
|
|
tag: "tvCounter"
|
2020-01-06 10:43:18 +08:00
|
|
|
}),
|
|
|
|
],
|
|
|
|
{
|
|
|
|
layoutConfig: layoutConfig().most(),
|
|
|
|
gravity: Gravity.Center,
|
|
|
|
space: 20,
|
|
|
|
}
|
|
|
|
).in(root)
|
2020-09-04 18:51:08 +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}`
|
2021-02-07 16:33:31 +08:00
|
|
|
log("onBind\nseee")
|
|
|
|
logw("onBind")
|
|
|
|
loge("onBind")
|
2019-12-06 11:41:51 +08:00
|
|
|
}
|
2019-12-04 14:07:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
@Entry
|
2020-09-04 18:51:08 +08:00
|
|
|
export class CounterPage extends VMPanel<CountModel, CounterView>{
|
2019-12-04 14:07:14 +08:00
|
|
|
|
|
|
|
|
|
|
|
getViewHolderClass() {
|
|
|
|
return CounterView
|
|
|
|
}
|
|
|
|
|
|
|
|
getViewModelClass() {
|
|
|
|
return CounterVM
|
|
|
|
}
|
|
|
|
|
|
|
|
getState(): CountModel {
|
|
|
|
return {
|
|
|
|
count: 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|