@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.
@@ -112,7 +112,7 @@ fun ToolkitHeaderRight(headerRight: HeaderRightData? = null) {
112
112
  }
113
113
 
114
114
  fun onPressClose() {
115
- api?.request("dismiss", "")
115
+ api?.request("dismiss", "", {_ -> })
116
116
  }
117
117
 
118
118
  fun onPressMore() {
@@ -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
- ComposeApi.shared.request(
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 = ApplicationContext.shared
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
- ComposeApi.shared.request(
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
- ComposeApi.shared.request(funcName: "dismiss", params: "")
119
+ environment.composeAPI.request(
120
+ funcName: "dismiss",
121
+ params: ""
122
+ ) { _ in }
118
123
  }
119
124
 
120
125
  private func onPressMore() {
121
- let context = ApplicationContext.shared
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
- ComposeApi.shared.request(
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
- HStack {
213
- if let goBack = goBack {
214
- Button(action: goBack) {
215
- Text("Back")
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/native-kits",
3
- "version": "0.112.1-beta.10",
3
+ "version": "0.112.1-beta.11",
4
4
  "private": false,
5
5
  "dependencies": {},
6
6
  "devDependencies": {},