1
1
//
2
- // OpenSwiftUI+UIKit .swift
2
+ // UIKitConversions .swift
3
3
// OpenSwiftUI
4
4
//
5
5
// Audited for iOS 18.0
6
6
// Status: WIP
7
- // ID: 6DC24D5146AF4B80347A1025025F68EE (SwiftUI? )
7
+ // ID: 6DC24D5146AF4B80347A1025025F68EE (SwiftUI)
8
8
9
9
#if canImport(UIKit)
10
10
11
11
public import OpenSwiftUICore
12
12
public import UIKit
13
13
import COpenSwiftUI
14
14
15
- // MARK: - Color + UIColor
15
+ // MARK: - UIColor Conversions
16
16
17
17
@available ( * , deprecated, message: " Use Color(uiColor:) when converting a UIColor, or create a standard Color directly " )
18
18
@available ( macOS, unavailable)
@@ -146,11 +146,13 @@ extension UIColor: ColorProvider {
146
146
}
147
147
}
148
148
149
- public extension ColorScheme {
149
+ // MARK: - UIUserInterfaceStyle Conversions
150
+
151
+ extension ColorScheme {
150
152
/// Creates a color scheme from its user interface style equivalent.
151
153
@available ( macOS, unavailable)
152
154
@available ( watchOS, unavailable)
153
- init ? ( _ uiUserInterfaceStyle: UIUserInterfaceStyle ) {
155
+ public init ? ( _ uiUserInterfaceStyle: UIUserInterfaceStyle ) {
154
156
switch uiUserInterfaceStyle {
155
157
case . unspecified: return nil
156
158
case . light: self = . light
@@ -160,16 +162,45 @@ public extension ColorScheme {
160
162
}
161
163
}
162
164
163
- public extension UIUserInterfaceStyle {
165
+ extension UIUserInterfaceStyle {
164
166
/// Creates a user interface style from its ColorScheme equivalent.
165
167
@available ( macOS, unavailable)
166
168
@available ( watchOS, unavailable)
167
- init ( _ colorScheme: ColorScheme ? ) {
169
+ public init ( _ colorScheme: ColorScheme ? ) {
168
170
switch colorScheme {
169
171
case . light: self = . light
170
172
case . dark: self = . dark
171
173
case nil : self = . unspecified
172
174
}
173
175
}
174
176
}
177
+
178
+ // MARK: - UIAccessibilityContrast Conversions [TODO]
179
+
180
+ // ColorSchemeContrast
181
+ // UIAccessibilityContrast
182
+
183
+ // MARK: - UIContentSizeCategory Conversions [WIP]
184
+
185
+ extension DynamicTypeSize {
186
+ /// Create a Dynamic Type size from its `UIContentSizeCategory` equivalent.
187
+ public init ? ( _ uiSizeCategory: UIContentSizeCategory ) {
188
+ switch uiSizeCategory {
189
+ case . extraSmall: self = . xSmall
190
+ case . small: self = . small
191
+ case . medium: self = . medium
192
+ case . large: self = . large
193
+ case . extraLarge: self = . xLarge
194
+ case . extraExtraLarge: self = . xxLarge
195
+ case . extraExtraExtraLarge: self = . xxxLarge
196
+ case . accessibilityMedium: self = . accessibility1
197
+ case . accessibilityLarge: self = . accessibility2
198
+ case . accessibilityExtraLarge: self = . accessibility3
199
+ case . accessibilityExtraExtraLarge: self = . accessibility4
200
+ case . accessibilityExtraExtraExtraLarge: self = . accessibility5
201
+ default : return nil
202
+ }
203
+ }
204
+ }
205
+
175
206
#endif
0 commit comments