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

Adds loading on send #2157

Merged
merged 1 commit into from
Sep 22, 2018
Merged
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
23 changes: 22 additions & 1 deletion Classes/Issues/IssueTextActionsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,30 @@ final class IssueTextActionsView: UIView, UICollectionViewDataSource, UICollecti
private let gradientWidth = Styles.Sizes.gutter
private let sendButtonGradientLayer = CAGradientLayer()
private let sendButton = UIButton()

private let activityIndicator = UIActivityIndicatorView(
activityIndicatorStyle: UIActivityIndicatorViewStyle.gray
)

public var sendButtonEnabled: Bool {
get { return sendButton.isEnabled }
set {
sendButton.isEnabled = newValue
sendButton.alpha = newValue ? 1 : 0.25
}
}

public var isProcessing: Bool = false {
didSet {
sendButton.isEnabled = !isProcessing
if isProcessing {
activityIndicator.startAnimating()
sendButton.isHidden = true
} else {
activityIndicator.stopAnimating()
sendButton.isHidden = false
}
}
}

init(operations: [IssueTextActionOperation], showSendButton: Bool) {
self.operations = operations
Expand Down Expand Up @@ -130,6 +146,9 @@ final class IssueTextActionsView: UIView, UICollectionViewDataSource, UICollecti
sendButton.setImage(UIImage(named: "send")?.withRenderingMode(.alwaysTemplate), for: .normal)
sendButton.addTarget(self, action: #selector(onSend), for: .touchUpInside)
addSubview(sendButton)

activityIndicator.hidesWhenStopped = true
addSubview(activityIndicator)
}
}

Expand All @@ -155,6 +174,7 @@ final class IssueTextActionsView: UIView, UICollectionViewDataSource, UICollecti
width: gradientWidth,
height: height
)
activityIndicator.center = sendButton.center
// put collection view beneath the gradient layer
collectionView.frame = CGRect(x: 0, y: 0, width: sendButton.frame.minX, height: height)
} else {
Expand All @@ -163,6 +183,7 @@ final class IssueTextActionsView: UIView, UICollectionViewDataSource, UICollecti
}

@objc private func onSend() {
isProcessing = true
sendDelegate?.didSend(for: self)
}

Expand Down
2 changes: 2 additions & 0 deletions Classes/Issues/IssuesViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,7 @@ final class IssuesViewController:
viewerCanUpdate: Bool,
viewerCanDelete: Bool
) {
self.actions?.isProcessing = false
guard let previous = result,
let comment = createCommentModel(
id: id,
Expand All @@ -546,6 +547,7 @@ final class IssuesViewController:
}

func didFailSendingComment(client: AddCommentClient, subjectId: String, body: String) {
self.actions?.isProcessing = false
messageView.text = body
}

Expand Down