@ledvance/ui-biz-bundle 1.1.157 → 1.1.159
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/package.json +1 -1
- package/src/modules/flags/FlagActions.ts +1 -1
- package/src/modules/flags/FlagInfo.tsx +82 -3
- package/src/modules/flags/FlagItem.tsx +123 -59
- package/src/modules/flags/FlagPage.tsx +116 -89
- package/src/modules/flags/LatamFlagPage.tsx +82 -0
- package/src/modules/flags/Router.ts +9 -0
- package/src/navigation/Routers.ts +1 -0
- package/src/newModules/mood/AddMoodPage.tsx +66 -65
- package/src/newModules/mood/MoodItem.tsx +166 -117
- package/src/newModules/mood/RecommendMoodItem.tsx +81 -49
package/package.json
CHANGED
|
@@ -59,7 +59,7 @@ export const useFlag: UseFlagType = (flagCode, extra) => {
|
|
|
59
59
|
})
|
|
60
60
|
const extraDps = {}
|
|
61
61
|
if(extra.isCeilingLight){
|
|
62
|
-
extraDps[extra.switchLedCode] = true
|
|
62
|
+
extraDps[extra.switchLedCode] = true
|
|
63
63
|
extraDps[extra.whiteSwitchCode!] = true
|
|
64
64
|
extraDps[extra.rgbcSwitchLedCode!] = true
|
|
65
65
|
extraDps[extra.rgbcWorkModeCode!] = WORK_MODE.COLOUR
|
|
@@ -2,13 +2,13 @@ import I18n from "@ledvance/base/src/i18n";
|
|
|
2
2
|
import { SceneNodeTransitionMode } from "../scene/SceneInfo";
|
|
3
3
|
|
|
4
4
|
type HSV = {
|
|
5
|
-
h: number
|
|
6
|
-
s: number
|
|
5
|
+
h: number
|
|
6
|
+
s: number
|
|
7
7
|
v: number
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
type BT = {
|
|
11
|
-
brightness: number
|
|
11
|
+
brightness: number
|
|
12
12
|
colorTemp: number
|
|
13
13
|
}
|
|
14
14
|
|
|
@@ -24,6 +24,7 @@ export interface FlagItemInfo {
|
|
|
24
24
|
|
|
25
25
|
export interface FlagUiInfo extends FlagItemInfo{
|
|
26
26
|
name: string
|
|
27
|
+
groupKey?: string
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
const defFlagConfig = {
|
|
@@ -45,36 +46,42 @@ export const defFlagList: FlagUiInfo[] = [
|
|
|
45
46
|
{
|
|
46
47
|
id: 255,
|
|
47
48
|
name: I18n.getLang('country_DE'),
|
|
49
|
+
groupKey: 'latam_2026_e',
|
|
48
50
|
...defFlagConfig,
|
|
49
51
|
colors: [{ h: 48, s: 100, v: 100 }, { h: 360, s: 100, v: 100 }, { h: 0, s: 0, v: 0 }],
|
|
50
52
|
},
|
|
51
53
|
{
|
|
52
54
|
id: 254,
|
|
53
55
|
name: I18n.getLang('country_BE'),
|
|
56
|
+
groupKey: 'latam_2026_g',
|
|
54
57
|
...defFlagConfig,
|
|
55
58
|
colors: [{ h: 360, s: 100, v: 100 }, { h: 48, s: 100, v: 100 }, { h: 0, s: 0, v: 0 }]
|
|
56
59
|
},
|
|
57
60
|
{
|
|
58
61
|
id: 253,
|
|
59
62
|
name: I18n.getLang('country_FR'),
|
|
63
|
+
groupKey: 'latam_2026_i',
|
|
60
64
|
...defFlagConfig,
|
|
61
65
|
colors: [{ h: 360, s: 100, v: 100 }, { h: 0, s: 0, v: 100 }, { h: 212, s: 100, v: 100 }]
|
|
62
66
|
},
|
|
63
67
|
{
|
|
64
68
|
id: 252,
|
|
65
69
|
name: I18n.getLang('country_PT'),
|
|
70
|
+
groupKey: 'latam_2026_k',
|
|
66
71
|
...defFlagConfig,
|
|
67
72
|
colors: [{ h: 360, s: 100, v: 100 }, { h: 360, s: 100, v: 100 }, { h: 120, s: 100, v: 64 }]
|
|
68
73
|
},
|
|
69
74
|
{
|
|
70
75
|
id: 251,
|
|
71
76
|
name: I18n.getLang('country_scotland'),
|
|
77
|
+
groupKey: 'latam_2026_c',
|
|
72
78
|
...defFlagConfig,
|
|
73
79
|
colors: [{ h: 209, s: 100, v: 100 }, { h: 0, s: 0, v: 100 }, { h: 209, s: 100, v: 100 }]
|
|
74
80
|
},
|
|
75
81
|
{
|
|
76
82
|
id: 250,
|
|
77
83
|
name: I18n.getLang('country_ES'),
|
|
84
|
+
groupKey: 'latam_2026_h',
|
|
78
85
|
...defFlagConfig,
|
|
79
86
|
colors: [{ h: 360, s: 100, v: 100 }, { h: 47, s: 100, v: 100 }, { h: 360, s: 100, v: 100 }]
|
|
80
87
|
},
|
|
@@ -87,12 +94,14 @@ export const defFlagList: FlagUiInfo[] = [
|
|
|
87
94
|
{
|
|
88
95
|
id: 248,
|
|
89
96
|
name: I18n.getLang('country_AT'),
|
|
97
|
+
groupKey: 'latam_2026_j',
|
|
90
98
|
...defFlagConfig,
|
|
91
99
|
colors: [{ h: 360, s: 100, v: 100 }, { h: 0, s: 0, v: 100 }, { h: 360, s: 100, v: 100 }]
|
|
92
100
|
},
|
|
93
101
|
{
|
|
94
102
|
id: 247,
|
|
95
103
|
name: I18n.getLang('country_england'),
|
|
104
|
+
groupKey: 'latam_2026_l',
|
|
96
105
|
...defFlagConfig,
|
|
97
106
|
colors: [{ h: 0, s: 0, v: 100 }, { h: 360, s: 100, v: 100 }, { h: 0, s: 0, v: 100 }]
|
|
98
107
|
},
|
|
@@ -123,6 +132,7 @@ export const defFlagList: FlagUiInfo[] = [
|
|
|
123
132
|
{
|
|
124
133
|
id: 242,
|
|
125
134
|
name: I18n.getLang('country_NL'),
|
|
135
|
+
groupKey: 'latam_2026_f',
|
|
126
136
|
...defFlagConfig,
|
|
127
137
|
colors: [{ h: 217, s: 100, v: 100 }, { h: 0, s: 0, v: 100 }, { h: 360, s: 100, v: 100 }]
|
|
128
138
|
},
|
|
@@ -135,6 +145,7 @@ export const defFlagList: FlagUiInfo[] = [
|
|
|
135
145
|
{
|
|
136
146
|
id: 240,
|
|
137
147
|
name: I18n.getLang('country_CH'),
|
|
148
|
+
groupKey: 'latam_2026_b',
|
|
138
149
|
...defFlagConfig,
|
|
139
150
|
colors: [{ h: 360, s: 100, v: 100 }, { h: 0, s: 0, v: 100 }, { h: 360, s: 100, v: 100 }]
|
|
140
151
|
},
|
|
@@ -165,6 +176,7 @@ export const defFlagList: FlagUiInfo[] = [
|
|
|
165
176
|
{
|
|
166
177
|
id: 235,
|
|
167
178
|
name: I18n.getLang('country_HR'),
|
|
179
|
+
groupKey: 'latam_2026_l',
|
|
168
180
|
...defFlagConfig,
|
|
169
181
|
colors: [{ h: 220, s: 89, v: 100 }, { h: 0, s: 0, v: 100 }, { h: 360, s: 100, v: 100 }]
|
|
170
182
|
},
|
|
@@ -177,6 +189,7 @@ export const defFlagList: FlagUiInfo[] = [
|
|
|
177
189
|
{
|
|
178
190
|
id: 233,
|
|
179
191
|
name: I18n.getLang('country_NO'),
|
|
192
|
+
groupKey: 'latam_2026_i',
|
|
180
193
|
...defFlagConfig,
|
|
181
194
|
colors: [{ h: 218, s: 100, v: 100 }, { h: 0, s: 0, v: 100 }, { h: 360, s: 100, v: 100 }]
|
|
182
195
|
},
|
|
@@ -215,24 +228,28 @@ export const defFlagList: FlagUiInfo[] = [
|
|
|
215
228
|
{
|
|
216
229
|
id: 226,
|
|
217
230
|
name: I18n.getLang('country_US'),
|
|
231
|
+
groupKey: 'latam_2026_d',
|
|
218
232
|
...defFlagConfig,
|
|
219
233
|
colors: [{ h: 210, s: 78, v: 100 }, { h: 0, s: 0, v: 100 }, { h: 0, s: 100, v: 100 }],
|
|
220
234
|
},
|
|
221
235
|
{
|
|
222
236
|
id: 225,
|
|
223
237
|
name: I18n.getLang('country_CA'),
|
|
238
|
+
groupKey: 'latam_2026_b',
|
|
224
239
|
...defFlagConfig,
|
|
225
240
|
colors: [{ h: 0, s: 100, v: 100 }, { h: 0, s: 0, v: 100 }, { h: 0, s: 100, v: 100 },],
|
|
226
241
|
},
|
|
227
242
|
{
|
|
228
243
|
id: 224,
|
|
229
244
|
name: I18n.getLang('country_MX'),
|
|
245
|
+
groupKey: 'latam_2026_a',
|
|
230
246
|
...defFlagConfig,
|
|
231
247
|
colors: [{ h: 0, s: 100, v: 100 }, { h: 0, s: 0, v: 100 }, { h: 103, s: 73, v: 64 },],
|
|
232
248
|
},
|
|
233
249
|
{
|
|
234
250
|
id: 223,
|
|
235
251
|
name: I18n.getLang('country_SA'),
|
|
252
|
+
groupKey: 'latam_2026_h',
|
|
236
253
|
...defFlagConfig,
|
|
237
254
|
colors: [{ h: 0, s: 0, v: 100 }, { h: 103, s: 73, v: 64 },],
|
|
238
255
|
},
|
|
@@ -245,24 +262,28 @@ export const defFlagList: FlagUiInfo[] = [
|
|
|
245
262
|
{
|
|
246
263
|
id: 221,
|
|
247
264
|
name: I18n.getLang('country_AU'),
|
|
265
|
+
groupKey: 'latam_2026_d',
|
|
248
266
|
...defFlagConfig,
|
|
249
267
|
colors: [{ h: 0, s: 100, v: 100 }, { h: 0, s: 0, v: 100 }, { h: 199, s: 84, v: 100 },],
|
|
250
268
|
},
|
|
251
269
|
{
|
|
252
270
|
id: 220,
|
|
253
271
|
name: I18n.getLang('country_JP'),
|
|
272
|
+
groupKey: 'latam_2026_f',
|
|
254
273
|
...defFlagConfig,
|
|
255
274
|
colors: [{ h: 360, s: 100, v: 100 }, { h: 0, s: 0, v: 100 }],
|
|
256
275
|
},
|
|
257
276
|
{
|
|
258
277
|
id: 219,
|
|
259
278
|
name: I18n.getLang('country_BR'),
|
|
279
|
+
groupKey: 'latam_2026_c',
|
|
260
280
|
...defFlagConfig,
|
|
261
281
|
colors: [{ h: 60, s: 100, v: 100 }, { h: 147, s: 100, v: 64 }, { h: 0, s: 0, v: 100 },],
|
|
262
282
|
},
|
|
263
283
|
{
|
|
264
284
|
id: 218,
|
|
265
285
|
name: I18n.getLang('country_AR'),
|
|
286
|
+
groupKey: 'latam_2026_j',
|
|
266
287
|
...defFlagConfig,
|
|
267
288
|
colors: [{ h: 210, s: 65, v: 100 }, { h: 0, s: 0, v: 100 }, { h: 210, s: 65, v: 100 },],
|
|
268
289
|
},
|
|
@@ -275,6 +296,7 @@ export const defFlagList: FlagUiInfo[] = [
|
|
|
275
296
|
{
|
|
276
297
|
id: 216,
|
|
277
298
|
name: I18n.getLang('country_EG'),
|
|
299
|
+
groupKey: 'latam_2026_g',
|
|
278
300
|
...defFlagConfig,
|
|
279
301
|
colors: [{ h: 0, s: 0, v: 0 }, { h: 0, s: 0, v: 100 }, { h: 0, s: 100, v: 100 },],
|
|
280
302
|
},
|
|
@@ -305,6 +327,7 @@ export const defFlagList: FlagUiInfo[] = [
|
|
|
305
327
|
{
|
|
306
328
|
id: 211,
|
|
307
329
|
name: I18n.getLang('country_EC'),
|
|
330
|
+
groupKey: 'latam_2026_e',
|
|
308
331
|
...defFlagConfig,
|
|
309
332
|
colors: [{ h: 0, s: 100, v: 100 }, { h: 210, s: 78, v: 100 }, { h: 60, s: 100, v: 100 },],
|
|
310
333
|
},
|
|
@@ -317,12 +340,14 @@ export const defFlagList: FlagUiInfo[] = [
|
|
|
317
340
|
{
|
|
318
341
|
id: 209,
|
|
319
342
|
name: I18n.getLang('country_CI'),
|
|
343
|
+
groupKey: 'latam_2026_e',
|
|
320
344
|
...defFlagConfig,
|
|
321
345
|
colors: [{ h: 147, s: 100, v: 64 }, { h: 0, s: 0, v: 100 }, { h: 45, s: 100, v: 100 },],
|
|
322
346
|
},
|
|
323
347
|
{
|
|
324
348
|
id: 208,
|
|
325
349
|
name: I18n.getLang('country_GH'),
|
|
350
|
+
groupKey: 'latam_2026_l',
|
|
326
351
|
...defFlagConfig,
|
|
327
352
|
colors: [{ h: 128, s: 77, v: 64 }, { h: 60, s: 100, v: 100 }, { h: 0, s: 100, v: 100 },],
|
|
328
353
|
},
|
|
@@ -359,6 +384,7 @@ export const defFlagList: FlagUiInfo[] = [
|
|
|
359
384
|
{
|
|
360
385
|
id: 202,
|
|
361
386
|
name: I18n.getLang('country_ir'),
|
|
387
|
+
groupKey: 'latam_2026_g',
|
|
362
388
|
...defFlagConfig,
|
|
363
389
|
colors: [{ h: 0, s: 100, v: 100 }, { h: 0, s: 0, v: 100 }, { h: 147, s: 100, v: 64 },],
|
|
364
390
|
},
|
|
@@ -383,6 +409,7 @@ export const defFlagList: FlagUiInfo[] = [
|
|
|
383
409
|
{
|
|
384
410
|
id: 198,
|
|
385
411
|
name: I18n.getLang('country_QA'),
|
|
412
|
+
groupKey: 'latam_2026_b',
|
|
386
413
|
...defFlagConfig,
|
|
387
414
|
colors: [{ h: 0, s: 100, v: 100 }, { h: 0, s: 0, v: 100 },],
|
|
388
415
|
},
|
|
@@ -395,6 +422,7 @@ export const defFlagList: FlagUiInfo[] = [
|
|
|
395
422
|
{
|
|
396
423
|
id: 196,
|
|
397
424
|
name: I18n.getLang('country_CO'),
|
|
425
|
+
groupKey: 'latam_2026_k',
|
|
398
426
|
...defFlagConfig,
|
|
399
427
|
colors: [{ h: 0, s: 100, v: 100 }, { h: 210, s: 78, v: 100 }, { h: 60, s: 100, v: 100 },],
|
|
400
428
|
},
|
|
@@ -449,6 +477,7 @@ export const defFlagList: FlagUiInfo[] = [
|
|
|
449
477
|
{
|
|
450
478
|
id: 187,
|
|
451
479
|
name: I18n.getLang('country_MA'),
|
|
480
|
+
groupKey: 'latam_2026_c',
|
|
452
481
|
...defFlagConfig,
|
|
453
482
|
colors: [{ h: 147, s: 100, v: 64 }, { h: 0, s: 100, v: 100 },],
|
|
454
483
|
},
|
|
@@ -467,6 +496,7 @@ export const defFlagList: FlagUiInfo[] = [
|
|
|
467
496
|
{
|
|
468
497
|
id: 184,
|
|
469
498
|
name: I18n.getLang('country_NZ'),
|
|
499
|
+
groupKey: 'latam_2026_g',
|
|
470
500
|
...defFlagConfig,
|
|
471
501
|
colors: [{ h: 0, s: 0, v: 100 }, { h: 0, s: 100, v: 100 }, { h: 220, s: 100, v: 100 },],
|
|
472
502
|
},
|
|
@@ -491,6 +521,7 @@ export const defFlagList: FlagUiInfo[] = [
|
|
|
491
521
|
{
|
|
492
522
|
id: 180,
|
|
493
523
|
name: I18n.getLang('country_PY'),
|
|
524
|
+
groupKey: 'latam_2026_d',
|
|
494
525
|
...defFlagConfig,
|
|
495
526
|
colors: [{ h: 205, s: 100, v: 100 }, { h: 0, s: 0, v: 100 }, { h: 0, s: 100, v: 100 },],
|
|
496
527
|
},
|
|
@@ -521,6 +552,7 @@ export const defFlagList: FlagUiInfo[] = [
|
|
|
521
552
|
{
|
|
522
553
|
id: 175,
|
|
523
554
|
name: I18n.getLang('country_ZA'),
|
|
555
|
+
groupKey: 'latam_2026_a',
|
|
524
556
|
...defFlagConfig,
|
|
525
557
|
colors: [{ h: 0, s: 0, v: 0 },{ h: 60, s: 100, v: 100 },{ h: 205, s: 100, v: 100 }, { h: 147, s: 100, v: 64 }, { h: 0, s: 0, v: 100 }, { h: 0, s: 100, v: 100 },],
|
|
526
558
|
},
|
|
@@ -539,6 +571,7 @@ export const defFlagList: FlagUiInfo[] = [
|
|
|
539
571
|
{
|
|
540
572
|
id: 172,
|
|
541
573
|
name: I18n.getLang('country_TN'),
|
|
574
|
+
groupKey: 'latam_2026_f',
|
|
542
575
|
...defFlagConfig,
|
|
543
576
|
colors: [{ h: 0, s: 0, v: 100 }, { h: 0, s: 100, v: 100 },],
|
|
544
577
|
},
|
|
@@ -551,6 +584,7 @@ export const defFlagList: FlagUiInfo[] = [
|
|
|
551
584
|
{
|
|
552
585
|
id: 170,
|
|
553
586
|
name: I18n.getLang('country_UY'),
|
|
587
|
+
groupKey: 'latam_2026_h',
|
|
554
588
|
...defFlagConfig,
|
|
555
589
|
colors: [{ h: 20, s: 100, v: 100 }, { h: 60, s: 100, v: 100 }, { h: 0, s: 0, v: 100 }, { h: 205, s: 100, v: 100 },],
|
|
556
590
|
},
|
|
@@ -563,18 +597,21 @@ export const defFlagList: FlagUiInfo[] = [
|
|
|
563
597
|
{
|
|
564
598
|
id: 168,
|
|
565
599
|
name: I18n.getLang('country_JO'),
|
|
600
|
+
groupKey: 'latam_2026_j',
|
|
566
601
|
...defFlagConfig,
|
|
567
602
|
colors: [{"h":150,"s":100,"v":48}, {"h":0,"s":0,"v":100}, {"h":0,"s":0,"v":0},{"h":353,"s":92,"v":81}],
|
|
568
603
|
},
|
|
569
604
|
{
|
|
570
605
|
id: 167,
|
|
571
606
|
name: I18n.getLang('country_CV'),
|
|
607
|
+
groupKey: 'latam_2026_h',
|
|
572
608
|
...defFlagConfig,
|
|
573
609
|
colors: [{"h":49,"s":100,"v":100}, {"h":356,"s":79,"v":94}, {"h":0,"s":0,"v":100},{"h":218,"s":100,"v":65}],
|
|
574
610
|
},
|
|
575
611
|
{
|
|
576
612
|
id: 166,
|
|
577
613
|
name: I18n.getLang('country_PA'),
|
|
614
|
+
groupKey: 'latam_2026_l',
|
|
578
615
|
...defFlagConfig,
|
|
579
616
|
colors: [{"h":219,"s":92,"v":34}, {"h":0,"s":0,"v":100}, {"h":358,"s":92,"v":85}],
|
|
580
617
|
},
|
|
@@ -608,4 +645,46 @@ export const defFlagList: FlagUiInfo[] = [
|
|
|
608
645
|
...defFlagConfig,
|
|
609
646
|
colors: [{"h":0,"s":0,"v":100}, {"h":160,"s":80,"v":34}],
|
|
610
647
|
},
|
|
648
|
+
{
|
|
649
|
+
id: 160,
|
|
650
|
+
name: I18n.getLang('country_KR'),
|
|
651
|
+
groupKey: 'latam_2026_a',
|
|
652
|
+
...defFlagConfig,
|
|
653
|
+
colors: [{"h":0,"s":0,"v":100}, {"h":355,"s":78,"v":80}, {"h":213,"s":93,"v":80}],
|
|
654
|
+
},
|
|
655
|
+
{
|
|
656
|
+
id: 159,
|
|
657
|
+
name: I18n.getLang('country_HT'),
|
|
658
|
+
groupKey: 'latam_2026_c',
|
|
659
|
+
...defFlagConfig,
|
|
660
|
+
colors: [{"h":228,"s":100,"v":62}, {"h":349,"s":92,"v":82}, {"h":0,"s":0,"v":100}],
|
|
661
|
+
},
|
|
662
|
+
{
|
|
663
|
+
id: 158,
|
|
664
|
+
name: I18n.getLang('country_CW'),
|
|
665
|
+
groupKey: 'latam_2026_e',
|
|
666
|
+
...defFlagConfig,
|
|
667
|
+
colors: [{"h":220,"s":100,"v":50}, {"h":56,"s":92,"v":98}, {"h":0,"s":0,"v":100}],
|
|
668
|
+
},
|
|
669
|
+
{
|
|
670
|
+
id: 157,
|
|
671
|
+
name: I18n.getLang('country_SN'),
|
|
672
|
+
groupKey: 'latam_2026_i',
|
|
673
|
+
...defFlagConfig,
|
|
674
|
+
colors: [{"h":148,"s":100,"v":52}, {"h":56,"s":74,"v":99}, {"h":358,"s":88,"v":89}],
|
|
675
|
+
},
|
|
676
|
+
{
|
|
677
|
+
id: 156,
|
|
678
|
+
name: I18n.getLang('country_DZ'),
|
|
679
|
+
groupKey: 'latam_2026_j',
|
|
680
|
+
...defFlagConfig,
|
|
681
|
+
colors: [{"h":150,"s":100,"v":40}, {"h":0,"s":0,"v":100}, {"h":349,"s":92,"v":82}],
|
|
682
|
+
},
|
|
683
|
+
{
|
|
684
|
+
id: 155,
|
|
685
|
+
name: I18n.getLang('country_UZ'),
|
|
686
|
+
groupKey: 'latam_2026_k',
|
|
687
|
+
...defFlagConfig,
|
|
688
|
+
colors: [{"h":207,"s":100,"v":81}, {"h":0,"s":0,"v":100}, {"h":109,"s":76,"v":69}],
|
|
689
|
+
},
|
|
611
690
|
]
|
|
@@ -1,80 +1,144 @@
|
|
|
1
|
-
import { StyleSheet, View, Text, ViewStyle, Image, TouchableOpacity } from 'react-native'
|
|
2
|
-
import React from 'react'
|
|
3
1
|
import Card from '@ledvance/base/src/components/Card'
|
|
4
|
-
import { Utils } from 'tuya-panel-kit'
|
|
5
2
|
import MoodColorsLine from '@ledvance/base/src/components/MoodColorsLine'
|
|
6
3
|
import Spacer from '@ledvance/base/src/components/Spacer'
|
|
7
4
|
import ThemeType from '@ledvance/base/src/config/themeType'
|
|
8
5
|
import res from '@ledvance/base/src/res'
|
|
6
|
+
import React, { useMemo, useState } from 'react' // 重新引入 useState 和 LayoutChangeEvent
|
|
7
|
+
import { Image, LayoutChangeEvent, StyleSheet, Text, TouchableOpacity, View, ViewStyle } from 'react-native'
|
|
8
|
+
import { Utils } from 'tuya-panel-kit'
|
|
9
9
|
|
|
10
|
-
const cx = Utils.RatioUtils
|
|
10
|
+
const { convertX: cx } = Utils.RatioUtils
|
|
11
11
|
const { withTheme } = Utils.ThemeUtils
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
13
|
+
const CONTENT_HORIZONTAL_MARGIN = cx(16)
|
|
14
|
+
|
|
15
|
+
interface FlagItemProps {
|
|
16
|
+
theme?: ThemeType;
|
|
17
|
+
enable: boolean;
|
|
18
|
+
title: string;
|
|
19
|
+
colors: string[];
|
|
20
|
+
icon?: number | string;
|
|
21
|
+
style?: ViewStyle;
|
|
22
|
+
containerWidth?: number; // 1. 将 containerWidth 变为可选属性
|
|
23
|
+
onPress?: () => void;
|
|
24
|
+
onSwitch: (enable: boolean) => void;
|
|
22
25
|
}
|
|
23
26
|
|
|
24
|
-
|
|
25
|
-
|
|
27
|
+
const getStyles = (theme?: ThemeType) => StyleSheet.create({
|
|
28
|
+
// ... 样式定义保持不变 ...
|
|
29
|
+
card: {
|
|
30
|
+
marginHorizontal: cx(24),
|
|
31
|
+
// 移除 Card 的水平内边距,以便我们能测量到完整的宽度
|
|
32
|
+
paddingHorizontal: 0,
|
|
33
|
+
},
|
|
34
|
+
headline: {
|
|
35
|
+
flexDirection: 'row',
|
|
36
|
+
marginHorizontal: CONTENT_HORIZONTAL_MARGIN,
|
|
37
|
+
justifyContent: 'space-between',
|
|
38
|
+
alignItems: 'center',
|
|
39
|
+
},
|
|
40
|
+
headText: {
|
|
41
|
+
color: theme?.global.fontColor,
|
|
42
|
+
fontSize: cx(16),
|
|
43
|
+
lineHeight: cx(20),
|
|
44
|
+
flex: 1,
|
|
45
|
+
},
|
|
46
|
+
checkbox: {
|
|
47
|
+
width: cx(45),
|
|
48
|
+
height: cx(45),
|
|
49
|
+
justifyContent: 'center',
|
|
50
|
+
alignItems: 'flex-end',
|
|
51
|
+
},
|
|
52
|
+
checkboxImage: {
|
|
53
|
+
width: cx(44),
|
|
54
|
+
height: cx(44),
|
|
55
|
+
},
|
|
56
|
+
lineContainer: {
|
|
57
|
+
marginHorizontal: CONTENT_HORIZONTAL_MARGIN,
|
|
58
|
+
minHeight: cx(24),
|
|
59
|
+
},
|
|
60
|
+
icon: {
|
|
61
|
+
width: cx(60),
|
|
62
|
+
aspectRatio: 2.14,
|
|
63
|
+
marginRight: cx(10),
|
|
64
|
+
},
|
|
65
|
+
titleContainer: {
|
|
66
|
+
flexDirection: 'row',
|
|
67
|
+
flex: 1,
|
|
68
|
+
paddingRight: cx(5),
|
|
69
|
+
justifyContent: 'flex-start',
|
|
70
|
+
alignItems: 'center',
|
|
71
|
+
}
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
function FlagItem(props: FlagItemProps) {
|
|
75
|
+
const { theme, containerWidth, enable, title, colors, icon: iconProp, style, onPress, onSwitch } = props
|
|
76
|
+
const styles = useMemo(() => getStyles(theme), [theme])
|
|
77
|
+
const icon = typeof iconProp === 'number' ? iconProp : { uri: iconProp }
|
|
78
|
+
|
|
79
|
+
// 2. 引入 state 用于存储内部测量的宽度
|
|
80
|
+
const [selfMeasuredWidth, setSelfMeasuredWidth] = useState(0)
|
|
81
|
+
|
|
82
|
+
// 3. 创建 onLayout 回调,用于自我测量
|
|
83
|
+
const handleLayout = (event: LayoutChangeEvent) => {
|
|
84
|
+
// 如果父组件已经提供了宽度,则忽略内部测量,避免冲突
|
|
85
|
+
if (containerWidth && containerWidth > 0) {
|
|
86
|
+
return
|
|
87
|
+
}
|
|
88
|
+
const { width: cardWidth } = event.nativeEvent.layout
|
|
89
|
+
if (cardWidth > 0 && cardWidth !== selfMeasuredWidth) {
|
|
90
|
+
setSelfMeasuredWidth(cardWidth)
|
|
91
|
+
}
|
|
92
|
+
}
|
|
26
93
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
checkbox: {
|
|
45
|
-
width: cx(45),
|
|
46
|
-
height: cx(45),
|
|
47
|
-
marginTop: cx(-5),
|
|
48
|
-
marginBottom: cx(-10),
|
|
49
|
-
},
|
|
50
|
-
gradientItem: {
|
|
51
|
-
alignItems: 'center',
|
|
52
|
-
},
|
|
53
|
-
})
|
|
94
|
+
// 4. 决定最终使用的宽度
|
|
95
|
+
const finalLineWidth = useMemo(() => {
|
|
96
|
+
// 优先使用父组件传入的宽度(适用于 FlatList)
|
|
97
|
+
if (containerWidth && containerWidth > 0) {
|
|
98
|
+
// 这里的计算需要注意:父组件传来的 containerWidth 是整个屏幕的宽度
|
|
99
|
+
// 所以需要减去 Card 的外边距
|
|
100
|
+
const cardOuterMargin = cx(24)
|
|
101
|
+
return containerWidth - (cardOuterMargin * 2) - (CONTENT_HORIZONTAL_MARGIN * 2)
|
|
102
|
+
}
|
|
103
|
+
// 其次使用自我测量的宽度(适用于普通 View)
|
|
104
|
+
if (selfMeasuredWidth > 0) {
|
|
105
|
+
// selfMeasuredWidth 是 Card 的宽度,所以只需减去内容的内边距
|
|
106
|
+
return selfMeasuredWidth - (CONTENT_HORIZONTAL_MARGIN * 2)
|
|
107
|
+
}
|
|
108
|
+
// 如果都没有,则返回 0
|
|
109
|
+
return 0
|
|
110
|
+
}, [containerWidth, selfMeasuredWidth])
|
|
54
111
|
|
|
55
112
|
return (
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
<Spacer height={cx(16)} />
|
|
113
|
+
// 5. 将 onLayout 绑定到 Card 上,让组件能自我测量
|
|
114
|
+
<Card style={[styles.card, style]} onPress={onPress} onLayout={handleLayout}>
|
|
115
|
+
<View accessibilityLabel={'FlagItem'} accessibilityHint={`${title}`}>
|
|
116
|
+
<Spacer height={cx(8)}/>
|
|
61
117
|
<View style={styles.headline}>
|
|
62
|
-
<View style={
|
|
63
|
-
{
|
|
64
|
-
{
|
|
118
|
+
<View style={styles.titleContainer}>
|
|
119
|
+
{title ? <Text style={styles.headText}>{title}</Text> : null}
|
|
120
|
+
{iconProp ? <Image source={icon} style={styles.icon}/> : null}
|
|
65
121
|
</View>
|
|
66
|
-
<TouchableOpacity style={styles.checkbox} onPress={() =>
|
|
67
|
-
<Image
|
|
122
|
+
<TouchableOpacity style={styles.checkbox} onPress={() => onSwitch(!enable)}>
|
|
123
|
+
<Image
|
|
124
|
+
source={{ uri: res.ic_check }}
|
|
125
|
+
style={[styles.checkboxImage, { tintColor: enable ? theme?.icon.primary : theme?.icon.disable }]}
|
|
126
|
+
/>
|
|
68
127
|
</TouchableOpacity>
|
|
69
128
|
</View>
|
|
70
|
-
<Spacer
|
|
71
|
-
<View style={styles.
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
129
|
+
<Spacer/>
|
|
130
|
+
<View style={styles.lineContainer}>
|
|
131
|
+
{/* 6. 使用最终计算出的宽度进行渲染 */}
|
|
132
|
+
{finalLineWidth > 0 && (
|
|
133
|
+
<MoodColorsLine
|
|
134
|
+
type={'separate'}
|
|
135
|
+
width={finalLineWidth}
|
|
136
|
+
nodeStyle={{ borderColor: theme?.card.border, borderWidth: 1 }}
|
|
137
|
+
colors={colors}
|
|
138
|
+
/>
|
|
139
|
+
)}
|
|
76
140
|
</View>
|
|
77
|
-
<Spacer height={cx(16)}
|
|
141
|
+
<Spacer height={cx(16)}/>
|
|
78
142
|
</View>
|
|
79
143
|
</Card>
|
|
80
144
|
)
|