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

@@ -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__ = {}

View File

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

View File

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

View File

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