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.
- package/CHANGELOG.md +37 -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 +889 -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 +1461 -226
- 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/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?:
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
217
|
-
|
|
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 ||
|
|
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 ||
|
|
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 ||
|
|
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
|
-
|
|
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:
|
|
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:
|
|
349
|
+
text:
|
|
350
|
+
String(resolveBindingValue(restProps.text) || '') || flattenTextChildren(children),
|
|
303
351
|
});
|
|
304
352
|
case 'Progress':
|
|
305
353
|
return UI.Progress(restProps.value ?? 0, restProps);
|