Skip to content

Commit

Permalink
Merge pull request #51 from chrs1885/feature/fix-swiftui-naming-colli…
Browse files Browse the repository at this point in the history
…sion

Fix naming collisions with SwiftUI
  • Loading branch information
chrs1885 committed Feb 11, 2020
2 parents e91a0c4 + c9b292f commit ae1f210
Show file tree
Hide file tree
Showing 14 changed files with 107 additions and 107 deletions.
18 changes: 9 additions & 9 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
PODS:
- Capable (1.1.1):
- Capable/Colors (= 1.1.1)
- Capable/Features (= 1.1.1)
- Capable/Fonts (= 1.1.1)
- Capable/Colors (1.1.1)
- Capable/Features (1.1.1)
- Capable/Fonts (1.1.1)
- Capable (1.1.2):
- Capable/Colors (= 1.1.2)
- Capable/Features (= 1.1.2)
- Capable/Fonts (= 1.1.2)
- Capable/Colors (1.1.2)
- Capable/Features (1.1.2)
- Capable/Fonts (1.1.2)
- Nimble (8.0.4)
- Quick (2.2.0)
- SheetyColors (1.0.1):
Expand All @@ -18,7 +18,7 @@ DEPENDENCIES:
- SheetyColors (= 1.0.1)

SPEC REPOS:
https://github.com/CocoaPods/Specs.git:
trunk:
- Nimble
- Quick
- SheetyColors
Expand All @@ -28,7 +28,7 @@ EXTERNAL SOURCES:
:path: "../"

SPEC CHECKSUMS:
Capable: c9a4ee37bb727af2255879f32e56b5cfa04857a5
Capable: 68f8213fb81f2e4667bcc06449adc6ade1926017
Nimble: 18d5360282923225d62b09d781f63abc1a0111fc
Quick: 7fb19e13be07b5dfb3b90d4f9824c855a11af40e
SheetyColors: ae8c3a5d04d310e8e2d08e4aa0bd543519d02252
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions Example/Source/Color+capable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@
#if os(iOS)

import UIKit
typealias Color = UIColor
typealias TypeColor = UIColor

#elseif os(OSX)

import AppKit
typealias Color = NSColor
typealias TypeColor = NSColor

#endif

extension Color {
static var capableGreen: Color {
return Color(red: 137 / 255.0, green: 176 / 255.0, blue: 106 / 255.0, alpha: 1.0)
extension TypeColor {
static var capableGreen: TypeColor {
return TypeColor(red: 137 / 255.0, green: 176 / 255.0, blue: 106 / 255.0, alpha: 1.0)
}

static var capableRed: Color {
return Color(red: 1.0, green: 120 / 255.0, blue: 120 / 255.0, alpha: 1.0)
static var capableRed: TypeColor {
return TypeColor(red: 1.0, green: 120 / 255.0, blue: 120 / 255.0, alpha: 1.0)
}
}
10 changes: 5 additions & 5 deletions Example/Source/ConformanceLevelView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
#if os(iOS)

import UIKit
typealias Font = UIFont
typealias TypeFont = UIFont
typealias Label = UILabel
typealias View = UIView

#elseif os(OSX)

import AppKit
typealias Font = NSFont
typealias TypeFont = NSFont
typealias Label = NSTextField
typealias View = NSView

Expand All @@ -38,8 +38,8 @@ class ConformanceLevelView: View {

var isPassing: Bool = false {
didSet {
self.backgroundColor = isPassing ? Color.capableGreen : Color.capableRed
self.textLabel.textColor = Color.getTextColor(onBackgroundColor: self.backgroundColor!)!
self.backgroundColor = isPassing ? TypeColor.capableGreen : TypeColor.capableRed
self.textLabel.textColor = TypeColor.getTextColor(onBackgroundColor: self.backgroundColor!)!
}
}

Expand All @@ -50,7 +50,7 @@ class ConformanceLevelView: View {

func setupView() {
addSubview(textLabel)
textLabel.font = Font.systemFont(ofSize: 13.0)
textLabel.font = TypeFont.systemFont(ofSize: 13.0)

textLabel.translatesAutoresizingMaskIntoConstraints = false
let views: [String: Any] = ["textLabel": self.textLabel]
Expand Down
108 changes: 54 additions & 54 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 = TypeImage.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: TypeImage!

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 = TypeImage.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(TypeColor.red.rgbaColor))
}
}
}
Expand Down
6 changes: 3 additions & 3 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 TypeImage {
class func mock(withColor color: TypeColor, rect: CGRect = CGRect(x: 0, y: 0, width: 1, height: 1)) -> TypeImage {
#if os(iOS) || os(tvOS)

UIGraphicsBeginImageContext(rect.size)
Expand All @@ -37,7 +37,7 @@ extension Image {
fatalError("Error creating the mock image.")
}

return Image(cgImage: cgImage, size: rect.size)
return TypeImage(cgImage: cgImage, size: rect.size)

#endif
}
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 TypeColor = UIColor

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

#elseif os(OSX)

import AppKit

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

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

#endif

/// Extension that adds functionality for calculating WCAG compliant high contrast colors.
extension Color {
extension TypeColor {
/**
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: TypeColor, onBackgroundColor backgroundColor: TypeColor) -> 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: TypeColor) -> TypeColor? {
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: [TypeColor], withFont font: TypeFont, onBackgroundColor backgroundColor: TypeColor, conformanceLevel: ConformanceLevel = .AA) -> TypeColor? {
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: TypeImage, imageArea: ImageArea = .full) -> TypeColor? {
guard let averageImageColor = image.averageColor(imageArea: imageArea) else { return nil }

return Color.getTextColor(onBackgroundColor: averageImageColor)
return TypeColor.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: [TypeColor], withFont font: TypeFont, onBackgroundImage image: TypeImage, imageArea: ImageArea = .full, conformanceLevel: ConformanceLevel = .AA) -> TypeColor? {
guard let averageImageColor = image.averageColor(imageArea: imageArea) else { return nil }

return Color.getTextColor(fromColors: colors, withFont: font, onBackgroundColor: averageImageColor, conformanceLevel: conformanceLevel)
return TypeColor.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: TypeColor) -> TypeColor? {
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: [TypeColor], forTextColor textColor: TypeColor, withFont font: TypeFont, conformanceLevel: ConformanceLevel = .AA) -> TypeColor? {
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 TypeImage = UIImage

#elseif os(OSX)

import AppKit

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

#endif

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

extension Image {
func averageColor(imageArea: ImageArea = .full) -> Color? {
extension TypeImage {
func averageColor(imageArea: ImageArea = .full) -> TypeColor? {
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) -> TypeColor? {
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 = TypeColor(
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: TypeImage) -> CGRect {
let imageWidth = image.size.width
let imageHeight = image.size.height
let widthThird = imageWidth / 3.0
Expand Down

0 comments on commit ae1f210

Please sign in to comment.