2019-12-19 17:32:49 +00:00
|
|
|
/*
|
2023-04-06 09:44:16 +00:00
|
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
2019-12-19 17:32:49 +00:00
|
|
|
*
|
|
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2016-10-21 07:09:11 +00:00
|
|
|
*/
|
2016-10-20 06:26:07 +00:00
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
|
|
2017-03-12 20:12:23 +00:00
|
|
|
final class ImageCell: UICollectionViewCell {
|
2016-10-20 06:26:07 +00:00
|
|
|
|
|
|
|
|
fileprivate let imageView: UIImageView = {
|
|
|
|
|
let view = UIImageView()
|
|
|
|
|
view.contentMode = .scaleAspectFill
|
|
|
|
|
view.clipsToBounds = true
|
2020-10-03 08:37:52 +00:00
|
|
|
view.backgroundColor = UIColor.secondaryBackground
|
2016-10-20 06:26:07 +00:00
|
|
|
return view
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
fileprivate let activityView: UIActivityIndicatorView = {
|
2020-10-03 08:37:52 +00:00
|
|
|
let view = UIActivityIndicatorView()
|
|
|
|
|
view.style = UIActivityIndicatorView.defaultStyle
|
2016-10-20 06:26:07 +00:00
|
|
|
view.startAnimating()
|
|
|
|
|
return view
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
override init(frame: CGRect) {
|
|
|
|
|
super.init(frame: frame)
|
|
|
|
|
contentView.addSubview(imageView)
|
|
|
|
|
contentView.addSubview(activityView)
|
|
|
|
|
}
|
2017-05-16 14:30:08 +00:00
|
|
|
|
2016-10-20 06:26:07 +00:00
|
|
|
required init?(coder aDecoder: NSCoder) {
|
|
|
|
|
fatalError("init(coder:) has not been implemented")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override func layoutSubviews() {
|
|
|
|
|
super.layoutSubviews()
|
|
|
|
|
let bounds = contentView.bounds
|
2018-01-22 20:01:53 +00:00
|
|
|
activityView.center = CGPoint(x: bounds.width / 2.0, y: bounds.height / 2.0)
|
2016-10-20 06:26:07 +00:00
|
|
|
imageView.frame = bounds
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func setImage(image: UIImage?) {
|
|
|
|
|
imageView.image = image
|
|
|
|
|
if image != nil {
|
|
|
|
|
activityView.stopAnimating()
|
|
|
|
|
} else {
|
|
|
|
|
activityView.startAnimating()
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-05-16 14:30:08 +00:00
|
|
|
|
2016-10-20 06:26:07 +00:00
|
|
|
}
|