react-native-live-widgets 1.0.0 → 1.1.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 +14 -0
- package/README.md +197 -49
- package/android/build.gradle +14 -20
- package/android/src/main/AndroidManifest.xml +1 -0
- package/android/src/main/java/com/reactnativeliveactivity/bridge/LiveActivityModule.kt +2 -1
- package/android/src/main/java/com/reactnativeliveactivity/liveactivity/LiveActivityHeadlessTaskService.kt +8 -0
- package/android/src/main/java/com/reactnativeliveactivity/liveactivity/LiveActivityReceiver.kt +4 -1
- package/android/src/main/java/com/reactnativeliveactivity/renderer/DynamicWidgetCanvasRenderer.kt +29 -3
- package/android/src/main/java/com/reactnativeliveactivity/storage/DynamicWidgetStateStore.kt +21 -0
- package/android/src/main/java/com/reactnativeliveactivity/widgets/DynamicHomeScreenWidgetProvider.kt +51 -15
- package/android/src/main/res/layout/rn_live_widget_host.xml +64 -74
- package/app.plugin.js +114 -0
- package/assets/cross_platform_parity.png +0 -0
- package/assets/donate_qr.png +0 -0
- package/assets/dynamic_island_expanded.png +0 -0
- package/assets/home_widget_interactive.png +0 -0
- package/assets/lock_screen_live_activity.png +0 -0
- package/cli/setup.js +445 -48
- package/docs/EXPO-GUIDE-EN.md +405 -0
- package/docs/EXPO-GUIDE-VI.md +427 -0
- package/docs/GUIDE-EN.md +75 -14
- package/docs/GUIDE-VI.md +75 -14
- package/docs/index.html +405 -0
- package/docs/llms-full.txt +118 -0
- package/docs/llms.txt +66 -0
- package/lib/builder.js +9 -13
- package/lib/builder.js.map +1 -1
- package/lib/dispatcher.js +6 -11
- package/lib/dispatcher.js.map +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +40 -53
- package/lib/index.js.map +1 -1
- package/lib/types.js +1 -2
- package/lib/types.js.map +1 -1
- package/package.json +22 -4
- package/src/index.ts +12 -4
- package/src/react-native-env.d.ts +29 -0
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# react-native-live-widgets — Full AI Reference Manual (llms-full.txt)
|
|
2
|
+
|
|
3
|
+
> Comprehensive reference guide for Large Language Models (LLMs) and autonomous AI coding agents implementing Live Activities, Dynamic Island, and Home Screen Widgets in React Native and Expo.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 1. High-Level Architecture
|
|
8
|
+
|
|
9
|
+
`react-native-live-widgets` solves cross-platform widget development by abstracting native complexity behind a high-performance JSON layout protocol and declarative DSL:
|
|
10
|
+
- **iOS 16.1+**: Maps `UI.*` nodes to SwiftUI primitives in WidgetKit (`DynamicNodeView.swift`). Supports ActivityKit for Live Activities on Lock Screen and Dynamic Island (expanded, compactLeading, compactTrailing, minimal). Supports iOS 17+ interactive `AppIntents`.
|
|
11
|
+
- **Android API 24 -> Android 16 (API 36)**: Maps `UI.*` nodes to a high-DPI 2D `Canvas` renderer (`DynamicWidgetCanvasRenderer.kt`) for Home Screen `AppWidgetProvider`, and uses `Notification.ProgressStyle` / Ongoing Notifications for Live Activities with interactive action buttons and segmented progress bars.
|
|
12
|
+
- **Shared Storage**: Uses iOS `UserDefaults(suiteName: appGroup)` and Android `SharedPreferences` to synchronize state with zero latency.
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## 2. API Signature & Type Definitions
|
|
17
|
+
|
|
18
|
+
```typescript
|
|
19
|
+
export interface StartActivityOptions {
|
|
20
|
+
activityName: string;
|
|
21
|
+
appGroup?: string;
|
|
22
|
+
layout: WidgetNode;
|
|
23
|
+
dynamicIsland?: {
|
|
24
|
+
compactLeading?: WidgetNode;
|
|
25
|
+
compactTrailing?: WidgetNode;
|
|
26
|
+
minimal?: WidgetNode;
|
|
27
|
+
expanded?: {
|
|
28
|
+
leading?: WidgetNode;
|
|
29
|
+
trailing?: WidgetNode;
|
|
30
|
+
center?: WidgetNode;
|
|
31
|
+
bottom?: WidgetNode;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
attributes?: Record<string, any>;
|
|
35
|
+
androidConfig?: {
|
|
36
|
+
channelId?: string;
|
|
37
|
+
channelName?: string;
|
|
38
|
+
notificationId?: number;
|
|
39
|
+
smallIcon?: string;
|
|
40
|
+
ongoing?: boolean;
|
|
41
|
+
color?: string;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface WidgetLayoutConfig {
|
|
46
|
+
layout?: WidgetNode;
|
|
47
|
+
small?: WidgetNode;
|
|
48
|
+
medium?: WidgetNode;
|
|
49
|
+
large?: WidgetNode;
|
|
50
|
+
pages?: Record<string, WidgetNode>;
|
|
51
|
+
initialPage?: string;
|
|
52
|
+
accessoryRectangular?: WidgetNode;
|
|
53
|
+
accessoryCircular?: WidgetNode;
|
|
54
|
+
accessoryInline?: WidgetNode;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface WidgetRemoteConfig {
|
|
58
|
+
url: string;
|
|
59
|
+
method?: 'GET' | 'POST';
|
|
60
|
+
headers?: Record<string, string>;
|
|
61
|
+
intervalMinutes?: number;
|
|
62
|
+
body?: Record<string, any>;
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Static API Methods
|
|
67
|
+
- `LiveActivity.start(options: StartActivityOptions): Promise<string>`: Starts an activity, returns `activityId`.
|
|
68
|
+
- `LiveActivity.update(options: { activityId?: string; layout?: WidgetNode; dynamicIsland?: ... }): Promise<void>`
|
|
69
|
+
- `LiveActivity.end(options: { activityId?: string; dismissalPolicy?: 'immediate'|'default' }): Promise<void>`
|
|
70
|
+
- `LiveActivity.endAll(): Promise<void>`
|
|
71
|
+
- `LiveActivity.getAllPushTokens(): Promise<{ devicePushToken: string; pushToStartToken: string; activityUpdateToken: string }>`
|
|
72
|
+
- `LiveActivity.registerActionHandler(handler: (actionId: string, payload?: any) => void): () => void`
|
|
73
|
+
- `Widget.setLayout(widgetKey: string, config: WidgetLayoutConfig, appGroup?: string): Promise<void>`
|
|
74
|
+
- `Widget.reload(widgetKey?: string): Promise<void>`
|
|
75
|
+
- `Widget.reloadAll(): Promise<void>`
|
|
76
|
+
- `Widget.setRemoteConfig(config: WidgetRemoteConfig, widgetKey?: string, appGroup?: string): Promise<void>`
|
|
77
|
+
- `Widget.requestPin(): Promise<boolean>`: Android only.
|
|
78
|
+
- `SharedStorage.setAppGroup(appGroup: string): void`
|
|
79
|
+
- `SharedStorage.set(key: string, value: string, appGroup?: string): Promise<void>`
|
|
80
|
+
- `SharedStorage.get(key: string, appGroup?: string): Promise<string | null>`
|
|
81
|
+
- `SharedStorage.remove(key: string, appGroup?: string): Promise<void>`
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## 3. Complete Declarative UI Engine (`UI.*`)
|
|
86
|
+
|
|
87
|
+
### Container Components
|
|
88
|
+
- `UI.VStack({ spacing, padding, backgroundColor, borderRadius, alignment: 'leading'|'center'|'trailing' }, ...children)`
|
|
89
|
+
- `UI.HStack({ spacing, padding, backgroundColor, borderRadius, alignment: 'top'|'center'|'bottom' }, ...children)`
|
|
90
|
+
- `UI.ZStack({ zAlignment: 'center'|'topLeading'|'bottomTrailing' }, ...children)`
|
|
91
|
+
- `UI.Grid({ columns: number, columnSpacing: number, rowSpacing: number }, ...children)`
|
|
92
|
+
- `UI.Divider({ color, thickness, marginVertical, marginHorizontal })`
|
|
93
|
+
|
|
94
|
+
### Content & Visual Components
|
|
95
|
+
- `UI.Text(content: string, options?: { color, fontSize, fontWeight: 'regular'|'medium'|'bold'|'heavy', maxLines, textAlign })`
|
|
96
|
+
- `UI.Image(options: { url?: string, base64?: string, systemName?: string, width: number, height: number, cornerRadius?: number, contentMode?: 'fill'|'fit', tintColor?: string })`
|
|
97
|
+
- `UI.Timer(timestampMs: number, options?: { mode: 'countdown'|'timer'|'relative', color?: string, fontSize?: number, fontWeight?: string, showsHours?: boolean })`: Zero-battery native clock.
|
|
98
|
+
- `UI.Progress(options: { style?: 'bar'|'segmented'|'circular', value?: number, segments?: number, currentSegment?: number, tintColor?: string, trackColor?: string, height?: number, showPercentage?: boolean })`
|
|
99
|
+
- `UI.Equalizer(options: { isPlaying: boolean, barCount?: number, tintColor?: string, height?: number, barWidth?: number, spacing?: number })`: Animated waveform.
|
|
100
|
+
- `UI.Badge(text: string, options?: { backgroundColor, textColor, fontSize, paddingHorizontal, paddingVertical, borderRadius })`
|
|
101
|
+
- `UI.Gauge(value: number, options?: { size, tintColor, trackColor, label, valueText, textColor, labelColor })`: 240° KPI Gauge.
|
|
102
|
+
- `UI.Chart(values: number[], options?: { style: 'bar'|'line', labels?: string[], tintColor, secondaryColor, labelColor, height })`
|
|
103
|
+
|
|
104
|
+
### Interactive Components
|
|
105
|
+
- `UI.Button(options: { title: string, actionId: string, backgroundColor?: string, activeBackgroundColor?: string, color?: string, activeColor?: string, fontSize?: number, paddingHorizontal?: number, paddingVertical?: number, borderRadius?: number })`
|
|
106
|
+
- `UI.Toggle(options: { isOn: boolean, actionId: string, onColor?: string, offColor?: string })`
|
|
107
|
+
- `UI.Link(options: { deepLink: string, padding?: number, backgroundColor?: string, borderRadius?: number }, ...children)`
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
## 4. Production Architectural Guidelines
|
|
112
|
+
|
|
113
|
+
1. **App Termination (Force-Kill)**:
|
|
114
|
+
When an iOS app is terminated from the App Switcher, Hermes/JSC is killed. Widget interactions run purely in native Swift. Do not design critical flows (such as employee clock-ins or payments) expecting a TypeScript callback to fire when the app is dead. Instead, write to `SharedStorage` natively, and consume the queue upon app launch.
|
|
115
|
+
2. **Widget Budget Limits**:
|
|
116
|
+
iOS limits daily widget reloads (~40-70/day). Android Doze Mode batches periodic tasks. Use `Widget.setRemoteConfig` for general background polling, but use Server Push (APNs / FCM) for second-by-second updates.
|
|
117
|
+
3. **App Group Setup**:
|
|
118
|
+
The App Group string passed to `SharedStorage.setAppGroup('group.com.yourcompany.app')` must match the entitlement configured in Xcode and `app.json`.
|
package/docs/llms.txt
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# react-native-live-widgets
|
|
2
|
+
|
|
3
|
+
> The All-in-One declarative TypeScript engine for iOS Live Activities, Dynamic Island, and interactive Home Screen Widgets in React Native & Expo (iOS 16.1+ & Android 16).
|
|
4
|
+
|
|
5
|
+
Write 100% Declarative TypeScript (`UI.*`) in your React Native code. Automatically renders to native SwiftUI (WidgetKit) and Android High-DPI 2D Canvas without manually touching Xcode or Android Studio.
|
|
6
|
+
|
|
7
|
+
## Quick Reference for LLMs & AI Agents
|
|
8
|
+
|
|
9
|
+
### Core Modules
|
|
10
|
+
- `LiveActivity`: Start, update, end, and inspect lock screen Live Activities & Dynamic Island on iOS, and Promoted Live Updates (`Notification.ProgressStyle`) on Android.
|
|
11
|
+
- `Widget`: Set dynamic multi-page layouts (`pages`), configure background API polling (`setRemoteConfig`), trigger reload, and request in-app widget pinning (`requestPin` on Android).
|
|
12
|
+
- `SharedStorage`: Fast synchronous App Group (iOS) and SharedPreferences (Android) key-value bridge.
|
|
13
|
+
- `UI`: Declarative DSL builder (`UI.VStack`, `UI.HStack`, `UI.ZStack`, `UI.Text`, `UI.Button`, `UI.Progress`, `UI.Timer`, `UI.Equalizer`, `UI.Image`, `UI.Gauge`, `UI.Chart`).
|
|
14
|
+
|
|
15
|
+
### Installation & Scaffolding
|
|
16
|
+
- **Expo (SDK 50, 51, 52, 58+)**:
|
|
17
|
+
```bash
|
|
18
|
+
npx expo install react-native-live-widgets
|
|
19
|
+
# Add plugin in app.json with appGroup, enableLiveActivities
|
|
20
|
+
npx expo prebuild
|
|
21
|
+
npx react-native-live-widgets init --group group.com.yourcompany.app
|
|
22
|
+
```
|
|
23
|
+
- **Bare React Native CLI**:
|
|
24
|
+
```bash
|
|
25
|
+
npm install react-native-live-widgets
|
|
26
|
+
npx react-native-live-widgets init --group group.com.yourcompany.app
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Key Declarative UI DSL Methods
|
|
30
|
+
- `UI.VStack(options, ...children)` / `UI.HStack(options, ...children)`: Flex containers with `spacing`, `padding`, `backgroundColor`, `borderRadius`, `alignment`.
|
|
31
|
+
- `UI.Text(content, { color, fontSize, fontWeight: 'bold'|'heavy'|'medium'|'regular', maxLines })`
|
|
32
|
+
- `UI.Timer(timestampMs, { mode: 'countdown'|'timer'|'relative', color, fontSize })`: Zero-battery native hardware clock.
|
|
33
|
+
- `UI.Progress(options)`: Supports `style: 'bar' | 'segmented' | 'circular'`, `value` (0.0 to 1.0), `tintColor`, `trackColor`.
|
|
34
|
+
- `UI.Equalizer({ isPlaying: true, barCount: 4, tintColor, height })`: Realtime animated audio waveform on Dynamic Island & lock screen.
|
|
35
|
+
- `UI.Image({ url, base64, systemName, width, height, cornerRadius, contentMode })`: Auto-cached remote images, base64 data, or SF Symbols.
|
|
36
|
+
- `UI.Button({ title, actionId, backgroundColor, color, fontSize })`: Interactive widget button triggering `AppIntents` (iOS 17+) and `BroadcastReceiver` (Android).
|
|
37
|
+
- `UI.Gauge(value, { size, tintColor, trackColor, label, valueText })`: 240° KPI circular gauge.
|
|
38
|
+
- `UI.Chart(dataPoints, { style: 'bar'|'line', labels, tintColor, height })`: Lightweight trend sparklines.
|
|
39
|
+
|
|
40
|
+
### Bidirectional Two-Way Action Handling
|
|
41
|
+
```typescript
|
|
42
|
+
import { LiveActivity, Widget } from 'react-native-live-widgets';
|
|
43
|
+
|
|
44
|
+
// Listen to widget button interactions inside App.tsx
|
|
45
|
+
const unsubscribe = LiveActivity.registerActionHandler((actionId, payload) => {
|
|
46
|
+
if (actionId === 'INCREMENT') {
|
|
47
|
+
// Update local state and trigger widget redraw
|
|
48
|
+
Widget.reload('main');
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Golden Rules for AI Agents
|
|
54
|
+
1. **Never write Swift or Kotlin files manually** when a declarative `UI.*` node exists.
|
|
55
|
+
2. **App Groups**: Both iOS app and Widget Extension MUST share the identical App Group name (e.g. `group.<bundle_id>`).
|
|
56
|
+
3. **Dynamic Island**: Always configure `compactLeading`, `compactTrailing`, `minimal`, and `expanded` (`leading`, `trailing`, `bottom`, `center`).
|
|
57
|
+
4. **App Termination (Force-Kill)**: When the app is force-killed on iOS, JS runtime stops. Design mission-critical actions (like employee attendance check-ins) using native `SharedStorage` queue rather than expecting live JS callbacks while killed.
|
|
58
|
+
5. **Background Sync**: `Widget.setRemoteConfig` allows native widgets to fetch fresh JSON from a REST endpoint without requiring server-side APNs push infrastructure.
|
|
59
|
+
|
|
60
|
+
## Documentation Links
|
|
61
|
+
- [English Full Guide](https://github.com/React-Native-Vu/react-native-live-widgets/blob/dev/docs/GUIDE-EN.md)
|
|
62
|
+
- [Vietnamese Full Guide](https://github.com/React-Native-Vu/react-native-live-widgets/blob/dev/docs/GUIDE-VI.md)
|
|
63
|
+
- [Dedicated Expo Guide (EN)](https://github.com/React-Native-Vu/react-native-live-widgets/blob/dev/docs/EXPO-GUIDE-EN.md)
|
|
64
|
+
- [Dedicated Expo Guide (VI)](https://github.com/React-Native-Vu/react-native-live-widgets/blob/dev/docs/EXPO-GUIDE-VI.md)
|
|
65
|
+
- [Official Expo Demo Repo](https://github.com/React-Native-Vu/LiveWidgetsExampleExpo)
|
|
66
|
+
- [Official Bare RN Demo Repo](https://github.com/React-Native-Vu/LiveWidgetsExample)
|
package/lib/builder.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.UI = exports.StyleSheet = void 0;
|
|
4
|
-
exports.flattenStyle = flattenStyle;
|
|
5
|
-
const dispatcher_1 = require("./dispatcher");
|
|
1
|
+
import { registerAction } from './dispatcher';
|
|
6
2
|
let autoActionCounter = 0;
|
|
7
|
-
function flattenStyle(...styles) {
|
|
3
|
+
export function flattenStyle(...styles) {
|
|
8
4
|
let merged = undefined;
|
|
9
5
|
function walk(item) {
|
|
10
6
|
if (!item)
|
|
@@ -24,7 +20,7 @@ function flattenStyle(...styles) {
|
|
|
24
20
|
}
|
|
25
21
|
return merged;
|
|
26
22
|
}
|
|
27
|
-
|
|
23
|
+
export const StyleSheet = {
|
|
28
24
|
create: (styles) => styles,
|
|
29
25
|
flatten: flattenStyle,
|
|
30
26
|
};
|
|
@@ -50,8 +46,8 @@ function parseContainerArgs(first, rest) {
|
|
|
50
46
|
/**
|
|
51
47
|
* Các hàm helper tạo node cây giao diện trực quan cho TypeScript/JavaScript
|
|
52
48
|
*/
|
|
53
|
-
|
|
54
|
-
StyleSheet
|
|
49
|
+
export const UI = {
|
|
50
|
+
StyleSheet,
|
|
55
51
|
VStack: (propsOrChildren, ...children) => {
|
|
56
52
|
const { props, children: parsedChildren } = parseContainerArgs(propsOrChildren, children);
|
|
57
53
|
return {
|
|
@@ -131,10 +127,10 @@ exports.UI = {
|
|
|
131
127
|
if (titleOrProps.onPress && !titleOrProps.actionId) {
|
|
132
128
|
autoActionCounter += 1;
|
|
133
129
|
titleOrProps.actionId = `act_${Date.now()}_${autoActionCounter}`;
|
|
134
|
-
|
|
130
|
+
registerAction(titleOrProps.actionId, titleOrProps.onPress);
|
|
135
131
|
}
|
|
136
132
|
else if (titleOrProps.onPress && titleOrProps.actionId) {
|
|
137
|
-
|
|
133
|
+
registerAction(titleOrProps.actionId, titleOrProps.onPress);
|
|
138
134
|
}
|
|
139
135
|
return {
|
|
140
136
|
type: 'Button',
|
|
@@ -147,7 +143,7 @@ exports.UI = {
|
|
|
147
143
|
autoActionCounter += 1;
|
|
148
144
|
finalActionId = `act_${Date.now()}_${autoActionCounter}`;
|
|
149
145
|
}
|
|
150
|
-
|
|
146
|
+
registerAction(finalActionId, options.onPress);
|
|
151
147
|
}
|
|
152
148
|
return {
|
|
153
149
|
type: 'Button',
|
|
@@ -165,7 +161,7 @@ exports.UI = {
|
|
|
165
161
|
ActionButton: (title, onPress, options) => {
|
|
166
162
|
autoActionCounter += 1;
|
|
167
163
|
const actionId = `act_${Date.now()}_${autoActionCounter}`;
|
|
168
|
-
|
|
164
|
+
registerAction(actionId, onPress);
|
|
169
165
|
return {
|
|
170
166
|
type: 'Button',
|
|
171
167
|
props: {
|
package/lib/builder.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"builder.js","sourceRoot":"","sources":["../src/builder.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"builder.js","sourceRoot":"","sources":["../src/builder.ts"],"names":[],"mappings":"AA4BA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C,IAAI,iBAAiB,GAAG,CAAC,CAAC;AAE1B,MAAM,UAAU,YAAY,CAAmB,GAAG,MAAsB;IACtE,IAAI,MAAM,GAAQ,SAAS,CAAC;IAE5B,SAAS,IAAI,CAAC,IAAS;QACrB,IAAI,CAAC,IAAI;YAAE,OAAO;QAClB,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;YACxB,KAAK,MAAM,GAAG,IAAI,IAAI;gBAAE,IAAI,CAAC,GAAG,CAAC,CAAC;QACpC,CAAC;aAAM,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;YACpC,IAAI,CAAC,MAAM;gBAAE,MAAM,GAAG,EAAE,CAAC;YACzB,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QAC9B,CAAC;IACH,CAAC;IAED,KAAK,MAAM,CAAC,IAAI,MAAM,EAAE,CAAC;QACvB,IAAI,CAAC,CAAC,CAAC,CAAC;IACV,CAAC;IACD,OAAO,MAAuB,CAAC;AACjC,CAAC;AAQD,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,MAAM,EAAE,CAA8C,MAA4B,EAAK,EAAE,CAAC,MAAM;IAChG,OAAO,EAAE,YAAY;CACtB,CAAC;AAEF,SAAS,YAAY,CAAC,IAAS;IAC7B,OAAO,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,OAAO,IAAI,CAAC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;YACd,KAAK,EAAE,cAAc;SACtB,CAAC;IACJ,CAAC;IAED,KAAK,EAAE,CACL,aAA0C,EAC1C,OAA0C,EAC/B,EAAE;QACb,IAAI,OAAO,aAAa,KAAK,QAAQ,EAAE,CAAC;YACtC,OAAO;gBACL,IAAI,EAAE,OAAO;gBACb,KAAK,EAAE;oBACL,IAAI,EAAE,aAAa;oBACnB,GAAG,OAAO;iBACX;aACF,CAAC;QACJ,CAAC;QACD,OAAO;YACL,IAAI,EAAE,OAAO;YACb,KAAK,EAAE,aAAa;SACrB,CAAC;IACJ,CAAC;IAED,IAAI,EAAE,CACJ,KAAgB,EAChB,GAAG,QAAsB,EACf,EAAE,CAAC,CAAC;QACd,IAAI,EAAE,MAAM;QACZ,KAAK;QACL,QAAQ;KACT,CAAC;IAEF;;;;OAIG;IACH,MAAM,EAAE,CACN,aAAqB,EACrB,KAA2B,EAC3B,GAAG,QAAsB,EACb,EAAE,CAAC,CAAC;QAChB,IAAI,EAAE,QAAQ;QACd,KAAK,EAAE;YACL,GAAG,KAAK;YACR,aAAa;SACd;QACD,QAAQ,EAAE,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS;KACrD,CAAC;IAEF;;;;OAIG;IACH,SAAS,EAAE,CAAC,OAAwB,EAAiB,EAAE,CAAC,CAAC;QACvD,IAAI,EAAE,WAAW;QACjB,KAAK,EAAE;YACL,SAAS,EAAE,IAAI;YACf,QAAQ,EAAE,CAAC;YACX,SAAS,EAAE,SAAS;YACpB,MAAM,EAAE,EAAE;YACV,QAAQ,EAAE,CAAC;YACX,OAAO,EAAE,CAAC;YACV,GAAG,OAAO;SACX;KACF,CAAC;CACH,CAAC"}
|
package/lib/dispatcher.js
CHANGED
|
@@ -1,23 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.actionHandlers = void 0;
|
|
4
|
-
exports.registerAction = registerAction;
|
|
5
|
-
exports.unregisterAction = unregisterAction;
|
|
6
|
-
exports.actionHandlers = new Map();
|
|
1
|
+
export const actionHandlers = new Map();
|
|
7
2
|
/**
|
|
8
3
|
* Đăng ký một hàm xử lý logic TypeScript khi người dùng bấm nút có `actionId` tương ứng ngoài Widget/Live Activity.
|
|
9
4
|
* Trả về hàm hủy đăng ký (unsubscribe).
|
|
10
5
|
*/
|
|
11
|
-
function registerAction(actionId, handler) {
|
|
12
|
-
|
|
6
|
+
export function registerAction(actionId, handler) {
|
|
7
|
+
actionHandlers.set(actionId, handler);
|
|
13
8
|
return () => {
|
|
14
|
-
|
|
9
|
+
actionHandlers.delete(actionId);
|
|
15
10
|
};
|
|
16
11
|
}
|
|
17
12
|
/**
|
|
18
13
|
* Hủy đăng ký action handler.
|
|
19
14
|
*/
|
|
20
|
-
function unregisterAction(actionId) {
|
|
21
|
-
|
|
15
|
+
export function unregisterAction(actionId) {
|
|
16
|
+
actionHandlers.delete(actionId);
|
|
22
17
|
}
|
|
23
18
|
//# sourceMappingURL=dispatcher.js.map
|
package/lib/dispatcher.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dispatcher.js","sourceRoot":"","sources":["../src/dispatcher.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"dispatcher.js","sourceRoot":"","sources":["../src/dispatcher.ts"],"names":[],"mappings":"AAMA,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,GAAG,EAAyB,CAAC;AAE/D;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,QAAgB,EAAE,OAAsB;IACrE,cAAc,CAAC,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACtC,OAAO,GAAG,EAAE;QACV,cAAc,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAClC,CAAC,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,QAAgB;IAC/C,cAAc,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;AAClC,CAAC"}
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,sBAAsB,EACtB,oBAAoB,EACpB,qBAAqB,EACrB,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,oBAAoB,EACrB,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,sBAAsB,EACtB,oBAAoB,EACpB,qBAAqB,EACrB,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,oBAAoB,EACrB,MAAM,SAAS,CAAC;AAsBjB,OAAO,EAAE,aAAa,EAAkB,cAAc,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAC/F,YAAY,EAAE,aAAa,EAAE,CAAC;AAC9B,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,CAAC;AAoB5C,eAAO,MAAM,YAAY;IACvB;;OAEG;qBACoB,oBAAoB,KAAG,OAAO,CAAC,OAAO,CAAC;IAW9D;;OAEG;sBACqB,qBAAqB,KAAG,OAAO,CAAC,OAAO,CAAC;IAWhE;;OAEG;sBACqB,MAAM,YAAY,kBAAkB,KAAG,OAAO,CAAC,OAAO,CAAC;IA4B/E;;OAEG;kBACe,OAAO,CAAC,OAAO,CAAC;IAUlC;;OAEG;8BAC2B,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAYzD;;OAEG;+BAC4B,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAY1D;;;OAGG;uCACsC,MAAM,KAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAY7E;;;;;OAKG;oCACmC,MAAM,KAAG,OAAO,CAAC,sB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EG;gBACa,OAAO,CAAC,OAAO,CAAC;IAUhC;;OAEG;qBACkB,OAAO,CAAC,iBAAiB,CAAC;CAUhD,CAAC;AAEF,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -1,42 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.StyleSheet = exports.AudioPlayer = exports.SharedStorage = exports.Widget = exports.LiveActivity = exports.unregisterAction = exports.registerAction = void 0;
|
|
18
|
-
const react_native_1 = require("react-native");
|
|
19
|
-
const { LiveActivityModule } = react_native_1.NativeModules;
|
|
20
|
-
if (!LiveActivityModule && __DEV__) {
|
|
1
|
+
import { AppRegistry, NativeEventEmitter, NativeModules, Platform } from 'react-native';
|
|
2
|
+
const { LiveActivityModule } = NativeModules;
|
|
3
|
+
if (!LiveActivityModule && typeof __DEV__ !== 'undefined' && __DEV__) {
|
|
21
4
|
console.warn('[react-native-live-widgets] Native module not found. ' +
|
|
22
5
|
'Please ensure you have run "npx react-native-live-widgets init" and re-compiled your app.');
|
|
23
6
|
}
|
|
24
7
|
const liveActivityEmitter = LiveActivityModule
|
|
25
|
-
? new
|
|
8
|
+
? new NativeEventEmitter(LiveActivityModule)
|
|
26
9
|
: null;
|
|
27
10
|
const DEVICE_TOKEN_CHANGED_EVENT = 'DevicePushTokenChanged';
|
|
28
11
|
const TOKEN_CHANGED_EVENT = 'LiveActivityTokenChanged';
|
|
29
12
|
const UPDATE_TOKEN_CHANGED_EVENT = 'LiveActivityUpdateTokenChanged';
|
|
30
13
|
const ACTION_CLICKED_EVENT = 'LiveActivityActionClicked';
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
Object.defineProperty(exports, "unregisterAction", { enumerable: true, get: function () { return dispatcher_1.unregisterAction; } });
|
|
14
|
+
import { actionHandlers, registerAction, unregisterAction } from './dispatcher';
|
|
15
|
+
export { registerAction, unregisterAction };
|
|
34
16
|
// Tự động lắng nghe action event từ Native để dispatch tới các hàm TypeScript đã đăng ký
|
|
35
17
|
if (liveActivityEmitter) {
|
|
36
18
|
liveActivityEmitter.addListener(ACTION_CLICKED_EVENT, async (event) => {
|
|
37
19
|
const actionId = event?.actionId || '';
|
|
38
20
|
const activityId = event?.activityId || '';
|
|
39
|
-
const handler =
|
|
21
|
+
const handler = actionHandlers.get(actionId);
|
|
40
22
|
if (handler) {
|
|
41
23
|
try {
|
|
42
24
|
await handler({ actionId, activityId });
|
|
@@ -48,7 +30,7 @@ if (liveActivityEmitter) {
|
|
|
48
30
|
});
|
|
49
31
|
}
|
|
50
32
|
// ─── 1. LIVE ACTIVITY & LIVE UPDATE ──────────────────────────────────────────
|
|
51
|
-
|
|
33
|
+
export const LiveActivity = {
|
|
52
34
|
/**
|
|
53
35
|
* Khởi động một Live Activity (iOS) hoặc Live Update / Ongoing Notification (Android).
|
|
54
36
|
*/
|
|
@@ -205,7 +187,9 @@ exports.LiveActivity = {
|
|
|
205
187
|
onDevicePushTokenChange: (listener) => {
|
|
206
188
|
if (!liveActivityEmitter)
|
|
207
189
|
return () => { };
|
|
208
|
-
const sub = liveActivityEmitter.addListener(DEVICE_TOKEN_CHANGED_EVENT,
|
|
190
|
+
const sub = liveActivityEmitter.addListener(DEVICE_TOKEN_CHANGED_EVENT, (token) => {
|
|
191
|
+
listener(typeof token === 'string' ? token : String(token ?? ''));
|
|
192
|
+
});
|
|
209
193
|
return () => sub.remove();
|
|
210
194
|
},
|
|
211
195
|
/**
|
|
@@ -214,7 +198,9 @@ exports.LiveActivity = {
|
|
|
214
198
|
onPushToStartTokenChange: (listener) => {
|
|
215
199
|
if (!liveActivityEmitter)
|
|
216
200
|
return () => { };
|
|
217
|
-
const sub = liveActivityEmitter.addListener(TOKEN_CHANGED_EVENT,
|
|
201
|
+
const sub = liveActivityEmitter.addListener(TOKEN_CHANGED_EVENT, (token) => {
|
|
202
|
+
listener(typeof token === 'string' ? token : String(token ?? ''));
|
|
203
|
+
});
|
|
218
204
|
return () => sub.remove();
|
|
219
205
|
},
|
|
220
206
|
/**
|
|
@@ -224,7 +210,9 @@ exports.LiveActivity = {
|
|
|
224
210
|
onActivityUpdateTokenChange: (listener) => {
|
|
225
211
|
if (!liveActivityEmitter)
|
|
226
212
|
return () => { };
|
|
227
|
-
const sub = liveActivityEmitter.addListener(UPDATE_TOKEN_CHANGED_EVENT,
|
|
213
|
+
const sub = liveActivityEmitter.addListener(UPDATE_TOKEN_CHANGED_EVENT, (event) => {
|
|
214
|
+
listener(event);
|
|
215
|
+
});
|
|
228
216
|
return () => sub.remove();
|
|
229
217
|
},
|
|
230
218
|
/**
|
|
@@ -233,16 +221,16 @@ exports.LiveActivity = {
|
|
|
233
221
|
* Trả về hàm hủy đăng ký (unsubscribe).
|
|
234
222
|
*/
|
|
235
223
|
registerAction: (actionId, handler) => {
|
|
236
|
-
|
|
224
|
+
actionHandlers.set(actionId, handler);
|
|
237
225
|
return () => {
|
|
238
|
-
|
|
226
|
+
actionHandlers.delete(actionId);
|
|
239
227
|
};
|
|
240
228
|
},
|
|
241
229
|
/**
|
|
242
230
|
* Hủy đăng ký action handler theo `actionId`.
|
|
243
231
|
*/
|
|
244
232
|
unregisterAction: (actionId) => {
|
|
245
|
-
|
|
233
|
+
actionHandlers.delete(actionId);
|
|
246
234
|
},
|
|
247
235
|
/**
|
|
248
236
|
* Lấy danh sách các phiên Live Activity đang chạy trên thiết bị (ID và Push Token).
|
|
@@ -307,7 +295,7 @@ exports.LiveActivity = {
|
|
|
307
295
|
* Android 16+: Kiểm tra quyền Promoted Ongoing Notifications.
|
|
308
296
|
*/
|
|
309
297
|
canPostPromoted: async () => {
|
|
310
|
-
if (
|
|
298
|
+
if (Platform.OS !== 'android' || !LiveActivityModule?.canPostPromoted) {
|
|
311
299
|
return false;
|
|
312
300
|
}
|
|
313
301
|
return await LiveActivityModule.canPostPromoted();
|
|
@@ -317,15 +305,15 @@ exports.LiveActivity = {
|
|
|
317
305
|
* Hoạt động ngay cả khi App chính đã bị người dùng vuốt đóng (Killed).
|
|
318
306
|
*/
|
|
319
307
|
registerBackgroundActionHandler: (handler) => {
|
|
320
|
-
if (
|
|
308
|
+
if (Platform.OS === 'android') {
|
|
321
309
|
try {
|
|
322
|
-
|
|
310
|
+
AppRegistry.registerHeadlessTask('LiveActivityBackgroundTask', () => async (taskData) => {
|
|
323
311
|
const actionId = taskData?.actionId || '';
|
|
324
312
|
const activityId = taskData?.activityId || '';
|
|
325
313
|
if (handler) {
|
|
326
314
|
await handler(actionId, activityId);
|
|
327
315
|
}
|
|
328
|
-
const registered =
|
|
316
|
+
const registered = actionHandlers.get(actionId);
|
|
329
317
|
if (registered) {
|
|
330
318
|
await registered({ actionId, activityId });
|
|
331
319
|
}
|
|
@@ -338,7 +326,7 @@ exports.LiveActivity = {
|
|
|
338
326
|
},
|
|
339
327
|
};
|
|
340
328
|
// ─── 2. HOME SCREEN WIDGETS ──────────────────────────────────────────────────
|
|
341
|
-
|
|
329
|
+
export const Widget = {
|
|
342
330
|
/**
|
|
343
331
|
* Yêu cầu hệ điều hành iOS và Android vẽ lại toàn bộ Home Screen Widgets ngay lập tức.
|
|
344
332
|
*/
|
|
@@ -373,10 +361,10 @@ exports.Widget = {
|
|
|
373
361
|
*/
|
|
374
362
|
setLayout: async (widgetKey, layoutConfig, appGroup) => {
|
|
375
363
|
try {
|
|
376
|
-
const saved = await
|
|
364
|
+
const saved = await SharedStorage.set(`widget_layout_${widgetKey}`, layoutConfig, appGroup);
|
|
377
365
|
if (!saved)
|
|
378
366
|
return false;
|
|
379
|
-
return await
|
|
367
|
+
return await Widget.reloadAll();
|
|
380
368
|
}
|
|
381
369
|
catch (error) {
|
|
382
370
|
console.warn('[react-native-live-widgets] setLayout error:', error);
|
|
@@ -409,10 +397,10 @@ exports.Widget = {
|
|
|
409
397
|
: timelineConfig.afterDate
|
|
410
398
|
: undefined,
|
|
411
399
|
};
|
|
412
|
-
const saved = await
|
|
400
|
+
const saved = await SharedStorage.set(`widget_timeline_${widgetKey}`, formattedConfig, appGroup);
|
|
413
401
|
if (!saved)
|
|
414
402
|
return false;
|
|
415
|
-
return await
|
|
403
|
+
return await Widget.reloadAll();
|
|
416
404
|
}
|
|
417
405
|
catch (error) {
|
|
418
406
|
console.warn('[react-native-live-widgets] setTimeline error:', error);
|
|
@@ -424,20 +412,20 @@ exports.Widget = {
|
|
|
424
412
|
* Ví dụ: Danh sách các Dự án, Chi nhánh, Ca làm để người dùng chọn khi nhấn giữ Widget ngoài Home Screen.
|
|
425
413
|
*/
|
|
426
414
|
setConfigurationOptions: async (widgetKey, options, appGroup) => {
|
|
427
|
-
return await
|
|
415
|
+
return await SharedStorage.set(`widget_config_options_${widgetKey}`, options, appGroup);
|
|
428
416
|
},
|
|
429
417
|
/**
|
|
430
418
|
* Lấy ID tùy chọn cấu hình đang được người dùng chọn ghim trên Widget.
|
|
431
419
|
*/
|
|
432
420
|
getSelectedConfiguration: async (widgetKey, appGroup) => {
|
|
433
|
-
return await
|
|
421
|
+
return await SharedStorage.get(`widget_selected_config_${widgetKey}`, appGroup);
|
|
434
422
|
},
|
|
435
423
|
/**
|
|
436
424
|
* Thiết lập lựa chọn cấu hình cho Widget từ trong ứng dụng.
|
|
437
425
|
*/
|
|
438
426
|
setSelectedConfiguration: async (widgetKey, selectedId, appGroup) => {
|
|
439
|
-
const ok = await
|
|
440
|
-
await
|
|
427
|
+
const ok = await SharedStorage.set(`widget_selected_config_${widgetKey}`, selectedId, appGroup);
|
|
428
|
+
await Widget.reloadAll();
|
|
441
429
|
return ok;
|
|
442
430
|
},
|
|
443
431
|
/**
|
|
@@ -447,10 +435,10 @@ exports.Widget = {
|
|
|
447
435
|
*/
|
|
448
436
|
setRemoteConfig: async (widgetKey, remoteConfig, appGroup) => {
|
|
449
437
|
try {
|
|
450
|
-
const saved = await
|
|
438
|
+
const saved = await SharedStorage.set(`widget_remote_config_${widgetKey}`, remoteConfig, appGroup);
|
|
451
439
|
if (!saved)
|
|
452
440
|
return false;
|
|
453
|
-
return await
|
|
441
|
+
return await Widget.reloadAll();
|
|
454
442
|
}
|
|
455
443
|
catch (error) {
|
|
456
444
|
console.warn('[react-native-live-widgets] setRemoteConfig error:', error);
|
|
@@ -487,7 +475,7 @@ exports.Widget = {
|
|
|
487
475
|
},
|
|
488
476
|
};
|
|
489
477
|
// ─── 3. SHARED STORAGE (App Groups & SharedPreferences) ─────────────────────
|
|
490
|
-
|
|
478
|
+
export const SharedStorage = {
|
|
491
479
|
/**
|
|
492
480
|
* Lưu dữ liệu vào App Group (iOS) hoặc SharedPreferences (Android) để Widget đọc.
|
|
493
481
|
*/
|
|
@@ -554,7 +542,7 @@ exports.SharedStorage = {
|
|
|
554
542
|
}
|
|
555
543
|
},
|
|
556
544
|
};
|
|
557
|
-
|
|
545
|
+
export const AudioPlayer = {
|
|
558
546
|
/**
|
|
559
547
|
* Phát nhạc trực tiếp từ URL (hỗ trợ stream mp3, m4a, aac, wav...)
|
|
560
548
|
* và đăng ký hệ thống Now Playing của iOS (hiện trên Dynamic Island & Lock Screen như Spotify).
|
|
@@ -627,8 +615,7 @@ exports.AudioPlayer = {
|
|
|
627
615
|
}
|
|
628
616
|
},
|
|
629
617
|
};
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
Object.defineProperty(exports, "StyleSheet", { enumerable: true, get: function () { return builder_1.StyleSheet; } });
|
|
618
|
+
export * from './types';
|
|
619
|
+
export * from './builder';
|
|
620
|
+
export { StyleSheet } from './builder';
|
|
634
621
|
//# sourceMappingURL=index.js.map
|