jsbox-cview 1.6.5 → 1.6.7
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/README.md +4 -0
- package/dist/components/alert/input-alert.d.ts +22 -0
- package/dist/components/alert/input-alert.js +1 -2
- package/dist/components/alert/login-alert.d.ts +21 -0
- package/dist/components/alert/login-alert.js +1 -2
- package/dist/components/alert/plain-alert.d.ts +15 -0
- package/dist/components/alert/plain-alert.js +1 -2
- package/dist/components/alert/uialert.d.ts +29 -0
- package/{components/base.ts → dist/components/base.d.ts} +9 -28
- package/dist/components/custom-navigation-bar.d.ts +117 -0
- package/dist/components/custom-navigation-bar.js +7 -1
- package/dist/components/dialogs/dialog-sheet.d.ts +46 -0
- package/dist/components/dialogs/dialog-sheet.js +3 -1
- package/dist/components/dialogs/form-dialog.d.ts +15 -0
- package/dist/components/dialogs/form-dialog.js +1 -2
- package/dist/components/dialogs/list-dialog.d.ts +23 -0
- package/dist/components/dialogs/list-dialog.js +2 -3
- package/dist/components/dialogs/text-dialog.d.ts +13 -0
- package/dist/components/dialogs/text-dialog.js +1 -2
- package/dist/components/dynamic-contextmenu-view.d.ts +40 -0
- package/dist/components/dynamic-contextmenu-view.js +5 -1
- package/dist/components/dynamic-itemsize-matrix.d.ts +79 -0
- package/dist/components/dynamic-itemsize-matrix.js +18 -15
- package/dist/components/dynamic-itemsize-section-matrix.d.ts +115 -0
- package/dist/components/dynamic-itemsize-section-matrix.js +293 -0
- package/dist/components/dynamic-preference-listview.d.ts +63 -0
- package/dist/components/dynamic-preference-listview.js +25 -16
- package/dist/components/dynamic-rowheight-list.d.ts +38 -0
- package/dist/components/dynamic-rowheight-list.js +10 -3
- package/dist/components/enhanced-imageview.d.ts +41 -0
- package/dist/components/enhanced-imageview.js +1 -1
- package/dist/components/flowlayout.d.ts +63 -0
- package/dist/components/flowlayout.js +10 -13
- package/dist/components/image-pager.d.ts +49 -0
- package/dist/components/image-pager.js +6 -1
- package/dist/components/oc-webview.d.ts +64 -0
- package/dist/components/oc-webview.js +13 -5
- package/dist/components/page-control.d.ts +45 -0
- package/dist/components/page-control.js +2 -13
- package/dist/components/pageviewer-titlebar.d.ts +48 -0
- package/dist/components/pageviewer-titlebar.js +7 -13
- package/dist/components/pageviewer.d.ts +41 -0
- package/dist/components/pageviewer.js +4 -1
- package/dist/components/refresh-button.d.ts +25 -0
- package/dist/components/refresh-button.js +3 -4
- package/dist/components/rotating-view.d.ts +45 -0
- package/dist/components/rotating-view.js +10 -2
- package/dist/components/searchbar.d.ts +118 -0
- package/dist/components/searchbar.js +8 -1
- package/dist/components/sheet.d.ts +42 -0
- package/dist/components/single-views.d.ts +289 -0
- package/dist/components/single-views.js +11 -4
- package/dist/components/spinners/loading-dual-ring.d.ts +18 -0
- package/dist/components/spinners/loading-wedges.d.ts +15 -0
- package/dist/components/spinners/spinner-androidstyle.d.ts +30 -0
- package/dist/components/spinners/spinner-androidstyle.js +7 -1
- package/dist/components/static-preference-listview.d.ts +389 -0
- package/dist/components/static-preference-listview.js +13 -10
- package/dist/components/symbol-button.d.ts +39 -0
- package/dist/components/symbol-button.js +8 -1
- package/dist/components/tabbar.d.ts +140 -0
- package/dist/components/tabbar.js +8 -1
- package/dist/controller/base-controller.d.ts +125 -0
- package/dist/controller/base-controller.js +11 -11
- package/dist/controller/controller-router.d.ts +48 -0
- package/dist/controller/pageviewer-controller.d.ts +38 -0
- package/dist/controller/pageviewer-controller.js +4 -1
- package/dist/controller/presented-page-controller.d.ts +41 -0
- package/dist/controller/presented-page-controller.js +7 -9
- package/dist/controller/splitview-controller.d.ts +90 -0
- package/dist/controller/splitview-controller.js +27 -11
- package/dist/controller/tabbar-controller.d.ts +49 -0
- package/dist/controller/tabbar-controller.js +12 -15
- package/{index.ts → dist/index.d.ts} +2 -0
- package/dist/index.js +2 -0
- package/dist/utils/colors.d.ts +7 -0
- package/dist/utils/cvid.d.ts +11 -0
- package/dist/utils/l10n.d.ts +1 -0
- package/dist/utils/l10n.js +1 -2
- package/dist/utils/path.d.ts +8 -0
- package/dist/utils/path.js +8 -9
- package/dist/utils/rect.d.ts +38 -0
- package/dist/utils/rect.js +8 -9
- package/dist/utils/uitools.d.ts +75 -0
- package/dist/utils/uitools.js +6 -6
- package/package.json +20 -5
- package/.prettierignore +0 -6
- package/.prettierrc +0 -3
- package/components/alert/input-alert.ts +0 -64
- package/components/alert/login-alert.ts +0 -66
- package/components/alert/plain-alert.ts +0 -39
- package/components/alert/uialert.ts +0 -107
- package/components/custom-navigation-bar.ts +0 -579
- package/components/dialogs/dialog-sheet.ts +0 -111
- package/components/dialogs/form-dialog.ts +0 -63
- package/components/dialogs/list-dialog.ts +0 -119
- package/components/dialogs/text-dialog.ts +0 -44
- package/components/dynamic-contextmenu-view.ts +0 -115
- package/components/dynamic-itemsize-matrix.ts +0 -206
- package/components/dynamic-preference-listview.ts +0 -684
- package/components/dynamic-rowheight-list.ts +0 -77
- package/components/enhanced-imageview.ts +0 -132
- package/components/flowlayout.ts +0 -248
- package/components/image-pager.ts +0 -180
- package/components/oc-webview.ts +0 -177
- package/components/page-control.ts +0 -93
- package/components/pageviewer-titlebar.ts +0 -166
- package/components/pageviewer.ts +0 -125
- package/components/refresh-button.ts +0 -83
- package/components/rotating-view.ts +0 -133
- package/components/searchbar.ts +0 -398
- package/components/sheet.ts +0 -104
- package/components/single-views.ts +0 -956
- package/components/spinners/loading-dual-ring.ts +0 -97
- package/components/spinners/loading-wedges.ts +0 -106
- package/components/spinners/spinner-androidstyle.ts +0 -269
- package/components/static-preference-listview.ts +0 -1282
- package/components/symbol-button.ts +0 -108
- package/components/tabbar.ts +0 -453
- package/controller/base-controller.ts +0 -214
- package/controller/controller-router.ts +0 -73
- package/controller/pageviewer-controller.ts +0 -93
- package/controller/presented-page-controller.ts +0 -76
- package/controller/splitview-controller.ts +0 -359
- package/controller/tabbar-controller.ts +0 -131
- package/dist/test/custom-navigation-bar.js +0 -40
- package/dist/test/dialog-sheet.js +0 -40
- package/dist/test/dynamic-contextmenu-view.js +0 -66
- package/dist/test/dynamic-itemsize-matrix.js +0 -74
- package/dist/test/dynamic-preference-listview.js +0 -150
- package/dist/test/flowlayout.js +0 -76
- package/dist/test/form-dialog.js +0 -51
- package/dist/test/oc-webview.js +0 -195
- package/dist/test/pageviewer-controller.js +0 -20
- package/dist/test/pageviewer-titlebar.js +0 -18
- package/dist/test/pageviewer.js +0 -32
- package/dist/test/refresh-button.js +0 -26
- package/dist/test/searchbar.js +0 -36
- package/dist/test/splitview-controller.js +0 -41
- package/dist/test/static-preference-listview.js +0 -143
- package/dist/test/tabbar-controller.js +0 -48
- package/test/custom-navigation-bar.ts +0 -40
- package/test/dialog-sheet.ts +0 -40
- package/test/dynamic-contextmenu-view.ts +0 -67
- package/test/dynamic-itemsize-matrix.ts +0 -74
- package/test/dynamic-preference-listview.ts +0 -151
- package/test/flowlayout.ts +0 -79
- package/test/form-dialog.ts +0 -48
- package/test/oc-webview.ts +0 -197
- package/test/pageviewer-controller.ts +0 -21
- package/test/pageviewer-titlebar.ts +0 -18
- package/test/pageviewer.ts +0 -31
- package/test/refresh-button.ts +0 -26
- package/test/searchbar.ts +0 -38
- package/test/splitview-controller.ts +0 -42
- package/test/static-preference-listview.ts +0 -142
- package/test/tabbar-controller.ts +0 -49
- package/tsconfig.json +0 -122
- package/utils/colors.ts +0 -17
- package/utils/cvid.ts +0 -32
- package/utils/l10n.ts +0 -42
- package/utils/path.ts +0 -97
- package/utils/rect.ts +0 -90
- package/utils/uitools.ts +0 -122
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { Base } from "./base";
|
|
2
|
+
import { Matrix } from "./single-views";
|
|
3
|
+
export interface DynamicItemSizeSectionMatrixSection {
|
|
4
|
+
title: string;
|
|
5
|
+
items: Record<string, unknown>[];
|
|
6
|
+
}
|
|
7
|
+
export interface DynamicItemSizeSectionMatrixProps extends Omit<UiTypes.MatrixProps, "data" | "itemSize" | "autoItemSize" | "estimatedItemSize" | "columns" | "square" | "waterfall" | "reorder" | "menu"> {
|
|
8
|
+
data?: DynamicItemSizeSectionMatrixSection[];
|
|
9
|
+
fixedItemHeight?: number;
|
|
10
|
+
minItemWidth?: number;
|
|
11
|
+
maxColumns?: number;
|
|
12
|
+
spacing?: number;
|
|
13
|
+
}
|
|
14
|
+
export interface DynamicItemSizeSectionMatrixEvents extends Omit<UiTypes.MatrixEvents, "itemSize" | "reorderBegan" | "reorderMoved" | "canMoveItem" | "reorderFinished"> {
|
|
15
|
+
itemHeight?: (width: number) => number;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* # CView Dynamic ItemSize Section Matrix
|
|
19
|
+
*
|
|
20
|
+
* 此组件是为了在 Dynamic ItemSize Matrix 的基础上添加 SectionTitle
|
|
21
|
+
*
|
|
22
|
+
* - 使用此组件必须在每个section中添加title,如果title为空字符串,依然添加高度35的空格(包含spacing)
|
|
23
|
+
* - sectionTitle的字体为font(13),左右边距为16(不含spacing),即总宽度为 totalWidth - 2 * spacing - 32
|
|
24
|
+
* - 由于它必然和底下的item会有spacing,所以不建议spacing设的太大,那样会很违和
|
|
25
|
+
* - sectionTitle会使得section之间的间隔增加自身的高度
|
|
26
|
+
* - matrix事件会自动调整indexPath,包括didSelect、didLongPress、forEachItem
|
|
27
|
+
* - matrix的方法都在该组件中重新实现,自动调整indexPath
|
|
28
|
+
* - 不支持matrix原有的重新排序、自动大小功能,为防止sectionTitle暴露,也不支持menu
|
|
29
|
+
* - 不支持Dynamic ItemSize Matrix的dynamicHeightEnabled、heightToWidth
|
|
30
|
+
*
|
|
31
|
+
* ## 动态调整 itemSize
|
|
32
|
+
*
|
|
33
|
+
* 动态的改变自己的 itemSize,从而使得 spacing 被优先满足。
|
|
34
|
+
* 思路为在 matrix 上层套一个 superView,在旋转的时候 superView 会调用 matrix.relayout()
|
|
35
|
+
* 和 matrix.reload(),从而触发 itemSize 事件
|
|
36
|
+
*
|
|
37
|
+
* 其排布逻辑是这样的:
|
|
38
|
+
*
|
|
39
|
+
* 1. 由 minItemWidth,spacing,maxColumns 这三个参数决定 cloumns,
|
|
40
|
+
* 并结合 totalWidth 确定 itemSize.width
|
|
41
|
+
* 2. 确定 itemHeight 有两种方法:
|
|
42
|
+
* - fixedItemHeight 固定高度,优先级第二
|
|
43
|
+
* - event: itemHeight(width) => height 通过 width 动态计算,优先级最高
|
|
44
|
+
* 3. 如果 minItemWidth 比 totalWidth - 2 * spacing 还要小,那么 itemSize.width
|
|
45
|
+
* 会被设定为 totalWidth - 2 * spacing,以保证item不会超出边框
|
|
46
|
+
*
|
|
47
|
+
* ## props:
|
|
48
|
+
*
|
|
49
|
+
* 可以使用 matrix 的全部属性。
|
|
50
|
+
*
|
|
51
|
+
* 但data的类型调整为:
|
|
52
|
+
* { title: string; items: Record<string, unknown>[] }
|
|
53
|
+
*
|
|
54
|
+
* 特殊属性:
|
|
55
|
+
*
|
|
56
|
+
* - fixedItemHeight 固定 itemSize 高度
|
|
57
|
+
* - minItemWidth 最小的 itemSize 宽度
|
|
58
|
+
* - maxColumns 最大列数
|
|
59
|
+
* - spacing
|
|
60
|
+
*
|
|
61
|
+
* events:
|
|
62
|
+
*
|
|
63
|
+
* 可以使用 matrix 除 itemSize 以外的全部事件
|
|
64
|
+
*
|
|
65
|
+
* 其他特殊事件:
|
|
66
|
+
*
|
|
67
|
+
* - itemHeight: width => height 通过 itemWidth 动态计算 itemHeight
|
|
68
|
+
*
|
|
69
|
+
*
|
|
70
|
+
* 方法:
|
|
71
|
+
* - get data
|
|
72
|
+
* - set data
|
|
73
|
+
* - reload(): void;
|
|
74
|
+
* - object(indexPath: NSIndexPath): any;
|
|
75
|
+
* - insert(args: { indexPath: NSIndexPath;value: any; } ): void;
|
|
76
|
+
* - delete(indexPathOrIndex: NSIndexPath | number): void;
|
|
77
|
+
* - cell(indexPath: NSIndexPath): AllUIView;
|
|
78
|
+
* - scrollTo(args: { indexPath: NSIndexPath; animated?: boolean }): void;
|
|
79
|
+
*/
|
|
80
|
+
export declare class DynamicItemSizeSectionMatrix extends Base<UIView, UiTypes.ViewOptions> {
|
|
81
|
+
_defineView: () => UiTypes.ViewOptions;
|
|
82
|
+
private _props;
|
|
83
|
+
private _data;
|
|
84
|
+
private _events;
|
|
85
|
+
private _itemSizeWidth;
|
|
86
|
+
private _itemSizeHeight;
|
|
87
|
+
private _totalWidth;
|
|
88
|
+
private _columns;
|
|
89
|
+
private _fixedItemHeight;
|
|
90
|
+
private _minItemWidth;
|
|
91
|
+
private _maxColumns;
|
|
92
|
+
private _spacing;
|
|
93
|
+
matrix: Matrix;
|
|
94
|
+
constructor({ props, layout, events, }: {
|
|
95
|
+
props: DynamicItemSizeSectionMatrixProps;
|
|
96
|
+
layout: (make: MASConstraintMaker, view: UIView) => void;
|
|
97
|
+
events: DynamicItemSizeSectionMatrixEvents;
|
|
98
|
+
});
|
|
99
|
+
private _mapData;
|
|
100
|
+
private _mapTemplate;
|
|
101
|
+
get data(): DynamicItemSizeSectionMatrixSection[];
|
|
102
|
+
set data(data: DynamicItemSizeSectionMatrixSection[]);
|
|
103
|
+
reload(): void;
|
|
104
|
+
object(indexPath: NSIndexPath): Record<string, unknown>;
|
|
105
|
+
insert({ indexPath, value }: {
|
|
106
|
+
indexPath: NSIndexPath;
|
|
107
|
+
value: any;
|
|
108
|
+
}): void;
|
|
109
|
+
delete(indexPath: NSIndexPath): void;
|
|
110
|
+
cell(indexPath: NSIndexPath): AllUIView;
|
|
111
|
+
scrollTo({ indexPath, animated }: {
|
|
112
|
+
indexPath: NSIndexPath;
|
|
113
|
+
animated?: boolean;
|
|
114
|
+
}): void;
|
|
115
|
+
}
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DynamicItemSizeSectionMatrix = void 0;
|
|
4
|
+
const uitools_1 = require("../utils/uitools");
|
|
5
|
+
const base_1 = require("./base");
|
|
6
|
+
const single_views_1 = require("./single-views");
|
|
7
|
+
function _getColumnsAndItemSizeWidth(containerWidth, minItemWidth, maxColumns, spacing) {
|
|
8
|
+
if (minItemWidth > containerWidth - 2 * spacing) {
|
|
9
|
+
return {
|
|
10
|
+
columns: 1,
|
|
11
|
+
itemSizeWidth: containerWidth - 2 * spacing,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
const columns = Math.max(Math.min(Math.floor((containerWidth - spacing) / (minItemWidth + spacing)), maxColumns), 1);
|
|
15
|
+
const itemSizeWidth = Math.max(Math.floor((containerWidth - spacing * (columns + 1)) / columns), minItemWidth);
|
|
16
|
+
return {
|
|
17
|
+
columns,
|
|
18
|
+
itemSizeWidth,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function _getTextHeight(text, width) {
|
|
22
|
+
return (0, uitools_1.getTextHeight)(text, {
|
|
23
|
+
width,
|
|
24
|
+
font: $font(13),
|
|
25
|
+
inset: 0,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* # CView Dynamic ItemSize Section Matrix
|
|
30
|
+
*
|
|
31
|
+
* 此组件是为了在 Dynamic ItemSize Matrix 的基础上添加 SectionTitle
|
|
32
|
+
*
|
|
33
|
+
* - 使用此组件必须在每个section中添加title,如果title为空字符串,依然添加高度35的空格(包含spacing)
|
|
34
|
+
* - sectionTitle的字体为font(13),左右边距为16(不含spacing),即总宽度为 totalWidth - 2 * spacing - 32
|
|
35
|
+
* - 由于它必然和底下的item会有spacing,所以不建议spacing设的太大,那样会很违和
|
|
36
|
+
* - sectionTitle会使得section之间的间隔增加自身的高度
|
|
37
|
+
* - matrix事件会自动调整indexPath,包括didSelect、didLongPress、forEachItem
|
|
38
|
+
* - matrix的方法都在该组件中重新实现,自动调整indexPath
|
|
39
|
+
* - 不支持matrix原有的重新排序、自动大小功能,为防止sectionTitle暴露,也不支持menu
|
|
40
|
+
* - 不支持Dynamic ItemSize Matrix的dynamicHeightEnabled、heightToWidth
|
|
41
|
+
*
|
|
42
|
+
* ## 动态调整 itemSize
|
|
43
|
+
*
|
|
44
|
+
* 动态的改变自己的 itemSize,从而使得 spacing 被优先满足。
|
|
45
|
+
* 思路为在 matrix 上层套一个 superView,在旋转的时候 superView 会调用 matrix.relayout()
|
|
46
|
+
* 和 matrix.reload(),从而触发 itemSize 事件
|
|
47
|
+
*
|
|
48
|
+
* 其排布逻辑是这样的:
|
|
49
|
+
*
|
|
50
|
+
* 1. 由 minItemWidth,spacing,maxColumns 这三个参数决定 cloumns,
|
|
51
|
+
* 并结合 totalWidth 确定 itemSize.width
|
|
52
|
+
* 2. 确定 itemHeight 有两种方法:
|
|
53
|
+
* - fixedItemHeight 固定高度,优先级第二
|
|
54
|
+
* - event: itemHeight(width) => height 通过 width 动态计算,优先级最高
|
|
55
|
+
* 3. 如果 minItemWidth 比 totalWidth - 2 * spacing 还要小,那么 itemSize.width
|
|
56
|
+
* 会被设定为 totalWidth - 2 * spacing,以保证item不会超出边框
|
|
57
|
+
*
|
|
58
|
+
* ## props:
|
|
59
|
+
*
|
|
60
|
+
* 可以使用 matrix 的全部属性。
|
|
61
|
+
*
|
|
62
|
+
* 但data的类型调整为:
|
|
63
|
+
* { title: string; items: Record<string, unknown>[] }
|
|
64
|
+
*
|
|
65
|
+
* 特殊属性:
|
|
66
|
+
*
|
|
67
|
+
* - fixedItemHeight 固定 itemSize 高度
|
|
68
|
+
* - minItemWidth 最小的 itemSize 宽度
|
|
69
|
+
* - maxColumns 最大列数
|
|
70
|
+
* - spacing
|
|
71
|
+
*
|
|
72
|
+
* events:
|
|
73
|
+
*
|
|
74
|
+
* 可以使用 matrix 除 itemSize 以外的全部事件
|
|
75
|
+
*
|
|
76
|
+
* 其他特殊事件:
|
|
77
|
+
*
|
|
78
|
+
* - itemHeight: width => height 通过 itemWidth 动态计算 itemHeight
|
|
79
|
+
*
|
|
80
|
+
*
|
|
81
|
+
* 方法:
|
|
82
|
+
* - get data
|
|
83
|
+
* - set data
|
|
84
|
+
* - reload(): void;
|
|
85
|
+
* - object(indexPath: NSIndexPath): any;
|
|
86
|
+
* - insert(args: { indexPath: NSIndexPath;value: any; } ): void;
|
|
87
|
+
* - delete(indexPathOrIndex: NSIndexPath | number): void;
|
|
88
|
+
* - cell(indexPath: NSIndexPath): AllUIView;
|
|
89
|
+
* - scrollTo(args: { indexPath: NSIndexPath; animated?: boolean }): void;
|
|
90
|
+
*/
|
|
91
|
+
class DynamicItemSizeSectionMatrix extends base_1.Base {
|
|
92
|
+
constructor({ props, layout, events, }) {
|
|
93
|
+
super();
|
|
94
|
+
this._totalWidth = 0;
|
|
95
|
+
this._columns = 1;
|
|
96
|
+
this._props = props;
|
|
97
|
+
this._data = this._props.data ?? [];
|
|
98
|
+
this._events = events;
|
|
99
|
+
this._itemSizeWidth = 0;
|
|
100
|
+
this._itemSizeHeight = 0;
|
|
101
|
+
this._fixedItemHeight = this._props.fixedItemHeight ?? 96;
|
|
102
|
+
this._minItemWidth = this._props.minItemWidth ?? 96;
|
|
103
|
+
this._maxColumns = this._props.maxColumns ?? 5;
|
|
104
|
+
this._spacing = this._props.spacing ?? 6;
|
|
105
|
+
const { itemHeight, didSelect, didLongPress, forEachItem, ...otherEvents } = this._events;
|
|
106
|
+
this.matrix = new single_views_1.Matrix({
|
|
107
|
+
props: {
|
|
108
|
+
...props,
|
|
109
|
+
data: this._mapData(this._data),
|
|
110
|
+
template: this._mapTemplate(props.template),
|
|
111
|
+
},
|
|
112
|
+
layout: $layout.fill,
|
|
113
|
+
events: {
|
|
114
|
+
...otherEvents,
|
|
115
|
+
itemSize: (_sender, indexPath) => {
|
|
116
|
+
if (this._totalWidth === 0) {
|
|
117
|
+
return $size(0, 0);
|
|
118
|
+
}
|
|
119
|
+
if (indexPath.item === 0) {
|
|
120
|
+
const width = Math.max(this._totalWidth - 2 * this._spacing, 32);
|
|
121
|
+
const textHeight = _getTextHeight(this._data[indexPath.section].title, width - 32);
|
|
122
|
+
const height = textHeight + 35 - this._spacing * (indexPath.section === 0 ? 1 : 2);
|
|
123
|
+
return $size(width, height);
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
return $size(this._itemSizeWidth, this._itemSizeHeight);
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
didSelect: didSelect
|
|
130
|
+
? (sender, indexPath) => {
|
|
131
|
+
if (indexPath.item === 0) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
didSelect(sender, $indexPath(indexPath.section, indexPath.item - 1), this._data[indexPath.section].items[indexPath.item - 1]);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
: undefined,
|
|
139
|
+
didLongPress: didLongPress
|
|
140
|
+
? (sender, indexPath) => {
|
|
141
|
+
if (indexPath.item === 0) {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
didLongPress(sender, $indexPath(indexPath.section, indexPath.item - 1), this._data[indexPath.section].items[indexPath.item - 1]);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
: undefined,
|
|
149
|
+
forEachItem: forEachItem
|
|
150
|
+
? (sender, indexPath) => {
|
|
151
|
+
if (indexPath.item === 0) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
forEachItem(sender, $indexPath(indexPath.section, indexPath.item - 1));
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
: undefined,
|
|
159
|
+
},
|
|
160
|
+
});
|
|
161
|
+
this._defineView = () => {
|
|
162
|
+
return {
|
|
163
|
+
type: "view",
|
|
164
|
+
props: {
|
|
165
|
+
id: this.id,
|
|
166
|
+
bgcolor: $color("clear"),
|
|
167
|
+
},
|
|
168
|
+
layout,
|
|
169
|
+
views: [this.matrix.definition],
|
|
170
|
+
events: {
|
|
171
|
+
layoutSubviews: (sender) => {
|
|
172
|
+
sender.relayout();
|
|
173
|
+
if (sender.frame.width === this._totalWidth)
|
|
174
|
+
return;
|
|
175
|
+
this._totalWidth = sender.frame.width;
|
|
176
|
+
const { columns, itemSizeWidth } = _getColumnsAndItemSizeWidth(this._totalWidth, this._minItemWidth, this._maxColumns, this._spacing);
|
|
177
|
+
this._columns = columns;
|
|
178
|
+
this._itemSizeWidth = itemSizeWidth;
|
|
179
|
+
this._itemSizeHeight = this._events.itemHeight
|
|
180
|
+
? this._events.itemHeight(this._itemSizeWidth)
|
|
181
|
+
: this._fixedItemHeight;
|
|
182
|
+
this.matrix.view.reload();
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
};
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
_mapData(data) {
|
|
189
|
+
return data.map((n) => {
|
|
190
|
+
const mappedItems = n.items.map((n) => {
|
|
191
|
+
return {
|
|
192
|
+
__section_title__: { hidden: true },
|
|
193
|
+
__original_template__: { hidden: false },
|
|
194
|
+
...n,
|
|
195
|
+
};
|
|
196
|
+
});
|
|
197
|
+
return {
|
|
198
|
+
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
|
+
],
|
|
207
|
+
};
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
_mapTemplate(template) {
|
|
211
|
+
if (!template)
|
|
212
|
+
return;
|
|
213
|
+
const newTemplate = {
|
|
214
|
+
views: [
|
|
215
|
+
{
|
|
216
|
+
type: "view",
|
|
217
|
+
props: {
|
|
218
|
+
id: "__section_title__",
|
|
219
|
+
},
|
|
220
|
+
layout: $layout.fill,
|
|
221
|
+
views: [
|
|
222
|
+
{
|
|
223
|
+
// 在这里放一个透明且无效果的button,从而取消item自己的highlight效果
|
|
224
|
+
type: "button",
|
|
225
|
+
props: {
|
|
226
|
+
bgcolor: $color("clear"),
|
|
227
|
+
},
|
|
228
|
+
layout: $layout.fill,
|
|
229
|
+
},
|
|
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
|
+
],
|
|
245
|
+
},
|
|
246
|
+
{
|
|
247
|
+
type: "view",
|
|
248
|
+
props: {
|
|
249
|
+
...template.props,
|
|
250
|
+
id: "__original_template__",
|
|
251
|
+
},
|
|
252
|
+
layout: $layout.fill,
|
|
253
|
+
views: template.views,
|
|
254
|
+
},
|
|
255
|
+
],
|
|
256
|
+
};
|
|
257
|
+
return newTemplate;
|
|
258
|
+
}
|
|
259
|
+
get data() {
|
|
260
|
+
return this._data;
|
|
261
|
+
}
|
|
262
|
+
set data(data) {
|
|
263
|
+
this._data = data;
|
|
264
|
+
this.matrix.view.data = this._mapData(data);
|
|
265
|
+
this.reload();
|
|
266
|
+
}
|
|
267
|
+
reload() {
|
|
268
|
+
this.matrix.view.reload();
|
|
269
|
+
}
|
|
270
|
+
object(indexPath) {
|
|
271
|
+
return this._data?.[indexPath.section]?.items[indexPath.item];
|
|
272
|
+
}
|
|
273
|
+
insert({ indexPath, value }) {
|
|
274
|
+
this._data?.[indexPath.section]?.items.splice(indexPath.item, 0, value);
|
|
275
|
+
this.matrix.view.data = this._mapData(this._data);
|
|
276
|
+
this.reload();
|
|
277
|
+
}
|
|
278
|
+
delete(indexPath) {
|
|
279
|
+
this._data?.[indexPath.section]?.items.splice(indexPath.item, 1);
|
|
280
|
+
this.matrix.view.data = this._mapData(this._data);
|
|
281
|
+
this.reload();
|
|
282
|
+
}
|
|
283
|
+
cell(indexPath) {
|
|
284
|
+
return this.matrix.view.cell($indexPath(indexPath.section, indexPath.item + 1));
|
|
285
|
+
}
|
|
286
|
+
scrollTo({ indexPath, animated }) {
|
|
287
|
+
this.matrix.view.scrollTo({
|
|
288
|
+
indexPath: $indexPath(indexPath.section, indexPath.item + 1),
|
|
289
|
+
animated,
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
exports.DynamicItemSizeSectionMatrix = DynamicItemSizeSectionMatrix;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Base } from "./base";
|
|
2
|
+
import { PreferenceSection } from "./static-preference-listview";
|
|
3
|
+
interface CunstomProps extends UiTypes.ListProps {
|
|
4
|
+
stringLeftInset?: number;
|
|
5
|
+
infoAndLinkLeftInset?: number;
|
|
6
|
+
sliderWidth?: number;
|
|
7
|
+
tabWidth?: number;
|
|
8
|
+
symbolSizeForSymbolAction?: JBSize;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* # cview PreferenceListView_dynamic
|
|
12
|
+
*
|
|
13
|
+
* 便捷的设置列表实现. 样式以及功能均以 PreferenceListView_static 为准.
|
|
14
|
+
*
|
|
15
|
+
* 优势在于:
|
|
16
|
+
*
|
|
17
|
+
* - 可以实现 sections 重新写入.
|
|
18
|
+
*
|
|
19
|
+
* 劣势在于:
|
|
20
|
+
*
|
|
21
|
+
* - 由于每个 cell 不能单独布局, 因此标题和内容的长度无法动态调整, 在两者都比较短的情况下没有问题, 长了布局可能会重叠.
|
|
22
|
+
* - 不能真正实现 selectable 为 false, 分割线仍然会闪动
|
|
23
|
+
*
|
|
24
|
+
* 为了缓解上面的问题, 让修改布局无需调整源代码, 增加下列 props:
|
|
25
|
+
*
|
|
26
|
+
* - stringLeftInset?: number = 120 将同时作用于 string, number, integer, list, date
|
|
27
|
+
* 但是由于后四者内容可控, 可视为只作用于 string
|
|
28
|
+
* - infoAndLinkLeftInset?: number = 120 作用于 info, link
|
|
29
|
+
* - sliderWidth?: number = 200 作用于 slider
|
|
30
|
+
* - tabWidth?: number = 200 作用于 tab
|
|
31
|
+
* - symbolSizeForSymbolAction?: size = $size(24, 24) 作用于symbol-action
|
|
32
|
+
* 注意以上的修改是应用于 template, 而不是应用于单个 cell 的
|
|
33
|
+
*
|
|
34
|
+
* 独特方法:
|
|
35
|
+
*
|
|
36
|
+
* - cview.sections = sections 可以写入新的 sections
|
|
37
|
+
*/
|
|
38
|
+
export declare class DynamicPreferenceListView extends Base<UIListView, UiTypes.ListOptions> {
|
|
39
|
+
_defineView: () => UiTypes.ListOptions;
|
|
40
|
+
private _sections;
|
|
41
|
+
private _props;
|
|
42
|
+
constructor({ sections, props, layout, events, }: {
|
|
43
|
+
sections: PreferenceSection[];
|
|
44
|
+
props: CunstomProps;
|
|
45
|
+
layout?: (make: MASConstraintMaker, view: UIListView) => void;
|
|
46
|
+
events?: {
|
|
47
|
+
changed?: (values: any) => void;
|
|
48
|
+
};
|
|
49
|
+
});
|
|
50
|
+
_handleText(text: string, type: string): number | undefined;
|
|
51
|
+
_handleSliderValue(num?: number, decimal?: number, min?: number, max?: number): number;
|
|
52
|
+
_map(sections: PreferenceSection[]): {
|
|
53
|
+
title: string;
|
|
54
|
+
rows: any[];
|
|
55
|
+
}[];
|
|
56
|
+
get sections(): PreferenceSection[];
|
|
57
|
+
set sections(sections: PreferenceSection[]);
|
|
58
|
+
get values(): {
|
|
59
|
+
[key: string]: any;
|
|
60
|
+
};
|
|
61
|
+
set(key: string, value: any): void;
|
|
62
|
+
}
|
|
63
|
+
export {};
|
|
@@ -36,14 +36,25 @@ class DynamicPreferenceListView extends base_1.Base {
|
|
|
36
36
|
super();
|
|
37
37
|
this._sections = sections.map((n) => ({
|
|
38
38
|
title: n.title,
|
|
39
|
-
rows: n.rows.map((r) => (
|
|
39
|
+
rows: n.rows.map((r) => ({ ...r })),
|
|
40
40
|
}));
|
|
41
|
-
this._props =
|
|
41
|
+
this._props = {
|
|
42
|
+
stringLeftInset: 120,
|
|
43
|
+
infoAndLinkLeftInset: 120,
|
|
44
|
+
sliderWidth: 200,
|
|
45
|
+
tabWidth: 200,
|
|
46
|
+
symbolSizeForSymbolAction: $size(24, 24),
|
|
47
|
+
...props,
|
|
48
|
+
};
|
|
42
49
|
this._layout = layout;
|
|
43
50
|
this._defineView = () => {
|
|
44
51
|
return {
|
|
45
52
|
type: "list",
|
|
46
|
-
props:
|
|
53
|
+
props: {
|
|
54
|
+
style: 2,
|
|
55
|
+
...this._props,
|
|
56
|
+
id: this.id,
|
|
57
|
+
template: {
|
|
47
58
|
views: [
|
|
48
59
|
{
|
|
49
60
|
type: "view",
|
|
@@ -169,17 +180,15 @@ class DynamicPreferenceListView extends base_1.Base {
|
|
|
169
180
|
},
|
|
170
181
|
events: {
|
|
171
182
|
changed: (sender) => {
|
|
172
|
-
var _a;
|
|
173
183
|
const { section, row } = sender.info;
|
|
174
184
|
const options = this._sections[section].rows[row];
|
|
175
185
|
const label = sender.next;
|
|
176
|
-
label.text = this._handleSliderValue(sender.value * (
|
|
186
|
+
label.text = this._handleSliderValue(sender.value * (options.max ?? 1), options.decimal, options.min, options.max).toString();
|
|
177
187
|
},
|
|
178
188
|
touchesEnded: (sender) => {
|
|
179
|
-
var _a;
|
|
180
189
|
const { section, row } = sender.info;
|
|
181
190
|
const options = this._sections[section].rows[row];
|
|
182
|
-
this._sections[section].rows[row].value = this._handleSliderValue(sender.value * (
|
|
191
|
+
this._sections[section].rows[row].value = this._handleSliderValue(sender.value * (options.max ?? 1), options.decimal, options.min, options.max);
|
|
183
192
|
if (events.changed)
|
|
184
193
|
events.changed(this.values);
|
|
185
194
|
},
|
|
@@ -263,11 +272,12 @@ class DynamicPreferenceListView extends base_1.Base {
|
|
|
263
272
|
],
|
|
264
273
|
},
|
|
265
274
|
],
|
|
266
|
-
},
|
|
275
|
+
},
|
|
276
|
+
data: this._map(this._sections),
|
|
277
|
+
},
|
|
267
278
|
layout: this._layout,
|
|
268
279
|
events: {
|
|
269
280
|
didSelect: (sender, indexPath, data) => {
|
|
270
|
-
var _a, _b;
|
|
271
281
|
const row = this._sections[indexPath.section].rows[indexPath.row];
|
|
272
282
|
if (!static_preference_listview_1.selectableTypes.includes(row.type))
|
|
273
283
|
return;
|
|
@@ -288,7 +298,7 @@ class DynamicPreferenceListView extends base_1.Base {
|
|
|
288
298
|
}
|
|
289
299
|
case "number": {
|
|
290
300
|
$input.text({
|
|
291
|
-
text:
|
|
301
|
+
text: row.value?.toString(),
|
|
292
302
|
type: $kbType.decimal,
|
|
293
303
|
placeholder: row.placeholder,
|
|
294
304
|
handler: (text) => {
|
|
@@ -309,7 +319,7 @@ class DynamicPreferenceListView extends base_1.Base {
|
|
|
309
319
|
}
|
|
310
320
|
case "integer": {
|
|
311
321
|
$input.text({
|
|
312
|
-
text:
|
|
322
|
+
text: row.value?.toString(),
|
|
313
323
|
type: $kbType.number,
|
|
314
324
|
placeholder: row.placeholder,
|
|
315
325
|
handler: (text) => {
|
|
@@ -472,7 +482,6 @@ class DynamicPreferenceListView extends base_1.Base {
|
|
|
472
482
|
return sections.map((section, sectionIndex) => ({
|
|
473
483
|
title: section.title,
|
|
474
484
|
rows: section.rows.map((n, rowIndex) => {
|
|
475
|
-
var _a, _b, _c;
|
|
476
485
|
const data = generateDefaultRow(n);
|
|
477
486
|
switch (n.type) {
|
|
478
487
|
case "string": {
|
|
@@ -531,7 +540,7 @@ class DynamicPreferenceListView extends base_1.Base {
|
|
|
531
540
|
text: adjustedValue,
|
|
532
541
|
};
|
|
533
542
|
data.slider = {
|
|
534
|
-
value: adjustedValue / (
|
|
543
|
+
value: adjustedValue / (n.max ?? 1),
|
|
535
544
|
info: { section: sectionIndex, row: rowIndex, key: n.key },
|
|
536
545
|
//min: n.min, // 不可用,否则会出现slider滑动结束变为0点的bug
|
|
537
546
|
//max: n.max,
|
|
@@ -594,8 +603,8 @@ class DynamicPreferenceListView extends base_1.Base {
|
|
|
594
603
|
data.symbol = {
|
|
595
604
|
hidden: n.symbol ? false : true,
|
|
596
605
|
symbol: n.symbol,
|
|
597
|
-
tintColor:
|
|
598
|
-
contentMode:
|
|
606
|
+
tintColor: n.tintColor ?? $color("primaryText"),
|
|
607
|
+
contentMode: n.contentMode ?? 1,
|
|
599
608
|
};
|
|
600
609
|
break;
|
|
601
610
|
}
|
|
@@ -616,7 +625,7 @@ class DynamicPreferenceListView extends base_1.Base {
|
|
|
616
625
|
set sections(sections) {
|
|
617
626
|
this._sections = sections.map((n) => ({
|
|
618
627
|
title: n.title,
|
|
619
|
-
rows: n.rows.map((r) => (
|
|
628
|
+
rows: n.rows.map((r) => ({ ...r })),
|
|
620
629
|
}));
|
|
621
630
|
this.view.data = this._map(this._sections);
|
|
622
631
|
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Base } from "./base";
|
|
2
|
+
interface DynamicRowHeightListProps extends Omit<UiTypes.ListProps, "data" | "template"> {
|
|
3
|
+
}
|
|
4
|
+
interface DynamicRowHeightListEvents extends Omit<UiTypes.ListEvents, "rowHeight"> {
|
|
5
|
+
}
|
|
6
|
+
interface DynamicRowHeightListCView extends Base<any, any> {
|
|
7
|
+
heightToWidth: (width: number) => number;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* # cview Dynamic RowHeight List
|
|
11
|
+
*
|
|
12
|
+
* 可以自动更新 rowHeight 的 list
|
|
13
|
+
*
|
|
14
|
+
* 核心策略为 list 的所有行均为 cview,且每一个 cview 需要实现一个方法:
|
|
15
|
+
* heightToWidth(width: number) => number
|
|
16
|
+
* 通过这个方法汇报自己在某个宽度的时候所需要的高度,这必须任何时候均立即可用;
|
|
17
|
+
*
|
|
18
|
+
* 特别参数
|
|
19
|
+
* sections: {title: string, rows: cview[]}[]
|
|
20
|
+
* rows: cview[]
|
|
21
|
+
* 两者不能同时存在,否则rows不起作用
|
|
22
|
+
*
|
|
23
|
+
* 除了 props.data, props.template 和 events.rowHeight 不可用,其他均和 list 一致
|
|
24
|
+
*/
|
|
25
|
+
export declare class DynamicRowHeightList extends Base<UIListView, UiTypes.ListOptions> {
|
|
26
|
+
_defineView: () => UiTypes.ListOptions;
|
|
27
|
+
constructor({ sections, rows, props, layout, events, }: {
|
|
28
|
+
sections?: {
|
|
29
|
+
title: string;
|
|
30
|
+
rows: DynamicRowHeightListCView[];
|
|
31
|
+
}[];
|
|
32
|
+
rows?: DynamicRowHeightListCView[];
|
|
33
|
+
props: DynamicRowHeightListProps;
|
|
34
|
+
layout: (make: MASConstraintMaker, view: UIListView) => void;
|
|
35
|
+
events: DynamicRowHeightListEvents;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
export {};
|
|
@@ -37,9 +37,14 @@ class DynamicRowHeightList extends base_1.Base {
|
|
|
37
37
|
}
|
|
38
38
|
return {
|
|
39
39
|
type: "list",
|
|
40
|
-
props:
|
|
40
|
+
props: {
|
|
41
|
+
id: this.id,
|
|
42
|
+
data,
|
|
43
|
+
...props,
|
|
44
|
+
},
|
|
41
45
|
layout,
|
|
42
|
-
events:
|
|
46
|
+
events: {
|
|
47
|
+
rowHeight: (sender, indexPath) => {
|
|
43
48
|
if (sections) {
|
|
44
49
|
const cview = sections[indexPath.section].rows[indexPath.row];
|
|
45
50
|
return cview.heightToWidth(sender.frame.width);
|
|
@@ -50,7 +55,9 @@ class DynamicRowHeightList extends base_1.Base {
|
|
|
50
55
|
else {
|
|
51
56
|
throw new Error("sections or rows must be provided");
|
|
52
57
|
}
|
|
53
|
-
}
|
|
58
|
+
},
|
|
59
|
+
...events,
|
|
60
|
+
},
|
|
54
61
|
};
|
|
55
62
|
};
|
|
56
63
|
}
|