2021-09-01 10:47:40 +08:00
|
|
|
import {
|
2021-09-02 11:39:51 +08:00
|
|
|
jsx,
|
2021-09-01 10:47:40 +08:00
|
|
|
VLayout,
|
2021-09-13 13:09:32 +08:00
|
|
|
HLayout,
|
2021-09-02 11:39:51 +08:00
|
|
|
Panel,
|
2021-09-01 10:47:40 +08:00
|
|
|
Gravity,
|
2021-09-02 11:39:51 +08:00
|
|
|
Group,
|
2021-09-03 13:42:25 +08:00
|
|
|
layoutConfig,
|
2021-09-01 10:47:40 +08:00
|
|
|
Text,
|
2021-09-03 16:48:24 +08:00
|
|
|
createRef,
|
2021-09-13 13:09:32 +08:00
|
|
|
Color,
|
2021-09-13 13:30:22 +08:00
|
|
|
statusbar,
|
|
|
|
navbar,
|
2021-09-01 10:47:40 +08:00
|
|
|
} from "doric";
|
|
|
|
|
|
|
|
@Entry
|
2021-09-13 13:30:22 +08:00
|
|
|
class Timer extends Panel {
|
|
|
|
onShow() {
|
|
|
|
navbar(this.context).setHidden(true);
|
|
|
|
statusbar(this.context).setHidden(true);
|
|
|
|
}
|
|
|
|
|
2021-09-02 11:39:51 +08:00
|
|
|
build(root: Group) {
|
2021-09-13 13:30:22 +08:00
|
|
|
statusbar(this.context).setHidden(true);
|
2021-09-13 13:09:32 +08:00
|
|
|
root.backgroundColor = Color.BLACK;
|
|
|
|
const hour1Ref = createRef<Text>();
|
|
|
|
const hour2Ref = createRef<Text>();
|
|
|
|
const min1Ref = createRef<Text>();
|
|
|
|
const min2Ref = createRef<Text>();
|
|
|
|
const sec1Ref = createRef<Text>();
|
|
|
|
const sec2Ref = createRef<Text>();
|
|
|
|
const comm1Ref = createRef<Text>();
|
|
|
|
const comm2Ref = createRef<Text>();
|
|
|
|
|
2021-09-02 11:39:51 +08:00
|
|
|
<VLayout
|
|
|
|
space={20}
|
|
|
|
gravity={Gravity.Center}
|
2021-09-03 13:42:25 +08:00
|
|
|
layoutConfig={layoutConfig().fit().configAlignment(Gravity.Center)}
|
2021-09-02 11:39:51 +08:00
|
|
|
parent={root}
|
|
|
|
>
|
2021-09-13 13:09:32 +08:00
|
|
|
<HLayout space={5}>
|
|
|
|
<Text
|
|
|
|
textSize={40}
|
|
|
|
ref={hour1Ref}
|
|
|
|
textColor={Color.WHITE}
|
|
|
|
padding={{ left: 10, right: 10, top: 10, bottom: 10 }}
|
|
|
|
>
|
|
|
|
0
|
|
|
|
</Text>
|
|
|
|
<Text
|
|
|
|
textSize={40}
|
|
|
|
ref={hour2Ref}
|
|
|
|
textColor={Color.WHITE}
|
|
|
|
padding={{ left: 10, right: 10, top: 10, bottom: 10 }}
|
|
|
|
>
|
|
|
|
0
|
|
|
|
</Text>
|
|
|
|
<Text
|
|
|
|
ref={comm1Ref}
|
|
|
|
textColor={Color.WHITE}
|
|
|
|
textSize={40}
|
|
|
|
padding={{ top: 10, bottom: 10 }}
|
|
|
|
>
|
|
|
|
:
|
|
|
|
</Text>
|
|
|
|
<Text
|
|
|
|
textSize={40}
|
|
|
|
ref={min1Ref}
|
|
|
|
textColor={Color.WHITE}
|
|
|
|
padding={{ left: 10, right: 10, top: 10, bottom: 10 }}
|
|
|
|
>
|
|
|
|
0
|
|
|
|
</Text>
|
|
|
|
<Text
|
|
|
|
textSize={40}
|
|
|
|
ref={min2Ref}
|
|
|
|
textColor={Color.WHITE}
|
|
|
|
padding={{ left: 10, right: 10, top: 10, bottom: 10 }}
|
|
|
|
>
|
|
|
|
0
|
|
|
|
</Text>
|
|
|
|
<Text
|
|
|
|
ref={comm2Ref}
|
|
|
|
textSize={40}
|
|
|
|
textColor={Color.WHITE}
|
|
|
|
padding={{ top: 10, bottom: 10 }}
|
|
|
|
>
|
|
|
|
:
|
|
|
|
</Text>
|
|
|
|
<Text
|
|
|
|
textSize={40}
|
|
|
|
ref={sec1Ref}
|
|
|
|
textColor={Color.WHITE}
|
|
|
|
padding={{ left: 10, right: 10, top: 10, bottom: 10 }}
|
|
|
|
>
|
|
|
|
0
|
|
|
|
</Text>
|
|
|
|
<Text
|
|
|
|
textSize={40}
|
|
|
|
ref={sec2Ref}
|
|
|
|
textColor={Color.WHITE}
|
|
|
|
padding={{ left: 10, right: 10, top: 10, bottom: 10 }}
|
|
|
|
>
|
|
|
|
0
|
|
|
|
</Text>
|
|
|
|
</HLayout>
|
2021-09-02 11:39:51 +08:00
|
|
|
</VLayout>;
|
2021-09-13 13:09:32 +08:00
|
|
|
|
|
|
|
this.addOnRenderFinishedCallback(async () => {
|
|
|
|
const width = await root.getWidth(this.context);
|
|
|
|
[
|
|
|
|
hour1Ref,
|
|
|
|
hour2Ref,
|
|
|
|
comm1Ref,
|
|
|
|
min1Ref,
|
|
|
|
min2Ref,
|
|
|
|
comm2Ref,
|
|
|
|
sec1Ref,
|
|
|
|
sec2Ref,
|
|
|
|
].forEach((e) => {
|
|
|
|
e.current.apply({
|
|
|
|
textSize: width / 10,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
setInterval(() => {
|
|
|
|
const time = new Date();
|
|
|
|
hour1Ref.current.text = `${Math.floor(time.getHours() / 10)}`;
|
|
|
|
hour2Ref.current.text = `${Math.floor(time.getHours() % 10)}`;
|
|
|
|
|
|
|
|
min1Ref.current.text = `${Math.floor(time.getMinutes() / 10)}`;
|
|
|
|
min2Ref.current.text = `${Math.floor(time.getMinutes() % 10)}`;
|
|
|
|
|
|
|
|
sec1Ref.current.text = `${Math.floor(time.getSeconds() / 10)}`;
|
|
|
|
sec2Ref.current.text = `${Math.floor(time.getSeconds() % 10)}`;
|
|
|
|
}, 100);
|
2021-09-01 10:47:40 +08:00
|
|
|
}
|
|
|
|
}
|