jsbox-cview 1.5.3 → 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.
@@ -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 } = this._getColumnsAndItemSizeWidth(
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 } = this._getColumnsAndItemSizeWidth(
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
  }
@@ -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", true);
110
+ this._PSViewController.invoke("dismissModalViewControllerAnimated", this._animated);
111
111
  }
112
112
  }
@@ -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 } = this._getColumnsAndItemSizeWidth(sender.frame.width, this._props.minItemWidth, this._props.maxColumns, this._props.spacing);
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 } = this._getColumnsAndItemSizeWidth(width, this._props.minItemWidth, this._props.maxColumns, this._props.spacing);
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;
@@ -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", true);
78
+ this._PSViewController.invoke("dismissModalViewControllerAnimated", this._animated);
79
79
  }
80
80
  }
81
81
  exports.Sheet = Sheet;
@@ -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",
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.30"
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
  });