feat:add network plugin for Android
This commit is contained in:
		
							
								
								
									
										34
									
								
								demo/src/NetworkDemo.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								demo/src/NetworkDemo.ts
									
									
									
									
									
										Normal 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) | ||||
|     } | ||||
| } | ||||
| @@ -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, | ||||
|     }) | ||||
| } | ||||
		Reference in New Issue
	
	Block a user