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.
Files changed (37) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +197 -49
  3. package/android/build.gradle +14 -20
  4. package/android/src/main/AndroidManifest.xml +1 -0
  5. package/android/src/main/java/com/reactnativeliveactivity/bridge/LiveActivityModule.kt +2 -1
  6. package/android/src/main/java/com/reactnativeliveactivity/liveactivity/LiveActivityHeadlessTaskService.kt +8 -0
  7. package/android/src/main/java/com/reactnativeliveactivity/liveactivity/LiveActivityReceiver.kt +4 -1
  8. package/android/src/main/java/com/reactnativeliveactivity/renderer/DynamicWidgetCanvasRenderer.kt +29 -3
  9. package/android/src/main/java/com/reactnativeliveactivity/storage/DynamicWidgetStateStore.kt +21 -0
  10. package/android/src/main/java/com/reactnativeliveactivity/widgets/DynamicHomeScreenWidgetProvider.kt +51 -15
  11. package/android/src/main/res/layout/rn_live_widget_host.xml +64 -74
  12. package/app.plugin.js +114 -0
  13. package/assets/cross_platform_parity.png +0 -0
  14. package/assets/donate_qr.png +0 -0
  15. package/assets/dynamic_island_expanded.png +0 -0
  16. package/assets/home_widget_interactive.png +0 -0
  17. package/assets/lock_screen_live_activity.png +0 -0
  18. package/cli/setup.js +445 -48
  19. package/docs/EXPO-GUIDE-EN.md +405 -0
  20. package/docs/EXPO-GUIDE-VI.md +427 -0
  21. package/docs/GUIDE-EN.md +75 -14
  22. package/docs/GUIDE-VI.md +75 -14
  23. package/docs/index.html +405 -0
  24. package/docs/llms-full.txt +118 -0
  25. package/docs/llms.txt +66 -0
  26. package/lib/builder.js +9 -13
  27. package/lib/builder.js.map +1 -1
  28. package/lib/dispatcher.js +6 -11
  29. package/lib/dispatcher.js.map +1 -1
  30. package/lib/index.d.ts.map +1 -1
  31. package/lib/index.js +40 -53
  32. package/lib/index.js.map +1 -1
  33. package/lib/types.js +1 -2
  34. package/lib/types.js.map +1 -1
  35. package/package.json +22 -4
  36. package/src/index.ts +12 -4
  37. package/src/react-native-env.d.ts +29 -0
@@ -13,6 +13,7 @@ import android.util.SizeF
13
13
  import android.widget.RemoteViews
14
14
  import org.json.JSONObject
15
15
  import kotlin.math.max
16
+ import kotlin.math.min
16
17
  import kotlin.math.roundToInt
17
18
 
18
19
  class DynamicHomeScreenWidgetProvider : AppWidgetProvider() {
@@ -163,25 +164,60 @@ class DynamicHomeScreenWidgetProvider : AppWidgetProvider() {
163
164
  appWidgetId: Int,
164
165
  bindings: List<ButtonActionBinding>
165
166
  ) {
166
- val topIds = listOf(R.id.rn_hit_top_1, R.id.rn_hit_top_2, R.id.rn_hit_top_3, R.id.rn_hit_top_4)
167
- val midIds = listOf(R.id.rn_hit_mid_1, R.id.rn_hit_mid_2, R.id.rn_hit_mid_3)
168
- val botIds = listOf(R.id.rn_hit_bot_1, R.id.rn_hit_bot_2)
167
+ val gridIds = listOf(
168
+ listOf(R.id.rn_hit_r0_c0, R.id.rn_hit_r0_c1, R.id.rn_hit_r0_c2, R.id.rn_hit_r0_c3),
169
+ listOf(R.id.rn_hit_r1_c0, R.id.rn_hit_r1_c1, R.id.rn_hit_r1_c2),
170
+ listOf(R.id.rn_hit_r2_c0, R.id.rn_hit_r2_c1, R.id.rn_hit_r2_c2),
171
+ listOf(R.id.rn_hit_r3_c0, R.id.rn_hit_r3_c1, R.id.rn_hit_r3_c2),
172
+ listOf(R.id.rn_hit_r4_c0, R.id.rn_hit_r4_c1, R.id.rn_hit_r4_c2),
173
+ listOf(R.id.rn_hit_r5_c0, R.id.rn_hit_r5_c1, R.id.rn_hit_r5_c2)
174
+ )
175
+
176
+ val cellBindings = mutableMapOf<Int, ButtonActionBinding>()
169
177
 
170
- val topBindings = bindings.filter { it.zone == "top" }
171
- val midBindings = bindings.filter { it.zone == "mid" }
172
- val botBindings = bindings.filter { it.zone == "bot" }
178
+ val topButtons = bindings.filter { it.zone == "top" || it.yFraction < 0.20f }
179
+ val otherButtons = bindings.filter { it !in topButtons }
173
180
 
174
- for (i in topIds.indices) {
175
- val b = topBindings.getOrNull(i)
176
- views.setOnClickPendingIntent(topIds[i], createPendingIntent(context, appWidgetId * 100 + i, b))
181
+ val row0 = gridIds[0]
182
+ for (c in 0 until min(row0.size, topButtons.size)) {
183
+ cellBindings[row0[c]] = topButtons[c]
177
184
  }
178
- for (i in midIds.indices) {
179
- val b = midBindings.getOrNull(i)
180
- views.setOnClickPendingIntent(midIds[i], createPendingIntent(context, appWidgetId * 100 + 20 + i, b))
185
+
186
+ for (b in otherButtons) {
187
+ val row = when {
188
+ b.yFraction < 0.35f -> 1
189
+ b.yFraction < 0.52f -> 2
190
+ b.yFraction < 0.62f -> 3
191
+ b.yFraction < 0.75f -> 4
192
+ else -> 5
193
+ }
194
+
195
+ val rowCols = gridIds[row]
196
+ if (b.widthFraction > 0.50f) {
197
+ for (viewId in rowCols) {
198
+ cellBindings[viewId] = b
199
+ }
200
+ } else {
201
+ if (b.xFraction < 0.40f) {
202
+ cellBindings[rowCols[0]] = b
203
+ cellBindings[rowCols[1]] = b
204
+ } else {
205
+ cellBindings[rowCols[1]] = b
206
+ cellBindings[rowCols[2]] = b
207
+ }
208
+ }
181
209
  }
182
- for (i in botIds.indices) {
183
- val b = botBindings.getOrNull(i)
184
- views.setOnClickPendingIntent(botIds[i], createPendingIntent(context, appWidgetId * 100 + 40 + i, b))
210
+
211
+ var requestIdx = 0
212
+ for (r in gridIds.indices) {
213
+ for (c in gridIds[r].indices) {
214
+ val viewId = gridIds[r][c]
215
+ val b = cellBindings[viewId]
216
+ views.setOnClickPendingIntent(
217
+ viewId,
218
+ createPendingIntent(context, appWidgetId * 100 + requestIdx++, b)
219
+ )
220
+ }
185
221
  }
186
222
  }
187
223
 
@@ -12,101 +12,91 @@
12
12
  android:scaleType="fitCenter"
13
13
  android:contentDescription="Live Widget Content" />
14
14
 
15
- <!-- Lớp vùng bấm tương tác (Interactive Hit Zones) cho các UI.Button trên Widget -->
15
+ <!-- Lớp vùng bấm tương tác (Interactive Hit Zones: 6 Hàng x 3 Cột) cho mọi layout Widget -->
16
16
  <LinearLayout
17
+ android:id="@+id/rn_widget_grid_container"
17
18
  android:layout_width="match_parent"
18
19
  android:layout_height="match_parent"
19
20
  android:orientation="vertical"
20
- android:weightSum="100">
21
+ android:weightSum="6">
21
22
 
22
- <!-- Hàng trên cùng (dành cho thanh Tab Bar chuyển trang: page:shift, page:todo, page:okr, page:next) -->
23
+ <!-- Row 0 (0% - 16.7%) -->
23
24
  <LinearLayout
24
- android:id="@+id/rn_widget_row_top"
25
+ android:id="@+id/rn_grid_row_0"
25
26
  android:layout_width="match_parent"
26
27
  android:layout_height="0dp"
27
- android:layout_weight="22"
28
- android:orientation="horizontal">
29
-
30
- <TextView
31
- android:id="@+id/rn_hit_top_1"
32
- android:layout_width="0dp"
33
- android:layout_height="match_parent"
34
- android:layout_weight="1"
35
- android:background="@android:color/transparent" />
36
-
37
- <TextView
38
- android:id="@+id/rn_hit_top_2"
39
- android:layout_width="0dp"
40
- android:layout_height="match_parent"
41
- android:layout_weight="1"
42
- android:background="@android:color/transparent" />
43
-
44
- <TextView
45
- android:id="@+id/rn_hit_top_3"
46
- android:layout_width="0dp"
47
- android:layout_height="match_parent"
48
- android:layout_weight="1"
49
- android:background="@android:color/transparent" />
50
-
51
- <TextView
52
- android:id="@+id/rn_hit_top_4"
53
- android:layout_width="0dp"
54
- android:layout_height="match_parent"
55
- android:layout_weight="1"
56
- android:background="@android:color/transparent" />
28
+ android:layout_weight="1"
29
+ android:orientation="horizontal"
30
+ android:weightSum="4">
31
+ <TextView android:id="@+id/rn_hit_r0_c0" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@android:color/transparent" />
32
+ <TextView android:id="@+id/rn_hit_r0_c1" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@android:color/transparent" />
33
+ <TextView android:id="@+id/rn_hit_r0_c2" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@android:color/transparent" />
34
+ <TextView android:id="@+id/rn_hit_r0_c3" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@android:color/transparent" />
57
35
  </LinearLayout>
58
36
 
59
- <!-- Vùng giữa (dành cho danh sách các nút bấm / Todo items: toggle:todo_1, toggle:todo_2, toggle:todo_3) -->
37
+ <!-- Row 1 (16.7% - 33.3%) -->
60
38
  <LinearLayout
61
- android:id="@+id/rn_widget_row_mid"
39
+ android:id="@+id/rn_grid_row_1"
62
40
  android:layout_width="match_parent"
63
41
  android:layout_height="0dp"
64
- android:layout_weight="58"
65
- android:orientation="vertical">
66
-
67
- <TextView
68
- android:id="@+id/rn_hit_mid_1"
69
- android:layout_width="match_parent"
70
- android:layout_height="0dp"
71
- android:layout_weight="1"
72
- android:background="@android:color/transparent" />
73
-
74
- <TextView
75
- android:id="@+id/rn_hit_mid_2"
76
- android:layout_width="match_parent"
77
- android:layout_height="0dp"
78
- android:layout_weight="1"
79
- android:background="@android:color/transparent" />
42
+ android:layout_weight="1"
43
+ android:orientation="horizontal"
44
+ android:weightSum="3">
45
+ <TextView android:id="@+id/rn_hit_r1_c0" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@android:color/transparent" />
46
+ <TextView android:id="@+id/rn_hit_r1_c1" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@android:color/transparent" />
47
+ <TextView android:id="@+id/rn_hit_r1_c2" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@android:color/transparent" />
48
+ </LinearLayout>
80
49
 
81
- <TextView
82
- android:id="@+id/rn_hit_mid_3"
83
- android:layout_width="match_parent"
84
- android:layout_height="0dp"
85
- android:layout_weight="1"
86
- android:background="@android:color/transparent" />
50
+ <!-- Row 2 (33.3% - 50.0%) -->
51
+ <LinearLayout
52
+ android:id="@+id/rn_grid_row_2"
53
+ android:layout_width="match_parent"
54
+ android:layout_height="0dp"
55
+ android:layout_weight="1"
56
+ android:orientation="horizontal"
57
+ android:weightSum="3">
58
+ <TextView android:id="@+id/rn_hit_r2_c0" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@android:color/transparent" />
59
+ <TextView android:id="@+id/rn_hit_r2_c1" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@android:color/transparent" />
60
+ <TextView android:id="@+id/rn_hit_r2_c2" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@android:color/transparent" />
87
61
  </LinearLayout>
88
62
 
89
- <!-- Hàng dưới cùng (dành cho nút Refresh API ngầm / Điều hướng: refresh, page:prev, page:next) -->
63
+ <!-- Row 3 (50.0% - 66.7%) -->
90
64
  <LinearLayout
91
- android:id="@+id/rn_widget_row_bottom"
65
+ android:id="@+id/rn_grid_row_3"
92
66
  android:layout_width="match_parent"
93
67
  android:layout_height="0dp"
94
- android:layout_weight="20"
95
- android:orientation="horizontal">
68
+ android:layout_weight="1"
69
+ android:orientation="horizontal"
70
+ android:weightSum="3">
71
+ <TextView android:id="@+id/rn_hit_r3_c0" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@android:color/transparent" />
72
+ <TextView android:id="@+id/rn_hit_r3_c1" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@android:color/transparent" />
73
+ <TextView android:id="@+id/rn_hit_r3_c2" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@android:color/transparent" />
74
+ </LinearLayout>
96
75
 
97
- <TextView
98
- android:id="@+id/rn_hit_bot_1"
99
- android:layout_width="0dp"
100
- android:layout_height="match_parent"
101
- android:layout_weight="1"
102
- android:background="@android:color/transparent" />
76
+ <!-- Row 4 (66.7% - 83.3%) -->
77
+ <LinearLayout
78
+ android:id="@+id/rn_grid_row_4"
79
+ android:layout_width="match_parent"
80
+ android:layout_height="0dp"
81
+ android:layout_weight="1"
82
+ android:orientation="horizontal"
83
+ android:weightSum="3">
84
+ <TextView android:id="@+id/rn_hit_r4_c0" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@android:color/transparent" />
85
+ <TextView android:id="@+id/rn_hit_r4_c1" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@android:color/transparent" />
86
+ <TextView android:id="@+id/rn_hit_r4_c2" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@android:color/transparent" />
87
+ </LinearLayout>
103
88
 
104
- <TextView
105
- android:id="@+id/rn_hit_bot_2"
106
- android:layout_width="0dp"
107
- android:layout_height="match_parent"
108
- android:layout_weight="1"
109
- android:background="@android:color/transparent" />
89
+ <!-- Row 5 (83.3% - 100.0%) -->
90
+ <LinearLayout
91
+ android:id="@+id/rn_grid_row_5"
92
+ android:layout_width="match_parent"
93
+ android:layout_height="0dp"
94
+ android:layout_weight="1"
95
+ android:orientation="horizontal"
96
+ android:weightSum="3">
97
+ <TextView android:id="@+id/rn_hit_r5_c0" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@android:color/transparent" />
98
+ <TextView android:id="@+id/rn_hit_r5_c1" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@android:color/transparent" />
99
+ <TextView android:id="@+id/rn_hit_r5_c2" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@android:color/transparent" />
110
100
  </LinearLayout>
111
101
  </LinearLayout>
112
102
  </FrameLayout>
package/app.plugin.js ADDED
@@ -0,0 +1,114 @@
1
+ const path = require('path');
2
+ const fs = require('fs');
3
+
4
+ /**
5
+ * Expo Config Plugin for react-native-live-widgets
6
+ *
7
+ * Automatically configures:
8
+ * 1. iOS Info.plist: NSSupportsLiveActivities = YES, NSSupportsLiveActivitiesFrequentUpdates = YES
9
+ * 2. iOS Entitlements: com.apple.security.application-groups = [appGroup]
10
+ * 3. Android AndroidManifest.xml: POST_NOTIFICATIONS, FOREGROUND_SERVICE permissions
11
+ */
12
+
13
+ let withLiveWidgets;
14
+
15
+ try {
16
+ const {
17
+ withInfoPlist,
18
+ withEntitlementsPlist,
19
+ withAndroidManifest,
20
+ createRunOncePlugin,
21
+ } = require('@expo/config-plugins');
22
+
23
+ const pkg = require('./package.json');
24
+
25
+ /**
26
+ * Configures iOS Info.plist to enable Live Activities support
27
+ */
28
+ const withLiveWidgetsInfoPlist = (config, options = {}) => {
29
+ return withInfoPlist(config, (plistConfig) => {
30
+ const enableLiveActivities =
31
+ options.enableLiveActivities !== undefined ? options.enableLiveActivities : true;
32
+ const frequentUpdates =
33
+ options.frequentUpdates !== undefined ? options.frequentUpdates : true;
34
+
35
+ plistConfig.modResults.NSSupportsLiveActivities = enableLiveActivities;
36
+ if (frequentUpdates) {
37
+ plistConfig.modResults.NSSupportsLiveActivitiesFrequentUpdates = true;
38
+ }
39
+
40
+ return plistConfig;
41
+ });
42
+ };
43
+
44
+ /**
45
+ * Configures iOS Entitlements for App Groups shared storage
46
+ */
47
+ const withLiveWidgetsEntitlements = (config, options = {}) => {
48
+ return withEntitlementsPlist(config, (entitlementsConfig) => {
49
+ if (options.appGroup) {
50
+ const existingGroups =
51
+ entitlementsConfig.modResults['com.apple.security.application-groups'] || [];
52
+ const groups = Array.isArray(existingGroups) ? [...existingGroups] : [existingGroups];
53
+
54
+ if (!groups.includes(options.appGroup)) {
55
+ groups.push(options.appGroup);
56
+ }
57
+
58
+ entitlementsConfig.modResults['com.apple.security.application-groups'] = groups;
59
+ }
60
+ return entitlementsConfig;
61
+ });
62
+ };
63
+
64
+ /**
65
+ * Configures Android Manifest permissions for Notifications & Background Service
66
+ */
67
+ const withLiveWidgetsAndroidManifest = (config, _options = {}) => {
68
+ return withAndroidManifest(config, (manifestConfig) => {
69
+ const manifest = manifestConfig.modResults.manifest;
70
+
71
+ if (!manifest['uses-permission']) {
72
+ manifest['uses-permission'] = [];
73
+ }
74
+
75
+ const permissions = [
76
+ 'android.permission.INTERNET',
77
+ 'android.permission.POST_NOTIFICATIONS',
78
+ 'android.permission.FOREGROUND_SERVICE',
79
+ ];
80
+
81
+ for (const permission of permissions) {
82
+ const hasPermission = manifest['uses-permission'].some(
83
+ (p) => p.$?.['android:name'] === permission
84
+ );
85
+ if (!hasPermission) {
86
+ manifest['uses-permission'].push({
87
+ $: { 'android:name': permission },
88
+ });
89
+ }
90
+ }
91
+
92
+ return manifestConfig;
93
+ });
94
+ };
95
+
96
+ /**
97
+ * Main Expo Config Plugin composite function
98
+ */
99
+ const plugin = (config, options = {}) => {
100
+ config = withLiveWidgetsInfoPlist(config, options);
101
+ config = withLiveWidgetsEntitlements(config, options);
102
+ config = withLiveWidgetsAndroidManifest(config, options);
103
+ return config;
104
+ };
105
+
106
+ withLiveWidgets = createRunOncePlugin(plugin, pkg.name, pkg.version);
107
+ } catch (_error) {
108
+ // Fallback for non-Expo / bare React Native environments where @expo/config-plugins is absent
109
+ withLiveWidgets = function (config) {
110
+ return config;
111
+ };
112
+ }
113
+
114
+ module.exports = withLiveWidgets;
Binary file
Binary file
Binary file
Binary file