js:compat es5,use context.sendNative to replace Proxy
This commit is contained in:
2
doric-js/lib/src/native/animate.d.ts
vendored
2
doric-js/lib/src/native/animate.d.ts
vendored
@@ -6,4 +6,4 @@ import { BridgeContext } from "../runtime/global";
|
||||
export declare function animate(context: BridgeContext): (args: {
|
||||
animations: () => void;
|
||||
duration: number;
|
||||
}) => Promise<any>;
|
||||
}) => Promise<unknown>;
|
||||
|
@@ -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]
|
||||
*
|
||||
@@ -23,33 +32,30 @@ export function animate(context) {
|
||||
const entity = context.entity;
|
||||
if (entity instanceof Panel) {
|
||||
let panel = entity;
|
||||
return (args) => {
|
||||
return takeLet(panel.context.animate)(it => {
|
||||
return it.submit().then(() => {
|
||||
args.animations();
|
||||
return takeLet(panel.getRootView())(root => {
|
||||
if (root.isDirty()) {
|
||||
const model = root.toModel();
|
||||
model.duration = args.duration;
|
||||
const ret = it.animateRender(model);
|
||||
root.clean();
|
||||
return ret;
|
||||
return (args) => __awaiter(this, void 0, void 0, function* () {
|
||||
yield context.callNative('animate', 'submit');
|
||||
args.animations();
|
||||
return takeLet(panel.getRootView())(root => {
|
||||
if (root.isDirty()) {
|
||||
const model = root.toModel();
|
||||
model.duration = args.duration;
|
||||
const ret = context.callNative('animate', 'animateRender', model);
|
||||
root.clean();
|
||||
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()) {
|
||||
const model = v.toModel();
|
||||
const ret = it.animateRender(model);
|
||||
it.clean();
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new Error('Cannot find any animated elements');
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
throw new Error('Cannot find any animated elements');
|
||||
});
|
||||
};
|
||||
});
|
||||
}
|
||||
else {
|
||||
return (args) => {
|
||||
|
@@ -2,29 +2,29 @@ import { Gravity } from "../util/gravity";
|
||||
export function modal(context) {
|
||||
return {
|
||||
toast: (msg, gravity = Gravity.Bottom) => {
|
||||
context.modal.toast({
|
||||
context.callNative('modal', 'toast', {
|
||||
msg,
|
||||
gravity: gravity.toModel(),
|
||||
});
|
||||
},
|
||||
alert: (arg) => {
|
||||
if (typeof arg === 'string') {
|
||||
return context.modal.alert({ msg: arg });
|
||||
return context.callNative('modal', 'alert', { msg: arg });
|
||||
}
|
||||
else {
|
||||
return context.modal.alert(arg);
|
||||
return context.callNative('modal', 'alert', arg);
|
||||
}
|
||||
},
|
||||
confirm: (arg) => {
|
||||
if (typeof arg === 'string') {
|
||||
return context.modal.confirm({ msg: arg });
|
||||
return context.callNative('modal', 'confirm', { msg: arg });
|
||||
}
|
||||
else {
|
||||
return context.modal.confirm(arg);
|
||||
return context.callNative('modal', 'confirm', arg);
|
||||
}
|
||||
},
|
||||
prompt: (arg) => {
|
||||
return context.modal.prompt(arg);
|
||||
return context.callNative('modal', 'prompt', arg);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
@@ -7,36 +7,30 @@ export function navbar(context) {
|
||||
}
|
||||
return {
|
||||
isHidden: () => {
|
||||
return context.navbar.isHidden();
|
||||
return context.callNative('navbar', 'isHidden');
|
||||
},
|
||||
setHidden: (hidden) => {
|
||||
return context.navbar.setHidden({
|
||||
hidden,
|
||||
});
|
||||
return context.callNative('navbar', 'setHidden', { hidden, });
|
||||
},
|
||||
setTitle: (title) => {
|
||||
return context.navbar.setTitle({
|
||||
title,
|
||||
});
|
||||
return context.callNative('navbar', 'setTitle', { title, });
|
||||
},
|
||||
setBgColor: (color) => {
|
||||
return context.navbar.setBgColor({
|
||||
color: color.toModel(),
|
||||
});
|
||||
return context.callNative('navbar', 'setBgColor', { color: color.toModel(), });
|
||||
},
|
||||
setLeft: (view) => {
|
||||
if (panel) {
|
||||
panel.clearHeadViews("navbar_left");
|
||||
panel.addHeadView("navbar_left", view);
|
||||
}
|
||||
return context.navbar.setLeft(view.toModel());
|
||||
return context.callNative('navbar', 'setLeft', view.toModel());
|
||||
},
|
||||
setRight: (view) => {
|
||||
if (panel) {
|
||||
panel.clearHeadViews("navbar_right");
|
||||
panel.addHeadView("navbar_right", view);
|
||||
}
|
||||
return context.navbar.setRight(view.toModel());
|
||||
return context.callNative('navbar', 'setRight', view.toModel());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@@ -4,12 +4,12 @@ export function navigator(context) {
|
||||
if (config && config.extra) {
|
||||
config.extra = JSON.stringify(config.extra);
|
||||
}
|
||||
return context.navigator.push({
|
||||
return context.callNative('navigator', 'push', {
|
||||
scheme, config
|
||||
});
|
||||
},
|
||||
pop: (animated = true) => {
|
||||
return context.navigator.pop({ animated });
|
||||
return context.callNative('navigator', 'pop', { animated });
|
||||
},
|
||||
};
|
||||
}
|
||||
|
@@ -15,7 +15,7 @@ function transformRequest(request) {
|
||||
export function network(context) {
|
||||
return {
|
||||
request: (config) => {
|
||||
return context.network.request(transformRequest(config));
|
||||
return context.callNative('network', 'request', transformRequest(config));
|
||||
},
|
||||
get: (url, config) => {
|
||||
let finalConfig = config;
|
||||
@@ -24,7 +24,7 @@ export function network(context) {
|
||||
}
|
||||
finalConfig.url = url;
|
||||
finalConfig.method = "get";
|
||||
return context.network.request(transformRequest(finalConfig));
|
||||
return context.callNative('network', 'request', transformRequest(finalConfig));
|
||||
},
|
||||
post: (url, data, config) => {
|
||||
let finalConfig = config;
|
||||
@@ -36,7 +36,7 @@ export function network(context) {
|
||||
if (data !== undefined) {
|
||||
finalConfig.data = data;
|
||||
}
|
||||
return context.network.request(transformRequest(finalConfig));
|
||||
return context.callNative('network', 'request', transformRequest(finalConfig));
|
||||
},
|
||||
put: (url, data, config) => {
|
||||
let finalConfig = config;
|
||||
@@ -48,7 +48,7 @@ export function network(context) {
|
||||
if (data !== undefined) {
|
||||
finalConfig.data = data;
|
||||
}
|
||||
return context.network.request(transformRequest(finalConfig));
|
||||
return context.callNative('network', 'request', transformRequest(finalConfig));
|
||||
},
|
||||
delete: (url, data, config) => {
|
||||
let finalConfig = config;
|
||||
@@ -57,7 +57,7 @@ export function network(context) {
|
||||
}
|
||||
finalConfig.url = url;
|
||||
finalConfig.method = "delete";
|
||||
return context.network.request(transformRequest(finalConfig));
|
||||
return context.callNative('network', 'request', transformRequest(finalConfig));
|
||||
},
|
||||
};
|
||||
}
|
||||
|
@@ -4,15 +4,15 @@ export function notification(context) {
|
||||
if (args.data !== undefined) {
|
||||
args.data = JSON.stringify(args.data);
|
||||
}
|
||||
return context.notification.publish(args);
|
||||
return context.callNative('notification', 'publish', args);
|
||||
},
|
||||
subscribe: (args) => {
|
||||
args.callback = context.function2Id(args.callback);
|
||||
return context.notification.subscribe(args);
|
||||
return context.callNative('notification', 'subscribe', args);
|
||||
},
|
||||
unsubscribe: (subscribeId) => {
|
||||
context.removeFuncById(subscribeId);
|
||||
return context.notification.unsubscribe(subscribeId);
|
||||
return context.callNative('notification', 'unsubscribe', subscribeId);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@@ -10,7 +10,7 @@ export function popover(context) {
|
||||
if (panel) {
|
||||
panel.addHeadView("popover", view);
|
||||
}
|
||||
return context.popover.show(view.toModel());
|
||||
return context.callNative('popover', 'show', view.toModel());
|
||||
},
|
||||
dismiss: (view = undefined) => {
|
||||
if (panel) {
|
||||
@@ -21,7 +21,7 @@ export function popover(context) {
|
||||
panel.clearHeadViews("popover");
|
||||
}
|
||||
}
|
||||
return context.popover.dismiss(view ? { id: view.viewId } : undefined);
|
||||
return context.callNative('popover', 'dismiss', view ? { id: view.viewId } : undefined);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
@@ -6,13 +6,13 @@ export var StatusBarMode;
|
||||
export function statusbar(context) {
|
||||
return {
|
||||
setHidden: (hidden) => {
|
||||
return context.statusbar.setHidden({ hidden });
|
||||
return context.callNative('statusbar', 'setHidden', { hidden });
|
||||
},
|
||||
setMode: (mode) => {
|
||||
return context.statusbar.setMode({ mode });
|
||||
return context.callNative('statusbar', 'setMode', { mode });
|
||||
},
|
||||
setColor: (color) => {
|
||||
return context.statusbar.setColor({ color: color.toModel() });
|
||||
return context.callNative('statusbar', 'setColor', { color: color.toModel() });
|
||||
},
|
||||
};
|
||||
}
|
||||
|
@@ -1,16 +1,16 @@
|
||||
export function storage(context) {
|
||||
return {
|
||||
setItem: (key, value, zone) => {
|
||||
return context.storage.setItem({ key, value, zone });
|
||||
return context.callNative('storage', 'setItem', { key, value, zone });
|
||||
},
|
||||
getItem: (key, zone) => {
|
||||
return context.storage.getItem({ key, zone });
|
||||
return context.callNative('storage', 'getItem', { key, zone });
|
||||
},
|
||||
remove: (key, zone) => {
|
||||
return context.storage.remove({ key, zone });
|
||||
return context.callNative('storage', 'remove', { key, zone });
|
||||
},
|
||||
clear: (zone) => {
|
||||
return context.storage.clear({ zone });
|
||||
return context.callNative('storage', 'clear', { zone });
|
||||
},
|
||||
};
|
||||
}
|
||||
|
28
doric-js/lib/src/runtime/global.d.ts
vendored
28
doric-js/lib/src/runtime/global.d.ts
vendored
@@ -1,8 +1,30 @@
|
||||
export * from 'reflect-metadata';
|
||||
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 {
|
||||
const context: BridgeContext;
|
||||
|
2
doric-js/lib/src/ui/view.d.ts
vendored
2
doric-js/lib/src/ui/view.d.ts
vendored
@@ -131,7 +131,7 @@ export declare abstract class View implements Modeling, IView {
|
||||
also(block: (it: this) => void): this;
|
||||
apply(config: IView): 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>;
|
||||
getHeight(context: BridgeContext): Promise<number>;
|
||||
getLocationOnScreen(context: BridgeContext): Promise<{
|
||||
|
@@ -149,7 +149,6 @@ export class View {
|
||||
nativeChannel(context, name) {
|
||||
let thisView = this;
|
||||
return function (args = undefined) {
|
||||
const func = context.shader.command;
|
||||
const viewIds = [];
|
||||
while (thisView != undefined) {
|
||||
viewIds.push(thisView.viewId);
|
||||
@@ -160,7 +159,7 @@ export class View {
|
||||
name,
|
||||
args,
|
||||
};
|
||||
return Reflect.apply(func, undefined, [params]);
|
||||
return context.callNative('shader', 'command', params);
|
||||
};
|
||||
}
|
||||
getWidth(context) {
|
||||
@@ -222,10 +221,6 @@ __decorate([
|
||||
Property,
|
||||
__metadata("design:type", Boolean)
|
||||
], View.prototype, "hidden", void 0);
|
||||
__decorate([
|
||||
Property,
|
||||
__metadata("design:type", Object)
|
||||
], View.prototype, "viewId", void 0);
|
||||
__decorate([
|
||||
Property,
|
||||
__metadata("design:type", Object)
|
||||
|
Reference in New Issue
Block a user