react-native-live-widgets 1.2.1 → 1.2.3

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 (79) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/README.md +89 -49
  3. package/android/src/main/AndroidManifest.xml +12 -0
  4. package/android/src/main/assets/fonts/MaterialIcons-Regular.ttf +0 -0
  5. package/android/src/main/java/com/reactnativeliveactivity/bridge/LiveActivityModule.kt +61 -1
  6. package/android/src/main/java/com/reactnativeliveactivity/liveactivity/LiveActivityNotifier.kt +153 -17
  7. package/android/src/main/java/com/reactnativeliveactivity/liveactivity/LiveActivityReceiver.kt +1 -1
  8. package/android/src/main/java/com/reactnativeliveactivity/renderer/DynamicWidgetCanvasRenderer.kt +86 -13
  9. package/android/src/main/java/com/reactnativeliveactivity/storage/DynamicWidgetImageCache.kt +53 -0
  10. package/android/src/main/java/com/reactnativeliveactivity/storage/DynamicWidgetStateStore.kt +647 -104
  11. package/android/src/main/java/com/reactnativeliveactivity/widgets/DynamicHomeScreenWidgetProvider.kt +3 -1
  12. package/android/src/main/java/com/reactnativeliveactivity/widgets/DynamicQuickSettingsTileService.kt +120 -0
  13. package/app.plugin.js +36 -0
  14. package/assets/MaterialIcons.json +2236 -0
  15. package/cli/codegen.js +889 -0
  16. package/cli/setup.js +323 -63
  17. package/docs/EXPO-GUIDE-EN.md +21 -3
  18. package/docs/EXPO-GUIDE-VI.md +21 -3
  19. package/docs/GUIDE-EN.md +203 -21
  20. package/docs/GUIDE-VI.md +207 -22
  21. package/docs/index.html +1461 -226
  22. package/docs/llms-full.txt +15 -0
  23. package/docs/llms.txt +16 -7
  24. package/ios/Bridge/LiveActivityModule.swift +333 -44
  25. package/ios/Intents/DynamicWidgetActionIntent.swift +57 -2
  26. package/ios/Models/DynamicLayoutModels.swift +114 -4
  27. package/ios/Renderer/DynamicNodeView.swift +15 -6
  28. package/ios/Storage/DynamicWidgetStateStore.swift +649 -38
  29. package/ios/Widgets/DynamicControlWidget.swift +63 -0
  30. package/ios/Widgets/DynamicHomeScreenWidget.swift +99 -26
  31. package/ios/Widgets/DynamicLiveActivityWidget.swift +25 -4
  32. package/lib/builder.d.ts +50 -7
  33. package/lib/builder.d.ts.map +1 -1
  34. package/lib/builder.js +326 -18
  35. package/lib/builder.js.map +1 -1
  36. package/lib/hooks.d.ts +13 -9
  37. package/lib/hooks.d.ts.map +1 -1
  38. package/lib/hooks.js +70 -12
  39. package/lib/hooks.js.map +1 -1
  40. package/lib/index.d.ts +80 -7
  41. package/lib/index.d.ts.map +1 -1
  42. package/lib/index.js +303 -59
  43. package/lib/index.js.map +1 -1
  44. package/lib/ir.d.ts.map +1 -1
  45. package/lib/ir.js +9 -2
  46. package/lib/ir.js.map +1 -1
  47. package/lib/jsx.d.ts +11 -7
  48. package/lib/jsx.d.ts.map +1 -1
  49. package/lib/jsx.js +50 -13
  50. package/lib/jsx.js.map +1 -1
  51. package/lib/material-icons.generated.d.ts +8 -0
  52. package/lib/material-icons.generated.d.ts.map +1 -0
  53. package/lib/material-icons.generated.js +9 -0
  54. package/lib/material-icons.generated.js.map +1 -0
  55. package/lib/preview.d.ts +11 -4
  56. package/lib/preview.d.ts.map +1 -1
  57. package/lib/preview.js +150 -82
  58. package/lib/preview.js.map +1 -1
  59. package/lib/sf-symbols.generated.d.ts +8 -0
  60. package/lib/sf-symbols.generated.d.ts.map +1 -0
  61. package/lib/sf-symbols.generated.js +9 -0
  62. package/lib/sf-symbols.generated.js.map +1 -0
  63. package/lib/types.d.ts +302 -18
  64. package/lib/types.d.ts.map +1 -1
  65. package/package.json +6 -2
  66. package/scripts/build.js +98 -0
  67. package/scripts/generate-material-icons.js +93 -0
  68. package/scripts/generate-sf-symbols.js +95 -0
  69. package/scripts/release.js +115 -0
  70. package/scripts/test-ir-semantic.js +314 -0
  71. package/src/builder.ts +382 -24
  72. package/src/hooks.ts +88 -12
  73. package/src/index.ts +319 -56
  74. package/src/ir.ts +8 -2
  75. package/src/jsx.tsx +69 -21
  76. package/src/material-icons.generated.ts +3844 -0
  77. package/src/preview.tsx +235 -81
  78. package/src/sf-symbols.generated.ts +9533 -0
  79. package/src/types.ts +348 -18
package/src/jsx.tsx CHANGED
@@ -25,8 +25,44 @@ import {
25
25
  LinkProps,
26
26
  EqualizerProps,
27
27
  StyleProp,
28
+ DataBindingField,
28
29
  } from './types';
29
- import { UI, flattenStyle } from './builder';
30
+ import { UI, flattenStyle, isDataBinding, resolveBindingValue } from './builder';
31
+
32
+ type WidgetTextChild =
33
+ | React.ReactNode
34
+ | DataBindingField<any>
35
+ | Array<React.ReactNode | DataBindingField<any>>;
36
+
37
+ function flattenTextChildren(children: any): string {
38
+ if (children === undefined || children === null || typeof children === 'boolean') {
39
+ return '';
40
+ }
41
+ if (isDataBinding(children)) {
42
+ return children.toToken();
43
+ }
44
+ if (typeof children === 'string' || typeof children === 'number') {
45
+ return String(children);
46
+ }
47
+ if (Array.isArray(children)) {
48
+ return children.map(flattenTextChildren).join('');
49
+ }
50
+ return '';
51
+ }
52
+
53
+ function collectChildElements(children: any, out: any[] = []): any[] {
54
+ if (children === undefined || children === null || typeof children === 'boolean') {
55
+ return out;
56
+ }
57
+ if (Array.isArray(children)) {
58
+ for (const item of children) {
59
+ collectChildElements(item, out);
60
+ }
61
+ return out;
62
+ }
63
+ out.push(children);
64
+ return out;
65
+ }
30
66
 
31
67
  // ─── 1. JSX COMPONENT DEFINITIONS ────────────────────────────────────────────
32
68
 
@@ -67,22 +103,24 @@ export const Grid: React.FC<GridJSXProps> = () => null;
67
103
  Grid.displayName = 'Grid';
68
104
 
69
105
  export interface TextJSXProps extends TextStyle {
70
- children?: React.ReactNode;
71
- text?: string;
106
+ children?: WidgetTextChild;
107
+ text?: string | DataBindingField<any>;
72
108
  style?: StyleProp<TextStyle>;
73
109
  }
74
110
  export const Text: React.FC<TextJSXProps> = () => null;
75
111
  Text.displayName = 'Text';
76
112
 
77
- export type ButtonJSXProps = ButtonNode['props'] & {
78
- children?: React.ReactNode;
113
+ export type ButtonJSXProps = Omit<ButtonNode['props'], 'title'> & {
114
+ title?: string | DataBindingField<any>;
115
+ children?: WidgetTextChild;
79
116
  style?: StyleProp<ButtonNode['props']>;
80
117
  };
81
118
  export const Button: React.FC<ButtonJSXProps> = () => null;
82
119
  Button.displayName = 'Button';
83
120
 
84
- export type BadgeJSXProps = BadgeNode['props'] & {
85
- children?: React.ReactNode;
121
+ export type BadgeJSXProps = Omit<BadgeNode['props'], 'text'> & {
122
+ text?: string | DataBindingField<any>;
123
+ children?: WidgetTextChild;
86
124
  style?: StyleProp<BadgeNode['props']>;
87
125
  };
88
126
  export const Badge: React.FC<BadgeJSXProps> = () => null;
@@ -164,6 +202,9 @@ export function renderToWidget(element: any): LayoutNode | null {
164
202
  if (element == null || typeof element === 'boolean') {
165
203
  return null;
166
204
  }
205
+ if (isDataBinding(element)) {
206
+ return UI.Text(element.toToken());
207
+ }
167
208
  if (typeof element === 'string' || typeof element === 'number') {
168
209
  return UI.Text(String(element));
169
210
  }
@@ -187,12 +228,12 @@ export function renderToWidget(element: any): LayoutNode | null {
187
228
 
188
229
  const parsedChildren: LayoutNode[] = [];
189
230
  if (children !== undefined && children !== null) {
190
- React.Children.forEach(children, (child: any) => {
231
+ for (const child of collectChildElements(children)) {
191
232
  const parsed = renderToWidget(child);
192
233
  if (parsed) {
193
234
  parsedChildren.push(parsed);
194
235
  }
195
- });
236
+ }
196
237
  }
197
238
 
198
239
  // Trường hợp Component là Function
@@ -213,20 +254,18 @@ export function renderToWidget(element: any): LayoutNode | null {
213
254
  return UI.Grid(restProps, ...parsedChildren);
214
255
  }
215
256
  if (isComp(Text, 'Text')) {
216
- const textContent =
217
- typeof children === 'string' || typeof children === 'number'
218
- ? String(children)
219
- : restProps.text || '';
257
+ const childText = flattenTextChildren(children);
258
+ const textContent = childText || String(resolveBindingValue(restProps.text) ?? '');
220
259
  return UI.Text(textContent, restProps);
221
260
  }
222
261
  if (isComp(Button, 'Button')) {
223
262
  const title =
224
- restProps.title || (typeof children === 'string' ? children : '');
263
+ String(resolveBindingValue(restProps.title) || '') || flattenTextChildren(children);
225
264
  return UI.Button({ ...restProps, title });
226
265
  }
227
266
  if (isComp(Badge, 'Badge')) {
228
267
  const text =
229
- restProps.text || (typeof children === 'string' ? children : '');
268
+ String(resolveBindingValue(restProps.text) || '') || flattenTextChildren(children);
230
269
  return UI.Badge({ ...restProps, text });
231
270
  }
232
271
  if (isComp(Progress, 'Progress')) {
@@ -237,7 +276,16 @@ export function renderToWidget(element: any): LayoutNode | null {
237
276
  }
238
277
  if (isComp(Image, 'Image')) {
239
278
  return UI.Image(
240
- restProps.url || restProps.base64 || restProps.systemName || restProps.source || '',
279
+ restProps.url ||
280
+ restProps.base64 ||
281
+ restProps.iosSystemName ||
282
+ restProps.systemNameIos ||
283
+ restProps.androidSystemName ||
284
+ restProps.systemNameAndroid ||
285
+ restProps.materialName ||
286
+ restProps.systemName ||
287
+ restProps.source ||
288
+ '',
241
289
  restProps
242
290
  );
243
291
  }
@@ -286,20 +334,20 @@ export function renderToWidget(element: any): LayoutNode | null {
286
334
  return UI.ZStack(restProps, ...parsedChildren);
287
335
  case 'Text': {
288
336
  const textContent =
289
- typeof children === 'string' || typeof children === 'number'
290
- ? String(children)
291
- : restProps.text || '';
337
+ flattenTextChildren(children) || String(resolveBindingValue(restProps.text) ?? '');
292
338
  return UI.Text(textContent, restProps);
293
339
  }
294
340
  case 'Button':
295
341
  return UI.Button({
296
342
  ...restProps,
297
- title: restProps.title || (typeof children === 'string' ? children : ''),
343
+ title:
344
+ String(resolveBindingValue(restProps.title) || '') || flattenTextChildren(children),
298
345
  });
299
346
  case 'Badge':
300
347
  return UI.Badge({
301
348
  ...restProps,
302
- text: restProps.text || (typeof children === 'string' ? children : ''),
349
+ text:
350
+ String(resolveBindingValue(restProps.text) || '') || flattenTextChildren(children),
303
351
  });
304
352
  case 'Progress':
305
353
  return UI.Progress(restProps.value ?? 0, restProps);