11//
2- // OpenSwiftUI+UIKit .swift
2+ // UIKitConversions .swift
33// OpenSwiftUI
44//
55// Audited for iOS 18.0
66// Status: WIP
7- // ID: 6DC24D5146AF4B80347A1025025F68EE (SwiftUI? )
7+ // ID: 6DC24D5146AF4B80347A1025025F68EE (SwiftUI)
88
99#if canImport(UIKit)
1010
1111public import OpenSwiftUICore
1212public import UIKit
1313import COpenSwiftUI
1414
15- // MARK: - Color + UIColor
15+ // MARK: - UIColor Conversions
1616
1717@available ( * , deprecated, message: " Use Color(uiColor:) when converting a UIColor, or create a standard Color directly " )
1818@available ( macOS, unavailable)
@@ -146,11 +146,13 @@ extension UIColor: ColorProvider {
146146 }
147147}
148148
149- public extension ColorScheme {
149+ // MARK: - UIUserInterfaceStyle Conversions
150+
151+ extension ColorScheme {
150152 /// Creates a color scheme from its user interface style equivalent.
151153 @available ( macOS, unavailable)
152154 @available ( watchOS, unavailable)
153- init ? ( _ uiUserInterfaceStyle: UIUserInterfaceStyle ) {
155+ public init ? ( _ uiUserInterfaceStyle: UIUserInterfaceStyle ) {
154156 switch uiUserInterfaceStyle {
155157 case . unspecified: return nil
156158 case . light: self = . light
@@ -160,16 +162,45 @@ public extension ColorScheme {
160162 }
161163}
162164
163- public extension UIUserInterfaceStyle {
165+ extension UIUserInterfaceStyle {
164166 /// Creates a user interface style from its ColorScheme equivalent.
165167 @available ( macOS, unavailable)
166168 @available ( watchOS, unavailable)
167- init ( _ colorScheme: ColorScheme ? ) {
169+ public init ( _ colorScheme: ColorScheme ? ) {
168170 switch colorScheme {
169171 case . light: self = . light
170172 case . dark: self = . dark
171173 case nil : self = . unspecified
172174 }
173175 }
174176}
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+
175206#endif
0 commit comments