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

Fix naming collisions with SwiftUI #50

Merged
merged 1 commit into from
Feb 11, 2020
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
112 changes: 56 additions & 56 deletions Example/Tests/Colors/ColorWcagTests.swift

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Example/Tests/Colors/ImageAreaTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ImageAreaTests: QuickSpec {
override func spec() {
describe("The ImageArea class") {
var sut: ImageArea!
let testImage = Image.mock(withColor: .white, rect: CGRect(x: 0, y: 0, width: 3, height: 3))
let testImage = ImageType.mock(withColor: .white, rect: CGRect(x: 0, y: 0, width: 3, height: 3))

context("calling rect()") {
var actualRect: CGRect!
Expand Down
6 changes: 3 additions & 3 deletions Example/Tests/Colors/ImageAverageColorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ import Quick
class ImageAverageColorTests: QuickSpec {
override func spec() {
describe("The UIImage/NSImage class") {
var sut: Image!
var sut: ImageType!

context("when calling averageColor() for a red image") {
beforeEach {
sut = Image.mock(withColor: .red, rect: CGRect(x: 0, y: 0, width: 3, height: 3))
sut = ImageType.mock(withColor: .red, rect: CGRect(x: 0, y: 0, width: 3, height: 3))
}

it("returns .red") {
expect(sut.averageColor()?.rgbaColor).to(equal(Color.red.rgbaColor))
expect(sut.averageColor()?.rgbaColor).to(equal(ColorType.red.rgbaColor))
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Example/Tests/Colors/Mocks/Image+mock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

import CoreImage

extension Image {
class func mock(withColor color: Color, rect: CGRect = CGRect(x: 0, y: 0, width: 1, height: 1)) -> Image {
extension ImageType {
class func mock(withColor color: ColorType, rect: CGRect = CGRect(x: 0, y: 0, width: 1, height: 1)) -> ImageType {
#if os(iOS) || os(tvOS)

UIGraphicsBeginImageContext(rect.size)
Expand Down
28 changes: 14 additions & 14 deletions Source/Colors/Extensions/Color+wcag.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@
import UIKit

/// Typealias used for colors. It maps to UIColor.
public typealias Color = UIColor
public typealias ColorType = UIColor

/// Typealias used for fonts. It maps to UIFont.
public typealias Font = UIFont
public typealias FontType = UIFont

#elseif os(OSX)

import AppKit

/// Typealias used for colors. It maps to NSColor.
public typealias Color = NSColor
public typealias ColorType = NSColor

/// Typealias used for fonts. It maps to NSFont.
public typealias Font = NSFont
public typealias FontType = NSFont

#endif

/// Extension that adds functionality for calculating WCAG compliant high contrast colors.
extension Color {
extension ColorType {
/**
Calculates the color ratio for a text color on a background color.

Expand All @@ -42,7 +42,7 @@ extension Color {

- Warning: This function will also return `nil` if any input color is not convertable to the sRGB color space.
*/
public class func getContrastRatio(forTextColor textColor: Color, onBackgroundColor backgroundColor: Color) -> CGFloat? {
public class func getContrastRatio(forTextColor textColor: ColorType, onBackgroundColor backgroundColor: ColorType) -> CGFloat? {
guard let rgbaTextColor = textColor.rgbaColor, let rgbaBackgroundColor = backgroundColor.rgbaColor else {
return nil
}
Expand All @@ -62,7 +62,7 @@ extension Color {

- Warning: This function will also return `nil` if any input color is not convertable to the sRGB color space.
*/
public class func getTextColor(onBackgroundColor backgroundColor: Color) -> Color? {
public class func getTextColor(onBackgroundColor backgroundColor: ColorType) -> ColorType? {
guard let rgbaBackgroundColor = backgroundColor.rgbaColor else { return nil }
let textColor = RGBAColor.getTextColor(onBackgroundColor: rgbaBackgroundColor)

Expand All @@ -84,7 +84,7 @@ extension Color {

- Warning: This function will also return `nil` if any input color is not convertable to the sRGB color space.
*/
public class func getTextColor(fromColors colors: [Color], withFont font: Font, onBackgroundColor backgroundColor: Color, conformanceLevel: ConformanceLevel = .AA) -> Color? {
public class func getTextColor(fromColors colors: [ColorType], withFont font: FontType, onBackgroundColor backgroundColor: ColorType, conformanceLevel: ConformanceLevel = .AA) -> ColorType? {
guard let rgbaBackgroundColor = backgroundColor.rgbaColor else { return nil }

for textColor in colors {
Expand Down Expand Up @@ -114,10 +114,10 @@ extension Color {

- Warning: This function will also return `nil` if the image is corrupted.
*/
public class func getTextColor(onBackgroundImage image: Image, imageArea: ImageArea = .full) -> Color? {
public class func getTextColor(onBackgroundImage image: ImageType, imageArea: ImageArea = .full) -> ColorType? {
guard let averageImageColor = image.averageColor(imageArea: imageArea) else { return nil }

return Color.getTextColor(onBackgroundColor: averageImageColor)
return ColorType.getTextColor(onBackgroundColor: averageImageColor)
}

/**
Expand All @@ -136,10 +136,10 @@ extension Color {

- Warning: This function will also return `nil` if any input color is not convertable to the sRGB color space.
*/
public class func getTextColor(fromColors colors: [Color], withFont font: Font, onBackgroundImage image: Image, imageArea: ImageArea = .full, conformanceLevel: ConformanceLevel = .AA) -> Color? {
public class func getTextColor(fromColors colors: [ColorType], withFont font: FontType, onBackgroundImage image: ImageType, imageArea: ImageArea = .full, conformanceLevel: ConformanceLevel = .AA) -> ColorType? {
guard let averageImageColor = image.averageColor(imageArea: imageArea) else { return nil }

return Color.getTextColor(fromColors: colors, withFont: font, onBackgroundColor: averageImageColor, conformanceLevel: conformanceLevel)
return ColorType.getTextColor(fromColors: colors, withFont: font, onBackgroundColor: averageImageColor, conformanceLevel: conformanceLevel)
}

#endif
Expand All @@ -156,7 +156,7 @@ extension Color {

- Warning: This function will also return `nil` if any input color is not convertable to the sRGB color space.
*/
public class func getBackgroundColor(forTextColor textColor: Color) -> Color? {
public class func getBackgroundColor(forTextColor textColor: ColorType) -> ColorType? {
guard let rgbaTextColor = textColor.rgbaColor else { return nil }
let backgroundColor = RGBAColor.getBackgroundColor(forTextColor: rgbaTextColor)

Expand All @@ -178,7 +178,7 @@ extension Color {

- Warning: This function will also return `nil` if any input color is not convertable to the sRGB color space.
*/
public class func getBackgroundColor(fromColors colors: [Color], forTextColor textColor: Color, withFont font: Font, conformanceLevel: ConformanceLevel = .AA) -> Color? {
public class func getBackgroundColor(fromColors colors: [ColorType], forTextColor textColor: ColorType, withFont font: FontType, conformanceLevel: ConformanceLevel = .AA) -> ColorType? {
guard let rgbaTextColor = textColor.rgbaColor else { return nil }

for backgroundColor in colors {
Expand Down
12 changes: 6 additions & 6 deletions Source/Colors/Extensions/Image+averageColor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ import CoreGraphics
import UIKit

/// Typealias used for images. It maps to UIImage.
public typealias Image = UIImage
public typealias ImageType = UIImage

#elseif os(OSX)

import AppKit

/// Typealias used for image. It maps to NSImage.
public typealias Image = NSImage
public typealias ImageType = NSImage

#endif

#if os(iOS) || os(tvOS) || os(OSX)

extension Image {
func averageColor(imageArea: ImageArea = .full) -> Color? {
extension ImageType {
func averageColor(imageArea: ImageArea = .full) -> ColorType? {
let imageAreaRect = imageArea.rect(forImage: self)
var transform = CGAffineTransform(scaleX: 1, y: -1)
transform = transform.translatedBy(x: 0, y: -size.height)
Expand All @@ -43,7 +43,7 @@ import CoreGraphics
}

private extension CIImage {
func averageColor(in rect: CGRect) -> Color? {
func averageColor(in rect: CGRect) -> ColorType? {
let extentVector = CIVector(x: rect.origin.x, y: rect.origin.y, z: rect.size.width, w: rect.size.height)

guard
Expand All @@ -56,7 +56,7 @@ import CoreGraphics
var bitmap = [UInt8](repeating: 0, count: 4)
let context = CIContext(options: [.workingColorSpace: kCFNull as Any])
context.render(imageSection, toBitmap: &bitmap, rowBytes: 4, bounds: CGRect(x: 0, y: 0, width: 1, height: 1), format: .RGBA8, colorSpace: nil)
let averageColor = Color(
let averageColor = ColorType(
red: CGFloat(bitmap[0]) / 255,
green: CGFloat(bitmap[1]) / 255,
blue: CGFloat(bitmap[2]) / 255,
Expand Down
2 changes: 1 addition & 1 deletion Source/Colors/Models/ImageArea.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
/// The second horizontal third.
case verticalCenter

func rect(forImage image: Image) -> CGRect {
func rect(forImage image: ImageType) -> CGRect {
let imageWidth = image.size.width
let imageHeight = image.size.height
let widthThird = imageWidth / 3.0
Expand Down