iOS:add ListItem actions api

This commit is contained in:
pengfei.zhou
2021-04-23 19:05:33 +08:00
committed by osborn
parent cc7df5d2ca
commit e18b7e781e
18 changed files with 167 additions and 36 deletions

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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);