jsbox-cview 1.2.2 → 1.2.4

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.
@@ -52,7 +52,7 @@
52
52
  */
53
53
 
54
54
  import { Base } from "./base";
55
- import { ContentView, Label, Button } from "./single-views";
55
+ import { ContentView, Label, Button, Blur } from "./single-views";
56
56
  import { SymbolButton } from "./symbol-button";
57
57
  import { getTextWidth } from "../utils/uitools";
58
58
 
@@ -122,6 +122,8 @@ interface NavigationBarCViews {
122
122
  titleViewWrapper?: ContentView | Label;
123
123
  contentView?: ContentView;
124
124
  toolViewWrapper?: ContentView;
125
+ bgview?: ContentView | Blur;
126
+ separator?: ContentView;
125
127
  }
126
128
 
127
129
  export class CustomNavigationBar extends Base<UIView | UIBlurView, UiTypes.ViewOptions | UiTypes.BlurOptions> {
@@ -318,19 +320,41 @@ export class CustomNavigationBar extends Base<UIView | UIBlurView, UiTypes.ViewO
318
320
  },
319
321
  views: this._props.toolView && [this._props.toolView.definition]
320
322
  });
321
-
323
+ if (this._props.bgcolor) {
324
+ this.cviews.bgview = new ContentView({
325
+ props: {
326
+ bgcolor: this._props.bgcolor
327
+ },
328
+ layout: $layout.fill
329
+ });
330
+ } else {
331
+ this.cviews.bgview = new Blur({
332
+ props: {
333
+ style: 10
334
+ },
335
+ layout: $layout.fill
336
+ });
337
+ }
338
+ this.cviews.separator = new ContentView({
339
+ props: {
340
+ bgcolor: $color("separatorColor")
341
+ },
342
+ layout: (make, view) => {
343
+ make.bottom.left.right.inset(0);
344
+ make.height.equalTo(0.5);
345
+ }
346
+ });
322
347
  return {
323
- type: this._props.bgcolor ? "view" : "blur",
348
+ type: "view",
324
349
  props: {
325
350
  id: this.id,
326
- style: this._props.bgcolor ? undefined : 10,
327
- bgcolor: this._props.bgcolor
328
351
  },
329
352
  layout: navBarLayouts[this._props.style],
330
353
  events: {
331
354
  ready: () => (this.style = this.style)
332
355
  },
333
356
  views: [
357
+ this.cviews.bgview.definition,
334
358
  {
335
359
  type: "view",
336
360
  props: {},
@@ -340,16 +364,7 @@ export class CustomNavigationBar extends Base<UIView | UIBlurView, UiTypes.ViewO
340
364
  this.cviews.toolViewWrapper.definition
341
365
  ]
342
366
  },
343
- {
344
- type: "view",
345
- props: {
346
- bgcolor: $color("separatorColor")
347
- },
348
- layout: (make, view) => {
349
- make.bottom.left.right.inset(0);
350
- make.height.equalTo(0.5);
351
- }
352
- }
367
+ this.cviews.separator.definition
353
368
  ]
354
369
  };
355
370
  }
@@ -35,7 +35,7 @@ interface SearchBarProps {
35
35
  tintColor: UIColor;
36
36
  bgcolor: UIColor;
37
37
  style: 0 | 1 | 2;
38
- accessoryCview?: Base<UIView, UiTypes.ViewOptions>;
38
+ accessoryCview?: Base<any, any>;
39
39
  }
40
40
 
41
41
  export class SearchBar extends Base<UIView, UiTypes.ViewOptions> {
@@ -80,12 +80,8 @@ export class SearchBar extends Base<UIView, UiTypes.ViewOptions> {
80
80
  style: 0,
81
81
  ...props
82
82
  };
83
- const cancelButtonWidth = getTextWidth(this._props.cancelText, {
84
- inset: 20
85
- });
86
- const placeholderWidth = getTextWidth(this._props.cancelText, {
87
- inset: 20
88
- });
83
+ const cancelButtonWidth = getTextWidth(this._props.cancelText, { inset: 20 });
84
+ const placeholderWidth = getTextWidth(this._props.placeholder, { inset: 20 });
89
85
  this._focused = false;
90
86
  this._layouts = this._defineLayouts(cancelButtonWidth, placeholderWidth);
91
87
  this.cviews = {} as {
@@ -205,13 +201,17 @@ export class SearchBar extends Base<UIView, UiTypes.ViewOptions> {
205
201
  switch (this._props.style) {
206
202
  case 0: {
207
203
  const IconInputLayout = $layout.fill;
204
+ const IconInputLayoutFocused = (make: MASConstraintMaker, view: AllUIView) => {
205
+ make.left.top.bottom.inset(0);
206
+ make.right.inset(cancelButtonWidth);
207
+ }
208
208
  const cancelButtonLayout = (make: MASConstraintMaker, view: AllUIView) => {
209
209
  make.right.top.bottom.inset(0);
210
210
  make.width.equalTo(cancelButtonWidth);
211
211
  };
212
212
  const bgviewLayout = $layout.fill;
213
213
  return {
214
- iconInput: { normal: IconInputLayout },
214
+ iconInput: { normal: IconInputLayout, focused: IconInputLayoutFocused },
215
215
  cancelButton: { normal: cancelButtonLayout },
216
216
  bgview: { normal: bgviewLayout }
217
217
  };
@@ -219,7 +219,7 @@ export class SearchBar extends Base<UIView, UiTypes.ViewOptions> {
219
219
  case 1: {
220
220
  const IconInputLayout = (make: MASConstraintMaker, view: AllUIView) => {
221
221
  make.left.top.bottom.inset(0);
222
- make.right.inset(cancelButtonWidth);
222
+ make.right.equalTo(view.prev);
223
223
  };
224
224
  const cancelButtonLayout = (make: MASConstraintMaker, view: AllUIView) => {
225
225
  make.top.bottom.inset(0);
@@ -273,11 +273,13 @@ export class SearchBar extends Base<UIView, UiTypes.ViewOptions> {
273
273
 
274
274
  _onFocused() {
275
275
  this._focused = true;
276
+ if (this._layouts.iconInput.focused) this.cviews.iconInput.view.remakeLayout(this._layouts.iconInput.focused);
276
277
  switch (this._props.style) {
277
278
  case 0: {
278
279
  $ui.animate({
279
280
  duration: 0.2,
280
281
  animation: () => {
282
+ this.cviews.iconInput.view.relayout();
281
283
  this.cviews.cancelButton.view.alpha = 1;
282
284
  }
283
285
  });
@@ -314,11 +316,13 @@ export class SearchBar extends Base<UIView, UiTypes.ViewOptions> {
314
316
 
315
317
  _onBlurred() {
316
318
  this._focused = false;
319
+ this.cviews.iconInput.view.remakeLayout(this._layouts.iconInput.normal);
317
320
  switch (this._props.style) {
318
321
  case 0: {
319
322
  $ui.animate({
320
323
  duration: 0.2,
321
324
  animation: () => {
325
+ this.cviews.iconInput.view.relayout();
322
326
  this.cviews.cancelButton.view.alpha = 0;
323
327
  }
324
328
  });
@@ -336,7 +340,15 @@ export class SearchBar extends Base<UIView, UiTypes.ViewOptions> {
336
340
  break;
337
341
  }
338
342
  case 2: {
339
- this.cviews.iconInput.view.remakeLayout(this._layouts.iconInput.normal);
343
+ const placeholderWidth = getTextWidth(this._props.placeholder, { inset: 20 });
344
+ const textWidth = getTextWidth(this.text, { inset: 20 });
345
+ const IconInputLayoutInputing = (make: MASConstraintMaker, view: AllUIView) => {
346
+ make.center.equalTo(view.super);
347
+ make.top.bottom.inset(0);
348
+ make.width.equalTo(Math.max(textWidth, placeholderWidth) + 50).priority(999);
349
+ make.width.lessThanOrEqualTo(view.super).priority(1000);
350
+ }
351
+ this.cviews.iconInput.view.remakeLayout(IconInputLayoutInputing);
340
352
  this.cviews.bgview.view.remakeLayout(this._layouts.bgview.normal);
341
353
  $ui.animate({
342
354
  duration: 0.2,
@@ -256,18 +256,42 @@ class CustomNavigationBar extends base_1.Base {
256
256
  },
257
257
  views: this._props.toolView && [this._props.toolView.definition]
258
258
  });
259
+ if (this._props.bgcolor) {
260
+ this.cviews.bgview = new single_views_1.ContentView({
261
+ props: {
262
+ bgcolor: this._props.bgcolor
263
+ },
264
+ layout: $layout.fill
265
+ });
266
+ }
267
+ else {
268
+ this.cviews.bgview = new single_views_1.Blur({
269
+ props: {
270
+ style: 10
271
+ },
272
+ layout: $layout.fill
273
+ });
274
+ }
275
+ this.cviews.separator = new single_views_1.ContentView({
276
+ props: {
277
+ bgcolor: $color("separatorColor")
278
+ },
279
+ layout: (make, view) => {
280
+ make.bottom.left.right.inset(0);
281
+ make.height.equalTo(0.5);
282
+ }
283
+ });
259
284
  return {
260
- type: this._props.bgcolor ? "view" : "blur",
285
+ type: "view",
261
286
  props: {
262
287
  id: this.id,
263
- style: this._props.bgcolor ? undefined : 10,
264
- bgcolor: this._props.bgcolor
265
288
  },
266
289
  layout: navBarLayouts[this._props.style],
267
290
  events: {
268
291
  ready: () => (this.style = this.style)
269
292
  },
270
293
  views: [
294
+ this.cviews.bgview.definition,
271
295
  {
272
296
  type: "view",
273
297
  props: {},
@@ -277,16 +301,7 @@ class CustomNavigationBar extends base_1.Base {
277
301
  this.cviews.toolViewWrapper.definition
278
302
  ]
279
303
  },
280
- {
281
- type: "view",
282
- props: {
283
- bgcolor: $color("separatorColor")
284
- },
285
- layout: (make, view) => {
286
- make.bottom.left.right.inset(0);
287
- make.height.equalTo(0.5);
288
- }
289
- }
304
+ this.cviews.separator.definition
290
305
  ]
291
306
  };
292
307
  };
@@ -34,12 +34,8 @@ class SearchBar extends base_1.Base {
34
34
  constructor({ props, layout, events = {} }) {
35
35
  super();
36
36
  this._props = Object.assign({ placeholder: (0, l10n_1.l10n)("SEARCH"), cancelText: (0, l10n_1.l10n)("CANCEL"), tintColor: $color("systemLink"), bgcolor: colors_1.searchBarBgcolor, style: 0 }, props);
37
- const cancelButtonWidth = (0, uitools_1.getTextWidth)(this._props.cancelText, {
38
- inset: 20
39
- });
40
- const placeholderWidth = (0, uitools_1.getTextWidth)(this._props.cancelText, {
41
- inset: 20
42
- });
37
+ const cancelButtonWidth = (0, uitools_1.getTextWidth)(this._props.cancelText, { inset: 20 });
38
+ const placeholderWidth = (0, uitools_1.getTextWidth)(this._props.placeholder, { inset: 20 });
43
39
  this._focused = false;
44
40
  this._layouts = this._defineLayouts(cancelButtonWidth, placeholderWidth);
45
41
  this.cviews = {};
@@ -156,13 +152,17 @@ class SearchBar extends base_1.Base {
156
152
  switch (this._props.style) {
157
153
  case 0: {
158
154
  const IconInputLayout = $layout.fill;
155
+ const IconInputLayoutFocused = (make, view) => {
156
+ make.left.top.bottom.inset(0);
157
+ make.right.inset(cancelButtonWidth);
158
+ };
159
159
  const cancelButtonLayout = (make, view) => {
160
160
  make.right.top.bottom.inset(0);
161
161
  make.width.equalTo(cancelButtonWidth);
162
162
  };
163
163
  const bgviewLayout = $layout.fill;
164
164
  return {
165
- iconInput: { normal: IconInputLayout },
165
+ iconInput: { normal: IconInputLayout, focused: IconInputLayoutFocused },
166
166
  cancelButton: { normal: cancelButtonLayout },
167
167
  bgview: { normal: bgviewLayout }
168
168
  };
@@ -170,7 +170,7 @@ class SearchBar extends base_1.Base {
170
170
  case 1: {
171
171
  const IconInputLayout = (make, view) => {
172
172
  make.left.top.bottom.inset(0);
173
- make.right.inset(cancelButtonWidth);
173
+ make.right.equalTo(view.prev);
174
174
  };
175
175
  const cancelButtonLayout = (make, view) => {
176
176
  make.top.bottom.inset(0);
@@ -223,11 +223,14 @@ class SearchBar extends base_1.Base {
223
223
  }
224
224
  _onFocused() {
225
225
  this._focused = true;
226
+ if (this._layouts.iconInput.focused)
227
+ this.cviews.iconInput.view.remakeLayout(this._layouts.iconInput.focused);
226
228
  switch (this._props.style) {
227
229
  case 0: {
228
230
  $ui.animate({
229
231
  duration: 0.2,
230
232
  animation: () => {
233
+ this.cviews.iconInput.view.relayout();
231
234
  this.cviews.cancelButton.view.alpha = 1;
232
235
  }
233
236
  });
@@ -266,11 +269,13 @@ class SearchBar extends base_1.Base {
266
269
  }
267
270
  _onBlurred() {
268
271
  this._focused = false;
272
+ this.cviews.iconInput.view.remakeLayout(this._layouts.iconInput.normal);
269
273
  switch (this._props.style) {
270
274
  case 0: {
271
275
  $ui.animate({
272
276
  duration: 0.2,
273
277
  animation: () => {
278
+ this.cviews.iconInput.view.relayout();
274
279
  this.cviews.cancelButton.view.alpha = 0;
275
280
  }
276
281
  });
@@ -288,7 +293,15 @@ class SearchBar extends base_1.Base {
288
293
  break;
289
294
  }
290
295
  case 2: {
291
- this.cviews.iconInput.view.remakeLayout(this._layouts.iconInput.normal);
296
+ const placeholderWidth = (0, uitools_1.getTextWidth)(this._props.placeholder, { inset: 20 });
297
+ const textWidth = (0, uitools_1.getTextWidth)(this.text, { inset: 20 });
298
+ const IconInputLayoutInputing = (make, view) => {
299
+ make.center.equalTo(view.super);
300
+ make.top.bottom.inset(0);
301
+ make.width.equalTo(Math.max(textWidth, placeholderWidth) + 50).priority(999);
302
+ make.width.lessThanOrEqualTo(view.super).priority(1000);
303
+ };
304
+ this.cviews.iconInput.view.remakeLayout(IconInputLayoutInputing);
292
305
  this.cviews.bgview.view.remakeLayout(this._layouts.bgview.normal);
293
306
  $ui.animate({
294
307
  duration: 0.2,
@@ -6,6 +6,11 @@ const navbar = new custom_navigation_bar_1.CustomNavigationBar({
6
6
  title: "Custom Navigation Bar",
7
7
  popButtonEnabled: true,
8
8
  popButtonTitle: "Back",
9
+ rightBarButtonItems: [
10
+ {
11
+ symbol: "gear",
12
+ }
13
+ ]
9
14
  }
10
15
  });
11
16
  $ui.render({
@@ -18,6 +23,14 @@ $ui.render({
18
23
  $ui.push({
19
24
  views: [navbar.definition]
20
25
  });
26
+ $delay(1, () => {
27
+ navbar.cviews.bgview.view.alpha = 0.5;
28
+ navbar.cviews.separator.view.alpha = 0.5;
29
+ });
30
+ $delay(2, () => {
31
+ navbar.cviews.bgview.view.alpha = 0;
32
+ navbar.cviews.separator.view.alpha = 0;
33
+ });
21
34
  }
22
35
  }
23
36
  }]
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const searchbar_1 = require("../components/searchbar");
4
+ const s0 = new searchbar_1.SearchBar({
5
+ props: {
6
+ style: 0
7
+ },
8
+ layout: (make, view) => {
9
+ make.centerX.equalTo(view.super);
10
+ make.size.equalTo($size(300, 44));
11
+ make.top.equalTo(view.super).inset(50);
12
+ }
13
+ });
14
+ const s1 = new searchbar_1.SearchBar({
15
+ props: {
16
+ style: 1
17
+ },
18
+ layout: (make, view) => {
19
+ make.centerX.equalTo(view.super);
20
+ make.size.equalTo($size(300, 44));
21
+ make.top.equalTo(view.super).inset(125);
22
+ }
23
+ });
24
+ const s2 = new searchbar_1.SearchBar({
25
+ props: {
26
+ style: 2
27
+ },
28
+ layout: (make, view) => {
29
+ make.centerX.equalTo(view.super);
30
+ make.size.equalTo($size(300, 44));
31
+ make.top.equalTo(view.super).inset(200);
32
+ }
33
+ });
34
+ $ui.render({
35
+ views: [s0.definition, s1.definition, s2.definition]
36
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jsbox-cview",
3
- "version": "1.2.2",
3
+ "version": "1.2.4",
4
4
  "description": "为 JSBox 设计的微型框架",
5
5
  "repository": {
6
6
  "type": "git",
@@ -5,6 +5,11 @@ const navbar = new CustomNavigationBar({
5
5
  title: "Custom Navigation Bar",
6
6
  popButtonEnabled: true,
7
7
  popButtonTitle: "Back",
8
+ rightBarButtonItems: [
9
+ {
10
+ symbol: "gear",
11
+ }
12
+ ]
8
13
  }
9
14
  })
10
15
 
@@ -20,6 +25,14 @@ $ui.render({
20
25
  $ui.push({
21
26
  views: [navbar.definition]
22
27
  })
28
+ $delay(1, () => {
29
+ navbar.cviews.bgview.view.alpha = 0.5
30
+ navbar.cviews.separator.view.alpha = 0.5
31
+ })
32
+ $delay(2, () => {
33
+ navbar.cviews.bgview.view.alpha = 0
34
+ navbar.cviews.separator.view.alpha = 0
35
+ })
23
36
  }
24
37
  }
25
38
  }]
@@ -0,0 +1,38 @@
1
+ import { SearchBar } from "../components/searchbar";
2
+
3
+ const s0 = new SearchBar({
4
+ props: {
5
+ style: 0
6
+ },
7
+ layout: (make, view) => {
8
+ make.centerX.equalTo(view.super);
9
+ make.size.equalTo($size(300, 44));
10
+ make.top.equalTo(view.super).inset(50);
11
+ }
12
+ });
13
+
14
+ const s1 = new SearchBar({
15
+ props: {
16
+ style: 1
17
+ },
18
+ layout: (make, view) => {
19
+ make.centerX.equalTo(view.super);
20
+ make.size.equalTo($size(300, 44));
21
+ make.top.equalTo(view.super).inset(125);
22
+ }
23
+ });
24
+
25
+ const s2 = new SearchBar({
26
+ props: {
27
+ style: 2
28
+ },
29
+ layout: (make, view) => {
30
+ make.centerX.equalTo(view.super);
31
+ make.size.equalTo($size(300, 44));
32
+ make.top.equalTo(view.super).inset(200);
33
+ }
34
+ });
35
+
36
+ $ui.render({
37
+ views: [s0.definition, s1.definition, s2.definition]
38
+ });