2020-04-16 19:21:24 +08:00
|
|
|
import { Group, Panel, gravity, Color, LayoutSpec, vlayout, scroller, layoutConfig, modal, notification } from "doric";
|
2020-01-09 11:50:49 +08:00
|
|
|
import { title, label, colors } from "./utils";
|
|
|
|
|
|
|
|
@Entry
|
|
|
|
class NotificationDemo extends Panel {
|
|
|
|
subscribeId?: string
|
|
|
|
build(rootView: Group): void {
|
|
|
|
scroller(vlayout([
|
|
|
|
title("Notification Demo"),
|
|
|
|
label('Publish').apply({
|
|
|
|
width: 200,
|
|
|
|
height: 50,
|
|
|
|
backgroundColor: colors[0],
|
|
|
|
textSize: 30,
|
|
|
|
textColor: Color.WHITE,
|
|
|
|
layoutConfig: layoutConfig().just(),
|
|
|
|
onClick: () => {
|
|
|
|
notification(context).publish({
|
|
|
|
biz: "Test",
|
|
|
|
name: "Demo",
|
|
|
|
data: {
|
|
|
|
a: "1",
|
|
|
|
b: "2",
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2020-04-16 19:21:24 +08:00
|
|
|
}),
|
2020-01-09 11:50:49 +08:00
|
|
|
label('Subscribe').apply({
|
|
|
|
width: 200,
|
|
|
|
height: 50,
|
|
|
|
backgroundColor: colors[0],
|
|
|
|
textSize: 30,
|
|
|
|
textColor: Color.WHITE,
|
|
|
|
layoutConfig: layoutConfig().just(),
|
|
|
|
onClick: () => {
|
|
|
|
notification(context).subscribe({
|
|
|
|
biz: "Test",
|
|
|
|
name: "Demo",
|
|
|
|
callback: (data) => {
|
|
|
|
modal(context).alert(`Received notification,data is ${JSON.stringify(data)}`)
|
|
|
|
}
|
|
|
|
}).then(e => {
|
|
|
|
this.subscribeId = e
|
|
|
|
})
|
|
|
|
}
|
2020-04-16 19:21:24 +08:00
|
|
|
}),
|
2020-01-09 11:50:49 +08:00
|
|
|
label('Unsubscribe').apply({
|
|
|
|
width: 200,
|
|
|
|
height: 50,
|
|
|
|
backgroundColor: colors[0],
|
|
|
|
textSize: 30,
|
|
|
|
textColor: Color.WHITE,
|
|
|
|
layoutConfig: layoutConfig().just(),
|
|
|
|
onClick: () => {
|
|
|
|
if (this.subscribeId) {
|
|
|
|
notification(context).unsubscribe(this.subscribeId).then(e => {
|
|
|
|
this.subscribeId = undefined
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2020-04-16 19:21:24 +08:00
|
|
|
}),
|
2020-01-09 11:50:49 +08:00
|
|
|
]).apply({
|
|
|
|
layoutConfig: layoutConfig().most().configHeight(LayoutSpec.FIT),
|
|
|
|
gravity: gravity().center(),
|
|
|
|
space: 10,
|
2020-04-16 19:21:24 +08:00
|
|
|
})).apply({
|
2020-01-09 11:50:49 +08:00
|
|
|
layoutConfig: layoutConfig().most(),
|
|
|
|
}).in(rootView)
|
|
|
|
}
|
|
|
|
}
|