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.
Files changed (50) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/README.md +40 -1
  3. package/android/src/main/java/com/reactnativeliveactivity/renderer/DynamicWidgetCanvasRenderer.kt +443 -46
  4. package/android/src/main/java/com/reactnativeliveactivity/storage/DynamicWidgetStateStore.kt +86 -28
  5. package/android/src/main/java/com/reactnativeliveactivity/widgets/DynamicHomeScreenWidgetProvider.kt +126 -56
  6. package/android/src/main/res/layout/rn_live_widget_hit_zone.xml +16 -0
  7. package/android/src/main/res/layout/rn_live_widget_host.xml +16 -87
  8. package/docs/GUIDE-EN.md +241 -0
  9. package/docs/GUIDE-VI.md +266 -0
  10. package/docs/index.html +1140 -259
  11. package/docs/llms-full.txt +26 -0
  12. package/docs/llms.txt +8 -0
  13. package/ios/Models/DynamicLayoutModels.swift +6 -1
  14. package/ios/Renderer/DynamicNodeView.swift +169 -14
  15. package/ios/Widgets/DynamicHomeScreenWidget.swift +5 -0
  16. package/lib/builder.d.ts.map +1 -1
  17. package/lib/builder.js +65 -11
  18. package/lib/builder.js.map +1 -1
  19. package/lib/dispatcher.js +16 -10
  20. package/lib/dispatcher.js.map +1 -1
  21. package/lib/hooks.js +36 -31
  22. package/lib/hooks.js.map +1 -1
  23. package/lib/index.d.ts +17 -2
  24. package/lib/index.d.ts.map +1 -1
  25. package/lib/index.js +124 -50
  26. package/lib/index.js.map +1 -1
  27. package/lib/ir.d.ts +15 -0
  28. package/lib/ir.d.ts.map +1 -0
  29. package/lib/ir.js +379 -0
  30. package/lib/ir.js.map +1 -0
  31. package/lib/jsx.d.ts +9 -1
  32. package/lib/jsx.d.ts.map +1 -1
  33. package/lib/jsx.js +131 -84
  34. package/lib/jsx.js.map +1 -1
  35. package/lib/preview.d.ts +0 -23
  36. package/lib/preview.d.ts.map +1 -1
  37. package/lib/preview.js +373 -104
  38. package/lib/preview.js.map +1 -1
  39. package/lib/types.d.ts +204 -12
  40. package/lib/types.d.ts.map +1 -1
  41. package/lib/types.js +2 -1
  42. package/lib/types.js.map +1 -1
  43. package/package.json +2 -1
  44. package/src/builder.ts +57 -2
  45. package/src/index.ts +66 -1
  46. package/src/ir.ts +430 -0
  47. package/src/jsx.tsx +30 -0
  48. package/src/preview.tsx +356 -32
  49. package/src/react-native-env.d.ts +1 -0
  50. package/src/types.ts +253 -13
package/src/types.ts CHANGED
@@ -27,28 +27,142 @@ export type LayoutNodeType =
27
27
  | 'Custom';
28
28
 
29
29
  /**
30
- * Định dạng màu hỗ trợ chuỗi Hex đơn (ví dụ '#0F172A')
31
- * hoặc Object Dynamic Color tự đổi theo chế độ Sáng / Tối (Dark Mode) của hệ điều hành.
30
+ * Định dạng màu hỗ trợ:
31
+ * - Chuỗi Hex đơn (ví dụ '#0F172A', '#38BDF8AA')
32
+ * - Object Dynamic Color tự đổi theo chế độ Sáng / Tối (Light / Dark Mode)
33
+ * - Chế độ Tinted / Accented trên iOS 18+ và Material You Android.
32
34
  */
33
- export type DynamicColor = string | { light: string; dark: string };
35
+ export type DynamicColor =
36
+ | string
37
+ | {
38
+ light: string;
39
+ dark: string;
40
+ /** Màu hiển thị ở chế độ Tinted Home Screen trên iOS 18+ hoặc Material You Dynamic Theming Android */
41
+ tinted?: string;
42
+ };
43
+
44
+ export type BorderStyle = 'solid' | 'dashed' | 'dotted';
45
+
46
+ /** Cấu hình đổ bóng (Shadow Modifier) cho Card, Button và Container */
47
+ export interface ShadowProps {
48
+ /** Màu bóng đổ (hỗ trợ DynamicColor) */
49
+ shadowColor?: DynamicColor;
50
+ /** Bán kính mờ của bóng đổ (dp/pt) */
51
+ shadowRadius?: number;
52
+ /** Độ mờ đục từ 0.0 (trong suốt) đến 1.0 (đậm đặc) */
53
+ shadowOpacity?: number;
54
+ /** Độ dời vị trí bóng đổ theo trục X và Y */
55
+ shadowOffset?: { x: number; y: number };
56
+ }
57
+
58
+ /** Cấu hình dải màu chuyển sắc (Gradient Modifier) */
59
+ export interface GradientProps {
60
+ /** Kiểu chuyển sắc: 'linear' (đường thẳng - mặc định) hoặc 'radial' (tâm tròn) */
61
+ type?: 'linear' | 'radial';
62
+ /** Danh sách các màu chuyển tiếp (hỗ trợ DynamicColor cho từng chặng) */
63
+ colors: DynamicColor[];
64
+ /** Điểm bắt đầu theo toạ độ tỉ lệ từ 0.0 đến 1.0 (mặc định { x: 0, y: 0 } top-left) */
65
+ startPoint?: { x: number; y: number };
66
+ /** Điểm kết thúc theo toạ độ tỉ lệ từ 0.0 đến 1.0 (mặc định { x: 1, y: 1 } bottom-right) */
67
+ endPoint?: { x: number; y: number };
68
+ /** Góc gradient theo độ (ví dụ 45, 90, 180) */
69
+ angle?: number;
70
+ }
71
+
72
+ export type TypographyStyle =
73
+ | 'largeTitle'
74
+ | 'title1'
75
+ | 'title2'
76
+ | 'title3'
77
+ | 'headline'
78
+ | 'subheadline'
79
+ | 'body'
80
+ | 'callout'
81
+ | 'footnote'
82
+ | 'caption1'
83
+ | 'caption2';
84
+
85
+ export type FontDesign = 'default' | 'monospaced' | 'rounded' | 'serif';
86
+
87
+ /**
88
+ * ♿ Vai trò ngữ nghĩa cho Trợ năng (Accessibility Semantic Role).
89
+ * Giúp các công cụ đọc màn hình (TalkBack trên Android, VoiceOver trên iOS, Screen Readers)
90
+ * phát âm chính xác bản chất của phần tử thay vì coi tất cả là hình ảnh raster.
91
+ */
92
+ export type AccessibilityRole =
93
+ | 'none'
94
+ | 'button'
95
+ | 'header'
96
+ | 'text'
97
+ | 'image'
98
+ | 'progressbar'
99
+ | 'timer'
100
+ | 'switch'
101
+ | 'checkbox'
102
+ | 'summary'
103
+ | 'alert';
104
+
105
+ /**
106
+ * ♿ Thuộc tính Trợ năng (Accessibility & Semantics Layer).
107
+ * Tách biệt hoàn toàn tầng ngữ nghĩa khỏi tầng vẽ đồ họa (Canvas/SwiftUI),
108
+ * cho phép TalkBack và VoiceOver tiếp cận dữ liệu chính xác ngay cả khi render bằng Canvas.
109
+ */
110
+ export interface AccessibilityProps {
111
+ /** Cho phép công cụ trợ năng (TalkBack/VoiceOver) tiếp cận thành phần này (mặc định true; đặt false cho các icon/hình trang trí decorative) */
112
+ accessible?: boolean;
113
+ /** Mô tả âm thanh phát âm cho người dùng khi TalkBack/VoiceOver lướt tới phần tử */
114
+ accessibilityLabel?: string;
115
+ /** Hướng dẫn hành động bổ sung (ví dụ: "Chạm hai lần để xác nhận chấm công") */
116
+ accessibilityHint?: string;
117
+ /** Vai trò ngữ nghĩa của phần tử (header, button, progressbar, ...) */
118
+ accessibilityRole?: AccessibilityRole;
119
+ /** Giá trị trạng thái đọc lên (ví dụ: "86%", "Đang vận chuyển", "Đã bật") */
120
+ accessibilityValue?: string | number;
121
+ }
34
122
 
35
123
  export interface BaseNode {
36
124
  type: LayoutNodeType;
37
125
  }
38
126
 
39
- export interface ContainerProps {
127
+ export interface ContainerProps extends ShadowProps, AccessibilityProps {
40
128
  padding?: number;
41
129
  paddingHorizontal?: number;
42
130
  paddingVertical?: number;
43
131
  spacing?: number;
132
+ /** Khoảng cách giữa các phần tử con (Alias chuẩn React Native Style cho spacing) */
133
+ gap?: number;
134
+ rowGap?: number;
135
+ columnGap?: number;
44
136
  backgroundColor?: DynamicColor;
137
+ /** Gradient màu nền (tự động graceful fallback sang backgroundColor nếu platform không hỗ trợ) */
138
+ gradient?: GradientProps;
45
139
  borderRadius?: number;
46
140
  /** Alias bo góc theo cú pháp SwiftUI (tự động ánh xạ sang borderRadius) */
47
141
  cornerRadius?: number;
48
142
  borderColor?: DynamicColor;
49
143
  borderWidth?: number;
50
- alignment?: 'leading' | 'center' | 'trailing' | string;
51
- justifyContent?: 'flexStart' | 'center' | 'flexEnd' | 'spaceBetween' | string;
144
+ borderStyle?: BorderStyle;
145
+ alignment?:
146
+ | 'leading'
147
+ | 'center'
148
+ | 'trailing'
149
+ | 'top'
150
+ | 'bottom'
151
+ | 'firstTextBaseline'
152
+ | 'lastTextBaseline'
153
+ | string;
154
+ justifyContent?:
155
+ | 'flexStart'
156
+ | 'center'
157
+ | 'flexEnd'
158
+ | 'spaceBetween'
159
+ | 'spaceAround'
160
+ | 'spaceEvenly'
161
+ | string;
162
+ /** Chiều viết văn bản (Hỗ trợ quốc tế hoá RTL cho tiếng Ả Rập, Do Thái) */
163
+ direction?: 'ltr' | 'rtl' | 'auto';
164
+ /** Cờ bật RTL chủ động cho khối container này */
165
+ isRTL?: boolean;
52
166
  /** Tự động ẩn hoặc làm mờ nội dung khi thiết bị đang khóa màn hình (Bảo mật chuẩn Apple) */
53
167
  privacySensitive?: boolean;
54
168
  /** Chủ động che nội dung thành vệt khối mờ Placeholder (Skeleton Redaction) */
@@ -65,10 +179,19 @@ export type FontWeight =
65
179
  | (string & {})
66
180
  | string;
67
181
 
68
- export interface TextStyle {
182
+ export interface TextStyle extends ShadowProps, AccessibilityProps {
69
183
  color?: DynamicColor;
70
184
  fontSize?: number;
71
185
  fontWeight?: FontWeight;
186
+ /** Hệ thống phân cấp cỡ chữ chuẩn Apple Human Interface Guidelines / Material Design */
187
+ typography?: TypographyStyle;
188
+ /** Kiểu dáng họ font chữ hệ thống */
189
+ fontDesign?: FontDesign;
190
+ /** Tự động co giãn cỡ chữ theo cài đặt Trợ năng (Accessibility Dynamic Type) của hệ điều hành (mặc định true) */
191
+ dynamicType?: boolean;
192
+ textAlign?: 'left' | 'center' | 'right' | 'leading' | 'trailing' | 'auto';
193
+ lineHeight?: number;
194
+ letterSpacing?: number;
72
195
  numberOfLines?: number;
73
196
  strikethroughWhenToggled?: string;
74
197
  /** Tự động làm mờ hoặc ẩn chữ khi màn hình khóa (iOS Privacy Redacted) */
@@ -104,7 +227,7 @@ export interface TextNode extends BaseNode {
104
227
 
105
228
  export interface TimerNode extends BaseNode {
106
229
  type: 'Timer';
107
- props: {
230
+ props: AccessibilityProps & {
108
231
  /** Epoch timestamp tính bằng giây để đếm tới (hoặc đếm từ) */
109
232
  targetTimestamp: number;
110
233
  /** 'countdown': đếm ngược tới mốc; 'countup': đếm tiến từ mốc */
@@ -119,7 +242,7 @@ export interface TimerNode extends BaseNode {
119
242
 
120
243
  export interface ProgressNode extends BaseNode {
121
244
  type: 'Progress';
122
- props: {
245
+ props: AccessibilityProps & {
123
246
  // ── 1. Nguồn dữ liệu tiến trình ─────────────────────────────
124
247
  /** Mốc bắt đầu (epoch giây) nếu dùng timer interval tự chạy */
125
248
  startTimestamp?: number;
@@ -178,7 +301,7 @@ export interface ProgressNode extends BaseNode {
178
301
 
179
302
  export interface ImageNode extends BaseNode {
180
303
  type: 'Image';
181
- props: {
304
+ props: AccessibilityProps & {
182
305
  /** URL ảnh từ mạng (https://...) - Tự động tải, nén tối ưu RAM và cache vào App Group cho Widget & Live Activity */
183
306
  url?: string;
184
307
  /** Chuỗi ảnh Base64 (có thể kèm tiền tố data:image/png;base64,... hoặc chuỗi raw base64) */
@@ -223,7 +346,7 @@ export interface SpacerNode extends BaseNode {
223
346
 
224
347
  export interface ButtonNode extends BaseNode {
225
348
  type: 'Button';
226
- props: {
349
+ props: ShadowProps & AccessibilityProps & {
227
350
  title: string;
228
351
  /**
229
352
  * Mã hành động chạy ngầm ngay trên Widget (iOS 17+ AppIntent, không mở App):
@@ -237,14 +360,21 @@ export interface ButtonNode extends BaseNode {
237
360
  /** Mở App và điều hướng tới URL Deep Link cụ thể */
238
361
  deepLink?: string;
239
362
  backgroundColor?: DynamicColor;
363
+ /** Gradient màu nền nút bấm */
364
+ gradient?: GradientProps;
240
365
  textColor?: DynamicColor;
241
366
  fontSize?: number;
242
367
  fontWeight?: 'regular' | 'medium' | 'semibold' | 'bold';
368
+ typography?: TypographyStyle;
369
+ fontDesign?: FontDesign;
243
370
  padding?: number;
244
371
  paddingHorizontal?: number;
245
372
  paddingVertical?: number;
246
373
  borderRadius?: number;
247
374
  cornerRadius?: number;
375
+ borderColor?: DynamicColor;
376
+ borderWidth?: number;
377
+ borderStyle?: BorderStyle;
248
378
  fullWidth?: boolean;
249
379
  /** Tiêu đề hiển thị khi nút ở trạng thái đã tick (dùng với actionId 'toggle:<key>') */
250
380
  checkedTitle?: string;
@@ -303,7 +433,7 @@ export interface DividerNode extends BaseNode {
303
433
 
304
434
  export interface GaugeNode extends BaseNode {
305
435
  type: 'Gauge';
306
- props: {
436
+ props: AccessibilityProps & {
307
437
  /** Giá trị tiến độ từ 0.0 đến 1.0 */
308
438
  value: number;
309
439
  /** Chuỗi hiển thị chính giữa đồng hồ (vd "85%", "120 km/h", "420") */
@@ -350,7 +480,7 @@ export interface ChartNode extends BaseNode {
350
480
 
351
481
  export interface ToggleNode extends BaseNode {
352
482
  type: 'Toggle';
353
- props: {
483
+ props: AccessibilityProps & {
354
484
  /** Mã định danh toggle (tự động gắn tiền tố 'toggle:' nếu chưa có) */
355
485
  actionId: string;
356
486
  label: string;
@@ -358,6 +488,7 @@ export interface ToggleNode extends BaseNode {
358
488
  /** 'checkbox' (ô tích) | 'switch' (công tắc gạt) */
359
489
  style?: 'checkbox' | 'switch';
360
490
  checked?: boolean;
491
+ isChecked?: boolean;
361
492
  tintColor?: string;
362
493
  textColor?: string;
363
494
  checkedTextColor?: string;
@@ -601,3 +732,112 @@ export interface ActiveActivityInfo {
601
732
  activityId: string;
602
733
  pushToken?: string;
603
734
  }
735
+
736
+ /**
737
+ * 📊 Bảng tra cứu năng lực nền tảng (Platform Capability & Fallback Matrix).
738
+ * Cho phép ứng dụng kiểm tra tính năng được hỗ trợ thực tế trên thiết bị đang chạy
739
+ * thay vì phỏng đoán, đảm bảo UI hoạt động ổn định và graceful fallback mượt mà.
740
+ */
741
+ export interface WidgetCapabilities {
742
+ /** Nền tảng hệ điều hành ('ios' hoặc 'android') */
743
+ platform: 'ios' | 'android';
744
+ /** Phiên bản OS (ví dụ '18.1', '17.2', '14.0' Android API 34) */
745
+ osVersion: string | number;
746
+ /** Hỗ trợ Live Activities trên Lock Screen (iOS 16.1+ / Android 8.0+ Ongoing Notification) */
747
+ supportsLiveActivities: boolean;
748
+ /** Hỗ trợ Dynamic Island (iPhone 14 Pro, 15, 16 series) */
749
+ supportsDynamicIsland: boolean;
750
+ /** Hỗ trợ Android 16+ Live Update thông báo kiểu tiến trình ProgressStyle */
751
+ supportsAndroidLiveUpdates: boolean;
752
+ /** Hỗ trợ ghim tiện ích Home Screen Widgets (iOS 14+ / Android 8.0+) */
753
+ supportsHomeWidgets: boolean;
754
+ /** Hỗ trợ tương tác bấm nút chạy ngầm không mở app (iOS 17+ AppIntent / Android PendingIntent) */
755
+ supportsInteractiveIntents: boolean;
756
+ /** Hỗ trợ dải màu chuyển tiếp Linear / Radial Gradient */
757
+ supportsGradients: boolean;
758
+ /** Hỗ trợ bóng đổ Elevation / Shadow layer */
759
+ supportsShadows: boolean;
760
+ /** Hỗ trợ viền nét đứt Dashed / Dotted Stroke */
761
+ supportsDashedBorders: boolean;
762
+ /** Hỗ trợ tự động co giãn cỡ chữ theo Trợ năng (Accessibility Dynamic Type) */
763
+ supportsDynamicType: boolean;
764
+ /** Hỗ trợ bố cục quốc tế hoá từ phải sang trái (RTL: Arabic, Hebrew, ...) */
765
+ supportsRTL: boolean;
766
+ /** Hỗ trợ chế độ màu Tinted / Accented Widgets (iOS 18+ / Android Material You) */
767
+ supportsTintedMode: boolean;
768
+ /** Hỗ trợ hiệu ứng Odometer số lật (iOS 16+ numericText) */
769
+ supportsNumericAnimation: boolean;
770
+ /** Hỗ trợ lớp Trợ năng phân cấp (Accessibility Fallback Layer: VoiceOver & TalkBack contentDescription) */
771
+ supportsAccessibility: boolean;
772
+ }
773
+
774
+ // ─── 14. UI INTERMEDIATE REPRESENTATION (IR) & SEMANTIC TREE (Phase 2) ────────
775
+
776
+ /**
777
+ * Mục tiêu kết xuất của bộ điều phối Renderer Planner.
778
+ * - 'native_remote_view': Kết xuất thành RemoteViews native (TextView, Button, ProgressBar).
779
+ * - 'canvas_bitmap': Kết xuất qua Canvas 2D Bitmap (Gauge 240°, Equalizer, đồ họa phức tạp).
780
+ * - 'composite': Vùng chứa phức hợp kết hợp cả Native Views và Canvas sub-views.
781
+ */
782
+ export type RenderPlanTarget = 'native_remote_view' | 'canvas_bitmap' | 'composite';
783
+
784
+ /**
785
+ * Kế hoạch kết xuất cho từng Node trong cây UI.
786
+ */
787
+ export interface NodeRenderPlan {
788
+ id: string;
789
+ type: LayoutNodeType;
790
+ target: RenderPlanTarget;
791
+ reason: string;
792
+ hasNativeEquivalent: boolean;
793
+ requiresCanvas: boolean;
794
+ childrenTargets?: RenderPlanTarget[];
795
+ }
796
+
797
+ /**
798
+ * ♿ Nút ngữ nghĩa độc lập (Semantic Node) tách biệt hoàn toàn khỏi Renderer.
799
+ */
800
+ export interface SemanticNode {
801
+ id: string;
802
+ path: string;
803
+ type: LayoutNodeType;
804
+ role: AccessibilityRole;
805
+ label: string;
806
+ hint?: string;
807
+ value?: string | number;
808
+ interactive: boolean;
809
+ actionId?: string;
810
+ deepLink?: string;
811
+ isDecorative?: boolean;
812
+ }
813
+
814
+ /**
815
+ * Liên kết trạng thái hai chiều giữa UI và Native Store / JavaScript.
816
+ */
817
+ export interface StateBinding {
818
+ id: string;
819
+ actionId: string;
820
+ bindingType: 'toggle' | 'page' | 'custom';
821
+ targetKey?: string;
822
+ initialValue?: any;
823
+ }
824
+
825
+ /**
826
+ * 🌲 UI Intermediate Representation (Cây đại diện trung gian IR).
827
+ * Chuẩn hóa toàn bộ cấu trúc UI, Semantic Tree, Kế hoạch kết xuất (Render Plan)
828
+ * và Liên kết trạng thái (State Bindings) trước khi chuyển giao cho Renderer nền tảng.
829
+ */
830
+ export interface WidgetIR {
831
+ version: '2.0';
832
+ timestamp: number;
833
+ root: LayoutNode;
834
+ semanticTree: SemanticNode[];
835
+ semanticSummary: string;
836
+ renderPlan: {
837
+ overallStrategy: 'native_first_hybrid' | 'canvas_fallback';
838
+ nativeNodeCount: number;
839
+ canvasNodeCount: number;
840
+ nodes: Record<string, NodeRenderPlan>;
841
+ };
842
+ stateBindings: StateBinding[];
843
+ }