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/StorageDemo.ts

93 lines
3.2 KiB
TypeScript
Raw Normal View History

import { storage, Panel, scroller, vlayout, text, layoutConfig, LayoutSpec, Color, gravity, Group, modal, Text, log, loge } from "doric";
2019-12-04 14:07:14 +08:00
import { colors, label } from "./utils";
const storedKey = 'StoredKey'
const zone = 'StorageDemo'
@Entry
class StorageDemo extends Panel {
stored!: Text
update() {
storage(context).getItem(storedKey, zone).then(e => {
this.stored.text = e || ""
log('Called in then')
})
}
build(root: Group) {
scroller(vlayout([
text({
text: "Storage Demo",
2019-12-14 16:32:04 +08:00
layoutConfig: layoutConfig().configWidth(LayoutSpec.MOST),
2019-12-04 14:07:14 +08:00
textSize: 30,
textColor: Color.WHITE,
backgroundColor: colors[1],
textAlignment: gravity().center(),
height: 50,
}),
label('Stored'),
text({
2019-12-14 16:32:04 +08:00
layoutConfig: layoutConfig().configWidth(LayoutSpec.MOST),
2019-12-04 14:07:14 +08:00
textSize: 20,
textColor: Color.WHITE,
backgroundColor: colors[3],
textAlignment: gravity().center(),
height: 50,
}).also(it => this.stored = it),
label('store a value').apply({
width: 200,
height: 50,
backgroundColor: colors[0],
textSize: 30,
textColor: Color.WHITE,
2019-12-14 16:32:04 +08:00
layoutConfig: layoutConfig().just(),
2019-12-04 14:07:14 +08:00
onClick: () => {
storage(context).getItem(storedKey, zone).then(e => {
modal(context).prompt({
text: e,
title: "Please input text to store",
defaultText: "Default Value",
}).then(text => {
storage(context).setItem(storedKey, text, zone).then(() => {
this.update()
})
})
})
},
}),
2019-12-04 14:07:14 +08:00
label('remove value').apply({
width: 200,
height: 50,
backgroundColor: colors[0],
textSize: 30,
textColor: Color.WHITE,
2019-12-14 16:32:04 +08:00
layoutConfig: layoutConfig().just(),
2019-12-04 14:07:14 +08:00
onClick: () => {
storage(context).remove(storedKey, zone).then(e => {
this.update()
})
},
}),
2019-12-04 14:07:14 +08:00
label('clear values').apply({
width: 200,
height: 50,
backgroundColor: colors[0],
textSize: 30,
textColor: Color.WHITE,
2019-12-14 16:32:04 +08:00
layoutConfig: layoutConfig().just(),
2019-12-04 14:07:14 +08:00
onClick: () => {
storage(context).clear(zone).then(e => {
this.update()
})
},
}),
2019-12-04 14:07:14 +08:00
]).apply({
2019-12-14 16:32:04 +08:00
layoutConfig: layoutConfig().most().configHeight(LayoutSpec.FIT),
2019-12-04 14:07:14 +08:00
gravity: gravity().center(),
space: 10,
})).apply({
2019-12-14 16:32:04 +08:00
layoutConfig: layoutConfig().most(),
2019-12-04 14:07:14 +08:00
}).in(root)
this.update()
}
}