react-native-live-widgets 1.2.1 → 1.2.3
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 +37 -0
- package/README.md +89 -49
- package/android/src/main/AndroidManifest.xml +12 -0
- package/android/src/main/assets/fonts/MaterialIcons-Regular.ttf +0 -0
- package/android/src/main/java/com/reactnativeliveactivity/bridge/LiveActivityModule.kt +61 -1
- package/android/src/main/java/com/reactnativeliveactivity/liveactivity/LiveActivityNotifier.kt +153 -17
- package/android/src/main/java/com/reactnativeliveactivity/liveactivity/LiveActivityReceiver.kt +1 -1
- package/android/src/main/java/com/reactnativeliveactivity/renderer/DynamicWidgetCanvasRenderer.kt +86 -13
- package/android/src/main/java/com/reactnativeliveactivity/storage/DynamicWidgetImageCache.kt +53 -0
- package/android/src/main/java/com/reactnativeliveactivity/storage/DynamicWidgetStateStore.kt +647 -104
- package/android/src/main/java/com/reactnativeliveactivity/widgets/DynamicHomeScreenWidgetProvider.kt +3 -1
- package/android/src/main/java/com/reactnativeliveactivity/widgets/DynamicQuickSettingsTileService.kt +120 -0
- package/app.plugin.js +36 -0
- package/assets/MaterialIcons.json +2236 -0
- package/cli/codegen.js +889 -0
- package/cli/setup.js +323 -63
- package/docs/EXPO-GUIDE-EN.md +21 -3
- package/docs/EXPO-GUIDE-VI.md +21 -3
- package/docs/GUIDE-EN.md +203 -21
- package/docs/GUIDE-VI.md +207 -22
- package/docs/index.html +1461 -226
- package/docs/llms-full.txt +15 -0
- package/docs/llms.txt +16 -7
- package/ios/Bridge/LiveActivityModule.swift +333 -44
- package/ios/Intents/DynamicWidgetActionIntent.swift +57 -2
- package/ios/Models/DynamicLayoutModels.swift +114 -4
- package/ios/Renderer/DynamicNodeView.swift +15 -6
- package/ios/Storage/DynamicWidgetStateStore.swift +649 -38
- package/ios/Widgets/DynamicControlWidget.swift +63 -0
- package/ios/Widgets/DynamicHomeScreenWidget.swift +99 -26
- package/ios/Widgets/DynamicLiveActivityWidget.swift +25 -4
- package/lib/builder.d.ts +50 -7
- package/lib/builder.d.ts.map +1 -1
- package/lib/builder.js +326 -18
- package/lib/builder.js.map +1 -1
- package/lib/hooks.d.ts +13 -9
- package/lib/hooks.d.ts.map +1 -1
- package/lib/hooks.js +70 -12
- package/lib/hooks.js.map +1 -1
- package/lib/index.d.ts +80 -7
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +303 -59
- package/lib/index.js.map +1 -1
- package/lib/ir.d.ts.map +1 -1
- package/lib/ir.js +9 -2
- package/lib/ir.js.map +1 -1
- package/lib/jsx.d.ts +11 -7
- package/lib/jsx.d.ts.map +1 -1
- package/lib/jsx.js +50 -13
- package/lib/jsx.js.map +1 -1
- package/lib/material-icons.generated.d.ts +8 -0
- package/lib/material-icons.generated.d.ts.map +1 -0
- package/lib/material-icons.generated.js +9 -0
- package/lib/material-icons.generated.js.map +1 -0
- package/lib/preview.d.ts +11 -4
- package/lib/preview.d.ts.map +1 -1
- package/lib/preview.js +150 -82
- package/lib/preview.js.map +1 -1
- package/lib/sf-symbols.generated.d.ts +8 -0
- package/lib/sf-symbols.generated.d.ts.map +1 -0
- package/lib/sf-symbols.generated.js +9 -0
- package/lib/sf-symbols.generated.js.map +1 -0
- package/lib/types.d.ts +302 -18
- package/lib/types.d.ts.map +1 -1
- package/package.json +6 -2
- package/scripts/build.js +98 -0
- package/scripts/generate-material-icons.js +93 -0
- package/scripts/generate-sf-symbols.js +95 -0
- package/scripts/release.js +115 -0
- package/scripts/test-ir-semantic.js +314 -0
- package/src/builder.ts +382 -24
- package/src/hooks.ts +88 -12
- package/src/index.ts +319 -56
- package/src/ir.ts +8 -2
- package/src/jsx.tsx +69 -21
- package/src/material-icons.generated.ts +3844 -0
- package/src/preview.tsx +235 -81
- package/src/sf-symbols.generated.ts +9533 -0
- package/src/types.ts +348 -18
package/android/src/main/java/com/reactnativeliveactivity/widgets/DynamicHomeScreenWidgetProvider.kt
CHANGED
|
@@ -91,6 +91,7 @@ class DynamicHomeScreenWidgetProvider : AppWidgetProvider() {
|
|
|
91
91
|
val family = when {
|
|
92
92
|
widgetWidthDp < 245f -> "small"
|
|
93
93
|
widgetHeightDp < 195f -> "medium"
|
|
94
|
+
widgetHeightDp >= 280f -> "extraLarge"
|
|
94
95
|
else -> "large"
|
|
95
96
|
}
|
|
96
97
|
|
|
@@ -206,7 +207,8 @@ class DynamicHomeScreenWidgetProvider : AppWidgetProvider() {
|
|
|
206
207
|
return when (family) {
|
|
207
208
|
"small" -> obj.optJSONObject("small") ?: obj.optJSONObject("medium") ?: obj.optJSONObject("large")
|
|
208
209
|
"medium" -> obj.optJSONObject("medium") ?: obj.optJSONObject("large") ?: obj.optJSONObject("small")
|
|
209
|
-
|
|
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")
|
|
210
212
|
}
|
|
211
213
|
}
|
|
212
214
|
|
package/android/src/main/java/com/reactnativeliveactivity/widgets/DynamicQuickSettingsTileService.kt
ADDED
|
@@ -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
|
+
}
|
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
|
|