@momo-kits/native-kits 0.112.1-beta.10 → 0.112.1-beta.11
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/src/commonMain/kotlin/vn/momo/kits/application/HeaderRight.kt +1 -1
- package/ios/Application/ApplicationContext.swift +13 -0
- package/ios/Application/ApplicationEnvironment.swift +17 -0
- package/ios/Application/ComposeApi.swift +22 -0
- package/ios/Application/HeaderRight.swift +11 -6
- package/ios/Application/Screen.swift +45 -11
- package/package.json +1 -1
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
|
|
3
|
+
public class ApplicationContext {
|
|
4
|
+
public static let shared = ApplicationContext()
|
|
5
|
+
|
|
6
|
+
public var appId: String = ""
|
|
7
|
+
public var appCode: String = ""
|
|
8
|
+
public var appName: Any? = nil
|
|
9
|
+
public var appIcon: String = ""
|
|
10
|
+
public var description: Any? = nil
|
|
11
|
+
|
|
12
|
+
private init() {}
|
|
13
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import SwiftUI
|
|
2
|
+
|
|
3
|
+
public class ApplicationEnvironment: ObservableObject {
|
|
4
|
+
@Published public var theme: Theme
|
|
5
|
+
@Published public var applicationContext: ApplicationContext
|
|
6
|
+
@Published public var composeAPI: ComposeApi
|
|
7
|
+
|
|
8
|
+
public init(
|
|
9
|
+
theme: Theme,
|
|
10
|
+
applicationContext: ApplicationContext,
|
|
11
|
+
composeAPI: ComposeApi
|
|
12
|
+
) {
|
|
13
|
+
self.theme = theme
|
|
14
|
+
self.applicationContext = applicationContext
|
|
15
|
+
self.composeAPI = composeAPI
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
|
|
3
|
+
public protocol ComposeApi {
|
|
4
|
+
func request(funcName: String, params: Any, _ completion: ((String) -> Void)?)
|
|
5
|
+
func request(funcName: String, params: Any) -> String
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
// Default implementation
|
|
9
|
+
public class ComposeApiImpl: ComposeApi {
|
|
10
|
+
public static let shared = ComposeApiImpl()
|
|
11
|
+
|
|
12
|
+
private init() {}
|
|
13
|
+
|
|
14
|
+
public func request(funcName: String, params: Any, _ completion: ((String) -> Void)?) {
|
|
15
|
+
// Implement your API request logic here
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
public func request(funcName: String, params: Any) -> String {
|
|
19
|
+
// Implement your API request logic here
|
|
20
|
+
return ""
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import SwiftUI
|
|
2
|
+
import Foundation
|
|
2
3
|
|
|
3
4
|
public struct HeaderRightData {
|
|
4
5
|
var useShortcut: Bool
|
|
@@ -87,10 +88,11 @@ struct ToolkitHeaderRight: View {
|
|
|
87
88
|
var headerRight: HeaderRightData?
|
|
88
89
|
@State private var isFavorite: Bool = false
|
|
89
90
|
@State private var isLoading: Bool = false
|
|
91
|
+
@EnvironmentObject private var environment: ApplicationEnvironment
|
|
90
92
|
|
|
91
93
|
// MARK: - Actions
|
|
92
94
|
private func onPressShortcut() {
|
|
93
|
-
|
|
95
|
+
environment.composeAPI.request(
|
|
94
96
|
funcName: "onToolAction",
|
|
95
97
|
params: ["item": ["key": "onFavorite"]]
|
|
96
98
|
) { _ in
|
|
@@ -99,7 +101,7 @@ struct ToolkitHeaderRight: View {
|
|
|
99
101
|
}
|
|
100
102
|
|
|
101
103
|
private func onPressHelpCenter() {
|
|
102
|
-
let context =
|
|
104
|
+
let context = environment.applicationContext
|
|
103
105
|
let paramMap: [String: Any] = [
|
|
104
106
|
"appId": context.appId,
|
|
105
107
|
"code": context.appCode,
|
|
@@ -107,18 +109,21 @@ struct ToolkitHeaderRight: View {
|
|
|
107
109
|
"icon": context.appIcon,
|
|
108
110
|
"description": context.description
|
|
109
111
|
]
|
|
110
|
-
|
|
112
|
+
environment.composeAPI.request(
|
|
111
113
|
funcName: "showHelpCenter",
|
|
112
114
|
params: paramMap
|
|
113
115
|
) { _ in }
|
|
114
116
|
}
|
|
115
117
|
|
|
116
118
|
private func onPressClose() {
|
|
117
|
-
|
|
119
|
+
environment.composeAPI.request(
|
|
120
|
+
funcName: "dismiss",
|
|
121
|
+
params: ""
|
|
122
|
+
) { _ in }
|
|
118
123
|
}
|
|
119
124
|
|
|
120
125
|
private func onPressMore() {
|
|
121
|
-
let context =
|
|
126
|
+
let context = environment.applicationContext
|
|
122
127
|
let params: [String: Any] = [
|
|
123
128
|
"tools": headerRight?.tools.map { $0.toMap() } ?? [],
|
|
124
129
|
"context": [
|
|
@@ -129,7 +134,7 @@ struct ToolkitHeaderRight: View {
|
|
|
129
134
|
"description": context.description
|
|
130
135
|
]
|
|
131
136
|
]
|
|
132
|
-
|
|
137
|
+
environment.composeAPI.request(
|
|
133
138
|
funcName: "showTools",
|
|
134
139
|
params: params
|
|
135
140
|
) { _ in }
|
|
@@ -209,19 +209,53 @@ public struct Header: View {
|
|
|
209
209
|
}
|
|
210
210
|
|
|
211
211
|
public var body: some View {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
212
|
+
if headerType != .none {
|
|
213
|
+
VStack(spacing: 0) {
|
|
214
|
+
ZStack {
|
|
215
|
+
HStack {
|
|
216
|
+
if let goBack = goBack {
|
|
217
|
+
Button(action: goBack) {
|
|
218
|
+
Text("Back")
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
Spacer()
|
|
223
|
+
|
|
224
|
+
if headerRight != nil {
|
|
225
|
+
HeaderRight(headerRight: headerRight)
|
|
226
|
+
.opacity(animatedHeader != nil ? opacity ?? 1 : 1)
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
if animatedHeader == nil {
|
|
231
|
+
HeaderBackground(headerType: headerType, scrollState: scrollState)
|
|
232
|
+
} else {
|
|
233
|
+
Color.white.opacity(Double(min(scrollState / 114, 1)))
|
|
234
|
+
.overlay(HeaderBackground(headerType: headerType, scrollState: scrollState))
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
HStack {
|
|
238
|
+
if goBack != nil && titlePosition == .left {
|
|
239
|
+
Spacer().frame(width: 40)
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
if let inputProps = inputSearchProps {
|
|
243
|
+
} else {
|
|
244
|
+
Text(title)
|
|
245
|
+
.font(.headline)
|
|
246
|
+
.foregroundColor(Colors.black17)
|
|
247
|
+
.frame(maxWidth: titlePosition == .center ? .infinity : nil,
|
|
248
|
+
alignment: titlePosition == .center ? .center : .leading)
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
if titlePosition == .left {
|
|
252
|
+
Spacer()
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
.frame(height: 52)
|
|
256
|
+
.padding(.horizontal)
|
|
216
257
|
}
|
|
217
258
|
}
|
|
218
|
-
|
|
219
|
-
Spacer()
|
|
220
|
-
|
|
221
|
-
if headerRight != nil {
|
|
222
|
-
HeaderRight(headerRight: headerRight)
|
|
223
|
-
.opacity(animatedHeader != nil ? opacity ?? 1 : 1)
|
|
224
|
-
}
|
|
225
259
|
}
|
|
226
260
|
}
|
|
227
261
|
}
|