Skip to content

Commit

Permalink
Add minimal UIColor support
Browse files Browse the repository at this point in the history
  • Loading branch information
aabewhite committed Dec 24, 2024
1 parent c11cdd7 commit 77d0a41
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 7 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ Support levels:
<li><code>init(red: Double, green: Double, blue: Double, opacity: Double = 1.0)</code></li>
<li><code>init(white: Double, opacity: Double = 1.0)</code></li>
<li><code>init(hue: Double, saturation: Double, brightness: Double, opacity: Double = 1.0)</code></li>
<li><code>init(_ color: UIColor)</code></li>
<li><code>static let accentColor: Color</code></li>
<li><code>static let primary: Color</code></li>
<li><code>static let secondary: Color</code></li>
Expand Down Expand Up @@ -1745,6 +1746,21 @@ Support levels:
</details>
</td>
</tr>
<tr>
<tr>
<td>✅</td>
<td><code>#colorLiteral()</code></td>
</tr>
<td>🟠</td>
<td>
<details>
<summary><code>UIColor</code></summary>
<ul>
<li><code>init(red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat)</code></li>
</ul>
</details>
</td>
</tr>
<tr>
<td>🟠</td>
<td>
Expand Down
11 changes: 4 additions & 7 deletions Sources/SkipUI/SkipUI/Color/Color.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,6 @@ public struct Color: ShapeStyle, Hashable, Sendable {
}
#endif

@available(*, unavailable)
public init(_ color: Any) {
#if SKIP
colorImpl = { androidx.compose.ui.graphics.Color.White }
#endif
}

@available(*, unavailable)
public init(cgColor: Any /* CGColor */) {
#if SKIP
Expand Down Expand Up @@ -112,6 +105,10 @@ public struct Color: ShapeStyle, Hashable, Sendable {
#endif
}

public init(_ color: UIColor) {
self.init(red: color.red, green: color.green, blue: color.blue, opacity: color.alpha)
}

private static func clamp(_ value: Double) -> Float {
return max(Float(0.0), min(Float(1.0), Float(value)))
}
Expand Down
23 changes: 23 additions & 0 deletions Sources/SkipUI/SkipUI/UIKit/UIColor.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2023 Skip
//
// This is free software: you can redistribute and/or modify it
// under the terms of the GNU Lesser General Public License 3.0
// as published by the Free Software Foundation https://fsf.org

#if !SKIP
import struct CoreGraphics.CGFloat
#endif

public final class UIColor {
let red: CGFloat
let green: CGFloat
let blue: CGFloat
let alpha: CGFloat

public init(red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat) {
self.red = red
self.green = green
self.blue = blue
self.alpha = alpha
}
}

0 comments on commit 77d0a41

Please sign in to comment.