jsbox-cview 1.2.3 → 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.
- package/components/searchbar.ts +22 -10
- package/dist/components/searchbar.js +22 -9
- package/dist/test/searchbar.js +36 -0
- package/package.json +1 -1
- package/test/searchbar.ts +38 -0
package/components/searchbar.ts
CHANGED
|
@@ -35,7 +35,7 @@ interface SearchBarProps {
|
|
|
35
35
|
tintColor: UIColor;
|
|
36
36
|
bgcolor: UIColor;
|
|
37
37
|
style: 0 | 1 | 2;
|
|
38
|
-
accessoryCview?: Base<
|
|
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
|
-
|
|
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.
|
|
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
|
-
|
|
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,
|
|
@@ -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
|
-
|
|
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.
|
|
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
|
-
|
|
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,
|
|
@@ -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
|
@@ -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
|
+
});
|