jsbox-cview 1.5.2 → 1.5.4
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/dynamic-itemsize-matrix.ts +41 -33
- package/components/sheet.ts +1 -1
- package/components/symbol-button.ts +5 -1
- package/dist/components/dynamic-itemsize-matrix.js +26 -19
- package/dist/components/sheet.js +1 -1
- package/dist/components/symbol-button.js +4 -2
- package/dist/test/dynamic-itemsize-matrix.js +8 -2
- package/package.json +2 -2
- package/test/dynamic-itemsize-matrix.ts +8 -2
|
@@ -22,6 +22,35 @@ interface DynamicItemSizeMatrixPropsPartial extends UiTypes.MatrixProps {
|
|
|
22
22
|
dynamicHeightEnabled?: boolean;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
function _getColumnsAndItemSizeWidth(
|
|
26
|
+
containerWidth: number,
|
|
27
|
+
minItemWidth: number,
|
|
28
|
+
maxColumns: number,
|
|
29
|
+
spacing: number
|
|
30
|
+
) {
|
|
31
|
+
if (minItemWidth > containerWidth - 2 * spacing) {
|
|
32
|
+
return {
|
|
33
|
+
columns: 1,
|
|
34
|
+
itemSizeWidth: containerWidth - 2 * spacing
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
const columns = Math.max(
|
|
38
|
+
Math.min(
|
|
39
|
+
Math.floor((containerWidth - spacing) / (minItemWidth + spacing)),
|
|
40
|
+
maxColumns
|
|
41
|
+
),
|
|
42
|
+
1 // 最少一列
|
|
43
|
+
);
|
|
44
|
+
const itemSizeWidth = Math.max(
|
|
45
|
+
Math.floor((containerWidth - spacing * (columns + 1)) / columns),
|
|
46
|
+
minItemWidth // 最小宽度
|
|
47
|
+
)
|
|
48
|
+
return {
|
|
49
|
+
columns,
|
|
50
|
+
itemSizeWidth
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
25
54
|
/**
|
|
26
55
|
* # CView Dynamic ItemSize Matrix
|
|
27
56
|
*
|
|
@@ -71,6 +100,7 @@ export class DynamicItemSizeMatrix extends Base<UIView, UiTypes.ViewOptions> {
|
|
|
71
100
|
private _itemSizeWidth: number;
|
|
72
101
|
private _itemSizeHeight: number;
|
|
73
102
|
private _totalWidth: number = 0;
|
|
103
|
+
private _columns: number = 1;
|
|
74
104
|
matrix: Matrix;
|
|
75
105
|
_defineView: () => UiTypes.ViewOptions;
|
|
76
106
|
|
|
@@ -117,13 +147,13 @@ export class DynamicItemSizeMatrix extends Base<UIView, UiTypes.ViewOptions> {
|
|
|
117
147
|
layoutSubviews: sender => {
|
|
118
148
|
sender.relayout();
|
|
119
149
|
if (sender.frame.width === this._totalWidth) return;
|
|
120
|
-
const { itemSizeWidth } =
|
|
150
|
+
const { columns, itemSizeWidth } = _getColumnsAndItemSizeWidth(
|
|
121
151
|
sender.frame.width,
|
|
122
152
|
this._props.minItemWidth,
|
|
123
153
|
this._props.maxColumns,
|
|
124
154
|
this._props.spacing
|
|
125
155
|
);
|
|
126
|
-
|
|
156
|
+
this._columns = columns;
|
|
127
157
|
this._itemSizeWidth = itemSizeWidth;
|
|
128
158
|
this._itemSizeHeight = this._events.itemHeight
|
|
129
159
|
? this._events.itemHeight(this._itemSizeWidth)
|
|
@@ -142,38 +172,8 @@ export class DynamicItemSizeMatrix extends Base<UIView, UiTypes.ViewOptions> {
|
|
|
142
172
|
}
|
|
143
173
|
}
|
|
144
174
|
|
|
145
|
-
// 此为纯函数
|
|
146
|
-
_getColumnsAndItemSizeWidth(
|
|
147
|
-
containerWidth: number,
|
|
148
|
-
minItemWidth: number,
|
|
149
|
-
maxColumns: number,
|
|
150
|
-
spacing: number
|
|
151
|
-
) {
|
|
152
|
-
if (minItemWidth > containerWidth - 2 * spacing) {
|
|
153
|
-
return {
|
|
154
|
-
columns: 1,
|
|
155
|
-
itemSizeWidth: containerWidth - 2 * spacing
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
const columns = Math.max(
|
|
159
|
-
Math.min(
|
|
160
|
-
Math.floor((containerWidth - spacing) / (minItemWidth + spacing)),
|
|
161
|
-
maxColumns
|
|
162
|
-
),
|
|
163
|
-
1 // 最少一列
|
|
164
|
-
);
|
|
165
|
-
const itemSizeWidth = Math.max(
|
|
166
|
-
Math.floor((containerWidth - spacing * (columns + 1)) / columns),
|
|
167
|
-
minItemWidth // 最小宽度
|
|
168
|
-
)
|
|
169
|
-
return {
|
|
170
|
-
columns,
|
|
171
|
-
itemSizeWidth
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
|
|
175
175
|
heightToWidth(width: number) {
|
|
176
|
-
const { columns, itemSizeWidth } =
|
|
176
|
+
const { columns, itemSizeWidth } = _getColumnsAndItemSizeWidth(
|
|
177
177
|
width,
|
|
178
178
|
this._props.minItemWidth,
|
|
179
179
|
this._props.maxColumns,
|
|
@@ -194,4 +194,12 @@ export class DynamicItemSizeMatrix extends Base<UIView, UiTypes.ViewOptions> {
|
|
|
194
194
|
this._props.data = data;
|
|
195
195
|
this.matrix.view.data = data;
|
|
196
196
|
}
|
|
197
|
+
|
|
198
|
+
get columns() {
|
|
199
|
+
return this._columns;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
get itemSize() {
|
|
203
|
+
return $size(this._itemSizeWidth, this._itemSizeHeight);
|
|
204
|
+
}
|
|
197
205
|
}
|
package/components/sheet.ts
CHANGED
|
@@ -107,6 +107,6 @@ export class Sheet<T extends Base<U, R>, U extends AllUIView, R extends UiTypes.
|
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
dismiss() {
|
|
110
|
-
this._PSViewController.invoke("dismissModalViewControllerAnimated",
|
|
110
|
+
this._PSViewController.invoke("dismissModalViewControllerAnimated", this._animated);
|
|
111
111
|
}
|
|
112
112
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Base } from "./base";
|
|
2
2
|
|
|
3
3
|
interface SymbolButtonProps {
|
|
4
|
+
enabled: boolean;
|
|
4
5
|
symbol?: string;
|
|
5
6
|
image?: UIImage;
|
|
6
7
|
src?: string;
|
|
@@ -34,6 +35,7 @@ export class SymbolButton extends Base<UIButtonView, UiTypes.ButtonOptions> {
|
|
|
34
35
|
}) {
|
|
35
36
|
super();
|
|
36
37
|
this._props = {
|
|
38
|
+
enabled: true,
|
|
37
39
|
contentMode: 1,
|
|
38
40
|
insets: $insets(12.5, 12.5, 12.5, 12.5),
|
|
39
41
|
tintColor: $color("primaryText"),
|
|
@@ -47,10 +49,12 @@ export class SymbolButton extends Base<UIButtonView, UiTypes.ButtonOptions> {
|
|
|
47
49
|
bgcolor: $color("clear"),
|
|
48
50
|
id: this.id,
|
|
49
51
|
menu: this._props.menu,
|
|
52
|
+
enabled: this._props.enabled
|
|
50
53
|
} : {
|
|
51
54
|
radius: 0,
|
|
52
55
|
bgcolor: $color("clear"),
|
|
53
|
-
id: this.id
|
|
56
|
+
id: this.id,
|
|
57
|
+
enabled: this._props.enabled
|
|
54
58
|
}
|
|
55
59
|
return {
|
|
56
60
|
type: "button",
|
|
@@ -14,6 +14,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
14
14
|
exports.DynamicItemSizeMatrix = void 0;
|
|
15
15
|
const base_1 = require("./base");
|
|
16
16
|
const single_views_1 = require("./single-views");
|
|
17
|
+
function _getColumnsAndItemSizeWidth(containerWidth, minItemWidth, maxColumns, spacing) {
|
|
18
|
+
if (minItemWidth > containerWidth - 2 * spacing) {
|
|
19
|
+
return {
|
|
20
|
+
columns: 1,
|
|
21
|
+
itemSizeWidth: containerWidth - 2 * spacing
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
const columns = Math.max(Math.min(Math.floor((containerWidth - spacing) / (minItemWidth + spacing)), maxColumns), 1 // 最少一列
|
|
25
|
+
);
|
|
26
|
+
const itemSizeWidth = Math.max(Math.floor((containerWidth - spacing * (columns + 1)) / columns), minItemWidth // 最小宽度
|
|
27
|
+
);
|
|
28
|
+
return {
|
|
29
|
+
columns,
|
|
30
|
+
itemSizeWidth
|
|
31
|
+
};
|
|
32
|
+
}
|
|
17
33
|
/**
|
|
18
34
|
* # CView Dynamic ItemSize Matrix
|
|
19
35
|
*
|
|
@@ -61,6 +77,7 @@ class DynamicItemSizeMatrix extends base_1.Base {
|
|
|
61
77
|
constructor({ props, layout, events = {} }) {
|
|
62
78
|
super();
|
|
63
79
|
this._totalWidth = 0;
|
|
80
|
+
this._columns = 1;
|
|
64
81
|
this._props = Object.assign({ fixedItemHeight: 40, minItemWidth: 96, maxColumns: 5, spacing: 6, dynamicHeightEnabled: false }, props);
|
|
65
82
|
this._events = events;
|
|
66
83
|
const _a = this._events, { itemHeight, heightChanged } = _a, rest = __rest(_a, ["itemHeight", "heightChanged"]);
|
|
@@ -85,7 +102,8 @@ class DynamicItemSizeMatrix extends base_1.Base {
|
|
|
85
102
|
sender.relayout();
|
|
86
103
|
if (sender.frame.width === this._totalWidth)
|
|
87
104
|
return;
|
|
88
|
-
const { itemSizeWidth } =
|
|
105
|
+
const { columns, itemSizeWidth } = _getColumnsAndItemSizeWidth(sender.frame.width, this._props.minItemWidth, this._props.maxColumns, this._props.spacing);
|
|
106
|
+
this._columns = columns;
|
|
89
107
|
this._itemSizeWidth = itemSizeWidth;
|
|
90
108
|
this._itemSizeHeight = this._events.itemHeight
|
|
91
109
|
? this._events.itemHeight(this._itemSizeWidth)
|
|
@@ -103,25 +121,8 @@ class DynamicItemSizeMatrix extends base_1.Base {
|
|
|
103
121
|
};
|
|
104
122
|
};
|
|
105
123
|
}
|
|
106
|
-
// 此为纯函数
|
|
107
|
-
_getColumnsAndItemSizeWidth(containerWidth, minItemWidth, maxColumns, spacing) {
|
|
108
|
-
if (minItemWidth > containerWidth - 2 * spacing) {
|
|
109
|
-
return {
|
|
110
|
-
columns: 1,
|
|
111
|
-
itemSizeWidth: containerWidth - 2 * spacing
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
const columns = Math.max(Math.min(Math.floor((containerWidth - spacing) / (minItemWidth + spacing)), maxColumns), 1 // 最少一列
|
|
115
|
-
);
|
|
116
|
-
const itemSizeWidth = Math.max(Math.floor((containerWidth - spacing * (columns + 1)) / columns), minItemWidth // 最小宽度
|
|
117
|
-
);
|
|
118
|
-
return {
|
|
119
|
-
columns,
|
|
120
|
-
itemSizeWidth
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
124
|
heightToWidth(width) {
|
|
124
|
-
const { columns, itemSizeWidth } =
|
|
125
|
+
const { columns, itemSizeWidth } = _getColumnsAndItemSizeWidth(width, this._props.minItemWidth, this._props.maxColumns, this._props.spacing);
|
|
125
126
|
const rows = Math.ceil(this._props.data.length / columns);
|
|
126
127
|
const itemSizeHeight = this._events.itemHeight
|
|
127
128
|
? this._events.itemHeight(itemSizeWidth)
|
|
@@ -135,5 +136,11 @@ class DynamicItemSizeMatrix extends base_1.Base {
|
|
|
135
136
|
this._props.data = data;
|
|
136
137
|
this.matrix.view.data = data;
|
|
137
138
|
}
|
|
139
|
+
get columns() {
|
|
140
|
+
return this._columns;
|
|
141
|
+
}
|
|
142
|
+
get itemSize() {
|
|
143
|
+
return $size(this._itemSizeWidth, this._itemSizeHeight);
|
|
144
|
+
}
|
|
138
145
|
}
|
|
139
146
|
exports.DynamicItemSizeMatrix = DynamicItemSizeMatrix;
|
package/dist/components/sheet.js
CHANGED
|
@@ -75,7 +75,7 @@ class Sheet {
|
|
|
75
75
|
.invoke("presentModalViewController:animated", this._PSViewController, this._animated);
|
|
76
76
|
}
|
|
77
77
|
dismiss() {
|
|
78
|
-
this._PSViewController.invoke("dismissModalViewControllerAnimated",
|
|
78
|
+
this._PSViewController.invoke("dismissModalViewControllerAnimated", this._animated);
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
exports.Sheet = Sheet;
|
|
@@ -15,7 +15,7 @@ const base_1 = require("./base");
|
|
|
15
15
|
class SymbolButton extends base_1.Base {
|
|
16
16
|
constructor({ props, layout, events = {} }) {
|
|
17
17
|
super();
|
|
18
|
-
this._props = Object.assign({ contentMode: 1, insets: $insets(12.5, 12.5, 12.5, 12.5), tintColor: $color("primaryText") }, props);
|
|
18
|
+
this._props = Object.assign({ enabled: true, contentMode: 1, insets: $insets(12.5, 12.5, 12.5, 12.5), tintColor: $color("primaryText") }, props);
|
|
19
19
|
this._layout = layout;
|
|
20
20
|
this._defineView = () => {
|
|
21
21
|
const props = this._props.menu
|
|
@@ -24,10 +24,12 @@ class SymbolButton extends base_1.Base {
|
|
|
24
24
|
bgcolor: $color("clear"),
|
|
25
25
|
id: this.id,
|
|
26
26
|
menu: this._props.menu,
|
|
27
|
+
enabled: this._props.enabled
|
|
27
28
|
} : {
|
|
28
29
|
radius: 0,
|
|
29
30
|
bgcolor: $color("clear"),
|
|
30
|
-
id: this.id
|
|
31
|
+
id: this.id,
|
|
32
|
+
enabled: this._props.enabled
|
|
31
33
|
};
|
|
32
34
|
return {
|
|
33
35
|
type: "button",
|
|
@@ -52,7 +52,13 @@ const matrix = new dynamic_itemsize_matrix_1.DynamicItemSizeMatrix({
|
|
|
52
52
|
},
|
|
53
53
|
events: {
|
|
54
54
|
itemHeight: width => width * 1.414 + 20,
|
|
55
|
-
didSelect: (sender, indexPath, data) => { }
|
|
55
|
+
didSelect: (sender, indexPath, data) => { },
|
|
56
|
+
didScroll: sender => {
|
|
57
|
+
matrix.columns;
|
|
58
|
+
console.log(sender.contentOffset.y);
|
|
59
|
+
console.log(Math.ceil(sender.contentOffset.y / (matrix.itemSize.height + 5)));
|
|
60
|
+
console.log(Math.ceil(sender.contentOffset.y / (matrix.itemSize.height + 5)) * matrix.columns);
|
|
61
|
+
},
|
|
56
62
|
}
|
|
57
63
|
});
|
|
58
64
|
$ui.render({
|
|
@@ -64,5 +70,5 @@ $ui.render({
|
|
|
64
70
|
}
|
|
65
71
|
]
|
|
66
72
|
},
|
|
67
|
-
views: [matrix.definition]
|
|
73
|
+
views: [matrix.definition],
|
|
68
74
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jsbox-cview",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.4",
|
|
4
4
|
"description": "为 JSBox 设计的微型框架",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -19,6 +19,6 @@
|
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"@types/node": "^20.11.17",
|
|
21
21
|
"browserify": "^17.0.0",
|
|
22
|
-
"jsbox-types": "^1.0.
|
|
22
|
+
"jsbox-types": "^1.0.31"
|
|
23
23
|
}
|
|
24
24
|
}
|
|
@@ -51,7 +51,13 @@ const matrix = new DynamicItemSizeMatrix({
|
|
|
51
51
|
},
|
|
52
52
|
events: {
|
|
53
53
|
itemHeight: width => width * 1.414 + 20,
|
|
54
|
-
didSelect: (sender, indexPath, data) => { }
|
|
54
|
+
didSelect: (sender, indexPath, data) => { },
|
|
55
|
+
didScroll: sender => {
|
|
56
|
+
matrix.columns
|
|
57
|
+
console.log(sender.contentOffset.y)
|
|
58
|
+
console.log(Math.ceil(sender.contentOffset.y / (matrix.itemSize.height + 5)))
|
|
59
|
+
console.log(Math.ceil(sender.contentOffset.y / (matrix.itemSize.height + 5)) * matrix.columns)
|
|
60
|
+
},
|
|
55
61
|
}
|
|
56
62
|
});
|
|
57
63
|
|
|
@@ -64,5 +70,5 @@ $ui.render({
|
|
|
64
70
|
}
|
|
65
71
|
]
|
|
66
72
|
},
|
|
67
|
-
views: [matrix.definition]
|
|
73
|
+
views: [matrix.definition],
|
|
68
74
|
});
|