react-native-live-widgets 1.2.1 → 1.2.2
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/CHANGELOG.md +27 -0
- package/README.md +89 -49
- package/android/src/main/AndroidManifest.xml +12 -0
- package/android/src/main/assets/fonts/MaterialIcons-Regular.ttf +0 -0
- package/android/src/main/java/com/reactnativeliveactivity/bridge/LiveActivityModule.kt +61 -1
- package/android/src/main/java/com/reactnativeliveactivity/liveactivity/LiveActivityNotifier.kt +153 -17
- package/android/src/main/java/com/reactnativeliveactivity/liveactivity/LiveActivityReceiver.kt +1 -1
- package/android/src/main/java/com/reactnativeliveactivity/renderer/DynamicWidgetCanvasRenderer.kt +86 -13
- package/android/src/main/java/com/reactnativeliveactivity/storage/DynamicWidgetImageCache.kt +53 -0
- package/android/src/main/java/com/reactnativeliveactivity/storage/DynamicWidgetStateStore.kt +647 -104
- package/android/src/main/java/com/reactnativeliveactivity/widgets/DynamicHomeScreenWidgetProvider.kt +3 -1
- package/android/src/main/java/com/reactnativeliveactivity/widgets/DynamicQuickSettingsTileService.kt +120 -0
- package/app.plugin.js +36 -0
- package/assets/MaterialIcons.json +2236 -0
- package/cli/codegen.js +789 -0
- package/cli/setup.js +323 -63
- package/docs/EXPO-GUIDE-EN.md +21 -3
- package/docs/EXPO-GUIDE-VI.md +21 -3
- package/docs/GUIDE-EN.md +203 -21
- package/docs/GUIDE-VI.md +207 -22
- package/docs/index.html +1328 -211
- package/docs/llms-full.txt +15 -0
- package/docs/llms.txt +16 -7
- package/ios/Bridge/LiveActivityModule.swift +333 -44
- package/ios/Intents/DynamicWidgetActionIntent.swift +57 -2
- package/ios/Models/DynamicLayoutModels.swift +114 -4
- package/ios/Renderer/DynamicNodeView.swift +15 -6
- package/ios/Storage/DynamicWidgetStateStore.swift +649 -38
- package/ios/Widgets/DynamicControlWidget.swift +63 -0
- package/ios/Widgets/DynamicHomeScreenWidget.swift +99 -26
- package/ios/Widgets/DynamicLiveActivityWidget.swift +25 -4
- package/lib/builder.d.ts +50 -7
- package/lib/builder.d.ts.map +1 -1
- package/lib/builder.js +326 -18
- package/lib/builder.js.map +1 -1
- package/lib/hooks.d.ts +13 -9
- package/lib/hooks.d.ts.map +1 -1
- package/lib/hooks.js +70 -12
- package/lib/hooks.js.map +1 -1
- package/lib/index.d.ts +80 -7
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +303 -59
- package/lib/index.js.map +1 -1
- package/lib/ir.d.ts.map +1 -1
- package/lib/ir.js +9 -2
- package/lib/ir.js.map +1 -1
- package/lib/jsx.d.ts +11 -7
- package/lib/jsx.d.ts.map +1 -1
- package/lib/jsx.js +50 -13
- package/lib/jsx.js.map +1 -1
- package/lib/material-icons.generated.d.ts +8 -0
- package/lib/material-icons.generated.d.ts.map +1 -0
- package/lib/material-icons.generated.js +9 -0
- package/lib/material-icons.generated.js.map +1 -0
- package/lib/preview.d.ts +11 -4
- package/lib/preview.d.ts.map +1 -1
- package/lib/preview.js +150 -82
- package/lib/preview.js.map +1 -1
- package/lib/sf-symbols.generated.d.ts +8 -0
- package/lib/sf-symbols.generated.d.ts.map +1 -0
- package/lib/sf-symbols.generated.js +9 -0
- package/lib/sf-symbols.generated.js.map +1 -0
- package/lib/types.d.ts +302 -18
- package/lib/types.d.ts.map +1 -1
- package/package.json +6 -2
- package/scripts/build.js +98 -0
- package/scripts/generate-material-icons.js +93 -0
- package/scripts/generate-sf-symbols.js +95 -0
- package/scripts/release.js +115 -0
- package/scripts/test-ir-semantic.js +314 -0
- package/src/builder.ts +382 -24
- package/src/hooks.ts +88 -12
- package/src/index.ts +319 -56
- package/src/ir.ts +8 -2
- package/src/jsx.tsx +69 -21
- package/src/material-icons.generated.ts +3844 -0
- package/src/preview.tsx +235 -81
- package/src/sf-symbols.generated.ts +9533 -0
- package/src/types.ts +348 -18
package/src/preview.tsx
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
TextStyle as RNTextStyle,
|
|
10
10
|
} from 'react-native';
|
|
11
11
|
import {
|
|
12
|
+
ControlWidgetConfig,
|
|
12
13
|
LayoutNode,
|
|
13
14
|
WidgetSinglePageConfig,
|
|
14
15
|
VStackNode,
|
|
@@ -22,8 +23,17 @@ import {
|
|
|
22
23
|
} from './types';
|
|
23
24
|
import { renderToWidget, extractPropsAndStyle } from './jsx';
|
|
24
25
|
import { actionHandlers, globalActionHandlers } from './dispatcher';
|
|
26
|
+
import { flattenDataObject, resolveTemplateString } from './builder';
|
|
25
27
|
|
|
26
|
-
export type WidgetPreviewSize =
|
|
28
|
+
export type WidgetPreviewSize =
|
|
29
|
+
| 'small'
|
|
30
|
+
| 'medium'
|
|
31
|
+
| 'large'
|
|
32
|
+
| 'extraLarge'
|
|
33
|
+
| 'standBy'
|
|
34
|
+
| 'lockScreen'
|
|
35
|
+
| 'dynamicIsland'
|
|
36
|
+
| 'control';
|
|
27
37
|
|
|
28
38
|
export interface WidgetPreviewProps {
|
|
29
39
|
/**
|
|
@@ -31,13 +41,20 @@ export interface WidgetPreviewProps {
|
|
|
31
41
|
* - 'small' (158 × 158 dp)
|
|
32
42
|
* - 'medium' (338 × 158 dp)
|
|
33
43
|
* - 'large' (338 × 354 dp)
|
|
44
|
+
* - 'extraLarge' (338 × 420 dp)
|
|
45
|
+
* - 'standBy' (310 × 158 dp)
|
|
34
46
|
* - 'lockScreen' (350 × 80 dp)
|
|
35
47
|
* - 'dynamicIsland' (350 × 160 dp)
|
|
36
|
-
*
|
|
48
|
+
* - 'control' (170 × 76 dp — iOS 18 Control Center / Android Quick Settings Tile)
|
|
49
|
+
* Mặc định là 'medium' (hoặc 'control' nếu truyền controlConfig).
|
|
37
50
|
*/
|
|
38
51
|
size?: WidgetPreviewSize;
|
|
39
|
-
/** Cây LayoutNode hoặc đối tượng chứa { small, medium, large } */
|
|
52
|
+
/** Cây LayoutNode hoặc đối tượng chứa { small, medium, large, extraLarge, standBy } */
|
|
40
53
|
layout?: LayoutNode | WidgetSinglePageConfig;
|
|
54
|
+
/** Dữ liệu JSON mẫu dùng để nội suy các biểu thức Data Binding (`{{user.name}}`, `data.*`) khi xem trước */
|
|
55
|
+
data?: Record<string, any>;
|
|
56
|
+
/** Cấu hình Control Widget dùng để xem trước Control Center / Quick Settings Tile */
|
|
57
|
+
controlConfig?: ControlWidgetConfig;
|
|
41
58
|
/** Cú pháp JSX trực tiếp truyền vào bên trong thẻ `<WidgetPreview>` */
|
|
42
59
|
children?: React.ReactNode;
|
|
43
60
|
/** Bắt sự kiện khi người dùng bấm vào các nút tương tác trên Widget xem trước */
|
|
@@ -54,8 +71,11 @@ const SIZE_DIMENSIONS: Record<WidgetPreviewSize, { width: number; height: number
|
|
|
54
71
|
small: { width: 158, height: 158, label: 'Small • 158×158' },
|
|
55
72
|
medium: { width: 338, height: 158, label: 'Medium • 338×158' },
|
|
56
73
|
large: { width: 338, height: 354, label: 'Large • 338×354' },
|
|
74
|
+
extraLarge: { width: 338, height: 420, label: 'Extra Large • 338×420' },
|
|
75
|
+
standBy: { width: 310, height: 158, label: 'StandBy • 310×158' },
|
|
57
76
|
lockScreen: { width: 350, height: 80, label: 'Lock Screen • 350×80' },
|
|
58
77
|
dynamicIsland: { width: 350, height: 160, label: 'Dynamic Island' },
|
|
78
|
+
control: { width: 170, height: 76, label: 'Control • iOS 18 / QS Tile' },
|
|
59
79
|
};
|
|
60
80
|
|
|
61
81
|
function parseDynamicColor(c: any, mode: 'light' | 'dark' | 'tinted' = 'dark'): string | undefined {
|
|
@@ -115,14 +135,17 @@ type PreviewSyncVars = {
|
|
|
115
135
|
};
|
|
116
136
|
|
|
117
137
|
export const WidgetPreview: React.FC<WidgetPreviewProps> = ({
|
|
118
|
-
size:
|
|
138
|
+
size: initialSizeProp,
|
|
119
139
|
layout,
|
|
140
|
+
data,
|
|
141
|
+
controlConfig,
|
|
120
142
|
children,
|
|
121
143
|
onAction,
|
|
122
144
|
showBadge = true,
|
|
123
145
|
interactiveSizeSwitch = false,
|
|
124
146
|
style,
|
|
125
147
|
}: WidgetPreviewProps) => {
|
|
148
|
+
const initialSize: WidgetPreviewSize = initialSizeProp ?? (controlConfig ? 'control' : 'medium');
|
|
126
149
|
const [activeSize, setActiveSize] = useState<WidgetPreviewSize>(initialSize);
|
|
127
150
|
|
|
128
151
|
const pageConfigObj =
|
|
@@ -168,24 +191,26 @@ export const WidgetPreview: React.FC<WidgetPreviewProps> = ({
|
|
|
168
191
|
rawTarget = layout;
|
|
169
192
|
} else if ((layout as any).type && typeof (layout as any).type === 'string' && (layout as any).props !== undefined) {
|
|
170
193
|
rawTarget = layout;
|
|
171
|
-
} else if (pageConfigObj && currentPageKey) {
|
|
172
|
-
const pageConfig = pageConfigObj.pages[currentPageKey] || {};
|
|
173
|
-
rawTarget =
|
|
174
|
-
pageConfig[activeSize] ||
|
|
175
|
-
pageConfig.medium ||
|
|
176
|
-
pageConfig.large ||
|
|
177
|
-
pageConfig.small ||
|
|
178
|
-
pageConfig.accessoryRectangular ||
|
|
179
|
-
null;
|
|
180
194
|
} else {
|
|
181
|
-
const pageConfig =
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
195
|
+
const pageConfig =
|
|
196
|
+
pageConfigObj && currentPageKey
|
|
197
|
+
? pageConfigObj.pages[currentPageKey] || {}
|
|
198
|
+
: (layout as any);
|
|
199
|
+
const primary = pageConfig?.[activeSize];
|
|
200
|
+
if (primary) {
|
|
201
|
+
rawTarget = primary;
|
|
202
|
+
} else if (activeSize === 'extraLarge') {
|
|
203
|
+
rawTarget = pageConfig?.large || pageConfig?.medium || pageConfig?.small || null;
|
|
204
|
+
} else if (activeSize === 'standBy') {
|
|
205
|
+
rawTarget = pageConfig?.small || pageConfig?.medium || pageConfig?.large || null;
|
|
206
|
+
} else {
|
|
207
|
+
rawTarget =
|
|
208
|
+
pageConfig?.medium ||
|
|
209
|
+
pageConfig?.large ||
|
|
210
|
+
pageConfig?.small ||
|
|
211
|
+
pageConfig?.accessoryRectangular ||
|
|
212
|
+
null;
|
|
213
|
+
}
|
|
189
214
|
}
|
|
190
215
|
}
|
|
191
216
|
|
|
@@ -235,18 +260,50 @@ export const WidgetPreview: React.FC<WidgetPreviewProps> = ({
|
|
|
235
260
|
const dim =
|
|
236
261
|
SIZE_DIMENSIONS[(activeSize as WidgetPreviewSize) || 'medium'] || SIZE_DIMENSIONS.medium;
|
|
237
262
|
|
|
263
|
+
const anyLayout = layout as any;
|
|
264
|
+
const effectiveControlConfig: ControlWidgetConfig | null =
|
|
265
|
+
controlConfig ||
|
|
266
|
+
(anyLayout?.control as ControlWidgetConfig) ||
|
|
267
|
+
(activeSize === 'control' && anyLayout && !anyLayout.type && typeof anyLayout.title === 'string' && typeof anyLayout.actionId === 'string'
|
|
268
|
+
? (anyLayout as ControlWidgetConfig)
|
|
269
|
+
: null);
|
|
270
|
+
|
|
271
|
+
const switchSizes: WidgetPreviewSize[] = ['small', 'medium', 'large'];
|
|
272
|
+
if (
|
|
273
|
+
initialSize === 'extraLarge' ||
|
|
274
|
+
anyLayout?.extraLarge ||
|
|
275
|
+
(currentPageKey && pageConfigObj?.pages?.[currentPageKey]?.extraLarge)
|
|
276
|
+
) {
|
|
277
|
+
switchSizes.push('extraLarge');
|
|
278
|
+
}
|
|
279
|
+
if (
|
|
280
|
+
initialSize === 'standBy' ||
|
|
281
|
+
anyLayout?.standBy ||
|
|
282
|
+
(currentPageKey && pageConfigObj?.pages?.[currentPageKey]?.standBy)
|
|
283
|
+
) {
|
|
284
|
+
switchSizes.push('standBy');
|
|
285
|
+
}
|
|
286
|
+
if (initialSize === 'control' || effectiveControlConfig) {
|
|
287
|
+
switchSizes.push('control');
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
const effectiveSyncVars: Record<string, string> = {
|
|
291
|
+
...syncVars,
|
|
292
|
+
...(data ? flattenDataObject(data) : {}),
|
|
293
|
+
};
|
|
294
|
+
|
|
238
295
|
return (
|
|
239
296
|
<View style={[styles.container, style]}>
|
|
240
297
|
{interactiveSizeSwitch && (
|
|
241
298
|
<View style={styles.tabBar}>
|
|
242
|
-
{
|
|
299
|
+
{switchSizes.map((s) => (
|
|
243
300
|
<TouchableOpacity
|
|
244
301
|
key={s}
|
|
245
302
|
onPress={() => setActiveSize(s)}
|
|
246
303
|
style={[styles.tabItem, activeSize === s && styles.tabItemActive]}
|
|
247
304
|
>
|
|
248
305
|
<RNText style={[styles.tabText, activeSize === s && styles.tabTextActive]}>
|
|
249
|
-
{s.toUpperCase()}
|
|
306
|
+
{s === 'extraLarge' ? 'XLARGE' : s === 'control' ? 'CONTROL' : s.toUpperCase()}
|
|
250
307
|
</RNText>
|
|
251
308
|
</TouchableOpacity>
|
|
252
309
|
))}
|
|
@@ -271,8 +328,20 @@ export const WidgetPreview: React.FC<WidgetPreviewProps> = ({
|
|
|
271
328
|
},
|
|
272
329
|
]}
|
|
273
330
|
>
|
|
274
|
-
{
|
|
275
|
-
|
|
331
|
+
{activeSize === 'control' ? (
|
|
332
|
+
<PreviewControlTile
|
|
333
|
+
config={
|
|
334
|
+
effectiveControlConfig || {
|
|
335
|
+
type: 'button',
|
|
336
|
+
title: 'Live Control',
|
|
337
|
+
subtitle: 'Nhấn để kích hoạt',
|
|
338
|
+
actionId: 'control_action_main',
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
onAction={handlePreviewAction}
|
|
342
|
+
/>
|
|
343
|
+
) : rootNode ? (
|
|
344
|
+
renderPreviewNode(rootNode, handlePreviewAction, true, 'column', effectiveSyncVars)
|
|
276
345
|
) : (
|
|
277
346
|
<View style={styles.emptyContainer}>
|
|
278
347
|
<RNText style={styles.emptyText}>Chưa có cấu hình layout cho kích thước {activeSize}</RNText>
|
|
@@ -288,6 +357,114 @@ export const VoltraWidgetPreview = WidgetPreview;
|
|
|
288
357
|
|
|
289
358
|
// ─── RECURSIVE NODE RENDERER ─────────────────────────────────────────────────
|
|
290
359
|
|
|
360
|
+
function dispatchPreviewAction(
|
|
361
|
+
actionId: string | undefined,
|
|
362
|
+
onAction?: (actionId: string) => void,
|
|
363
|
+
extraPayload?: Record<string, any>
|
|
364
|
+
) {
|
|
365
|
+
if (!actionId) return;
|
|
366
|
+
if (onAction) {
|
|
367
|
+
onAction(actionId);
|
|
368
|
+
}
|
|
369
|
+
const payload = { actionId, ...extraPayload };
|
|
370
|
+
const registered = actionHandlers.get(actionId);
|
|
371
|
+
if (registered) {
|
|
372
|
+
try {
|
|
373
|
+
registered(payload);
|
|
374
|
+
} catch (e) {
|
|
375
|
+
console.warn(`[WidgetPreview] Action '${actionId}' error:`, e);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
for (const globalHandler of globalActionHandlers) {
|
|
379
|
+
try {
|
|
380
|
+
globalHandler(actionId, extraPayload);
|
|
381
|
+
} catch (e) {
|
|
382
|
+
console.warn(`[WidgetPreview] Global action handler error:`, e);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
const PreviewControlTile: React.FC<{
|
|
388
|
+
config: ControlWidgetConfig;
|
|
389
|
+
onAction?: (actionId: string) => void;
|
|
390
|
+
}> = ({ config, onAction }) => {
|
|
391
|
+
const [isOn, setIsOn] = useState<boolean>(Boolean(config.checked));
|
|
392
|
+
|
|
393
|
+
useEffect(() => {
|
|
394
|
+
setIsOn(Boolean(config.checked));
|
|
395
|
+
}, [config.checked]);
|
|
396
|
+
|
|
397
|
+
const isToggle = config.type === 'toggle' || Boolean(config.actionId?.startsWith('toggle:'));
|
|
398
|
+
const active = isToggle && isOn;
|
|
399
|
+
const tint = config.tintColor || '#2563EB';
|
|
400
|
+
const title = active ? config.checkedTitle || config.title : config.title;
|
|
401
|
+
const subtitle = active
|
|
402
|
+
? config.checkedSubtitle ?? config.subtitle ?? 'Đang bật'
|
|
403
|
+
: config.subtitle ?? (isToggle ? 'Tạm tắt' : config.systemName || 'Control');
|
|
404
|
+
|
|
405
|
+
return (
|
|
406
|
+
<TouchableOpacity
|
|
407
|
+
accessible
|
|
408
|
+
accessibilityRole={isToggle ? 'switch' : 'button'}
|
|
409
|
+
accessibilityLabel={title}
|
|
410
|
+
accessibilityValue={isToggle ? { text: active ? 'Bật' : 'Tắt' } : undefined}
|
|
411
|
+
activeOpacity={0.75}
|
|
412
|
+
onPress={() => {
|
|
413
|
+
const nextVal = isToggle ? !isOn : undefined;
|
|
414
|
+
if (isToggle) {
|
|
415
|
+
setIsOn(Boolean(nextVal));
|
|
416
|
+
}
|
|
417
|
+
dispatchPreviewAction(
|
|
418
|
+
config.actionId,
|
|
419
|
+
onAction,
|
|
420
|
+
isToggle ? { isChecked: nextVal } : undefined
|
|
421
|
+
);
|
|
422
|
+
}}
|
|
423
|
+
style={{
|
|
424
|
+
width: '100%',
|
|
425
|
+
height: '100%',
|
|
426
|
+
flexDirection: 'row',
|
|
427
|
+
alignItems: 'center',
|
|
428
|
+
paddingHorizontal: 12,
|
|
429
|
+
gap: 10,
|
|
430
|
+
backgroundColor: active ? '#1E293B' : '#0F172A',
|
|
431
|
+
borderWidth: active ? 1.5 : 1,
|
|
432
|
+
borderColor: active ? tint : 'rgba(148, 163, 184, 0.2)',
|
|
433
|
+
borderRadius: 20,
|
|
434
|
+
}}
|
|
435
|
+
>
|
|
436
|
+
<View
|
|
437
|
+
style={{
|
|
438
|
+
width: 34,
|
|
439
|
+
height: 34,
|
|
440
|
+
borderRadius: 17,
|
|
441
|
+
backgroundColor: active ? tint : 'rgba(255, 255, 255, 0.1)',
|
|
442
|
+
alignItems: 'center',
|
|
443
|
+
justifyContent: 'center',
|
|
444
|
+
}}
|
|
445
|
+
>
|
|
446
|
+
<RNText style={{ color: '#FFFFFF', fontSize: 14, fontWeight: 'bold' }}>
|
|
447
|
+
{active ? '✓' : '⚡'}
|
|
448
|
+
</RNText>
|
|
449
|
+
</View>
|
|
450
|
+
<View style={{ flex: 1 }}>
|
|
451
|
+
<RNText
|
|
452
|
+
numberOfLines={1}
|
|
453
|
+
style={{ color: '#F8FAFC', fontSize: 12, fontWeight: '700' }}
|
|
454
|
+
>
|
|
455
|
+
{title}
|
|
456
|
+
</RNText>
|
|
457
|
+
<RNText
|
|
458
|
+
numberOfLines={1}
|
|
459
|
+
style={{ color: active ? '#93C5FD' : '#94A3B8', fontSize: 10, marginTop: 1 }}
|
|
460
|
+
>
|
|
461
|
+
{subtitle}
|
|
462
|
+
</RNText>
|
|
463
|
+
</View>
|
|
464
|
+
</TouchableOpacity>
|
|
465
|
+
);
|
|
466
|
+
};
|
|
467
|
+
|
|
291
468
|
const PreviewToggleItem: React.FC<{
|
|
292
469
|
node: any;
|
|
293
470
|
onAction?: (actionId: string) => void;
|
|
@@ -300,26 +477,7 @@ const PreviewToggleItem: React.FC<{
|
|
|
300
477
|
const handlePress = () => {
|
|
301
478
|
const nextVal = !isChecked;
|
|
302
479
|
setIsChecked(nextVal);
|
|
303
|
-
|
|
304
|
-
if (onAction) {
|
|
305
|
-
onAction(p.actionId);
|
|
306
|
-
}
|
|
307
|
-
const registered = actionHandlers.get(p.actionId);
|
|
308
|
-
if (registered) {
|
|
309
|
-
try {
|
|
310
|
-
registered({ actionId: p.actionId, isChecked: nextVal });
|
|
311
|
-
} catch (e) {
|
|
312
|
-
console.warn(`[WidgetPreview] Action '${p.actionId}' error:`, e);
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
for (const globalHandler of globalActionHandlers) {
|
|
316
|
-
try {
|
|
317
|
-
globalHandler(p.actionId, { isChecked: nextVal });
|
|
318
|
-
} catch (e) {
|
|
319
|
-
console.warn(`[WidgetPreview] Global action handler error:`, e);
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
}
|
|
480
|
+
dispatchPreviewAction(p.actionId, onAction, { isChecked: nextVal });
|
|
323
481
|
};
|
|
324
482
|
|
|
325
483
|
return (
|
|
@@ -435,12 +593,31 @@ const PreviewTimerText: React.FC<{
|
|
|
435
593
|
);
|
|
436
594
|
};
|
|
437
595
|
|
|
596
|
+
function resolvePreviewText(raw: any, syncVars?: Record<string, string>): string {
|
|
597
|
+
const str = String(raw ?? '');
|
|
598
|
+
return syncVars ? resolveTemplateString(str, syncVars) : str;
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
function resolvePreviewNumber(
|
|
602
|
+
raw: any,
|
|
603
|
+
fallback: number,
|
|
604
|
+
syncVars?: Record<string, string>
|
|
605
|
+
): number {
|
|
606
|
+
if (typeof raw === 'number' && !Number.isNaN(raw)) return raw;
|
|
607
|
+
if (typeof raw === 'string') {
|
|
608
|
+
const resolved = syncVars ? resolveTemplateString(raw, syncVars) : raw;
|
|
609
|
+
const num = parseFloat(resolved);
|
|
610
|
+
return Number.isNaN(num) ? fallback : num;
|
|
611
|
+
}
|
|
612
|
+
return fallback;
|
|
613
|
+
}
|
|
614
|
+
|
|
438
615
|
function renderPreviewNode(
|
|
439
616
|
node: any,
|
|
440
617
|
onAction?: (actionId: string) => void,
|
|
441
618
|
isRoot: boolean = false,
|
|
442
619
|
parentDirection: 'row' | 'column' = 'column',
|
|
443
|
-
syncVars?:
|
|
620
|
+
syncVars?: Record<string, string>
|
|
444
621
|
): React.ReactNode {
|
|
445
622
|
if (!node) return null;
|
|
446
623
|
|
|
@@ -636,13 +813,7 @@ function renderPreviewNode(
|
|
|
636
813
|
const isRtl = p.direction === 'rtl' || p.isRTL;
|
|
637
814
|
const shadowColor = parseDynamicColor(p.shadowColor);
|
|
638
815
|
|
|
639
|
-
const
|
|
640
|
-
const resolvedText = syncVars
|
|
641
|
-
? rawText
|
|
642
|
-
.replace(/\{\{_lastSyncTime\}\}/g, syncVars._lastSyncTime)
|
|
643
|
-
.replace(/\{\{id\}\}/g, syncVars.id)
|
|
644
|
-
.replace(/\{\{title\}\}/g, syncVars.title)
|
|
645
|
-
: rawText;
|
|
816
|
+
const resolvedText = resolvePreviewText(p.text, syncVars);
|
|
646
817
|
const isRedacted = Boolean(p.redacted);
|
|
647
818
|
|
|
648
819
|
const textStyle: RNTextStyle = {
|
|
@@ -712,39 +883,20 @@ function renderPreviewNode(
|
|
|
712
883
|
fontFamily: p.fontDesign === 'monospaced' ? 'monospace' : undefined,
|
|
713
884
|
};
|
|
714
885
|
|
|
886
|
+
const btnTitle = resolvePreviewText(p.title, syncVars);
|
|
887
|
+
|
|
715
888
|
return (
|
|
716
889
|
<TouchableOpacity
|
|
717
890
|
accessible={p.accessible !== false}
|
|
718
|
-
accessibilityLabel={p.accessibilityLabel ||
|
|
891
|
+
accessibilityLabel={p.accessibilityLabel || btnTitle}
|
|
719
892
|
accessibilityHint={p.accessibilityHint}
|
|
720
893
|
accessibilityRole="button"
|
|
721
894
|
activeOpacity={0.7}
|
|
722
|
-
onPress={() =>
|
|
723
|
-
if (p.actionId) {
|
|
724
|
-
if (onAction) {
|
|
725
|
-
onAction(p.actionId);
|
|
726
|
-
}
|
|
727
|
-
const registered = actionHandlers.get(p.actionId);
|
|
728
|
-
if (registered) {
|
|
729
|
-
try {
|
|
730
|
-
registered({ actionId: p.actionId });
|
|
731
|
-
} catch (e) {
|
|
732
|
-
console.warn(`[WidgetPreview] Action '${p.actionId}' error:`, e);
|
|
733
|
-
}
|
|
734
|
-
}
|
|
735
|
-
for (const globalHandler of globalActionHandlers) {
|
|
736
|
-
try {
|
|
737
|
-
globalHandler(p.actionId);
|
|
738
|
-
} catch (e) {
|
|
739
|
-
console.warn(`[WidgetPreview] Global action handler error:`, e);
|
|
740
|
-
}
|
|
741
|
-
}
|
|
742
|
-
}
|
|
743
|
-
}}
|
|
895
|
+
onPress={() => dispatchPreviewAction(p.actionId, onAction)}
|
|
744
896
|
style={btnStyle}
|
|
745
897
|
>
|
|
746
898
|
<RNText numberOfLines={1} style={textStyle}>
|
|
747
|
-
{
|
|
899
|
+
{btnTitle}
|
|
748
900
|
</RNText>
|
|
749
901
|
</TouchableOpacity>
|
|
750
902
|
);
|
|
@@ -772,7 +924,7 @@ function renderPreviewNode(
|
|
|
772
924
|
fontWeight: '600',
|
|
773
925
|
}}
|
|
774
926
|
>
|
|
775
|
-
{p.text}
|
|
927
|
+
{resolvePreviewText(p.text, syncVars)}
|
|
776
928
|
</RNText>
|
|
777
929
|
</View>
|
|
778
930
|
);
|
|
@@ -781,7 +933,7 @@ function renderPreviewNode(
|
|
|
781
933
|
case 'Progress': {
|
|
782
934
|
const pnode = node as ProgressNode;
|
|
783
935
|
const p = pnode.props || {};
|
|
784
|
-
const val = Math.max(0, Math.min(1, p.value
|
|
936
|
+
const val = Math.max(0, Math.min(1, resolvePreviewNumber(p.value, 0.5, syncVars)));
|
|
785
937
|
const height = p.height ?? 6;
|
|
786
938
|
const tint = parseDynamicColor(p.tintColor) || '#2563EB';
|
|
787
939
|
const track = parseDynamicColor(p.trackColor) || '#334155';
|
|
@@ -926,11 +1078,13 @@ function renderPreviewNode(
|
|
|
926
1078
|
case 'Gauge': {
|
|
927
1079
|
const gnode = node as any;
|
|
928
1080
|
const p = gnode.props || {};
|
|
929
|
-
const val = Math.round((p.value
|
|
1081
|
+
const val = Math.round(resolvePreviewNumber(p.value, 0.75, syncVars) * 100);
|
|
930
1082
|
const tint = parseDynamicColor(p.tintColor) || '#10B981';
|
|
931
1083
|
return (
|
|
932
1084
|
<View style={{ alignItems: 'center', justifyContent: 'center' }}>
|
|
933
|
-
<RNText style={{ color: tint, fontSize: 13, fontWeight: 'bold' }}>
|
|
1085
|
+
<RNText style={{ color: tint, fontSize: 13, fontWeight: 'bold' }}>
|
|
1086
|
+
{p.valueText ? resolvePreviewText(p.valueText, syncVars) : `${val}%`}
|
|
1087
|
+
</RNText>
|
|
934
1088
|
</View>
|
|
935
1089
|
);
|
|
936
1090
|
}
|