iOS:add ListItem actions api
This commit is contained in:
@@ -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