jsbox-cview 1.5.21 → 1.5.23
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.
- package/components/alert/input-alert.ts +5 -7
- package/components/alert/login-alert.ts +7 -7
- package/components/alert/plain-alert.ts +3 -3
- package/components/alert/uialert.ts +14 -6
- package/components/base.ts +12 -8
- package/components/custom-navigation-bar.ts +106 -88
- package/components/dialogs/dialog-sheet.ts +12 -8
- package/components/dialogs/form-dialog.ts +29 -16
- package/components/dialogs/list-dialog.ts +26 -20
- package/components/dialogs/text-dialog.ts +13 -8
- package/components/dynamic-contextmenu-view.ts +57 -25
- package/components/dynamic-itemsize-matrix.ts +45 -40
- package/components/dynamic-preference-listview.ts +135 -117
- package/components/dynamic-rowheight-list.ts +32 -20
- package/components/enhanced-imageview.ts +37 -28
- package/components/flowlayout.ts +61 -42
- package/components/image-pager.ts +33 -29
- package/components/page-control.ts +15 -11
- package/components/pageviewer-titlebar.ts +29 -22
- package/components/pageviewer.ts +33 -23
- package/components/refresh-button.ts +8 -8
- package/components/rotating-view.ts +24 -20
- package/components/searchbar.ts +113 -65
- package/components/sheet.ts +23 -17
- package/components/single-views.ts +228 -72
- package/components/spinners/loading-dual-ring.ts +21 -15
- package/components/spinners/loading-wedges.ts +24 -18
- package/components/spinners/spinner-androidstyle.ts +58 -47
- package/components/static-preference-listview.ts +197 -151
- package/components/symbol-button.ts +23 -22
- package/components/tabbar.ts +80 -64
- package/controller/base-controller.ts +42 -35
- package/controller/controller-router.ts +4 -4
- package/controller/pageviewer-controller.ts +41 -27
- package/controller/presented-page-controller.ts +27 -15
- package/controller/splitview-controller.ts +77 -44
- package/controller/tabbar-controller.ts +33 -23
- package/dist/components/alert/input-alert.js +3 -3
- package/dist/components/alert/login-alert.js +5 -5
- package/dist/components/alert/plain-alert.js +1 -1
- package/dist/components/alert/uialert.js +4 -4
- package/dist/components/base.js +2 -1
- package/dist/components/custom-navigation-bar.js +61 -59
- package/dist/components/dialogs/dialog-sheet.js +5 -5
- package/dist/components/dialogs/form-dialog.js +2 -2
- package/dist/components/dialogs/list-dialog.js +15 -15
- package/dist/components/dialogs/text-dialog.js +6 -6
- package/dist/components/dynamic-contextmenu-view.js +11 -8
- package/dist/components/dynamic-itemsize-matrix.js +15 -13
- package/dist/components/dynamic-preference-listview.js +95 -90
- package/dist/components/dynamic-rowheight-list.js +7 -6
- package/dist/components/enhanced-imageview.js +18 -16
- package/dist/components/flowlayout.js +15 -14
- package/dist/components/image-pager.js +22 -21
- package/dist/components/page-control.js +2 -2
- package/dist/components/pageviewer-titlebar.js +20 -17
- package/dist/components/pageviewer.js +13 -12
- package/dist/components/refresh-button.js +5 -5
- package/dist/components/rotating-view.js +11 -11
- package/dist/components/searchbar.js +53 -41
- package/dist/components/sheet.js +4 -4
- package/dist/components/single-views.js +68 -68
- package/dist/components/spinners/loading-dual-ring.js +10 -10
- package/dist/components/spinners/loading-wedges.js +15 -15
- package/dist/components/spinners/spinner-androidstyle.js +45 -43
- package/dist/components/static-preference-listview.js +101 -102
- package/dist/components/symbol-button.js +14 -13
- package/dist/components/tabbar.js +54 -50
- package/dist/controller/base-controller.js +17 -14
- package/dist/controller/pageviewer-controller.js +13 -11
- package/dist/controller/presented-page-controller.js +6 -4
- package/dist/controller/splitview-controller.js +48 -31
- package/dist/controller/tabbar-controller.js +13 -12
- package/dist/test/custom-navigation-bar.js +11 -9
- package/dist/test/dynamic-contextmenu-view.js +16 -14
- package/dist/test/dynamic-itemsize-matrix.js +18 -17
- package/dist/test/dynamic-preference-listview.js +29 -29
- package/dist/test/flowlayout.js +33 -27
- package/dist/test/form-dialog.js +15 -13
- package/dist/test/pageviewer-controller.js +10 -7
- package/dist/test/pageviewer-titlebar.js +3 -3
- package/dist/test/pageviewer.js +16 -7
- package/dist/test/refresh-button.js +4 -4
- package/dist/test/searchbar.js +7 -7
- package/dist/test/splitview-controller.js +14 -11
- package/dist/test/static-preference-listview.js +29 -30
- package/dist/test/tabbar-controller.js +15 -12
- package/dist/utils/colors.js +1 -2
- package/dist/utils/l10n.js +28 -28
- package/dist/utils/path.js +2 -2
- package/dist/utils/rect.js +30 -8
- package/dist/utils/uitools.js +29 -19
- package/index.ts +43 -43
- package/package.json +2 -2
- package/test/custom-navigation-bar.ts +28 -28
- package/test/dynamic-contextmenu-view.ts +23 -21
- package/test/dynamic-itemsize-matrix.ts +27 -22
- package/test/dynamic-preference-listview.ts +35 -35
- package/test/flowlayout.ts +43 -33
- package/test/form-dialog.ts +44 -43
- package/test/pageviewer-controller.ts +13 -11
- package/test/pageviewer-titlebar.ts +4 -5
- package/test/pageviewer.ts +17 -8
- package/test/refresh-button.ts +5 -5
- package/test/searchbar.ts +8 -8
- package/test/splitview-controller.ts +31 -30
- package/test/static-preference-listview.ts +35 -34
- package/test/tabbar-controller.ts +32 -29
- package/utils/colors.ts +7 -8
- package/utils/cvid.ts +1 -2
- package/utils/l10n.ts +32 -32
- package/utils/path.ts +9 -9
- package/utils/rect.ts +31 -8
- package/utils/uitools.ts +30 -22
|
@@ -1,30 +1,36 @@
|
|
|
1
|
-
import { DialogSheet } from
|
|
2
|
-
import { List } from
|
|
1
|
+
import { DialogSheet } from "./dialog-sheet";
|
|
2
|
+
import { List } from "../single-views";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* 显示一个列表以供选择
|
|
6
|
-
*
|
|
6
|
+
*
|
|
7
7
|
* @param items 选项
|
|
8
8
|
* @param multiSelectEnabled 是否允许多选
|
|
9
9
|
* @param value 默认选中的选项
|
|
10
10
|
* @param values 默认选中的选项, 配合multiSelectEnabled使用
|
|
11
11
|
* @param title 标题
|
|
12
12
|
*/
|
|
13
|
-
export function listDialog({
|
|
13
|
+
export function listDialog({
|
|
14
|
+
items,
|
|
15
|
+
multiSelectEnabled,
|
|
16
|
+
value,
|
|
17
|
+
values = [],
|
|
18
|
+
title,
|
|
19
|
+
}: {
|
|
14
20
|
items: string[];
|
|
15
21
|
multiSelectEnabled?: boolean;
|
|
16
22
|
value?: number;
|
|
17
23
|
values?: number[];
|
|
18
24
|
title: string;
|
|
19
25
|
}): Promise<number | number[]> {
|
|
20
|
-
if (value) values = [value]
|
|
26
|
+
if (value) values = [value];
|
|
21
27
|
const listView = new List({
|
|
22
28
|
props: {
|
|
23
29
|
style: 2,
|
|
24
30
|
data: items.map((n, i) => {
|
|
25
31
|
return {
|
|
26
32
|
label: { text: n },
|
|
27
|
-
image: { hidden: !values.includes(i) }
|
|
33
|
+
image: { hidden: !values.includes(i) },
|
|
28
34
|
};
|
|
29
35
|
}),
|
|
30
36
|
template: {
|
|
@@ -32,13 +38,13 @@ export function listDialog({ items, multiSelectEnabled, value, values = [], titl
|
|
|
32
38
|
{
|
|
33
39
|
type: "label",
|
|
34
40
|
props: {
|
|
35
|
-
id: "label"
|
|
41
|
+
id: "label",
|
|
36
42
|
},
|
|
37
43
|
layout: (make, view) => {
|
|
38
44
|
make.top.bottom.inset(0);
|
|
39
45
|
make.left.inset(20);
|
|
40
46
|
make.right.inset(50);
|
|
41
|
-
}
|
|
47
|
+
},
|
|
42
48
|
},
|
|
43
49
|
{
|
|
44
50
|
type: "image",
|
|
@@ -46,31 +52,31 @@ export function listDialog({ items, multiSelectEnabled, value, values = [], titl
|
|
|
46
52
|
id: "image",
|
|
47
53
|
symbol: "checkmark",
|
|
48
54
|
contentMode: 1,
|
|
49
|
-
tintColor: $color("systemLink")
|
|
55
|
+
tintColor: $color("systemLink"),
|
|
50
56
|
},
|
|
51
57
|
layout: (make, view) => {
|
|
52
58
|
make.top.bottom.right.inset(10);
|
|
53
59
|
make.width.equalTo(30);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
]
|
|
57
|
-
}
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
},
|
|
58
64
|
},
|
|
59
65
|
events: {
|
|
60
66
|
didSelect: (sender, indexPath) => {
|
|
61
67
|
const data = sender.data;
|
|
62
68
|
if (multiSelectEnabled) {
|
|
63
|
-
data[indexPath.item].image.hidden =
|
|
64
|
-
.hidden;
|
|
69
|
+
data[indexPath.item].image.hidden =
|
|
70
|
+
!data[indexPath.item].image.hidden;
|
|
65
71
|
} else {
|
|
66
72
|
data.forEach((n, i) => {
|
|
67
73
|
n.image.hidden = i !== indexPath.item;
|
|
68
74
|
});
|
|
69
75
|
}
|
|
70
76
|
sender.data = data;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
})
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
});
|
|
74
80
|
const sheet = new DialogSheet({
|
|
75
81
|
title,
|
|
76
82
|
bgcolor: $color("insetGroupedBackground"),
|
|
@@ -78,10 +84,10 @@ export function listDialog({ items, multiSelectEnabled, value, values = [], titl
|
|
|
78
84
|
doneHandler: () => {
|
|
79
85
|
const filtered = listView.view.data
|
|
80
86
|
.map((n, i) => (n.image.hidden ? -1 : i))
|
|
81
|
-
.filter(n => n !== -1);
|
|
87
|
+
.filter((n) => n !== -1);
|
|
82
88
|
if (multiSelectEnabled) return filtered;
|
|
83
89
|
else return filtered[0];
|
|
84
|
-
}
|
|
90
|
+
},
|
|
85
91
|
});
|
|
86
92
|
return new Promise((resolve, reject) => {
|
|
87
93
|
sheet.promisify(resolve, reject);
|
|
@@ -8,7 +8,12 @@ import { DialogSheet } from "./dialog-sheet";
|
|
|
8
8
|
* @param placeholder 占位符
|
|
9
9
|
* @param editable 是否可编辑
|
|
10
10
|
*/
|
|
11
|
-
export function textDialog({
|
|
11
|
+
export function textDialog({
|
|
12
|
+
title,
|
|
13
|
+
text = "",
|
|
14
|
+
placeholder = "",
|
|
15
|
+
editable = true,
|
|
16
|
+
}: {
|
|
12
17
|
title: string;
|
|
13
18
|
text?: string;
|
|
14
19
|
placeholder?: string;
|
|
@@ -18,22 +23,22 @@ export function textDialog({ title, text = "", placeholder = "", editable = true
|
|
|
18
23
|
props: {
|
|
19
24
|
text,
|
|
20
25
|
placeholder,
|
|
21
|
-
editable
|
|
26
|
+
editable,
|
|
22
27
|
},
|
|
23
28
|
events: {
|
|
24
|
-
ready: sender => {
|
|
25
|
-
if (sender.editable) sender.focus()
|
|
26
|
-
}
|
|
27
|
-
}
|
|
29
|
+
ready: (sender) => {
|
|
30
|
+
if (sender.editable) sender.focus();
|
|
31
|
+
},
|
|
32
|
+
},
|
|
28
33
|
});
|
|
29
34
|
|
|
30
35
|
const sheet = new DialogSheet({
|
|
31
36
|
title,
|
|
32
37
|
cview: textView,
|
|
33
|
-
doneHandler: () => textView.view.text
|
|
38
|
+
doneHandler: () => textView.view.text,
|
|
34
39
|
});
|
|
35
40
|
return new Promise((resolve, reject) => {
|
|
36
41
|
sheet.promisify(resolve, reject);
|
|
37
42
|
sheet.present();
|
|
38
43
|
});
|
|
39
|
-
}
|
|
44
|
+
}
|
|
@@ -6,28 +6,47 @@ type MenuItem = {
|
|
|
6
6
|
symbol: string;
|
|
7
7
|
handler: () => void;
|
|
8
8
|
destructive?: boolean;
|
|
9
|
-
}
|
|
9
|
+
};
|
|
10
10
|
|
|
11
|
-
const RegisteredOCClassName: Set<string> = new Set()
|
|
11
|
+
const RegisteredOCClassName: Set<string> = new Set();
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* 动态上下文菜单视图,此视图是为了弥补JSBox中无法动态调整上下文菜单的缺陷而设计的。
|
|
15
|
-
*
|
|
15
|
+
*
|
|
16
16
|
* 此视图除了一般UIView的props, layout, events, views四个参数外,还有必须的特殊参数:
|
|
17
17
|
* 1. classname?: string OC类名,如果不指定则会自动生成一个唯一的类名。
|
|
18
|
-
* 如果有不同的DynamicContextMenuView实例使用相同的OC
|
|
18
|
+
* 如果有不同的DynamicContextMenuView实例使用相同的OC类,
|
|
19
|
+
* 那么无法确定弹出的contextMenu是绑定了哪个实例。
|
|
20
|
+
* 换言之,实例A弹出的Menu可能是绑定的实例B。
|
|
19
21
|
* 如果这样做,必须使用下面generateContextMenu的sender参数来定位。
|
|
20
|
-
* 2. generateContextMenu: (sender: UIView) => { title: string; items: MenuItem[]; }
|
|
21
|
-
*
|
|
22
|
+
* 2. generateContextMenu: (sender: UIView) => { title: string; items: MenuItem[]; }
|
|
23
|
+
* 生成上下文菜单的回调函数。
|
|
24
|
+
*
|
|
22
25
|
*/
|
|
23
|
-
export class DynamicContextMenuView extends Base<
|
|
24
|
-
|
|
26
|
+
export class DynamicContextMenuView extends Base<
|
|
27
|
+
UIView,
|
|
28
|
+
UiTypes.RuntimeOptions
|
|
29
|
+
> {
|
|
30
|
+
private generateContextMenu: (sender: UIView) => {
|
|
31
|
+
title: string;
|
|
32
|
+
items: MenuItem[];
|
|
33
|
+
};
|
|
25
34
|
private _ocClassName: string;
|
|
26
35
|
_defineView: () => UiTypes.RuntimeOptions;
|
|
27
|
-
|
|
28
|
-
constructor({
|
|
36
|
+
|
|
37
|
+
constructor({
|
|
38
|
+
classname,
|
|
39
|
+
generateContextMenu,
|
|
40
|
+
props,
|
|
41
|
+
layout,
|
|
42
|
+
events,
|
|
43
|
+
views,
|
|
44
|
+
}: {
|
|
29
45
|
classname?: string;
|
|
30
|
-
generateContextMenu: (sender: UIView) => {
|
|
46
|
+
generateContextMenu: (sender: UIView) => {
|
|
47
|
+
title: string;
|
|
48
|
+
items: MenuItem[];
|
|
49
|
+
};
|
|
31
50
|
props: UiTypes.BaseViewProps;
|
|
32
51
|
layout?: (make: MASConstraintMaker, view: UIView) => void;
|
|
33
52
|
events?: UiTypes.BaseViewEvents;
|
|
@@ -43,13 +62,13 @@ export class DynamicContextMenuView extends Base<UIView, UiTypes.RuntimeOptions>
|
|
|
43
62
|
props: {
|
|
44
63
|
...props,
|
|
45
64
|
id: this.id,
|
|
46
|
-
view: runtimeView
|
|
65
|
+
view: runtimeView,
|
|
47
66
|
},
|
|
48
67
|
layout,
|
|
49
68
|
events,
|
|
50
|
-
views
|
|
51
|
-
}
|
|
52
|
-
}
|
|
69
|
+
views,
|
|
70
|
+
};
|
|
71
|
+
};
|
|
53
72
|
}
|
|
54
73
|
|
|
55
74
|
private defineOCClass() {
|
|
@@ -58,22 +77,35 @@ export class DynamicContextMenuView extends Base<UIView, UiTypes.RuntimeOptions>
|
|
|
58
77
|
$define({
|
|
59
78
|
type: this._ocClassName + " : UIView <UIContextMenuInteractionDelegate>",
|
|
60
79
|
events: {
|
|
61
|
-
"contextMenuInteraction:configurationForMenuAtLocation:": (
|
|
62
|
-
|
|
80
|
+
"contextMenuInteraction:configurationForMenuAtLocation:": (
|
|
81
|
+
interacton: any,
|
|
82
|
+
point: JBPoint
|
|
83
|
+
) => {
|
|
84
|
+
const view = interacton.$view().jsValue();
|
|
63
85
|
const menu = this.generateContextMenu(view);
|
|
64
86
|
return this.createContextMenuConfiguration(menu);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
})
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
});
|
|
68
90
|
}
|
|
69
91
|
|
|
70
|
-
private createContextMenuConfiguration({
|
|
71
|
-
|
|
92
|
+
private createContextMenuConfiguration({
|
|
93
|
+
title,
|
|
94
|
+
items,
|
|
95
|
+
}: {
|
|
96
|
+
title: string;
|
|
97
|
+
items: MenuItem[];
|
|
98
|
+
}) {
|
|
99
|
+
return $objc(
|
|
100
|
+
"UIContextMenuConfiguration"
|
|
101
|
+
).$configurationWithIdentifier_previewProvider_actionProvider(
|
|
72
102
|
null,
|
|
73
103
|
null,
|
|
74
104
|
$block("UIMenu *, NSArray *", () => {
|
|
75
|
-
const actions = items.map(item => {
|
|
76
|
-
const action = $objc(
|
|
105
|
+
const actions = items.map((item) => {
|
|
106
|
+
const action = $objc(
|
|
107
|
+
"UIAction"
|
|
108
|
+
).$actionWithTitle_image_identifier_handler(
|
|
77
109
|
item.title,
|
|
78
110
|
item.symbol,
|
|
79
111
|
null,
|
|
@@ -81,7 +113,7 @@ export class DynamicContextMenuView extends Base<UIView, UiTypes.RuntimeOptions>
|
|
|
81
113
|
);
|
|
82
114
|
if (item.destructive) action.$setAttributes(1 << 1);
|
|
83
115
|
return action;
|
|
84
|
-
})
|
|
116
|
+
});
|
|
85
117
|
return $objc("UIMenu").$menuWithTitle_children(title, actions);
|
|
86
118
|
})
|
|
87
119
|
);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Base } from
|
|
1
|
+
import { Base } from "./base";
|
|
2
2
|
import { Matrix } from "./single-views";
|
|
3
3
|
|
|
4
4
|
interface DynamicItemSizeMatrixProps extends UiTypes.MatrixProps {
|
|
@@ -31,7 +31,7 @@ function _getColumnsAndItemSizeWidth(
|
|
|
31
31
|
if (minItemWidth > containerWidth - 2 * spacing) {
|
|
32
32
|
return {
|
|
33
33
|
columns: 1,
|
|
34
|
-
itemSizeWidth: containerWidth - 2 * spacing
|
|
34
|
+
itemSizeWidth: containerWidth - 2 * spacing,
|
|
35
35
|
};
|
|
36
36
|
}
|
|
37
37
|
const columns = Math.max(
|
|
@@ -39,58 +39,60 @@ function _getColumnsAndItemSizeWidth(
|
|
|
39
39
|
Math.floor((containerWidth - spacing) / (minItemWidth + spacing)),
|
|
40
40
|
maxColumns
|
|
41
41
|
),
|
|
42
|
-
1
|
|
42
|
+
1 // 最少一列
|
|
43
|
+
);
|
|
44
|
+
const itemSizeWidth = Math.max(
|
|
45
|
+
Math.floor((containerWidth - spacing * (columns + 1)) / columns),
|
|
46
|
+
minItemWidth // 最小宽度
|
|
43
47
|
);
|
|
44
|
-
const itemSizeWidth = Math.max(
|
|
45
|
-
Math.floor((containerWidth - spacing * (columns + 1)) / columns),
|
|
46
|
-
minItemWidth // 最小宽度
|
|
47
|
-
)
|
|
48
48
|
return {
|
|
49
49
|
columns,
|
|
50
|
-
itemSizeWidth
|
|
50
|
+
itemSizeWidth,
|
|
51
51
|
};
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
/**
|
|
55
55
|
* # CView Dynamic ItemSize Matrix
|
|
56
|
-
*
|
|
56
|
+
*
|
|
57
57
|
* 此组件是为了解决让 Matrix 的 ItemSize 跟随重新布局而动态变化的问题
|
|
58
|
-
*
|
|
58
|
+
*
|
|
59
59
|
* 动态的改变自己的 itemSize,从而使得 spacing 被优先满足。
|
|
60
|
-
* 思路为在 matrix 上层套一个 superView,在旋转的时候 superView 会调用 matrix.relayout()
|
|
61
|
-
*
|
|
62
|
-
*
|
|
60
|
+
* 思路为在 matrix 上层套一个 superView,在旋转的时候 superView 会调用 matrix.relayout()
|
|
61
|
+
* 和 matrix.reload(),从而触发 itemSize 事件
|
|
62
|
+
*
|
|
63
63
|
* 此视图的高度可以自动调整,需要 dynamicHeightEnabled 设为 true,且 layout 中要有关于 height 的约束
|
|
64
|
-
*
|
|
64
|
+
*
|
|
65
65
|
* 其排布逻辑是这样的:
|
|
66
|
-
*
|
|
67
|
-
* 1. 由 minItemWidth,spacing,maxColumns 这三个参数决定 cloumns
|
|
66
|
+
*
|
|
67
|
+
* 1. 由 minItemWidth,spacing,maxColumns 这三个参数决定 cloumns,
|
|
68
|
+
* 并结合 totalWidth 确定 itemSize.width
|
|
68
69
|
* 2. 确定 itemHeight 有两种方法:
|
|
69
70
|
* - fixedItemHeight 固定高度,优先级第二
|
|
70
71
|
* - event: itemHeight(width) => height 通过 width 动态计算,优先级最高
|
|
71
|
-
* 3. 如果 minItemWidth 比 totalWidth - 2 * spacing 还要小,那么 itemSize.width
|
|
72
|
-
*
|
|
72
|
+
* 3. 如果 minItemWidth 比 totalWidth - 2 * spacing 还要小,那么 itemSize.width
|
|
73
|
+
* 会被设定为 totalWidth - 2 * spacing,以保证item不会超出边框
|
|
74
|
+
*
|
|
73
75
|
* props:
|
|
74
|
-
*
|
|
76
|
+
*
|
|
75
77
|
* 可以使用 matrix 的全部属性
|
|
76
|
-
*
|
|
78
|
+
*
|
|
77
79
|
* 特殊属性:
|
|
78
|
-
*
|
|
80
|
+
*
|
|
79
81
|
* - fixedItemHeight 固定 itemSize 高度
|
|
80
82
|
* - minItemWidth 最小的 itemSize 宽度
|
|
81
83
|
* - maxColumns 最大列数
|
|
82
84
|
* - spacing
|
|
83
85
|
* - dynamicHeightEnabled 此项为 true,那么 scrollEnabled 自动设为 false,且高度可以自动调整
|
|
84
|
-
*
|
|
86
|
+
*
|
|
85
87
|
* events:
|
|
86
|
-
*
|
|
88
|
+
*
|
|
87
89
|
* 可以使用 matrix 除 itemSize 以外的全部事件
|
|
88
|
-
*
|
|
90
|
+
*
|
|
89
91
|
* 其他特殊事件:
|
|
90
|
-
*
|
|
92
|
+
*
|
|
91
93
|
* - itemHeight: width => height 通过 itemWidth 动态计算 itemHeight
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
+
*
|
|
95
|
+
*
|
|
94
96
|
* 方法:
|
|
95
97
|
* - heightToWidth(width) 计算特定width时的应有的高度
|
|
96
98
|
*/
|
|
@@ -104,11 +106,14 @@ export class DynamicItemSizeMatrix extends Base<UIView, UiTypes.ViewOptions> {
|
|
|
104
106
|
matrix: Matrix;
|
|
105
107
|
_defineView: () => UiTypes.ViewOptions;
|
|
106
108
|
|
|
107
|
-
constructor({
|
|
109
|
+
constructor({
|
|
110
|
+
props,
|
|
111
|
+
layout,
|
|
112
|
+
events = {},
|
|
113
|
+
}: {
|
|
108
114
|
props: DynamicItemSizeMatrixPropsPartial;
|
|
109
115
|
layout: (make: MASConstraintMaker, view: UIView) => void;
|
|
110
116
|
events: DynamicItemSizeMatrixEvents;
|
|
111
|
-
|
|
112
117
|
}) {
|
|
113
118
|
super();
|
|
114
119
|
this._props = {
|
|
@@ -117,7 +122,7 @@ export class DynamicItemSizeMatrix extends Base<UIView, UiTypes.ViewOptions> {
|
|
|
117
122
|
maxColumns: 5,
|
|
118
123
|
spacing: 6,
|
|
119
124
|
dynamicHeightEnabled: false,
|
|
120
|
-
...props
|
|
125
|
+
...props,
|
|
121
126
|
};
|
|
122
127
|
this._events = events;
|
|
123
128
|
const { itemHeight, heightChanged, ...rest } = this._events;
|
|
@@ -127,24 +132,24 @@ export class DynamicItemSizeMatrix extends Base<UIView, UiTypes.ViewOptions> {
|
|
|
127
132
|
this.matrix = new Matrix({
|
|
128
133
|
props: {
|
|
129
134
|
...this._props,
|
|
130
|
-
scrollEnabled: !this._props.dynamicHeightEnabled
|
|
135
|
+
scrollEnabled: !this._props.dynamicHeightEnabled,
|
|
131
136
|
},
|
|
132
137
|
layout: $layout.fill,
|
|
133
138
|
events: {
|
|
134
139
|
..._matrixEvents,
|
|
135
|
-
itemSize: sender => $size(this._itemSizeWidth, this._itemSizeHeight)
|
|
136
|
-
}
|
|
140
|
+
itemSize: (sender) => $size(this._itemSizeWidth, this._itemSizeHeight),
|
|
141
|
+
},
|
|
137
142
|
});
|
|
138
143
|
this._defineView = () => {
|
|
139
144
|
return {
|
|
140
145
|
type: "view",
|
|
141
146
|
props: {
|
|
142
147
|
bgcolor: $color("clear"),
|
|
143
|
-
id: this.id
|
|
148
|
+
id: this.id,
|
|
144
149
|
},
|
|
145
150
|
layout,
|
|
146
151
|
events: {
|
|
147
|
-
layoutSubviews: sender => {
|
|
152
|
+
layoutSubviews: (sender) => {
|
|
148
153
|
sender.relayout();
|
|
149
154
|
if (sender.frame.width === this._totalWidth) return;
|
|
150
155
|
const { columns, itemSizeWidth } = _getColumnsAndItemSizeWidth(
|
|
@@ -161,17 +166,17 @@ export class DynamicItemSizeMatrix extends Base<UIView, UiTypes.ViewOptions> {
|
|
|
161
166
|
this.matrix.view.reload();
|
|
162
167
|
if (this._props.dynamicHeightEnabled) {
|
|
163
168
|
const height = this.heightToWidth(sender.frame.width);
|
|
164
|
-
sender.updateLayout(make => make.height.equalTo(height));
|
|
169
|
+
sender.updateLayout((make) => make.height.equalTo(height));
|
|
165
170
|
if (this._events.heightChanged)
|
|
166
171
|
this._events.heightChanged(this, height);
|
|
167
172
|
}
|
|
168
|
-
}
|
|
173
|
+
},
|
|
169
174
|
},
|
|
170
|
-
views: [this.matrix.definition]
|
|
175
|
+
views: [this.matrix.definition],
|
|
171
176
|
};
|
|
172
|
-
}
|
|
177
|
+
};
|
|
173
178
|
}
|
|
174
|
-
|
|
179
|
+
|
|
175
180
|
heightToWidth(width: number) {
|
|
176
181
|
const { columns, itemSizeWidth } = _getColumnsAndItemSizeWidth(
|
|
177
182
|
width,
|