react-native-live-widgets 1.2.0 → 1.2.1
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 +7 -0
- package/README.md +40 -1
- package/android/src/main/java/com/reactnativeliveactivity/renderer/DynamicWidgetCanvasRenderer.kt +443 -46
- package/android/src/main/java/com/reactnativeliveactivity/storage/DynamicWidgetStateStore.kt +86 -28
- package/android/src/main/java/com/reactnativeliveactivity/widgets/DynamicHomeScreenWidgetProvider.kt +126 -56
- package/android/src/main/res/layout/rn_live_widget_hit_zone.xml +16 -0
- package/android/src/main/res/layout/rn_live_widget_host.xml +16 -87
- package/docs/GUIDE-EN.md +241 -0
- package/docs/GUIDE-VI.md +266 -0
- package/docs/index.html +1140 -259
- package/docs/llms-full.txt +26 -0
- package/docs/llms.txt +8 -0
- package/ios/Models/DynamicLayoutModels.swift +6 -1
- package/ios/Renderer/DynamicNodeView.swift +169 -14
- package/ios/Widgets/DynamicHomeScreenWidget.swift +5 -0
- package/lib/builder.d.ts.map +1 -1
- package/lib/builder.js +65 -11
- package/lib/builder.js.map +1 -1
- package/lib/dispatcher.js +16 -10
- package/lib/dispatcher.js.map +1 -1
- package/lib/hooks.js +36 -31
- package/lib/hooks.js.map +1 -1
- package/lib/index.d.ts +17 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +124 -50
- package/lib/index.js.map +1 -1
- package/lib/ir.d.ts +15 -0
- package/lib/ir.d.ts.map +1 -0
- package/lib/ir.js +379 -0
- package/lib/ir.js.map +1 -0
- package/lib/jsx.d.ts +9 -1
- package/lib/jsx.d.ts.map +1 -1
- package/lib/jsx.js +131 -84
- package/lib/jsx.js.map +1 -1
- package/lib/preview.d.ts +0 -23
- package/lib/preview.d.ts.map +1 -1
- package/lib/preview.js +373 -104
- package/lib/preview.js.map +1 -1
- package/lib/types.d.ts +204 -12
- package/lib/types.d.ts.map +1 -1
- package/lib/types.js +2 -1
- package/lib/types.js.map +1 -1
- package/package.json +2 -1
- package/src/builder.ts +57 -2
- package/src/index.ts +66 -1
- package/src/ir.ts +430 -0
- package/src/jsx.tsx +30 -0
- package/src/preview.tsx +356 -32
- package/src/react-native-env.d.ts +1 -0
- package/src/types.ts +253 -13
package/src/preview.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useState } from 'react';
|
|
1
|
+
import React, { useEffect, useState } from 'react';
|
|
2
2
|
import {
|
|
3
3
|
View,
|
|
4
4
|
Text as RNText,
|
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
ImageNode,
|
|
22
22
|
} from './types';
|
|
23
23
|
import { renderToWidget, extractPropsAndStyle } from './jsx';
|
|
24
|
+
import { actionHandlers, globalActionHandlers } from './dispatcher';
|
|
24
25
|
|
|
25
26
|
export type WidgetPreviewSize = 'small' | 'medium' | 'large' | 'lockScreen' | 'dynamicIsland';
|
|
26
27
|
|
|
@@ -57,13 +58,33 @@ const SIZE_DIMENSIONS: Record<WidgetPreviewSize, { width: number; height: number
|
|
|
57
58
|
dynamicIsland: { width: 350, height: 160, label: 'Dynamic Island' },
|
|
58
59
|
};
|
|
59
60
|
|
|
60
|
-
function parseDynamicColor(c: any): string | undefined {
|
|
61
|
+
function parseDynamicColor(c: any, mode: 'light' | 'dark' | 'tinted' = 'dark'): string | undefined {
|
|
61
62
|
if (!c) return undefined;
|
|
62
63
|
if (typeof c === 'string') return c;
|
|
63
|
-
if (typeof c === 'object')
|
|
64
|
+
if (typeof c === 'object') {
|
|
65
|
+
if (mode === 'tinted' && c.tinted) return c.tinted;
|
|
66
|
+
if (mode === 'light' && c.light) return c.light;
|
|
67
|
+
return c.dark || c.light || c.tinted;
|
|
68
|
+
}
|
|
64
69
|
return undefined;
|
|
65
70
|
}
|
|
66
71
|
|
|
72
|
+
function extractShadowStyle(p: any): ViewStyle {
|
|
73
|
+
if (!p) return {};
|
|
74
|
+
const shadowColor = parseDynamicColor(p.shadowColor);
|
|
75
|
+
if (!shadowColor) return {};
|
|
76
|
+
const rad = p.shadowRadius ?? 4;
|
|
77
|
+
return {
|
|
78
|
+
shadowColor,
|
|
79
|
+
shadowOffset: p.shadowOffset
|
|
80
|
+
? { width: p.shadowOffset.x ?? 0, height: p.shadowOffset.y ?? 2 }
|
|
81
|
+
: { width: 0, height: 2 },
|
|
82
|
+
shadowOpacity: p.shadowOpacity ?? 0.35,
|
|
83
|
+
shadowRadius: rad,
|
|
84
|
+
elevation: Math.min(8, Math.max(1, Math.round(rad))),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
67
88
|
/**
|
|
68
89
|
* 📱 Bộ Component xem trước tiện ích trực tiếp trong ứng dụng React Native (In-App Widget Preview).
|
|
69
90
|
* Cho phép lập trình viên và người dùng trải nghiệm giao diện & bấm thử tương tác của Widget
|
|
@@ -87,6 +108,12 @@ function parseDynamicColor(c: any): string | undefined {
|
|
|
87
108
|
* </WidgetPreview>
|
|
88
109
|
* ```
|
|
89
110
|
*/
|
|
111
|
+
type PreviewSyncVars = {
|
|
112
|
+
_lastSyncTime: string;
|
|
113
|
+
id: string;
|
|
114
|
+
title: string;
|
|
115
|
+
};
|
|
116
|
+
|
|
90
117
|
export const WidgetPreview: React.FC<WidgetPreviewProps> = ({
|
|
91
118
|
size: initialSize = 'medium',
|
|
92
119
|
layout,
|
|
@@ -98,9 +125,41 @@ export const WidgetPreview: React.FC<WidgetPreviewProps> = ({
|
|
|
98
125
|
}: WidgetPreviewProps) => {
|
|
99
126
|
const [activeSize, setActiveSize] = useState<WidgetPreviewSize>(initialSize);
|
|
100
127
|
|
|
128
|
+
const pageConfigObj =
|
|
129
|
+
!children && layout && typeof layout === 'object' && (layout as any).pages
|
|
130
|
+
? (layout as any)
|
|
131
|
+
: null;
|
|
132
|
+
const pageOrder: string[] = pageConfigObj
|
|
133
|
+
? Array.isArray(pageConfigObj.pageOrder) && pageConfigObj.pageOrder.length > 0
|
|
134
|
+
? pageConfigObj.pageOrder
|
|
135
|
+
: Object.keys(pageConfigObj.pages)
|
|
136
|
+
: [];
|
|
137
|
+
const defaultPage: string = pageConfigObj
|
|
138
|
+
? pageConfigObj.initialPage || pageOrder[0] || ''
|
|
139
|
+
: '';
|
|
140
|
+
|
|
141
|
+
const [activePage, setActivePage] = useState<string>(defaultPage);
|
|
142
|
+
const [syncVars, setSyncVars] = useState<PreviewSyncVars>(() => ({
|
|
143
|
+
_lastSyncTime: new Date().toLocaleTimeString('en-GB', { hour12: false }),
|
|
144
|
+
id: '2026',
|
|
145
|
+
title: 'Hoàn thành kế hoạch quý 4',
|
|
146
|
+
}));
|
|
147
|
+
|
|
148
|
+
useEffect(() => {
|
|
149
|
+
if (defaultPage) {
|
|
150
|
+
setActivePage((prev) => (pageConfigObj?.pages?.[prev] ? prev : defaultPage));
|
|
151
|
+
}
|
|
152
|
+
}, [defaultPage, pageConfigObj]);
|
|
153
|
+
|
|
101
154
|
// Trích xuất LayoutNode từ props hoặc JSX children
|
|
102
155
|
let rootNode: LayoutNode | null = null;
|
|
103
156
|
let rawTarget: any = null;
|
|
157
|
+
const currentPageKey =
|
|
158
|
+
pageConfigObj && pageConfigObj.pages
|
|
159
|
+
? pageConfigObj.pages[activePage]
|
|
160
|
+
? activePage
|
|
161
|
+
: defaultPage
|
|
162
|
+
: '';
|
|
104
163
|
|
|
105
164
|
if (children) {
|
|
106
165
|
rawTarget = children;
|
|
@@ -109,6 +168,15 @@ export const WidgetPreview: React.FC<WidgetPreviewProps> = ({
|
|
|
109
168
|
rawTarget = layout;
|
|
110
169
|
} else if ((layout as any).type && typeof (layout as any).type === 'string' && (layout as any).props !== undefined) {
|
|
111
170
|
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;
|
|
112
180
|
} else {
|
|
113
181
|
const pageConfig = layout as WidgetSinglePageConfig;
|
|
114
182
|
rawTarget =
|
|
@@ -121,6 +189,41 @@ export const WidgetPreview: React.FC<WidgetPreviewProps> = ({
|
|
|
121
189
|
}
|
|
122
190
|
}
|
|
123
191
|
|
|
192
|
+
const handlePreviewAction = (actionId: string) => {
|
|
193
|
+
if (actionId.startsWith('page:') && pageConfigObj && pageOrder.length > 0) {
|
|
194
|
+
const target = actionId.slice('page:'.length);
|
|
195
|
+
if (target === 'next') {
|
|
196
|
+
const idx = pageOrder.indexOf(currentPageKey);
|
|
197
|
+
const nextPage = idx >= 0 ? pageOrder[(idx + 1) % pageOrder.length] : pageOrder[0];
|
|
198
|
+
setActivePage(nextPage);
|
|
199
|
+
} else if (target === 'prev') {
|
|
200
|
+
const idx = pageOrder.indexOf(currentPageKey);
|
|
201
|
+
const prevPage =
|
|
202
|
+
idx >= 0 ? pageOrder[(idx - 1 + pageOrder.length) % pageOrder.length] : pageOrder[0];
|
|
203
|
+
setActivePage(prevPage);
|
|
204
|
+
} else if (pageConfigObj.pages[target]) {
|
|
205
|
+
setActivePage(target);
|
|
206
|
+
}
|
|
207
|
+
} else if (actionId === 'refresh' || actionId.startsWith('refresh:')) {
|
|
208
|
+
const nowTime = new Date().toLocaleTimeString('en-GB', { hour12: false });
|
|
209
|
+
const sampleNotes = [
|
|
210
|
+
'Đồng bộ báo cáo tiến độ OKRs',
|
|
211
|
+
'Kiểm tra chấm công ca hành chính',
|
|
212
|
+
'Rà soát task Sprint tuần này',
|
|
213
|
+
'Cập nhật số liệu Realtime API',
|
|
214
|
+
];
|
|
215
|
+
const nextId = String(Math.floor(Math.random() * 90) + 10);
|
|
216
|
+
setSyncVars({
|
|
217
|
+
_lastSyncTime: nowTime,
|
|
218
|
+
id: nextId,
|
|
219
|
+
title: sampleNotes[Number(nextId) % sampleNotes.length],
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
if (onAction) {
|
|
223
|
+
onAction(actionId);
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
|
|
124
227
|
if (rawTarget) {
|
|
125
228
|
if (React.isValidElement(rawTarget) || (rawTarget as any)?.$$typeof || typeof (rawTarget as any)?.type === 'function') {
|
|
126
229
|
rootNode = renderToWidget(rawTarget);
|
|
@@ -169,7 +272,7 @@ export const WidgetPreview: React.FC<WidgetPreviewProps> = ({
|
|
|
169
272
|
]}
|
|
170
273
|
>
|
|
171
274
|
{rootNode ? (
|
|
172
|
-
renderPreviewNode(rootNode,
|
|
275
|
+
renderPreviewNode(rootNode, handlePreviewAction, true, 'column', syncVars)
|
|
173
276
|
) : (
|
|
174
277
|
<View style={styles.emptyContainer}>
|
|
175
278
|
<RNText style={styles.emptyText}>Chưa có cấu hình layout cho kích thước {activeSize}</RNText>
|
|
@@ -185,38 +288,191 @@ export const VoltraWidgetPreview = WidgetPreview;
|
|
|
185
288
|
|
|
186
289
|
// ─── RECURSIVE NODE RENDERER ─────────────────────────────────────────────────
|
|
187
290
|
|
|
291
|
+
const PreviewToggleItem: React.FC<{
|
|
292
|
+
node: any;
|
|
293
|
+
onAction?: (actionId: string) => void;
|
|
294
|
+
}> = ({ node, onAction }) => {
|
|
295
|
+
const p = node.props || {};
|
|
296
|
+
const [isChecked, setIsChecked] = useState<boolean>(!!p.checked || !!p.isChecked);
|
|
297
|
+
const tint = parseDynamicColor(p.tintColor) || '#38BDF8';
|
|
298
|
+
const isSwitch = p.style === 'switch';
|
|
299
|
+
|
|
300
|
+
const handlePress = () => {
|
|
301
|
+
const nextVal = !isChecked;
|
|
302
|
+
setIsChecked(nextVal);
|
|
303
|
+
if (p.actionId) {
|
|
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
|
+
}
|
|
323
|
+
};
|
|
324
|
+
|
|
325
|
+
return (
|
|
326
|
+
<TouchableOpacity
|
|
327
|
+
accessible={p.accessible !== false}
|
|
328
|
+
accessibilityLabel={p.accessibilityLabel || p.label}
|
|
329
|
+
accessibilityHint={p.accessibilityHint}
|
|
330
|
+
accessibilityRole="switch"
|
|
331
|
+
accessibilityValue={{ text: isChecked ? 'Đã chọn' : 'Chưa chọn' }}
|
|
332
|
+
activeOpacity={0.7}
|
|
333
|
+
onPress={handlePress}
|
|
334
|
+
style={{
|
|
335
|
+
flexDirection: 'row',
|
|
336
|
+
alignItems: 'center',
|
|
337
|
+
gap: 8,
|
|
338
|
+
paddingVertical: 6,
|
|
339
|
+
paddingHorizontal: 2,
|
|
340
|
+
width: '100%',
|
|
341
|
+
alignSelf: 'stretch',
|
|
342
|
+
}}
|
|
343
|
+
>
|
|
344
|
+
{isSwitch ? (
|
|
345
|
+
<View
|
|
346
|
+
style={{
|
|
347
|
+
width: 34,
|
|
348
|
+
height: 20,
|
|
349
|
+
borderRadius: 10,
|
|
350
|
+
backgroundColor: isChecked ? tint : '#475569',
|
|
351
|
+
justifyContent: 'center',
|
|
352
|
+
paddingHorizontal: 3,
|
|
353
|
+
}}
|
|
354
|
+
>
|
|
355
|
+
<View
|
|
356
|
+
style={{
|
|
357
|
+
width: 14,
|
|
358
|
+
height: 14,
|
|
359
|
+
borderRadius: 7,
|
|
360
|
+
backgroundColor: '#FFFFFF',
|
|
361
|
+
alignSelf: isChecked ? 'flex-end' : 'flex-start',
|
|
362
|
+
}}
|
|
363
|
+
/>
|
|
364
|
+
</View>
|
|
365
|
+
) : (
|
|
366
|
+
<View
|
|
367
|
+
style={{
|
|
368
|
+
width: 18,
|
|
369
|
+
height: 18,
|
|
370
|
+
borderRadius: 4,
|
|
371
|
+
borderWidth: 1.5,
|
|
372
|
+
borderColor: isChecked ? tint : '#64748B',
|
|
373
|
+
backgroundColor: isChecked ? tint : 'transparent',
|
|
374
|
+
alignItems: 'center',
|
|
375
|
+
justifyContent: 'center',
|
|
376
|
+
}}
|
|
377
|
+
>
|
|
378
|
+
{isChecked && (
|
|
379
|
+
<RNText style={{ color: '#FFFFFF', fontSize: 11, fontWeight: 'bold' }}>✓</RNText>
|
|
380
|
+
)}
|
|
381
|
+
</View>
|
|
382
|
+
)}
|
|
383
|
+
<RNText
|
|
384
|
+
style={{
|
|
385
|
+
flex: 1,
|
|
386
|
+
color:
|
|
387
|
+
isChecked && p.strikethroughOnCheck
|
|
388
|
+
? '#64748B'
|
|
389
|
+
: parseDynamicColor(p.textColor) || '#F8FAFC',
|
|
390
|
+
fontSize: p.fontSize ?? 13,
|
|
391
|
+
textDecorationLine:
|
|
392
|
+
isChecked && p.strikethroughOnCheck ? 'line-through' : 'none',
|
|
393
|
+
}}
|
|
394
|
+
>
|
|
395
|
+
{p.label}
|
|
396
|
+
</RNText>
|
|
397
|
+
</TouchableOpacity>
|
|
398
|
+
);
|
|
399
|
+
};
|
|
400
|
+
|
|
401
|
+
const PreviewTimerText: React.FC<{
|
|
402
|
+
nodeProps: any;
|
|
403
|
+
parentDirection: 'row' | 'column';
|
|
404
|
+
}> = ({ nodeProps: p, parentDirection }) => {
|
|
405
|
+
const formatRemaining = () => {
|
|
406
|
+
const target = Number(p.targetTimestamp ?? 0);
|
|
407
|
+
if (!target) return '00:00';
|
|
408
|
+
const diff = Math.max(0, Math.round(Math.abs(target - Date.now() / 1000)));
|
|
409
|
+
const hrs = Math.floor(diff / 3600);
|
|
410
|
+
const mins = Math.floor((diff % 3600) / 60);
|
|
411
|
+
const secs = diff % 60;
|
|
412
|
+
const pad = (n: number) => (n < 10 ? `0${n}` : `${n}`);
|
|
413
|
+
return hrs > 0 ? `${hrs}:${pad(mins)}:${pad(secs)}` : `${pad(mins)}:${pad(secs)}`;
|
|
414
|
+
};
|
|
415
|
+
|
|
416
|
+
const [display, setDisplay] = useState<string>(formatRemaining);
|
|
417
|
+
|
|
418
|
+
useEffect(() => {
|
|
419
|
+
setDisplay(formatRemaining());
|
|
420
|
+
const id = setInterval(() => {
|
|
421
|
+
setDisplay(formatRemaining());
|
|
422
|
+
}, 1000);
|
|
423
|
+
return () => clearInterval(id);
|
|
424
|
+
}, [p.targetTimestamp, p.mode]);
|
|
425
|
+
|
|
426
|
+
return (
|
|
427
|
+
<RNText
|
|
428
|
+
style={[
|
|
429
|
+
{ color: parseDynamicColor(p.color) || '#2563EB', fontSize: p.fontSize ?? 14, fontWeight: 'bold' },
|
|
430
|
+
parentDirection === 'row' ? { flexShrink: 0 } : undefined,
|
|
431
|
+
]}
|
|
432
|
+
>
|
|
433
|
+
{p.prefix || ''}{display}{p.suffix || ''}
|
|
434
|
+
</RNText>
|
|
435
|
+
);
|
|
436
|
+
};
|
|
437
|
+
|
|
188
438
|
function renderPreviewNode(
|
|
189
439
|
node: any,
|
|
190
440
|
onAction?: (actionId: string) => void,
|
|
191
441
|
isRoot: boolean = false,
|
|
192
|
-
parentDirection: 'row' | 'column' = 'column'
|
|
442
|
+
parentDirection: 'row' | 'column' = 'column',
|
|
443
|
+
syncVars?: PreviewSyncVars
|
|
193
444
|
): React.ReactNode {
|
|
194
445
|
if (!node) return null;
|
|
195
446
|
|
|
196
447
|
if (React.isValidElement(node) || (node as any)?.$$typeof || typeof (node as any)?.type === 'function') {
|
|
197
448
|
const converted = renderToWidget(node);
|
|
198
449
|
if (!converted) return null;
|
|
199
|
-
return renderPreviewNode(converted, onAction, isRoot, parentDirection);
|
|
450
|
+
return renderPreviewNode(converted, onAction, isRoot, parentDirection, syncVars);
|
|
200
451
|
}
|
|
201
452
|
|
|
202
453
|
switch (node.type) {
|
|
203
454
|
case 'VStack': {
|
|
204
455
|
const vnode = node as VStackNode;
|
|
205
456
|
const p = extractPropsAndStyle(vnode.props);
|
|
457
|
+
const bg = p.gradient?.colors?.[0]
|
|
458
|
+
? parseDynamicColor(p.gradient.colors[0])
|
|
459
|
+
: parseDynamicColor(p.backgroundColor) || 'transparent';
|
|
460
|
+
|
|
206
461
|
const containerStyle: ViewStyle = {
|
|
207
462
|
flexDirection: 'column',
|
|
208
463
|
padding: p.padding ?? (p.paddingHorizontal || p.paddingVertical ? undefined : 0),
|
|
209
464
|
paddingHorizontal: p.paddingHorizontal,
|
|
210
465
|
paddingVertical: p.paddingVertical,
|
|
211
|
-
backgroundColor:
|
|
466
|
+
backgroundColor: bg,
|
|
212
467
|
borderRadius: p.borderRadius ?? p.cornerRadius ?? 0,
|
|
213
468
|
borderWidth: p.borderWidth,
|
|
214
469
|
borderColor: parseDynamicColor(p.borderColor),
|
|
470
|
+
borderStyle: p.borderStyle || 'solid',
|
|
215
471
|
rowGap: p.spacing ?? 0,
|
|
216
472
|
alignItems:
|
|
217
473
|
p.alignment === 'center'
|
|
218
474
|
? 'center'
|
|
219
|
-
: p.alignment === 'trailing'
|
|
475
|
+
: p.alignment === 'trailing' || p.alignment === 'end'
|
|
220
476
|
? 'flex-end'
|
|
221
477
|
: 'flex-start',
|
|
222
478
|
justifyContent:
|
|
@@ -226,9 +482,12 @@ function renderPreviewNode(
|
|
|
226
482
|
? 'space-between'
|
|
227
483
|
: p.justifyContent === 'spaceAround'
|
|
228
484
|
? 'space-around'
|
|
485
|
+
: p.justifyContent === 'spaceEvenly'
|
|
486
|
+
? 'space-evenly'
|
|
229
487
|
: p.justifyContent === 'flexEnd'
|
|
230
488
|
? 'flex-end'
|
|
231
489
|
: 'flex-start',
|
|
490
|
+
...extractShadowStyle(p),
|
|
232
491
|
};
|
|
233
492
|
|
|
234
493
|
if (isRoot) {
|
|
@@ -247,7 +506,7 @@ function renderPreviewNode(
|
|
|
247
506
|
<View style={containerStyle}>
|
|
248
507
|
{vnode.children?.map((child, idx) => (
|
|
249
508
|
<React.Fragment key={idx}>
|
|
250
|
-
{renderPreviewNode(child, onAction, false, 'column')}
|
|
509
|
+
{renderPreviewNode(child, onAction, false, 'column', syncVars)}
|
|
251
510
|
</React.Fragment>
|
|
252
511
|
))}
|
|
253
512
|
</View>
|
|
@@ -257,20 +516,26 @@ function renderPreviewNode(
|
|
|
257
516
|
case 'HStack': {
|
|
258
517
|
const hnode = node as HStackNode;
|
|
259
518
|
const p = extractPropsAndStyle(hnode.props);
|
|
519
|
+
const isRtl = p.direction === 'rtl' || p.isRTL;
|
|
520
|
+
const bg = p.gradient?.colors?.[0]
|
|
521
|
+
? parseDynamicColor(p.gradient.colors[0])
|
|
522
|
+
: parseDynamicColor(p.backgroundColor) || 'transparent';
|
|
523
|
+
|
|
260
524
|
const containerStyle: ViewStyle = {
|
|
261
|
-
flexDirection: 'row',
|
|
525
|
+
flexDirection: isRtl ? 'row-reverse' : 'row',
|
|
262
526
|
padding: p.padding,
|
|
263
527
|
paddingHorizontal: p.paddingHorizontal,
|
|
264
528
|
paddingVertical: p.paddingVertical,
|
|
265
|
-
backgroundColor:
|
|
529
|
+
backgroundColor: bg,
|
|
266
530
|
borderRadius: p.borderRadius ?? p.cornerRadius ?? 0,
|
|
267
531
|
borderWidth: p.borderWidth,
|
|
268
532
|
borderColor: parseDynamicColor(p.borderColor),
|
|
533
|
+
borderStyle: p.borderStyle || 'solid',
|
|
269
534
|
columnGap: p.spacing ?? 0,
|
|
270
535
|
alignItems:
|
|
271
536
|
p.alignment === 'center'
|
|
272
537
|
? 'center'
|
|
273
|
-
: p.alignment === 'trailing'
|
|
538
|
+
: p.alignment === 'trailing' || p.alignment === 'bottom'
|
|
274
539
|
? 'flex-end'
|
|
275
540
|
: p.alignment === 'top'
|
|
276
541
|
? 'flex-start'
|
|
@@ -282,9 +547,12 @@ function renderPreviewNode(
|
|
|
282
547
|
? 'space-between'
|
|
283
548
|
: p.justifyContent === 'spaceAround'
|
|
284
549
|
? 'space-around'
|
|
550
|
+
: p.justifyContent === 'spaceEvenly'
|
|
551
|
+
? 'space-evenly'
|
|
285
552
|
: p.justifyContent === 'flexEnd'
|
|
286
553
|
? 'flex-end'
|
|
287
554
|
: 'flex-start',
|
|
555
|
+
...extractShadowStyle(p),
|
|
288
556
|
};
|
|
289
557
|
|
|
290
558
|
if (isRoot) {
|
|
@@ -300,7 +568,7 @@ function renderPreviewNode(
|
|
|
300
568
|
<View style={containerStyle}>
|
|
301
569
|
{hnode.children?.map((child, idx) => (
|
|
302
570
|
<React.Fragment key={idx}>
|
|
303
|
-
{renderPreviewNode(child, onAction, false, 'row')}
|
|
571
|
+
{renderPreviewNode(child, onAction, false, 'row', syncVars)}
|
|
304
572
|
</React.Fragment>
|
|
305
573
|
))}
|
|
306
574
|
</View>
|
|
@@ -332,7 +600,7 @@ function renderPreviewNode(
|
|
|
332
600
|
: { ...StyleSheet.absoluteFillObject, alignItems: 'center', justifyContent: 'center' }
|
|
333
601
|
}
|
|
334
602
|
>
|
|
335
|
-
{renderPreviewNode(child, onAction, false, parentDirection)}
|
|
603
|
+
{renderPreviewNode(child, onAction, false, parentDirection, syncVars)}
|
|
336
604
|
</View>
|
|
337
605
|
))}
|
|
338
606
|
</View>
|
|
@@ -355,7 +623,7 @@ function renderPreviewNode(
|
|
|
355
623
|
>
|
|
356
624
|
{gnode.children?.map((child: any, idx: number) => (
|
|
357
625
|
<View key={idx} style={{ flexBasis: `${Math.floor(100 / cols) - 3}%` }}>
|
|
358
|
-
{renderPreviewNode(child, onAction, false, 'column')}
|
|
626
|
+
{renderPreviewNode(child, onAction, false, 'column', syncVars)}
|
|
359
627
|
</View>
|
|
360
628
|
))}
|
|
361
629
|
</View>
|
|
@@ -365,6 +633,18 @@ function renderPreviewNode(
|
|
|
365
633
|
case 'Text': {
|
|
366
634
|
const tnode = node as TextNode;
|
|
367
635
|
const p = extractPropsAndStyle(tnode.props);
|
|
636
|
+
const isRtl = p.direction === 'rtl' || p.isRTL;
|
|
637
|
+
const shadowColor = parseDynamicColor(p.shadowColor);
|
|
638
|
+
|
|
639
|
+
const rawText = String(p.text ?? '');
|
|
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;
|
|
646
|
+
const isRedacted = Boolean(p.redacted);
|
|
647
|
+
|
|
368
648
|
const textStyle: RNTextStyle = {
|
|
369
649
|
color: parseDynamicColor(p.color) || '#FFFFFF',
|
|
370
650
|
fontSize: p.fontSize ?? 14,
|
|
@@ -376,17 +656,30 @@ function renderPreviewNode(
|
|
|
376
656
|
: p.fontWeight === 'medium'
|
|
377
657
|
? '500'
|
|
378
658
|
: 'normal',
|
|
379
|
-
|
|
659
|
+
fontFamily: p.fontDesign === 'monospaced' ? 'monospace' : undefined,
|
|
660
|
+
textAlign: p.textAlign ?? (isRtl ? 'right' : 'left'),
|
|
661
|
+
lineHeight: p.lineHeight,
|
|
662
|
+
letterSpacing: p.letterSpacing,
|
|
663
|
+
opacity: isRedacted ? 0.45 : undefined,
|
|
664
|
+
textShadowColor: shadowColor,
|
|
665
|
+
textShadowOffset: p.shadowOffset
|
|
666
|
+
? { width: p.shadowOffset.x ?? 0, height: p.shadowOffset.y ?? 1 }
|
|
667
|
+
: undefined,
|
|
668
|
+
textShadowRadius: p.shadowRadius,
|
|
380
669
|
};
|
|
381
670
|
return (
|
|
382
671
|
<RNText
|
|
672
|
+
accessible={p.accessible !== false}
|
|
673
|
+
accessibilityLabel={p.accessibilityLabel || resolvedText}
|
|
674
|
+
accessibilityHint={p.accessibilityHint}
|
|
675
|
+
accessibilityRole={p.accessibilityRole as any}
|
|
383
676
|
numberOfLines={p.numberOfLines}
|
|
384
677
|
style={[
|
|
385
678
|
textStyle,
|
|
386
679
|
parentDirection === 'row' ? { flexShrink: 1 } : undefined,
|
|
387
680
|
]}
|
|
388
681
|
>
|
|
389
|
-
{
|
|
682
|
+
{isRedacted ? '••••••••' : resolvedText}
|
|
390
683
|
</RNText>
|
|
391
684
|
);
|
|
392
685
|
}
|
|
@@ -394,28 +687,58 @@ function renderPreviewNode(
|
|
|
394
687
|
case 'Button': {
|
|
395
688
|
const bnode = node as ButtonNode;
|
|
396
689
|
const p = bnode.props;
|
|
690
|
+
const bg = p.gradient?.colors?.[0]
|
|
691
|
+
? parseDynamicColor(p.gradient.colors[0])
|
|
692
|
+
: parseDynamicColor(p.backgroundColor) || '#2563EB';
|
|
693
|
+
|
|
397
694
|
const btnStyle: ViewStyle = {
|
|
398
|
-
backgroundColor:
|
|
695
|
+
backgroundColor: bg,
|
|
399
696
|
borderRadius: p.borderRadius ?? p.cornerRadius ?? 8,
|
|
697
|
+
borderWidth: p.borderWidth,
|
|
698
|
+
borderColor: parseDynamicColor(p.borderColor),
|
|
699
|
+
borderStyle: p.borderStyle || 'solid',
|
|
400
700
|
paddingHorizontal: p.paddingHorizontal ?? p.padding ?? 12,
|
|
401
701
|
paddingVertical: p.paddingVertical ?? p.padding ?? 6,
|
|
402
702
|
alignItems: 'center',
|
|
403
703
|
justifyContent: 'center',
|
|
404
704
|
alignSelf: p.fullWidth ? 'stretch' : 'auto',
|
|
405
|
-
|
|
705
|
+
...(p.fullWidth ? (parentDirection === 'row' ? { flex: 1 } : { width: '100%' }) : {}),
|
|
706
|
+
...extractShadowStyle(p),
|
|
406
707
|
};
|
|
407
708
|
const textStyle: RNTextStyle = {
|
|
408
709
|
color: parseDynamicColor(p.textColor) || '#FFFFFF',
|
|
409
710
|
fontSize: p.fontSize ?? 12,
|
|
410
711
|
fontWeight: (p.fontWeight as any) ?? '600',
|
|
712
|
+
fontFamily: p.fontDesign === 'monospaced' ? 'monospace' : undefined,
|
|
411
713
|
};
|
|
412
714
|
|
|
413
715
|
return (
|
|
414
716
|
<TouchableOpacity
|
|
717
|
+
accessible={p.accessible !== false}
|
|
718
|
+
accessibilityLabel={p.accessibilityLabel || p.title}
|
|
719
|
+
accessibilityHint={p.accessibilityHint}
|
|
720
|
+
accessibilityRole="button"
|
|
415
721
|
activeOpacity={0.7}
|
|
416
722
|
onPress={() => {
|
|
417
|
-
if (p.actionId
|
|
418
|
-
onAction
|
|
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
|
+
}
|
|
419
742
|
}
|
|
420
743
|
}}
|
|
421
744
|
style={btnStyle}
|
|
@@ -500,16 +823,7 @@ function renderPreviewNode(
|
|
|
500
823
|
case 'Timer': {
|
|
501
824
|
const tnode = node as TimerNode;
|
|
502
825
|
const p = tnode.props || {};
|
|
503
|
-
return
|
|
504
|
-
<RNText
|
|
505
|
-
style={[
|
|
506
|
-
{ color: parseDynamicColor(p.color) || '#2563EB', fontSize: p.fontSize ?? 14, fontWeight: 'bold' },
|
|
507
|
-
parentDirection === 'row' ? { flexShrink: 0 } : undefined,
|
|
508
|
-
]}
|
|
509
|
-
>
|
|
510
|
-
{p.prefix || ''}1:29:55{p.suffix || ''}
|
|
511
|
-
</RNText>
|
|
512
|
-
);
|
|
826
|
+
return <PreviewTimerText nodeProps={p} parentDirection={parentDirection} />;
|
|
513
827
|
}
|
|
514
828
|
|
|
515
829
|
case 'Image': {
|
|
@@ -589,7 +903,7 @@ function renderPreviewNode(
|
|
|
589
903
|
>
|
|
590
904
|
{lnode.children?.map((child: any, idx: number) => (
|
|
591
905
|
<React.Fragment key={idx}>
|
|
592
|
-
{renderPreviewNode(child, onAction, false, parentDirection)}
|
|
906
|
+
{renderPreviewNode(child, onAction, false, parentDirection, syncVars)}
|
|
593
907
|
</React.Fragment>
|
|
594
908
|
))}
|
|
595
909
|
</TouchableOpacity>
|
|
@@ -644,6 +958,16 @@ function renderPreviewNode(
|
|
|
644
958
|
);
|
|
645
959
|
}
|
|
646
960
|
|
|
961
|
+
case 'Toggle': {
|
|
962
|
+
return (
|
|
963
|
+
<PreviewToggleItem
|
|
964
|
+
key={`toggle-${(node as any).id || (node as any).props?.actionId || Math.random()}`}
|
|
965
|
+
node={node}
|
|
966
|
+
onAction={onAction}
|
|
967
|
+
/>
|
|
968
|
+
);
|
|
969
|
+
}
|
|
970
|
+
|
|
647
971
|
default:
|
|
648
972
|
return null;
|
|
649
973
|
}
|
|
@@ -28,6 +28,7 @@ declare module 'react' {
|
|
|
28
28
|
declare module 'react-native' {
|
|
29
29
|
export interface PlatformOSType {
|
|
30
30
|
OS: 'ios' | 'android' | 'windows' | 'macos' | 'web';
|
|
31
|
+
Version: string | number;
|
|
31
32
|
select<T>(specifics: { [platform in 'ios' | 'android' | 'default']?: T }): T;
|
|
32
33
|
}
|
|
33
34
|
export const Platform: PlatformOSType;
|