Add resource system for doric,start with android

This commit is contained in:
pengfei.zhou
2021-10-20 18:57:17 +08:00
committed by osborn
parent 7637a820e5
commit 5501dd38d9
26 changed files with 880 additions and 23 deletions

View File

@@ -139,7 +139,7 @@ function logw() {
nativeLog('w', out);
}
var __extends$h = (undefined && undefined.__extends) || (function () {
var __extends$i = (undefined && undefined.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
@@ -571,7 +571,7 @@ var View = /** @class */ (function () {
return View;
}());
var Superview = /** @class */ (function (_super) {
__extends$h(Superview, _super);
__extends$i(Superview, _super);
function Superview() {
return _super !== null && _super.apply(this, arguments) || this;
}
@@ -687,7 +687,7 @@ var Superview = /** @class */ (function (_super) {
return Superview;
}(View));
var Group = /** @class */ (function (_super) {
__extends$h(Group, _super);
__extends$i(Group, _super);
function Group() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.children = [];
@@ -905,7 +905,7 @@ function layoutConfig() {
return new LayoutConfigImpl;
}
var __extends$g = (undefined && undefined.__extends) || (function () {
var __extends$h = (undefined && undefined.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
@@ -941,21 +941,21 @@ var __values$4 = (undefined && undefined.__values) || function(o) {
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
var Stack = /** @class */ (function (_super) {
__extends$g(Stack, _super);
__extends$h(Stack, _super);
function Stack() {
return _super !== null && _super.apply(this, arguments) || this;
}
return Stack;
}(Group));
var Root = /** @class */ (function (_super) {
__extends$g(Root, _super);
__extends$h(Root, _super);
function Root() {
return _super !== null && _super.apply(this, arguments) || this;
}
return Root;
}(Stack));
var LinearLayout = /** @class */ (function (_super) {
__extends$g(LinearLayout, _super);
__extends$h(LinearLayout, _super);
function LinearLayout() {
return _super !== null && _super.apply(this, arguments) || this;
}
@@ -970,14 +970,14 @@ var LinearLayout = /** @class */ (function (_super) {
return LinearLayout;
}(Group));
var VLayout = /** @class */ (function (_super) {
__extends$g(VLayout, _super);
__extends$h(VLayout, _super);
function VLayout() {
return _super !== null && _super.apply(this, arguments) || this;
}
return VLayout;
}(LinearLayout));
var HLayout = /** @class */ (function (_super) {
__extends$g(HLayout, _super);
__extends$h(HLayout, _super);
function HLayout() {
return _super !== null && _super.apply(this, arguments) || this;
}
@@ -1050,7 +1050,7 @@ function vlayout(views, config) {
return ret;
}
var FlexLayout = /** @class */ (function (_super) {
__extends$g(FlexLayout, _super);
__extends$h(FlexLayout, _super);
function FlexLayout() {
return _super !== null && _super.apply(this, arguments) || this;
}
@@ -1499,7 +1499,7 @@ exports.GradientOrientation = void 0;
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var __extends$f = (undefined && undefined.__extends) || (function () {
var __extends$g = (undefined && undefined.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
@@ -1615,7 +1615,7 @@ var Animation = /** @class */ (function () {
return Animation;
}());
var ScaleAnimation = /** @class */ (function (_super) {
__extends$f(ScaleAnimation, _super);
__extends$g(ScaleAnimation, _super);
function ScaleAnimation() {
var _this = _super.call(this) || this;
_this.scaleXChangeable = {
@@ -1689,7 +1689,7 @@ var ScaleAnimation = /** @class */ (function (_super) {
return ScaleAnimation;
}(Animation));
var TranslationAnimation = /** @class */ (function (_super) {
__extends$f(TranslationAnimation, _super);
__extends$g(TranslationAnimation, _super);
function TranslationAnimation() {
var _this = _super.call(this) || this;
_this.translationXChangeable = {
@@ -1766,7 +1766,7 @@ var TranslationAnimation = /** @class */ (function (_super) {
* Rotation range is [0..2]
*/
var RotationAnimation = /** @class */ (function (_super) {
__extends$f(RotationAnimation, _super);
__extends$g(RotationAnimation, _super);
function RotationAnimation() {
var _this = _super.call(this) || this;
_this.rotationChaneable = {
@@ -1810,7 +1810,7 @@ var RotationAnimation = /** @class */ (function (_super) {
* Rotation range is [0..2]
*/
var RotationXAnimation = /** @class */ (function (_super) {
__extends$f(RotationXAnimation, _super);
__extends$g(RotationXAnimation, _super);
function RotationXAnimation() {
var _this = _super.call(this) || this;
_this.rotationChaneable = {
@@ -1854,7 +1854,7 @@ var RotationXAnimation = /** @class */ (function (_super) {
* Rotation range is [0..2]
*/
var RotationYAnimation = /** @class */ (function (_super) {
__extends$f(RotationYAnimation, _super);
__extends$g(RotationYAnimation, _super);
function RotationYAnimation() {
var _this = _super.call(this) || this;
_this.rotationChaneable = {
@@ -1895,7 +1895,7 @@ var RotationYAnimation = /** @class */ (function (_super) {
return RotationYAnimation;
}(Animation));
var BackgroundColorAnimation = /** @class */ (function (_super) {
__extends$f(BackgroundColorAnimation, _super);
__extends$g(BackgroundColorAnimation, _super);
function BackgroundColorAnimation() {
var _this = _super.call(this) || this;
_this.backgroundColorChangeable = {
@@ -1939,7 +1939,7 @@ var BackgroundColorAnimation = /** @class */ (function (_super) {
* Alpha range is [0..1]
*/
var AlphaAnimation = /** @class */ (function (_super) {
__extends$f(AlphaAnimation, _super);
__extends$g(AlphaAnimation, _super);
function AlphaAnimation() {
var _this = _super.call(this) || this;
_this.opacityChangeable = {
@@ -2011,7 +2011,7 @@ var AnimationSet = /** @class */ (function () {
return AnimationSet;
}());
var __extends$e = (undefined && undefined.__extends) || (function () {
var __extends$f = (undefined && undefined.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
@@ -2043,7 +2043,7 @@ exports.TruncateAt = void 0;
TruncateAt[TruncateAt["Clip"] = 3] = "Clip";
})(exports.TruncateAt || (exports.TruncateAt = {}));
var Text = /** @class */ (function (_super) {
__extends$e(Text, _super);
__extends$f(Text, _super);
function Text() {
return _super !== null && _super.apply(this, arguments) || this;
}
@@ -2119,6 +2119,76 @@ function text(config) {
return ret;
}
var __extends$e = (undefined && undefined.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) { if (Object.prototype.hasOwnProperty.call(b, p)) { d[p] = b[p]; } } };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
{ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); }
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var Resource = /** @class */ (function () {
function Resource(type, identifier) {
this.type = type;
this.identifier = identifier;
}
Resource.prototype.toModel = function () {
return {
type: this.type,
identifier: this.identifier,
};
};
return Resource;
}());
/** @class */ ((function (_super) {
__extends$e(FileResource, _super);
function FileResource(path) {
return _super.call(this, "file", path) || this;
}
return FileResource;
})(Resource));
/** @class */ ((function (_super) {
__extends$e(RemoteResource, _super);
function RemoteResource(url) {
return _super.call(this, "remote", url) || this;
}
return RemoteResource;
})(Resource));
/**
* This is for android platform
*/
/** @class */ ((function (_super) {
__extends$e(DrawableResource, _super);
function DrawableResource(url) {
return _super.call(this, "drawable", url) || this;
}
return DrawableResource;
})(Resource));
/** @class */ ((function (_super) {
__extends$e(AssetResource, _super);
function AssetResource(path) {
return _super.call(this, "assets", path) || this;
}
return AssetResource;
})(Resource));
/**
* This is for iOS platform
*/
/** @class */ ((function (_super) {
__extends$e(MainBundleResource, _super);
function MainBundleResource(path) {
return _super.call(this, "mainBundle", path) || this;
}
return MainBundleResource;
})(Resource));
var __extends$d = (undefined && undefined.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
@@ -2163,6 +2233,10 @@ var Image = /** @class */ (function (_super) {
Image.prototype.stopAnimating = function (context) {
return this.nativeChannel(context, "stopAnimating")();
};
__decorate$a([
Property,
__metadata$a("design:type", Resource)
], Image.prototype, "image", void 0);
__decorate$a([
Property,
__metadata$a("design:type", String)

View File

@@ -1603,6 +1603,19 @@ function text(config) {
return ret;
}
class Resource {
constructor(type, identifier) {
this.type = type;
this.identifier = identifier;
}
toModel() {
return {
type: this.type,
identifier: this.identifier,
};
}
}
var __decorate$a = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -1629,6 +1642,10 @@ class Image extends View {
return this.nativeChannel(context, "stopAnimating")();
}
}
__decorate$a([
Property,
__metadata$a("design:type", Resource)
], Image.prototype, "image", void 0);
__decorate$a([
Property,
__metadata$a("design:type", String)

View File

@@ -3124,6 +3124,19 @@ function text(config) {
return ret;
}
class Resource {
constructor(type, identifier) {
this.type = type;
this.identifier = identifier;
}
toModel() {
return {
type: this.type,
identifier: this.identifier,
};
}
}
var __decorate$a = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -3150,6 +3163,10 @@ class Image extends View {
return this.nativeChannel(context, "stopAnimating")();
}
}
__decorate$a([
Property,
__metadata$a("design:type", Resource)
], Image.prototype, "image", void 0);
__decorate$a([
Property,
__metadata$a("design:type", String)

39
doric-js/index.d.ts vendored
View File

@@ -612,12 +612,17 @@ declare module 'doric/lib/src/widget/image' {
import { View } from "doric/lib/src/ui/view";
import { Color } from "doric/lib/src/util/color";
import { BridgeContext } from "doric/lib/src/runtime/global";
import { Resource } from "doric/lib/src/util/resource";
export enum ScaleType {
ScaleToFill = 0,
ScaleAspectFit = 1,
ScaleAspectFill = 2
}
export class Image extends View {
/**
* This could be loaded by customized resource loader
*/
image?: Resource;
imageUrl?: string;
/**
* Read image from local file system.
@@ -1761,6 +1766,40 @@ declare module 'doric/lib/src/pattern/modular' {
}
}
declare module 'doric/lib/src/util/resource' {
import { Modeling } from "doric/lib/src/util/types";
export abstract class Resource implements Modeling {
type: string;
identifier: string;
constructor(type: string, identifier: string);
toModel(): {
type: string;
identifier: string;
};
}
export class FileResource extends Resource {
constructor(path: string);
}
export class RemoteResource extends Resource {
constructor(url: string);
}
/**
* This is for android platform
*/
export class DrawableResource extends Resource {
constructor(url: string);
}
export class AssetResource extends Resource {
constructor(path: string);
}
/**
* This is for iOS platform
*/
export class MainBundleResource extends Resource {
constructor(path: string);
}
}
declare module '*.png' {
const value: any;
export default value;

31
doric-js/lib/src/util/resource.d.ts vendored Normal file
View File

@@ -0,0 +1,31 @@
import { Modeling } from "./types";
export declare abstract class Resource implements Modeling {
type: string;
identifier: string;
constructor(type: string, identifier: string);
toModel(): {
type: string;
identifier: string;
};
}
export declare class FileResource extends Resource {
constructor(path: string);
}
export declare class RemoteResource extends Resource {
constructor(url: string);
}
/**
* This is for android platform
*/
export declare class DrawableResource extends Resource {
constructor(url: string);
}
export declare class AssetResource extends Resource {
constructor(path: string);
}
/**
* This is for iOS platform
*/
export declare class MainBundleResource extends Resource {
constructor(path: string);
}

View File

@@ -0,0 +1,43 @@
export class Resource {
constructor(type, identifier) {
this.type = type;
this.identifier = identifier;
}
toModel() {
return {
type: this.type,
identifier: this.identifier,
};
}
}
export class FileResource extends Resource {
constructor(path) {
super("file", path);
}
}
export class RemoteResource extends Resource {
constructor(url) {
super("remote", url);
}
}
/**
* This is for android platform
*/
export class DrawableResource extends Resource {
constructor(url) {
super("drawable", url);
}
}
export class AssetResource extends Resource {
constructor(path) {
super("assets", path);
}
}
/**
* This is for iOS platform
*/
export class MainBundleResource extends Resource {
constructor(path) {
super("mainBundle", path);
}
}

View File

@@ -1,12 +1,17 @@
import { View } from "../ui/view";
import { Color } from "../util/color";
import { BridgeContext } from "../runtime/global";
import { Resource } from "../util/resource";
export declare enum ScaleType {
ScaleToFill = 0,
ScaleAspectFit = 1,
ScaleAspectFill = 2
}
export declare class Image extends View {
/**
* This could be loaded by customized resource loader
*/
image?: Resource;
imageUrl?: string;
/**
* Read image from local file system.

View File

@@ -25,6 +25,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
import { View, Property } from "../ui/view";
import { layoutConfig } from "../util/layoutconfig";
import { Color } from "../util/color";
import { Resource } from "../util/resource";
export var ScaleType;
(function (ScaleType) {
ScaleType[ScaleType["ScaleToFill"] = 0] = "ScaleToFill";
@@ -42,6 +43,10 @@ export class Image extends View {
return this.nativeChannel(context, "stopAnimating")();
}
}
__decorate([
Property,
__metadata("design:type", Resource)
], Image.prototype, "image", void 0);
__decorate([
Property,
__metadata("design:type", String)

View 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)
}
}

View File

@@ -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.
*/