@momo-kits/native-kits 0.112.1-beta.12 → 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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
// ) {
|
|
13
|
-
// self.theme = theme
|
|
14
|
-
// self.applicationContext = applicationContext
|
|
15
|
-
// self.composeAPI = composeAPI
|
|
16
|
-
// }
|
|
17
|
-
}
|
|
27
|
+
let applicationContext: MiniAppContext?
|
|
28
|
+
let composeApi: KitComposeApi
|
|
29
|
+
|
|
30
|
+
public init(applicationContext: MiniAppContext?, composeApi: KitComposeApi) {
|
|
31
|
+
self.applicationContext = applicationContext
|
|
32
|
+
self.composeApi = composeApi
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -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:
|
|
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:
|
|
121
|
+
headerRight: (()->any View)? = {HeaderRight()},
|
|
122
122
|
goBack: (() -> Void)? = nil,
|
|
123
123
|
opacity: CGFloat? = nil,
|
|
124
124
|
animatedHeader: AnimatedHeader? = nil,
|
|
@@ -162,9 +162,10 @@ public struct Header: View {
|
|
|
162
162
|
|
|
163
163
|
Spacer()
|
|
164
164
|
|
|
165
|
-
if
|
|
166
|
-
|
|
165
|
+
if (headerRight != nil) {
|
|
166
|
+
AnyView(headerRight!())
|
|
167
167
|
}
|
|
168
|
+
|
|
168
169
|
}
|
|
169
170
|
.frame(height: 52)
|
|
170
171
|
.padding(.horizontal)
|
|
@@ -95,54 +95,54 @@ struct ToolkitHeaderRight: View {
|
|
|
95
95
|
|
|
96
96
|
// MARK: - Actions
|
|
97
97
|
private func onPressShortcut() {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
98
|
+
environment.composeApi.request(
|
|
99
|
+
funcName: "onToolAction",
|
|
100
|
+
params: ["item": ["key": "onFavorite"]]
|
|
101
|
+
) { _ in
|
|
102
|
+
isFavorite.toggle()
|
|
103
|
+
}
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
private func onPressHelpCenter() {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
107
|
+
let context = environment.applicationContext
|
|
108
|
+
let paramMap: [String: Any] = [
|
|
109
|
+
"appId": context?.appId,
|
|
110
|
+
"code": context?.appCode,
|
|
111
|
+
"name": context?.appName,
|
|
112
|
+
"icon": context?.appIcon,
|
|
113
|
+
"description": context?.description
|
|
114
|
+
]
|
|
115
|
+
environment.composeApi.request(
|
|
116
|
+
funcName: "showHelpCenter",
|
|
117
|
+
params: paramMap
|
|
118
|
+
) { _ in }
|
|
119
119
|
|
|
120
120
|
print("Press help center")
|
|
121
121
|
}
|
|
122
122
|
|
|
123
123
|
private func onPressClose() {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
124
|
+
environment.composeApi.request(
|
|
125
|
+
funcName: "dismiss",
|
|
126
|
+
params: ""
|
|
127
|
+
) { _ in }
|
|
128
128
|
}
|
|
129
129
|
|
|
130
130
|
private func onPressMore() {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
131
|
+
let context = environment.applicationContext
|
|
132
|
+
let params: [String: Any] = [
|
|
133
|
+
"tools": headerRight?.tools.map { $0.toMap() } ?? [],
|
|
134
|
+
"context": [
|
|
135
|
+
"appId": context?.appId,
|
|
136
|
+
"code": context?.appCode,
|
|
137
|
+
"name": context?.appName,
|
|
138
|
+
"icon": context?.appIcon,
|
|
139
|
+
"description": context?.description
|
|
140
|
+
]
|
|
141
|
+
]
|
|
142
|
+
environment.composeApi.request(
|
|
143
|
+
funcName: "showTools",
|
|
144
|
+
params: params
|
|
145
|
+
) { _ in }
|
|
146
146
|
}
|
|
147
147
|
|
|
148
148
|
private func getNavigationButtonConfig() -> NavigationButtonConfig {
|
|
@@ -238,4 +238,4 @@ struct NavigationButton: View {
|
|
|
238
238
|
}
|
|
239
239
|
}
|
|
240
240
|
}
|
|
241
|
-
}
|
|
241
|
+
}
|
|
@@ -20,7 +20,7 @@ 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: (any View)?
|
|
23
|
+
var headerRight: (()->any View)? = {HeaderRight()}
|
|
24
24
|
var animatedHeader: AnimatedHeader? = nil
|
|
25
25
|
var layoutOffset: CGFloat
|
|
26
26
|
var inputSearchProps: InputSearchProps? = nil
|
|
@@ -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:
|
|
43
|
+
headerRight: (()->any View)? = {HeaderRight()},
|
|
44
44
|
animatedHeader: AnimatedHeader? = nil,
|
|
45
45
|
layoutOffset: CGFloat = 56,
|
|
46
46
|
inputSearchProps: InputSearchProps? = nil,
|
|
@@ -93,7 +93,7 @@ public struct Screen<Content: View>: View {
|
|
|
93
93
|
headerType: headerType,
|
|
94
94
|
titlePosition: titlePosition,
|
|
95
95
|
title: title,
|
|
96
|
-
|
|
96
|
+
headerRight: headerRight,
|
|
97
97
|
goBack: goBack,
|
|
98
98
|
opacity: min(scrollOffset / 114, 1),
|
|
99
99
|
animatedHeader: animatedHeader,
|
package/package.json
CHANGED
|
@@ -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
|
-
}
|