jsbox-cview 1.5.15 → 1.5.17
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/flowlayout.ts +17 -17
- package/components/refresh-button.ts +82 -0
- package/components/symbol-button.ts +1 -2
- package/dist/components/refresh-button.js +71 -0
- package/dist/components/symbol-button.js +1 -2
- package/dist/index.js +1 -0
- package/dist/test/refresh-button.js +35 -0
- package/index.ts +1 -0
- package/package.json +1 -1
- package/test/refresh-button.ts +26 -0
package/components/flowlayout.ts
CHANGED
|
@@ -29,10 +29,10 @@ import { Base } from "./base";
|
|
|
29
29
|
* - set items(items: FlowlayoutItem[]) 设置子视图
|
|
30
30
|
* - get items(): FlowlayoutItem[] 获取子视图
|
|
31
31
|
*/
|
|
32
|
-
export class Flowlayout extends Base<UIView, UiTypes.ViewOptions> {
|
|
32
|
+
export class Flowlayout<T extends FlowlayoutItem> extends Base<UIView, UiTypes.ViewOptions> {
|
|
33
33
|
private _width: number; // 缓存宽度,用于判断是否需要重新布局
|
|
34
34
|
private _props: {
|
|
35
|
-
items:
|
|
35
|
+
items: T[];
|
|
36
36
|
spacing: number;
|
|
37
37
|
itemHeight: number;
|
|
38
38
|
fixedRows?: number;
|
|
@@ -40,16 +40,16 @@ export class Flowlayout extends Base<UIView, UiTypes.ViewOptions> {
|
|
|
40
40
|
menu?: UiTypes.ContextMenuOptions;
|
|
41
41
|
bgcolor?: UIColor;
|
|
42
42
|
}
|
|
43
|
-
private _wrappers: WrapperView[];
|
|
43
|
+
private _wrappers: WrapperView<T>[];
|
|
44
44
|
private _events?: {
|
|
45
|
-
didSelect?: (sender: Flowlayout
|
|
46
|
-
didLongPress?: (sender: Flowlayout
|
|
45
|
+
didSelect?: (sender: Flowlayout<T>, index: number, item: T) => void;
|
|
46
|
+
didLongPress?: (sender: Flowlayout<T>, index: number, item: T) => void;
|
|
47
47
|
}
|
|
48
48
|
_defineView: () => UiTypes.ViewOptions;
|
|
49
49
|
|
|
50
50
|
constructor({ props, layout, events }: {
|
|
51
51
|
props: {
|
|
52
|
-
items:
|
|
52
|
+
items: T[];
|
|
53
53
|
spacing: number;
|
|
54
54
|
itemHeight: number;
|
|
55
55
|
fixedRows?: number;
|
|
@@ -59,8 +59,8 @@ export class Flowlayout extends Base<UIView, UiTypes.ViewOptions> {
|
|
|
59
59
|
};
|
|
60
60
|
layout: (make: MASConstraintMaker, view: UIView) => void;
|
|
61
61
|
events?: {
|
|
62
|
-
didSelect?: (sender: Flowlayout
|
|
63
|
-
didLongPress?: (sender: Flowlayout
|
|
62
|
+
didSelect?: (sender: Flowlayout<T>, index: number, item: T) => void;
|
|
63
|
+
didLongPress?: (sender: Flowlayout<T>, index: number, item: T) => void;
|
|
64
64
|
}
|
|
65
65
|
}) {
|
|
66
66
|
super();
|
|
@@ -95,15 +95,15 @@ export class Flowlayout extends Base<UIView, UiTypes.ViewOptions> {
|
|
|
95
95
|
});
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
-
cell(index: number):
|
|
98
|
+
cell(index: number): T {
|
|
99
99
|
return this._props.items[index];
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
get items():
|
|
102
|
+
get items(): T[] {
|
|
103
103
|
return this._props.items;
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
set items(items:
|
|
106
|
+
set items(items: T[]) {
|
|
107
107
|
this._props.items = items;
|
|
108
108
|
this._wrappers = items.map((item, index) => new WrapperView({
|
|
109
109
|
item,
|
|
@@ -176,9 +176,9 @@ interface FlowlayoutItem extends Base<any, any> {
|
|
|
176
176
|
itemWidth: () => number;
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
-
class WrapperView extends Base<UIView, UiTypes.ViewOptions> {
|
|
179
|
+
class WrapperView<T extends FlowlayoutItem> extends Base<UIView, UiTypes.ViewOptions> {
|
|
180
180
|
_defineView: () => UiTypes.ViewOptions;
|
|
181
|
-
item:
|
|
181
|
+
item: T;
|
|
182
182
|
constructor({
|
|
183
183
|
item,
|
|
184
184
|
menu,
|
|
@@ -187,11 +187,11 @@ class WrapperView extends Base<UIView, UiTypes.ViewOptions> {
|
|
|
187
187
|
flowlayout,
|
|
188
188
|
index
|
|
189
189
|
}: {
|
|
190
|
-
item:
|
|
190
|
+
item: T;
|
|
191
191
|
menu?: UiTypes.ContextMenuOptions;
|
|
192
|
-
didSelect?: (sender: Flowlayout
|
|
193
|
-
didLongPress?: (sender: Flowlayout
|
|
194
|
-
flowlayout: Flowlayout
|
|
192
|
+
didSelect?: (sender: Flowlayout<T>, index: number, item: T) => void;
|
|
193
|
+
didLongPress?: (sender: Flowlayout<T>, index: number, item: T) => void;
|
|
194
|
+
flowlayout: Flowlayout<T>;
|
|
195
195
|
index: number;
|
|
196
196
|
}) {
|
|
197
197
|
super();
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { Base } from "./base";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 创建一个刷新按钮,平时显示一个刷新的symbol,刷新时显示一个loading的symbol
|
|
5
|
+
* props:
|
|
6
|
+
* - tintColor
|
|
7
|
+
* - enabled
|
|
8
|
+
* - hidden
|
|
9
|
+
* events:
|
|
10
|
+
* - tapped
|
|
11
|
+
*/
|
|
12
|
+
export class RefreshButton extends Base<UIButtonView, UiTypes.ButtonOptions> {
|
|
13
|
+
_defineView: () => UiTypes.ButtonOptions;
|
|
14
|
+
_loading: boolean = false;
|
|
15
|
+
constructor({
|
|
16
|
+
props,
|
|
17
|
+
layout,
|
|
18
|
+
events = {}
|
|
19
|
+
}: {
|
|
20
|
+
props: {
|
|
21
|
+
tintColor: UIColor;
|
|
22
|
+
enabled: boolean;
|
|
23
|
+
hidden: boolean;
|
|
24
|
+
};
|
|
25
|
+
layout?: (make: MASConstraintMaker, view: UIButtonView) => void;
|
|
26
|
+
events?: UiTypes.BaseViewEvents<UIButtonView>;
|
|
27
|
+
}) {
|
|
28
|
+
super();
|
|
29
|
+
this._defineView = () => {
|
|
30
|
+
return {
|
|
31
|
+
type: "button",
|
|
32
|
+
props: {
|
|
33
|
+
id: this.id,
|
|
34
|
+
bgcolor: $color("clear"),
|
|
35
|
+
enabled: props.enabled ?? true,
|
|
36
|
+
hidden: props.hidden ?? false,
|
|
37
|
+
},
|
|
38
|
+
layout,
|
|
39
|
+
events,
|
|
40
|
+
views: [
|
|
41
|
+
{
|
|
42
|
+
type: "image",
|
|
43
|
+
props: {
|
|
44
|
+
id: this.id + "_image",
|
|
45
|
+
symbol: "arrow.clockwise",
|
|
46
|
+
tintColor: props.tintColor ?? $color("primaryText"),
|
|
47
|
+
contentMode: 1,
|
|
48
|
+
hidden: this._loading,
|
|
49
|
+
},
|
|
50
|
+
layout: (make, view) => {
|
|
51
|
+
make.edges.insets($insets(12.5, 12.5, 12.5, 12.5));
|
|
52
|
+
make.center.equalTo(view.super);
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
type: "spinner",
|
|
57
|
+
props: {
|
|
58
|
+
id: this.id + "_spinner",
|
|
59
|
+
loading: this._loading,
|
|
60
|
+
hidden: !this._loading,
|
|
61
|
+
},
|
|
62
|
+
layout: (make, view) => {
|
|
63
|
+
make.center.equalTo(view.super);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
]
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
get loading() {
|
|
72
|
+
return this._loading;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
set loading(value: boolean) {
|
|
76
|
+
this._loading = value;
|
|
77
|
+
$(this.id + "_image").hidden = value;
|
|
78
|
+
$(this.id + "_spinner").hidden = !value;
|
|
79
|
+
($(this.id + "_spinner") as UISpinnerView).loading = value;
|
|
80
|
+
this.view.enabled = !value;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -79,8 +79,7 @@ export class SymbolButton extends Base<UIButtonView, UiTypes.ButtonOptions> {
|
|
|
79
79
|
},
|
|
80
80
|
layout: (make, view: UIImageView) => {
|
|
81
81
|
make.edges.insets(this._props.insets);
|
|
82
|
-
make.
|
|
83
|
-
make.width.equalTo(view.height);
|
|
82
|
+
make.center.equalTo(view.super);
|
|
84
83
|
}
|
|
85
84
|
}
|
|
86
85
|
],
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RefreshButton = void 0;
|
|
4
|
+
const base_1 = require("./base");
|
|
5
|
+
/**
|
|
6
|
+
* 创建一个刷新按钮,平时显示一个刷新的symbol,刷新时显示一个loading的symbol
|
|
7
|
+
* props:
|
|
8
|
+
* - tintColor
|
|
9
|
+
* - enabled
|
|
10
|
+
* - hidden
|
|
11
|
+
* events:
|
|
12
|
+
* - tapped
|
|
13
|
+
*/
|
|
14
|
+
class RefreshButton extends base_1.Base {
|
|
15
|
+
constructor({ props, layout, events = {} }) {
|
|
16
|
+
super();
|
|
17
|
+
this._loading = false;
|
|
18
|
+
this._defineView = () => {
|
|
19
|
+
var _a, _b, _c;
|
|
20
|
+
return {
|
|
21
|
+
type: "button",
|
|
22
|
+
props: {
|
|
23
|
+
id: this.id,
|
|
24
|
+
bgcolor: $color("clear"),
|
|
25
|
+
enabled: (_a = props.enabled) !== null && _a !== void 0 ? _a : true,
|
|
26
|
+
hidden: (_b = props.hidden) !== null && _b !== void 0 ? _b : false,
|
|
27
|
+
},
|
|
28
|
+
layout,
|
|
29
|
+
events,
|
|
30
|
+
views: [
|
|
31
|
+
{
|
|
32
|
+
type: "image",
|
|
33
|
+
props: {
|
|
34
|
+
id: this.id + "_image",
|
|
35
|
+
symbol: "arrow.clockwise",
|
|
36
|
+
tintColor: (_c = props.tintColor) !== null && _c !== void 0 ? _c : $color("primaryText"),
|
|
37
|
+
contentMode: 1,
|
|
38
|
+
hidden: this._loading,
|
|
39
|
+
},
|
|
40
|
+
layout: (make, view) => {
|
|
41
|
+
make.edges.insets($insets(12.5, 12.5, 12.5, 12.5));
|
|
42
|
+
make.center.equalTo(view.super);
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
type: "spinner",
|
|
47
|
+
props: {
|
|
48
|
+
id: this.id + "_spinner",
|
|
49
|
+
loading: this._loading,
|
|
50
|
+
hidden: !this._loading,
|
|
51
|
+
},
|
|
52
|
+
layout: (make, view) => {
|
|
53
|
+
make.center.equalTo(view.super);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
]
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
get loading() {
|
|
61
|
+
return this._loading;
|
|
62
|
+
}
|
|
63
|
+
set loading(value) {
|
|
64
|
+
this._loading = value;
|
|
65
|
+
$(this.id + "_image").hidden = value;
|
|
66
|
+
$(this.id + "_spinner").hidden = !value;
|
|
67
|
+
$(this.id + "_spinner").loading = value;
|
|
68
|
+
this.view.enabled = !value;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.RefreshButton = RefreshButton;
|
package/dist/index.js
CHANGED
|
@@ -26,6 +26,7 @@ __exportStar(require("./components/image-pager"), exports);
|
|
|
26
26
|
__exportStar(require("./components/page-control"), exports);
|
|
27
27
|
__exportStar(require("./components/pageviewer-titlebar"), exports);
|
|
28
28
|
__exportStar(require("./components/pageviewer"), exports);
|
|
29
|
+
__exportStar(require("./components/refresh-button"), exports);
|
|
29
30
|
__exportStar(require("./components/rotating-view"), exports);
|
|
30
31
|
__exportStar(require("./components/searchbar"), exports);
|
|
31
32
|
__exportStar(require("./components/sheet"), exports);
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const refresh_button_1 = require("../components/refresh-button");
|
|
13
|
+
const refreshButton = new refresh_button_1.RefreshButton({
|
|
14
|
+
props: {
|
|
15
|
+
tintColor: $color("primaryText"),
|
|
16
|
+
enabled: true,
|
|
17
|
+
hidden: false
|
|
18
|
+
},
|
|
19
|
+
layout: (make, view) => {
|
|
20
|
+
make.width.equalTo(50);
|
|
21
|
+
make.height.equalTo(50);
|
|
22
|
+
make.top.inset(100);
|
|
23
|
+
make.centerX.equalTo(view.super);
|
|
24
|
+
},
|
|
25
|
+
events: {
|
|
26
|
+
tapped: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
27
|
+
refreshButton.loading = true;
|
|
28
|
+
yield $wait(2);
|
|
29
|
+
refreshButton.loading = false;
|
|
30
|
+
})
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
$ui.render({
|
|
34
|
+
views: [refreshButton.definition]
|
|
35
|
+
});
|
package/index.ts
CHANGED
|
@@ -10,6 +10,7 @@ export * from './components/image-pager';
|
|
|
10
10
|
export * from './components/page-control';
|
|
11
11
|
export * from './components/pageviewer-titlebar';
|
|
12
12
|
export * from './components/pageviewer';
|
|
13
|
+
export * from './components/refresh-button';
|
|
13
14
|
export * from './components/rotating-view';
|
|
14
15
|
export * from './components/searchbar';
|
|
15
16
|
export * from './components/sheet';
|
package/package.json
CHANGED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { RefreshButton } from "../components/refresh-button";
|
|
2
|
+
|
|
3
|
+
const refreshButton = new RefreshButton({
|
|
4
|
+
props: {
|
|
5
|
+
tintColor: $color("primaryText"),
|
|
6
|
+
enabled: true,
|
|
7
|
+
hidden: false
|
|
8
|
+
},
|
|
9
|
+
layout: (make, view) => {
|
|
10
|
+
make.width.equalTo(50);
|
|
11
|
+
make.height.equalTo(50);
|
|
12
|
+
make.top.inset(100);
|
|
13
|
+
make.centerX.equalTo(view.super);
|
|
14
|
+
},
|
|
15
|
+
events: {
|
|
16
|
+
tapped: async () => {
|
|
17
|
+
refreshButton.loading = true;
|
|
18
|
+
await $wait(2);
|
|
19
|
+
refreshButton.loading = false;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
$ui.render({
|
|
25
|
+
views: [refreshButton.definition]
|
|
26
|
+
});
|