@momo-kits/native-kits 0.162.2-sp.6 → 0.162.2-sp.7
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/ios/Application/ApplicationEnvironment.swift +11 -0
- package/ios/Application/HeaderRight.swift +1 -1
- package/ios/Application/Navigation/NavigationContainer.swift +16 -0
- package/ios/Colors+Radius+Spacing/MoMoUIKitsResources.swift +2 -32
- package/ios/Extensions/Color++.swift +29 -0
- package/ios/native-kits.podspec +1 -1
- package/ios-demo/MoMoUIKitsDemo.podspec +1 -1
- package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/Home.swift +16 -2
- package/ios-demo/Sources/MoMoUIKitsDemo/SwiftUIDemoBrowserView.swift +4 -4
- package/package.json +1 -1
|
@@ -48,3 +48,14 @@ public class ApplicationEnvironment: ObservableObject {
|
|
|
48
48
|
self.config = config
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
|
+
|
|
52
|
+
private struct ApplicationEnvironmentKey: EnvironmentKey {
|
|
53
|
+
static let defaultValue = ApplicationEnvironment()
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public extension EnvironmentValues {
|
|
57
|
+
var applicationEnvironment: ApplicationEnvironment {
|
|
58
|
+
get { self[ApplicationEnvironmentKey.self] }
|
|
59
|
+
set { self[ApplicationEnvironmentKey.self] = newValue }
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -101,7 +101,7 @@ struct ToolkitHeaderRight: View {
|
|
|
101
101
|
var tintColor: Color?
|
|
102
102
|
@State private var isFavorite: Bool = false
|
|
103
103
|
@State private var isLoading: Bool = false
|
|
104
|
-
@
|
|
104
|
+
@Environment(\.applicationEnvironment) private var environment
|
|
105
105
|
|
|
106
106
|
private func apiValue(_ value: Any?) -> Any {
|
|
107
107
|
value ?? NSNull()
|
|
@@ -13,6 +13,7 @@ import SwiftUI
|
|
|
13
13
|
@available(iOS 16.0, *)
|
|
14
14
|
public struct NavigationContainer<Initial: View>: View {
|
|
15
15
|
@StateObject private var navigator: Navigator
|
|
16
|
+
@StateObject private var applicationEnvironment: ApplicationEnvironment
|
|
16
17
|
|
|
17
18
|
private let setNavigator: ((Navigator) -> Void)?
|
|
18
19
|
private let composeApi: KitComposeApi?
|
|
@@ -21,7 +22,9 @@ public struct NavigationContainer<Initial: View>: View {
|
|
|
21
22
|
initialScreenName: String = "",
|
|
22
23
|
@ViewBuilder initialScreen: @escaping () -> Initial,
|
|
23
24
|
options: NavigationOptions? = nil,
|
|
25
|
+
applicationContext: MiniAppContext? = nil,
|
|
24
26
|
composeApi: KitComposeApi? = nil,
|
|
27
|
+
config: KitConfig? = nil,
|
|
25
28
|
setNavigator: ((Navigator) -> Void)? = nil
|
|
26
29
|
) {
|
|
27
30
|
let nav = Navigator(
|
|
@@ -31,6 +34,13 @@ public struct NavigationContainer<Initial: View>: View {
|
|
|
31
34
|
composeApi: composeApi
|
|
32
35
|
)
|
|
33
36
|
_navigator = StateObject(wrappedValue: nav)
|
|
37
|
+
_applicationEnvironment = StateObject(
|
|
38
|
+
wrappedValue: ApplicationEnvironment(
|
|
39
|
+
applicationContext: applicationContext,
|
|
40
|
+
composeApi: composeApi,
|
|
41
|
+
config: config
|
|
42
|
+
)
|
|
43
|
+
)
|
|
34
44
|
self.composeApi = composeApi
|
|
35
45
|
self.setNavigator = setNavigator
|
|
36
46
|
}
|
|
@@ -43,14 +53,20 @@ public struct NavigationContainer<Initial: View>: View {
|
|
|
43
53
|
}
|
|
44
54
|
}
|
|
45
55
|
.environmentObject(navigator)
|
|
56
|
+
.environmentObject(applicationEnvironment)
|
|
57
|
+
.environment(\.applicationEnvironment, applicationEnvironment)
|
|
46
58
|
.fullScreenCover(item: $navigator.presented) { route in
|
|
47
59
|
screenView(forDialog: route)
|
|
48
60
|
.environmentObject(navigator)
|
|
61
|
+
.environmentObject(applicationEnvironment)
|
|
62
|
+
.environment(\.applicationEnvironment, applicationEnvironment)
|
|
49
63
|
}
|
|
50
64
|
.overlay {
|
|
51
65
|
if let item = navigator.overplay {
|
|
52
66
|
OverplayHost(item: item)
|
|
53
67
|
.environmentObject(navigator)
|
|
68
|
+
.environmentObject(applicationEnvironment)
|
|
69
|
+
.environment(\.applicationEnvironment, applicationEnvironment)
|
|
54
70
|
}
|
|
55
71
|
}
|
|
56
72
|
.onAppear {
|
|
@@ -1,32 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
private final class MoMoUIKitsBundleToken {}
|
|
5
|
-
|
|
6
|
-
enum MoMoUIKitsResources {
|
|
7
|
-
static let bundle: Bundle = {
|
|
8
|
-
let bundleName = "MoMoUIKitsResources"
|
|
9
|
-
let tokenBundle = Bundle(for: MoMoUIKitsBundleToken.self)
|
|
10
|
-
let candidates = [
|
|
11
|
-
Bundle.main.resourceURL,
|
|
12
|
-
tokenBundle.resourceURL,
|
|
13
|
-
tokenBundle.bundleURL
|
|
14
|
-
]
|
|
15
|
-
|
|
16
|
-
for candidate in candidates {
|
|
17
|
-
guard let bundleURL = candidate?.appendingPathComponent("\(bundleName).bundle"),
|
|
18
|
-
let bundle = Bundle(url: bundleURL) else {
|
|
19
|
-
continue
|
|
20
|
-
}
|
|
21
|
-
return bundle
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return tokenBundle
|
|
25
|
-
}()
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
extension Color {
|
|
29
|
-
static func momoAsset(_ name: String) -> Color {
|
|
30
|
-
Color(name, bundle: MoMoUIKitsResources.bundle)
|
|
31
|
-
}
|
|
32
|
-
}
|
|
1
|
+
// Resource bundle lookup lives in Extensions/Color++.swift so existing Pods
|
|
2
|
+
// projects that already include the color extension can resolve Color.momoAsset.
|
|
@@ -1,6 +1,35 @@
|
|
|
1
1
|
import SwiftUI
|
|
2
|
+
import Foundation
|
|
3
|
+
|
|
4
|
+
private final class MoMoUIKitsBundleToken {}
|
|
5
|
+
|
|
6
|
+
enum MoMoUIKitsResources {
|
|
7
|
+
static let bundle: Bundle = {
|
|
8
|
+
let bundleName = "MoMoUIKitsResources"
|
|
9
|
+
let tokenBundle = Bundle(for: MoMoUIKitsBundleToken.self)
|
|
10
|
+
let candidates = [
|
|
11
|
+
Bundle.main.resourceURL,
|
|
12
|
+
tokenBundle.resourceURL,
|
|
13
|
+
tokenBundle.bundleURL
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
for candidate in candidates {
|
|
17
|
+
guard let bundleURL = candidate?.appendingPathComponent("\(bundleName).bundle"),
|
|
18
|
+
let bundle = Bundle(url: bundleURL) else {
|
|
19
|
+
continue
|
|
20
|
+
}
|
|
21
|
+
return bundle
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return tokenBundle
|
|
25
|
+
}()
|
|
26
|
+
}
|
|
2
27
|
|
|
3
28
|
public extension Color {
|
|
29
|
+
static func momoAsset(_ name: String) -> Color {
|
|
30
|
+
Color(name, bundle: MoMoUIKitsResources.bundle)
|
|
31
|
+
}
|
|
32
|
+
|
|
4
33
|
init(hex: UInt, alpha: Double = 1) {
|
|
5
34
|
self.init(
|
|
6
35
|
.sRGB,
|
package/ios/native-kits.podspec
CHANGED
|
@@ -97,9 +97,20 @@ public struct HomeView: View {
|
|
|
97
97
|
// forwarded into the content for filtering.
|
|
98
98
|
@State private var searchText = ""
|
|
99
99
|
private let onOpenCompose: () -> Void
|
|
100
|
+
private let applicationContext: MiniAppContext?
|
|
101
|
+
private let composeApi: KitComposeApi?
|
|
102
|
+
private let config: KitConfig?
|
|
100
103
|
|
|
101
|
-
public init(
|
|
104
|
+
public init(
|
|
105
|
+
onOpenCompose: @escaping () -> Void = {},
|
|
106
|
+
applicationContext: MiniAppContext? = nil,
|
|
107
|
+
composeApi: KitComposeApi? = nil,
|
|
108
|
+
config: KitConfig? = nil
|
|
109
|
+
) {
|
|
102
110
|
self.onOpenCompose = onOpenCompose
|
|
111
|
+
self.applicationContext = applicationContext
|
|
112
|
+
self.composeApi = composeApi
|
|
113
|
+
self.config = config
|
|
103
114
|
}
|
|
104
115
|
|
|
105
116
|
public var body: some View {
|
|
@@ -182,7 +193,10 @@ public struct HomeView: View {
|
|
|
182
193
|
position: .right,
|
|
183
194
|
bottomPadding: nil
|
|
184
195
|
)
|
|
185
|
-
)
|
|
196
|
+
),
|
|
197
|
+
applicationContext: applicationContext,
|
|
198
|
+
composeApi: composeApi,
|
|
199
|
+
config: config
|
|
186
200
|
)
|
|
187
201
|
}
|
|
188
202
|
}
|
|
@@ -9,15 +9,15 @@ struct SwiftUIDemoBrowserView: View {
|
|
|
9
9
|
var body: some View {
|
|
10
10
|
Group {
|
|
11
11
|
if #available(iOS 16.0, *) {
|
|
12
|
-
HomeView(
|
|
12
|
+
HomeView(
|
|
13
|
+
onOpenCompose: onOpenCompose,
|
|
14
|
+
applicationContext: context.miniAppContext
|
|
15
|
+
)
|
|
13
16
|
} else {
|
|
14
17
|
fallbackBrowser
|
|
15
18
|
}
|
|
16
19
|
}
|
|
17
20
|
.environment(\.appTheme, defaultTheme)
|
|
18
|
-
.environmentObject(
|
|
19
|
-
ApplicationEnvironment(applicationContext: context.miniAppContext)
|
|
20
|
-
)
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
private var fallbackBrowser: some View {
|