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

150 lines
5.5 KiB
TypeScript
Raw Normal View History

2019-12-04 14:07:14 +08:00
import { Group, Panel, List, text, gravity, Color, Stack, LayoutSpec, list, NativeCall, listItem, log, vlayout, Gravity, hlayout, Text, scroller, layoutConfig, image, IView, IVLayout, ScaleType, IText, modal } from "doric";
import { colors, label } from "./utils";
@Entry
class ModalDemo extends Panel {
build(rootView: Group): void {
scroller(vlayout([
text({
text: "Modal",
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('toast on bottom'),
label('Click me').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: () => {
modal(context).toast('This is a toast.')
}
} as IText),
label('toast on top'),
label('Click me').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: () => {
modal(context).toast('This is a toast.', Gravity.Top)
}
} as IText),
label('toast on center'),
label('Click me').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: () => {
modal(context).toast('This is a toast.', Gravity.Center)
}
} as IText),
text({
text: "Alert",
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[2],
textAlignment: Gravity.Center,
height: 50,
}),
label('Click me').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: () => {
modal(context).alert({
msg: 'This is alert.',
title: 'Alert title',
okLabel: "OkLabel"
}).then(e => {
modal(context).toast('Clicked OK.')
})
}
} as IText),
text({
text: "Confirm",
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[3],
textAlignment: Gravity.Center,
height: 50,
}),
label('Click me').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: () => {
modal(context).confirm({
msg: 'This is Confirm.',
title: 'Confirm title',
okLabel: "OkLabel",
cancelLabel: 'CancelLabel',
}).then(
() => {
modal(context).toast('Clicked OK.')
},
() => {
modal(context).toast('Clicked Cancel.')
})
}
} as IText),
text({
text: "Prompt",
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[4],
textAlignment: Gravity.Center,
height: 50,
}),
label('Click me').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: () => {
modal(context).prompt({
msg: 'This is Prompt.',
title: 'Prompt title',
okLabel: "OkLabel",
cancelLabel: 'CancelLabel',
}).then(
e => {
modal(context).toast(`Clicked OK.Input:${e}`)
},
e => {
modal(context).toast(`Clicked Cancel.Input:${e}`)
})
}
} as IText),
]).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,
} as IVLayout)).apply({
2019-12-14 16:32:04 +08:00
layoutConfig: layoutConfig().most(),
2019-12-04 14:07:14 +08:00
}).in(rootView)
}
}