iOS:add ListItem actions api
This commit is contained in:
@@ -2,9 +2,12 @@
|
||||
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
|
||||
function obj2Model(obj) {
|
||||
if (obj instanceof Array) {
|
||||
return obj.map(function (e) { return obj2Model(e); });
|
||||
function obj2Model(obj, convertor) {
|
||||
if (obj instanceof Function) {
|
||||
return convertor(obj);
|
||||
}
|
||||
else if (obj instanceof Array) {
|
||||
return obj.map(function (e) { return obj2Model(e, convertor); });
|
||||
}
|
||||
else if (obj instanceof Object) {
|
||||
if (Reflect.has(obj, 'toModel') && Reflect.get(obj, 'toModel') instanceof Function) {
|
||||
@@ -14,7 +17,7 @@ function obj2Model(obj) {
|
||||
else {
|
||||
for (var key in obj) {
|
||||
var val = Reflect.get(obj, key);
|
||||
Reflect.set(obj, key, obj2Model(val));
|
||||
Reflect.set(obj, key, obj2Model(val, convertor));
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
@@ -298,11 +301,12 @@ var View = /** @class */ (function () {
|
||||
configurable: true
|
||||
});
|
||||
View.prototype.onPropertyChanged = function (propKey, oldV, newV) {
|
||||
var _this = this;
|
||||
if (newV instanceof Function) {
|
||||
newV = this.callback2Id(newV);
|
||||
}
|
||||
else {
|
||||
newV = obj2Model(newV);
|
||||
newV = obj2Model(newV, function (v) { return _this.callback2Id(v); });
|
||||
}
|
||||
if (this.__dirty_props__ === undefined) {
|
||||
this.__dirty_props__ = {};
|
||||
@@ -2048,6 +2052,10 @@ var ListItem = /** @class */ (function (_super) {
|
||||
Property,
|
||||
__metadata$8("design:type", String)
|
||||
], ListItem.prototype, "identifier", void 0);
|
||||
__decorate$8([
|
||||
Property,
|
||||
__metadata$8("design:type", Array)
|
||||
], ListItem.prototype, "actions", void 0);
|
||||
return ListItem;
|
||||
}(Stack));
|
||||
var List = /** @class */ (function (_super) {
|
||||
|
||||
@@ -2,9 +2,12 @@
|
||||
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
|
||||
function obj2Model(obj) {
|
||||
if (obj instanceof Array) {
|
||||
return obj.map(e => obj2Model(e));
|
||||
function obj2Model(obj, convertor) {
|
||||
if (obj instanceof Function) {
|
||||
return convertor(obj);
|
||||
}
|
||||
else if (obj instanceof Array) {
|
||||
return obj.map(e => obj2Model(e, convertor));
|
||||
}
|
||||
else if (obj instanceof Object) {
|
||||
if (Reflect.has(obj, 'toModel') && Reflect.get(obj, 'toModel') instanceof Function) {
|
||||
@@ -14,7 +17,7 @@ function obj2Model(obj) {
|
||||
else {
|
||||
for (let key in obj) {
|
||||
const val = Reflect.get(obj, key);
|
||||
Reflect.set(obj, key, obj2Model(val));
|
||||
Reflect.set(obj, key, obj2Model(val, convertor));
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
@@ -228,7 +231,7 @@ class View {
|
||||
newV = this.callback2Id(newV);
|
||||
}
|
||||
else {
|
||||
newV = obj2Model(newV);
|
||||
newV = obj2Model(newV, (v) => this.callback2Id(v));
|
||||
}
|
||||
this.__dirty_props__[propKey] = newV;
|
||||
}
|
||||
@@ -1548,6 +1551,10 @@ __decorate$8([
|
||||
Property,
|
||||
__metadata$8("design:type", String)
|
||||
], ListItem.prototype, "identifier", void 0);
|
||||
__decorate$8([
|
||||
Property,
|
||||
__metadata$8("design:type", Array)
|
||||
], ListItem.prototype, "actions", void 0);
|
||||
class List extends Superview {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
|
||||
@@ -1593,9 +1593,12 @@ var doric = /*#__PURE__*/Object.freeze({
|
||||
jsCallbackTimer: jsCallbackTimer
|
||||
});
|
||||
|
||||
function obj2Model(obj) {
|
||||
if (obj instanceof Array) {
|
||||
return obj.map(e => obj2Model(e));
|
||||
function obj2Model(obj, convertor) {
|
||||
if (obj instanceof Function) {
|
||||
return convertor(obj);
|
||||
}
|
||||
else if (obj instanceof Array) {
|
||||
return obj.map(e => obj2Model(e, convertor));
|
||||
}
|
||||
else if (obj instanceof Object) {
|
||||
if (Reflect.has(obj, 'toModel') && Reflect.get(obj, 'toModel') instanceof Function) {
|
||||
@@ -1605,7 +1608,7 @@ function obj2Model(obj) {
|
||||
else {
|
||||
for (let key in obj) {
|
||||
const val = Reflect.get(obj, key);
|
||||
Reflect.set(obj, key, obj2Model(val));
|
||||
Reflect.set(obj, key, obj2Model(val, convertor));
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
@@ -1749,7 +1752,7 @@ class View {
|
||||
newV = this.callback2Id(newV);
|
||||
}
|
||||
else {
|
||||
newV = obj2Model(newV);
|
||||
newV = obj2Model(newV, (v) => this.callback2Id(v));
|
||||
}
|
||||
this.__dirty_props__[propKey] = newV;
|
||||
}
|
||||
@@ -3069,6 +3072,10 @@ __decorate$8([
|
||||
Property,
|
||||
__metadata$8("design:type", String)
|
||||
], ListItem.prototype, "identifier", void 0);
|
||||
__decorate$8([
|
||||
Property,
|
||||
__metadata$8("design:type", Array)
|
||||
], ListItem.prototype, "actions", void 0);
|
||||
class List extends Superview {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
|
||||
8
doric-js/index.d.ts
vendored
8
doric-js/index.d.ts
vendored
@@ -587,11 +587,17 @@ declare module 'doric/lib/src/widget/list' {
|
||||
import { View, Superview, NativeViewModel } from "doric/lib/src/ui/view";
|
||||
import { Stack } from "doric/lib/src/widget/layouts";
|
||||
import { BridgeContext } from "doric/lib/src/runtime/global";
|
||||
import { Color } from "doric/lib/src/util/color";
|
||||
export class ListItem extends Stack {
|
||||
/**
|
||||
* Set to reuse native view
|
||||
*/
|
||||
identifier?: string;
|
||||
actions?: {
|
||||
title: string;
|
||||
backgroundColor?: Color;
|
||||
callback: () => void;
|
||||
}[];
|
||||
}
|
||||
export class List extends Superview {
|
||||
allSubviews(): IterableIterator<ListItem> | ListItem[];
|
||||
@@ -1187,7 +1193,7 @@ declare module 'doric/lib/src/util/types' {
|
||||
export interface Modeling {
|
||||
toModel(): Model;
|
||||
}
|
||||
export function obj2Model(obj: Model): Model;
|
||||
export function obj2Model(obj: Model, convertor: (v: Function) => string): Model;
|
||||
type _M = string | number | boolean | Modeling | {
|
||||
[index: string]: Model;
|
||||
} | undefined;
|
||||
|
||||
@@ -113,7 +113,7 @@ export class View {
|
||||
newV = this.callback2Id(newV);
|
||||
}
|
||||
else {
|
||||
newV = obj2Model(newV);
|
||||
newV = obj2Model(newV, (v) => this.callback2Id(v));
|
||||
}
|
||||
this.__dirty_props__[propKey] = newV;
|
||||
}
|
||||
|
||||
2
doric-js/lib/src/util/types.d.ts
vendored
2
doric-js/lib/src/util/types.d.ts
vendored
@@ -1,7 +1,7 @@
|
||||
export interface Modeling {
|
||||
toModel(): Model;
|
||||
}
|
||||
export declare function obj2Model(obj: Model): Model;
|
||||
export declare function obj2Model(obj: Model, convertor: (v: Function) => string): Model;
|
||||
declare type _M = string | number | boolean | Modeling | {
|
||||
[index: string]: Model;
|
||||
} | undefined;
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
export function obj2Model(obj) {
|
||||
if (obj instanceof Array) {
|
||||
return obj.map(e => obj2Model(e));
|
||||
export function obj2Model(obj, convertor) {
|
||||
if (obj instanceof Function) {
|
||||
return convertor(obj);
|
||||
}
|
||||
else if (obj instanceof Array) {
|
||||
return obj.map(e => obj2Model(e, convertor));
|
||||
}
|
||||
else if (obj instanceof Object) {
|
||||
if (Reflect.has(obj, 'toModel') && Reflect.get(obj, 'toModel') instanceof Function) {
|
||||
@@ -10,7 +13,7 @@ export function obj2Model(obj) {
|
||||
else {
|
||||
for (let key in obj) {
|
||||
const val = Reflect.get(obj, key);
|
||||
Reflect.set(obj, key, obj2Model(val));
|
||||
Reflect.set(obj, key, obj2Model(val, convertor));
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
6
doric-js/lib/src/widget/list.d.ts
vendored
6
doric-js/lib/src/widget/list.d.ts
vendored
@@ -1,11 +1,17 @@
|
||||
import { View, Superview, NativeViewModel } from "../ui/view";
|
||||
import { Stack } from "./layouts";
|
||||
import { BridgeContext } from "../runtime/global";
|
||||
import { Color } from "../util/color";
|
||||
export declare class ListItem extends Stack {
|
||||
/**
|
||||
* Set to reuse native view
|
||||
*/
|
||||
identifier?: string;
|
||||
actions?: {
|
||||
title: string;
|
||||
backgroundColor?: Color;
|
||||
callback: () => void;
|
||||
}[];
|
||||
}
|
||||
export declare class List extends Superview {
|
||||
private cachedViews;
|
||||
|
||||
@@ -31,6 +31,10 @@ __decorate([
|
||||
Property,
|
||||
__metadata("design:type", String)
|
||||
], ListItem.prototype, "identifier", void 0);
|
||||
__decorate([
|
||||
Property,
|
||||
__metadata("design:type", Array)
|
||||
], ListItem.prototype, "actions", void 0);
|
||||
export class List extends Superview {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
|
||||
@@ -193,7 +193,7 @@ export abstract class View implements Modeling {
|
||||
if (newV instanceof Function) {
|
||||
newV = this.callback2Id(newV)
|
||||
} else {
|
||||
newV = obj2Model(newV)
|
||||
newV = obj2Model(newV, (v) => this.callback2Id(v))
|
||||
}
|
||||
if (this.__dirty_props__ === undefined) {
|
||||
this.__dirty_props__ = {}
|
||||
|
||||
@@ -199,7 +199,7 @@ export abstract class View implements Modeling {
|
||||
if (newV instanceof Function) {
|
||||
newV = this.callback2Id(newV)
|
||||
} else {
|
||||
newV = obj2Model(newV)
|
||||
newV = obj2Model(newV, (v) => this.callback2Id(v))
|
||||
}
|
||||
this.__dirty_props__[propKey] = newV
|
||||
}
|
||||
|
||||
@@ -16,9 +16,11 @@
|
||||
export interface Modeling {
|
||||
toModel(): Model
|
||||
}
|
||||
export function obj2Model(obj: Model): Model {
|
||||
if (obj instanceof Array) {
|
||||
return obj.map(e => obj2Model(e)) as Model
|
||||
export function obj2Model(obj: Model, convertor: (v: Function) => string): Model {
|
||||
if (obj instanceof Function) {
|
||||
return convertor(obj)
|
||||
} else if (obj instanceof Array) {
|
||||
return obj.map(e => obj2Model(e, convertor)) as Model
|
||||
} else if (obj instanceof Object) {
|
||||
if (Reflect.has(obj, 'toModel') && Reflect.get(obj, 'toModel') instanceof Function) {
|
||||
obj = Reflect.apply(Reflect.get(obj, 'toModel'), obj, [])
|
||||
@@ -26,7 +28,7 @@ export function obj2Model(obj: Model): Model {
|
||||
} else {
|
||||
for (let key in obj) {
|
||||
const val = Reflect.get(obj, key)
|
||||
Reflect.set(obj, key, obj2Model(val))
|
||||
Reflect.set(obj, key, obj2Model(val, convertor))
|
||||
}
|
||||
return obj
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ import { View, Property, Superview, NativeViewModel } from "../ui/view";
|
||||
import { Stack } from "./layouts";
|
||||
import { layoutConfig } from "../util/layoutconfig";
|
||||
import { BridgeContext } from "../runtime/global";
|
||||
|
||||
import { Color } from "../util/color";
|
||||
|
||||
export class ListItem extends Stack {
|
||||
/**
|
||||
@@ -26,6 +26,13 @@ export class ListItem extends Stack {
|
||||
*/
|
||||
@Property
|
||||
identifier?: string
|
||||
|
||||
@Property
|
||||
actions?: {
|
||||
title: string,
|
||||
backgroundColor?: Color,
|
||||
callback: () => void,
|
||||
}[]
|
||||
}
|
||||
|
||||
export class List extends Superview {
|
||||
|
||||
Reference in New Issue
Block a user