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/demo/src/ImageDemo.ts

109 lines
3.8 KiB
TypeScript
Raw Normal View History

2019-11-27 19:15:57 +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, Image } from "doric";
2019-11-20 15:36:07 +08:00
import { colors, label } from "./utils";
2019-11-26 20:15:16 +08:00
import { img_base64 } from "./image_base64";
2019-11-21 14:15:43 +08:00
const imageUrl = 'https://img.zcool.cn/community/01e75b5da933daa801209e1ffa4649.jpg@1280w_1l_2o_100sh.jpg'
2019-11-26 20:15:16 +08:00
2019-11-20 15:36:07 +08:00
@Entry
class ImageDemo extends Panel {
build(rootView: Group): void {
2019-11-27 19:15:57 +08:00
let imageView: Image
2019-11-20 15:36:07 +08:00
scroller(vlayout([
text({
text: "Image Demo",
layoutConfig: layoutConfig().w(LayoutSpec.AT_MOST),
textSize: 30,
textColor: Color.WHITE,
2019-11-21 15:49:15 +08:00
bgColor: colors[5],
2019-11-20 15:36:07 +08:00
textAlignment: gravity().center(),
height: 50,
}),
2019-11-21 14:15:43 +08:00
label('Gif'),
image({
imageUrl: "https://misc.aotu.io/ONE-SUNDAY/world-cup_2014_42.gif",
scaleType: ScaleType.ScaleToFill,
loadCallback: function (ret) {
log('this')
log('loadCallback', ret)
}
}),
label('APNG'),
image({
imageUrl: "https://misc.aotu.io/ONE-SUNDAY/world_cup_2014_42.png",
loadCallback: (ret) => {
}
}),
2019-11-22 10:30:01 +08:00
label('Animated WebP'),
image({
imageUrl: "https://p.upyun.com/demo/webp/webp/animated-gif-0.webp",
loadCallback: (ret) => {
}
}),
label('WebP'),
2019-11-27 19:15:57 +08:00
imageView = image({
2019-11-22 10:30:01 +08:00
imageUrl: "https://p.upyun.com/demo/webp/webp/jpg-0.webp",
loadCallback: (ret) => {
2019-11-27 19:15:57 +08:00
if (ret) {
imageView.width = ret.width
imageView.height = ret.height
}
2019-11-22 10:30:01 +08:00
}
}),
2019-11-20 15:36:07 +08:00
label('ScaleToFill'),
image({
imageUrl,
width: 300,
height: 300,
border: {
width: 2,
color: Color.GRAY,
},
scaleType: ScaleType.ScaleToFill,
layoutConfig: layoutConfig().exactly(),
loadCallback: (ret) => {
}
2019-11-20 15:36:07 +08:00
}),
label('ScaleAspectFit'),
image({
imageUrl,
width: 300,
height: 300,
border: {
width: 2,
color: Color.GRAY,
},
scaleType: ScaleType.ScaleAspectFit,
layoutConfig: layoutConfig().exactly(),
}),
label('ScaleAspectFill'),
image({
imageUrl,
width: 300,
height: 300,
border: {
width: 2,
color: Color.GRAY,
},
scaleType: ScaleType.ScaleAspectFill,
layoutConfig: layoutConfig().exactly(),
}),
label('ImageBase64'),
image({
2019-11-26 20:15:16 +08:00
imageBase64: img_base64,
width: 300,
height: 300,
border: {
width: 2,
color: Color.GRAY,
},
scaleType: ScaleType.ScaleAspectFill,
layoutConfig: layoutConfig().exactly(),
}),
2019-11-20 15:36:07 +08:00
]).apply({
layoutConfig: layoutConfig().atmost().h(LayoutSpec.WRAP_CONTENT),
gravity: gravity().center(),
space: 10,
} as IVLayout)).apply({
layoutConfig: layoutConfig().atmost(),
}).in(rootView)
}
}