jsbox-cview 1.5.9 → 1.5.11

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.
@@ -169,15 +169,17 @@ interface SplitViewControllerProps extends BaseControllerProps {
169
169
  *
170
170
  * 此控制器加载后,会禁用原本的ScreenEdgePanGesture,此控制器应该作为根控制器使用
171
171
  *
172
- * ## Props
172
+ * @param options.props.items: { controller: Controller, bgcolor: UIColor }[] 其中第一个放在主视图上, 第二个放在次视图上
173
173
  *
174
- * - 只写 items: { controller: Controller, bgcolor: UIColor }[] 其中第一个放在主视图上, 第二个放在次视图上
175
- * - 读写 sideBarShown: boolean = false 侧栏是否显示
174
+ * @property sideBarShown: boolean = false 侧栏是否显示
175
+ * @property canShowSidebar: boolean = true 是否启动显示侧栏的动作(若为false,依然可以用sideBarShown来控制侧栏的显示)
176
176
  */
177
177
  export class SplitViewController extends BaseController {
178
178
  private _screenEdgePanGestureObject: any;
179
179
  private _sideBarShown: boolean;
180
180
  private _canShowSidebar: boolean;
181
+ private _primaryController: BaseController;
182
+ private _secondaryController: BaseController;
181
183
  cviews: {
182
184
  primaryView: ContentView;
183
185
  secondaryView: SecondaryView;
@@ -196,6 +198,8 @@ export class SplitViewController extends BaseController {
196
198
  });
197
199
  this._sideBarShown = false;
198
200
  this._canShowSidebar = true;
201
+ this._primaryController = props.items[0].controller;
202
+ this._secondaryController = props.items[1].controller;
199
203
  this.cviews = {} as {
200
204
  primaryView: ContentView;
201
205
  secondaryView: SecondaryView;
@@ -322,6 +326,13 @@ export class SplitViewController extends BaseController {
322
326
  this._hideSideBar();
323
327
  }
324
328
  this._sideBarShown = bool;
329
+ if (bool) {
330
+ this._primaryController.disappear();
331
+ this._secondaryController.appear();
332
+ } else {
333
+ this._primaryController.appear();
334
+ this._secondaryController.disappear();
335
+ }
325
336
  }
326
337
 
327
338
  get canShowSidebar() {
@@ -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,31 @@ 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?: BaseControllerEvents;
48
+ events?: TabBarControllerEvents;
43
49
  }) {
44
50
  super({
45
51
  props: {
46
52
  id: props.id,
47
53
  bgcolor: props.bgcolor
48
- }, layout, events
54
+ },
55
+ layout,
56
+ events: {
57
+ ...events,
58
+ didAppear: () => {
59
+ this._props.items[this.index].controller.appear();
60
+ this._events.didAppear?.(this);
61
+ },
62
+ didDisappear: () => {
63
+ this._props.items[this.index].controller.disappear();
64
+ this._events.didDisappear?.(this);
65
+ }
66
+ }
49
67
  });
50
68
  this._props = {
51
69
  items: props.items,
52
70
  index: props.index || 0
53
71
  };
72
+ this._events = events;
54
73
  this.cviews = {} as {
55
74
  tabbar: TabBar;
56
75
  pageContentView: ContentView;
@@ -61,7 +80,15 @@ export class TabBarController extends BaseController {
61
80
  index: this._props.index
62
81
  },
63
82
  events: {
64
- changed: (cview, index) => (this.index = index)
83
+ changed: (cview, index) => {
84
+ this.index = index;
85
+ this._props.items.find(item=>item.controller.status === 2)?.controller.disappear();
86
+ this._props.items[index].controller.appear();
87
+ this._events.changed?.(this, index);
88
+ },
89
+ doubleTapped: (cview, index) => {
90
+ this._events.doubleTapped?.(this, index);
91
+ }
65
92
  }
66
93
  });
67
94
 
@@ -126,10 +126,10 @@ class MaskView extends base_1.Base {
126
126
  *
127
127
  * 此控制器加载后,会禁用原本的ScreenEdgePanGesture,此控制器应该作为根控制器使用
128
128
  *
129
- * ## Props
129
+ * @param options.props.items: { controller: Controller, bgcolor: UIColor }[] 其中第一个放在主视图上, 第二个放在次视图上
130
130
  *
131
- * - 只写 items: { controller: Controller, bgcolor: UIColor }[] 其中第一个放在主视图上, 第二个放在次视图上
132
- * - 读写 sideBarShown: boolean = false 侧栏是否显示
131
+ * @property sideBarShown: boolean = false 侧栏是否显示
132
+ * @property canShowSidebar: boolean = true 是否启动显示侧栏的动作(若为false,依然可以用sideBarShown来控制侧栏的显示)
133
133
  */
134
134
  class SplitViewController extends base_controller_1.BaseController {
135
135
  constructor({ props, layout, events }) {
@@ -141,6 +141,8 @@ class SplitViewController extends base_controller_1.BaseController {
141
141
  });
142
142
  this._sideBarShown = false;
143
143
  this._canShowSidebar = true;
144
+ this._primaryController = props.items[0].controller;
145
+ this._secondaryController = props.items[1].controller;
144
146
  this.cviews = {};
145
147
  this.cviews.secondaryView = new SecondaryView({
146
148
  props: {
@@ -250,6 +252,14 @@ class SplitViewController extends base_controller_1.BaseController {
250
252
  this._hideSideBar();
251
253
  }
252
254
  this._sideBarShown = bool;
255
+ if (bool) {
256
+ this._primaryController.disappear();
257
+ this._secondaryController.appear();
258
+ }
259
+ else {
260
+ this._primaryController.appear();
261
+ this._secondaryController.disappear();
262
+ }
253
263
  }
254
264
  get canShowSidebar() {
255
265
  return this._canShowSidebar;
@@ -25,12 +25,23 @@ class TabBarController extends base_controller_1.BaseController {
25
25
  props: {
26
26
  id: props.id,
27
27
  bgcolor: props.bgcolor
28
- }, layout, events
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
+ }, didDisappear: () => {
35
+ var _a, _b;
36
+ this._props.items[this.index].controller.disappear();
37
+ (_b = (_a = this._events).didDisappear) === null || _b === void 0 ? void 0 : _b.call(_a, this);
38
+ } })
29
39
  });
30
40
  this._props = {
31
41
  items: props.items,
32
42
  index: props.index || 0
33
43
  };
44
+ this._events = events;
34
45
  this.cviews = {};
35
46
  this.cviews.tabbar = new tabbar_1.TabBar({
36
47
  props: {
@@ -38,7 +49,17 @@ class TabBarController extends base_controller_1.BaseController {
38
49
  index: this._props.index
39
50
  },
40
51
  events: {
41
- changed: (cview, index) => (this.index = index)
52
+ changed: (cview, index) => {
53
+ var _a, _b, _c;
54
+ this.index = index;
55
+ (_a = this._props.items.find(item => item.controller.status === 2)) === null || _a === void 0 ? void 0 : _a.controller.disappear();
56
+ this._props.items[index].controller.appear();
57
+ (_c = (_b = this._events).changed) === null || _c === void 0 ? void 0 : _c.call(_b, this, index);
58
+ },
59
+ doubleTapped: (cview, index) => {
60
+ var _a, _b;
61
+ (_b = (_a = this._events).doubleTapped) === null || _b === void 0 ? void 0 : _b.call(_a, this, index);
62
+ }
42
63
  }
43
64
  });
44
65
  this.pages = this._props.items.map((n, i) => {
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const splitview_controller_1 = require("../controller/splitview-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
+ bgcolor: $color("red")
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
+ bgcolor: $color("green")
31
+ }];
32
+ const pageViewerController = new splitview_controller_1.SplitViewController({
33
+ props: {
34
+ items
35
+ },
36
+ events: {}
37
+ });
38
+ pageViewerController.uirender();
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jsbox-cview",
3
- "version": "1.5.9",
3
+ "version": "1.5.11",
4
4
  "description": "为 JSBox 设计的微型框架",
5
5
  "repository": {
6
6
  "type": "git",
@@ -0,0 +1,41 @@
1
+ import { SplitViewController } from "../controller/splitview-controller";
2
+ import { BaseController } from "../controller/base-controller";
3
+
4
+ const items = [{
5
+ controller: new BaseController({
6
+ props: { bgcolor: $color("red") },
7
+ events: {
8
+ didAppear: () => {
9
+ console.log("Page 1 did appear");
10
+ },
11
+ didDisappear: () => {
12
+ console.log("Page 1 did disappear");
13
+ }
14
+ }
15
+ }),
16
+ bgcolor: $color("red")
17
+ }, {
18
+ controller: new BaseController({
19
+ props: { bgcolor: $color("yellow") },
20
+ events: {
21
+ didAppear: () => {
22
+ console.log("Page 2 did appear");
23
+ },
24
+ didDisappear: () => {
25
+ console.log("Page 2 did disappear");
26
+ }
27
+ }
28
+ }),
29
+ bgcolor: $color("green")
30
+ }]
31
+
32
+ const pageViewerController = new SplitViewController({
33
+ props: {
34
+ items
35
+ },
36
+ events: {
37
+
38
+ }
39
+ });
40
+
41
+ pageViewerController.uirender();
@@ -0,0 +1,46 @@
1
+ import { TabBarController } from "../controller/tabbar-controller";
2
+ import { BaseController } from "../controller/base-controller";
3
+
4
+ const items = [{
5
+ controller: new BaseController({
6
+ props: { bgcolor: $color("red") },
7
+ events: {
8
+ didAppear: () => {
9
+ console.log("Page 1 did appear");
10
+ },
11
+ didDisappear: () => {
12
+ console.log("Page 1 did disappear");
13
+ }
14
+ }
15
+ }),
16
+ title: "Page 1"
17
+ }, {
18
+ controller: new BaseController({
19
+ props: { bgcolor: $color("yellow") },
20
+ events: {
21
+ didAppear: () => {
22
+ console.log("Page 2 did appear");
23
+ },
24
+ didDisappear: () => {
25
+ console.log("Page 2 did disappear");
26
+ }
27
+ }
28
+ }),
29
+ title: "Page 2"
30
+ }]
31
+
32
+ const pageViewerController = new 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
+
46
+ pageViewerController.uirender({});