@momo-kits/native-kits 0.162.29-debug → 0.162.30-debug
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/compose/build.gradle.kts
CHANGED
package/gradle.properties
CHANGED
|
@@ -105,9 +105,25 @@ struct ToolkitHeaderRight: View {
|
|
|
105
105
|
|
|
106
106
|
// MARK: - Actions
|
|
107
107
|
private func onPressShortcut() {
|
|
108
|
+
// onToolAction needs the app context (appId/code) so the host knows which app to (un)favorite;
|
|
109
|
+
// without it the favorite is a no-op. Mirrors onPressMore below and the Compose HeaderRight.
|
|
110
|
+
let context = environment.applicationContext
|
|
108
111
|
environment.composeApi?.request(
|
|
109
112
|
funcName: "onToolAction",
|
|
110
|
-
params: [
|
|
113
|
+
params: [
|
|
114
|
+
"item": ["key": "onFavorite"],
|
|
115
|
+
"context": [
|
|
116
|
+
"appId": context?.appId,
|
|
117
|
+
"code": context?.appCode,
|
|
118
|
+
"name": context?.appName,
|
|
119
|
+
"icon": context?.appIcon,
|
|
120
|
+
"description": context?.description,
|
|
121
|
+
"support": context?.support,
|
|
122
|
+
"toolkitConfig": context?.toolkitConfig,
|
|
123
|
+
"providerId": context?.providerId,
|
|
124
|
+
"permissions": context?.permissions
|
|
125
|
+
]
|
|
126
|
+
]
|
|
111
127
|
) { _ in
|
|
112
128
|
isFavorite.toggle()
|
|
113
129
|
}
|
|
@@ -168,6 +184,22 @@ struct ToolkitHeaderRight: View {
|
|
|
168
184
|
}
|
|
169
185
|
}
|
|
170
186
|
|
|
187
|
+
// Load the current favorite state on appear so the star reflects reality; without this the button
|
|
188
|
+
// always renders "not favorited" until the user taps it. Mirrors the Compose LaunchedEffect.
|
|
189
|
+
private func loadFavoriteState() {
|
|
190
|
+
let context = environment.applicationContext
|
|
191
|
+
environment.composeApi?.request(
|
|
192
|
+
funcName: "isFavoriteApp",
|
|
193
|
+
params: ["code": context?.appCode]
|
|
194
|
+
) { response in
|
|
195
|
+
guard let data = response.data(using: .utf8),
|
|
196
|
+
let json = try? JSONSerialization.jsonObject(with: data) as? [String: Any] else {
|
|
197
|
+
return
|
|
198
|
+
}
|
|
199
|
+
isFavorite = (json["response"] as? Bool) ?? false
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
171
203
|
private func getNavigationButtonConfig() -> NavigationButtonConfig {
|
|
172
204
|
let totalTools = headerRight?.tools.reduce(0) { $0 + $1.items.count } ?? 0
|
|
173
205
|
var icon = isFavorite ? "pin_star_checked" : "pin_star"
|
|
@@ -231,6 +263,9 @@ struct ToolkitHeaderRight: View {
|
|
|
231
263
|
)
|
|
232
264
|
.padding(.leading, Spacing.S)
|
|
233
265
|
}
|
|
266
|
+
.onAppear {
|
|
267
|
+
loadFavoriteState()
|
|
268
|
+
}
|
|
234
269
|
}
|
|
235
270
|
}
|
|
236
271
|
|