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
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to `react-native-live-widgets` will be documented in this file.
|
|
4
4
|
|
|
5
|
+
## [1.1.1] - 2026-11-16
|
|
6
|
+
### Fixed
|
|
7
|
+
- **Android Widget Interaction Crash**: Added `android.permission.WAKE_LOCK` and safely wrapped `HeadlessJsTaskService` wake lock acquisition to prevent `SecurityException` on widget tap events.
|
|
8
|
+
- **Android Hit Zone Accuracy**: Upgraded `rn_live_widget_host.xml` to a dynamic 6-row x 3-column interaction grid (`rn_hit_r0_c0` - `rn_hit_r5_c2`), mapping button physical coordinates (`yFraction`, `xFraction`) accurately to fix misaligned tap zones.
|
|
9
|
+
- **Background Headless Responsiveness**: Added native state store handling and `LiveActivity.registerBackgroundActionHandler()` support for zero-latency widget interactions even when the app is swiped away or force-killed.
|
|
10
|
+
|
|
11
|
+
## [1.1.0] - 2026-11-16
|
|
12
|
+
### Added
|
|
13
|
+
- **Expo Config Plugin (`app.plugin.js`)**: Full Expo & EAS Build support (`npx expo prebuild` / `npx expo run:ios` / `npx expo run:android`). Automatically configures `NSSupportsLiveActivities` and `NSSupportsLiveActivitiesFrequentUpdates` in iOS `Info.plist`, App Groups entitlements, and Android notifications & foreground service permissions.
|
|
14
|
+
|
|
15
|
+
### Fixed
|
|
16
|
+
- **TypeScript Module Resolution**: Fixed `error TS7016` when resolving React Native package exports by updating to `moduleResolution: bundler` and `module: ES2020`.
|
|
17
|
+
- **Global `__DEV__` Declaration**: Fixed `error TS2304: Cannot find name '__DEV__'` with safe typing and fallback checks.
|
|
18
|
+
|
|
5
19
|
## [1.0.0] - 2026-11-15
|
|
6
20
|
### Added
|
|
7
21
|
- **Declarative UI Engine (`UI.*`)**: Build Home Screen Widgets (`small`, `medium`, `large`) and Live Activities (`lockScreen`, `dynamicIsland`) 100% in React Native using `UI.VStack`, `UI.HStack`, `UI.Text`, `UI.Timer`, `UI.Progress` (`bar`, `segmented`, `circular`), `UI.Image`, and `UI.Button`.
|
package/README.md
CHANGED
|
@@ -2,27 +2,86 @@
|
|
|
2
2
|
|
|
3
3
|
<div align="center">
|
|
4
4
|
|
|
5
|
-
[](https://www.npmjs.com/package/react-native-live-widgets)
|
|
6
|
+
[](https://expo.dev)
|
|
7
|
+
[](https://react-native-vu.github.io/react-native-live-widgets/)
|
|
8
|
+
[](https://react-native-vu.github.io/react-native-live-widgets/llms.txt)
|
|
6
9
|
[](https://github.com/React-Native-Vu/react-native-live-widgets)
|
|
7
10
|
[](https://www.typescriptlang.org/)
|
|
8
11
|
[](LICENSE)
|
|
9
12
|
|
|
10
|
-
**The Ultimate All-in-One Engine for Live Activities, Dynamic Island, and Interactive Home Screen Widgets in
|
|
13
|
+
**The Ultimate All-in-One Engine for Live Activities, Dynamic Island, and Interactive Home Screen Widgets in React Native & Expo.**
|
|
11
14
|
|
|
12
|
-
*Write 100% Declarative TypeScript. Render dynamically to Native SwiftUI & Android 2D Canvas without touching Xcode or Android Studio.*
|
|
15
|
+
*Write 100% Declarative TypeScript. Render dynamically to Native SwiftUI (WidgetKit) & Android 2D Canvas without touching Xcode or Android Studio.*
|
|
13
16
|
|
|
14
|
-
[📖 English Guide](docs/GUIDE-EN.md) • [🇻🇳 Hướng dẫn Tiếng Việt](docs/GUIDE-VI.md) • [
|
|
17
|
+
[🌐 Docs Website](https://react-native-vu.github.io/react-native-live-widgets/) • [🤖 llms.txt](https://react-native-vu.github.io/react-native-live-widgets/llms.txt) • [🧠 AI Agent Skill](skills/react-native-live-widgets/SKILL.md) • [📖 English Guide](docs/GUIDE-EN.md) • [🇻🇳 Hướng dẫn Tiếng Việt](docs/GUIDE-VI.md) • [⚡ Expo Guide](docs/EXPO-GUIDE-VI.md) • [📱 Bare RN Demo](https://github.com/React-Native-Vu/LiveWidgetsExample) • [⚡ Expo Demo](https://github.com/React-Native-Vu/LiveWidgetsExampleExpo)
|
|
15
18
|
|
|
16
19
|
---
|
|
17
20
|
|
|
18
21
|
</div>
|
|
19
22
|
|
|
23
|
+
## 📱 Live Demo Example Apps
|
|
24
|
+
|
|
25
|
+
Full, ready-to-run demo applications are available on GitHub for both architectures:
|
|
26
|
+
|
|
27
|
+
| Platform | Repository | Description |
|
|
28
|
+
| :--- | :--- | :--- |
|
|
29
|
+
| **⚛️ Bare React Native CLI** | 👉 **[React-Native-Vu/LiveWidgetsExample](https://github.com/React-Native-Vu/LiveWidgetsExample)** | Full Xcode Widget Extension & Android Studio setup |
|
|
30
|
+
| **🚀 Expo (SDK 58 / CNG)** | 👉 **[React-Native-Vu/LiveWidgetsExampleExpo](https://github.com/React-Native-Vu/LiveWidgetsExampleExpo)** | Continuous Native Generation via Expo Config Plugin |
|
|
31
|
+
|
|
32
|
+
### ✨ Highlights of Both Demos:
|
|
33
|
+
- 🚀 **100% Pre-configured**: Xcode App Groups, `WidgetExtension`, and Android `AppWidgetProvider` ready out of the box.
|
|
34
|
+
- 🎨 **5 Real-world Presets**:
|
|
35
|
+
1. **Executive KPI Dashboard**: Live sales sync, circular progress ring, and weekly chart.
|
|
36
|
+
2. **Coffee Delivery Tracker**: Dynamic Island countdown and delivery driver status.
|
|
37
|
+
3. **Interactive Task Checklist**: Check off items right from your Home Screen without opening the app.
|
|
38
|
+
4. **Music & Audio Player**: Dynamic Island equalizer animation and lock screen media style.
|
|
39
|
+
5. **Flight Status**: Real-time gate, departure time, and airport progress bar.
|
|
40
|
+
- 🔄 **Bidirectional Real-Time Sync**: Instant state updates between Main App and WidgetKit.
|
|
41
|
+
|
|
42
|
+
#### 1. Clone & Run Bare React Native Demo:
|
|
43
|
+
```bash
|
|
44
|
+
git clone https://github.com/React-Native-Vu/LiveWidgetsExample.git
|
|
45
|
+
cd LiveWidgetsExample && npm install
|
|
46
|
+
npx react-native run-ios # or npx react-native run-android
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
#### 2. Clone & Run Expo Demo:
|
|
50
|
+
```bash
|
|
51
|
+
git clone https://github.com/React-Native-Vu/LiveWidgetsExampleExpo.git
|
|
52
|
+
cd LiveWidgetsExampleExpo && npm install
|
|
53
|
+
npx expo prebuild
|
|
54
|
+
npx expo run:ios # or npx expo run:android
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
20
59
|
## 📸 Showcase & Demos
|
|
21
60
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
61
|
+
<div align="center">
|
|
62
|
+
<table>
|
|
63
|
+
<tr>
|
|
64
|
+
<td width="50%" align="center">
|
|
65
|
+
<b>🏝️ Dynamic Island Expanded & KPI Dashboard</b><br/><br/>
|
|
66
|
+
<img src="assets/dynamic_island_expanded.png" alt="Dynamic Island Expanded" width="380" />
|
|
67
|
+
</td>
|
|
68
|
+
<td width="50%" align="center">
|
|
69
|
+
<b>📱 Interactive Home Screen Widget (iOS)</b><br/><br/>
|
|
70
|
+
<img src="assets/home_widget_interactive.png" alt="Home Screen Widget Interactive" width="380" />
|
|
71
|
+
</td>
|
|
72
|
+
</tr>
|
|
73
|
+
<tr>
|
|
74
|
+
<td width="50%" align="center">
|
|
75
|
+
<b>🔒 Lock Screen Live Activity & Gauges</b><br/><br/>
|
|
76
|
+
<img src="assets/lock_screen_live_activity.png" alt="Lock Screen Live Activity" width="380" />
|
|
77
|
+
</td>
|
|
78
|
+
<td width="50%" align="center">
|
|
79
|
+
<b>🤖 100% Feature Parity (Android & iOS)</b><br/><br/>
|
|
80
|
+
<img src="assets/cross_platform_parity.png" alt="Cross Platform Parity" width="380" />
|
|
81
|
+
</td>
|
|
82
|
+
</tr>
|
|
83
|
+
</table>
|
|
84
|
+
</div>
|
|
26
85
|
|
|
27
86
|
---
|
|
28
87
|
|
|
@@ -32,7 +91,8 @@ Until now, adding **Live Activities** or **Home Screen Widgets** to a React Nati
|
|
|
32
91
|
|
|
33
92
|
`react-native-live-widgets` solves this with a **Declarative TypeScript UI DSL**:
|
|
34
93
|
- 🚫 **No SwiftUI / Kotlin coding required** for custom screens.
|
|
35
|
-
- 🎨 **100% Declarative UI in React Native (`UI.VStack`, `UI.HStack`, `UI.Text`, `UI.Button`, `UI.Progress`)**.
|
|
94
|
+
- 🎨 **100% Declarative UI in React Native (`UI.VStack`, `UI.HStack`, `UI.Text`, `UI.Button`, `UI.Progress`, `UI.Image`)**.
|
|
95
|
+
- 🚀 **Full Expo & EAS Build Support** via automated Expo Config Plugin (`app.plugin.js`).
|
|
36
96
|
- ⚡ **Interactive Buttons**: Tap buttons on the Home Screen Widget to run native Swift extensions or wake up TypeScript handlers.
|
|
37
97
|
- 🔄 **Realtime Data Sync (`SharedStorage`)**: Single source of truth across Main App, Lock Screen, and Home Screen.
|
|
38
98
|
- 🌐 **Silent Background Remote API Sync**: Automatically fetch REST APIs and update Widgets even when the App is **Force-Killed**.
|
|
@@ -56,8 +116,9 @@ Until now, adding **Live Activities** or **Home Screen Widgets** to a React Nati
|
|
|
56
116
|
### 3. ⚡ Bi-directional Action Dispatcher (TypeScript + Native)
|
|
57
117
|
- Tap a widget button outside on the Home Screen to trigger a registered TypeScript function:
|
|
58
118
|
```ts
|
|
59
|
-
LiveActivity.registerAction('action_checkin', async () => {
|
|
119
|
+
LiveActivity.registerAction('action_checkin', async (payload) => {
|
|
60
120
|
// Runs inside React Native JS engine!
|
|
121
|
+
console.log('Action triggered from Home Screen Widget:', payload);
|
|
61
122
|
});
|
|
62
123
|
```
|
|
63
124
|
- **App-Killed Protection**: Native fallback ensures UI responds instantly and persists data even if the main app is terminated.
|
|
@@ -82,9 +143,6 @@ Until now, adding **Live Activities** or **Home Screen Widgets** to a React Nati
|
|
|
82
143
|
// tokens.activityUpdateToken
|
|
83
144
|
```
|
|
84
145
|
|
|
85
|
-
### 6. 🎵 Background Audio & Media Notification
|
|
86
|
-
- Integrated with `MPNowPlayingInfoCenter` on iOS and `MediaStyle` Notifications on Android for audio playback status.
|
|
87
|
-
|
|
88
146
|
---
|
|
89
147
|
|
|
90
148
|
## ⚡ Quick Start
|
|
@@ -92,12 +150,56 @@ Until now, adding **Live Activities** or **Home Screen Widgets** to a React Nati
|
|
|
92
150
|
### 1. Installation
|
|
93
151
|
|
|
94
152
|
```bash
|
|
153
|
+
# React Native CLI
|
|
95
154
|
npm install react-native-live-widgets
|
|
96
|
-
|
|
97
|
-
|
|
155
|
+
|
|
156
|
+
# Expo (Managed or Bare)
|
|
157
|
+
npx expo install react-native-live-widgets
|
|
98
158
|
```
|
|
99
159
|
|
|
100
|
-
|
|
160
|
+
---
|
|
161
|
+
|
|
162
|
+
### 2. Configuration
|
|
163
|
+
|
|
164
|
+
#### A. If using Expo (Config Plugin)
|
|
165
|
+
|
|
166
|
+
Add `react-native-live-widgets` to your `app.json` or `app.config.js`:
|
|
167
|
+
|
|
168
|
+
```json
|
|
169
|
+
{
|
|
170
|
+
"expo": {
|
|
171
|
+
"name": "My Expo App",
|
|
172
|
+
"plugins": [
|
|
173
|
+
[
|
|
174
|
+
"react-native-live-widgets",
|
|
175
|
+
{
|
|
176
|
+
"appGroup": "group.com.yourcompany.app",
|
|
177
|
+
"enableLiveActivities": true,
|
|
178
|
+
"frequentUpdates": true
|
|
179
|
+
}
|
|
180
|
+
]
|
|
181
|
+
]
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
Then generate native projects or run with Expo Dev Client:
|
|
187
|
+
|
|
188
|
+
```bash
|
|
189
|
+
# 1. Generate native folders
|
|
190
|
+
npx expo prebuild
|
|
191
|
+
|
|
192
|
+
# 2. Automatically scaffold & link Xcode Widget Extension target
|
|
193
|
+
npx react-native-live-widgets init --group group.com.yourcompany.app
|
|
194
|
+
|
|
195
|
+
# 3. Run on iOS Simulator & Android Emulator:
|
|
196
|
+
npx expo run:ios
|
|
197
|
+
npx expo run:android
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
> 📖 **Detailed Step-by-Step Expo Guide**: [English](docs/EXPO-GUIDE-EN.md) • [Tiếng Việt](docs/EXPO-GUIDE-VI.md)
|
|
201
|
+
|
|
202
|
+
#### B. If using Bare React Native CLI
|
|
101
203
|
|
|
102
204
|
Run the automated scaffolding script in your React Native project root:
|
|
103
205
|
|
|
@@ -110,7 +212,7 @@ This will automatically:
|
|
|
110
212
|
- Scaffold the `LiveWidgetsExtension` bundle in your `ios/` folder.
|
|
111
213
|
- Configure `AndroidManifest.xml` with required notification permissions.
|
|
112
214
|
|
|
113
|
-
|
|
215
|
+
And install CocoaPods dependencies:
|
|
114
216
|
|
|
115
217
|
```bash
|
|
116
218
|
cd ios && pod install
|
|
@@ -126,51 +228,79 @@ cd ios && pod install
|
|
|
126
228
|
import { UI, LiveActivity } from 'react-native-live-widgets';
|
|
127
229
|
|
|
128
230
|
await LiveActivity.start({
|
|
129
|
-
activityId: '
|
|
231
|
+
activityId: 'kpi_q4_2026',
|
|
130
232
|
dynamicIsland: {
|
|
131
|
-
compactLeading: UI.
|
|
132
|
-
compactTrailing: UI.Text('
|
|
133
|
-
minimal: UI.
|
|
233
|
+
compactLeading: UI.Text('KPI Q4', { color: '#38BDF8', fontWeight: 'bold' }),
|
|
234
|
+
compactTrailing: UI.Text('86%', { color: '#10B981', fontWeight: 'bold' }),
|
|
235
|
+
minimal: UI.Text('86%', { color: '#10B981' }),
|
|
134
236
|
expanded: UI.VStack(
|
|
135
|
-
{ padding: 14, spacing: 8 },
|
|
237
|
+
{ padding: 14, spacing: 8, backgroundColor: '#0F172A' },
|
|
136
238
|
UI.HStack(
|
|
137
239
|
{ justifyContent: 'spaceBetween' },
|
|
138
|
-
UI.Text('
|
|
139
|
-
UI.Badge({ text: '
|
|
240
|
+
UI.Text('BẢNG ĐIỀU HÀNH KPI', { fontSize: 11, color: '#94A3B8' }),
|
|
241
|
+
UI.Badge({ text: '86% Hoàn thành', backgroundColor: '#064E3B', textColor: '#6EE7B7' })
|
|
140
242
|
),
|
|
141
|
-
UI.Text('
|
|
243
|
+
UI.Text('Mục tiêu Q4/2026', { fontSize: 16, fontWeight: 'bold', color: '#FFFFFF' }),
|
|
142
244
|
UI.Progress({
|
|
143
245
|
style: 'bar',
|
|
144
|
-
value: 0.
|
|
246
|
+
value: 0.86,
|
|
145
247
|
tintColor: '#10B981',
|
|
146
248
|
trackColor: '#334155'
|
|
147
|
-
})
|
|
249
|
+
}),
|
|
250
|
+
UI.Text('Doanh số 12.8 tỷ / 15 tỷ VNĐ • Tăng trưởng +22%', { fontSize: 12, color: '#94A3B8' })
|
|
148
251
|
)
|
|
149
252
|
},
|
|
150
253
|
lockScreen: UI.VStack(
|
|
151
|
-
{ padding: 16, backgroundColor: '#0F172A' },
|
|
152
|
-
UI.
|
|
153
|
-
|
|
254
|
+
{ padding: 16, backgroundColor: '#0F172A', cornerRadius: 16 },
|
|
255
|
+
UI.HStack(
|
|
256
|
+
{ justifyContent: 'spaceBetween' },
|
|
257
|
+
UI.Text('KPI Quý 4: Đạt 86% mục tiêu', { fontSize: 14, fontWeight: 'bold', color: '#FFFFFF' }),
|
|
258
|
+
UI.Badge({ text: '+18%', backgroundColor: '#064E3B', textColor: '#6EE7B7' })
|
|
259
|
+
),
|
|
260
|
+
UI.Progress({
|
|
261
|
+
style: 'segmented',
|
|
262
|
+
segments: 7,
|
|
263
|
+
currentSegment: 6,
|
|
264
|
+
tintColor: '#38BDF8',
|
|
265
|
+
trackColor: '#1E293B'
|
|
266
|
+
})
|
|
154
267
|
)
|
|
155
268
|
});
|
|
156
269
|
```
|
|
157
270
|
|
|
158
|
-
### 2.
|
|
271
|
+
### 2. Configure Home Screen Widget with Live Sync
|
|
159
272
|
|
|
160
273
|
```tsx
|
|
161
|
-
import { UI, Widget } from 'react-native-live-widgets';
|
|
274
|
+
import { UI, Widget, SharedStorage } from 'react-native-live-widgets';
|
|
162
275
|
|
|
163
276
|
const APP_GROUP = 'group.com.yourcompany.app';
|
|
164
277
|
|
|
278
|
+
// Set shared data
|
|
279
|
+
await SharedStorage.set('kpi_percent', '86', APP_GROUP);
|
|
280
|
+
await SharedStorage.set('revenue_month', '4.85 Tỷ đ', APP_GROUP);
|
|
281
|
+
|
|
282
|
+
// Build Declarative Layout
|
|
165
283
|
await Widget.setLayout('main', {
|
|
166
|
-
|
|
167
|
-
{ padding:
|
|
168
|
-
UI.
|
|
169
|
-
|
|
284
|
+
large: UI.VStack(
|
|
285
|
+
{ padding: 16, backgroundColor: '#0B132B', cornerRadius: 20 },
|
|
286
|
+
UI.HStack(
|
|
287
|
+
{ justifyContent: 'spaceBetween' },
|
|
288
|
+
UI.Text('TỔNG QUAN ĐIỀU HÀNH (KPI & BIỂU ĐỒ)', { fontSize: 11, color: '#38BDF8', fontWeight: 'bold' }),
|
|
289
|
+
UI.Badge({ text: 'LIVE SYNC', backgroundColor: '#064E3B', textColor: '#6EE7B7' })
|
|
290
|
+
),
|
|
291
|
+
UI.HStack(
|
|
292
|
+
{ spacing: 12, marginTop: 10 },
|
|
293
|
+
UI.VStack(
|
|
294
|
+
{ width: 90, alignItems: 'center' },
|
|
295
|
+
UI.Progress({ style: 'circular', value: 0.86, tintColor: '#38BDF8', trackColor: '#1E293B' }),
|
|
296
|
+
UI.Text('86%', { fontSize: 16, fontWeight: 'bold', color: '#FFFFFF' }),
|
|
297
|
+
UI.Text('KPI Quý', { fontSize: 10, color: '#94A3B8' })
|
|
298
|
+
)
|
|
299
|
+
),
|
|
170
300
|
UI.Spacer(),
|
|
171
|
-
UI.Button('
|
|
172
|
-
actionId: '
|
|
173
|
-
backgroundColor: '#
|
|
301
|
+
UI.Button('Duyệt báo cáo doanh thu tuần', {
|
|
302
|
+
actionId: 'action_approve_report',
|
|
303
|
+
backgroundColor: '#1E293B',
|
|
174
304
|
textColor: '#FFFFFF'
|
|
175
305
|
})
|
|
176
306
|
)
|
|
@@ -193,11 +323,35 @@ await Widget.reloadAll();
|
|
|
193
323
|
| **SharedStorage Data Sync** | App Group UserDefaults | Context SharedPreferences |
|
|
194
324
|
| **Remote API Silent Sync** | Background Timeline URLSession | WorkManager / Background Fetch |
|
|
195
325
|
| **Push Remote Updates** | Apple APNs Activity Tokens | Firebase Cloud Messaging (FCM) |
|
|
326
|
+
| **Expo & EAS Build Ready** | ✅ Automated Config Plugin | ✅ Automated Config Plugin |
|
|
196
327
|
|
|
197
328
|
---
|
|
198
329
|
|
|
199
|
-
##
|
|
330
|
+
## ☕ Sponsor & Donate (Ủng hộ tác giả)
|
|
331
|
+
|
|
332
|
+
`react-native-live-widgets` là dự án mã nguồn mở **hoàn toàn miễn phí (100% Free & MIT License)**, được phát triển và duy trì với tâm huyết mang lại giải pháp Live Activities & Widgets tốt nhất cho cộng đồng React Native Việt Nam và quốc tế.
|
|
200
333
|
|
|
334
|
+
Nếu thư viện này giúp ích cho dự án hoặc công ty của bạn, bạn có thể **mời tác giả một tách cà phê** để tiếp thêm động lực phát triển thêm nhiều tính năng mới nhé! ☕❤️
|
|
335
|
+
|
|
336
|
+
<div align="center">
|
|
337
|
+
|
|
338
|
+
<img src="assets/donate_qr.png" alt="Donate qua VietQR VPBank" width="300" style="border-radius: 16px; box-shadow: 0 4px 20px rgba(0,0,0,0.15);" />
|
|
339
|
+
|
|
340
|
+
### 🏦 Thông tin chuyển khoản ủng hộ:
|
|
341
|
+
- **Ngân hàng**: VPBank (Ngân hàng TMCP Việt Nam Thịnh Vượng)
|
|
342
|
+
- **Số tài khoản / Số điện thoại**: `0906472426`
|
|
343
|
+
- **Chủ tài khoản**: `TRAN LE VU`
|
|
344
|
+
- **Nội dung**: `LiveWidgets Support` hoặc lời nhắn của bạn
|
|
345
|
+
|
|
346
|
+
*Chân thành cảm ơn sự đồng hành và ủng hộ quý báu của bạn!* 🙏✨
|
|
347
|
+
|
|
348
|
+
</div>
|
|
349
|
+
|
|
350
|
+
---
|
|
351
|
+
|
|
352
|
+
## 📚 Documentation & Guides
|
|
353
|
+
|
|
354
|
+
- 📱 **[LiveWidgetsExample Demo Project](https://github.com/React-Native-Vu/LiveWidgetsExample)**: Complete working sample app demonstrating all 5 presets with bidirectional sync on iOS & Android.
|
|
201
355
|
- 🇬🇧 **[Full English Developer Guide](docs/GUIDE-EN.md)**: Architecture, DSL specs, push notification server configuration, and best practices.
|
|
202
356
|
- 🇻🇳 **[Hướng dẫn Chi tiết bằng Tiếng Việt](docs/GUIDE-VI.md)**: Hướng dẫn tích hợp từng bước, thiết lập App Group, giải quyết lỗi thường gặp.
|
|
203
357
|
|
|
@@ -205,18 +359,12 @@ await Widget.reloadAll();
|
|
|
205
359
|
|
|
206
360
|
## 🤝 Contributing
|
|
207
361
|
|
|
208
|
-
Contributions are welcome! Please feel free to submit a Pull Request or open an Issue.
|
|
209
|
-
|
|
210
|
-
1. Fork the Project.
|
|
211
|
-
2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`).
|
|
212
|
-
3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`).
|
|
213
|
-
4. Push to the Branch (`git push origin feature/AmazingFeature`).
|
|
214
|
-
5. Open a Pull Request.
|
|
362
|
+
Contributions are welcome! Please feel free to submit a Pull Request or open an Issue on [GitHub Repository](https://github.com/React-Native-Vu/react-native-live-widgets).
|
|
215
363
|
|
|
216
364
|
---
|
|
217
365
|
|
|
218
366
|
## 📄 License
|
|
219
367
|
|
|
220
|
-
Distributed under the **MIT License**. See
|
|
368
|
+
Distributed under the **MIT License**. See [LICENSE](LICENSE) for more information.
|
|
221
369
|
|
|
222
|
-
Developed with ❤️ by **vu-tran** for high-performance React Native applications.
|
|
370
|
+
Developed with ❤️ by **vu-tran** for high-performance React Native & Expo applications.
|
package/android/build.gradle
CHANGED
|
@@ -1,29 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
ext.
|
|
3
|
-
repositories {
|
|
4
|
-
google()
|
|
5
|
-
mavenCentral()
|
|
6
|
-
}
|
|
7
|
-
dependencies {
|
|
8
|
-
classpath "com.android.tools.build:gradle:8.2.1"
|
|
9
|
-
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
|
10
|
-
}
|
|
1
|
+
def safeExtGet(prop, fallback) {
|
|
2
|
+
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
|
|
11
3
|
}
|
|
12
4
|
|
|
13
5
|
apply plugin: 'com.android.library'
|
|
14
6
|
apply plugin: 'kotlin-android'
|
|
15
7
|
|
|
16
|
-
def safeExtGet(prop, fallback) {
|
|
17
|
-
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
|
|
18
|
-
}
|
|
19
|
-
|
|
20
8
|
android {
|
|
21
9
|
namespace "com.reactnativeliveactivity"
|
|
22
|
-
compileSdkVersion safeExtGet('compileSdkVersion',
|
|
10
|
+
compileSdkVersion safeExtGet('compileSdkVersion', safeExtGet('compileSdk', 35))
|
|
23
11
|
|
|
24
12
|
defaultConfig {
|
|
25
|
-
minSdkVersion safeExtGet('minSdkVersion', 24)
|
|
26
|
-
targetSdkVersion safeExtGet('targetSdkVersion',
|
|
13
|
+
minSdkVersion safeExtGet('minSdkVersion', safeExtGet('minSdk', 24))
|
|
14
|
+
targetSdkVersion safeExtGet('targetSdkVersion', safeExtGet('targetSdk', 35))
|
|
27
15
|
}
|
|
28
16
|
|
|
29
17
|
compileOptions {
|
|
@@ -42,8 +30,14 @@ repositories {
|
|
|
42
30
|
}
|
|
43
31
|
|
|
44
32
|
dependencies {
|
|
45
|
-
|
|
46
|
-
|
|
33
|
+
// Resolve react-android safely according to consumer project
|
|
34
|
+
if (findProject(':ReactAndroid') != null) {
|
|
35
|
+
implementation project(':ReactAndroid')
|
|
36
|
+
} else {
|
|
37
|
+
implementation 'com.facebook.react:react-android'
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
def kotlinVersion = safeExtGet('kotlinVersion', safeExtGet('kotlin_version', '2.1.20'))
|
|
41
|
+
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
|
|
47
42
|
implementation 'androidx.core:core-ktx:1.12.0'
|
|
48
43
|
}
|
|
49
|
-
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
|
5
5
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
|
6
6
|
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
|
|
7
|
+
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
|
7
8
|
|
|
8
9
|
<application>
|
|
9
10
|
<!-- Receiver xử lý Live Update, Background API Sync & Interactive Widget Actions -->
|
|
@@ -12,6 +12,7 @@ import com.facebook.react.bridge.Promise
|
|
|
12
12
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
13
13
|
import com.facebook.react.bridge.ReactContextBaseJavaModule
|
|
14
14
|
import com.facebook.react.bridge.ReactMethod
|
|
15
|
+
import com.facebook.react.bridge.ReadableMap
|
|
15
16
|
import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
16
17
|
import org.json.JSONObject
|
|
17
18
|
import java.util.concurrent.Executors
|
|
@@ -121,7 +122,7 @@ class LiveActivityModule(private val reactContext: ReactApplicationContext) :
|
|
|
121
122
|
val seconds = if (options?.hasKey("dismissalAfterSeconds") == true) options.getDouble("dismissalAfterSeconds").toLong() else 0L
|
|
122
123
|
|
|
123
124
|
if (finalPayload != null) {
|
|
124
|
-
LiveActivityNotifier.
|
|
125
|
+
LiveActivityNotifier.update(reactContext, activityId, finalPayload)
|
|
125
126
|
}
|
|
126
127
|
|
|
127
128
|
if (seconds > 0) {
|
|
@@ -6,6 +6,14 @@ import com.facebook.react.bridge.Arguments
|
|
|
6
6
|
import com.facebook.react.jstasks.HeadlessJsTaskConfig
|
|
7
7
|
|
|
8
8
|
class LiveActivityHeadlessTaskService : HeadlessJsTaskService() {
|
|
9
|
+
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
|
10
|
+
return try {
|
|
11
|
+
super.onStartCommand(intent, flags, startId)
|
|
12
|
+
} catch (_: Throwable) {
|
|
13
|
+
START_NOT_STICKY
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
9
17
|
override fun getTaskConfig(intent: Intent?): HeadlessJsTaskConfig? {
|
|
10
18
|
val actionId = intent?.getStringExtra("actionId") ?: return null
|
|
11
19
|
val activityId = intent.getStringExtra("activityId") ?: ""
|
package/android/src/main/java/com/reactnativeliveactivity/liveactivity/LiveActivityReceiver.kt
CHANGED
|
@@ -55,8 +55,11 @@ class LiveActivityReceiver : BroadcastReceiver() {
|
|
|
55
55
|
putExtra("actionId", actionId)
|
|
56
56
|
putExtra("activityId", activityId)
|
|
57
57
|
}
|
|
58
|
+
try {
|
|
59
|
+
com.facebook.react.HeadlessJsTaskService.acquireWakeLockNow(context)
|
|
60
|
+
} catch (_: Throwable) {}
|
|
58
61
|
context.startService(headlessIntent)
|
|
59
|
-
} catch (_:
|
|
62
|
+
} catch (_: Throwable) {}
|
|
60
63
|
} finally {
|
|
61
64
|
pendingResult.finish()
|
|
62
65
|
}
|
package/android/src/main/java/com/reactnativeliveactivity/renderer/DynamicWidgetCanvasRenderer.kt
CHANGED
|
@@ -21,7 +21,10 @@ import kotlin.math.roundToInt
|
|
|
21
21
|
data class ButtonActionBinding(
|
|
22
22
|
val actionId: String,
|
|
23
23
|
val deepLink: String?,
|
|
24
|
-
val zone: String // "top", "mid", "bot"
|
|
24
|
+
val zone: String = "mid", // "top", "mid", "bot"
|
|
25
|
+
val xFraction: Float = 0.5f,
|
|
26
|
+
val yFraction: Float = 0.5f,
|
|
27
|
+
val widthFraction: Float = 1.0f
|
|
25
28
|
)
|
|
26
29
|
|
|
27
30
|
object DynamicWidgetCanvasRenderer {
|
|
@@ -576,7 +579,19 @@ object DynamicWidgetCanvasRenderer {
|
|
|
576
579
|
top > totalHeight * 0.76f -> "bot"
|
|
577
580
|
else -> "mid"
|
|
578
581
|
}
|
|
579
|
-
|
|
582
|
+
val xF = ((left + btnW / 2f) / availWidth).coerceIn(0f, 1f)
|
|
583
|
+
val yF = ((top + btnH / 2f) / totalHeight).coerceIn(0f, 1f)
|
|
584
|
+
val wF = (btnW / availWidth).coerceIn(0.1f, 1f)
|
|
585
|
+
bindings.add(
|
|
586
|
+
ButtonActionBinding(
|
|
587
|
+
actionId = actionId,
|
|
588
|
+
deepLink = deepLink,
|
|
589
|
+
zone = zone,
|
|
590
|
+
xFraction = xF,
|
|
591
|
+
yFraction = yF,
|
|
592
|
+
widthFraction = if (fullWidth) 1.0f else wF
|
|
593
|
+
)
|
|
594
|
+
)
|
|
580
595
|
}
|
|
581
596
|
btnH + 1.5f * density
|
|
582
597
|
}
|
|
@@ -912,7 +927,18 @@ object DynamicWidgetCanvasRenderer {
|
|
|
912
927
|
top > totalHeight * 0.76f -> "bot"
|
|
913
928
|
else -> "mid"
|
|
914
929
|
}
|
|
915
|
-
|
|
930
|
+
val xF = ((left + availWidth / 2f) / availWidth).coerceIn(0f, 1f)
|
|
931
|
+
val yF = ((top + usedH / 2f) / totalHeight).coerceIn(0f, 1f)
|
|
932
|
+
bindings.add(
|
|
933
|
+
ButtonActionBinding(
|
|
934
|
+
actionId = actionId,
|
|
935
|
+
deepLink = deepLink,
|
|
936
|
+
zone = zone,
|
|
937
|
+
xFraction = xF,
|
|
938
|
+
yFraction = yF,
|
|
939
|
+
widthFraction = 1.0f
|
|
940
|
+
)
|
|
941
|
+
)
|
|
916
942
|
}
|
|
917
943
|
usedH
|
|
918
944
|
}
|
package/android/src/main/java/com/reactnativeliveactivity/storage/DynamicWidgetStateStore.kt
CHANGED
|
@@ -161,6 +161,20 @@ object DynamicWidgetStateStore {
|
|
|
161
161
|
val current = state.toggledItems[key] ?: false
|
|
162
162
|
state.toggledItems[key] = !current
|
|
163
163
|
}
|
|
164
|
+
actionId == "action_counter_inc" || actionId.startsWith("counter:inc") -> {
|
|
165
|
+
val current = (readSharedString(context, "widget_counter_value")?.toIntOrNull() ?: 10) + 1
|
|
166
|
+
writeSharedString(context, "widget_counter_value", current.toString())
|
|
167
|
+
state.remoteVariables["counter"] = current.toString()
|
|
168
|
+
}
|
|
169
|
+
actionId == "action_counter_dec" || actionId.startsWith("counter:dec") -> {
|
|
170
|
+
val current = (readSharedString(context, "widget_counter_value")?.toIntOrNull() ?: 10) - 1
|
|
171
|
+
writeSharedString(context, "widget_counter_value", current.toString())
|
|
172
|
+
state.remoteVariables["counter"] = current.toString()
|
|
173
|
+
}
|
|
174
|
+
actionId == "action_counter_reset" || actionId.startsWith("counter:reset") -> {
|
|
175
|
+
writeSharedString(context, "widget_counter_value", "0")
|
|
176
|
+
state.remoteVariables["counter"] = "0"
|
|
177
|
+
}
|
|
164
178
|
}
|
|
165
179
|
|
|
166
180
|
saveState(context, state)
|
|
@@ -177,6 +191,13 @@ object DynamicWidgetStateStore {
|
|
|
177
191
|
?: SimpleDateFormat("HH:mm:ss", Locale.getDefault()).format(Date())
|
|
178
192
|
raw = raw.replace("{{_lastSyncTime}}", syncTime)
|
|
179
193
|
|
|
194
|
+
val counterVal = readSharedString(context, "widget_counter_value")
|
|
195
|
+
if (counterVal != null) {
|
|
196
|
+
raw = raw.replace(Regex("\"text\":\"-?\\d+\",\"props\":\\{\"fontSize\":(26|32)"), "\"text\":\"$counterVal\",\"props\":{\"fontSize\":$1")
|
|
197
|
+
raw = raw.replace(Regex("\"text\":\"-?\\d+ lượt\","), "\"text\":\"$counterVal lượt\",")
|
|
198
|
+
raw = raw.replace("{{counter}}", counterVal)
|
|
199
|
+
}
|
|
200
|
+
|
|
180
201
|
for ((k, v) in state.remoteVariables) {
|
|
181
202
|
val escaped = v.replace("\"", "\\\"")
|
|
182
203
|
raw = raw.replace("{{$k}}", escaped)
|