jsbox-cview 1.2.5 → 1.2.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/components/dynamic-itemsize-matrix.ts +15 -2
- package/components/pageviewer.ts +1 -2
- package/controller/pageviewer-controller.ts +2 -2
- package/dist/components/dynamic-itemsize-matrix.js +12 -2
- package/dist/components/pageviewer.js +1 -2
- package/dist/controller/pageviewer-controller.js +2 -2
- package/dist/test/dynamic-itemsize-matrix.js +68 -0
- package/dist/test/pageviewer-controller.js +17 -0
- package/dist/test/pageviewer-titlebar.js +18 -0
- package/dist/test/pageviewer.js +23 -0
- package/package.json +1 -1
- package/test/dynamic-itemsize-matrix.ts +68 -0
- package/test/pageviewer-controller.ts +19 -0
- package/test/pageviewer-titlebar.ts +19 -0
- package/test/pageviewer.ts +22 -0
|
@@ -165,11 +165,15 @@ export class DynamicItemSizeMatrix extends Base<UIView, UiTypes.ViewOptions> {
|
|
|
165
165
|
Math.floor((totalWidth - spacing) / (minItemWidth + spacing)),
|
|
166
166
|
maxColumns
|
|
167
167
|
),
|
|
168
|
-
1
|
|
168
|
+
1 // 最少一列
|
|
169
169
|
);
|
|
170
|
+
const itemSizeWidth = Math.max(
|
|
171
|
+
Math.floor((totalWidth - spacing * (columns + 1)) / columns),
|
|
172
|
+
minItemWidth // 最小宽度
|
|
173
|
+
)
|
|
170
174
|
return {
|
|
171
175
|
columns,
|
|
172
|
-
itemSizeWidth
|
|
176
|
+
itemSizeWidth
|
|
173
177
|
};
|
|
174
178
|
}
|
|
175
179
|
|
|
@@ -187,4 +191,13 @@ export class DynamicItemSizeMatrix extends Base<UIView, UiTypes.ViewOptions> {
|
|
|
187
191
|
: this._props.fixedItemHeight;
|
|
188
192
|
return rows * itemSizeHeight + (rows + 1) * this._props.spacing;
|
|
189
193
|
}
|
|
194
|
+
|
|
195
|
+
get data() {
|
|
196
|
+
return this.matrix.view.data;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
set data(data) {
|
|
200
|
+
this._props.data = data;
|
|
201
|
+
this.matrix.view.data = data;
|
|
202
|
+
}
|
|
190
203
|
}
|
package/components/pageviewer.ts
CHANGED
|
@@ -50,7 +50,6 @@ export class PageViewer extends Base<UIView, UiTypes.ViewOptions> {
|
|
|
50
50
|
this._pageWidth = 0;
|
|
51
51
|
this._floatPage = this._props.page;
|
|
52
52
|
const contentViews = this._props.cviews.map(n => {
|
|
53
|
-
n._layout = $layout.fill;
|
|
54
53
|
return new ContentView({
|
|
55
54
|
views: [n.definition],
|
|
56
55
|
layout: (make, view) => {
|
|
@@ -93,7 +92,7 @@ export class PageViewer extends Base<UIView, UiTypes.ViewOptions> {
|
|
|
93
92
|
return {
|
|
94
93
|
type: "view",
|
|
95
94
|
props: { id: this.id },
|
|
96
|
-
layout
|
|
95
|
+
layout,
|
|
97
96
|
views: [this.scroll.definition],
|
|
98
97
|
events: {
|
|
99
98
|
layoutSubviews: sender => {
|
|
@@ -44,7 +44,7 @@ export class PageViewerController extends BaseController {
|
|
|
44
44
|
};
|
|
45
45
|
this.cviews.pageviewer = new PageViewer({
|
|
46
46
|
props: {
|
|
47
|
-
page: this._props.index,
|
|
47
|
+
page: this._props.index || 0,
|
|
48
48
|
cviews: this._props.items.map(n => n.controller.rootView)
|
|
49
49
|
},
|
|
50
50
|
layout: (make, view) => {
|
|
@@ -58,7 +58,7 @@ export class PageViewerController extends BaseController {
|
|
|
58
58
|
this.cviews.titlebar = new PageViewerTitleBar({
|
|
59
59
|
props: {
|
|
60
60
|
items: this._props.items.map(n => n.title),
|
|
61
|
-
index: this._props.index
|
|
61
|
+
index: this._props.index || 0
|
|
62
62
|
},
|
|
63
63
|
layout: $layout.fill,
|
|
64
64
|
events: {
|
|
@@ -111,10 +111,13 @@ class DynamicItemSizeMatrix extends base_1.Base {
|
|
|
111
111
|
const totalWidth = maxTotalWidth
|
|
112
112
|
? Math.min(maxTotalWidth, containerWidth)
|
|
113
113
|
: containerWidth;
|
|
114
|
-
const columns = Math.max(Math.min(Math.floor((totalWidth - spacing) / (minItemWidth + spacing)), maxColumns), 1
|
|
114
|
+
const columns = Math.max(Math.min(Math.floor((totalWidth - spacing) / (minItemWidth + spacing)), maxColumns), 1 // 最少一列
|
|
115
|
+
);
|
|
116
|
+
const itemSizeWidth = Math.max(Math.floor((totalWidth - spacing * (columns + 1)) / columns), minItemWidth // 最小宽度
|
|
117
|
+
);
|
|
115
118
|
return {
|
|
116
119
|
columns,
|
|
117
|
-
itemSizeWidth
|
|
120
|
+
itemSizeWidth
|
|
118
121
|
};
|
|
119
122
|
}
|
|
120
123
|
heightToWidth(width) {
|
|
@@ -125,5 +128,12 @@ class DynamicItemSizeMatrix extends base_1.Base {
|
|
|
125
128
|
: this._props.fixedItemHeight;
|
|
126
129
|
return rows * itemSizeHeight + (rows + 1) * this._props.spacing;
|
|
127
130
|
}
|
|
131
|
+
get data() {
|
|
132
|
+
return this.matrix.view.data;
|
|
133
|
+
}
|
|
134
|
+
set data(data) {
|
|
135
|
+
this._props.data = data;
|
|
136
|
+
this.matrix.view.data = data;
|
|
137
|
+
}
|
|
128
138
|
}
|
|
129
139
|
exports.DynamicItemSizeMatrix = DynamicItemSizeMatrix;
|
|
@@ -25,7 +25,6 @@ class PageViewer extends base_1.Base {
|
|
|
25
25
|
this._pageWidth = 0;
|
|
26
26
|
this._floatPage = this._props.page;
|
|
27
27
|
const contentViews = this._props.cviews.map(n => {
|
|
28
|
-
n._layout = $layout.fill;
|
|
29
28
|
return new single_views_1.ContentView({
|
|
30
29
|
views: [n.definition],
|
|
31
30
|
layout: (make, view) => {
|
|
@@ -68,7 +67,7 @@ class PageViewer extends base_1.Base {
|
|
|
68
67
|
return {
|
|
69
68
|
type: "view",
|
|
70
69
|
props: { id: this.id },
|
|
71
|
-
layout
|
|
70
|
+
layout,
|
|
72
71
|
views: [this.scroll.definition],
|
|
73
72
|
events: {
|
|
74
73
|
layoutSubviews: sender => {
|
|
@@ -25,7 +25,7 @@ class PageViewerController extends base_controller_1.BaseController {
|
|
|
25
25
|
this.cviews = {};
|
|
26
26
|
this.cviews.pageviewer = new pageviewer_1.PageViewer({
|
|
27
27
|
props: {
|
|
28
|
-
page: this._props.index,
|
|
28
|
+
page: this._props.index || 0,
|
|
29
29
|
cviews: this._props.items.map(n => n.controller.rootView)
|
|
30
30
|
},
|
|
31
31
|
layout: (make, view) => {
|
|
@@ -39,7 +39,7 @@ class PageViewerController extends base_controller_1.BaseController {
|
|
|
39
39
|
this.cviews.titlebar = new pageviewer_titlebar_1.PageViewerTitleBar({
|
|
40
40
|
props: {
|
|
41
41
|
items: this._props.items.map(n => n.title),
|
|
42
|
-
index: this._props.index
|
|
42
|
+
index: this._props.index || 0
|
|
43
43
|
},
|
|
44
44
|
layout: $layout.fill,
|
|
45
45
|
events: {
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const dynamic_itemsize_matrix_1 = require("../components/dynamic-itemsize-matrix");
|
|
4
|
+
const matrix = new dynamic_itemsize_matrix_1.DynamicItemSizeMatrix({
|
|
5
|
+
props: {
|
|
6
|
+
spacing: 5,
|
|
7
|
+
minItemWidth: $device.isIpad ? 140 : 118,
|
|
8
|
+
maxColumns: 10,
|
|
9
|
+
template: {
|
|
10
|
+
views: [
|
|
11
|
+
{
|
|
12
|
+
type: "label",
|
|
13
|
+
props: {
|
|
14
|
+
id: "label",
|
|
15
|
+
align: $align.center,
|
|
16
|
+
font: $font(13)
|
|
17
|
+
},
|
|
18
|
+
layout: (make, view) => {
|
|
19
|
+
make.left.right.bottom.inset(0);
|
|
20
|
+
make.height.equalTo(20);
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
type: "image",
|
|
25
|
+
props: {
|
|
26
|
+
symbol: "sun.dust",
|
|
27
|
+
bgcolor: $color("backgroundColor", "secondarySurface"),
|
|
28
|
+
contentMode: $contentMode.scaleAspectFit
|
|
29
|
+
},
|
|
30
|
+
layout: (make, view) => {
|
|
31
|
+
make.top.left.right.equalTo(0);
|
|
32
|
+
make.bottom.equalTo(view.prev.top);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
]
|
|
36
|
+
},
|
|
37
|
+
data: [...Array(100)].map((n, i) => {
|
|
38
|
+
return {
|
|
39
|
+
label: { text: i + 1 }
|
|
40
|
+
};
|
|
41
|
+
}),
|
|
42
|
+
footer: {
|
|
43
|
+
type: "view",
|
|
44
|
+
props: {
|
|
45
|
+
height: 20
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
layout: (make, view) => {
|
|
50
|
+
make.left.right.equalTo(view.super.safeArea);
|
|
51
|
+
make.top.bottom.equalTo(view.super);
|
|
52
|
+
},
|
|
53
|
+
events: {
|
|
54
|
+
itemHeight: width => width * 1.414 + 20,
|
|
55
|
+
didSelect: (sender, indexPath, data) => { }
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
$ui.render({
|
|
59
|
+
props: {
|
|
60
|
+
navButtons: [
|
|
61
|
+
{
|
|
62
|
+
symbol: "plus",
|
|
63
|
+
handler: () => matrix.data = [{ label: { text: "New" } }]
|
|
64
|
+
}
|
|
65
|
+
]
|
|
66
|
+
},
|
|
67
|
+
views: [matrix.definition]
|
|
68
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const pageviewer_controller_1 = require("../controller/pageviewer-controller");
|
|
4
|
+
const base_controller_1 = require("../controller/base-controller");
|
|
5
|
+
const items = [{
|
|
6
|
+
controller: new base_controller_1.BaseController({ props: { bgcolor: $color("red") } }),
|
|
7
|
+
title: "Page 1"
|
|
8
|
+
}, {
|
|
9
|
+
controller: new base_controller_1.BaseController({ props: { bgcolor: $color("yellow") } }),
|
|
10
|
+
title: "Page 2"
|
|
11
|
+
}];
|
|
12
|
+
const pageViewerController = new pageviewer_controller_1.PageViewerController({
|
|
13
|
+
props: {
|
|
14
|
+
items
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
pageViewerController.uirender({});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const pageviewer_titlebar_1 = require("../components/pageviewer-titlebar");
|
|
4
|
+
const pageViewerTitleBar = new pageviewer_titlebar_1.PageViewerTitleBar({
|
|
5
|
+
props: {
|
|
6
|
+
items: ["Page 1", "Page 2", "Page 3"],
|
|
7
|
+
index: 0
|
|
8
|
+
},
|
|
9
|
+
layout: (make, view) => {
|
|
10
|
+
make.left.right.inset(0);
|
|
11
|
+
make.top.equalTo(view.super.safeAreaTop);
|
|
12
|
+
make.height.equalTo(44);
|
|
13
|
+
},
|
|
14
|
+
events: {}
|
|
15
|
+
});
|
|
16
|
+
$ui.render({
|
|
17
|
+
views: [pageViewerTitleBar.definition]
|
|
18
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const pageviewer_1 = require("../components/pageviewer");
|
|
4
|
+
const single_views_1 = require("../components/single-views");
|
|
5
|
+
const pageViewer = new pageviewer_1.PageViewer({
|
|
6
|
+
props: {
|
|
7
|
+
page: 0,
|
|
8
|
+
cviews: [
|
|
9
|
+
new single_views_1.ContentView({ props: { bgcolor: $color("red") }, layout: $layout.fill }),
|
|
10
|
+
new single_views_1.ContentView({ props: { bgcolor: $color("green") }, layout: $layout.fill }),
|
|
11
|
+
new single_views_1.ContentView({ props: { bgcolor: $color("blue") }, layout: $layout.fill })
|
|
12
|
+
]
|
|
13
|
+
},
|
|
14
|
+
layout: $layout.fill,
|
|
15
|
+
events: {
|
|
16
|
+
floatPageChanged: (cview, floatPage) => {
|
|
17
|
+
console.log(floatPage);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
$ui.render({
|
|
22
|
+
views: [pageViewer.definition]
|
|
23
|
+
});
|
package/package.json
CHANGED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { DynamicItemSizeMatrix } from "../components/dynamic-itemsize-matrix";
|
|
2
|
+
|
|
3
|
+
const matrix = new DynamicItemSizeMatrix({
|
|
4
|
+
props: {
|
|
5
|
+
spacing: 5,
|
|
6
|
+
minItemWidth: $device.isIpad ? 140 : 118,
|
|
7
|
+
maxColumns: 10,
|
|
8
|
+
template: {
|
|
9
|
+
views: [
|
|
10
|
+
{
|
|
11
|
+
type: "label",
|
|
12
|
+
props: {
|
|
13
|
+
id: "label",
|
|
14
|
+
align: $align.center,
|
|
15
|
+
font: $font(13)
|
|
16
|
+
},
|
|
17
|
+
layout: (make, view) => {
|
|
18
|
+
make.left.right.bottom.inset(0);
|
|
19
|
+
make.height.equalTo(20);
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
type: "image",
|
|
24
|
+
props: {
|
|
25
|
+
symbol: "sun.dust",
|
|
26
|
+
bgcolor: $color("backgroundColor", "secondarySurface"),
|
|
27
|
+
contentMode: $contentMode.scaleAspectFit
|
|
28
|
+
},
|
|
29
|
+
layout: (make, view) => {
|
|
30
|
+
make.top.left.right.equalTo(0);
|
|
31
|
+
make.bottom.equalTo(view.prev.top);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
]
|
|
35
|
+
},
|
|
36
|
+
data: [...Array(100)].map((n, i) => {
|
|
37
|
+
return {
|
|
38
|
+
label: { text: i + 1 }
|
|
39
|
+
};
|
|
40
|
+
}),
|
|
41
|
+
footer: {
|
|
42
|
+
type: "view",
|
|
43
|
+
props: {
|
|
44
|
+
height: 20
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
layout: (make, view) => {
|
|
49
|
+
make.left.right.equalTo(view.super.safeArea);
|
|
50
|
+
make.top.bottom.equalTo(view.super);
|
|
51
|
+
},
|
|
52
|
+
events: {
|
|
53
|
+
itemHeight: width => width * 1.414 + 20,
|
|
54
|
+
didSelect: (sender, indexPath, data) => { }
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
$ui.render({
|
|
59
|
+
props: {
|
|
60
|
+
navButtons: [
|
|
61
|
+
{
|
|
62
|
+
symbol: "plus",
|
|
63
|
+
handler: () => matrix.data = [{ label: { text: "New" } }]
|
|
64
|
+
}
|
|
65
|
+
]
|
|
66
|
+
},
|
|
67
|
+
views: [matrix.definition]
|
|
68
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { PageViewerController } from "../controller/pageviewer-controller";
|
|
2
|
+
import { BaseController } from "../controller/base-controller";
|
|
3
|
+
import { PageViewer } from "../components/pageviewer";
|
|
4
|
+
|
|
5
|
+
const items = [{
|
|
6
|
+
controller: new BaseController({props: {bgcolor: $color("red")}}),
|
|
7
|
+
title: "Page 1"
|
|
8
|
+
}, {
|
|
9
|
+
controller: new BaseController({props: {bgcolor: $color("yellow")}}),
|
|
10
|
+
title: "Page 2"
|
|
11
|
+
}]
|
|
12
|
+
|
|
13
|
+
const pageViewerController = new PageViewerController({
|
|
14
|
+
props: {
|
|
15
|
+
items
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
pageViewerController.uirender({});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { PageViewerTitleBar } from "../components/pageviewer-titlebar";
|
|
2
|
+
|
|
3
|
+
const pageViewerTitleBar = new PageViewerTitleBar({
|
|
4
|
+
props: {
|
|
5
|
+
items: ["Page 1", "Page 2", "Page 3"],
|
|
6
|
+
index: 0
|
|
7
|
+
},
|
|
8
|
+
layout: (make, view) => {
|
|
9
|
+
make.left.right.inset(0);
|
|
10
|
+
make.top.equalTo(view.super.safeAreaTop);
|
|
11
|
+
make.height.equalTo(44);
|
|
12
|
+
},
|
|
13
|
+
events: {
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
$ui.render({
|
|
18
|
+
views: [pageViewerTitleBar.definition]
|
|
19
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { PageViewer } from "../components/pageviewer";
|
|
2
|
+
import { ContentView } from "../components/single-views";
|
|
3
|
+
const pageViewer = new PageViewer({
|
|
4
|
+
props: {
|
|
5
|
+
page: 0,
|
|
6
|
+
cviews: [
|
|
7
|
+
new ContentView({ props: { bgcolor: $color("red") }, layout: $layout.fill }),
|
|
8
|
+
new ContentView({ props: { bgcolor: $color("green") }, layout: $layout.fill }),
|
|
9
|
+
new ContentView({ props: { bgcolor: $color("blue") }, layout: $layout.fill })
|
|
10
|
+
]
|
|
11
|
+
},
|
|
12
|
+
layout: $layout.fill,
|
|
13
|
+
events: {
|
|
14
|
+
floatPageChanged: (cview, floatPage) => {
|
|
15
|
+
console.log(floatPage);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
$ui.render({
|
|
21
|
+
views: [pageViewer.definition]
|
|
22
|
+
});
|