jsbox-cview 1.6.7 → 1.6.9
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/dist/components/dialogs/dialog-sheet.js +1 -1
- package/dist/components/dynamic-itemsize-section-matrix.d.ts +48 -17
- package/dist/components/dynamic-itemsize-section-matrix.js +114 -51
- package/dist/components/pageviewer.js +12 -3
- package/dist/controller/base-controller.d.ts +0 -17
- package/dist/controller/base-controller.js +11 -26
- package/dist/controller/controller-router.js +2 -1
- package/dist/controller/controller-status.d.ts +16 -0
- package/dist/controller/controller-status.js +19 -0
- package/dist/controller/pageviewer-controller.js +32 -3
- package/dist/controller/splitview-controller.js +3 -2
- package/dist/controller/tabbar-controller.js +2 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +1 -1
|
@@ -20,7 +20,7 @@ const single_views_1 = require("../single-views");
|
|
|
20
20
|
class DialogSheet extends sheet_1.Sheet {
|
|
21
21
|
constructor(props) {
|
|
22
22
|
super({
|
|
23
|
-
presentMode: props.presentMode
|
|
23
|
+
presentMode: props.presentMode ?? ($device.isIpad ? 2 : 1),
|
|
24
24
|
bgcolor: props.bgcolor,
|
|
25
25
|
});
|
|
26
26
|
this._props = props;
|
|
@@ -4,29 +4,52 @@ export interface DynamicItemSizeSectionMatrixSection {
|
|
|
4
4
|
title: string;
|
|
5
5
|
items: Record<string, unknown>[];
|
|
6
6
|
}
|
|
7
|
-
export interface
|
|
8
|
-
|
|
7
|
+
export interface DynamicItemSizeSectionMatrixCustomSection {
|
|
8
|
+
title: Record<string, unknown>;
|
|
9
|
+
titleHeight: number;
|
|
10
|
+
items: Record<string, unknown>[];
|
|
11
|
+
}
|
|
12
|
+
export type DynamicItemSizeSectionMatrixAnySection = DynamicItemSizeSectionMatrixSection | DynamicItemSizeSectionMatrixCustomSection;
|
|
13
|
+
export type DynamicItemSizeSectionMatrixTitleTemplate = NonNullable<UiTypes.MatrixProps["template"]>;
|
|
14
|
+
interface BaseProps extends Omit<UiTypes.MatrixProps, "data" | "itemSize" | "autoItemSize" | "estimatedItemSize" | "columns" | "square" | "waterfall" | "reorder" | "menu"> {
|
|
9
15
|
fixedItemHeight?: number;
|
|
10
16
|
minItemWidth?: number;
|
|
11
17
|
maxColumns?: number;
|
|
12
18
|
spacing?: number;
|
|
13
19
|
}
|
|
20
|
+
type TitleProps<T extends DynamicItemSizeSectionMatrixAnySection> = [T] extends [
|
|
21
|
+
DynamicItemSizeSectionMatrixCustomSection
|
|
22
|
+
] ? {
|
|
23
|
+
sectionTitleTemplate: DynamicItemSizeSectionMatrixTitleTemplate;
|
|
24
|
+
} : [T] extends [DynamicItemSizeSectionMatrixSection] ? {
|
|
25
|
+
sectionTitleTemplate?: never;
|
|
26
|
+
} : never;
|
|
27
|
+
export type DynamicItemSizeSectionMatrixProps<T extends DynamicItemSizeSectionMatrixAnySection = DynamicItemSizeSectionMatrixSection> = BaseProps & TitleProps<T> & {
|
|
28
|
+
data?: T[];
|
|
29
|
+
};
|
|
14
30
|
export interface DynamicItemSizeSectionMatrixEvents extends Omit<UiTypes.MatrixEvents, "itemSize" | "reorderBegan" | "reorderMoved" | "canMoveItem" | "reorderFinished"> {
|
|
15
31
|
itemHeight?: (width: number) => number;
|
|
16
32
|
}
|
|
17
33
|
/**
|
|
18
34
|
* # CView Dynamic ItemSize Section Matrix
|
|
19
35
|
*
|
|
20
|
-
* 此组件是为了在 Dynamic ItemSize Matrix 的基础上添加 SectionTitle
|
|
36
|
+
* 此组件是为了在 Dynamic ItemSize Matrix 的基础上添加 SectionTitle。
|
|
37
|
+
* SectionTitle 实际上是一个位于每个 section 首位的全宽 header cell,为兼容现有API继续使用title命名。
|
|
21
38
|
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* -
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
39
|
+
* 注意事项:
|
|
40
|
+
* 1. 默认模式中每个section的title为字符串;空字符串依然添加高度35的空格(该高度包含spacing)
|
|
41
|
+
* 2. 默认title的字体为font(13),左右边距为10,即文本宽度为 totalWidth - 2 * spacing - 20
|
|
42
|
+
* 3. 提供sectionTitleTemplate后进入自定义模式,title为模板数据,titleHeight为标题cell的实际高度(不包含spacing)
|
|
43
|
+
* 4. sectionTitle会使得section之间的间隔增加自身的高度
|
|
44
|
+
* 5. 由于sectionTitle必然和底下的item会有spacing,所以不建议spacing设的太大,那样会很违和
|
|
45
|
+
* 6. 每个section会使用不可见item补齐最后一行,避免原生Flow Layout将未满行居中排列
|
|
46
|
+
* 7. matrix事件会自动过滤sectionTitle和不可见item,并调整indexPath,包括didSelect、didLongPress、forEachItem
|
|
47
|
+
* 8. matrix的方法都在该组件中重新实现,自动调整indexPath
|
|
48
|
+
*
|
|
49
|
+
* 不支持:
|
|
50
|
+
* 1. 不支持matrix原有的重新排序、自动大小功能
|
|
51
|
+
* 2. 为防止sectionTitle暴露,也不支持menu
|
|
52
|
+
* 3. 不支持Dynamic ItemSize Matrix的dynamicHeightEnabled、heightToWidth
|
|
30
53
|
*
|
|
31
54
|
* ## 动态调整 itemSize
|
|
32
55
|
*
|
|
@@ -48,11 +71,15 @@ export interface DynamicItemSizeSectionMatrixEvents extends Omit<UiTypes.MatrixE
|
|
|
48
71
|
*
|
|
49
72
|
* 可以使用 matrix 的全部属性。
|
|
50
73
|
*
|
|
51
|
-
*
|
|
74
|
+
* 默认模式的data类型为:
|
|
52
75
|
* { title: string; items: Record<string, unknown>[] }
|
|
53
76
|
*
|
|
77
|
+
* 提供sectionTitleTemplate后,自定义模式的data类型为:
|
|
78
|
+
* { title: Record<string, unknown>; titleHeight: number; items: Record<string, unknown>[] }
|
|
79
|
+
*
|
|
54
80
|
* 特殊属性:
|
|
55
81
|
*
|
|
82
|
+
* - sectionTitleTemplate 自定义section title模板;是否提供该属性即为模式开关
|
|
56
83
|
* - fixedItemHeight 固定 itemSize 高度
|
|
57
84
|
* - minItemWidth 最小的 itemSize 宽度
|
|
58
85
|
* - maxColumns 最大列数
|
|
@@ -60,7 +87,7 @@ export interface DynamicItemSizeSectionMatrixEvents extends Omit<UiTypes.MatrixE
|
|
|
60
87
|
*
|
|
61
88
|
* events:
|
|
62
89
|
*
|
|
63
|
-
* 可以使用 matrix
|
|
90
|
+
* 可以使用 matrix 事件,但不包括 itemSize 以及与重新排序相关的事件
|
|
64
91
|
*
|
|
65
92
|
* 其他特殊事件:
|
|
66
93
|
*
|
|
@@ -77,11 +104,12 @@ export interface DynamicItemSizeSectionMatrixEvents extends Omit<UiTypes.MatrixE
|
|
|
77
104
|
* - cell(indexPath: NSIndexPath): AllUIView;
|
|
78
105
|
* - scrollTo(args: { indexPath: NSIndexPath; animated?: boolean }): void;
|
|
79
106
|
*/
|
|
80
|
-
export declare class DynamicItemSizeSectionMatrix extends Base<UIView, UiTypes.ViewOptions> {
|
|
107
|
+
export declare class DynamicItemSizeSectionMatrix<TSection extends DynamicItemSizeSectionMatrixAnySection = DynamicItemSizeSectionMatrixSection> extends Base<UIView, UiTypes.ViewOptions> {
|
|
81
108
|
_defineView: () => UiTypes.ViewOptions;
|
|
82
109
|
private _props;
|
|
83
110
|
private _data;
|
|
84
111
|
private _events;
|
|
112
|
+
private _sectionTitleTemplate?;
|
|
85
113
|
private _itemSizeWidth;
|
|
86
114
|
private _itemSizeHeight;
|
|
87
115
|
private _totalWidth;
|
|
@@ -92,14 +120,16 @@ export declare class DynamicItemSizeSectionMatrix extends Base<UIView, UiTypes.V
|
|
|
92
120
|
private _spacing;
|
|
93
121
|
matrix: Matrix;
|
|
94
122
|
constructor({ props, layout, events, }: {
|
|
95
|
-
props: DynamicItemSizeSectionMatrixProps
|
|
123
|
+
props: DynamicItemSizeSectionMatrixProps<TSection>;
|
|
96
124
|
layout: (make: MASConstraintMaker, view: UIView) => void;
|
|
97
125
|
events: DynamicItemSizeSectionMatrixEvents;
|
|
98
126
|
});
|
|
127
|
+
private _isOriginalItem;
|
|
128
|
+
private _getSectionTitleHeight;
|
|
99
129
|
private _mapData;
|
|
100
130
|
private _mapTemplate;
|
|
101
|
-
get data():
|
|
102
|
-
set data(data:
|
|
131
|
+
get data(): TSection[];
|
|
132
|
+
set data(data: TSection[]);
|
|
103
133
|
reload(): void;
|
|
104
134
|
object(indexPath: NSIndexPath): Record<string, unknown>;
|
|
105
135
|
insert({ indexPath, value }: {
|
|
@@ -113,3 +143,4 @@ export declare class DynamicItemSizeSectionMatrix extends Base<UIView, UiTypes.V
|
|
|
113
143
|
animated?: boolean;
|
|
114
144
|
}): void;
|
|
115
145
|
}
|
|
146
|
+
export {};
|
|
@@ -25,19 +25,27 @@ function _getTextHeight(text, width) {
|
|
|
25
25
|
inset: 0,
|
|
26
26
|
});
|
|
27
27
|
}
|
|
28
|
+
const _defaultSectionTitleHorizontalInset = 10;
|
|
28
29
|
/**
|
|
29
30
|
* # CView Dynamic ItemSize Section Matrix
|
|
30
31
|
*
|
|
31
|
-
* 此组件是为了在 Dynamic ItemSize Matrix 的基础上添加 SectionTitle
|
|
32
|
+
* 此组件是为了在 Dynamic ItemSize Matrix 的基础上添加 SectionTitle。
|
|
33
|
+
* SectionTitle 实际上是一个位于每个 section 首位的全宽 header cell,为兼容现有API继续使用title命名。
|
|
32
34
|
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* -
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
35
|
+
* 注意事项:
|
|
36
|
+
* 1. 默认模式中每个section的title为字符串;空字符串依然添加高度35的空格(该高度包含spacing)
|
|
37
|
+
* 2. 默认title的字体为font(13),左右边距为10,即文本宽度为 totalWidth - 2 * spacing - 20
|
|
38
|
+
* 3. 提供sectionTitleTemplate后进入自定义模式,title为模板数据,titleHeight为标题cell的实际高度(不包含spacing)
|
|
39
|
+
* 4. sectionTitle会使得section之间的间隔增加自身的高度
|
|
40
|
+
* 5. 由于sectionTitle必然和底下的item会有spacing,所以不建议spacing设的太大,那样会很违和
|
|
41
|
+
* 6. 每个section会使用不可见item补齐最后一行,避免原生Flow Layout将未满行居中排列
|
|
42
|
+
* 7. matrix事件会自动过滤sectionTitle和不可见item,并调整indexPath,包括didSelect、didLongPress、forEachItem
|
|
43
|
+
* 8. matrix的方法都在该组件中重新实现,自动调整indexPath
|
|
44
|
+
*
|
|
45
|
+
* 不支持:
|
|
46
|
+
* 1. 不支持matrix原有的重新排序、自动大小功能
|
|
47
|
+
* 2. 为防止sectionTitle暴露,也不支持menu
|
|
48
|
+
* 3. 不支持Dynamic ItemSize Matrix的dynamicHeightEnabled、heightToWidth
|
|
41
49
|
*
|
|
42
50
|
* ## 动态调整 itemSize
|
|
43
51
|
*
|
|
@@ -59,11 +67,15 @@ function _getTextHeight(text, width) {
|
|
|
59
67
|
*
|
|
60
68
|
* 可以使用 matrix 的全部属性。
|
|
61
69
|
*
|
|
62
|
-
*
|
|
70
|
+
* 默认模式的data类型为:
|
|
63
71
|
* { title: string; items: Record<string, unknown>[] }
|
|
64
72
|
*
|
|
73
|
+
* 提供sectionTitleTemplate后,自定义模式的data类型为:
|
|
74
|
+
* { title: Record<string, unknown>; titleHeight: number; items: Record<string, unknown>[] }
|
|
75
|
+
*
|
|
65
76
|
* 特殊属性:
|
|
66
77
|
*
|
|
78
|
+
* - sectionTitleTemplate 自定义section title模板;是否提供该属性即为模式开关
|
|
67
79
|
* - fixedItemHeight 固定 itemSize 高度
|
|
68
80
|
* - minItemWidth 最小的 itemSize 宽度
|
|
69
81
|
* - maxColumns 最大列数
|
|
@@ -71,7 +83,7 @@ function _getTextHeight(text, width) {
|
|
|
71
83
|
*
|
|
72
84
|
* events:
|
|
73
85
|
*
|
|
74
|
-
* 可以使用 matrix
|
|
86
|
+
* 可以使用 matrix 事件,但不包括 itemSize 以及与重新排序相关的事件
|
|
75
87
|
*
|
|
76
88
|
* 其他特殊事件:
|
|
77
89
|
*
|
|
@@ -96,6 +108,7 @@ class DynamicItemSizeSectionMatrix extends base_1.Base {
|
|
|
96
108
|
this._props = props;
|
|
97
109
|
this._data = this._props.data ?? [];
|
|
98
110
|
this._events = events;
|
|
111
|
+
this._sectionTitleTemplate = props.sectionTitleTemplate;
|
|
99
112
|
this._itemSizeWidth = 0;
|
|
100
113
|
this._itemSizeHeight = 0;
|
|
101
114
|
this._fixedItemHeight = this._props.fixedItemHeight ?? 96;
|
|
@@ -103,9 +116,11 @@ class DynamicItemSizeSectionMatrix extends base_1.Base {
|
|
|
103
116
|
this._maxColumns = this._props.maxColumns ?? 5;
|
|
104
117
|
this._spacing = this._props.spacing ?? 6;
|
|
105
118
|
const { itemHeight, didSelect, didLongPress, forEachItem, ...otherEvents } = this._events;
|
|
119
|
+
const { sectionTitleTemplate, ...matrixProps } = props;
|
|
106
120
|
this.matrix = new single_views_1.Matrix({
|
|
107
121
|
props: {
|
|
108
|
-
...
|
|
122
|
+
...matrixProps,
|
|
123
|
+
spacing: this._spacing,
|
|
109
124
|
data: this._mapData(this._data),
|
|
110
125
|
template: this._mapTemplate(props.template),
|
|
111
126
|
},
|
|
@@ -118,8 +133,7 @@ class DynamicItemSizeSectionMatrix extends base_1.Base {
|
|
|
118
133
|
}
|
|
119
134
|
if (indexPath.item === 0) {
|
|
120
135
|
const width = Math.max(this._totalWidth - 2 * this._spacing, 32);
|
|
121
|
-
const
|
|
122
|
-
const height = textHeight + 35 - this._spacing * (indexPath.section === 0 ? 1 : 2);
|
|
136
|
+
const height = this._getSectionTitleHeight(indexPath.section, width);
|
|
123
137
|
return $size(width, height);
|
|
124
138
|
}
|
|
125
139
|
else {
|
|
@@ -128,32 +142,23 @@ class DynamicItemSizeSectionMatrix extends base_1.Base {
|
|
|
128
142
|
},
|
|
129
143
|
didSelect: didSelect
|
|
130
144
|
? (sender, indexPath) => {
|
|
131
|
-
if (indexPath
|
|
145
|
+
if (!this._isOriginalItem(indexPath))
|
|
132
146
|
return;
|
|
133
|
-
|
|
134
|
-
else {
|
|
135
|
-
didSelect(sender, $indexPath(indexPath.section, indexPath.item - 1), this._data[indexPath.section].items[indexPath.item - 1]);
|
|
136
|
-
}
|
|
147
|
+
didSelect(sender, $indexPath(indexPath.section, indexPath.item - 1), this._data[indexPath.section].items[indexPath.item - 1]);
|
|
137
148
|
}
|
|
138
149
|
: undefined,
|
|
139
150
|
didLongPress: didLongPress
|
|
140
151
|
? (sender, indexPath) => {
|
|
141
|
-
if (indexPath
|
|
152
|
+
if (!this._isOriginalItem(indexPath))
|
|
142
153
|
return;
|
|
143
|
-
|
|
144
|
-
else {
|
|
145
|
-
didLongPress(sender, $indexPath(indexPath.section, indexPath.item - 1), this._data[indexPath.section].items[indexPath.item - 1]);
|
|
146
|
-
}
|
|
154
|
+
didLongPress(sender, $indexPath(indexPath.section, indexPath.item - 1), this._data[indexPath.section].items[indexPath.item - 1]);
|
|
147
155
|
}
|
|
148
156
|
: undefined,
|
|
149
157
|
forEachItem: forEachItem
|
|
150
158
|
? (sender, indexPath) => {
|
|
151
|
-
if (indexPath
|
|
159
|
+
if (!this._isOriginalItem(indexPath))
|
|
152
160
|
return;
|
|
153
|
-
|
|
154
|
-
else {
|
|
155
|
-
forEachItem(sender, $indexPath(indexPath.section, indexPath.item - 1));
|
|
156
|
-
}
|
|
161
|
+
forEachItem(sender, $indexPath(indexPath.section, indexPath.item - 1));
|
|
157
162
|
}
|
|
158
163
|
: undefined,
|
|
159
164
|
},
|
|
@@ -174,36 +179,68 @@ class DynamicItemSizeSectionMatrix extends base_1.Base {
|
|
|
174
179
|
return;
|
|
175
180
|
this._totalWidth = sender.frame.width;
|
|
176
181
|
const { columns, itemSizeWidth } = _getColumnsAndItemSizeWidth(this._totalWidth, this._minItemWidth, this._maxColumns, this._spacing);
|
|
182
|
+
const columnsChanged = columns !== this._columns;
|
|
177
183
|
this._columns = columns;
|
|
178
184
|
this._itemSizeWidth = itemSizeWidth;
|
|
179
185
|
this._itemSizeHeight = this._events.itemHeight
|
|
180
186
|
? this._events.itemHeight(this._itemSizeWidth)
|
|
181
187
|
: this._fixedItemHeight;
|
|
188
|
+
if (columnsChanged) {
|
|
189
|
+
this.matrix.view.data = this._mapData(this._data);
|
|
190
|
+
}
|
|
182
191
|
this.matrix.view.reload();
|
|
183
192
|
},
|
|
184
193
|
},
|
|
185
194
|
};
|
|
186
195
|
};
|
|
187
196
|
}
|
|
197
|
+
_isOriginalItem(indexPath) {
|
|
198
|
+
const itemCount = this._data[indexPath.section]?.items.length ?? 0;
|
|
199
|
+
return indexPath.item > 0 && indexPath.item <= itemCount;
|
|
200
|
+
}
|
|
201
|
+
_getSectionTitleHeight(section, width) {
|
|
202
|
+
const sectionData = this._data[section];
|
|
203
|
+
if (this._sectionTitleTemplate) {
|
|
204
|
+
return Math.max(sectionData.titleHeight, 1);
|
|
205
|
+
}
|
|
206
|
+
const textHeight = _getTextHeight(sectionData.title, width - _defaultSectionTitleHorizontalInset * 2);
|
|
207
|
+
return textHeight + 35 - this._spacing * (section === 0 ? 1 : 2);
|
|
208
|
+
}
|
|
188
209
|
_mapData(data) {
|
|
189
210
|
return data.map((n) => {
|
|
190
211
|
const mappedItems = n.items.map((n) => {
|
|
191
212
|
return {
|
|
192
213
|
__section_title__: { hidden: true },
|
|
214
|
+
__placeholder__: { hidden: true },
|
|
193
215
|
__original_template__: { hidden: false },
|
|
194
216
|
...n,
|
|
195
217
|
};
|
|
196
218
|
});
|
|
219
|
+
const placeholderCount = (this._columns - (n.items.length % this._columns)) % this._columns;
|
|
220
|
+
const placeholders = Array.from({ length: placeholderCount }, () => ({
|
|
221
|
+
__section_title__: { hidden: true },
|
|
222
|
+
__placeholder__: { hidden: false },
|
|
223
|
+
__original_template__: { hidden: true },
|
|
224
|
+
}));
|
|
225
|
+
const titleData = this._sectionTitleTemplate
|
|
226
|
+
? {
|
|
227
|
+
...n.title,
|
|
228
|
+
__section_title__: { hidden: false },
|
|
229
|
+
__placeholder__: { hidden: true },
|
|
230
|
+
__original_template__: { hidden: true },
|
|
231
|
+
}
|
|
232
|
+
: {
|
|
233
|
+
__section_title__: { hidden: false },
|
|
234
|
+
__placeholder__: { hidden: true },
|
|
235
|
+
__section_title_label__: {
|
|
236
|
+
hidden: false,
|
|
237
|
+
text: n.title,
|
|
238
|
+
},
|
|
239
|
+
__original_template__: { hidden: true },
|
|
240
|
+
};
|
|
197
241
|
return {
|
|
198
242
|
title: "",
|
|
199
|
-
items: [
|
|
200
|
-
{
|
|
201
|
-
__section_title__: { hidden: false },
|
|
202
|
-
__section_title_label__: { text: n.title },
|
|
203
|
-
__original_template__: { hidden: true },
|
|
204
|
-
},
|
|
205
|
-
...mappedItems,
|
|
206
|
-
],
|
|
243
|
+
items: [titleData, ...mappedItems, ...placeholders],
|
|
207
244
|
};
|
|
208
245
|
});
|
|
209
246
|
}
|
|
@@ -218,6 +255,46 @@ class DynamicItemSizeSectionMatrix extends base_1.Base {
|
|
|
218
255
|
id: "__section_title__",
|
|
219
256
|
},
|
|
220
257
|
layout: $layout.fill,
|
|
258
|
+
views: this._sectionTitleTemplate
|
|
259
|
+
? [
|
|
260
|
+
{
|
|
261
|
+
type: "view",
|
|
262
|
+
props: this._sectionTitleTemplate.props ?? {},
|
|
263
|
+
layout: $layout.fill,
|
|
264
|
+
views: this._sectionTitleTemplate.views,
|
|
265
|
+
},
|
|
266
|
+
]
|
|
267
|
+
: [
|
|
268
|
+
{
|
|
269
|
+
type: "label",
|
|
270
|
+
props: {
|
|
271
|
+
id: "__section_title_label__",
|
|
272
|
+
bgcolor: $color("clear"),
|
|
273
|
+
font: $font(13),
|
|
274
|
+
textColor: $color("secondaryText"),
|
|
275
|
+
lines: 0,
|
|
276
|
+
},
|
|
277
|
+
layout: (make, view) => {
|
|
278
|
+
make.left.right.inset(_defaultSectionTitleHorizontalInset);
|
|
279
|
+
make.bottom.inset(0);
|
|
280
|
+
},
|
|
281
|
+
},
|
|
282
|
+
{
|
|
283
|
+
// 在这里放一个透明且无效果的button,从而取消item自己的highlight效果
|
|
284
|
+
type: "button",
|
|
285
|
+
props: {
|
|
286
|
+
bgcolor: $color("clear"),
|
|
287
|
+
},
|
|
288
|
+
layout: $layout.fill,
|
|
289
|
+
},
|
|
290
|
+
],
|
|
291
|
+
},
|
|
292
|
+
{
|
|
293
|
+
type: "view",
|
|
294
|
+
props: {
|
|
295
|
+
id: "__placeholder__",
|
|
296
|
+
},
|
|
297
|
+
layout: $layout.fill,
|
|
221
298
|
views: [
|
|
222
299
|
{
|
|
223
300
|
// 在这里放一个透明且无效果的button,从而取消item自己的highlight效果
|
|
@@ -227,20 +304,6 @@ class DynamicItemSizeSectionMatrix extends base_1.Base {
|
|
|
227
304
|
},
|
|
228
305
|
layout: $layout.fill,
|
|
229
306
|
},
|
|
230
|
-
{
|
|
231
|
-
type: "label",
|
|
232
|
-
props: {
|
|
233
|
-
id: "__section_title_label__",
|
|
234
|
-
bgcolor: $color("clear"),
|
|
235
|
-
font: $font(13),
|
|
236
|
-
textColor: $color("secondaryText"),
|
|
237
|
-
lines: 0,
|
|
238
|
-
},
|
|
239
|
-
layout: (make, view) => {
|
|
240
|
-
make.left.right.inset(16);
|
|
241
|
-
make.bottom.inset(0);
|
|
242
|
-
},
|
|
243
|
-
},
|
|
244
307
|
],
|
|
245
308
|
},
|
|
246
309
|
{
|
|
@@ -89,13 +89,22 @@ class PageViewer extends base_1.Base {
|
|
|
89
89
|
return this._props.page;
|
|
90
90
|
}
|
|
91
91
|
set page(page) {
|
|
92
|
-
this.
|
|
93
|
-
if (this.scroll.view.contentOffset.x !== page * this._pageWidth)
|
|
92
|
+
if (this.scroll.view.contentOffset.x !== page * this._pageWidth) {
|
|
94
93
|
this.scroll.view.contentOffset = $point(page * this._pageWidth, 0);
|
|
94
|
+
}
|
|
95
|
+
if (this._props.page !== page) {
|
|
96
|
+
this._props.page = page;
|
|
97
|
+
if (this._events.changed)
|
|
98
|
+
this._events.changed(this, page);
|
|
99
|
+
}
|
|
95
100
|
}
|
|
96
101
|
scrollToPage(page) {
|
|
97
102
|
this.scroll.view.scrollToOffset($point(page * this._pageWidth, 0));
|
|
98
|
-
this._props.page
|
|
103
|
+
if (this._props.page !== page) {
|
|
104
|
+
this._props.page = page;
|
|
105
|
+
if (this._events.changed)
|
|
106
|
+
this._events.changed(this, page);
|
|
107
|
+
}
|
|
99
108
|
}
|
|
100
109
|
}
|
|
101
110
|
exports.PageViewer = PageViewer;
|
|
@@ -1,21 +1,5 @@
|
|
|
1
1
|
import { Base } from "../components/base";
|
|
2
2
|
import { ContentView } from "../components/single-views";
|
|
3
|
-
/**
|
|
4
|
-
* status
|
|
5
|
-
* - created = 0 被创建,未被加载
|
|
6
|
-
* - loaded = 1 被加载,显示状态未知
|
|
7
|
-
* - appeared= 2 处于可显示状态
|
|
8
|
-
* - disappeared = 3 处于不显示状态
|
|
9
|
-
* - removed = 4 根视图被移除
|
|
10
|
-
* 其中只有 2 和 3 可以相互转化,其他不可以
|
|
11
|
-
*/
|
|
12
|
-
export declare const controllerStatus: {
|
|
13
|
-
created: number;
|
|
14
|
-
loaded: number;
|
|
15
|
-
appeared: number;
|
|
16
|
-
disappeared: number;
|
|
17
|
-
removed: number;
|
|
18
|
-
};
|
|
19
3
|
export declare class ControllerRootView extends ContentView {
|
|
20
4
|
constructor({ props, layout, events, }: {
|
|
21
5
|
props: {
|
|
@@ -33,7 +17,6 @@ export interface BaseControllerProps {
|
|
|
33
17
|
bgcolor?: UIColor;
|
|
34
18
|
}
|
|
35
19
|
export interface BaseControllerEvents {
|
|
36
|
-
didCreate?: (controller: BaseController) => void;
|
|
37
20
|
didLoad?: (controller: BaseController) => void;
|
|
38
21
|
didAppear?: (controller: BaseController) => void;
|
|
39
22
|
didDisappear?: (controller: BaseController) => void;
|
|
@@ -1,26 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BaseController = exports.ControllerRootView =
|
|
3
|
+
exports.BaseController = exports.ControllerRootView = void 0;
|
|
4
4
|
const base_1 = require("../components/base");
|
|
5
5
|
const single_views_1 = require("../components/single-views");
|
|
6
6
|
const cvid_1 = require("../utils/cvid");
|
|
7
7
|
const controller_router_1 = require("./controller-router");
|
|
8
|
-
|
|
9
|
-
* status
|
|
10
|
-
* - created = 0 被创建,未被加载
|
|
11
|
-
* - loaded = 1 被加载,显示状态未知
|
|
12
|
-
* - appeared= 2 处于可显示状态
|
|
13
|
-
* - disappeared = 3 处于不显示状态
|
|
14
|
-
* - removed = 4 根视图被移除
|
|
15
|
-
* 其中只有 2 和 3 可以相互转化,其他不可以
|
|
16
|
-
*/
|
|
17
|
-
exports.controllerStatus = {
|
|
18
|
-
created: 0,
|
|
19
|
-
loaded: 1,
|
|
20
|
-
appeared: 2,
|
|
21
|
-
disappeared: 3,
|
|
22
|
-
removed: 4,
|
|
23
|
-
};
|
|
8
|
+
const controller_status_1 = require("./controller-status");
|
|
24
9
|
class ControllerRootView extends single_views_1.ContentView {
|
|
25
10
|
constructor({ props, layout, events, }) {
|
|
26
11
|
super({ props, layout, events });
|
|
@@ -102,7 +87,7 @@ class BaseController {
|
|
|
102
87
|
this._props = props || {};
|
|
103
88
|
this._events = events;
|
|
104
89
|
this.id = this._props.id || cvid_1.cvid.newId;
|
|
105
|
-
this._status =
|
|
90
|
+
this._status = controller_status_1.controllerStatus.created; // status使用额外的get来使其只读
|
|
106
91
|
this.rootView = new ControllerRootView({
|
|
107
92
|
props: {
|
|
108
93
|
bgcolor: this._props.bgcolor || $color("primarySurface"),
|
|
@@ -116,38 +101,38 @@ class BaseController {
|
|
|
116
101
|
}
|
|
117
102
|
load() {
|
|
118
103
|
// 只有status为created才可以运行
|
|
119
|
-
if (this._status !==
|
|
104
|
+
if (this._status !== controller_status_1.controllerStatus.created)
|
|
120
105
|
return;
|
|
121
|
-
this._status =
|
|
106
|
+
this._status = controller_status_1.controllerStatus.loaded;
|
|
122
107
|
if (this._events.didLoad)
|
|
123
108
|
this._events.didLoad(this);
|
|
124
109
|
controller_router_1.router.add(this);
|
|
125
110
|
}
|
|
126
111
|
appear() {
|
|
127
112
|
// 只有status为loaded或者disappeared,才可以运行
|
|
128
|
-
if (this._status !==
|
|
113
|
+
if (this._status !== controller_status_1.controllerStatus.loaded && this._status !== controller_status_1.controllerStatus.disappeared)
|
|
129
114
|
return;
|
|
130
115
|
if (this._events.didAppear)
|
|
131
116
|
this._events.didAppear(this);
|
|
132
|
-
this._status =
|
|
117
|
+
this._status = controller_status_1.controllerStatus.appeared;
|
|
133
118
|
}
|
|
134
119
|
disappear() {
|
|
135
120
|
// 只有status为loaded或者appeared,才可以运行
|
|
136
|
-
if (this._status !==
|
|
121
|
+
if (this._status !== controller_status_1.controllerStatus.loaded && this._status !== controller_status_1.controllerStatus.appeared)
|
|
137
122
|
return;
|
|
138
123
|
if (this._events.didDisappear)
|
|
139
124
|
this._events.didDisappear(this);
|
|
140
|
-
this._status =
|
|
125
|
+
this._status = controller_status_1.controllerStatus.disappeared;
|
|
141
126
|
}
|
|
142
127
|
// 此方法不能用于移除rootView,其作用是将控制器从Router中移除,并触发didRemove事件
|
|
143
128
|
remove() {
|
|
144
129
|
// 如果已经移除,不可以再次运行
|
|
145
|
-
if (this._status ===
|
|
130
|
+
if (this._status === controller_status_1.controllerStatus.removed)
|
|
146
131
|
return;
|
|
147
132
|
if (this._events.didRemove)
|
|
148
133
|
this._events.didRemove(this);
|
|
149
134
|
controller_router_1.router.delete(this);
|
|
150
|
-
this._status =
|
|
135
|
+
this._status = controller_status_1.controllerStatus.removed;
|
|
151
136
|
}
|
|
152
137
|
uirender(props) {
|
|
153
138
|
controller_router_1.router.root = this;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.router = void 0;
|
|
4
|
+
const controller_status_1 = require("./controller-status");
|
|
4
5
|
/**
|
|
5
6
|
* 控制器的路由器,用于管理控制器的集合和操作。
|
|
6
7
|
*
|
|
@@ -52,7 +53,7 @@ class Router {
|
|
|
52
53
|
get appeared() {
|
|
53
54
|
const appearedControllers = [];
|
|
54
55
|
for (const c of this._set) {
|
|
55
|
-
if (c.status ===
|
|
56
|
+
if (c.status === controller_status_1.controllerStatus.appeared)
|
|
56
57
|
appearedControllers.push(c);
|
|
57
58
|
}
|
|
58
59
|
return appearedControllers;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* status
|
|
3
|
+
* - created = 0 被创建,未被加载
|
|
4
|
+
* - loaded = 1 被加载,显示状态未知
|
|
5
|
+
* - appeared= 2 处于可显示状态
|
|
6
|
+
* - disappeared = 3 处于不显示状态
|
|
7
|
+
* - removed = 4 根视图被移除
|
|
8
|
+
* 其中只有 2 和 3 可以相互转化,其他不可以
|
|
9
|
+
*/
|
|
10
|
+
export declare const controllerStatus: {
|
|
11
|
+
readonly created: 0;
|
|
12
|
+
readonly loaded: 1;
|
|
13
|
+
readonly appeared: 2;
|
|
14
|
+
readonly disappeared: 3;
|
|
15
|
+
readonly removed: 4;
|
|
16
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.controllerStatus = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* status
|
|
6
|
+
* - created = 0 被创建,未被加载
|
|
7
|
+
* - loaded = 1 被加载,显示状态未知
|
|
8
|
+
* - appeared= 2 处于可显示状态
|
|
9
|
+
* - disappeared = 3 处于不显示状态
|
|
10
|
+
* - removed = 4 根视图被移除
|
|
11
|
+
* 其中只有 2 和 3 可以相互转化,其他不可以
|
|
12
|
+
*/
|
|
13
|
+
exports.controllerStatus = {
|
|
14
|
+
created: 0,
|
|
15
|
+
loaded: 1,
|
|
16
|
+
appeared: 2,
|
|
17
|
+
disappeared: 3,
|
|
18
|
+
removed: 4,
|
|
19
|
+
};
|
|
@@ -5,6 +5,7 @@ const base_controller_1 = require("./base-controller");
|
|
|
5
5
|
const pageviewer_1 = require("../components/pageviewer");
|
|
6
6
|
const pageviewer_titlebar_1 = require("../components/pageviewer-titlebar");
|
|
7
7
|
const custom_navigation_bar_1 = require("../components/custom-navigation-bar");
|
|
8
|
+
const controller_status_1 = require("./controller-status");
|
|
8
9
|
/**
|
|
9
10
|
* # CView PageViewer Controller
|
|
10
11
|
*
|
|
@@ -23,7 +24,20 @@ class PageViewerController extends base_controller_1.BaseController {
|
|
|
23
24
|
bgcolor: props.bgcolor,
|
|
24
25
|
},
|
|
25
26
|
layout,
|
|
26
|
-
events
|
|
27
|
+
events: {
|
|
28
|
+
didLoad: events.didLoad,
|
|
29
|
+
didAppear: (controller) => {
|
|
30
|
+
props.items[this.index].controller.appear();
|
|
31
|
+
events.didAppear?.(controller);
|
|
32
|
+
},
|
|
33
|
+
didDisappear: (controller) => {
|
|
34
|
+
props.items.forEach((item) => item.controller.disappear());
|
|
35
|
+
events.didDisappear?.(controller);
|
|
36
|
+
},
|
|
37
|
+
didRemove: (controller) => {
|
|
38
|
+
events.didRemove?.(controller);
|
|
39
|
+
},
|
|
40
|
+
},
|
|
27
41
|
});
|
|
28
42
|
this._props = props;
|
|
29
43
|
this.cviews = {};
|
|
@@ -37,13 +51,28 @@ class PageViewerController extends base_controller_1.BaseController {
|
|
|
37
51
|
make.top.equalTo(view.prev.bottom);
|
|
38
52
|
},
|
|
39
53
|
events: {
|
|
40
|
-
floatPageChanged: (cview, floatPage) =>
|
|
54
|
+
floatPageChanged: (cview, floatPage) => {
|
|
55
|
+
this.cviews.titlebar.floatedIndex = floatPage;
|
|
56
|
+
},
|
|
57
|
+
changed: (cview, page) => {
|
|
58
|
+
this._props.index = page;
|
|
59
|
+
if (this.status !== controller_status_1.controllerStatus.appeared)
|
|
60
|
+
return;
|
|
61
|
+
this._props.items.forEach((item, i) => {
|
|
62
|
+
if (i === page) {
|
|
63
|
+
item.controller.appear();
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
item.controller.disappear();
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
},
|
|
41
70
|
},
|
|
42
71
|
});
|
|
43
72
|
this.cviews.titlebar = new pageviewer_titlebar_1.PageViewerTitleBar({
|
|
44
73
|
props: {
|
|
45
74
|
items: this._props.items.map((n) => n.title),
|
|
46
|
-
index: this._props.index
|
|
75
|
+
index: this._props.index ?? 0,
|
|
47
76
|
},
|
|
48
77
|
layout: $layout.fill,
|
|
49
78
|
events: {
|
|
@@ -5,6 +5,7 @@ const base_controller_1 = require("./base-controller");
|
|
|
5
5
|
const base_1 = require("../components/base");
|
|
6
6
|
const single_views_1 = require("../components/single-views");
|
|
7
7
|
const cvid_1 = require("../utils/cvid");
|
|
8
|
+
const controller_status_1 = require("./controller-status");
|
|
8
9
|
class SecondaryView extends base_1.Base {
|
|
9
10
|
constructor({ props, layout, views = [], }) {
|
|
10
11
|
super();
|
|
@@ -207,13 +208,13 @@ class SplitViewController extends base_controller_1.BaseController {
|
|
|
207
208
|
this.rootView.views = [this.cviews.secondaryView, this.cviews.primaryView];
|
|
208
209
|
}
|
|
209
210
|
load() {
|
|
210
|
-
if (this.status !==
|
|
211
|
+
if (this.status !== controller_status_1.controllerStatus.created)
|
|
211
212
|
return;
|
|
212
213
|
super.load();
|
|
213
214
|
this._renewScreenEdgePanGesture();
|
|
214
215
|
}
|
|
215
216
|
remove() {
|
|
216
|
-
if (this.status ===
|
|
217
|
+
if (this.status === controller_status_1.controllerStatus.removed)
|
|
217
218
|
return;
|
|
218
219
|
$objc_release(this._screenEdgePanGestureObject);
|
|
219
220
|
this.cviews.maskView.releaseGestureObject();
|
|
@@ -4,6 +4,7 @@ exports.TabBarController = void 0;
|
|
|
4
4
|
const base_controller_1 = require("./base-controller");
|
|
5
5
|
const single_views_1 = require("../components/single-views");
|
|
6
6
|
const tabbar_1 = require("../components/tabbar");
|
|
7
|
+
const controller_status_1 = require("./controller-status");
|
|
7
8
|
/**
|
|
8
9
|
* # CView TabBar Controller
|
|
9
10
|
*
|
|
@@ -86,7 +87,7 @@ class TabBarController extends base_controller_1.BaseController {
|
|
|
86
87
|
n.view.hidden = i !== num;
|
|
87
88
|
});
|
|
88
89
|
this._props.index = num;
|
|
89
|
-
this._props.items.find((item) => item.controller.status ===
|
|
90
|
+
this._props.items.find((item) => item.controller.status === controller_status_1.controllerStatus.appeared)?.controller.disappear();
|
|
90
91
|
this._props.items[num].controller.appear();
|
|
91
92
|
}
|
|
92
93
|
get index() {
|
package/dist/index.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ export * from "./components/single-views";
|
|
|
21
21
|
export * from "./components/static-preference-listview";
|
|
22
22
|
export * from "./components/symbol-button";
|
|
23
23
|
export * from "./components/tabbar";
|
|
24
|
+
export * from "./controller/controller-status";
|
|
24
25
|
export * from "./controller/base-controller";
|
|
25
26
|
export * from "./controller/controller-router";
|
|
26
27
|
export * from "./controller/pageviewer-controller";
|
package/dist/index.js
CHANGED
|
@@ -37,6 +37,7 @@ __exportStar(require("./components/single-views"), exports);
|
|
|
37
37
|
__exportStar(require("./components/static-preference-listview"), exports);
|
|
38
38
|
__exportStar(require("./components/symbol-button"), exports);
|
|
39
39
|
__exportStar(require("./components/tabbar"), exports);
|
|
40
|
+
__exportStar(require("./controller/controller-status"), exports);
|
|
40
41
|
__exportStar(require("./controller/base-controller"), exports);
|
|
41
42
|
__exportStar(require("./controller/controller-router"), exports);
|
|
42
43
|
__exportStar(require("./controller/pageviewer-controller"), exports);
|