diff --git a/Classes/Issues/IssueTextActionsView.swift b/Classes/Issues/IssueTextActionsView.swift index 888b5d92a..6e42f61a0 100644 --- a/Classes/Issues/IssueTextActionsView.swift +++ b/Classes/Issues/IssueTextActionsView.swift @@ -94,7 +94,10 @@ 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 { @@ -102,6 +105,19 @@ final class IssueTextActionsView: UIView, UICollectionViewDataSource, UICollecti 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 @@ -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) } } @@ -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 { @@ -163,6 +183,7 @@ final class IssueTextActionsView: UIView, UICollectionViewDataSource, UICollecti } @objc private func onSend() { + isProcessing = true sendDelegate?.didSend(for: self) } diff --git a/Classes/Issues/IssuesViewController.swift b/Classes/Issues/IssuesViewController.swift index f5a0c1029..9135ce615 100644 --- a/Classes/Issues/IssuesViewController.swift +++ b/Classes/Issues/IssuesViewController.swift @@ -521,6 +521,7 @@ final class IssuesViewController: viewerCanUpdate: Bool, viewerCanDelete: Bool ) { + self.actions?.isProcessing = false guard let previous = result, let comment = createCommentModel( id: id, @@ -546,6 +547,7 @@ final class IssuesViewController: } func didFailSendingComment(client: AddCommentClient, subjectId: String, body: String) { + self.actions?.isProcessing = false messageView.text = body }