js:compat es5,use context.sendNative to replace Proxy

This commit is contained in:
pengfei.zhou 2020-01-17 16:51:17 +08:00 committed by osborn
parent c813787318
commit b6f7588321
30 changed files with 461 additions and 414 deletions

View File

@ -205,6 +205,9 @@ var View = /** @class */ (function () {
return id; return id;
}; };
View.prototype.id2Callback = function (id) { View.prototype.id2Callback = function (id) {
if (this.callbacks === undefined) {
this.callbacks = new Map;
}
var f = this.callbacks.get(id); var f = this.callbacks.get(id);
if (f === undefined) { if (f === undefined) {
f = Reflect.get(this, id); f = Reflect.get(this, id);
@ -345,7 +348,6 @@ var View = /** @class */ (function () {
var thisView = this; var thisView = this;
return function (args) { return function (args) {
if (args === void 0) { args = undefined; } if (args === void 0) { args = undefined; }
var func = context.shader.command;
var viewIds = []; var viewIds = [];
while (thisView != undefined) { while (thisView != undefined) {
viewIds.push(thisView.viewId); viewIds.push(thisView.viewId);
@ -356,7 +358,7 @@ var View = /** @class */ (function () {
name: name, name: name,
args: args, args: args,
}; };
return Reflect.apply(func, undefined, [params]); return context.callNative('shader', 'command', params);
}; };
}; };
View.prototype.getWidth = function (context) { View.prototype.getWidth = function (context) {
@ -418,10 +420,6 @@ var View = /** @class */ (function () {
Property, Property,
__metadata("design:type", Boolean) __metadata("design:type", Boolean)
], View.prototype, "hidden", void 0); ], View.prototype, "hidden", void 0);
__decorate([
Property,
__metadata("design:type", Object)
], View.prototype, "viewId", void 0);
__decorate([ __decorate([
Property, Property,
__metadata("design:type", Object) __metadata("design:type", Object)
@ -2441,29 +2439,29 @@ function modal(context) {
return { return {
toast: function (msg, gravity) { toast: function (msg, gravity) {
if (gravity === void 0) { gravity = Gravity.Bottom; } if (gravity === void 0) { gravity = Gravity.Bottom; }
context.modal.toast({ context.callNative('modal', 'toast', {
msg: msg, msg: msg,
gravity: gravity.toModel(), gravity: gravity.toModel(),
}); });
}, },
alert: function (arg) { alert: function (arg) {
if (typeof arg === 'string') { if (typeof arg === 'string') {
return context.modal.alert({ msg: arg }); return context.callNative('modal', 'alert', { msg: arg });
} }
else { else {
return context.modal.alert(arg); return context.callNative('modal', 'alert', arg);
} }
}, },
confirm: function (arg) { confirm: function (arg) {
if (typeof arg === 'string') { if (typeof arg === 'string') {
return context.modal.confirm({ msg: arg }); return context.callNative('modal', 'confirm', { msg: arg });
} }
else { else {
return context.modal.confirm(arg); return context.callNative('modal', 'confirm', arg);
} }
}, },
prompt: function (arg) { prompt: function (arg) {
return context.modal.prompt(arg); return context.callNative('modal', 'prompt', arg);
}, },
}; };
} }
@ -2476,36 +2474,30 @@ function navbar(context) {
} }
return { return {
isHidden: function () { isHidden: function () {
return context.navbar.isHidden(); return context.callNative('navbar', 'isHidden');
}, },
setHidden: function (hidden) { setHidden: function (hidden) {
return context.navbar.setHidden({ return context.callNative('navbar', 'setHidden', { hidden: hidden, });
hidden: hidden,
});
}, },
setTitle: function (title) { setTitle: function (title) {
return context.navbar.setTitle({ return context.callNative('navbar', 'setTitle', { title: title, });
title: title,
});
}, },
setBgColor: function (color) { setBgColor: function (color) {
return context.navbar.setBgColor({ return context.callNative('navbar', 'setBgColor', { color: color.toModel(), });
color: color.toModel(),
});
}, },
setLeft: function (view) { setLeft: function (view) {
if (panel) { if (panel) {
panel.clearHeadViews("navbar_left"); panel.clearHeadViews("navbar_left");
panel.addHeadView("navbar_left", view); panel.addHeadView("navbar_left", view);
} }
return context.navbar.setLeft(view.toModel()); return context.callNative('navbar', 'setLeft', view.toModel());
}, },
setRight: function (view) { setRight: function (view) {
if (panel) { if (panel) {
panel.clearHeadViews("navbar_right"); panel.clearHeadViews("navbar_right");
panel.addHeadView("navbar_right", view); panel.addHeadView("navbar_right", view);
} }
return context.navbar.setRight(view.toModel()); return context.callNative('navbar', 'setRight', view.toModel());
} }
}; };
} }
@ -2516,13 +2508,13 @@ function navigator(context) {
if (config && config.extra) { if (config && config.extra) {
config.extra = JSON.stringify(config.extra); config.extra = JSON.stringify(config.extra);
} }
return context.navigator.push({ return context.callNative('navigator', 'push', {
scheme: scheme, config: config scheme: scheme, config: config
}); });
}, },
pop: function (animated) { pop: function (animated) {
if (animated === void 0) { animated = true; } if (animated === void 0) { animated = true; }
return context.navigator.pop({ animated: animated }); return context.callNative('navigator', 'pop', { animated: animated });
}, },
}; };
} }
@ -2544,7 +2536,7 @@ function transformRequest(request) {
function network(context) { function network(context) {
return { return {
request: function (config) { request: function (config) {
return context.network.request(transformRequest(config)); return context.callNative('network', 'request', transformRequest(config));
}, },
get: function (url, config) { get: function (url, config) {
var finalConfig = config; var finalConfig = config;
@ -2553,7 +2545,7 @@ function network(context) {
} }
finalConfig.url = url; finalConfig.url = url;
finalConfig.method = "get"; finalConfig.method = "get";
return context.network.request(transformRequest(finalConfig)); return context.callNative('network', 'request', transformRequest(finalConfig));
}, },
post: function (url, data, config) { post: function (url, data, config) {
var finalConfig = config; var finalConfig = config;
@ -2565,7 +2557,7 @@ function network(context) {
if (data !== undefined) { if (data !== undefined) {
finalConfig.data = data; finalConfig.data = data;
} }
return context.network.request(transformRequest(finalConfig)); return context.callNative('network', 'request', transformRequest(finalConfig));
}, },
put: function (url, data, config) { put: function (url, data, config) {
var finalConfig = config; var finalConfig = config;
@ -2577,7 +2569,7 @@ function network(context) {
if (data !== undefined) { if (data !== undefined) {
finalConfig.data = data; finalConfig.data = data;
} }
return context.network.request(transformRequest(finalConfig)); return context.callNative('network', 'request', transformRequest(finalConfig));
}, },
delete: function (url, data, config) { delete: function (url, data, config) {
var finalConfig = config; var finalConfig = config;
@ -2586,7 +2578,7 @@ function network(context) {
} }
finalConfig.url = url; finalConfig.url = url;
finalConfig.method = "delete"; finalConfig.method = "delete";
return context.network.request(transformRequest(finalConfig)); return context.callNative('network', 'request', transformRequest(finalConfig));
}, },
}; };
} }
@ -2594,16 +2586,16 @@ function network(context) {
function storage(context) { function storage(context) {
return { return {
setItem: function (key, value, zone) { setItem: function (key, value, zone) {
return context.storage.setItem({ key: key, value: value, zone: zone }); return context.callNative('storage', 'setItem', { key: key, value: value, zone: zone });
}, },
getItem: function (key, zone) { getItem: function (key, zone) {
return context.storage.getItem({ key: key, zone: zone }); return context.callNative('storage', 'getItem', { key: key, zone: zone });
}, },
remove: function (key, zone) { remove: function (key, zone) {
return context.storage.remove({ key: key, zone: zone }); return context.callNative('storage', 'remove', { key: key, zone: zone });
}, },
clear: function (zone) { clear: function (zone) {
return context.storage.clear({ zone: zone }); return context.callNative('storage', 'clear', { zone: zone });
}, },
}; };
} }
@ -2619,7 +2611,7 @@ function popover(context) {
if (panel) { if (panel) {
panel.addHeadView("popover", view); panel.addHeadView("popover", view);
} }
return context.popover.show(view.toModel()); return context.callNative('popover', 'show', view.toModel());
}, },
dismiss: function (view) { dismiss: function (view) {
if (view === void 0) { view = undefined; } if (view === void 0) { view = undefined; }
@ -2631,7 +2623,7 @@ function popover(context) {
panel.clearHeadViews("popover"); panel.clearHeadViews("popover");
} }
} }
return context.popover.dismiss(view ? { id: view.viewId } : undefined); return context.callNative('popover', 'dismiss', view ? { id: view.viewId } : undefined);
}, },
}; };
} }
@ -2699,6 +2691,42 @@ function repeat(action) {
}; };
} }
var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (undefined && undefined.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) { throw t[1]; } return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) { throw new TypeError("Generator is already executing."); }
while (_) { try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) { return t; }
if (y = 0, t) { op = [op[0] & 2, t.value]; }
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) { _.ops.pop(); }
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } }
if (op[0] & 5) { throw op[1]; } return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __values$4 = (undefined && undefined.__values) || function(o) { var __values$4 = (undefined && undefined.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) { return m.call(o); } if (m) { return m.call(o); }
@ -2715,57 +2743,61 @@ var __values$4 = (undefined && undefined.__values) || function(o) {
* @param panel @see Panel * @param panel @see Panel
*/ */
function animate(context) { function animate(context) {
var _this = this;
var entity = context.entity; var entity = context.entity;
if (entity instanceof Panel) { if (entity instanceof Panel) {
var panel_1 = entity; var panel_1 = entity;
return function (args) { return function (args) { return __awaiter(_this, void 0, void 0, function () {
return takeLet(panel_1.context.animate)(function (it) { return __generator(this, function (_a) {
return it.submit().then(function () { switch (_a.label) {
args.animations(); case 0: return [4 /*yield*/, context.callNative('animate', 'submit')];
return takeLet(panel_1.getRootView())(function (root) { case 1:
var e_1, _a, e_2, _b; _a.sent();
if (root.isDirty()) { args.animations();
var model = root.toModel(); return [2 /*return*/, takeLet(panel_1.getRootView())(function (root) {
model.duration = args.duration; var e_1, _a, e_2, _b;
var ret = it.animateRender(model); if (root.isDirty()) {
root.clean(); var model = root.toModel();
return ret; model.duration = args.duration;
} var ret = context.callNative('animate', 'animateRender', model);
try { root.clean();
for (var _c = __values$4(panel_1.allHeadViews()), _d = _c.next(); !_d.done; _d = _c.next()) { return ret;
var map = _d.value; }
try { try {
for (var _e = (e_2 = void 0, __values$4(map.values())), _f = _e.next(); !_f.done; _f = _e.next()) { for (var _c = __values$4(panel_1.allHeadViews()), _d = _c.next(); !_d.done; _d = _c.next()) {
var v = _f.value; var map = _d.value;
if (v.isDirty()) { try {
var model = v.toModel(); for (var _e = (e_2 = void 0, __values$4(map.values())), _f = _e.next(); !_f.done; _f = _e.next()) {
var ret = it.animateRender(model); var v = _f.value;
it.clean(); if (v.isDirty()) {
return ret; var model_1 = v.toModel();
var ret_1 = context.callNative('animate', 'animateRender', model_1);
v.clean();
return ret_1;
}
}
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (_f && !_f.done && (_b = _e.return)) { _b.call(_e); }
}
finally { if (e_2) { throw e_2.error; } }
} }
} }
} }
catch (e_2_1) { e_2 = { error: e_2_1 }; } catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally { finally {
try { try {
if (_f && !_f.done && (_b = _e.return)) { _b.call(_e); } if (_d && !_d.done && (_a = _c.return)) { _a.call(_c); }
} }
finally { if (e_2) { throw e_2.error; } } finally { if (e_1) { throw e_1.error; } }
} }
} throw new Error('Cannot find any animated elements');
} })];
catch (e_1_1) { e_1 = { error: e_1_1 }; } }
finally {
try {
if (_d && !_d.done && (_a = _c.return)) { _a.call(_c); }
}
finally { if (e_1) { throw e_1.error; } }
}
throw new Error('Cannot find any animated elements');
});
});
}); });
}; }); };
} }
else { else {
return function (args) { return function (args) {
@ -2780,15 +2812,15 @@ function notification(context) {
if (args.data !== undefined) { if (args.data !== undefined) {
args.data = JSON.stringify(args.data); args.data = JSON.stringify(args.data);
} }
return context.notification.publish(args); return context.callNative('notification', 'publish', args);
}, },
subscribe: function (args) { subscribe: function (args) {
args.callback = context.function2Id(args.callback); args.callback = context.function2Id(args.callback);
return context.notification.subscribe(args); return context.callNative('notification', 'subscribe', args);
}, },
unsubscribe: function (subscribeId) { unsubscribe: function (subscribeId) {
context.removeFuncById(subscribeId); context.removeFuncById(subscribeId);
return context.notification.unsubscribe(subscribeId); return context.callNative('notification', 'unsubscribe', subscribeId);
} }
}; };
} }
@ -2800,13 +2832,13 @@ function notification(context) {
function statusbar(context) { function statusbar(context) {
return { return {
setHidden: function (hidden) { setHidden: function (hidden) {
return context.statusbar.setHidden({ hidden: hidden }); return context.callNative('statusbar', 'setHidden', { hidden: hidden });
}, },
setMode: function (mode) { setMode: function (mode) {
return context.statusbar.setMode({ mode: mode }); return context.callNative('statusbar', 'setMode', { mode: mode });
}, },
setColor: function (color) { setColor: function (color) {
return context.statusbar.setColor({ color: color.toModel() }); return context.callNative('statusbar', 'setColor', { color: color.toModel() });
}, },
}; };
} }

View File

@ -264,7 +264,6 @@ class View {
nativeChannel(context, name) { nativeChannel(context, name) {
let thisView = this; let thisView = this;
return function (args = undefined) { return function (args = undefined) {
const func = context.shader.command;
const viewIds = []; const viewIds = [];
while (thisView != undefined) { while (thisView != undefined) {
viewIds.push(thisView.viewId); viewIds.push(thisView.viewId);
@ -275,7 +274,7 @@ class View {
name, name,
args, args,
}; };
return Reflect.apply(func, undefined, [params]); return context.callNative('shader', 'command', params);
}; };
} }
getWidth(context) { getWidth(context) {
@ -337,10 +336,6 @@ __decorate([
Property, Property,
__metadata("design:type", Boolean) __metadata("design:type", Boolean)
], View.prototype, "hidden", void 0); ], View.prototype, "hidden", void 0);
__decorate([
Property,
__metadata("design:type", Object)
], View.prototype, "viewId", void 0);
__decorate([ __decorate([
Property, Property,
__metadata("design:type", Object) __metadata("design:type", Object)
@ -1819,29 +1814,29 @@ function draggable(views, config) {
function modal(context) { function modal(context) {
return { return {
toast: (msg, gravity = Gravity.Bottom) => { toast: (msg, gravity = Gravity.Bottom) => {
context.modal.toast({ context.callNative('modal', 'toast', {
msg, msg,
gravity: gravity.toModel(), gravity: gravity.toModel(),
}); });
}, },
alert: (arg) => { alert: (arg) => {
if (typeof arg === 'string') { if (typeof arg === 'string') {
return context.modal.alert({ msg: arg }); return context.callNative('modal', 'alert', { msg: arg });
} }
else { else {
return context.modal.alert(arg); return context.callNative('modal', 'alert', arg);
} }
}, },
confirm: (arg) => { confirm: (arg) => {
if (typeof arg === 'string') { if (typeof arg === 'string') {
return context.modal.confirm({ msg: arg }); return context.callNative('modal', 'confirm', { msg: arg });
} }
else { else {
return context.modal.confirm(arg); return context.callNative('modal', 'confirm', arg);
} }
}, },
prompt: (arg) => { prompt: (arg) => {
return context.modal.prompt(arg); return context.callNative('modal', 'prompt', arg);
}, },
}; };
} }
@ -1854,36 +1849,30 @@ function navbar(context) {
} }
return { return {
isHidden: () => { isHidden: () => {
return context.navbar.isHidden(); return context.callNative('navbar', 'isHidden');
}, },
setHidden: (hidden) => { setHidden: (hidden) => {
return context.navbar.setHidden({ return context.callNative('navbar', 'setHidden', { hidden, });
hidden,
});
}, },
setTitle: (title) => { setTitle: (title) => {
return context.navbar.setTitle({ return context.callNative('navbar', 'setTitle', { title, });
title,
});
}, },
setBgColor: (color) => { setBgColor: (color) => {
return context.navbar.setBgColor({ return context.callNative('navbar', 'setBgColor', { color: color.toModel(), });
color: color.toModel(),
});
}, },
setLeft: (view) => { setLeft: (view) => {
if (panel) { if (panel) {
panel.clearHeadViews("navbar_left"); panel.clearHeadViews("navbar_left");
panel.addHeadView("navbar_left", view); panel.addHeadView("navbar_left", view);
} }
return context.navbar.setLeft(view.toModel()); return context.callNative('navbar', 'setLeft', view.toModel());
}, },
setRight: (view) => { setRight: (view) => {
if (panel) { if (panel) {
panel.clearHeadViews("navbar_right"); panel.clearHeadViews("navbar_right");
panel.addHeadView("navbar_right", view); panel.addHeadView("navbar_right", view);
} }
return context.navbar.setRight(view.toModel()); return context.callNative('navbar', 'setRight', view.toModel());
} }
}; };
} }
@ -1894,12 +1883,12 @@ function navigator(context) {
if (config && config.extra) { if (config && config.extra) {
config.extra = JSON.stringify(config.extra); config.extra = JSON.stringify(config.extra);
} }
return context.navigator.push({ return context.callNative('navigator', 'push', {
scheme, config scheme, config
}); });
}, },
pop: (animated = true) => { pop: (animated = true) => {
return context.navigator.pop({ animated }); return context.callNative('navigator', 'pop', { animated });
}, },
}; };
} }
@ -1921,7 +1910,7 @@ function transformRequest(request) {
function network(context) { function network(context) {
return { return {
request: (config) => { request: (config) => {
return context.network.request(transformRequest(config)); return context.callNative('network', 'request', transformRequest(config));
}, },
get: (url, config) => { get: (url, config) => {
let finalConfig = config; let finalConfig = config;
@ -1930,7 +1919,7 @@ function network(context) {
} }
finalConfig.url = url; finalConfig.url = url;
finalConfig.method = "get"; finalConfig.method = "get";
return context.network.request(transformRequest(finalConfig)); return context.callNative('network', 'request', transformRequest(finalConfig));
}, },
post: (url, data, config) => { post: (url, data, config) => {
let finalConfig = config; let finalConfig = config;
@ -1942,7 +1931,7 @@ function network(context) {
if (data !== undefined) { if (data !== undefined) {
finalConfig.data = data; finalConfig.data = data;
} }
return context.network.request(transformRequest(finalConfig)); return context.callNative('network', 'request', transformRequest(finalConfig));
}, },
put: (url, data, config) => { put: (url, data, config) => {
let finalConfig = config; let finalConfig = config;
@ -1954,7 +1943,7 @@ function network(context) {
if (data !== undefined) { if (data !== undefined) {
finalConfig.data = data; finalConfig.data = data;
} }
return context.network.request(transformRequest(finalConfig)); return context.callNative('network', 'request', transformRequest(finalConfig));
}, },
delete: (url, data, config) => { delete: (url, data, config) => {
let finalConfig = config; let finalConfig = config;
@ -1963,7 +1952,7 @@ function network(context) {
} }
finalConfig.url = url; finalConfig.url = url;
finalConfig.method = "delete"; finalConfig.method = "delete";
return context.network.request(transformRequest(finalConfig)); return context.callNative('network', 'request', transformRequest(finalConfig));
}, },
}; };
} }
@ -1971,16 +1960,16 @@ function network(context) {
function storage(context) { function storage(context) {
return { return {
setItem: (key, value, zone) => { setItem: (key, value, zone) => {
return context.storage.setItem({ key, value, zone }); return context.callNative('storage', 'setItem', { key, value, zone });
}, },
getItem: (key, zone) => { getItem: (key, zone) => {
return context.storage.getItem({ key, zone }); return context.callNative('storage', 'getItem', { key, zone });
}, },
remove: (key, zone) => { remove: (key, zone) => {
return context.storage.remove({ key, zone }); return context.callNative('storage', 'remove', { key, zone });
}, },
clear: (zone) => { clear: (zone) => {
return context.storage.clear({ zone }); return context.callNative('storage', 'clear', { zone });
}, },
}; };
} }
@ -1996,7 +1985,7 @@ function popover(context) {
if (panel) { if (panel) {
panel.addHeadView("popover", view); panel.addHeadView("popover", view);
} }
return context.popover.show(view.toModel()); return context.callNative('popover', 'show', view.toModel());
}, },
dismiss: (view = undefined) => { dismiss: (view = undefined) => {
if (panel) { if (panel) {
@ -2007,7 +1996,7 @@ function popover(context) {
panel.clearHeadViews("popover"); panel.clearHeadViews("popover");
} }
} }
return context.popover.dismiss(view ? { id: view.viewId } : undefined); return context.callNative('popover', 'dismiss', view ? { id: view.viewId } : undefined);
}, },
}; };
} }
@ -2075,21 +2064,15 @@ function repeat(action) {
}; };
} }
/* var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
* Copyright [2019] [Doric.Pub] function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
* return new (P || (P = Promise))(function (resolve, reject) {
* Licensed under the Apache License, Version 2.0 (the "License"); function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
* you may not use this file except in compliance with the License. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
* You may obtain a copy of the License at function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
* step((generator = generator.apply(thisArg, _arguments || [])).next());
* http://www.apache.org/licenses/LICENSE-2.0 });
* };
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/** /**
* Only supports x,y,width,height,corner(just for four corners),rotation,bgColor, * Only supports x,y,width,height,corner(just for four corners),rotation,bgColor,
* @param panel @see Panel * @param panel @see Panel
@ -2098,33 +2081,30 @@ function animate(context) {
const entity = context.entity; const entity = context.entity;
if (entity instanceof Panel) { if (entity instanceof Panel) {
let panel = entity; let panel = entity;
return (args) => { return (args) => __awaiter(this, void 0, void 0, function* () {
return takeLet(panel.context.animate)(it => { yield context.callNative('animate', 'submit');
return it.submit().then(() => { args.animations();
args.animations(); return takeLet(panel.getRootView())(root => {
return takeLet(panel.getRootView())(root => { if (root.isDirty()) {
if (root.isDirty()) { const model = root.toModel();
const model = root.toModel(); model.duration = args.duration;
model.duration = args.duration; const ret = context.callNative('animate', 'animateRender', model);
const ret = it.animateRender(model); root.clean();
root.clean(); return ret;
return ret; }
for (let map of panel.allHeadViews()) {
for (let v of map.values()) {
if (v.isDirty()) {
const model_1 = v.toModel();
const ret_1 = context.callNative('animate', 'animateRender', model_1);
v.clean();
return ret_1;
} }
for (let map of panel.allHeadViews()) { }
for (let v of map.values()) { }
if (v.isDirty()) { throw new Error('Cannot find any animated elements');
const model = v.toModel();
const ret = it.animateRender(model);
it.clean();
return ret;
}
}
}
throw new Error('Cannot find any animated elements');
});
});
}); });
}; });
} }
else { else {
return (args) => { return (args) => {
@ -2139,15 +2119,15 @@ function notification(context) {
if (args.data !== undefined) { if (args.data !== undefined) {
args.data = JSON.stringify(args.data); args.data = JSON.stringify(args.data);
} }
return context.notification.publish(args); return context.callNative('notification', 'publish', args);
}, },
subscribe: (args) => { subscribe: (args) => {
args.callback = context.function2Id(args.callback); args.callback = context.function2Id(args.callback);
return context.notification.subscribe(args); return context.callNative('notification', 'subscribe', args);
}, },
unsubscribe: (subscribeId) => { unsubscribe: (subscribeId) => {
context.removeFuncById(subscribeId); context.removeFuncById(subscribeId);
return context.notification.unsubscribe(subscribeId); return context.callNative('notification', 'unsubscribe', subscribeId);
} }
}; };
} }
@ -2159,13 +2139,13 @@ function notification(context) {
function statusbar(context) { function statusbar(context) {
return { return {
setHidden: (hidden) => { setHidden: (hidden) => {
return context.statusbar.setHidden({ hidden }); return context.callNative('statusbar', 'setHidden', { hidden });
}, },
setMode: (mode) => { setMode: (mode) => {
return context.statusbar.setMode({ mode }); return context.callNative('statusbar', 'setMode', { mode });
}, },
setColor: (color) => { setColor: (color) => {
return context.statusbar.setColor({ color: color.toModel() }); return context.callNative('statusbar', 'setColor', { color: color.toModel() });
}, },
}; };
} }

View File

@ -1723,7 +1723,6 @@ class View {
nativeChannel(context, name) { nativeChannel(context, name) {
let thisView = this; let thisView = this;
return function (args = undefined) { return function (args = undefined) {
const func = context.shader.command;
const viewIds = []; const viewIds = [];
while (thisView != undefined) { while (thisView != undefined) {
viewIds.push(thisView.viewId); viewIds.push(thisView.viewId);
@ -1734,7 +1733,7 @@ class View {
name, name,
args, args,
}; };
return Reflect.apply(func, undefined, [params]); return context.callNative('shader', 'command', params);
}; };
} }
getWidth(context) { getWidth(context) {
@ -1796,10 +1795,6 @@ __decorate([
Property, Property,
__metadata("design:type", Boolean) __metadata("design:type", Boolean)
], View.prototype, "hidden", void 0); ], View.prototype, "hidden", void 0);
__decorate([
Property,
__metadata("design:type", Object)
], View.prototype, "viewId", void 0);
__decorate([ __decorate([
Property, Property,
__metadata("design:type", Object) __metadata("design:type", Object)
@ -3278,29 +3273,29 @@ function draggable(views, config) {
function modal(context) { function modal(context) {
return { return {
toast: (msg, gravity = Gravity.Bottom) => { toast: (msg, gravity = Gravity.Bottom) => {
context.modal.toast({ context.callNative('modal', 'toast', {
msg, msg,
gravity: gravity.toModel(), gravity: gravity.toModel(),
}); });
}, },
alert: (arg) => { alert: (arg) => {
if (typeof arg === 'string') { if (typeof arg === 'string') {
return context.modal.alert({ msg: arg }); return context.callNative('modal', 'alert', { msg: arg });
} }
else { else {
return context.modal.alert(arg); return context.callNative('modal', 'alert', arg);
} }
}, },
confirm: (arg) => { confirm: (arg) => {
if (typeof arg === 'string') { if (typeof arg === 'string') {
return context.modal.confirm({ msg: arg }); return context.callNative('modal', 'confirm', { msg: arg });
} }
else { else {
return context.modal.confirm(arg); return context.callNative('modal', 'confirm', arg);
} }
}, },
prompt: (arg) => { prompt: (arg) => {
return context.modal.prompt(arg); return context.callNative('modal', 'prompt', arg);
}, },
}; };
} }
@ -3313,36 +3308,30 @@ function navbar(context) {
} }
return { return {
isHidden: () => { isHidden: () => {
return context.navbar.isHidden(); return context.callNative('navbar', 'isHidden');
}, },
setHidden: (hidden) => { setHidden: (hidden) => {
return context.navbar.setHidden({ return context.callNative('navbar', 'setHidden', { hidden, });
hidden,
});
}, },
setTitle: (title) => { setTitle: (title) => {
return context.navbar.setTitle({ return context.callNative('navbar', 'setTitle', { title, });
title,
});
}, },
setBgColor: (color) => { setBgColor: (color) => {
return context.navbar.setBgColor({ return context.callNative('navbar', 'setBgColor', { color: color.toModel(), });
color: color.toModel(),
});
}, },
setLeft: (view) => { setLeft: (view) => {
if (panel) { if (panel) {
panel.clearHeadViews("navbar_left"); panel.clearHeadViews("navbar_left");
panel.addHeadView("navbar_left", view); panel.addHeadView("navbar_left", view);
} }
return context.navbar.setLeft(view.toModel()); return context.callNative('navbar', 'setLeft', view.toModel());
}, },
setRight: (view) => { setRight: (view) => {
if (panel) { if (panel) {
panel.clearHeadViews("navbar_right"); panel.clearHeadViews("navbar_right");
panel.addHeadView("navbar_right", view); panel.addHeadView("navbar_right", view);
} }
return context.navbar.setRight(view.toModel()); return context.callNative('navbar', 'setRight', view.toModel());
} }
}; };
} }
@ -3353,12 +3342,12 @@ function navigator(context) {
if (config && config.extra) { if (config && config.extra) {
config.extra = JSON.stringify(config.extra); config.extra = JSON.stringify(config.extra);
} }
return context.navigator.push({ return context.callNative('navigator', 'push', {
scheme, config scheme, config
}); });
}, },
pop: (animated = true) => { pop: (animated = true) => {
return context.navigator.pop({ animated }); return context.callNative('navigator', 'pop', { animated });
}, },
}; };
} }
@ -3380,7 +3369,7 @@ function transformRequest(request) {
function network(context) { function network(context) {
return { return {
request: (config) => { request: (config) => {
return context.network.request(transformRequest(config)); return context.callNative('network', 'request', transformRequest(config));
}, },
get: (url, config) => { get: (url, config) => {
let finalConfig = config; let finalConfig = config;
@ -3389,7 +3378,7 @@ function network(context) {
} }
finalConfig.url = url; finalConfig.url = url;
finalConfig.method = "get"; finalConfig.method = "get";
return context.network.request(transformRequest(finalConfig)); return context.callNative('network', 'request', transformRequest(finalConfig));
}, },
post: (url, data, config) => { post: (url, data, config) => {
let finalConfig = config; let finalConfig = config;
@ -3401,7 +3390,7 @@ function network(context) {
if (data !== undefined) { if (data !== undefined) {
finalConfig.data = data; finalConfig.data = data;
} }
return context.network.request(transformRequest(finalConfig)); return context.callNative('network', 'request', transformRequest(finalConfig));
}, },
put: (url, data, config) => { put: (url, data, config) => {
let finalConfig = config; let finalConfig = config;
@ -3413,7 +3402,7 @@ function network(context) {
if (data !== undefined) { if (data !== undefined) {
finalConfig.data = data; finalConfig.data = data;
} }
return context.network.request(transformRequest(finalConfig)); return context.callNative('network', 'request', transformRequest(finalConfig));
}, },
delete: (url, data, config) => { delete: (url, data, config) => {
let finalConfig = config; let finalConfig = config;
@ -3422,7 +3411,7 @@ function network(context) {
} }
finalConfig.url = url; finalConfig.url = url;
finalConfig.method = "delete"; finalConfig.method = "delete";
return context.network.request(transformRequest(finalConfig)); return context.callNative('network', 'request', transformRequest(finalConfig));
}, },
}; };
} }
@ -3430,16 +3419,16 @@ function network(context) {
function storage(context) { function storage(context) {
return { return {
setItem: (key, value, zone) => { setItem: (key, value, zone) => {
return context.storage.setItem({ key, value, zone }); return context.callNative('storage', 'setItem', { key, value, zone });
}, },
getItem: (key, zone) => { getItem: (key, zone) => {
return context.storage.getItem({ key, zone }); return context.callNative('storage', 'getItem', { key, zone });
}, },
remove: (key, zone) => { remove: (key, zone) => {
return context.storage.remove({ key, zone }); return context.callNative('storage', 'remove', { key, zone });
}, },
clear: (zone) => { clear: (zone) => {
return context.storage.clear({ zone }); return context.callNative('storage', 'clear', { zone });
}, },
}; };
} }
@ -3455,7 +3444,7 @@ function popover(context) {
if (panel) { if (panel) {
panel.addHeadView("popover", view); panel.addHeadView("popover", view);
} }
return context.popover.show(view.toModel()); return context.callNative('popover', 'show', view.toModel());
}, },
dismiss: (view = undefined) => { dismiss: (view = undefined) => {
if (panel) { if (panel) {
@ -3466,7 +3455,7 @@ function popover(context) {
panel.clearHeadViews("popover"); panel.clearHeadViews("popover");
} }
} }
return context.popover.dismiss(view ? { id: view.viewId } : undefined); return context.callNative('popover', 'dismiss', view ? { id: view.viewId } : undefined);
}, },
}; };
} }
@ -3534,21 +3523,15 @@ function repeat(action) {
}; };
} }
/* var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
* Copyright [2019] [Doric.Pub] function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
* return new (P || (P = Promise))(function (resolve, reject) {
* Licensed under the Apache License, Version 2.0 (the "License"); function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
* you may not use this file except in compliance with the License. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
* You may obtain a copy of the License at function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
* step((generator = generator.apply(thisArg, _arguments || [])).next());
* http://www.apache.org/licenses/LICENSE-2.0 });
* };
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/** /**
* Only supports x,y,width,height,corner(just for four corners),rotation,bgColor, * Only supports x,y,width,height,corner(just for four corners),rotation,bgColor,
* @param panel @see Panel * @param panel @see Panel
@ -3557,33 +3540,30 @@ function animate(context) {
const entity = context.entity; const entity = context.entity;
if (entity instanceof Panel) { if (entity instanceof Panel) {
let panel = entity; let panel = entity;
return (args) => { return (args) => __awaiter(this, void 0, void 0, function* () {
return takeLet(panel.context.animate)(it => { yield context.callNative('animate', 'submit');
return it.submit().then(() => { args.animations();
args.animations(); return takeLet(panel.getRootView())(root => {
return takeLet(panel.getRootView())(root => { if (root.isDirty()) {
if (root.isDirty()) { const model = root.toModel();
const model = root.toModel(); model.duration = args.duration;
model.duration = args.duration; const ret = context.callNative('animate', 'animateRender', model);
const ret = it.animateRender(model); root.clean();
root.clean(); return ret;
return ret; }
for (let map of panel.allHeadViews()) {
for (let v of map.values()) {
if (v.isDirty()) {
const model_1 = v.toModel();
const ret_1 = context.callNative('animate', 'animateRender', model_1);
v.clean();
return ret_1;
} }
for (let map of panel.allHeadViews()) { }
for (let v of map.values()) { }
if (v.isDirty()) { throw new Error('Cannot find any animated elements');
const model = v.toModel();
const ret = it.animateRender(model);
it.clean();
return ret;
}
}
}
throw new Error('Cannot find any animated elements');
});
});
}); });
}; });
} }
else { else {
return (args) => { return (args) => {
@ -3598,15 +3578,15 @@ function notification(context) {
if (args.data !== undefined) { if (args.data !== undefined) {
args.data = JSON.stringify(args.data); args.data = JSON.stringify(args.data);
} }
return context.notification.publish(args); return context.callNative('notification', 'publish', args);
}, },
subscribe: (args) => { subscribe: (args) => {
args.callback = context.function2Id(args.callback); args.callback = context.function2Id(args.callback);
return context.notification.subscribe(args); return context.callNative('notification', 'subscribe', args);
}, },
unsubscribe: (subscribeId) => { unsubscribe: (subscribeId) => {
context.removeFuncById(subscribeId); context.removeFuncById(subscribeId);
return context.notification.unsubscribe(subscribeId); return context.callNative('notification', 'unsubscribe', subscribeId);
} }
}; };
} }
@ -3618,13 +3598,13 @@ function notification(context) {
function statusbar(context) { function statusbar(context) {
return { return {
setHidden: (hidden) => { setHidden: (hidden) => {
return context.statusbar.setHidden({ hidden }); return context.callNative('statusbar', 'setHidden', { hidden });
}, },
setMode: (mode) => { setMode: (mode) => {
return context.statusbar.setMode({ mode }); return context.callNative('statusbar', 'setMode', { mode });
}, },
setColor: (color) => { setColor: (color) => {
return context.statusbar.setColor({ color: color.toModel() }); return context.callNative('statusbar', 'setColor', { color: color.toModel() });
}, },
}; };
} }

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

@ -14,25 +14,47 @@ declare module 'doric' {
declare module 'doric/lib/src/runtime/global' { declare module 'doric/lib/src/runtime/global' {
export * from 'reflect-metadata'; export * from 'reflect-metadata';
export type BridgeContext = { export type BridgeContext = {
[index: string]: { /**
[index: string]: (args?: any) => Promise<any>; * The identify of current context
}; */
id: string;
/**
* In this case,It's current panel
*/
entity: any;
/**
* call native plugin
* @param namespace
* @param method
* @param args
*/
callNative(namespace: string, method: string, args?: any): Promise<any>;
/**
* Transform function to functionId as string
* @param func
*/
function2Id(func: Function): string;
/**
* Remove transformed functions
* @param funcId
*/
removeFuncById(funcId: string): void;
}; };
global { global {
const context: BridgeContext; const context: BridgeContext;
const Environment: { const Environment: {
platform: "Android" | "iOS" | "Qt" | "web"; platform: "Android" | "iOS" | "Qt" | "web";
platformVersion: string; platformVersion: string;
appName: string; appName: string;
appVersion: string; appVersion: string;
libVersion: string; libVersion: string;
screenWidth: number; screenWidth: number;
screenHeight: number; screenHeight: number;
[index: string]: number | string | boolean | object | undefined; [index: string]: number | string | boolean | object | undefined;
}; };
function Entry(constructor: { function Entry(constructor: {
new (...args: any[]): {}; new (...args: any[]): {};
}): any; }): any;
} }
export {}; export {};
} }
@ -214,7 +236,7 @@ declare module 'doric/lib/src/ui/view' {
also(block: (it: this) => void): this; also(block: (it: this) => void): this;
apply(config: IView): this; apply(config: IView): this;
in(group: Group): this; in(group: Group): this;
nativeChannel(context: any, name: string): (args?: any) => Promise<any>; nativeChannel(context: BridgeContext, name: string): (args?: any) => Promise<any>;
getWidth(context: BridgeContext): Promise<number>; getWidth(context: BridgeContext): Promise<number>;
getHeight(context: BridgeContext): Promise<number>; getHeight(context: BridgeContext): Promise<number>;
getLocationOnScreen(context: BridgeContext): Promise<{ getLocationOnScreen(context: BridgeContext): Promise<{
@ -797,7 +819,7 @@ declare module 'doric/lib/src/native/animate' {
export function animate(context: BridgeContext): (args: { export function animate(context: BridgeContext): (args: {
animations: () => void; animations: () => void;
duration: number; duration: number;
}) => Promise<any>; }) => Promise<unknown>;
} }
declare module 'doric/lib/src/native/notification' { declare module 'doric/lib/src/native/notification' {

View File

@ -6,4 +6,4 @@ import { BridgeContext } from "../runtime/global";
export declare function animate(context: BridgeContext): (args: { export declare function animate(context: BridgeContext): (args: {
animations: () => void; animations: () => void;
duration: number; duration: number;
}) => Promise<any>; }) => Promise<unknown>;

View File

@ -1,3 +1,12 @@
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
/* /*
* Copyright [2019] [Doric.Pub] * Copyright [2019] [Doric.Pub]
* *
@ -23,33 +32,30 @@ export function animate(context) {
const entity = context.entity; const entity = context.entity;
if (entity instanceof Panel) { if (entity instanceof Panel) {
let panel = entity; let panel = entity;
return (args) => { return (args) => __awaiter(this, void 0, void 0, function* () {
return takeLet(panel.context.animate)(it => { yield context.callNative('animate', 'submit');
return it.submit().then(() => { args.animations();
args.animations(); return takeLet(panel.getRootView())(root => {
return takeLet(panel.getRootView())(root => { if (root.isDirty()) {
if (root.isDirty()) { const model = root.toModel();
const model = root.toModel(); model.duration = args.duration;
model.duration = args.duration; const ret = context.callNative('animate', 'animateRender', model);
const ret = it.animateRender(model); root.clean();
root.clean(); return ret;
return ret; }
for (let map of panel.allHeadViews()) {
for (let v of map.values()) {
if (v.isDirty()) {
const model_1 = v.toModel();
const ret_1 = context.callNative('animate', 'animateRender', model_1);
v.clean();
return ret_1;
} }
for (let map of panel.allHeadViews()) { }
for (let v of map.values()) { }
if (v.isDirty()) { throw new Error('Cannot find any animated elements');
const model = v.toModel();
const ret = it.animateRender(model);
it.clean();
return ret;
}
}
}
throw new Error('Cannot find any animated elements');
});
});
}); });
}; });
} }
else { else {
return (args) => { return (args) => {

View File

@ -2,29 +2,29 @@ import { Gravity } from "../util/gravity";
export function modal(context) { export function modal(context) {
return { return {
toast: (msg, gravity = Gravity.Bottom) => { toast: (msg, gravity = Gravity.Bottom) => {
context.modal.toast({ context.callNative('modal', 'toast', {
msg, msg,
gravity: gravity.toModel(), gravity: gravity.toModel(),
}); });
}, },
alert: (arg) => { alert: (arg) => {
if (typeof arg === 'string') { if (typeof arg === 'string') {
return context.modal.alert({ msg: arg }); return context.callNative('modal', 'alert', { msg: arg });
} }
else { else {
return context.modal.alert(arg); return context.callNative('modal', 'alert', arg);
} }
}, },
confirm: (arg) => { confirm: (arg) => {
if (typeof arg === 'string') { if (typeof arg === 'string') {
return context.modal.confirm({ msg: arg }); return context.callNative('modal', 'confirm', { msg: arg });
} }
else { else {
return context.modal.confirm(arg); return context.callNative('modal', 'confirm', arg);
} }
}, },
prompt: (arg) => { prompt: (arg) => {
return context.modal.prompt(arg); return context.callNative('modal', 'prompt', arg);
}, },
}; };
} }

View File

@ -7,36 +7,30 @@ export function navbar(context) {
} }
return { return {
isHidden: () => { isHidden: () => {
return context.navbar.isHidden(); return context.callNative('navbar', 'isHidden');
}, },
setHidden: (hidden) => { setHidden: (hidden) => {
return context.navbar.setHidden({ return context.callNative('navbar', 'setHidden', { hidden, });
hidden,
});
}, },
setTitle: (title) => { setTitle: (title) => {
return context.navbar.setTitle({ return context.callNative('navbar', 'setTitle', { title, });
title,
});
}, },
setBgColor: (color) => { setBgColor: (color) => {
return context.navbar.setBgColor({ return context.callNative('navbar', 'setBgColor', { color: color.toModel(), });
color: color.toModel(),
});
}, },
setLeft: (view) => { setLeft: (view) => {
if (panel) { if (panel) {
panel.clearHeadViews("navbar_left"); panel.clearHeadViews("navbar_left");
panel.addHeadView("navbar_left", view); panel.addHeadView("navbar_left", view);
} }
return context.navbar.setLeft(view.toModel()); return context.callNative('navbar', 'setLeft', view.toModel());
}, },
setRight: (view) => { setRight: (view) => {
if (panel) { if (panel) {
panel.clearHeadViews("navbar_right"); panel.clearHeadViews("navbar_right");
panel.addHeadView("navbar_right", view); panel.addHeadView("navbar_right", view);
} }
return context.navbar.setRight(view.toModel()); return context.callNative('navbar', 'setRight', view.toModel());
} }
}; };
} }

View File

@ -4,12 +4,12 @@ export function navigator(context) {
if (config && config.extra) { if (config && config.extra) {
config.extra = JSON.stringify(config.extra); config.extra = JSON.stringify(config.extra);
} }
return context.navigator.push({ return context.callNative('navigator', 'push', {
scheme, config scheme, config
}); });
}, },
pop: (animated = true) => { pop: (animated = true) => {
return context.navigator.pop({ animated }); return context.callNative('navigator', 'pop', { animated });
}, },
}; };
} }

View File

@ -15,7 +15,7 @@ function transformRequest(request) {
export function network(context) { export function network(context) {
return { return {
request: (config) => { request: (config) => {
return context.network.request(transformRequest(config)); return context.callNative('network', 'request', transformRequest(config));
}, },
get: (url, config) => { get: (url, config) => {
let finalConfig = config; let finalConfig = config;
@ -24,7 +24,7 @@ export function network(context) {
} }
finalConfig.url = url; finalConfig.url = url;
finalConfig.method = "get"; finalConfig.method = "get";
return context.network.request(transformRequest(finalConfig)); return context.callNative('network', 'request', transformRequest(finalConfig));
}, },
post: (url, data, config) => { post: (url, data, config) => {
let finalConfig = config; let finalConfig = config;
@ -36,7 +36,7 @@ export function network(context) {
if (data !== undefined) { if (data !== undefined) {
finalConfig.data = data; finalConfig.data = data;
} }
return context.network.request(transformRequest(finalConfig)); return context.callNative('network', 'request', transformRequest(finalConfig));
}, },
put: (url, data, config) => { put: (url, data, config) => {
let finalConfig = config; let finalConfig = config;
@ -48,7 +48,7 @@ export function network(context) {
if (data !== undefined) { if (data !== undefined) {
finalConfig.data = data; finalConfig.data = data;
} }
return context.network.request(transformRequest(finalConfig)); return context.callNative('network', 'request', transformRequest(finalConfig));
}, },
delete: (url, data, config) => { delete: (url, data, config) => {
let finalConfig = config; let finalConfig = config;
@ -57,7 +57,7 @@ export function network(context) {
} }
finalConfig.url = url; finalConfig.url = url;
finalConfig.method = "delete"; finalConfig.method = "delete";
return context.network.request(transformRequest(finalConfig)); return context.callNative('network', 'request', transformRequest(finalConfig));
}, },
}; };
} }

View File

@ -4,15 +4,15 @@ export function notification(context) {
if (args.data !== undefined) { if (args.data !== undefined) {
args.data = JSON.stringify(args.data); args.data = JSON.stringify(args.data);
} }
return context.notification.publish(args); return context.callNative('notification', 'publish', args);
}, },
subscribe: (args) => { subscribe: (args) => {
args.callback = context.function2Id(args.callback); args.callback = context.function2Id(args.callback);
return context.notification.subscribe(args); return context.callNative('notification', 'subscribe', args);
}, },
unsubscribe: (subscribeId) => { unsubscribe: (subscribeId) => {
context.removeFuncById(subscribeId); context.removeFuncById(subscribeId);
return context.notification.unsubscribe(subscribeId); return context.callNative('notification', 'unsubscribe', subscribeId);
} }
}; };
} }

View File

@ -10,7 +10,7 @@ export function popover(context) {
if (panel) { if (panel) {
panel.addHeadView("popover", view); panel.addHeadView("popover", view);
} }
return context.popover.show(view.toModel()); return context.callNative('popover', 'show', view.toModel());
}, },
dismiss: (view = undefined) => { dismiss: (view = undefined) => {
if (panel) { if (panel) {
@ -21,7 +21,7 @@ export function popover(context) {
panel.clearHeadViews("popover"); panel.clearHeadViews("popover");
} }
} }
return context.popover.dismiss(view ? { id: view.viewId } : undefined); return context.callNative('popover', 'dismiss', view ? { id: view.viewId } : undefined);
}, },
}; };
} }

View File

@ -6,13 +6,13 @@ export var StatusBarMode;
export function statusbar(context) { export function statusbar(context) {
return { return {
setHidden: (hidden) => { setHidden: (hidden) => {
return context.statusbar.setHidden({ hidden }); return context.callNative('statusbar', 'setHidden', { hidden });
}, },
setMode: (mode) => { setMode: (mode) => {
return context.statusbar.setMode({ mode }); return context.callNative('statusbar', 'setMode', { mode });
}, },
setColor: (color) => { setColor: (color) => {
return context.statusbar.setColor({ color: color.toModel() }); return context.callNative('statusbar', 'setColor', { color: color.toModel() });
}, },
}; };
} }

View File

@ -1,16 +1,16 @@
export function storage(context) { export function storage(context) {
return { return {
setItem: (key, value, zone) => { setItem: (key, value, zone) => {
return context.storage.setItem({ key, value, zone }); return context.callNative('storage', 'setItem', { key, value, zone });
}, },
getItem: (key, zone) => { getItem: (key, zone) => {
return context.storage.getItem({ key, zone }); return context.callNative('storage', 'getItem', { key, zone });
}, },
remove: (key, zone) => { remove: (key, zone) => {
return context.storage.remove({ key, zone }); return context.callNative('storage', 'remove', { key, zone });
}, },
clear: (zone) => { clear: (zone) => {
return context.storage.clear({ zone }); return context.callNative('storage', 'clear', { zone });
}, },
}; };
} }

View File

@ -1,8 +1,30 @@
export * from 'reflect-metadata'; export * from 'reflect-metadata';
export declare type BridgeContext = { export declare type BridgeContext = {
[index: string]: { /**
[index: string]: (args?: any) => Promise<any>; * The identify of current context
}; */
id: string;
/**
* In this case,It's current panel
*/
entity: any;
/**
* call native plugin
* @param namespace
* @param method
* @param args
*/
callNative(namespace: string, method: string, args?: any): Promise<any>;
/**
* Transform function to functionId as string
* @param func
*/
function2Id(func: Function): string;
/**
* Remove transformed functions
* @param funcId
*/
removeFuncById(funcId: string): void;
}; };
declare global { declare global {
const context: BridgeContext; const context: BridgeContext;

View File

@ -131,7 +131,7 @@ export declare abstract class View implements Modeling, IView {
also(block: (it: this) => void): this; also(block: (it: this) => void): this;
apply(config: IView): this; apply(config: IView): this;
in(group: Group): this; in(group: Group): this;
nativeChannel(context: any, name: string): (args?: any) => Promise<any>; nativeChannel(context: BridgeContext, name: string): (args?: any) => Promise<any>;
getWidth(context: BridgeContext): Promise<number>; getWidth(context: BridgeContext): Promise<number>;
getHeight(context: BridgeContext): Promise<number>; getHeight(context: BridgeContext): Promise<number>;
getLocationOnScreen(context: BridgeContext): Promise<{ getLocationOnScreen(context: BridgeContext): Promise<{

View File

@ -149,7 +149,6 @@ export class View {
nativeChannel(context, name) { nativeChannel(context, name) {
let thisView = this; let thisView = this;
return function (args = undefined) { return function (args = undefined) {
const func = context.shader.command;
const viewIds = []; const viewIds = [];
while (thisView != undefined) { while (thisView != undefined) {
viewIds.push(thisView.viewId); viewIds.push(thisView.viewId);
@ -160,7 +159,7 @@ export class View {
name, name,
args, args,
}; };
return Reflect.apply(func, undefined, [params]); return context.callNative('shader', 'command', params);
}; };
} }
getWidth(context) { getWidth(context) {
@ -222,10 +221,6 @@ __decorate([
Property, Property,
__metadata("design:type", Boolean) __metadata("design:type", Boolean)
], View.prototype, "hidden", void 0); ], View.prototype, "hidden", void 0);
__decorate([
Property,
__metadata("design:type", Object)
], View.prototype, "viewId", void 0);
__decorate([ __decorate([
Property, Property,
__metadata("design:type", Object) __metadata("design:type", Object)

View File

@ -24,35 +24,32 @@ export function animate(context: BridgeContext) {
const entity = context.entity const entity = context.entity
if (entity instanceof Panel) { if (entity instanceof Panel) {
let panel = entity let panel = entity
return (args: { return async (args: {
animations: () => void, animations: () => void,
duration: number, duration: number,
}) => { }) => {
return takeLet(panel.context.animate)(it => { await context.callNative('animate', 'submit')
return it.submit().then(() => { args.animations()
args.animations() return takeLet(panel.getRootView())(root => {
return takeLet(panel.getRootView())(root => { if (root.isDirty()) {
if (root.isDirty()) { const model = root.toModel();
const model = root.toModel(); (model as any).duration = args.duration
(model as any).duration = args.duration const ret = context.callNative('animate', 'animateRender', model)
const ret = it.animateRender(model) root.clean()
root.clean() return ret
return ret }
for (let map of panel.allHeadViews()) {
for (let v of map.values()) {
if (v.isDirty()) {
const model_1 = v.toModel()
const ret_1 = context.callNative('animate', 'animateRender', model_1)
v.clean()
return ret_1
} }
for (let map of panel.allHeadViews()) { }
for (let v of map.values()) { }
if (v.isDirty()) { throw new Error('Cannot find any animated elements')
const model = v.toModel() })
const ret = it.animateRender(model)
it.clean()
return ret
}
}
}
throw new Error('Cannot find any animated elements')
})
})
}) as Promise<any>
} }
} else { } else {
return (args: { return (args: {

View File

@ -19,7 +19,7 @@ import { Gravity } from "../util/gravity"
export function modal(context: BridgeContext) { export function modal(context: BridgeContext) {
return { return {
toast: (msg: string, gravity: Gravity = Gravity.Bottom) => { toast: (msg: string, gravity: Gravity = Gravity.Bottom) => {
context.modal.toast({ context.callNative('modal', 'toast', {
msg, msg,
gravity: gravity.toModel(), gravity: gravity.toModel(),
}) })
@ -30,9 +30,9 @@ export function modal(context: BridgeContext) {
okLabel?: string, okLabel?: string,
}) => { }) => {
if (typeof arg === 'string') { if (typeof arg === 'string') {
return context.modal.alert({ msg: arg }) return context.callNative('modal', 'alert', { msg: arg })
} else { } else {
return context.modal.alert(arg) return context.callNative('modal', 'alert', arg)
} }
}, },
confirm: (arg: string | { confirm: (arg: string | {
@ -42,9 +42,9 @@ export function modal(context: BridgeContext) {
cancelLabel?: string, cancelLabel?: string,
}) => { }) => {
if (typeof arg === 'string') { if (typeof arg === 'string') {
return context.modal.confirm({ msg: arg }) return context.callNative('modal', 'confirm', { msg: arg })
} else { } else {
return context.modal.confirm(arg) return context.callNative('modal', 'confirm', arg)
} }
}, },
prompt: (arg: { prompt: (arg: {
@ -55,7 +55,7 @@ export function modal(context: BridgeContext) {
text?: string, text?: string,
defaultText?: string, defaultText?: string,
}) => { }) => {
return context.modal.prompt(arg) as Promise<string> return context.callNative('modal', 'prompt', arg) as Promise<string>
}, },
} }
} }

View File

@ -27,36 +27,30 @@ export function navbar(context: BridgeContext) {
return { return {
isHidden: () => { isHidden: () => {
return context.navbar.isHidden() as Promise<boolean> return context.callNative('navbar', 'isHidden') as Promise<boolean>
}, },
setHidden: (hidden: boolean) => { setHidden: (hidden: boolean) => {
return context.navbar.setHidden({ return context.callNative('navbar', 'setHidden', { hidden, })
hidden,
})
}, },
setTitle: (title: string) => { setTitle: (title: string) => {
return context.navbar.setTitle({ return context.callNative('navbar', 'setTitle', { title, })
title,
})
}, },
setBgColor: (color: Color) => { setBgColor: (color: Color) => {
return context.navbar.setBgColor({ return context.callNative('navbar', 'setBgColor', { color: color.toModel(), })
color: color.toModel(),
})
}, },
setLeft: (view: View) => { setLeft: (view: View) => {
if (panel) { if (panel) {
panel.clearHeadViews("navbar_left") panel.clearHeadViews("navbar_left")
panel.addHeadView("navbar_left", view) panel.addHeadView("navbar_left", view)
} }
return context.navbar.setLeft(view.toModel()) return context.callNative('navbar', 'setLeft', view.toModel())
}, },
setRight: (view: View) => { setRight: (view: View) => {
if (panel) { if (panel) {
panel.clearHeadViews("navbar_right") panel.clearHeadViews("navbar_right")
panel.addHeadView("navbar_right", view) panel.addHeadView("navbar_right", view)
} }
return context.navbar.setRight(view.toModel()) return context.callNative('navbar', 'setRight', view.toModel())
} }
} }
} }

View File

@ -25,12 +25,12 @@ export function navigator(context: BridgeContext) {
if (config && config.extra) { if (config && config.extra) {
(config as any).extra = JSON.stringify(config.extra) (config as any).extra = JSON.stringify(config.extra)
} }
return context.navigator.push({ return context.callNative('navigator', 'push', {
scheme, config scheme, config
}) })
}, },
pop: (animated = true) => { pop: (animated = true) => {
return context.navigator.pop({ animated }) return context.callNative('navigator', 'pop', { animated })
}, },
} }
} }

View File

@ -61,7 +61,7 @@ function transformRequest(request: IRequest) {
export function network(context: BridgeContext) { export function network(context: BridgeContext) {
return { return {
request: (config: IRequest) => { request: (config: IRequest) => {
return context.network.request(transformRequest(config)) as Promise<IResponse> return context.callNative('network', 'request', transformRequest(config)) as Promise<IResponse>
}, },
get: (url: string, config?: IRequest) => { get: (url: string, config?: IRequest) => {
let finalConfig = config let finalConfig = config
@ -70,7 +70,7 @@ export function network(context: BridgeContext) {
} }
finalConfig.url = url finalConfig.url = url
finalConfig.method = "get" finalConfig.method = "get"
return context.network.request(transformRequest(finalConfig)) as Promise<IResponse> return context.callNative('network', 'request', transformRequest(finalConfig)) as Promise<IResponse>
}, },
post: (url: string, data?: object | string, config?: IRequest) => { post: (url: string, data?: object | string, config?: IRequest) => {
let finalConfig = config let finalConfig = config
@ -82,7 +82,7 @@ export function network(context: BridgeContext) {
if (data !== undefined) { if (data !== undefined) {
finalConfig.data = data finalConfig.data = data
} }
return context.network.request(transformRequest(finalConfig)) as Promise<IResponse> return context.callNative('network', 'request', transformRequest(finalConfig)) as Promise<IResponse>
}, },
put: (url: string, data?: object | string, config?: IRequest) => { put: (url: string, data?: object | string, config?: IRequest) => {
let finalConfig = config let finalConfig = config
@ -94,7 +94,7 @@ export function network(context: BridgeContext) {
if (data !== undefined) { if (data !== undefined) {
finalConfig.data = data finalConfig.data = data
} }
return context.network.request(transformRequest(finalConfig)) as Promise<IResponse> return context.callNative('network', 'request', transformRequest(finalConfig)) as Promise<IResponse>
}, },
delete: (url: string, data?: object | string, config?: IRequest) => { delete: (url: string, data?: object | string, config?: IRequest) => {
let finalConfig = config let finalConfig = config
@ -103,7 +103,7 @@ export function network(context: BridgeContext) {
} }
finalConfig.url = url finalConfig.url = url
finalConfig.method = "delete" finalConfig.method = "delete"
return context.network.request(transformRequest(finalConfig)) as Promise<IResponse> return context.callNative('network', 'request', transformRequest(finalConfig)) as Promise<IResponse>
}, },
} }
} }

View File

@ -20,15 +20,15 @@ export function notification(context: BridgeContext) {
if (args.data !== undefined) { if (args.data !== undefined) {
(args as any).data = JSON.stringify(args.data) (args as any).data = JSON.stringify(args.data)
} }
return context.notification.publish(args) return context.callNative('notification', 'publish', args)
}, },
subscribe: (args: { biz?: string, name: string, callback: (data?: any) => void, androidSystem?: boolean }) => { subscribe: (args: { biz?: string, name: string, callback: (data?: any) => void, androidSystem?: boolean }) => {
(args as any).callback = (context as any).function2Id(args.callback) (args as any).callback = context.function2Id(args.callback)
return context.notification.subscribe(args) as Promise<string> return context.callNative('notification', 'subscribe', args) as Promise<string>
}, },
unsubscribe: (subscribeId: string) => { unsubscribe: (subscribeId: string) => {
(context as any).removeFuncById(subscribeId) context.removeFuncById(subscribeId)
return context.notification.unsubscribe(subscribeId) return context.callNative('notification', 'unsubscribe', subscribeId)
} }
} }
} }

View File

@ -28,7 +28,7 @@ export function popover(context: BridgeContext) {
if (panel) { if (panel) {
panel.addHeadView("popover", view) panel.addHeadView("popover", view)
} }
return context.popover.show(view.toModel()) return context.callNative('popover', 'show', view.toModel())
}, },
dismiss: (view: View | undefined = undefined) => { dismiss: (view: View | undefined = undefined) => {
if (panel) { if (panel) {
@ -38,7 +38,7 @@ export function popover(context: BridgeContext) {
panel.clearHeadViews("popover") panel.clearHeadViews("popover")
} }
} }
return context.popover.dismiss(view ? { id: view.viewId } : undefined) return context.callNative('popover', 'dismiss', view ? { id: view.viewId } : undefined)
}, },
} }
} }

View File

@ -21,13 +21,13 @@ export enum StatusBarMode { LIGHT, DARK }
export function statusbar(context: BridgeContext) { export function statusbar(context: BridgeContext) {
return { return {
setHidden: (hidden: boolean) => { setHidden: (hidden: boolean) => {
return context.statusbar.setHidden({hidden}) return context.callNative('statusbar', 'setHidden', { hidden })
}, },
setMode: (mode: StatusBarMode) => { setMode: (mode: StatusBarMode) => {
return context.statusbar.setMode({mode}) return context.callNative('statusbar', 'setMode', { mode })
}, },
setColor: (color: Color) => { setColor: (color: Color) => {
return context.statusbar.setColor({color: color.toModel()}) return context.callNative('statusbar', 'setColor', { color: color.toModel() })
}, },
} }
} }

View File

@ -18,16 +18,16 @@ import { BridgeContext } from "../runtime/global"
export function storage(context: BridgeContext) { export function storage(context: BridgeContext) {
return { return {
setItem: (key: string, value: string, zone?: string) => { setItem: (key: string, value: string, zone?: string) => {
return context.storage.setItem({ key, value, zone }) return context.callNative('storage', 'setItem', { key, value, zone })
}, },
getItem: (key: string, zone?: string) => { getItem: (key: string, zone?: string) => {
return context.storage.getItem({ key, zone }) as Promise<string> return context.callNative('storage', 'getItem', { key, zone }) as Promise<string>
}, },
remove: (key: string, zone?: string) => { remove: (key: string, zone?: string) => {
return context.storage.remove({ key, zone }) return context.callNative('storage', 'remove', { key, zone })
}, },
clear: (zone: string) => { clear: (zone: string) => {
return context.storage.clear({ zone }) return context.callNative('storage', 'clear', { zone })
}, },
} }
} }

View File

@ -16,7 +16,31 @@
export * from 'reflect-metadata' export * from 'reflect-metadata'
export type BridgeContext = { export type BridgeContext = {
[index: string]: { [index: string]: (args?: any) => Promise<any> } /**
* The identify of current context
*/
id: string
/**
* In this case,It's current panel
*/
entity: any
/**
* call native plugin
* @param namespace
* @param method
* @param args
*/
callNative(namespace: string, method: string, args?: any): Promise<any>
/**
* Transform function to functionId as string
* @param func
*/
function2Id(func: Function): string
/**
* Remove transformed functions
* @param funcId
*/
removeFuncById(funcId: string): void
} }
declare global { declare global {

View File

@ -157,7 +157,7 @@ export abstract class Panel {
} }
private nativeRender(model: Model) { private nativeRender(model: Model) {
(this.context as any).callNative("shader", "render", model) this.context.callNative("shader", "render", model)
} }
private hookBeforeNativeCall() { private hookBeforeNativeCall() {

View File

@ -122,7 +122,6 @@ export abstract class View implements Modeling, IView {
@Property @Property
hidden?: boolean hidden?: boolean
@Property
viewId = uniqueId('ViewId') viewId = uniqueId('ViewId')
@Property @Property
@ -152,6 +151,9 @@ export abstract class View implements Modeling, IView {
} }
private id2Callback(id: string) { private id2Callback(id: string) {
if (this.callbacks === undefined) {
this.callbacks = new Map
}
let f = this.callbacks.get(id) let f = this.callbacks.get(id)
if (f === undefined) { if (f === undefined) {
f = Reflect.get(this, id) as Function f = Reflect.get(this, id) as Function
@ -280,10 +282,9 @@ export abstract class View implements Modeling, IView {
return this return this
} }
nativeChannel(context: any, name: string) { nativeChannel(context: BridgeContext, name: string) {
let thisView: View | undefined = this let thisView: View | undefined = this
return function (args: any = undefined) { return function (args: any = undefined) {
const func = context.shader.command
const viewIds = [] const viewIds = []
while (thisView != undefined) { while (thisView != undefined) {
viewIds.push(thisView.viewId) viewIds.push(thisView.viewId)
@ -294,7 +295,8 @@ export abstract class View implements Modeling, IView {
name, name,
args, args,
} }
return Reflect.apply(func, undefined, [params]) as Promise<any>
return context.callNative('shader', 'command', params) as Promise<any>
} }
} }

View File

@ -109,7 +109,6 @@ export abstract class View implements Modeling, IView {
@Property @Property
hidden?: boolean hidden?: boolean
@Property
viewId = uniqueId('ViewId') viewId = uniqueId('ViewId')
@Property @Property
@ -278,10 +277,9 @@ export abstract class View implements Modeling, IView {
return this return this
} }
nativeChannel(context: any, name: string) { nativeChannel(context: BridgeContext, name: string) {
let thisView: View | undefined = this let thisView: View | undefined = this
return function (args: any = undefined) { return function (args: any = undefined) {
const func = context.shader.command
const viewIds = [] const viewIds = []
while (thisView != undefined) { while (thisView != undefined) {
viewIds.push(thisView.viewId) viewIds.push(thisView.viewId)
@ -292,7 +290,8 @@ export abstract class View implements Modeling, IView {
name, name,
args, args,
} }
return Reflect.apply(func, undefined, [params]) as Promise<any>
return context.callNative('shader', 'command', params) as Promise<any>
} }
} }