diff --git a/Signal/src/ViewControllers/GifPicker/GifPickerCell.swift b/Signal/src/ViewControllers/GifPicker/GifPickerCell.swift index 96bda3f3d..8983b1e0f 100644 --- a/Signal/src/ViewControllers/GifPicker/GifPickerCell.swift +++ b/Signal/src/ViewControllers/GifPicker/GifPickerCell.swift @@ -35,6 +35,14 @@ class GifPickerCell: UICollectionViewCell { var animatedAssetRequest: GiphyAssetRequest? var animatedAsset: GiphyAsset? var imageView: YYAnimatedImageView? + var activityIndicator: UIActivityIndicatorView? + + var isCellSelected: Bool = false { + didSet { + AssertIsOnMainThread() + ensureCellState() + } + } // As another bandwidth saving measure, we only fetch the full sized GIF when the user selects it. private var renditionForSending: GiphyRendition? @@ -59,6 +67,8 @@ class GifPickerCell: UICollectionViewCell { animatedAssetRequest = nil imageView?.removeFromSuperview() imageView = nil + activityIndicator = nil + isCellSelected = false } private func clearStillAssetRequest() { @@ -202,6 +212,24 @@ class GifPickerCell: UICollectionViewCell { } imageView.image = image self.backgroundColor = nil + + if self.isCellSelected { + let activityIndicator = UIActivityIndicatorView(activityIndicatorStyle: .gray) + self.activityIndicator = activityIndicator + addSubview(activityIndicator) + activityIndicator.autoCenterInSuperview() + activityIndicator.startAnimating() + + // Render activityIndicator on a white tile to ensure it's visible on + // when overalayed on a variety of potential gifs. + activityIndicator.backgroundColor = UIColor.white.withAlphaComponent(0.3) + activityIndicator.autoSetDimension(.width, toSize: 30) + activityIndicator.autoSetDimension(.height, toSize: 30) + activityIndicator.layer.cornerRadius = 3 + } else { + self.activityIndicator?.stopAnimating() + self.activityIndicator = nil + } } public func requestRenditionForSending() -> Promise { diff --git a/Signal/src/ViewControllers/GifPicker/GifPickerViewController.swift b/Signal/src/ViewControllers/GifPicker/GifPickerViewController.swift index 5b3afce68..c57762629 100644 --- a/Signal/src/ViewControllers/GifPicker/GifPickerViewController.swift +++ b/Signal/src/ViewControllers/GifPicker/GifPickerViewController.swift @@ -293,6 +293,12 @@ class GifPickerViewController: OWSViewController, UISearchBarDelegate, UICollect return } + guard cell.stillAsset != nil || cell.animatedAsset != nil else { + // we don't want to let the user blindly select a gray cell + Logger.debug("\(TAG) ignoring selection of cell with no preview") + return + } + guard self.selectedCell == nil else { owsFail("\(TAG) Already selected cell") return @@ -302,13 +308,9 @@ class GifPickerViewController: OWSViewController, UISearchBarDelegate, UICollect // Fade out all cells except the selected one. let maskingView = OWSBezierPathView() self.view.addSubview(maskingView) - - maskingView.configureShapeLayerBlock = { [weak self] layer, bounds in - guard let strongSelf = self else { - return - } + let cellRect = self.collectionView.convert(cell.frame, to: self.view) + maskingView.configureShapeLayerBlock = { layer, bounds in let path = UIBezierPath(rect: bounds) - let cellRect = strongSelf.collectionView.convert(cell.frame, to: strongSelf.view) path.append(UIBezierPath(rect: cellRect)) layer.path = path.cgPath @@ -318,19 +320,7 @@ class GifPickerViewController: OWSViewController, UISearchBarDelegate, UICollect } maskingView.autoPinEdgesToSuperviewEdges() - let activityIndicator = UIActivityIndicatorView(activityIndicatorStyle: .gray) - cell.contentView.addSubview(activityIndicator) - activityIndicator.autoCenterInSuperview() - - activityIndicator.startAnimating() - - // Render activityIndicator on a white tile to ensure it's visible on - // when overalayed on a variety of potential gifs. - activityIndicator.backgroundColor = UIColor.white.withAlphaComponent(0.3) - activityIndicator.autoSetDimension(.width, toSize: 30) - activityIndicator.autoSetDimension(.height, toSize: 30) - activityIndicator.layer.cornerRadius = 3 - + cell.isCellSelected = true self.collectionView.isUserInteractionEnabled = false getFileForCell(cell)