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/android/src/main/java/com/reactnativeliveactivity/widgets/DynamicHomeScreenWidgetProvider.kt
CHANGED
|
@@ -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
|
|
167
|
-
|
|
168
|
-
|
|
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
|
|
171
|
-
val
|
|
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
|
-
|
|
175
|
-
|
|
176
|
-
|
|
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
|
-
|
|
179
|
-
|
|
180
|
-
|
|
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
|
-
|
|
183
|
-
|
|
184
|
-
|
|
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
|
|
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="
|
|
21
|
+
android:weightSum="6">
|
|
21
22
|
|
|
22
|
-
<!--
|
|
23
|
+
<!-- Row 0 (0% - 16.7%) -->
|
|
23
24
|
<LinearLayout
|
|
24
|
-
android:id="@+id/
|
|
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="
|
|
28
|
-
android:orientation="horizontal"
|
|
29
|
-
|
|
30
|
-
<TextView
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
<!--
|
|
37
|
+
<!-- Row 1 (16.7% - 33.3%) -->
|
|
60
38
|
<LinearLayout
|
|
61
|
-
android:id="@+id/
|
|
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="
|
|
65
|
-
android:orientation="
|
|
66
|
-
|
|
67
|
-
<TextView
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
-
<!--
|
|
63
|
+
<!-- Row 3 (50.0% - 66.7%) -->
|
|
90
64
|
<LinearLayout
|
|
91
|
-
android:id="@+id/
|
|
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="
|
|
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
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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
|
|
Binary file
|