Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add minimal UIColor support #93

Merged
merged 1 commit into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}
Loading