feat:add network plugin for Android

This commit is contained in:
pengfei.zhou
2019-11-21 19:51:58 +08:00
parent e1372af38a
commit 632e4b98b9
7 changed files with 173 additions and 2 deletions

View File

@@ -8,4 +8,5 @@ export default [
'src/EffectsDemo',
'src/ImageDemo',
'src/ModalDemo',
'src/NetworkDemo',
]

34
demo/src/NetworkDemo.ts Normal file
View File

@@ -0,0 +1,34 @@
import { Group, Panel, List, text, gravity, Color, Stack, LayoutSpec, list, NativeCall, listItem, log, vlayout, Gravity, hlayout, Text, scroller, layoutConfig, image, IView, IVLayout, ScaleType, modal, IText, network } from "doric";
import { title, label, colors } from "./utils";
@Entry
class NetworkDemo extends Panel {
build(rootView: Group): void {
scroller(vlayout([
title("Network Demo"),
label('Click me').apply({
width: 200,
height: 50,
bgColor: colors[0],
textSize: 30,
textColor: Color.WHITE,
layoutConfig: layoutConfig().exactly(),
onClick: () => {
network(context).get('https://doric.pub').then(
e => {
modal(context).toast(JSON.stringify(e))
}
).catch(e => {
modal(context).toast('Catched:' + JSON.stringify(e))
})
}
} as IText),
]).apply({
layoutConfig: layoutConfig().atmost().h(LayoutSpec.WRAP_CONTENT),
gravity: gravity().center(),
space: 10,
} as IVLayout)).apply({
layoutConfig: layoutConfig().atmost(),
}).in(rootView)
}
}

View File

@@ -1,4 +1,4 @@
import { Color, text, Stack, Text } from "doric";
import { Color, text, Stack, Text, layoutConfig, LayoutSpec, gravity } from "doric";
export const colors = [
"#70a1ff",
@@ -33,4 +33,16 @@ export function boxStr(str: string, idx = 0) {
it.textColor = Color.WHITE
it.bgColor = colors[idx || 0]
})
}
export function title(str: string) {
return text({
text: "Network Demo",
layoutConfig: layoutConfig().w(LayoutSpec.AT_MOST),
textSize: 30,
textColor: Color.WHITE,
bgColor: colors[1],
textAlignment: gravity().center(),
height: 50,
})
}