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

Commit 8a8da14

Browse files
authored
new send button position (#2066)
1 parent 38023e8 commit 8a8da14

File tree

7 files changed

+120
-57
lines changed

7 files changed

+120
-57
lines changed

Classes/Issues/EditComment/EditCommentViewController.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ MessageTextViewListener {
120120
repo: issueModel.repo,
121121
owner: issueModel.repo,
122122
addBorder: true,
123-
supportsImageUpload: true
123+
supportsImageUpload: true,
124+
showSendButton: false
124125
)
125126

126127
textActionsController.configure(client: client, textView: textView, actions: actions)

Classes/Issues/IssueTextActionsView.swift

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ protocol IssueTextActionsViewDelegate: class {
5252
func didSelect(actionsView: IssueTextActionsView, operation: IssueTextActionOperation)
5353
}
5454

55+
protocol IssueTextActionsViewSendDelegate: class {
56+
func didSend(for actionsView: IssueTextActionsView)
57+
}
58+
5559
struct IssueTextActionOperation {
5660

5761
enum Operation {
@@ -71,6 +75,7 @@ struct IssueTextActionOperation {
7175
final class IssueTextActionsView: UIView, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
7276

7377
weak var delegate: IssueTextActionsViewDelegate?
78+
weak var sendDelegate: IssueTextActionsViewSendDelegate?
7479

7580
private let operations: [IssueTextActionOperation]
7681
private let identifier = "cell"
@@ -86,18 +91,43 @@ final class IssueTextActionsView: UIView, UICollectionViewDataSource, UICollecti
8691
c.showsHorizontalScrollIndicator = false
8792
return c
8893
}()
94+
private let gradientWidth = Styles.Sizes.gutter
95+
private let sendButtonGradientLayer = CAGradientLayer()
96+
private let sendButton = UIButton()
97+
98+
public var sendButtonEnabled: Bool {
99+
get { return sendButton.isEnabled }
100+
set { sendButton.isEnabled = newValue }
101+
}
89102

90-
init(operations: [IssueTextActionOperation]) {
103+
init(operations: [IssueTextActionOperation], showSendButton: Bool) {
91104
self.operations = operations
92105

93106
super.init(frame: .zero)
94107

95108
translatesAutoresizingMaskIntoConstraints = false
96109

110+
collectionView.clipsToBounds = true
97111
collectionView.register(IssueTextActionsCell.self, forCellWithReuseIdentifier: identifier)
98112
collectionView.dataSource = self
99113
collectionView.delegate = self
100114
addSubview(collectionView)
115+
116+
if showSendButton {
117+
collectionView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: gradientWidth)
118+
119+
sendButtonGradientLayer.startPoint = CGPoint(x: 0, y: 0.5)
120+
sendButtonGradientLayer.endPoint = CGPoint(x: 1, y: 0.5)
121+
sendButtonGradientLayer.colors = [UIColor(white: 1, alpha: 0).cgColor, UIColor.white.cgColor]
122+
layer.addSublayer(sendButtonGradientLayer)
123+
124+
let blue = Styles.Colors.Blue.medium.color
125+
sendButton.tintColor = blue
126+
sendButton.imageView?.tintColor = blue
127+
sendButton.setImage(UIImage(named: "send")?.withRenderingMode(.alwaysTemplate), for: .normal)
128+
sendButton.addTarget(self, action: #selector(onSend), for: .touchUpInside)
129+
addSubview(sendButton)
130+
}
101131
}
102132

103133
required init?(coder aDecoder: NSCoder) {
@@ -106,7 +136,31 @@ final class IssueTextActionsView: UIView, UICollectionViewDataSource, UICollecti
106136

107137
override func layoutSubviews() {
108138
super.layoutSubviews()
109-
collectionView.frame = bounds
139+
if sendButton.superview != nil {
140+
let height = bounds.height
141+
let imageWidth = sendButton.image(for: .normal)?.size.width ?? 0
142+
let buttonWidth = imageWidth + 2*Styles.Sizes.gutter
143+
sendButton.frame = CGRect(
144+
x: bounds.width - buttonWidth,
145+
y: 0,
146+
width: buttonWidth,
147+
height: height
148+
)
149+
sendButtonGradientLayer.frame = CGRect(
150+
x: sendButton.frame.minX - gradientWidth,
151+
y: 0,
152+
width: gradientWidth,
153+
height: height
154+
)
155+
// put collection view beneath the gradient layer
156+
collectionView.frame = CGRect(x: 0, y: 0, width: sendButton.frame.minX, height: height)
157+
} else {
158+
collectionView.frame = bounds
159+
}
160+
}
161+
162+
@objc private func onSend() {
163+
sendDelegate?.didSend(for: self)
110164
}
111165

112166
// MARK: UICollectionViewDataSource

Classes/Issues/IssuesViewController.swift

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ final class IssuesViewController:
3131
FeedSelectionProviding,
3232
IssueNeckLoadSectionControllerDelegate,
3333
FlatCacheListener,
34-
IssueCommentSectionControllerDelegate {
34+
IssueCommentSectionControllerDelegate,
35+
IssueTextActionsViewSendDelegate {
3536

3637
private let client: GithubClient
3738
private let model: IssueDetailsModel
@@ -165,7 +166,7 @@ final class IssuesViewController:
165166
view.backgroundColor = Styles.Colors.background
166167

167168
// setup message view properties
168-
configure(target: self, action: #selector(didPressButton(_:)))
169+
configure()
169170

170171
let getMarkdownBlock = { [weak self] () -> (String) in
171172
return self?.messageView.text ?? ""
@@ -176,10 +177,12 @@ final class IssuesViewController:
176177
repo: model.repo,
177178
owner: model.owner,
178179
addBorder: false,
179-
supportsImageUpload: true
180+
supportsImageUpload: true,
181+
showSendButton: true
180182
)
181183
// text input bar uses UIVisualEffectView, don't try to match it
182184
actions.backgroundColor = .clear
185+
actions.sendDelegate = self
183186

184187
textActionsController.configure(client: client, textView: messageView.textView, actions: actions)
185188
textActionsController.viewController = self
@@ -190,7 +193,8 @@ final class IssuesViewController:
190193
//show disabled bookmark button until issue has finished loading
191194
navigationItem.rightBarButtonItems = [ moreOptionsItem, BookmarkNavigationController.disabledNavigationItem ]
192195

193-
view.addSubview(manageController.manageButton)
196+
// insert below so button doesn't appear above autocomplete
197+
view.insertSubview(manageController.manageButton, belowSubview: messageView)
194198
}
195199

196200
override func viewDidAppear(_ animated: Bool) {
@@ -230,19 +234,6 @@ final class IssuesViewController:
230234

231235
// MARK: Private API
232236

233-
@objc func didPressButton(_ sender: Any?) {
234-
// get text before calling super b/c it will clear it
235-
let text = messageView.text
236-
messageView.text = ""
237-
238-
if let id = resultID {
239-
addCommentClient.addComment(
240-
subjectId: id,
241-
body: text
242-
)
243-
}
244-
}
245-
246237
var externalURL: URL {
247238
return URL(string: "https://github.com/\(model.owner)/\(model.repo)/issues/\(model.number)")!
248239
}
@@ -594,4 +585,19 @@ final class IssuesViewController:
594585
return substring + " ..."
595586
}
596587

588+
// MARK: IssueTextActionsViewSendDelegate
589+
590+
func didSend(for actionsView: IssueTextActionsView) {
591+
// get text before calling super b/c it will clear it
592+
let text = messageView.text
593+
messageView.text = ""
594+
595+
if let id = resultID {
596+
addCommentClient.addComment(
597+
subjectId: id,
598+
body: text
599+
)
600+
}
601+
}
602+
597603
}

Classes/New Issue/NewIssueTableViewController.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,8 @@ final class NewIssueTableViewController: UITableViewController, UITextFieldDeleg
195195
repo: repo,
196196
owner: owner,
197197
addBorder: true,
198-
supportsImageUpload: true
198+
supportsImageUpload: true,
199+
showSendButton: false
199200
)
200201

201202
textActionsController.configure(client: client, textView: bodyField, actions: actions)

Classes/PullRequestReviews/PullRequestReviewCommentsViewController.swift

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ import Squawk
1515
final class PullRequestReviewCommentsViewController: MessageViewController,
1616
ListAdapterDataSource,
1717
FeedDelegate,
18-
PullRequestReviewReplySectionControllerDelegate {
18+
PullRequestReviewReplySectionControllerDelegate,
19+
IssueTextActionsViewSendDelegate {
1920

2021
private let model: IssueDetailsModel
2122
private let client: GithubClient
@@ -66,7 +67,7 @@ final class PullRequestReviewCommentsViewController: MessageViewController,
6667
view.backgroundColor = Styles.Colors.background
6768

6869
// setup message view properties
69-
configure(target: self, action: #selector(didPressButton(_:)))
70+
configure()
7071

7172
let getMarkdownBlock = { [weak self] () -> (String) in
7273
return self?.messageView.text ?? ""
@@ -77,10 +78,12 @@ final class PullRequestReviewCommentsViewController: MessageViewController,
7778
repo: model.repo,
7879
owner: model.owner,
7980
addBorder: false,
80-
supportsImageUpload: true
81+
supportsImageUpload: true,
82+
showSendButton: true
8183
)
8284
// text input bar uses UIVisualEffectView, don't try to match it
8385
actions.backgroundColor = .clear
86+
actions.sendDelegate = self
8487

8588
textActionsController.configure(client: client, textView: messageView.textView, actions: actions)
8689
textActionsController.viewController = self
@@ -132,30 +135,6 @@ final class PullRequestReviewCommentsViewController: MessageViewController,
132135
}
133136
}
134137

135-
@objc func didPressButton(_ sender: Any) {
136-
guard let reply = focusedReplyModel else { return }
137-
138-
let text = messageView.text
139-
messageView.text = ""
140-
messageView.textView.resignFirstResponder()
141-
setMessageView(hidden: true, animated: true)
142-
143-
client.sendComment(
144-
body: text,
145-
inReplyTo: reply.replyID,
146-
owner: model.owner,
147-
repo: model.repo,
148-
number: model.number,
149-
width: insetWidth
150-
) { [weak self] result in
151-
switch result {
152-
case .error: break
153-
case .success(let comment): self?.insertComment(model: comment, reply: reply)
154-
}
155-
}
156-
157-
}
158-
159138
func insertComment(model: IssueCommentModel, reply: PullRequestReviewReplyModel) {
160139
let section = feed.adapter.section(for: reply)
161140
guard section < NSNotFound && section < results.count else { return }
@@ -208,4 +187,29 @@ final class PullRequestReviewCommentsViewController: MessageViewController,
208187
focusedReplyModel = reply
209188
}
210189

190+
// MARK: IssueTextActionsViewSendDelegate
191+
192+
func didSend(for actionsView: IssueTextActionsView) {
193+
guard let reply = focusedReplyModel else { return }
194+
195+
let text = messageView.text
196+
messageView.text = ""
197+
messageView.textView.resignFirstResponder()
198+
setMessageView(hidden: true, animated: true)
199+
200+
client.sendComment(
201+
body: text,
202+
inReplyTo: reply.replyID,
203+
owner: model.owner,
204+
repo: model.repo,
205+
number: model.number,
206+
width: insetWidth
207+
) { [weak self] result in
208+
switch result {
209+
case .error: break
210+
case .success(let comment): self?.insertComment(model: comment, reply: reply)
211+
}
212+
}
213+
}
214+
211215
}

Classes/Views/IssueTextActionsView+Markdown.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ extension IssueTextActionsView {
1616
repo: String,
1717
owner: String,
1818
addBorder: Bool,
19-
supportsImageUpload: Bool
19+
supportsImageUpload: Bool,
20+
showSendButton: Bool
2021
) -> IssueTextActionsView {
2122
var operations: [IssueTextActionOperation] = [
2223
IssueTextActionOperation(
@@ -82,7 +83,7 @@ extension IssueTextActionsView {
8283
name: NSLocalizedString("Upload Image", comment: "The name of the action to upload an image from the markdown actions bar")))
8384
}
8485

85-
let actions = IssueTextActionsView(operations: operations)
86+
let actions = IssueTextActionsView(operations: operations, showSendButton: showSendButton)
8687
actions.backgroundColor = Styles.Colors.Gray.lighter.color
8788
if addBorder {
8889
actions.addBorder(.top)

Classes/Views/MessageView+Styles.swift

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,19 @@ import MessageViewController
1111

1212
extension MessageViewController {
1313

14-
func configure(target: Any, action: Selector) {
15-
// setup message view properties
14+
func configure() {
1615
borderColor = Styles.Colors.Gray.border.color
1716
messageView.textView.placeholderText = NSLocalizedString("Leave a comment", comment: "")
1817
messageView.textView.placeholderTextColor = Styles.Colors.Gray.light.color
19-
messageView.setButton(icon: UIImage(named: "send")?.withRenderingMode(.alwaysTemplate), for: .normal, position: .right)
20-
messageView.rightButtonTint = Styles.Colors.Blue.medium.color
2118
messageView.font = Styles.Text.body.preferredFont
2219
messageView.textViewInset = UIEdgeInsets(
2320
top: Styles.Sizes.rowSpacing*1.5,
2421
left: Styles.Sizes.gutter,
2522
bottom: Styles.Sizes.rowSpacing,
26-
right: Styles.Sizes.rowSpacing
23+
right: Styles.Sizes.gutter
2724
)
28-
messageView.setButton(inset: Styles.Sizes.gutter, position: .right)
2925
messageView.bottomInset = Styles.Sizes.rowSpacing / 2
30-
messageView.addButton(target: target, action: action, position: .right)
26+
messageView.maxLineCount = 10
3127
}
3228

3329
}

0 commit comments

Comments
 (0)