update typescript and remove reflect-metadata lib
This commit is contained in:
@@ -33,228 +33,232 @@ export function NativeCall(target, propertyKey, descriptor) {
|
||||
};
|
||||
return descriptor;
|
||||
}
|
||||
export class Panel {
|
||||
constructor() {
|
||||
this.destroyed = false;
|
||||
this.__root__ = new Root;
|
||||
this.headviews = new Map;
|
||||
this.onRenderFinishedCallback = [];
|
||||
this.__rendering__ = false;
|
||||
}
|
||||
onCreate() { }
|
||||
onDestroy() { }
|
||||
onShow() { }
|
||||
onHidden() { }
|
||||
addHeadView(type, v) {
|
||||
let map = this.headviews.get(type);
|
||||
if (map) {
|
||||
map.set(v.viewId, v);
|
||||
let Panel = /** @class */ (() => {
|
||||
class Panel {
|
||||
constructor() {
|
||||
this.destroyed = false;
|
||||
this.__root__ = new Root;
|
||||
this.headviews = new Map;
|
||||
this.onRenderFinishedCallback = [];
|
||||
this.__rendering__ = false;
|
||||
}
|
||||
else {
|
||||
map = new Map;
|
||||
map.set(v.viewId, v);
|
||||
this.headviews.set(type, map);
|
||||
}
|
||||
}
|
||||
allHeadViews() {
|
||||
return this.headviews.values();
|
||||
}
|
||||
removeHeadView(type, v) {
|
||||
if (this.headviews.has(type)) {
|
||||
onCreate() { }
|
||||
onDestroy() { }
|
||||
onShow() { }
|
||||
onHidden() { }
|
||||
addHeadView(type, v) {
|
||||
let map = this.headviews.get(type);
|
||||
if (map) {
|
||||
if (v instanceof View) {
|
||||
map.delete(v.viewId);
|
||||
}
|
||||
else {
|
||||
map.delete(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
clearHeadViews(type) {
|
||||
if (this.headviews.has(type)) {
|
||||
this.headviews.delete(type);
|
||||
}
|
||||
}
|
||||
getRootView() {
|
||||
return this.__root__;
|
||||
}
|
||||
getInitData() {
|
||||
return this.__data__;
|
||||
}
|
||||
__init__(data) {
|
||||
if (data) {
|
||||
this.__data__ = JSON.parse(data);
|
||||
}
|
||||
}
|
||||
__onCreate__() {
|
||||
this.onCreate();
|
||||
}
|
||||
__onDestroy__() {
|
||||
this.destroyed = true;
|
||||
this.onDestroy();
|
||||
}
|
||||
__onShow__() {
|
||||
this.onShow();
|
||||
}
|
||||
__onHidden__() {
|
||||
this.onHidden();
|
||||
}
|
||||
__build__(frame) {
|
||||
this.__root__.width = frame.width;
|
||||
this.__root__.height = frame.height;
|
||||
this.__root__.children.length = 0;
|
||||
this.build(this.__root__);
|
||||
}
|
||||
__response__(viewIds, callbackId) {
|
||||
const v = this.retrospectView(viewIds);
|
||||
if (v === undefined) {
|
||||
loge(`Cannot find view for ${viewIds}`);
|
||||
}
|
||||
else {
|
||||
const argumentsList = [callbackId];
|
||||
for (let i = 2; i < arguments.length; i++) {
|
||||
argumentsList.push(arguments[i]);
|
||||
}
|
||||
return Reflect.apply(v.responseCallback, v, argumentsList);
|
||||
}
|
||||
}
|
||||
retrospectView(ids) {
|
||||
return ids.reduce((acc, cur) => {
|
||||
if (acc === undefined) {
|
||||
if (cur === this.__root__.viewId) {
|
||||
return this.__root__;
|
||||
}
|
||||
for (let map of this.headviews.values()) {
|
||||
if (map.has(cur)) {
|
||||
return map.get(cur);
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
map.set(v.viewId, v);
|
||||
}
|
||||
else {
|
||||
if (Reflect.has(acc, "subviewById")) {
|
||||
return Reflect.apply(Reflect.get(acc, "subviewById"), acc, [cur]);
|
||||
}
|
||||
return acc;
|
||||
}
|
||||
}, undefined);
|
||||
}
|
||||
nativeRender(model) {
|
||||
return this.context.callNative("shader", "render", model);
|
||||
}
|
||||
hookBeforeNativeCall() {
|
||||
if (Environment.platform !== 'web') {
|
||||
this.__root__.clean();
|
||||
for (let map of this.headviews.values()) {
|
||||
for (let v of map.values()) {
|
||||
v.clean();
|
||||
}
|
||||
map = new Map;
|
||||
map.set(v.viewId, v);
|
||||
this.headviews.set(type, map);
|
||||
}
|
||||
}
|
||||
}
|
||||
hookAfterNativeCall() {
|
||||
if (this.destroyed) {
|
||||
return;
|
||||
allHeadViews() {
|
||||
return this.headviews.values();
|
||||
}
|
||||
const promises = [];
|
||||
if (Environment.platform !== 'web') {
|
||||
//Here insert a native call to ensure the promise is resolved done.
|
||||
nativeEmpty();
|
||||
if (this.__root__.isDirty()) {
|
||||
const model = this.__root__.toModel();
|
||||
promises.push(this.nativeRender(model));
|
||||
}
|
||||
for (let map of this.headviews.values()) {
|
||||
for (let v of map.values()) {
|
||||
if (v.isDirty()) {
|
||||
const model = v.toModel();
|
||||
promises.push(this.nativeRender(model));
|
||||
removeHeadView(type, v) {
|
||||
if (this.headviews.has(type)) {
|
||||
let map = this.headviews.get(type);
|
||||
if (map) {
|
||||
if (v instanceof View) {
|
||||
map.delete(v.viewId);
|
||||
}
|
||||
else {
|
||||
map.delete(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
Promise.resolve().then(() => {
|
||||
clearHeadViews(type) {
|
||||
if (this.headviews.has(type)) {
|
||||
this.headviews.delete(type);
|
||||
}
|
||||
}
|
||||
getRootView() {
|
||||
return this.__root__;
|
||||
}
|
||||
getInitData() {
|
||||
return this.__data__;
|
||||
}
|
||||
__init__(data) {
|
||||
if (data) {
|
||||
this.__data__ = JSON.parse(data);
|
||||
}
|
||||
}
|
||||
__onCreate__() {
|
||||
this.onCreate();
|
||||
}
|
||||
__onDestroy__() {
|
||||
this.destroyed = true;
|
||||
this.onDestroy();
|
||||
}
|
||||
__onShow__() {
|
||||
this.onShow();
|
||||
}
|
||||
__onHidden__() {
|
||||
this.onHidden();
|
||||
}
|
||||
__build__(frame) {
|
||||
this.__root__.width = frame.width;
|
||||
this.__root__.height = frame.height;
|
||||
this.__root__.children.length = 0;
|
||||
this.build(this.__root__);
|
||||
}
|
||||
__response__(viewIds, callbackId) {
|
||||
const v = this.retrospectView(viewIds);
|
||||
if (v === undefined) {
|
||||
loge(`Cannot find view for ${viewIds}`);
|
||||
}
|
||||
else {
|
||||
const argumentsList = [callbackId];
|
||||
for (let i = 2; i < arguments.length; i++) {
|
||||
argumentsList.push(arguments[i]);
|
||||
}
|
||||
return Reflect.apply(v.responseCallback, v, argumentsList);
|
||||
}
|
||||
}
|
||||
retrospectView(ids) {
|
||||
return ids.reduce((acc, cur) => {
|
||||
if (acc === undefined) {
|
||||
if (cur === this.__root__.viewId) {
|
||||
return this.__root__;
|
||||
}
|
||||
for (let map of this.headviews.values()) {
|
||||
if (map.has(cur)) {
|
||||
return map.get(cur);
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
else {
|
||||
if (Reflect.has(acc, "subviewById")) {
|
||||
return Reflect.apply(Reflect.get(acc, "subviewById"), acc, [cur]);
|
||||
}
|
||||
return acc;
|
||||
}
|
||||
}, undefined);
|
||||
}
|
||||
nativeRender(model) {
|
||||
return this.context.callNative("shader", "render", model);
|
||||
}
|
||||
hookBeforeNativeCall() {
|
||||
if (Environment.platform !== 'web') {
|
||||
this.__root__.clean();
|
||||
for (let map of this.headviews.values()) {
|
||||
for (let v of map.values()) {
|
||||
v.clean();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
hookAfterNativeCall() {
|
||||
if (this.destroyed) {
|
||||
return;
|
||||
}
|
||||
const promises = [];
|
||||
if (Environment.platform !== 'web') {
|
||||
//Here insert a native call to ensure the promise is resolved done.
|
||||
nativeEmpty();
|
||||
if (this.__root__.isDirty()) {
|
||||
const model = this.__root__.toModel();
|
||||
promises.push(this.nativeRender(model));
|
||||
this.__root__.clean();
|
||||
}
|
||||
for (let map of this.headviews.values()) {
|
||||
for (let v of map.values()) {
|
||||
if (v.isDirty()) {
|
||||
const model = v.toModel();
|
||||
promises.push(this.nativeRender(model));
|
||||
v.clean();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
Promise.resolve().then(() => {
|
||||
if (this.__root__.isDirty()) {
|
||||
const model = this.__root__.toModel();
|
||||
promises.push(this.nativeRender(model));
|
||||
this.__root__.clean();
|
||||
}
|
||||
for (let map of this.headviews.values()) {
|
||||
for (let v of map.values()) {
|
||||
if (v.isDirty()) {
|
||||
const model = v.toModel();
|
||||
promises.push(this.nativeRender(model));
|
||||
v.clean();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
if (this.__rendering__) {
|
||||
//skip
|
||||
Promise.all(promises).then(_ => {
|
||||
});
|
||||
}
|
||||
else {
|
||||
this.__rendering__ = true;
|
||||
Promise.all(promises).then(_ => {
|
||||
this.__rendering__ = false;
|
||||
this.onRenderFinished();
|
||||
});
|
||||
}
|
||||
}
|
||||
if (this.__rendering__) {
|
||||
//skip
|
||||
Promise.all(promises).then(_ => {
|
||||
onRenderFinished() {
|
||||
this.onRenderFinishedCallback.forEach(e => {
|
||||
e();
|
||||
});
|
||||
this.onRenderFinishedCallback.length = 0;
|
||||
}
|
||||
else {
|
||||
this.__rendering__ = true;
|
||||
Promise.all(promises).then(_ => {
|
||||
this.__rendering__ = false;
|
||||
this.onRenderFinished();
|
||||
});
|
||||
addOnRenderFinishedCallback(cb) {
|
||||
this.onRenderFinishedCallback.push(cb);
|
||||
}
|
||||
}
|
||||
onRenderFinished() {
|
||||
this.onRenderFinishedCallback.forEach(e => {
|
||||
e();
|
||||
});
|
||||
this.onRenderFinishedCallback.length = 0;
|
||||
}
|
||||
addOnRenderFinishedCallback(cb) {
|
||||
this.onRenderFinishedCallback.push(cb);
|
||||
}
|
||||
}
|
||||
__decorate([
|
||||
NativeCall,
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [String]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], Panel.prototype, "__init__", null);
|
||||
__decorate([
|
||||
NativeCall,
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", []),
|
||||
__metadata("design:returntype", void 0)
|
||||
], Panel.prototype, "__onCreate__", null);
|
||||
__decorate([
|
||||
NativeCall,
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", []),
|
||||
__metadata("design:returntype", void 0)
|
||||
], Panel.prototype, "__onDestroy__", null);
|
||||
__decorate([
|
||||
NativeCall,
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", []),
|
||||
__metadata("design:returntype", void 0)
|
||||
], Panel.prototype, "__onShow__", null);
|
||||
__decorate([
|
||||
NativeCall,
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", []),
|
||||
__metadata("design:returntype", void 0)
|
||||
], Panel.prototype, "__onHidden__", null);
|
||||
__decorate([
|
||||
NativeCall,
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], Panel.prototype, "__build__", null);
|
||||
__decorate([
|
||||
NativeCall,
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Array, String]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], Panel.prototype, "__response__", null);
|
||||
__decorate([
|
||||
NativeCall,
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [String]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], Panel.prototype, "__init__", null);
|
||||
__decorate([
|
||||
NativeCall,
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", []),
|
||||
__metadata("design:returntype", void 0)
|
||||
], Panel.prototype, "__onCreate__", null);
|
||||
__decorate([
|
||||
NativeCall,
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", []),
|
||||
__metadata("design:returntype", void 0)
|
||||
], Panel.prototype, "__onDestroy__", null);
|
||||
__decorate([
|
||||
NativeCall,
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", []),
|
||||
__metadata("design:returntype", void 0)
|
||||
], Panel.prototype, "__onShow__", null);
|
||||
__decorate([
|
||||
NativeCall,
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", []),
|
||||
__metadata("design:returntype", void 0)
|
||||
], Panel.prototype, "__onHidden__", null);
|
||||
__decorate([
|
||||
NativeCall,
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Object]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], Panel.prototype, "__build__", null);
|
||||
__decorate([
|
||||
NativeCall,
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Array, String]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], Panel.prototype, "__response__", null);
|
||||
return Panel;
|
||||
})();
|
||||
export { Panel };
|
||||
|
||||
@@ -13,263 +13,267 @@ import { loge } from "../util/log";
|
||||
export function Property(target, propKey) {
|
||||
Reflect.defineMetadata(propKey, true, target);
|
||||
}
|
||||
export class View {
|
||||
constructor() {
|
||||
this.width = 0;
|
||||
this.height = 0;
|
||||
this.x = 0;
|
||||
this.y = 0;
|
||||
this.viewId = uniqueId('ViewId');
|
||||
this.callbacks = new Map;
|
||||
/** Anchor end*/
|
||||
this.__dirty_props__ = {};
|
||||
this.nativeViewModel = {
|
||||
id: this.viewId,
|
||||
type: this.constructor.name,
|
||||
props: this.__dirty_props__,
|
||||
};
|
||||
return new Proxy(this, {
|
||||
get: (target, p, receiver) => {
|
||||
return Reflect.get(target, p, receiver);
|
||||
},
|
||||
set: (target, p, v, receiver) => {
|
||||
const oldV = Reflect.get(target, p, receiver);
|
||||
const ret = Reflect.set(target, p, v, receiver);
|
||||
if (Reflect.getMetadata(p, target) && oldV !== v) {
|
||||
receiver.onPropertyChanged(p.toString(), oldV, v);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
});
|
||||
}
|
||||
callback2Id(f) {
|
||||
const id = uniqueId('Function');
|
||||
this.callbacks.set(id, f);
|
||||
return id;
|
||||
}
|
||||
id2Callback(id) {
|
||||
let f = this.callbacks.get(id);
|
||||
if (f === undefined) {
|
||||
f = Reflect.get(this, id);
|
||||
}
|
||||
return f;
|
||||
}
|
||||
/** Anchor start*/
|
||||
get left() {
|
||||
return this.x;
|
||||
}
|
||||
set left(v) {
|
||||
this.x = v;
|
||||
}
|
||||
get right() {
|
||||
return this.x + this.width;
|
||||
}
|
||||
set right(v) {
|
||||
this.x = v - this.width;
|
||||
}
|
||||
get top() {
|
||||
return this.y;
|
||||
}
|
||||
set top(v) {
|
||||
this.y = v;
|
||||
}
|
||||
get bottom() {
|
||||
return this.y + this.height;
|
||||
}
|
||||
set bottom(v) {
|
||||
this.y = v - this.height;
|
||||
}
|
||||
get centerX() {
|
||||
return this.x + this.width / 2;
|
||||
}
|
||||
get centerY() {
|
||||
return this.y + this.height / 2;
|
||||
}
|
||||
set centerX(v) {
|
||||
this.x = v - this.width / 2;
|
||||
}
|
||||
set centerY(v) {
|
||||
this.y = v - this.height / 2;
|
||||
}
|
||||
get dirtyProps() {
|
||||
return this.__dirty_props__;
|
||||
}
|
||||
onPropertyChanged(propKey, oldV, newV) {
|
||||
if (newV instanceof Function) {
|
||||
newV = this.callback2Id(newV);
|
||||
}
|
||||
else {
|
||||
newV = obj2Model(newV);
|
||||
}
|
||||
this.__dirty_props__[propKey] = newV;
|
||||
}
|
||||
clean() {
|
||||
for (const key in this.__dirty_props__) {
|
||||
if (Reflect.has(this.__dirty_props__, key)) {
|
||||
Reflect.deleteProperty(this.__dirty_props__, key);
|
||||
}
|
||||
}
|
||||
}
|
||||
isDirty() {
|
||||
return Reflect.ownKeys(this.__dirty_props__).length !== 0;
|
||||
}
|
||||
responseCallback(id, ...args) {
|
||||
const f = this.id2Callback(id);
|
||||
if (f instanceof Function) {
|
||||
const argumentsList = [];
|
||||
for (let i = 1; i < arguments.length; i++) {
|
||||
argumentsList.push(arguments[i]);
|
||||
}
|
||||
return Reflect.apply(f, this, argumentsList);
|
||||
}
|
||||
else {
|
||||
loge(`Cannot find callback:${id} for ${JSON.stringify(this.toModel())}`);
|
||||
}
|
||||
}
|
||||
toModel() {
|
||||
return this.nativeViewModel;
|
||||
}
|
||||
let(block) {
|
||||
block(this);
|
||||
}
|
||||
also(block) {
|
||||
block(this);
|
||||
return this;
|
||||
}
|
||||
apply(config) {
|
||||
for (let key in config) {
|
||||
Reflect.set(this, key, Reflect.get(config, key, config), this);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
in(group) {
|
||||
group.addChild(this);
|
||||
return this;
|
||||
}
|
||||
nativeChannel(context, name) {
|
||||
let thisView = this;
|
||||
return function (args = undefined) {
|
||||
const viewIds = [];
|
||||
while (thisView != undefined) {
|
||||
viewIds.push(thisView.viewId);
|
||||
thisView = thisView.superview;
|
||||
}
|
||||
const params = {
|
||||
viewIds: viewIds.reverse(),
|
||||
name,
|
||||
args,
|
||||
let View = /** @class */ (() => {
|
||||
class View {
|
||||
constructor() {
|
||||
this.width = 0;
|
||||
this.height = 0;
|
||||
this.x = 0;
|
||||
this.y = 0;
|
||||
this.viewId = uniqueId('ViewId');
|
||||
this.callbacks = new Map;
|
||||
/** Anchor end*/
|
||||
this.__dirty_props__ = {};
|
||||
this.nativeViewModel = {
|
||||
id: this.viewId,
|
||||
type: this.constructor.name,
|
||||
props: this.__dirty_props__,
|
||||
};
|
||||
return context.callNative('shader', 'command', params);
|
||||
};
|
||||
}
|
||||
getWidth(context) {
|
||||
return this.nativeChannel(context, 'getWidth')();
|
||||
}
|
||||
getHeight(context) {
|
||||
return this.nativeChannel(context, 'getHeight')();
|
||||
}
|
||||
getX(context) {
|
||||
return this.nativeChannel(context, 'getX')();
|
||||
}
|
||||
getY(context) {
|
||||
return this.nativeChannel(context, 'getY')();
|
||||
}
|
||||
getLocationOnScreen(context) {
|
||||
return this.nativeChannel(context, "getLocationOnScreen")();
|
||||
}
|
||||
doAnimation(context, animation) {
|
||||
return this.nativeChannel(context, "doAnimation")(animation.toModel()).then((args) => {
|
||||
for (let key in args) {
|
||||
Reflect.set(this, key, Reflect.get(args, key, args), this);
|
||||
Reflect.deleteProperty(this.__dirty_props__, key);
|
||||
return new Proxy(this, {
|
||||
get: (target, p, receiver) => {
|
||||
return Reflect.get(target, p, receiver);
|
||||
},
|
||||
set: (target, p, v, receiver) => {
|
||||
const oldV = Reflect.get(target, p, receiver);
|
||||
const ret = Reflect.set(target, p, v, receiver);
|
||||
if (Reflect.getMetadata(p, target) && oldV !== v) {
|
||||
receiver.onPropertyChanged(p.toString(), oldV, v);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
});
|
||||
}
|
||||
callback2Id(f) {
|
||||
const id = uniqueId('Function');
|
||||
this.callbacks.set(id, f);
|
||||
return id;
|
||||
}
|
||||
id2Callback(id) {
|
||||
let f = this.callbacks.get(id);
|
||||
if (f === undefined) {
|
||||
f = Reflect.get(this, id);
|
||||
}
|
||||
});
|
||||
return f;
|
||||
}
|
||||
/** Anchor start*/
|
||||
get left() {
|
||||
return this.x;
|
||||
}
|
||||
set left(v) {
|
||||
this.x = v;
|
||||
}
|
||||
get right() {
|
||||
return this.x + this.width;
|
||||
}
|
||||
set right(v) {
|
||||
this.x = v - this.width;
|
||||
}
|
||||
get top() {
|
||||
return this.y;
|
||||
}
|
||||
set top(v) {
|
||||
this.y = v;
|
||||
}
|
||||
get bottom() {
|
||||
return this.y + this.height;
|
||||
}
|
||||
set bottom(v) {
|
||||
this.y = v - this.height;
|
||||
}
|
||||
get centerX() {
|
||||
return this.x + this.width / 2;
|
||||
}
|
||||
get centerY() {
|
||||
return this.y + this.height / 2;
|
||||
}
|
||||
set centerX(v) {
|
||||
this.x = v - this.width / 2;
|
||||
}
|
||||
set centerY(v) {
|
||||
this.y = v - this.height / 2;
|
||||
}
|
||||
get dirtyProps() {
|
||||
return this.__dirty_props__;
|
||||
}
|
||||
onPropertyChanged(propKey, oldV, newV) {
|
||||
if (newV instanceof Function) {
|
||||
newV = this.callback2Id(newV);
|
||||
}
|
||||
else {
|
||||
newV = obj2Model(newV);
|
||||
}
|
||||
this.__dirty_props__[propKey] = newV;
|
||||
}
|
||||
clean() {
|
||||
for (const key in this.__dirty_props__) {
|
||||
if (Reflect.has(this.__dirty_props__, key)) {
|
||||
Reflect.deleteProperty(this.__dirty_props__, key);
|
||||
}
|
||||
}
|
||||
}
|
||||
isDirty() {
|
||||
return Reflect.ownKeys(this.__dirty_props__).length !== 0;
|
||||
}
|
||||
responseCallback(id, ...args) {
|
||||
const f = this.id2Callback(id);
|
||||
if (f instanceof Function) {
|
||||
const argumentsList = [];
|
||||
for (let i = 1; i < arguments.length; i++) {
|
||||
argumentsList.push(arguments[i]);
|
||||
}
|
||||
return Reflect.apply(f, this, argumentsList);
|
||||
}
|
||||
else {
|
||||
loge(`Cannot find callback:${id} for ${JSON.stringify(this.toModel())}`);
|
||||
}
|
||||
}
|
||||
toModel() {
|
||||
return this.nativeViewModel;
|
||||
}
|
||||
let(block) {
|
||||
block(this);
|
||||
}
|
||||
also(block) {
|
||||
block(this);
|
||||
return this;
|
||||
}
|
||||
apply(config) {
|
||||
for (let key in config) {
|
||||
Reflect.set(this, key, Reflect.get(config, key, config), this);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
in(group) {
|
||||
group.addChild(this);
|
||||
return this;
|
||||
}
|
||||
nativeChannel(context, name) {
|
||||
let thisView = this;
|
||||
return function (args = undefined) {
|
||||
const viewIds = [];
|
||||
while (thisView != undefined) {
|
||||
viewIds.push(thisView.viewId);
|
||||
thisView = thisView.superview;
|
||||
}
|
||||
const params = {
|
||||
viewIds: viewIds.reverse(),
|
||||
name,
|
||||
args,
|
||||
};
|
||||
return context.callNative('shader', 'command', params);
|
||||
};
|
||||
}
|
||||
getWidth(context) {
|
||||
return this.nativeChannel(context, 'getWidth')();
|
||||
}
|
||||
getHeight(context) {
|
||||
return this.nativeChannel(context, 'getHeight')();
|
||||
}
|
||||
getX(context) {
|
||||
return this.nativeChannel(context, 'getX')();
|
||||
}
|
||||
getY(context) {
|
||||
return this.nativeChannel(context, 'getY')();
|
||||
}
|
||||
getLocationOnScreen(context) {
|
||||
return this.nativeChannel(context, "getLocationOnScreen")();
|
||||
}
|
||||
doAnimation(context, animation) {
|
||||
return this.nativeChannel(context, "doAnimation")(animation.toModel()).then((args) => {
|
||||
for (let key in args) {
|
||||
Reflect.set(this, key, Reflect.get(args, key, args), this);
|
||||
Reflect.deleteProperty(this.__dirty_props__, key);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
__decorate([
|
||||
Property,
|
||||
__metadata("design:type", Number)
|
||||
], View.prototype, "width", void 0);
|
||||
__decorate([
|
||||
Property,
|
||||
__metadata("design:type", Number)
|
||||
], View.prototype, "height", void 0);
|
||||
__decorate([
|
||||
Property,
|
||||
__metadata("design:type", Number)
|
||||
], View.prototype, "x", void 0);
|
||||
__decorate([
|
||||
Property,
|
||||
__metadata("design:type", Number)
|
||||
], View.prototype, "y", void 0);
|
||||
__decorate([
|
||||
Property,
|
||||
__metadata("design:type", Object)
|
||||
], View.prototype, "backgroundColor", void 0);
|
||||
__decorate([
|
||||
Property,
|
||||
__metadata("design:type", Object)
|
||||
], View.prototype, "corners", void 0);
|
||||
__decorate([
|
||||
Property,
|
||||
__metadata("design:type", Object)
|
||||
], View.prototype, "border", void 0);
|
||||
__decorate([
|
||||
Property,
|
||||
__metadata("design:type", Object)
|
||||
], View.prototype, "shadow", void 0);
|
||||
__decorate([
|
||||
Property,
|
||||
__metadata("design:type", Number)
|
||||
], View.prototype, "alpha", void 0);
|
||||
__decorate([
|
||||
Property,
|
||||
__metadata("design:type", Boolean)
|
||||
], View.prototype, "hidden", void 0);
|
||||
__decorate([
|
||||
Property,
|
||||
__metadata("design:type", Object)
|
||||
], View.prototype, "padding", void 0);
|
||||
__decorate([
|
||||
Property,
|
||||
__metadata("design:type", Object)
|
||||
], View.prototype, "layoutConfig", void 0);
|
||||
__decorate([
|
||||
Property,
|
||||
__metadata("design:type", Function)
|
||||
], View.prototype, "onClick", void 0);
|
||||
__decorate([
|
||||
Property,
|
||||
__metadata("design:type", Number)
|
||||
], View.prototype, "translationX", void 0);
|
||||
__decorate([
|
||||
Property,
|
||||
__metadata("design:type", Number)
|
||||
], View.prototype, "translationY", void 0);
|
||||
__decorate([
|
||||
Property,
|
||||
__metadata("design:type", Number)
|
||||
], View.prototype, "scaleX", void 0);
|
||||
__decorate([
|
||||
Property,
|
||||
__metadata("design:type", Number)
|
||||
], View.prototype, "scaleY", void 0);
|
||||
__decorate([
|
||||
Property,
|
||||
__metadata("design:type", Number)
|
||||
], View.prototype, "pivotX", void 0);
|
||||
__decorate([
|
||||
Property,
|
||||
__metadata("design:type", Number)
|
||||
], View.prototype, "pivotY", void 0);
|
||||
__decorate([
|
||||
Property,
|
||||
__metadata("design:type", Number)
|
||||
], View.prototype, "rotation", void 0);
|
||||
__decorate([
|
||||
Property,
|
||||
__metadata("design:type", Object)
|
||||
], View.prototype, "flexConfig", void 0);
|
||||
__decorate([
|
||||
Property,
|
||||
__metadata("design:type", Number)
|
||||
], View.prototype, "width", void 0);
|
||||
__decorate([
|
||||
Property,
|
||||
__metadata("design:type", Number)
|
||||
], View.prototype, "height", void 0);
|
||||
__decorate([
|
||||
Property,
|
||||
__metadata("design:type", Number)
|
||||
], View.prototype, "x", void 0);
|
||||
__decorate([
|
||||
Property,
|
||||
__metadata("design:type", Number)
|
||||
], View.prototype, "y", void 0);
|
||||
__decorate([
|
||||
Property,
|
||||
__metadata("design:type", Object)
|
||||
], View.prototype, "backgroundColor", void 0);
|
||||
__decorate([
|
||||
Property,
|
||||
__metadata("design:type", Object)
|
||||
], View.prototype, "corners", void 0);
|
||||
__decorate([
|
||||
Property,
|
||||
__metadata("design:type", Object)
|
||||
], View.prototype, "border", void 0);
|
||||
__decorate([
|
||||
Property,
|
||||
__metadata("design:type", Object)
|
||||
], View.prototype, "shadow", void 0);
|
||||
__decorate([
|
||||
Property,
|
||||
__metadata("design:type", Number)
|
||||
], View.prototype, "alpha", void 0);
|
||||
__decorate([
|
||||
Property,
|
||||
__metadata("design:type", Boolean)
|
||||
], View.prototype, "hidden", void 0);
|
||||
__decorate([
|
||||
Property,
|
||||
__metadata("design:type", Object)
|
||||
], View.prototype, "padding", void 0);
|
||||
__decorate([
|
||||
Property,
|
||||
__metadata("design:type", Object)
|
||||
], View.prototype, "layoutConfig", void 0);
|
||||
__decorate([
|
||||
Property,
|
||||
__metadata("design:type", Function)
|
||||
], View.prototype, "onClick", void 0);
|
||||
__decorate([
|
||||
Property,
|
||||
__metadata("design:type", Number)
|
||||
], View.prototype, "translationX", void 0);
|
||||
__decorate([
|
||||
Property,
|
||||
__metadata("design:type", Number)
|
||||
], View.prototype, "translationY", void 0);
|
||||
__decorate([
|
||||
Property,
|
||||
__metadata("design:type", Number)
|
||||
], View.prototype, "scaleX", void 0);
|
||||
__decorate([
|
||||
Property,
|
||||
__metadata("design:type", Number)
|
||||
], View.prototype, "scaleY", void 0);
|
||||
__decorate([
|
||||
Property,
|
||||
__metadata("design:type", Number)
|
||||
], View.prototype, "pivotX", void 0);
|
||||
__decorate([
|
||||
Property,
|
||||
__metadata("design:type", Number)
|
||||
], View.prototype, "pivotY", void 0);
|
||||
__decorate([
|
||||
Property,
|
||||
__metadata("design:type", Number)
|
||||
], View.prototype, "rotation", void 0);
|
||||
__decorate([
|
||||
Property,
|
||||
__metadata("design:type", Object)
|
||||
], View.prototype, "flexConfig", void 0);
|
||||
return View;
|
||||
})();
|
||||
export { View };
|
||||
export class Superview extends View {
|
||||
subviewById(id) {
|
||||
for (let v of this.allSubviews()) {
|
||||
|
||||
Reference in New Issue
Block a user