jsbox-cview 1.2.8 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -5,10 +5,11 @@
|
|
|
5
5
|
*
|
|
6
6
|
* 核心策略为 list 的所有行均为 cview,且每一个 cview 需要实现一个方法:heightToWidth(width: number) => number
|
|
7
7
|
* 通过这个方法汇报自己在某个宽度的时候所需要的高度,这必须任何时候均立即可用;
|
|
8
|
-
* 如果这个方法不可用,那么行高设为 44
|
|
9
8
|
*
|
|
10
9
|
* 特别参数
|
|
11
10
|
* sections: {title: string, rows: cview[]}[]
|
|
11
|
+
* rows: cview[]
|
|
12
|
+
* 两者不能同时存在,否则rows不起作用
|
|
12
13
|
*
|
|
13
14
|
* 除了 props.data, props.template 和 events.rowHeight 不可用,其他均和 list 一致
|
|
14
15
|
*/
|
|
@@ -22,21 +23,27 @@ interface DynamicRowHeightListCView extends Base<any, any> {
|
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
export class DynamicRowHeightList extends Base<UIListView, UiTypes.ListOptions>{
|
|
25
|
-
_sections: {title: string, rows: DynamicRowHeightListCView[]}[];
|
|
26
26
|
_defineView: () => UiTypes.ListOptions;
|
|
27
|
-
constructor({ sections, props, layout, events }: {
|
|
28
|
-
sections
|
|
27
|
+
constructor({ sections, rows, props, layout, events }: {
|
|
28
|
+
sections?: {title: string, rows: DynamicRowHeightListCView[]}[];
|
|
29
|
+
rows?: DynamicRowHeightListCView[];
|
|
29
30
|
props: DynamicRowHeightListProps;
|
|
30
31
|
layout: (make: MASConstraintMaker, view: UIListView) => void;
|
|
31
32
|
events: DynamicRowHeightListEvents;
|
|
32
33
|
}) {
|
|
33
34
|
super();
|
|
34
|
-
this._sections = sections;
|
|
35
35
|
this._defineView = () => {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
let data: any;
|
|
37
|
+
if (sections && sections.length > 0) {
|
|
38
|
+
data = sections.map(n => ({
|
|
39
|
+
title: n.title,
|
|
40
|
+
rows: n.rows.map(r => r.definition)
|
|
41
|
+
}));
|
|
42
|
+
} else if (rows && rows.length > 0) {
|
|
43
|
+
data = rows.map(r => r.definition);
|
|
44
|
+
} else {
|
|
45
|
+
throw new Error("sections or rows must be provided");
|
|
46
|
+
}
|
|
40
47
|
return {
|
|
41
48
|
type: "list",
|
|
42
49
|
props: {
|
|
@@ -46,13 +53,14 @@ export class DynamicRowHeightList extends Base<UIListView, UiTypes.ListOptions>{
|
|
|
46
53
|
layout,
|
|
47
54
|
events: {
|
|
48
55
|
rowHeight: (sender, indexPath) => {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
cview.heightToWidth &&
|
|
52
|
-
typeof cview.heightToWidth === "function"
|
|
53
|
-
)
|
|
56
|
+
if (sections) {
|
|
57
|
+
const cview = sections[indexPath.section].rows[indexPath.row];
|
|
54
58
|
return cview.heightToWidth(sender.frame.width);
|
|
55
|
-
else
|
|
59
|
+
} else if (rows) {
|
|
60
|
+
return rows[indexPath.row].heightToWidth(sender.frame.width);
|
|
61
|
+
} else {
|
|
62
|
+
throw new Error("sections or rows must be provided");
|
|
63
|
+
}
|
|
56
64
|
},
|
|
57
65
|
...events
|
|
58
66
|
}
|
|
@@ -6,10 +6,11 @@
|
|
|
6
6
|
*
|
|
7
7
|
* 核心策略为 list 的所有行均为 cview,且每一个 cview 需要实现一个方法:heightToWidth(width: number) => number
|
|
8
8
|
* 通过这个方法汇报自己在某个宽度的时候所需要的高度,这必须任何时候均立即可用;
|
|
9
|
-
* 如果这个方法不可用,那么行高设为 44
|
|
10
9
|
*
|
|
11
10
|
* 特别参数
|
|
12
11
|
* sections: {title: string, rows: cview[]}[]
|
|
12
|
+
* rows: cview[]
|
|
13
|
+
* 两者不能同时存在,否则rows不起作用
|
|
13
14
|
*
|
|
14
15
|
* 除了 props.data, props.template 和 events.rowHeight 不可用,其他均和 list 一致
|
|
15
16
|
*/
|
|
@@ -17,25 +18,37 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
18
|
exports.DynamicRowHeightList = void 0;
|
|
18
19
|
const base_1 = require("./base");
|
|
19
20
|
class DynamicRowHeightList extends base_1.Base {
|
|
20
|
-
constructor({ sections, props, layout, events }) {
|
|
21
|
+
constructor({ sections, rows, props, layout, events }) {
|
|
21
22
|
super();
|
|
22
|
-
this._sections = sections;
|
|
23
23
|
this._defineView = () => {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
let data;
|
|
25
|
+
if (sections && sections.length > 0) {
|
|
26
|
+
data = sections.map(n => ({
|
|
27
|
+
title: n.title,
|
|
28
|
+
rows: n.rows.map(r => r.definition)
|
|
29
|
+
}));
|
|
30
|
+
}
|
|
31
|
+
else if (rows && rows.length > 0) {
|
|
32
|
+
data = rows.map(r => r.definition);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
throw new Error("sections or rows must be provided");
|
|
36
|
+
}
|
|
28
37
|
return {
|
|
29
38
|
type: "list",
|
|
30
39
|
props: Object.assign({ data }, props),
|
|
31
40
|
layout,
|
|
32
41
|
events: Object.assign({ rowHeight: (sender, indexPath) => {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
typeof cview.heightToWidth === "function")
|
|
42
|
+
if (sections) {
|
|
43
|
+
const cview = sections[indexPath.section].rows[indexPath.row];
|
|
36
44
|
return cview.heightToWidth(sender.frame.width);
|
|
37
|
-
|
|
38
|
-
|
|
45
|
+
}
|
|
46
|
+
else if (rows) {
|
|
47
|
+
return rows[indexPath.row].heightToWidth(sender.frame.width);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
throw new Error("sections or rows must be provided");
|
|
51
|
+
}
|
|
39
52
|
} }, events)
|
|
40
53
|
};
|
|
41
54
|
};
|