2021-12-07 19:13:42 +08:00
|
|
|
import { Base64Resource, Group, Panel, coordinator, text, gravity, Color, LayoutSpec, log, vlayout, scroller, layoutConfig, image, ScaleType, Image, modal, RemoteResource, MainBundleResource, AndroidAssetsResource, AssetsResource } from "doric";
|
2019-12-04 14:07:14 +08:00
|
|
|
import { colors, label } from "./utils";
|
|
|
|
import { img_base64 } from "./image_base64";
|
2020-04-18 15:59:21 +08:00
|
|
|
|
2019-12-04 14:07:14 +08:00
|
|
|
const imageUrl = 'https://img.zcool.cn/community/01e75b5da933daa801209e1ffa4649.jpg@1280w_1l_2o_100sh.jpg'
|
|
|
|
|
2020-04-18 15:59:21 +08:00
|
|
|
import logo from "./images/logo_w.png"
|
2020-04-23 16:49:19 +08:00
|
|
|
import button from "./images/button.png"
|
2020-04-18 15:59:21 +08:00
|
|
|
|
2019-12-04 14:07:14 +08:00
|
|
|
@Entry
|
|
|
|
class ImageDemo extends Panel {
|
|
|
|
build(rootView: Group): void {
|
|
|
|
let imageView: Image
|
2020-01-06 10:43:18 +08:00
|
|
|
scroller(
|
|
|
|
vlayout(
|
|
|
|
[
|
|
|
|
text({
|
|
|
|
text: "Image Demo",
|
|
|
|
layoutConfig: layoutConfig().configWidth(LayoutSpec.MOST),
|
|
|
|
textSize: 30,
|
|
|
|
textColor: Color.WHITE,
|
|
|
|
backgroundColor: colors[5],
|
|
|
|
textAlignment: gravity().center(),
|
|
|
|
height: 50,
|
|
|
|
}),
|
2021-01-29 10:27:28 +08:00
|
|
|
|
|
|
|
label('Button'),
|
|
|
|
image({
|
2021-10-25 16:01:44 +08:00
|
|
|
image: Environment.platform === 'Android'
|
2021-12-07 18:38:05 +08:00
|
|
|
? new AndroidAssetsResource("assets/The_Parthenon_in_Athens.jpeg")
|
2021-12-07 18:11:15 +08:00
|
|
|
: new MainBundleResource("assets/The_Parthenon_in_Athens.jpeg"),
|
2021-01-29 10:27:28 +08:00
|
|
|
}),
|
2021-12-07 18:38:05 +08:00
|
|
|
image({
|
2021-12-07 19:13:42 +08:00
|
|
|
image: new AssetsResource("The_Parthenon_in_Athens.jpeg"),
|
2021-12-07 18:38:05 +08:00
|
|
|
}),
|
2021-01-29 10:27:28 +08:00
|
|
|
image({
|
2021-10-25 16:01:44 +08:00
|
|
|
image: new RemoteResource("https://p.upyun.com/demo/webp/webp/jpg-0.webp"),
|
2021-01-29 10:27:28 +08:00
|
|
|
}),
|
|
|
|
image({
|
2021-10-25 16:01:44 +08:00
|
|
|
image: new Base64Resource(img_base64[0]),
|
2021-01-29 10:27:28 +08:00
|
|
|
scaleType: ScaleType.ScaleToFill,
|
|
|
|
layoutConfig: {
|
2021-10-25 16:01:44 +08:00
|
|
|
widthSpec: LayoutSpec.FIT,
|
|
|
|
heightSpec: LayoutSpec.FIT,
|
2021-01-29 10:27:28 +08:00
|
|
|
},
|
|
|
|
}),
|
2021-10-25 16:01:44 +08:00
|
|
|
// image({
|
|
|
|
// imageBase64: button,
|
|
|
|
// scaleType: ScaleType.ScaleToFill,
|
|
|
|
// layoutConfig: {
|
|
|
|
// widthSpec: LayoutSpec.JUST,
|
|
|
|
// heightSpec: LayoutSpec.JUST,
|
|
|
|
// },
|
|
|
|
// width: 200,
|
|
|
|
// height: 150 / 2.75,
|
|
|
|
// stretchInset: {
|
|
|
|
// left: 100,
|
|
|
|
// top: 0,
|
|
|
|
// right: 100,
|
|
|
|
// bottom: 0
|
|
|
|
// },
|
|
|
|
// imageScale: 2.75,
|
|
|
|
// }),
|
|
|
|
// image({
|
|
|
|
// imageBase64: button,
|
|
|
|
// scaleType: ScaleType.ScaleToFill,
|
|
|
|
// layoutConfig: {
|
|
|
|
// widthSpec: LayoutSpec.JUST,
|
|
|
|
// heightSpec: LayoutSpec.JUST,
|
|
|
|
// },
|
|
|
|
// width: 200,
|
|
|
|
// height: 75,
|
|
|
|
// stretchInset: {
|
|
|
|
// left: 100,
|
|
|
|
// top: 0,
|
|
|
|
// right: 100,
|
|
|
|
// bottom: 0
|
|
|
|
// },
|
|
|
|
// imageScale: 2,
|
2021-09-23 18:15:55 +08:00
|
|
|
|
2021-10-25 16:01:44 +08:00
|
|
|
// }),
|
|
|
|
// label('Gif '),
|
|
|
|
// image({
|
|
|
|
// imageUrl: "https://www.w3.org/People/mimasa/test/imgformat/img/w3c_home_animation.gif",
|
|
|
|
// scaleType: ScaleType.ScaleToFill,
|
|
|
|
// imageScale: 3,
|
|
|
|
// }),
|
|
|
|
// label('APNG'),
|
|
|
|
// image({
|
|
|
|
// imageUrl: "https://upload.wikimedia.org/wikipedia/commons/1/14/Animated_PNG_example_bouncing_beach_ball.png",
|
|
|
|
// }),
|
|
|
|
// label('Animated WebP'),
|
|
|
|
// image({
|
|
|
|
// imageUrl: "https://p.upyun.com/demo/webp/webp/animated-gif-0.webp",
|
2021-09-23 18:15:55 +08:00
|
|
|
|
2021-10-25 16:01:44 +08:00
|
|
|
// }),
|
|
|
|
// label('WebP'),
|
|
|
|
// imageView = image({
|
|
|
|
// imageUrl: "https://p.upyun.com/demo/webp/webp/jpg-0.webp",
|
|
|
|
// layoutConfig: layoutConfig().just(),
|
|
|
|
// width: 200,
|
|
|
|
// height: 200,
|
|
|
|
// loadCallback: (ret) => {
|
|
|
|
// if (ret) {
|
|
|
|
// imageView.width = ret.width
|
|
|
|
// imageView.height = ret.height
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }),
|
|
|
|
// label('ScaleToFill'),
|
|
|
|
// image({
|
|
|
|
// imageUrl,
|
|
|
|
// width: 300,
|
|
|
|
// height: 300,
|
|
|
|
// isBlur: true,
|
|
|
|
// border: {
|
|
|
|
// width: 2,
|
|
|
|
// color: Color.GRAY,
|
|
|
|
// },
|
|
|
|
// scaleType: ScaleType.ScaleToFill,
|
|
|
|
// layoutConfig: layoutConfig().just(),
|
|
|
|
// loadCallback: (ret) => {
|
|
|
|
// }
|
|
|
|
// }),
|
|
|
|
// label('ScaleAspectFit'),
|
|
|
|
// image({
|
|
|
|
// imageUrl,
|
|
|
|
// width: 300,
|
|
|
|
// height: 300,
|
|
|
|
// border: {
|
|
|
|
// width: 2,
|
|
|
|
// color: Color.GRAY,
|
|
|
|
// },
|
|
|
|
// scaleType: ScaleType.ScaleAspectFit,
|
|
|
|
// layoutConfig: layoutConfig().just(),
|
|
|
|
// }),
|
|
|
|
// label('ScaleAspectFill'),
|
|
|
|
// image({
|
|
|
|
// imageUrl,
|
|
|
|
// width: 300,
|
|
|
|
// height: 300,
|
|
|
|
// border: {
|
|
|
|
// width: 2,
|
|
|
|
// color: Color.GRAY,
|
|
|
|
// },
|
|
|
|
// scaleType: ScaleType.ScaleAspectFill,
|
|
|
|
// layoutConfig: layoutConfig().just(),
|
|
|
|
// }),
|
|
|
|
// label('ImageBase64'),
|
|
|
|
// image({
|
|
|
|
// imageBase64: img_base64[0],
|
|
|
|
// width: 300,
|
|
|
|
// height: 300,
|
|
|
|
// border: {
|
|
|
|
// width: 2,
|
|
|
|
// color: Color.GRAY,
|
|
|
|
// },
|
|
|
|
// scaleType: ScaleType.ScaleAspectFill,
|
|
|
|
// layoutConfig: layoutConfig().just(),
|
|
|
|
// }),
|
|
|
|
// label('StretchInset'),
|
|
|
|
// image({
|
|
|
|
// imageBase64: img_base64[1],
|
|
|
|
// height: 60,
|
|
|
|
// width: 134,
|
|
|
|
// scaleType: ScaleType.ScaleAspectFill,
|
|
|
|
// layoutConfig: layoutConfig().just(),
|
|
|
|
// }),
|
|
|
|
// image({
|
|
|
|
// imageBase64: img_base64[1],
|
|
|
|
// height: 60,
|
|
|
|
// width: 294,
|
|
|
|
// scaleType: ScaleType.ScaleToFill,
|
|
|
|
// layoutConfig: layoutConfig().just(),
|
|
|
|
// stretchInset: {
|
|
|
|
// left: 0.85,
|
|
|
|
// top: 0,
|
|
|
|
// right: 0.149,
|
|
|
|
// bottom: 0
|
|
|
|
// }
|
|
|
|
// }),
|
2020-01-06 10:43:18 +08:00
|
|
|
],
|
|
|
|
{
|
|
|
|
layoutConfig: layoutConfig().most().configHeight(LayoutSpec.FIT),
|
|
|
|
gravity: gravity().center(),
|
|
|
|
space: 10,
|
|
|
|
}),
|
|
|
|
{
|
|
|
|
layoutConfig: layoutConfig().most(),
|
|
|
|
}
|
2020-02-13 22:18:13 +08:00
|
|
|
).also(it => {
|
|
|
|
coordinator(context).verticalScrolling({
|
|
|
|
scrollable: it,
|
|
|
|
scrollRange: {
|
|
|
|
start: 0,
|
|
|
|
end: 100,
|
|
|
|
},
|
|
|
|
target: "NavBar",
|
|
|
|
changing: {
|
|
|
|
name: "backgroundColor",
|
|
|
|
start: Color.WHITE,
|
|
|
|
end: Color.RED,
|
|
|
|
}
|
|
|
|
})
|
2020-03-10 19:18:33 +08:00
|
|
|
coordinator(context).verticalScrolling({
|
|
|
|
scrollable: it,
|
|
|
|
scrollRange: {
|
|
|
|
start: 0,
|
|
|
|
end: 100,
|
|
|
|
},
|
|
|
|
target: imageView,
|
|
|
|
changing: {
|
|
|
|
name: "width",
|
|
|
|
start: 10,
|
|
|
|
end: 200,
|
|
|
|
}
|
|
|
|
})
|
2020-02-13 22:18:13 +08:00
|
|
|
}).in(rootView)
|
2019-12-04 14:07:14 +08:00
|
|
|
}
|
2020-04-23 17:42:32 +08:00
|
|
|
onDestroy() {
|
|
|
|
modal(context).toast('onDestroy')
|
|
|
|
}
|
2021-01-29 10:27:28 +08:00
|
|
|
}
|