Add resource system for doric,start with android
This commit is contained in:
57
doric-js/src/util/resource.ts
Normal file
57
doric-js/src/util/resource.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
import { Modeling } from "./types";
|
||||
|
||||
export abstract class Resource implements Modeling {
|
||||
type: string;
|
||||
identifier: string;
|
||||
constructor(type: string, identifier: string) {
|
||||
this.type = type;
|
||||
this.identifier = identifier;
|
||||
}
|
||||
toModel() {
|
||||
return {
|
||||
type: this.type,
|
||||
identifier: this.identifier,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class FileResource extends Resource {
|
||||
constructor(path: string) {
|
||||
super("file", path);
|
||||
}
|
||||
}
|
||||
|
||||
export class RemoteResource extends Resource {
|
||||
constructor(url: string) {
|
||||
super("remote", url)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This is for android platform
|
||||
*/
|
||||
export class DrawableResource extends Resource {
|
||||
constructor(url: string) {
|
||||
super("drawable", url)
|
||||
}
|
||||
}
|
||||
export class RawResource extends Resource {
|
||||
constructor(url: string) {
|
||||
super("raw", url)
|
||||
}
|
||||
}
|
||||
|
||||
export class AssetResource extends Resource {
|
||||
constructor(path: string) {
|
||||
super("assets", path)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This is for iOS platform
|
||||
*/
|
||||
export class MainBundleResource extends Resource {
|
||||
constructor(path: string) {
|
||||
super("mainBundle", path)
|
||||
}
|
||||
}
|
@@ -17,6 +17,7 @@ import { View, Property } from "../ui/view"
|
||||
import { layoutConfig } from "../util/layoutconfig"
|
||||
import { Color } from "../util/color"
|
||||
import { BridgeContext } from "../runtime/global"
|
||||
import { Resource } from "../util/resource"
|
||||
|
||||
export enum ScaleType {
|
||||
ScaleToFill = 0,
|
||||
@@ -25,9 +26,14 @@ export enum ScaleType {
|
||||
}
|
||||
|
||||
export class Image extends View {
|
||||
/**
|
||||
* This could be loaded by customized resource loader
|
||||
*/
|
||||
@Property
|
||||
image?: Resource
|
||||
|
||||
@Property
|
||||
imageUrl?: string
|
||||
|
||||
/**
|
||||
* Read image from local file system.
|
||||
*/
|
||||
|
Reference in New Issue
Block a user