Skip to content

Commit

Permalink
QT-11 Reduce codebeat warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
quver committed Mar 4, 2017
1 parent f8e434f commit 41498af
Show file tree
Hide file tree
Showing 32 changed files with 130 additions and 114 deletions.
4 changes: 4 additions & 0 deletions SlidableImage.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
D55BB1951CB97A10000B2875 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D55BB1931CB97A10000B2875 /* LaunchScreen.storyboard */; };
D55BB1A01CB97A10000B2875 /* SlidableImageSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = D55BB19F1CB97A10000B2875 /* SlidableImageSpec.swift */; };
D565D0A51DCD6B2D0028788A /* SlidableImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = D565D0A41DCD6B2D0028788A /* SlidableImage.swift */; };
D5865DFA1E6B7D8A006E578E /* SlidableImageFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5865DF91E6B7D8A006E578E /* SlidableImageFactory.swift */; };
D5C0D7011E2AA33600E957F8 /* RecordableSnapshots.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5C0D7001E2AA33600E957F8 /* RecordableSnapshots.swift */; };
D5C0D7031E2AB93A00E957F8 /* ArrowsViewSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5C0D7021E2AB93A00E957F8 /* ArrowsViewSpec.swift */; };
D5C164DA1E07260700606F9F /* ArrowsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5C164D91E07260700606F9F /* ArrowsView.swift */; };
Expand Down Expand Up @@ -49,6 +50,7 @@
D55BB19F1CB97A10000B2875 /* SlidableImageSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SlidableImageSpec.swift; sourceTree = "<group>"; };
D55BB1A11CB97A10000B2875 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
D565D0A41DCD6B2D0028788A /* SlidableImage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SlidableImage.swift; path = Sources/SlidableImage.swift; sourceTree = SOURCE_ROOT; };
D5865DF91E6B7D8A006E578E /* SlidableImageFactory.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SlidableImageFactory.swift; sourceTree = "<group>"; };
D5C0D7001E2AA33600E957F8 /* RecordableSnapshots.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecordableSnapshots.swift; sourceTree = "<group>"; };
D5C0D7021E2AB93A00E957F8 /* ArrowsViewSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ArrowsViewSpec.swift; sourceTree = "<group>"; };
D5C164D91E07260700606F9F /* ArrowsView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ArrowsView.swift; path = Sources/ArrowsView.swift; sourceTree = SOURCE_ROOT; };
Expand Down Expand Up @@ -120,6 +122,7 @@
D55BB18A1CB97A10000B2875 /* AppDelegate.swift */,
D55BB18C1CB97A10000B2875 /* ViewController.swift */,
D565D0A41DCD6B2D0028788A /* SlidableImage.swift */,
D5865DF91E6B7D8A006E578E /* SlidableImageFactory.swift */,
D5C164D91E07260700606F9F /* ArrowsView.swift */,
D55BB18E1CB97A10000B2875 /* Main.storyboard */,
D55BB1911CB97A10000B2875 /* Assets.xcassets */,
Expand Down Expand Up @@ -345,6 +348,7 @@
files = (
D5C164DA1E07260700606F9F /* ArrowsView.swift in Sources */,
D55BB18D1CB97A10000B2875 /* ViewController.swift in Sources */,
D5865DFA1E6B7D8A006E578E /* SlidableImageFactory.swift in Sources */,
D565D0A51DCD6B2D0028788A /* SlidableImage.swift in Sources */,
D55BB18B1CB97A10000B2875 /* AppDelegate.swift in Sources */,
);
Expand Down
67 changes: 67 additions & 0 deletions SlidableImage/SlidableImageFactory.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//
// SlidableImageFactory.swift
// SlidableImage
//
// Created by Pawel Bednorz on 04.03.2017.
// Copyright © 2017 Quver. All rights reserved.
//

import UIKit

extension SlidableImage {

struct Factory {

static func makeSliderCircle(sliderImage: UIImage? = nil) -> UIView {
let frame = CGRect(x: 0, y: 0, width: 50, height: 50)
let circle = UIView(frame: frame)

guard let sliderImage = sliderImage else {
return ArrowsView(frame: frame)
}

circle.layer.cornerRadius = circle.bounds.width / 2

let imageView = UIImageView(image: sliderImage)
imageView.contentMode = .scaleAspectFill
circle.addSubview(imageView)
imageView.center = circle.center

return circle
}

static func makeContainer(image: UIImage, frame: CGRect) -> UIImageView {
let imageView = UIImageView(frame: frame)
imageView.image = image
imageView.contentMode = .scaleAspectFill

return imageView
}

static func makeMaskRect(for maskLocation: CGFloat, bounds: CGRect, slideDirection: Direction) -> CGRect {
switch slideDirection {
case .left:
return CGRect(x: maskLocation,
y: bounds.minY,
width: bounds.width,
height: bounds.height)
case .right:
return CGRect(x: bounds.minX,
y: bounds.minY,
width: maskLocation,
height: bounds.height)
case .top:
return CGRect(x: bounds.minX,
y: maskLocation,
width: bounds.width,
height: bounds.height)
case .bottom:
return CGRect(x: bounds.minX,
y: bounds.minY,
width: bounds.width,
height: maskLocation)
}
}
}

}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 8 additions & 4 deletions SlidableImageTests/SlidableImageSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,27 @@ class SlidableImageSpec: QuickSpec {
}

context("with custom slide direction") {
beforeEach {
slider = SlidableImage(frame: rect, images: (firstImage, secondImage))
}

it("is initialized with right") {
slider = SlidableImage(frame: rect, images: (firstImage, secondImage), slideDirection: .right)
slider.slideDirection = .right
expect(slider).to(self.recordValidSnapshot())
}

it("is initialized with left") {
slider = SlidableImage(frame: rect, images: (firstImage, secondImage), slideDirection: .left)
slider.slideDirection = .left
expect(slider).to(self.recordValidSnapshot())
}

it("is initialized with top") {
slider = SlidableImage(frame: rect, images: (firstImage, secondImage), slideDirection: .top)
slider.slideDirection = .top
expect(slider).to(self.recordValidSnapshot())
}

it("is initialized with bottom") {
slider = SlidableImage(frame: rect, images: (firstImage, secondImage), slideDirection: .bottom)
slider.slideDirection = .bottom
expect(slider).to(self.recordValidSnapshot())
}
}
Expand Down
56 changes: 31 additions & 25 deletions Sources/ArrowsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,8 @@ import UIKit
class ArrowsView: UIView {

private typealias FactorTuple = (single: CGFloat, double: CGFloat)

private enum Side {

case left
case right

}
private typealias Side = SlidableImage.Direction
private typealias SidesTuple = (vertical: Side, horizontal: Side)

private let factorValue: CGFloat = 0.05

Expand Down Expand Up @@ -49,14 +44,14 @@ class ArrowsView: UIView {
layer.addSublayer(circleLayer)
}

private func drawArrow(_ rect: CGRect, side: Side) {
private func drawArrow(_ rect: CGRect, side: SlidableImage.Direction) {
let factor = makeFactor(rect)
let startPoint = makeStartPoint(rect, side: side, factor: factor)

let arrow = UIBezierPath()
arrow.move(to: startPoint)
arrow.addLine(to: makeBottomPoint(rect, side: side, factor: factor))
arrow.addLine(to: makeTopPoint(rect, side: side, factor: factor))
arrow.addLine(to: makePoint(rect, side: (.bottom, side), factor: factor))
arrow.addLine(to: makePoint(rect, side: (.top, side), factor: factor))
arrow.addLine(to: startPoint)

let arrowLeftLayer = CAShapeLayer()
Expand All @@ -71,35 +66,46 @@ class ArrowsView: UIView {
return (factor, 2 * factor)
}

private func makeStartPoint(_ rect: CGRect, side: Side, factor: FactorTuple) -> CGPoint {
private func makeStartPoint(_ rect: CGRect, side: SlidableImage.Direction, factor: FactorTuple) -> CGPoint {
let startPointX: CGFloat = {
switch side {
case .left:
return rect.minX + factor.double
case .right:
return rect.maxX - factor.double
default:
return 0
}
}()

return CGPoint(x: startPointX, y: rect.midY)
}

private func makeBottomPoint(_ rect: CGRect, side: Side, factor: FactorTuple) -> CGPoint {
switch side {
case .left:
return CGPoint(x: (rect.midX - factor.single), y: (rect.minY + factor.double))
case .right:
return CGPoint(x: (rect.midX + factor.single), y: (rect.minY + factor.double))
}
private func makePoint(_ rect: CGRect, side: SidesTuple, factor: FactorTuple) -> CGPoint {
return CGPoint(x: makeX(rect, side: side.horizontal, factor: factor),
y: makeY(rect, side: side.vertical, factor: factor))
}

private func makeTopPoint(_ rect: CGRect, side: Side, factor: FactorTuple) -> CGPoint {
switch side {
case .left:
return CGPoint(x: (rect.midX - factor.single), y: (rect.maxY - factor.double))
case .right:
return CGPoint(x: (rect.midX + factor.single), y: (rect.maxY - factor.double))
}
private func makeX(_ rect: CGRect, side: SlidableImage.Direction, factor: FactorTuple) -> CGFloat {
switch side {
case .left:
return rect.midX - factor.single
case .right:
return rect.midX + factor.single
default:
return 0
}
}

private func makeY(_ rect: CGRect, side: SlidableImage.Direction, factor: FactorTuple) -> CGFloat {
switch side {
case .top:
return rect.minY + factor.double
case .bottom:
return rect.maxY - factor.double
default:
return 0
}
}

}
Loading

0 comments on commit 41498af

Please sign in to comment.