@momo-kits/native-kits 0.112.1-beta.11 → 0.112.1-beta.13

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.
@@ -1,17 +1,34 @@
1
1
  import SwiftUI
2
2
 
3
+ public protocol KitComposeApi {
4
+ func request(funcName: String, params: Any?) -> String
5
+ func request(funcName: String, params: Any?, onResponse: ((String) -> Void)?) -> String
6
+ func requestCallback(funcName: String, params: Any?, onResponse: ((String) -> Void)?)
7
+ func removeCallback(id: String)
8
+ }
9
+
10
+ public class MiniAppContext {
11
+ public var appId: String = ""
12
+ public var appCode: String = ""
13
+ public var appName: Any? = nil
14
+ public var appIcon: String = ""
15
+ public var description: Any? = nil
16
+
17
+ public init(appId: String, appCode: String, appName: Any? = nil, appIcon: String, description: Any? = nil) {
18
+ self.appId = appId
19
+ self.appCode = appCode
20
+ self.appName = appName
21
+ self.appIcon = appIcon
22
+ self.description = description
23
+ }
24
+ }
25
+
3
26
  public class ApplicationEnvironment: ObservableObject {
4
- @Published public var theme: Theme
5
- @Published public var applicationContext: ApplicationContext
6
- @Published public var composeAPI: ComposeApi
27
+ let applicationContext: MiniAppContext?
28
+ let composeApi: KitComposeApi
7
29
 
8
- public init(
9
- theme: Theme,
10
- applicationContext: ApplicationContext,
11
- composeAPI: ComposeApi
12
- ) {
13
- self.theme = theme
30
+ public init(applicationContext: MiniAppContext?, composeApi: KitComposeApi) {
14
31
  self.applicationContext = applicationContext
15
- self.composeAPI = composeAPI
32
+ self.composeApi = composeApi
16
33
  }
17
- }
34
+ }
@@ -0,0 +1 @@
1
+
@@ -105,7 +105,7 @@ public struct Header: View {
105
105
  var headerType: HeaderType = .default
106
106
  var titlePosition: TitlePosition
107
107
  var title: String
108
- var headerRight: (() -> AnyView)?
108
+ var headerRight: (()->any View)? = {HeaderRight()}
109
109
  var goBack: (() -> Void)?
110
110
  var opacity: CGFloat? = nil
111
111
  var animatedHeader: AnimatedHeader? = nil
@@ -118,7 +118,7 @@ public struct Header: View {
118
118
  headerType: HeaderType = .default,
119
119
  titlePosition: TitlePosition,
120
120
  title: String,
121
- headerRight: (() -> AnyView)? = nil,
121
+ headerRight: (()->any View)? = {HeaderRight()},
122
122
  goBack: (() -> Void)? = nil,
123
123
  opacity: CGFloat? = nil,
124
124
  animatedHeader: AnimatedHeader? = nil,
@@ -160,11 +160,12 @@ public struct Header: View {
160
160
 
161
161
  }
162
162
 
163
- Spacer() // Pushes headerRight to the right
163
+ Spacer()
164
164
 
165
- if let headerRight = headerRight {
166
- headerRight()
165
+ if (headerRight != nil) {
166
+ AnyView(headerRight!())
167
167
  }
168
+
168
169
  }
169
170
  .frame(height: 52)
170
171
  .padding(.horizontal)
@@ -204,12 +205,10 @@ public struct Header: View {
204
205
  .foregroundColor(tintIconColor)
205
206
  .frame(maxWidth: titlePosition == .center ? .infinity : nil, alignment: titlePosition == .center ? .center : .leading)
206
207
  }
207
-
208
208
  Spacer()
209
209
  }
210
210
  .frame(height: 52)
211
211
  .padding(.horizontal)
212
-
213
212
  }
214
213
  .background(Color.clear)
215
214
  }
@@ -74,10 +74,13 @@ struct NavigationButtonConfig {
74
74
  }
75
75
 
76
76
  // MARK: - Components
77
- struct HeaderRight: View {
77
+ public struct HeaderRight: View {
78
+ public init(headerRight: HeaderRightData? = nil) {
79
+ self.headerRight = headerRight
80
+ }
78
81
  var headerRight: HeaderRightData?
79
82
 
80
- var body: some View {
83
+ public var body: some View {
81
84
  HStack(alignment: .center) {
82
85
  ToolkitHeaderRight(headerRight: headerRight)
83
86
  }
@@ -92,7 +95,7 @@ struct ToolkitHeaderRight: View {
92
95
 
93
96
  // MARK: - Actions
94
97
  private func onPressShortcut() {
95
- environment.composeAPI.request(
98
+ environment.composeApi.request(
96
99
  funcName: "onToolAction",
97
100
  params: ["item": ["key": "onFavorite"]]
98
101
  ) { _ in
@@ -103,20 +106,22 @@ struct ToolkitHeaderRight: View {
103
106
  private func onPressHelpCenter() {
104
107
  let context = environment.applicationContext
105
108
  let paramMap: [String: Any] = [
106
- "appId": context.appId,
107
- "code": context.appCode,
108
- "name": context.appName,
109
- "icon": context.appIcon,
110
- "description": context.description
109
+ "appId": context?.appId,
110
+ "code": context?.appCode,
111
+ "name": context?.appName,
112
+ "icon": context?.appIcon,
113
+ "description": context?.description
111
114
  ]
112
- environment.composeAPI.request(
115
+ environment.composeApi.request(
113
116
  funcName: "showHelpCenter",
114
117
  params: paramMap
115
118
  ) { _ in }
119
+
120
+ print("Press help center")
116
121
  }
117
122
 
118
123
  private func onPressClose() {
119
- environment.composeAPI.request(
124
+ environment.composeApi.request(
120
125
  funcName: "dismiss",
121
126
  params: ""
122
127
  ) { _ in }
@@ -127,14 +132,14 @@ struct ToolkitHeaderRight: View {
127
132
  let params: [String: Any] = [
128
133
  "tools": headerRight?.tools.map { $0.toMap() } ?? [],
129
134
  "context": [
130
- "appId": context.appId,
131
- "code": context.appCode,
132
- "name": context.appName,
133
- "icon": context.appIcon,
134
- "description": context.description
135
+ "appId": context?.appId,
136
+ "code": context?.appCode,
137
+ "name": context?.appName,
138
+ "icon": context?.appIcon,
139
+ "description": context?.description
135
140
  ]
136
141
  ]
137
- environment.composeAPI.request(
142
+ environment.composeApi.request(
138
143
  funcName: "showTools",
139
144
  params: params
140
145
  ) { _ in }
@@ -198,7 +203,7 @@ struct ToolkitHeaderRight: View {
198
203
  RoundedRectangle(cornerRadius: 14)
199
204
  .stroke(Color.black.opacity(0.2), lineWidth: 0.2)
200
205
  )
201
- .padding(.leading, 8)
206
+ .padding(.leading, Spacing.S)
202
207
  }
203
208
  }
204
209
  }
@@ -233,4 +238,4 @@ struct NavigationButton: View {
233
238
  }
234
239
  }
235
240
  }
236
- }
241
+ }
@@ -20,13 +20,13 @@ public struct Screen<Content: View>: View {
20
20
  var onContentLayout: ((CGRect) -> Void)?
21
21
  var useAvoidKeyboard: Bool
22
22
  var footer: (() -> AnyView)?
23
- var headerRight: HeaderRightData?
23
+ var headerRight: (()->any View)? = {HeaderRight()}
24
24
  var animatedHeader: AnimatedHeader? = nil
25
25
  var layoutOffset: CGFloat
26
26
  var inputSearchProps: InputSearchProps? = nil
27
27
  var fabProps: FabProps? = nil
28
28
  var content: () -> Content
29
-
29
+
30
30
  public init(
31
31
  backgroundColor: Color? = nil,
32
32
  isBack: Bool = true,
@@ -40,7 +40,7 @@ public struct Screen<Content: View>: View {
40
40
  onContentLayout: ((CGRect) -> Void)? = nil,
41
41
  useAvoidKeyboard: Bool = true,
42
42
  footer: (() -> AnyView)? = nil,
43
- headerRight: HeaderRightData? = nil,
43
+ headerRight: (()->any View)? = {HeaderRight()},
44
44
  animatedHeader: AnimatedHeader? = nil,
45
45
  layoutOffset: CGFloat = 56,
46
46
  inputSearchProps: InputSearchProps? = nil,
@@ -66,19 +66,19 @@ public struct Screen<Content: View>: View {
66
66
  self.fabProps = fabProps
67
67
  self.content = content
68
68
  }
69
-
69
+
70
70
  @State private var scrollOffset: CGFloat = 0
71
-
71
+
72
72
  public var body: some View {
73
73
  GeometryReader { geometry in
74
74
  let safeAreaInsets = geometry.safeAreaInsets
75
75
  let statusBarHeight = safeAreaInsets.top
76
76
  let keyboardHeight: CGFloat = 0
77
77
  let keyboardSize: CGFloat = useAvoidKeyboard ? max(keyboardHeight, 0) : 0
78
-
78
+
79
79
  ZStack {
80
80
  (backgroundColor ?? Color.white).edgesIgnoringSafeArea(.all)
81
-
81
+
82
82
  VStack(spacing: 0) {
83
83
  ZStack {
84
84
  if animatedHeader == nil {
@@ -86,9 +86,9 @@ public struct Screen<Content: View>: View {
86
86
  } else {
87
87
  Color.white.opacity(Double(min(scrollOffset / 114, 1)))
88
88
  .overlay(HeaderBackground(headerType: headerType, scrollState: scrollOffset))
89
-
89
+
90
90
  }
91
-
91
+
92
92
  Header(
93
93
  headerType: headerType,
94
94
  titlePosition: titlePosition,
@@ -101,13 +101,13 @@ public struct Screen<Content: View>: View {
101
101
  inputSearchProps: inputSearchProps
102
102
  ).padding(.bottom, headerType == .extended ? 0 : -safeAreaTopInset())
103
103
  }.padding(.top, -safeAreaTopInset())
104
-
105
-
104
+
105
+
106
106
  VStack(alignment: horizontalAlignment, spacing: 0) {
107
107
  if animatedHeader != nil {
108
108
  Spacer().frame(height: statusBarHeight + 52 + layoutOffset)
109
109
  }
110
-
110
+
111
111
  if scrollable {
112
112
  ScrollView(.vertical, showsIndicators: false) {
113
113
  VStack {
@@ -125,19 +125,19 @@ public struct Screen<Content: View>: View {
125
125
  }
126
126
  }
127
127
  .padding(.bottom, keyboardSize)
128
-
129
-
128
+
129
+
130
130
  if let footerView = footer?() {
131
131
  ZStack(alignment: .top) {
132
132
  Rectangle()
133
133
  .fill(Colors.black20)
134
134
  .frame(height: 4)
135
135
  .shadow(color: Colors.black20.opacity(0.2), radius: 10, x: 0, y: -2)
136
-
136
+
137
137
  Footer(footerView: footerView, keyboardSize: keyboardSize)
138
138
  }
139
139
  }
140
-
140
+
141
141
  if let fabProps = fabProps {
142
142
  FloatingButton(
143
143
  scrollOffset: scrollOffset,
@@ -154,7 +154,7 @@ public struct Screen<Content: View>: View {
154
154
  )
155
155
  }
156
156
  }
157
-
157
+
158
158
  }
159
159
  }
160
160
  }
@@ -163,7 +163,7 @@ public struct Screen<Content: View>: View {
163
163
  struct Footer: View {
164
164
  var footerView: AnyView
165
165
  var keyboardSize: CGFloat
166
-
166
+
167
167
  var body: some View {
168
168
  VStack {
169
169
  footerView
@@ -172,91 +172,3 @@ struct Footer: View {
172
172
  .background(Colors.black01)
173
173
  }
174
174
  }
175
-
176
- public struct Header: View {
177
- var headerType: HeaderType = .default
178
- var titlePosition: TitlePosition
179
- var title: String
180
- var headerRight: HeaderRightData?
181
- var goBack: (() -> Void)?
182
- var opacity: CGFloat? = nil
183
- var animatedHeader: AnimatedHeader? = nil
184
- var scrollState: CGFloat = 0
185
- var inputSearchProps: InputSearchProps? = nil
186
-
187
- @State private var colorFraction: CGFloat = 0
188
-
189
- public init(
190
- headerType: HeaderType = .default,
191
- titlePosition: TitlePosition,
192
- title: String,
193
- headerRight: HeaderRightData? = nil,
194
- goBack: (() -> Void)? = nil,
195
- opacity: CGFloat? = nil,
196
- animatedHeader: AnimatedHeader? = nil,
197
- scrollState: CGFloat = 0,
198
- inputSearchProps: InputSearchProps? = nil
199
- ) {
200
- self.headerType = headerType
201
- self.titlePosition = titlePosition
202
- self.title = title
203
- self.headerRight = headerRight
204
- self.goBack = goBack
205
- self.opacity = opacity
206
- self.animatedHeader = animatedHeader
207
- self.scrollState = scrollState
208
- self.inputSearchProps = inputSearchProps
209
- }
210
-
211
- public var body: some View {
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)
257
- }
258
- }
259
- }
260
- }
261
- }
262
-
@@ -0,0 +1,42 @@
1
+ import SwiftUI
2
+
3
+ public enum DotSize {
4
+ case small
5
+ case large
6
+
7
+ var size: CGFloat {
8
+ switch self {
9
+ case .small: return 10
10
+ case .large: return 16
11
+ }
12
+ }
13
+ }
14
+
15
+ public struct BadgeDot: View {
16
+ var size: DotSize
17
+
18
+ public init(size: DotSize = .large) {
19
+ self.size = size
20
+ }
21
+
22
+ public var body: some View {
23
+ Circle()
24
+ .fill(Colors.red03)
25
+ .frame(width: size.size, height: size.size)
26
+ .overlay(
27
+ Circle()
28
+ .stroke(Colors.black01, lineWidth: 1)
29
+ )
30
+ }
31
+ }
32
+
33
+ #if DEBUG
34
+ struct BadgeDot_Previews: PreviewProvider {
35
+ static var previews: some View {
36
+ VStack(spacing: 10) {
37
+ BadgeDot(size: .small)
38
+ BadgeDot(size: .large)
39
+ }
40
+ }
41
+ }
42
+ #endif
@@ -43,11 +43,11 @@ public struct Icon: View {
43
43
  }
44
44
 
45
45
  public var body: some View {
46
- if let uri = iconSources[source]?.uri {
47
- ImageView(uri)
46
+ // if let uri = iconSources[source]?.uri {
47
+ ImageView(source)
48
48
  .frame(width: size, height: size)
49
49
  .foregroundColor(color)
50
- }
50
+ // }
51
51
  }
52
52
  }
53
53
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/native-kits",
3
- "version": "0.112.1-beta.11",
3
+ "version": "0.112.1-beta.13",
4
4
  "private": false,
5
5
  "dependencies": {},
6
6
  "devDependencies": {},
@@ -1,13 +0,0 @@
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
- }