Skip to content
Open
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
40 changes: 40 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
whitelist_rules:
- closure_spacing
- colon
- empty_enum_arguments
- fatal_error_message
- force_cast
- force_try
- force_unwrapping
- implicitly_unwrapped_optional
- legacy_cggeometry_functions
- legacy_constant
- legacy_constructor
- legacy_nsgeometry_functions
- operator_usage_whitespace
- redundant_string_enum_value
- redundant_void_return
- return_arrow_whitespace
- trailing_newline
- type_name
- unused_closure_parameter
- unused_optional_binding
- vertical_whitespace
- void_return
- custom_rules

excluded:
- Carthage
- Pods

colon:
apply_to_dictionaries: false

indentation: 2

custom_rules:
no_objcMembers:
name: "@objcMembers"
regex: "@objcMembers"
message: "Explicitly use @objc on each member you want to expose to Objective-C"
severity: error
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@ To install swiftLint run 'brew install swiftLint'
- We will be using the AirBnB [Style guide](https://github.com/airbnb/swift)
- Out slack workspace is __CodeCritique.slack.com__
- xkcd [api docs](https://xkcd.com/json.html)
- Wireframes are available [here](https://drive.google.com/open?id=1Y-WynUGdnrcfIhpY74KbroAzQoGMhlJX)
- [slack invite](https://join.slack.com/t/codecritique/shared_invite/enQtNzI5OTE3MTA0MTQ5LTMzOTNjOTBlNGFmOGIyZGYxMTEzNWNjZjRlYzIxNTA2MDc2YmI0OWFhMmUyMGQyYjdjYWNmZGUwOWZkYTQ0YjY)


3 changes: 3 additions & 0 deletions sources/ComicModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ struct ComicModel: Codable {
let id: Int // swiftlint:disable:this identifier_name
let title: String
let imageURL: URL
let alt: String
var image: UIImage?

enum CodingKeys: String, CodingKey {
case id = "num" // swiftlint:disable:this identifier_name
case title
case imageURL = "img"
case alt
}

init(from decoder: Decoder) throws {
Expand All @@ -30,6 +32,7 @@ struct ComicModel: Codable {
}

self.imageURL = imageURL
alt = try container.decode(String.self, forKey: .alt)
}

func encode(to encoder: Encoder) throws {
Expand Down
24 changes: 22 additions & 2 deletions sources/ComicViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ class ComicViewController: UIViewController {
return UITapGestureRecognizer(target: self, action: #selector(handleTapGesture(_:)))
}()

lazy var longPressRecognizer: UILongPressGestureRecognizer = {
return UILongPressGestureRecognizer(target: self, action: #selector(handleLongPressGesture(_:)))
}()

var historyStack = ComicStack()
var futureStack = ComicStack()
var currentComic: ComicModel?
Expand Down Expand Up @@ -70,9 +74,9 @@ class ComicViewController: UIViewController {
view.addGestureRecognizer(backGestureRecognizer)
view.addGestureRecognizer(forwardGestureRecognizer)
comicImageView.addGestureRecognizer(tapGestureRecognizer)
comicImageView.addGestureRecognizer(longPressRecognizer)
}


// MARK: UTILITIES

private func nextComic() {
Expand All @@ -93,7 +97,6 @@ class ComicViewController: UIViewController {
currentComic = previousComic
}


private func showDetails() {
let comicDetailsViewController = ComicDetailsViewController()
comicDetailsViewController.comicId = currentComic?.id
Expand All @@ -106,6 +109,15 @@ class ComicViewController: UIViewController {
return Int.random(in: 0 ... 2198)
}

lazy var popupVC = PopupViewViewController()
private func showAltText() {
popupVC.altTextLabel.text = currentComic?.alt
view.addSubview(popupVC.view)
}

private func closeAltText() {
popupVC.view.removeFromSuperview()
}

// MARK: ACTIONS

Expand All @@ -121,6 +133,14 @@ class ComicViewController: UIViewController {
showDetails()
}

@objc func handleLongPressGesture(_ sender: UILongPressGestureRecognizer) {
if sender.state == .began {
showAltText()
} else if sender.state == .ended {
closeAltText()
}
}

// MARK: Navigation

private func fetchComicData(completion: @escaping (ComicModel) -> Void) {
Expand Down
44 changes: 44 additions & 0 deletions sources/PopupViewViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// PopupViewViewController.swift
// xkcd
//
// Created by Shota Iwamoto on 2019-10-04.
//

import UIKit

class PopupViewViewController: UIViewController {

let baseView = UIView()
let altTextLabel = UILabel()

override func viewDidLoad() {
super.viewDidLoad()
setupSubViews()

self.view.backgroundColor = UIColor(red: 150 / 255, green: 150 / 255, blue: 150 / 255, alpha: 0.6)
}

private func setupSubViews() {
let screenWidth = self.view.frame.width
let screenHeight = self.view.frame.height

let popupWidth = (screenWidth * 3) / 4
let popupHeight = (screenWidth * 4) / 4

baseView.frame = CGRect(x: screenWidth / 8, y: screenHeight / 5, width: popupWidth, height: popupHeight)

baseView.backgroundColor = UIColor.white
baseView.layer.cornerRadius = 10

self.view.addSubview(baseView)
baseView.addSubview(altTextLabel)
altTextLabel.numberOfLines = 0
altTextLabel.lineBreakMode = .byWordWrapping
altTextLabel.sizeToFit()
altTextLabel.translatesAutoresizingMaskIntoConstraints = false
altTextLabel.topAnchor.constraint(equalTo: baseView.topAnchor, constant: 20).isActive = true
altTextLabel.leadingAnchor.constraint(equalTo: baseView.leadingAnchor, constant: 20).isActive = true
altTextLabel.trailingAnchor.constraint(equalTo: baseView.trailingAnchor, constant: -20).isActive = true
}
}