react-native-live-widgets 1.2.0 → 1.2.2

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 (87) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/README.md +129 -50
  3. package/android/src/main/AndroidManifest.xml +12 -0
  4. package/android/src/main/assets/fonts/MaterialIcons-Regular.ttf +0 -0
  5. package/android/src/main/java/com/reactnativeliveactivity/bridge/LiveActivityModule.kt +61 -1
  6. package/android/src/main/java/com/reactnativeliveactivity/liveactivity/LiveActivityNotifier.kt +153 -17
  7. package/android/src/main/java/com/reactnativeliveactivity/liveactivity/LiveActivityReceiver.kt +1 -1
  8. package/android/src/main/java/com/reactnativeliveactivity/renderer/DynamicWidgetCanvasRenderer.kt +529 -59
  9. package/android/src/main/java/com/reactnativeliveactivity/storage/DynamicWidgetImageCache.kt +53 -0
  10. package/android/src/main/java/com/reactnativeliveactivity/storage/DynamicWidgetStateStore.kt +684 -83
  11. package/android/src/main/java/com/reactnativeliveactivity/widgets/DynamicHomeScreenWidgetProvider.kt +129 -57
  12. package/android/src/main/java/com/reactnativeliveactivity/widgets/DynamicQuickSettingsTileService.kt +120 -0
  13. package/android/src/main/res/layout/rn_live_widget_hit_zone.xml +16 -0
  14. package/android/src/main/res/layout/rn_live_widget_host.xml +16 -87
  15. package/app.plugin.js +36 -0
  16. package/assets/MaterialIcons.json +2236 -0
  17. package/cli/codegen.js +789 -0
  18. package/cli/setup.js +323 -63
  19. package/docs/EXPO-GUIDE-EN.md +21 -3
  20. package/docs/EXPO-GUIDE-VI.md +21 -3
  21. package/docs/GUIDE-EN.md +444 -21
  22. package/docs/GUIDE-VI.md +473 -22
  23. package/docs/index.html +2263 -265
  24. package/docs/llms-full.txt +41 -0
  25. package/docs/llms.txt +24 -7
  26. package/ios/Bridge/LiveActivityModule.swift +333 -44
  27. package/ios/Intents/DynamicWidgetActionIntent.swift +57 -2
  28. package/ios/Models/DynamicLayoutModels.swift +120 -5
  29. package/ios/Renderer/DynamicNodeView.swift +184 -20
  30. package/ios/Storage/DynamicWidgetStateStore.swift +649 -38
  31. package/ios/Widgets/DynamicControlWidget.swift +63 -0
  32. package/ios/Widgets/DynamicHomeScreenWidget.swift +104 -26
  33. package/ios/Widgets/DynamicLiveActivityWidget.swift +25 -4
  34. package/lib/builder.d.ts +50 -7
  35. package/lib/builder.d.ts.map +1 -1
  36. package/lib/builder.js +391 -29
  37. package/lib/builder.js.map +1 -1
  38. package/lib/dispatcher.js +16 -10
  39. package/lib/dispatcher.js.map +1 -1
  40. package/lib/hooks.d.ts +13 -9
  41. package/lib/hooks.d.ts.map +1 -1
  42. package/lib/hooks.js +105 -42
  43. package/lib/hooks.js.map +1 -1
  44. package/lib/index.d.ts +96 -8
  45. package/lib/index.d.ts.map +1 -1
  46. package/lib/index.js +415 -97
  47. package/lib/index.js.map +1 -1
  48. package/lib/ir.d.ts +15 -0
  49. package/lib/ir.d.ts.map +1 -0
  50. package/lib/ir.js +386 -0
  51. package/lib/ir.js.map +1 -0
  52. package/lib/jsx.d.ts +19 -7
  53. package/lib/jsx.d.ts.map +1 -1
  54. package/lib/jsx.js +179 -95
  55. package/lib/jsx.js.map +1 -1
  56. package/lib/material-icons.generated.d.ts +8 -0
  57. package/lib/material-icons.generated.d.ts.map +1 -0
  58. package/lib/material-icons.generated.js +9 -0
  59. package/lib/material-icons.generated.js.map +1 -0
  60. package/lib/preview.d.ts +11 -27
  61. package/lib/preview.d.ts.map +1 -1
  62. package/lib/preview.js +456 -119
  63. package/lib/preview.js.map +1 -1
  64. package/lib/sf-symbols.generated.d.ts +8 -0
  65. package/lib/sf-symbols.generated.d.ts.map +1 -0
  66. package/lib/sf-symbols.generated.js +9 -0
  67. package/lib/sf-symbols.generated.js.map +1 -0
  68. package/lib/types.d.ts +506 -30
  69. package/lib/types.d.ts.map +1 -1
  70. package/lib/types.js +2 -1
  71. package/lib/types.js.map +1 -1
  72. package/package.json +7 -2
  73. package/scripts/build.js +98 -0
  74. package/scripts/generate-material-icons.js +93 -0
  75. package/scripts/generate-sf-symbols.js +95 -0
  76. package/scripts/release.js +115 -0
  77. package/scripts/test-ir-semantic.js +314 -0
  78. package/src/builder.ts +439 -26
  79. package/src/hooks.ts +88 -12
  80. package/src/index.ts +385 -57
  81. package/src/ir.ts +436 -0
  82. package/src/jsx.tsx +99 -21
  83. package/src/material-icons.generated.ts +3844 -0
  84. package/src/preview.tsx +533 -55
  85. package/src/react-native-env.d.ts +1 -0
  86. package/src/sf-symbols.generated.ts +9533 -0
  87. package/src/types.ts +601 -31
@@ -10,6 +10,8 @@ import android.net.Uri
10
10
  import android.os.Build
11
11
  import android.os.Bundle
12
12
  import android.util.SizeF
13
+ import android.util.TypedValue
14
+ import android.view.View
13
15
  import android.widget.RemoteViews
14
16
  import org.json.JSONObject
15
17
  import kotlin.math.max
@@ -88,7 +90,8 @@ class DynamicHomeScreenWidgetProvider : AppWidgetProvider() {
88
90
 
89
91
  val family = when {
90
92
  widgetWidthDp < 245f -> "small"
91
- widgetHeightDp < 235f -> "medium"
93
+ widgetHeightDp < 195f -> "medium"
94
+ widgetHeightDp >= 280f -> "extraLarge"
92
95
  else -> "large"
93
96
  }
94
97
 
@@ -100,10 +103,10 @@ class DynamicHomeScreenWidgetProvider : AppWidgetProvider() {
100
103
  "medium" -> 330f
101
104
  else -> 340f
102
105
  }
103
- val aspectRatio = when (family) {
104
- "small" -> 1.02f
105
- "medium" -> (widgetHeightDp / widgetWidthDp).coerceIn(0.45f, 0.62f)
106
- else -> (widgetHeightDp / widgetWidthDp).coerceIn(0.78f, 1.45f)
106
+ val aspectRatio = if (family == "small") {
107
+ 1.02f
108
+ } else {
109
+ (widgetHeightDp / widgetWidthDp).coerceIn(0.38f, 1.65f)
107
110
  }
108
111
  val logicalHeightDp = logicalWidthDp * aspectRatio
109
112
 
@@ -123,7 +126,47 @@ class DynamicHomeScreenWidgetProvider : AppWidgetProvider() {
123
126
  )
124
127
  views.setImageViewBitmap(R.id.rn_widget_canvas, bmp)
125
128
 
126
- bindHitZones(context, views, appWidgetId, bindings)
129
+ // 📐 Ánh xạ toạ độ Bitmap -> toạ độ thật của widget trên Launcher.
130
+ // ImageView dùng scaleType=fitCenter nên Bitmap có thể bị thu/phóng và chừa viền (letterbox).
131
+ // Mọi vùng bấm & đồng hồ phải đi qua phép ánh xạ này thì mới khớp 100% với hình đã vẽ.
132
+ val mapping = computeCanvasMapping(context, rawWidthDp, rawHeightDp, widthPx, heightPx)
133
+
134
+ // ⏱️ Live Chronometer tự đếm bằng engine native của hệ điều hành
135
+ val timerInfo = DynamicWidgetCanvasRenderer.activeTimerInfo
136
+ if (timerInfo != null) {
137
+ views.setViewVisibility(R.id.rn_widget_chronometer, View.VISIBLE)
138
+ views.setViewPadding(
139
+ R.id.rn_widget_chronometer,
140
+ (mapping.offX + timerInfo.leftPx * mapping.scale).roundToInt(),
141
+ (mapping.offY + timerInfo.topPx * mapping.scale).roundToInt(),
142
+ 0,
143
+ 0
144
+ )
145
+ views.setTextViewTextSize(
146
+ R.id.rn_widget_chronometer,
147
+ TypedValue.COMPLEX_UNIT_PX,
148
+ timerInfo.fontSizePx * mapping.scale
149
+ )
150
+ views.setTextColor(R.id.rn_widget_chronometer, timerInfo.color)
151
+ views.setChronometer(R.id.rn_widget_chronometer, timerInfo.baseMillis, null, true)
152
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
153
+ views.setChronometerCountDown(R.id.rn_widget_chronometer, timerInfo.isCountDown)
154
+ }
155
+ } else {
156
+ views.setViewVisibility(R.id.rn_widget_chronometer, View.GONE)
157
+ }
158
+
159
+ // ♿ Gán Accessibility Summary từ IR Semantic Tree (hoặc fallback Canvas extractor)
160
+ val a11ySummary = if (activeNode?.has("semanticSummary") == true) {
161
+ activeNode.optString("semanticSummary")
162
+ } else {
163
+ DynamicWidgetCanvasRenderer.extractAccessibilitySummary(activeNode)
164
+ }
165
+ if (a11ySummary.isNotEmpty()) {
166
+ views.setContentDescription(R.id.rn_widget_canvas, a11ySummary)
167
+ }
168
+
169
+ bindHitZones(context, views, appWidgetId, bindings, mapping)
127
170
  appWidgetManager.updateAppWidget(appWidgetId, views)
128
171
  }
129
172
 
@@ -131,6 +174,16 @@ class DynamicHomeScreenWidgetProvider : AppWidgetProvider() {
131
174
  if (rawJson.isNullOrEmpty()) return null
132
175
  return try {
133
176
  val payload = JSONObject(rawJson)
177
+
178
+ // Hỗ trợ trực tiếp cấu trúc UI Intermediate Representation (IR v2.0)
179
+ if (payload.optString("version") == "2.0" && payload.has("root")) {
180
+ val root = payload.optJSONObject("root")
181
+ if (root != null && payload.has("semanticSummary")) {
182
+ root.put("semanticSummary", payload.optString("semanticSummary"))
183
+ }
184
+ return root
185
+ }
186
+
134
187
  val pages = payload.optJSONObject("pages")
135
188
  if (pages != null && pages.length() > 0) {
136
189
  val state = DynamicWidgetStateStore.loadState(context)
@@ -154,70 +207,88 @@ class DynamicHomeScreenWidgetProvider : AppWidgetProvider() {
154
207
  return when (family) {
155
208
  "small" -> obj.optJSONObject("small") ?: obj.optJSONObject("medium") ?: obj.optJSONObject("large")
156
209
  "medium" -> obj.optJSONObject("medium") ?: obj.optJSONObject("large") ?: obj.optJSONObject("small")
157
- else -> obj.optJSONObject("large") ?: obj.optJSONObject("medium") ?: obj.optJSONObject("small")
210
+ "extraLarge" -> obj.optJSONObject("extraLarge") ?: obj.optJSONObject("large") ?: obj.optJSONObject("medium") ?: obj.optJSONObject("small")
211
+ else -> obj.optJSONObject("large") ?: obj.optJSONObject("extraLarge") ?: obj.optJSONObject("medium") ?: obj.optJSONObject("small")
158
212
  }
159
213
  }
160
214
 
215
+ /** Thông số ánh xạ từ toạ độ Bitmap sang toạ độ pixel thật của host view trên Launcher. */
216
+ private data class CanvasMapping(
217
+ val hostW: Float,
218
+ val hostH: Float,
219
+ val bmpW: Float,
220
+ val bmpH: Float,
221
+ val scale: Float,
222
+ val offX: Float,
223
+ val offY: Float
224
+ )
225
+
226
+ private fun computeCanvasMapping(
227
+ context: Context,
228
+ widgetWidthDp: Float,
229
+ widgetHeightDp: Float,
230
+ bmpWidthPx: Int,
231
+ bmpHeightPx: Int
232
+ ): CanvasMapping {
233
+ val density = context.resources.displayMetrics.density
234
+ val bmpW = bmpWidthPx.toFloat()
235
+ val bmpH = bmpHeightPx.toFloat()
236
+ val hostW = (widgetWidthDp * density).takeIf { it > 1f } ?: bmpW
237
+ val hostH = (widgetHeightDp * density).takeIf { it > 1f } ?: bmpH
238
+ // fitCenter: scale đồng đều theo chiều nhỏ hơn, căn giữa phần còn lại
239
+ val scale = min(hostW / bmpW, hostH / bmpH)
240
+ val offX = (hostW - bmpW * scale) / 2f
241
+ val offY = (hostH - bmpH * scale) / 2f
242
+ return CanvasMapping(hostW, hostH, bmpW, bmpH, scale, offX, offY)
243
+ }
244
+
245
+ /**
246
+ * 🎯 Exact Hit Layer: mỗi Button / Toggle / Link nhận 1 view bấm riêng được đặt CHÍNH XÁC
247
+ * theo hình chữ nhật đã vẽ trên Canvas (không còn chia lưới cố định / đoán theo hàng-cột).
248
+ * - Bấm đúng nút nào => ăn đúng nút đó.
249
+ * - Bấm vào vùng trống => không kích hoạt hành động nào.
250
+ * - Nút nhỏ nằm trong vùng lớn (vd Button bên trong Link) luôn được ưu tiên vì nằm trên cùng.
251
+ */
161
252
  private fun bindHitZones(
162
253
  context: Context,
163
254
  views: RemoteViews,
164
255
  appWidgetId: Int,
165
- bindings: List<ButtonActionBinding>
256
+ bindings: List<ButtonActionBinding>,
257
+ mapping: CanvasMapping
166
258
  ) {
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
- )
259
+ views.removeAllViews(R.id.rn_hit_layer)
260
+ if (bindings.isEmpty()) return
175
261
 
176
- val cellBindings = mutableMapOf<Int, ButtonActionBinding>()
262
+ val density = context.resources.displayMetrics.density
263
+ val slop = 1.5f * density // nới nhẹ vùng chạm cho dễ bấm, không đủ lớn để lấn sang nút bên cạnh
177
264
 
178
- val topButtons = bindings.filter { it.zone == "top" || it.yFraction < 0.20f }
179
- val otherButtons = bindings.filter { it !in topButtons }
265
+ // Vùng lớn thêm trước (nằm dưới), vùng nhỏ thêm sau (nằm trên) => ưu tiên nút nhỏ/cụ thể
266
+ val ordered = bindings
267
+ .filter { it.rightFraction > it.leftFraction && it.bottomFraction > it.topFraction }
268
+ .sortedByDescending { (it.rightFraction - it.leftFraction) * (it.bottomFraction - it.topFraction) }
269
+ .take(48)
180
270
 
181
- val row0 = gridIds[0]
182
- for (c in 0 until min(row0.size, topButtons.size)) {
183
- cellBindings[row0[c]] = topButtons[c]
184
- }
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
- }
271
+ ordered.forEachIndexed { index, b ->
272
+ val left = mapping.offX + b.leftFraction * mapping.bmpW * mapping.scale - slop
273
+ val right = mapping.offX + b.rightFraction * mapping.bmpW * mapping.scale + slop
274
+ val top = mapping.offY + b.topFraction * mapping.bmpH * mapping.scale - slop
275
+ val bottom = mapping.offY + b.bottomFraction * mapping.bmpH * mapping.scale + slop
194
276
 
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
- }
209
- }
277
+ val padL = left.coerceIn(0f, mapping.hostW).roundToInt()
278
+ val padT = top.coerceIn(0f, mapping.hostH).roundToInt()
279
+ val padR = (mapping.hostW - right).coerceIn(0f, mapping.hostW).roundToInt()
280
+ val padB = (mapping.hostH - bottom).coerceIn(0f, mapping.hostH).roundToInt()
210
281
 
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
- }
282
+ val zone = RemoteViews(context.packageName, R.layout.rn_live_widget_hit_zone)
283
+ zone.setViewPadding(R.id.rn_hit_zone_root, padL, padT, padR, padB)
284
+ zone.setOnClickPendingIntent(
285
+ R.id.rn_hit_zone,
286
+ createPendingIntent(context, appWidgetId * 1000 + index, b)
287
+ )
288
+ val btnLabel = if (!b.accessibilityLabel.isNullOrEmpty()) b.accessibilityLabel else b.title
289
+ val fullDesc = if (!b.accessibilityHint.isNullOrEmpty()) "$btnLabel. ${b.accessibilityHint}" else btnLabel
290
+ zone.setContentDescription(R.id.rn_hit_zone, fullDesc)
291
+ views.addView(R.id.rn_hit_layer, zone)
221
292
  }
222
293
  }
223
294
 
@@ -251,6 +322,7 @@ class DynamicHomeScreenWidgetProvider : AppWidgetProvider() {
251
322
 
252
323
  val intent = Intent(context, LiveActivityReceiver::class.java).apply {
253
324
  action = LiveActivityReceiver.ACTION_WIDGET_ACTION
325
+ data = Uri.parse("rnlivewidget://action/$requestCode/${Uri.encode(binding.actionId)}")
254
326
  putExtra("actionId", binding.actionId)
255
327
  }
256
328
  return PendingIntent.getBroadcast(
@@ -0,0 +1,120 @@
1
+ package com.reactnativeliveactivity
2
+
3
+ import android.content.ComponentName
4
+ import android.content.Context
5
+ import android.content.Intent
6
+ import android.os.Build
7
+ import android.service.quicksettings.Tile
8
+ import android.service.quicksettings.TileService
9
+ import org.json.JSONObject
10
+ import java.util.concurrent.Executors
11
+
12
+ /**
13
+ * 🎛️ Android Quick Settings Tile (API 24+) đồng bộ 2 chiều với API `Widget.setControl` / `ControlWidget`.
14
+ */
15
+ class DynamicQuickSettingsTileService : TileService() {
16
+
17
+ private data class ResolvedControlConfig(
18
+ val isToggleType: Boolean,
19
+ val rawActionId: String,
20
+ val title: String,
21
+ val subtitle: String,
22
+ val checkedTitle: String,
23
+ val checkedSubtitle: String,
24
+ val defaultChecked: Boolean
25
+ )
26
+
27
+ private fun resolveConfig(): ResolvedControlConfig {
28
+ val rawJson = DynamicWidgetStateStore.readSharedString(applicationContext, "widget_control_toggle")
29
+ ?: DynamicWidgetStateStore.readSharedString(applicationContext, "widget_control_main")
30
+ val cfg = rawJson?.let { runCatching { JSONObject(it) }.getOrNull() }
31
+
32
+ val type = cfg?.optString("type", "")?.ifEmpty { null }
33
+ val explicitActionId = cfg?.optString("actionId", "")?.ifEmpty { null }
34
+ val isToggleType = type == "toggle" || (type != "button" && explicitActionId?.startsWith("toggle:") == true)
35
+ val rawActionId = explicitActionId ?: if (isToggleType) "toggle:control_main" else "control_action_main"
36
+
37
+ val title = cfg?.optString("title", "")?.ifEmpty { null } ?: "Live Widgets"
38
+ val subtitle = cfg?.optString("subtitle", "")?.ifEmpty { null } ?: ""
39
+ val checkedTitle = cfg?.optString("checkedTitle", "")?.ifEmpty { null } ?: title
40
+ val checkedSubtitle = cfg?.optString("checkedSubtitle", "")?.ifEmpty { null } ?: subtitle
41
+ val defaultChecked = cfg?.optBoolean("checked", false) ?: false
42
+
43
+ return ResolvedControlConfig(
44
+ isToggleType = isToggleType,
45
+ rawActionId = rawActionId,
46
+ title = title,
47
+ subtitle = subtitle,
48
+ checkedTitle = checkedTitle,
49
+ checkedSubtitle = checkedSubtitle,
50
+ defaultChecked = defaultChecked
51
+ )
52
+ }
53
+
54
+ private fun refreshTileState() {
55
+ val tile = qsTile ?: return
56
+ val cfg = resolveConfig()
57
+ val state = DynamicWidgetStateStore.loadState(applicationContext)
58
+
59
+ val isOn = if (cfg.isToggleType) {
60
+ val key = cfg.rawActionId.removePrefix("toggle:")
61
+ state.toggledItems[key] ?: cfg.defaultChecked
62
+ } else {
63
+ false
64
+ }
65
+
66
+ tile.state = if (isOn) Tile.STATE_ACTIVE else Tile.STATE_INACTIVE
67
+ tile.label = if (isOn) cfg.checkedTitle else cfg.title
68
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
69
+ val sub = if (isOn) cfg.checkedSubtitle else cfg.subtitle
70
+ tile.subtitle = sub.ifEmpty { null }
71
+ }
72
+ runCatching { tile.updateTile() }
73
+ }
74
+
75
+ override fun onStartListening() {
76
+ super.onStartListening()
77
+ refreshTileState()
78
+ }
79
+
80
+ override fun onClick() {
81
+ super.onClick()
82
+ val cfg = resolveConfig()
83
+ val rawActionId = cfg.rawActionId
84
+
85
+ DynamicWidgetStateStore.handleAction(applicationContext, rawActionId)
86
+ refreshTileState()
87
+
88
+ val ctx = applicationContext
89
+ executor.execute {
90
+ runCatching { DynamicHomeScreenWidgetProvider.updateAllWidgets(ctx) }
91
+ runCatching { LiveActivityNotifier.refreshAllActive(ctx) }
92
+ runCatching { LiveActivityModule.emitActionClicked(rawActionId, "control_tile") }
93
+ runCatching {
94
+ val headlessIntent = Intent(ctx, LiveActivityHeadlessTaskService::class.java).apply {
95
+ putExtra("actionId", rawActionId)
96
+ putExtra("activityId", "control_tile")
97
+ }
98
+ runCatching {
99
+ com.facebook.react.HeadlessJsTaskService.acquireWakeLockNow(ctx)
100
+ }
101
+ ctx.startService(headlessIntent)
102
+ }
103
+ }
104
+ }
105
+
106
+ companion object {
107
+ private val executor = Executors.newCachedThreadPool()
108
+
109
+ @JvmStatic
110
+ fun requestTileUpdate(context: Context) {
111
+ runCatching {
112
+ val appCtx = context.applicationContext
113
+ requestListeningState(
114
+ appCtx,
115
+ ComponentName(appCtx, DynamicQuickSettingsTileService::class.java)
116
+ )
117
+ }
118
+ }
119
+ }
120
+ }
@@ -0,0 +1,16 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <!--
3
+ 1 vùng bấm. Root phủ toàn widget nhưng KHÔNG clickable (chạm vào phần padding sẽ rơi xuống view bên dưới).
4
+ Padding (left, top, right, bottom) được set động => view con rn_hit_zone nằm đúng hình chữ nhật của nút.
5
+ -->
6
+ <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
7
+ android:id="@+id/rn_hit_zone_root"
8
+ android:layout_width="match_parent"
9
+ android:layout_height="match_parent">
10
+
11
+ <TextView
12
+ android:id="@+id/rn_hit_zone"
13
+ android:layout_width="match_parent"
14
+ android:layout_height="match_parent"
15
+ android:background="@android:color/transparent" />
16
+ </FrameLayout>
@@ -12,92 +12,21 @@
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: 6 Hàng x 3 Cột) cho mọi layout Widget -->
16
- <LinearLayout
17
- android:id="@+id/rn_widget_grid_container"
15
+ <!-- Đồng hồ Live Chronometer tự đếm bằng engine native của hệ thống -->
16
+ <Chronometer
17
+ android:id="@+id/rn_widget_chronometer"
18
+ android:layout_width="wrap_content"
19
+ android:layout_height="wrap_content"
20
+ android:layout_gravity="top|start"
21
+ android:visibility="gone" />
22
+
23
+ <!--
24
+ Lớp vùng bấm động (Exact Hit Layer): mỗi Button / Toggle / Link được thêm 1 view riêng
25
+ (rn_live_widget_hit_zone.xml) đặt CHÍNH XÁC theo toạ độ đã vẽ trên Canvas.
26
+ Vùng trống không gắn hành động nào => bấm vào không kích hoạt gì.
27
+ -->
28
+ <FrameLayout
29
+ android:id="@+id/rn_hit_layer"
18
30
  android:layout_width="match_parent"
19
- android:layout_height="match_parent"
20
- android:orientation="vertical"
21
- android:weightSum="6">
22
-
23
- <!-- Row 0 (0% - 16.7%) -->
24
- <LinearLayout
25
- android:id="@+id/rn_grid_row_0"
26
- android:layout_width="match_parent"
27
- android:layout_height="0dp"
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" />
35
- </LinearLayout>
36
-
37
- <!-- Row 1 (16.7% - 33.3%) -->
38
- <LinearLayout
39
- android:id="@+id/rn_grid_row_1"
40
- android:layout_width="match_parent"
41
- android:layout_height="0dp"
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>
49
-
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" />
61
- </LinearLayout>
62
-
63
- <!-- Row 3 (50.0% - 66.7%) -->
64
- <LinearLayout
65
- android:id="@+id/rn_grid_row_3"
66
- android:layout_width="match_parent"
67
- android:layout_height="0dp"
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>
75
-
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>
88
-
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" />
100
- </LinearLayout>
101
- </LinearLayout>
31
+ android:layout_height="match_parent" />
102
32
  </FrameLayout>
103
-
package/app.plugin.js CHANGED
@@ -17,10 +17,12 @@ try {
17
17
  withInfoPlist,
18
18
  withEntitlementsPlist,
19
19
  withAndroidManifest,
20
+ withDangerousMod,
20
21
  createRunOncePlugin,
21
22
  } = require('@expo/config-plugins');
22
23
 
23
24
  const pkg = require('./package.json');
25
+ const { runCodegen } = require('./cli/codegen');
24
26
 
25
27
  /**
26
28
  * Configures iOS Info.plist to enable Live Activities support
@@ -93,6 +95,39 @@ try {
93
95
  });
94
96
  };
95
97
 
98
+ /**
99
+ * Tự động chạy TypeScript-driven Widget Codegen & i18n Sync trong quá trình expo prebuild
100
+ */
101
+ const withLiveWidgetsCodegen = (config, options = {}) => {
102
+ config = withDangerousMod(config, [
103
+ 'ios',
104
+ async (modConfig) => {
105
+ const projectRoot = modConfig.modRequest.projectRoot;
106
+ try {
107
+ runCodegen(projectRoot, options.configPath);
108
+ } catch (error) {
109
+ console.log(`ℹ️ [Expo Plugin] LiveWidgets Codegen: ${error.message}`);
110
+ }
111
+ return modConfig;
112
+ },
113
+ ]);
114
+
115
+ config = withDangerousMod(config, [
116
+ 'android',
117
+ async (modConfig) => {
118
+ const projectRoot = modConfig.modRequest.projectRoot;
119
+ try {
120
+ runCodegen(projectRoot, options.configPath);
121
+ } catch (error) {
122
+ console.log(`ℹ️ [Expo Plugin] LiveWidgets Codegen: ${error.message}`);
123
+ }
124
+ return modConfig;
125
+ },
126
+ ]);
127
+
128
+ return config;
129
+ };
130
+
96
131
  /**
97
132
  * Main Expo Config Plugin composite function
98
133
  */
@@ -100,6 +135,7 @@ try {
100
135
  config = withLiveWidgetsInfoPlist(config, options);
101
136
  config = withLiveWidgetsEntitlements(config, options);
102
137
  config = withLiveWidgetsAndroidManifest(config, options);
138
+ config = withLiveWidgetsCodegen(config, options);
103
139
  return config;
104
140
  };
105
141