From e99918e6eb78b7dc65c2b3b19b1ad6b5cde9e0b3 Mon Sep 17 00:00:00 2001 From: Tom Clark Date: Mon, 2 Sep 2019 13:23:22 -0700 Subject: [PATCH 1/4] Updated swiftlint rules for airbnb --- .swiftlint.yml | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 .swiftlint.yml diff --git a/.swiftlint.yml b/.swiftlint.yml new file mode 100644 index 0000000..8fec773 --- /dev/null +++ b/.swiftlint.yml @@ -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 From d4105332c22bd72b52cf29226d357fb8ff9d6157 Mon Sep 17 00:00:00 2001 From: TMin Date: Mon, 2 Sep 2019 14:59:43 -0700 Subject: [PATCH 2/4] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 287f1da..79896fa 100644 --- a/README.md +++ b/README.md @@ -27,3 +27,5 @@ 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) + From b2ba450dd1246972560c6b102c781738aff32d96 Mon Sep 17 00:00:00 2001 From: TMin Date: Wed, 4 Sep 2019 18:36:27 -0700 Subject: [PATCH 3/4] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 79896fa..7ed27bc 100644 --- a/README.md +++ b/README.md @@ -28,4 +28,6 @@ To install swiftLint run 'brew install swiftLint' - 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) + From 87c8eaf7c233e3265985a15ec5cac9c36968eeb1 Mon Sep 17 00:00:00 2001 From: Shota Iwamoto Date: Sat, 5 Oct 2019 00:57:02 -0700 Subject: [PATCH 4/4] Add showing alt text in comic view --- sources/ComicModel.swift | 3 ++ sources/ComicViewController.swift | 24 +++++++++++++-- sources/PopupViewViewController.swift | 44 +++++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 sources/PopupViewViewController.swift diff --git a/sources/ComicModel.swift b/sources/ComicModel.swift index f4846d6..11a433c 100644 --- a/sources/ComicModel.swift +++ b/sources/ComicModel.swift @@ -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 { @@ -30,6 +32,7 @@ struct ComicModel: Codable { } self.imageURL = imageURL + alt = try container.decode(String.self, forKey: .alt) } func encode(to encoder: Encoder) throws { diff --git a/sources/ComicViewController.swift b/sources/ComicViewController.swift index 21856c1..b5f7acd 100644 --- a/sources/ComicViewController.swift +++ b/sources/ComicViewController.swift @@ -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? @@ -70,9 +74,9 @@ class ComicViewController: UIViewController { view.addGestureRecognizer(backGestureRecognizer) view.addGestureRecognizer(forwardGestureRecognizer) comicImageView.addGestureRecognizer(tapGestureRecognizer) + comicImageView.addGestureRecognizer(longPressRecognizer) } - // MARK: UTILITIES private func nextComic() { @@ -93,7 +97,6 @@ class ComicViewController: UIViewController { currentComic = previousComic } - private func showDetails() { let comicDetailsViewController = ComicDetailsViewController() comicDetailsViewController.comicId = currentComic?.id @@ -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 @@ -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) { diff --git a/sources/PopupViewViewController.swift b/sources/PopupViewViewController.swift new file mode 100644 index 0000000..5479100 --- /dev/null +++ b/sources/PopupViewViewController.swift @@ -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 + } +}