jsbox-cview 1.5.8 → 1.5.10
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.
|
@@ -11,6 +11,7 @@ export class ImagePager extends Base<UIView, UiTypes.ViewOptions> {
|
|
|
11
11
|
_props: {
|
|
12
12
|
srcs: string[];
|
|
13
13
|
page: number;
|
|
14
|
+
doubleTapToZoom: boolean;
|
|
14
15
|
};
|
|
15
16
|
_matrix: Matrix;
|
|
16
17
|
_pageLoadRecorder: { [key: number]: boolean };
|
|
@@ -21,6 +22,7 @@ export class ImagePager extends Base<UIView, UiTypes.ViewOptions> {
|
|
|
21
22
|
* @param props
|
|
22
23
|
* - srcs: string[] - 图片地址列表
|
|
23
24
|
* - page: number - 当前页码
|
|
25
|
+
* - doubleTapToZoom: boolean - 是否双击放大,默认为true
|
|
24
26
|
* @param layout
|
|
25
27
|
* @param events
|
|
26
28
|
* - changed: (page: number) => void - 页码变化时触发
|
|
@@ -30,6 +32,7 @@ export class ImagePager extends Base<UIView, UiTypes.ViewOptions> {
|
|
|
30
32
|
props: {
|
|
31
33
|
srcs?: string[];
|
|
32
34
|
page?: number;
|
|
35
|
+
doubleTapToZoom?: boolean;
|
|
33
36
|
};
|
|
34
37
|
layout: (make: MASConstraintMaker, view: UIView) => void;
|
|
35
38
|
events: {
|
|
@@ -42,6 +45,7 @@ export class ImagePager extends Base<UIView, UiTypes.ViewOptions> {
|
|
|
42
45
|
this._props = {
|
|
43
46
|
srcs: [],
|
|
44
47
|
page: 0,
|
|
48
|
+
doubleTapToZoom: true,
|
|
45
49
|
...props
|
|
46
50
|
};
|
|
47
51
|
this._pageLoadRecorder = {};
|
|
@@ -60,7 +64,7 @@ export class ImagePager extends Base<UIView, UiTypes.ViewOptions> {
|
|
|
60
64
|
id: "scroll",
|
|
61
65
|
zoomEnabled: true,
|
|
62
66
|
maxZoomScale: 3,
|
|
63
|
-
doubleTapToZoom:
|
|
67
|
+
doubleTapToZoom: this._props.doubleTapToZoom
|
|
64
68
|
},
|
|
65
69
|
layout: $layout.fill,
|
|
66
70
|
views: [
|
|
@@ -84,6 +88,7 @@ export class ImagePager extends Base<UIView, UiTypes.ViewOptions> {
|
|
|
84
88
|
ready: sender => {
|
|
85
89
|
// 如果没有此处的relayout,则会出现莫名其妙的bug
|
|
86
90
|
sender.relayout();
|
|
91
|
+
if (!this._matrix.view) return;
|
|
87
92
|
this.page = this.page;
|
|
88
93
|
this.loadsrc(this.page);
|
|
89
94
|
},
|
|
@@ -112,8 +117,7 @@ export class ImagePager extends Base<UIView, UiTypes.ViewOptions> {
|
|
|
112
117
|
return {
|
|
113
118
|
type: "view",
|
|
114
119
|
props: {
|
|
115
|
-
id: this.id
|
|
116
|
-
userInteractionEnabled: true
|
|
120
|
+
id: this.id
|
|
117
121
|
},
|
|
118
122
|
layout,
|
|
119
123
|
views: [this._matrix.definition],
|
|
@@ -121,21 +125,11 @@ export class ImagePager extends Base<UIView, UiTypes.ViewOptions> {
|
|
|
121
125
|
layoutSubviews: sender => {
|
|
122
126
|
this._pageLoadRecorder = {};
|
|
123
127
|
sender.relayout();
|
|
128
|
+
if (!this._matrix.view) return;
|
|
124
129
|
this._matrix.view.reload();
|
|
125
130
|
this.page = this.page;
|
|
126
131
|
$delay(0.1, () => this.loadsrc(this.page, true));
|
|
127
132
|
$delay(0.3, () => this.loadsrc(this.page, true));
|
|
128
|
-
},
|
|
129
|
-
tapped: sender => {
|
|
130
|
-
const cell = this._matrix.view.cell($indexPath(0, this.page));
|
|
131
|
-
if (!cell) return;
|
|
132
|
-
const scroll = cell.get("scroll") as UIScrollView;
|
|
133
|
-
const zoomScale = scroll.zoomScale;
|
|
134
|
-
$delay(0.3, () => {
|
|
135
|
-
const zoomScale1 = scroll.zoomScale;
|
|
136
|
-
if (zoomScale === zoomScale1 && events.tapped)
|
|
137
|
-
events.tapped(this);
|
|
138
|
-
});
|
|
139
133
|
}
|
|
140
134
|
}
|
|
141
135
|
};
|
|
@@ -14,6 +14,11 @@ interface TabBarControllerProps extends BaseControllerProps {
|
|
|
14
14
|
index?: number;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
interface TabBarControllerEvents extends BaseControllerEvents {
|
|
18
|
+
changed?: (controller: TabBarController, index: number) => void;
|
|
19
|
+
doubleTapped?: (controller: TabBarController, index: number) => void;
|
|
20
|
+
}
|
|
21
|
+
|
|
17
22
|
/**
|
|
18
23
|
* # CView TabBar Controller
|
|
19
24
|
*
|
|
@@ -31,6 +36,7 @@ interface TabBarControllerProps extends BaseControllerProps {
|
|
|
31
36
|
*/
|
|
32
37
|
export class TabBarController extends BaseController {
|
|
33
38
|
_props: TabBarControllerProps;
|
|
39
|
+
_events: TabBarControllerEvents;
|
|
34
40
|
cviews: {
|
|
35
41
|
tabbar: TabBar;
|
|
36
42
|
pageContentView: ContentView;
|
|
@@ -39,18 +45,27 @@ export class TabBarController extends BaseController {
|
|
|
39
45
|
constructor({ props, layout, events = {} }: {
|
|
40
46
|
props: TabBarControllerProps;
|
|
41
47
|
layout?: (make: MASConstraintMaker, view: UIView) => void;
|
|
42
|
-
events?:
|
|
48
|
+
events?: TabBarControllerEvents;
|
|
43
49
|
}) {
|
|
44
50
|
super({
|
|
45
51
|
props: {
|
|
46
52
|
id: props.id,
|
|
47
53
|
bgcolor: props.bgcolor
|
|
48
|
-
},
|
|
54
|
+
},
|
|
55
|
+
layout,
|
|
56
|
+
events: {
|
|
57
|
+
...events,
|
|
58
|
+
didAppear: () => {
|
|
59
|
+
this._props.items[this.index].controller.appear();
|
|
60
|
+
this._events.didAppear?.(this);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
49
63
|
});
|
|
50
64
|
this._props = {
|
|
51
65
|
items: props.items,
|
|
52
66
|
index: props.index || 0
|
|
53
67
|
};
|
|
68
|
+
this._events = events;
|
|
54
69
|
this.cviews = {} as {
|
|
55
70
|
tabbar: TabBar;
|
|
56
71
|
pageContentView: ContentView;
|
|
@@ -61,7 +76,15 @@ export class TabBarController extends BaseController {
|
|
|
61
76
|
index: this._props.index
|
|
62
77
|
},
|
|
63
78
|
events: {
|
|
64
|
-
changed: (cview, index) =>
|
|
79
|
+
changed: (cview, index) => {
|
|
80
|
+
this.index = index;
|
|
81
|
+
this._props.items.find(item=>item.controller.status === 2)?.controller.disappear();
|
|
82
|
+
this._props.items[index].controller.appear();
|
|
83
|
+
this._events.changed?.(this, index);
|
|
84
|
+
},
|
|
85
|
+
doubleTapped: (cview, index) => {
|
|
86
|
+
this._events.doubleTapped?.(this, index);
|
|
87
|
+
}
|
|
65
88
|
}
|
|
66
89
|
});
|
|
67
90
|
|
|
@@ -15,6 +15,7 @@ class ImagePager extends base_1.Base {
|
|
|
15
15
|
* @param props
|
|
16
16
|
* - srcs: string[] - 图片地址列表
|
|
17
17
|
* - page: number - 当前页码
|
|
18
|
+
* - doubleTapToZoom: boolean - 是否双击放大,默认为true
|
|
18
19
|
* @param layout
|
|
19
20
|
* @param events
|
|
20
21
|
* - changed: (page: number) => void - 页码变化时触发
|
|
@@ -22,7 +23,7 @@ class ImagePager extends base_1.Base {
|
|
|
22
23
|
*/
|
|
23
24
|
constructor({ props, layout, events = {} }) {
|
|
24
25
|
super();
|
|
25
|
-
this._props = Object.assign({ srcs: [], page: 0 }, props);
|
|
26
|
+
this._props = Object.assign({ srcs: [], page: 0, doubleTapToZoom: true }, props);
|
|
26
27
|
this._pageLoadRecorder = {};
|
|
27
28
|
this._matrix = new single_views_1.Matrix({
|
|
28
29
|
props: {
|
|
@@ -39,7 +40,7 @@ class ImagePager extends base_1.Base {
|
|
|
39
40
|
id: "scroll",
|
|
40
41
|
zoomEnabled: true,
|
|
41
42
|
maxZoomScale: 3,
|
|
42
|
-
doubleTapToZoom:
|
|
43
|
+
doubleTapToZoom: this._props.doubleTapToZoom
|
|
43
44
|
},
|
|
44
45
|
layout: $layout.fill,
|
|
45
46
|
views: [
|
|
@@ -63,6 +64,8 @@ class ImagePager extends base_1.Base {
|
|
|
63
64
|
ready: sender => {
|
|
64
65
|
// 如果没有此处的relayout,则会出现莫名其妙的bug
|
|
65
66
|
sender.relayout();
|
|
67
|
+
if (!this._matrix.view)
|
|
68
|
+
return;
|
|
66
69
|
this.page = this.page;
|
|
67
70
|
this.loadsrc(this.page);
|
|
68
71
|
},
|
|
@@ -91,8 +94,7 @@ class ImagePager extends base_1.Base {
|
|
|
91
94
|
return {
|
|
92
95
|
type: "view",
|
|
93
96
|
props: {
|
|
94
|
-
id: this.id
|
|
95
|
-
userInteractionEnabled: true
|
|
97
|
+
id: this.id
|
|
96
98
|
},
|
|
97
99
|
layout,
|
|
98
100
|
views: [this._matrix.definition],
|
|
@@ -100,22 +102,12 @@ class ImagePager extends base_1.Base {
|
|
|
100
102
|
layoutSubviews: sender => {
|
|
101
103
|
this._pageLoadRecorder = {};
|
|
102
104
|
sender.relayout();
|
|
105
|
+
if (!this._matrix.view)
|
|
106
|
+
return;
|
|
103
107
|
this._matrix.view.reload();
|
|
104
108
|
this.page = this.page;
|
|
105
109
|
$delay(0.1, () => this.loadsrc(this.page, true));
|
|
106
110
|
$delay(0.3, () => this.loadsrc(this.page, true));
|
|
107
|
-
},
|
|
108
|
-
tapped: sender => {
|
|
109
|
-
const cell = this._matrix.view.cell($indexPath(0, this.page));
|
|
110
|
-
if (!cell)
|
|
111
|
-
return;
|
|
112
|
-
const scroll = cell.get("scroll");
|
|
113
|
-
const zoomScale = scroll.zoomScale;
|
|
114
|
-
$delay(0.3, () => {
|
|
115
|
-
const zoomScale1 = scroll.zoomScale;
|
|
116
|
-
if (zoomScale === zoomScale1 && events.tapped)
|
|
117
|
-
events.tapped(this);
|
|
118
|
-
});
|
|
119
111
|
}
|
|
120
112
|
}
|
|
121
113
|
};
|
|
@@ -25,12 +25,19 @@ class TabBarController extends base_controller_1.BaseController {
|
|
|
25
25
|
props: {
|
|
26
26
|
id: props.id,
|
|
27
27
|
bgcolor: props.bgcolor
|
|
28
|
-
},
|
|
28
|
+
},
|
|
29
|
+
layout,
|
|
30
|
+
events: Object.assign(Object.assign({}, events), { didAppear: () => {
|
|
31
|
+
var _a, _b;
|
|
32
|
+
this._props.items[this.index].controller.appear();
|
|
33
|
+
(_b = (_a = this._events).didAppear) === null || _b === void 0 ? void 0 : _b.call(_a, this);
|
|
34
|
+
} })
|
|
29
35
|
});
|
|
30
36
|
this._props = {
|
|
31
37
|
items: props.items,
|
|
32
38
|
index: props.index || 0
|
|
33
39
|
};
|
|
40
|
+
this._events = events;
|
|
34
41
|
this.cviews = {};
|
|
35
42
|
this.cviews.tabbar = new tabbar_1.TabBar({
|
|
36
43
|
props: {
|
|
@@ -38,7 +45,17 @@ class TabBarController extends base_controller_1.BaseController {
|
|
|
38
45
|
index: this._props.index
|
|
39
46
|
},
|
|
40
47
|
events: {
|
|
41
|
-
changed: (cview, index) =>
|
|
48
|
+
changed: (cview, index) => {
|
|
49
|
+
var _a, _b, _c;
|
|
50
|
+
this.index = index;
|
|
51
|
+
(_a = this._props.items.find(item => item.controller.status === 2)) === null || _a === void 0 ? void 0 : _a.controller.disappear();
|
|
52
|
+
this._props.items[index].controller.appear();
|
|
53
|
+
(_c = (_b = this._events).changed) === null || _c === void 0 ? void 0 : _c.call(_b, this, index);
|
|
54
|
+
},
|
|
55
|
+
doubleTapped: (cview, index) => {
|
|
56
|
+
var _a, _b;
|
|
57
|
+
(_b = (_a = this._events).doubleTapped) === null || _b === void 0 ? void 0 : _b.call(_a, this, index);
|
|
58
|
+
}
|
|
42
59
|
}
|
|
43
60
|
});
|
|
44
61
|
this.pages = this._props.items.map((n, i) => {
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tabbar_controller_1 = require("../controller/tabbar-controller");
|
|
4
|
+
const base_controller_1 = require("../controller/base-controller");
|
|
5
|
+
const items = [{
|
|
6
|
+
controller: new base_controller_1.BaseController({
|
|
7
|
+
props: { bgcolor: $color("red") },
|
|
8
|
+
events: {
|
|
9
|
+
didAppear: () => {
|
|
10
|
+
console.log("Page 1 did appear");
|
|
11
|
+
},
|
|
12
|
+
didDisappear: () => {
|
|
13
|
+
console.log("Page 1 did disappear");
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}),
|
|
17
|
+
title: "Page 1"
|
|
18
|
+
}, {
|
|
19
|
+
controller: new base_controller_1.BaseController({
|
|
20
|
+
props: { bgcolor: $color("yellow") },
|
|
21
|
+
events: {
|
|
22
|
+
didAppear: () => {
|
|
23
|
+
console.log("Page 2 did appear");
|
|
24
|
+
},
|
|
25
|
+
didDisappear: () => {
|
|
26
|
+
console.log("Page 2 did disappear");
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}),
|
|
30
|
+
title: "Page 2"
|
|
31
|
+
}];
|
|
32
|
+
const pageViewerController = new tabbar_controller_1.TabBarController({
|
|
33
|
+
props: {
|
|
34
|
+
items
|
|
35
|
+
},
|
|
36
|
+
events: {
|
|
37
|
+
changed: (sender, index) => {
|
|
38
|
+
console.log(`Index changed to ${index}`);
|
|
39
|
+
},
|
|
40
|
+
doubleTapped: (sender, index) => {
|
|
41
|
+
console.log(`Double tapped on index ${index}`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
pageViewerController.uirender({});
|
package/package.json
CHANGED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { TabBarController } from "../controller/tabbar-controller";
|
|
2
|
+
import { BaseController } from "../controller/base-controller";
|
|
3
|
+
import { PageViewer } from "../components/pageviewer";
|
|
4
|
+
|
|
5
|
+
const items = [{
|
|
6
|
+
controller: new BaseController({
|
|
7
|
+
props: { bgcolor: $color("red") },
|
|
8
|
+
events: {
|
|
9
|
+
didAppear: () => {
|
|
10
|
+
console.log("Page 1 did appear");
|
|
11
|
+
},
|
|
12
|
+
didDisappear: () => {
|
|
13
|
+
console.log("Page 1 did disappear");
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}),
|
|
17
|
+
title: "Page 1"
|
|
18
|
+
}, {
|
|
19
|
+
controller: new BaseController({
|
|
20
|
+
props: { bgcolor: $color("yellow") },
|
|
21
|
+
events: {
|
|
22
|
+
didAppear: () => {
|
|
23
|
+
console.log("Page 2 did appear");
|
|
24
|
+
},
|
|
25
|
+
didDisappear: () => {
|
|
26
|
+
console.log("Page 2 did disappear");
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}),
|
|
30
|
+
title: "Page 2"
|
|
31
|
+
}]
|
|
32
|
+
|
|
33
|
+
const pageViewerController = new TabBarController({
|
|
34
|
+
props: {
|
|
35
|
+
items
|
|
36
|
+
},
|
|
37
|
+
events: {
|
|
38
|
+
changed: (sender, index) => {
|
|
39
|
+
console.log(`Index changed to ${index}`);
|
|
40
|
+
},
|
|
41
|
+
doubleTapped: (sender, index) => {
|
|
42
|
+
console.log(`Double tapped on index ${index}`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
pageViewerController.uirender({});
|