Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.

Commit af4e0f8

Browse files
Huddiernystrom
authored andcommitted
Choose double tap (#2022)
* Addresses #2013 * fixed issue with creating reaction from string * Switched from MenuController to Separate TableViewController * Minor wording change * Minor wording update * Switched all cells to StyleTextCells * UX fixes. Migrated back into GitHawk Section Removed None and replaced it with a switch * Switched Set Double Tap Reaction -> Double Tap Reaction
1 parent e5cac53 commit af4e0f8

File tree

8 files changed

+399
-16
lines changed

8 files changed

+399
-16
lines changed

Classes/Issues/Comments/IssueCommentBaseCell.swift

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,7 @@ class IssueCommentBaseCell: UICollectionViewCell, UIGestureRecognizerDelegate {
2727

2828
contentView.clipsToBounds = true
2929

30-
doubleTapGesture.addTarget(self, action: #selector(onDoubleTap))
31-
doubleTapGesture.numberOfTapsRequired = 2
32-
doubleTapGesture.delegate = self
33-
addGestureRecognizer(doubleTapGesture)
30+
setUpDoubleTapIfNeeded()
3431

3532
collapseLayer.isHidden = true
3633
collapseLayer.colors = [
@@ -98,6 +95,16 @@ class IssueCommentBaseCell: UICollectionViewCell, UIGestureRecognizerDelegate {
9895

9996
// MARK: Private API
10097

98+
private func setUpDoubleTapIfNeeded()
99+
{
100+
// If reaction is set to none, no need for the double-tap
101+
if ReactionContent.defaultReaction == .__unknown("Disabled") { return }
102+
103+
doubleTapGesture.addTarget(self, action: #selector(onDoubleTap))
104+
doubleTapGesture.numberOfTapsRequired = 2
105+
doubleTapGesture.delegate = self
106+
addGestureRecognizer(doubleTapGesture)
107+
}
101108
@objc private func onDoubleTap() {
102109
doubleTapDelegate?.didDoubleTap(cell: self)
103110
}

Classes/Issues/Comments/IssueCommentSectionController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ final class IssueCommentSectionController:
442442
// MARK: IssueCommentDoubleTapDelegate
443443

444444
func didDoubleTap(cell: IssueCommentBaseCell) {
445-
let reaction = ReactionContent.thumbsUp
445+
let reaction = ReactionContent.defaultReaction
446446
guard let reactions = reactionMutation ?? self.object?.reactions,
447447
!reactions.viewerDidReact(reaction: reaction)
448448
else { return }
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//
2+
// Defaults+Reaction.swift
3+
// Freetime
4+
//
5+
// Created by Ehud Adler on 7/30/18.
6+
// Copyright © 2018 Ryan Nystrom. All rights reserved.
7+
//
8+
extension UserDefaults {
9+
// Stores ReactionContent in string form but
10+
// accepts and returns in original form
11+
static func setDefault(reaction: ReactionContent)
12+
{
13+
standard.set(reaction.emoji, forKey: "default.reaction")
14+
}
15+
16+
static var getDefaultReaction: ReactionContent
17+
{
18+
guard let reactionAsString = standard.string(forKey: "default.reaction")
19+
else { return ReactionContent.thumbsUp }
20+
let reaction = reactionAsString.reaction
21+
return reaction
22+
}
23+
24+
}

Classes/Issues/Comments/Reactions/ReactionContent+ReactionType.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,26 @@ extension ReactionContent {
1515
case .heart: return "❤️"
1616
case .hooray: return "🎉"
1717
case .laugh: return "😄"
18+
case .__unknown("Disabled"): return "Disabled"
1819
case .thumbsUp, .__unknown: return "👍"
1920
case .thumbsDown: return "👎"
2021
}
2122
}
23+
24+
static var defaultReaction: ReactionContent {
25+
return UserDefaults.getDefaultReaction
26+
}
27+
}
28+
extension String {
29+
var reaction: ReactionContent {
30+
switch self {
31+
case "😕": return .confused
32+
case "❤️": return .heart
33+
case "🎉": return .hooray
34+
case "😄": return .laugh
35+
case "👍": return .thumbsUp
36+
case "👎": return .thumbsDown
37+
default: return .__unknown(self)
38+
}
39+
}
2240
}
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
//
2+
// DefaultReactionSubController.swift
3+
// Freetime
4+
//
5+
// Created by Ehud Adler on 8/5/18.
6+
// Copyright © 2018 Ryan Nystrom. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
class DefaultReactionDetailController: UITableViewController {
12+
13+
@IBOutlet var thumbsUpCell: UITableViewCell!
14+
@IBOutlet var thumbsDownCell: UITableViewCell!
15+
@IBOutlet var laughCell: UITableViewCell!
16+
@IBOutlet var hoorayCell: UITableViewCell!
17+
@IBOutlet var confusedCell: UITableViewCell!
18+
@IBOutlet var heartCell: UITableViewCell!
19+
@IBOutlet var enabledSwitch: UISwitch!
20+
21+
override func viewDidLoad() {
22+
super.viewDidLoad()
23+
checkCurrentDefault()
24+
tableView.reloadData()
25+
}
26+
27+
override func numberOfSections(in tableView: UITableView) -> Int {
28+
return enabledSwitch.isOn ? 2 : 1
29+
}
30+
31+
private func checkCurrentDefault() {
32+
switch (ReactionContent.defaultReaction)
33+
{
34+
case ReactionContent.thumbsUp:
35+
updateCells(cell: thumbsUpCell)
36+
case ReactionContent.thumbsDown:
37+
updateCells(cell: thumbsDownCell)
38+
case ReactionContent.laugh:
39+
updateCells(cell: laughCell)
40+
case ReactionContent.hooray:
41+
updateCells(cell: hoorayCell)
42+
case ReactionContent.confused:
43+
updateCells(cell: confusedCell)
44+
case ReactionContent.heart:
45+
updateCells(cell: heartCell)
46+
case ReactionContent.__unknown("Disabled"):
47+
enabledSwitch.isOn = false
48+
default:
49+
updateCells(cell: thumbsUpCell)
50+
}
51+
52+
}
53+
54+
private func updateCells(cell: UITableViewCell) {
55+
56+
rz_smoothlyDeselectRows(tableView: self.tableView)
57+
58+
// Reset all to none
59+
thumbsUpCell.accessoryType = .none
60+
thumbsDownCell.accessoryType = .none
61+
laughCell.accessoryType = .none
62+
hoorayCell.accessoryType = .none
63+
confusedCell.accessoryType = .none
64+
heartCell.accessoryType = .none
65+
66+
// Set proper cell to check
67+
cell.accessoryType = .checkmark
68+
69+
}
70+
71+
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
72+
73+
tableView.deselectRow(at: indexPath, animated: trueUnlessReduceMotionEnabled)
74+
let cell = tableView.cellForRow(at: indexPath)
75+
76+
switch cell {
77+
case thumbsUpCell:
78+
updateDefaultReaction(.thumbsUp)
79+
case thumbsDownCell:
80+
updateDefaultReaction(.thumbsDown)
81+
case laughCell:
82+
updateDefaultReaction(.laugh)
83+
case hoorayCell:
84+
updateDefaultReaction(.hooray)
85+
case confusedCell:
86+
updateDefaultReaction(.confused)
87+
case heartCell:
88+
updateDefaultReaction(.heart)
89+
default:
90+
break
91+
}
92+
}
93+
94+
@IBAction func toggleDefaultReaction(_ sender: Any) {
95+
if(enabledSwitch.isOn) {
96+
updateDefaultReaction(.thumbsUp)
97+
} else {
98+
updateDefaultReaction(.__unknown("Disabled"))
99+
}
100+
updateSections()
101+
}
102+
103+
private func updateDefaultReaction(_ reaction: ReactionContent) {
104+
UserDefaults.setDefault(reaction: reaction)
105+
checkCurrentDefault()
106+
}
107+
108+
private func updateSections() {
109+
tableView.performBatchUpdates({
110+
if(enabledSwitch.isOn) {
111+
self.tableView.insertSections(IndexSet(integer: 1), with: .top)
112+
} else {
113+
self.tableView.deleteSections(IndexSet(integer: 1), with: .top)
114+
}
115+
}, completion: nil)
116+
}
117+
}
118+

0 commit comments

Comments
 (0)