chore: profile media image container layout
This commit is contained in:
parent
0a622f6ca8
commit
69f6c5176e
|
@ -24,18 +24,21 @@ final class MosaicImageViewContainer: UIView {
|
||||||
weak var delegate: MosaicImageViewContainerDelegate?
|
weak var delegate: MosaicImageViewContainerDelegate?
|
||||||
|
|
||||||
let container = UIStackView()
|
let container = UIStackView()
|
||||||
var imageViews: [UIImageView] = [] {
|
private(set) lazy var imageViews: [UIImageView] = {
|
||||||
didSet {
|
(0..<4).map { _ -> UIImageView in
|
||||||
imageViews.forEach { imageView in
|
let imageView = UIImageView()
|
||||||
imageView.isUserInteractionEnabled = true
|
imageView.isUserInteractionEnabled = true
|
||||||
let tapGesture = UITapGestureRecognizer.singleTapGestureRecognizer
|
let tapGesture = UITapGestureRecognizer.singleTapGestureRecognizer
|
||||||
tapGesture.addTarget(self, action: #selector(MosaicImageViewContainer.photoTapGestureRecognizerHandler(_:)))
|
tapGesture.addTarget(self, action: #selector(MosaicImageViewContainer.photoTapGestureRecognizerHandler(_:)))
|
||||||
imageView.addGestureRecognizer(tapGesture)
|
imageView.addGestureRecognizer(tapGesture)
|
||||||
imageView.isAccessibilityElement = true
|
imageView.isAccessibilityElement = true
|
||||||
}
|
imageView.backgroundColor = .systemFill
|
||||||
|
return imageView
|
||||||
}
|
}
|
||||||
}
|
}()
|
||||||
var blurhashOverlayImageViews: [UIImageView] = []
|
let blurhashOverlayImageViews: [UIImageView] = {
|
||||||
|
(0..<4).map { _ in UIImageView() }
|
||||||
|
}()
|
||||||
|
|
||||||
let contentWarningOverlayView: ContentWarningOverlayView = {
|
let contentWarningOverlayView: ContentWarningOverlayView = {
|
||||||
let contentWarningOverlayView = ContentWarningOverlayView()
|
let contentWarningOverlayView = ContentWarningOverlayView()
|
||||||
|
@ -97,12 +100,19 @@ extension MosaicImageViewContainer {
|
||||||
container.subviews.forEach { subview in
|
container.subviews.forEach { subview in
|
||||||
subview.removeFromSuperview()
|
subview.removeFromSuperview()
|
||||||
}
|
}
|
||||||
|
imageViews.forEach { imageView in
|
||||||
|
imageView.constraints.forEach { imageView.removeConstraint($0) }
|
||||||
|
imageView.removeFromSuperview()
|
||||||
|
}
|
||||||
|
blurhashOverlayImageViews.forEach { imageView in
|
||||||
|
imageView.constraints.forEach { imageView.removeConstraint($0) }
|
||||||
|
imageView.removeFromSuperview()
|
||||||
|
}
|
||||||
|
|
||||||
contentWarningOverlayView.removeFromSuperview()
|
contentWarningOverlayView.removeFromSuperview()
|
||||||
contentWarningOverlayView.blurVisualEffectView.effect = ContentWarningOverlayView.blurVisualEffect
|
contentWarningOverlayView.blurVisualEffectView.effect = ContentWarningOverlayView.blurVisualEffect
|
||||||
contentWarningOverlayView.vibrancyVisualEffectView.alpha = 1.0
|
contentWarningOverlayView.vibrancyVisualEffectView.alpha = 1.0
|
||||||
contentWarningOverlayView.isUserInteractionEnabled = true
|
contentWarningOverlayView.isUserInteractionEnabled = true
|
||||||
imageViews = []
|
|
||||||
blurhashOverlayImageViews = []
|
|
||||||
|
|
||||||
container.spacing = UIView.separatorLineHeight(of: self) * 2 // 2px
|
container.spacing = UIView.separatorLineHeight(of: self) * 2 // 2px
|
||||||
}
|
}
|
||||||
|
@ -129,8 +139,7 @@ extension MosaicImageViewContainer {
|
||||||
}()
|
}()
|
||||||
let imageViewFrame = CGRect(origin: .zero, size: imageViewSize)
|
let imageViewFrame = CGRect(origin: .zero, size: imageViewSize)
|
||||||
|
|
||||||
let imageView = UIImageView(frame: imageViewFrame)
|
let imageView = imageViews[0]
|
||||||
imageViews.append(imageView)
|
|
||||||
imageView.layer.masksToBounds = true
|
imageView.layer.masksToBounds = true
|
||||||
imageView.layer.cornerRadius = ContentWarningOverlayView.cornerRadius
|
imageView.layer.cornerRadius = ContentWarningOverlayView.cornerRadius
|
||||||
imageView.layer.cornerCurve = .continuous
|
imageView.layer.cornerCurve = .continuous
|
||||||
|
@ -147,12 +156,11 @@ extension MosaicImageViewContainer {
|
||||||
containerHeightLayoutConstraint.constant = imageViewFrame.height
|
containerHeightLayoutConstraint.constant = imageViewFrame.height
|
||||||
containerHeightLayoutConstraint.isActive = true
|
containerHeightLayoutConstraint.isActive = true
|
||||||
|
|
||||||
let blurhashOverlayImageView = UIImageView()
|
let blurhashOverlayImageView = blurhashOverlayImageViews[0]
|
||||||
blurhashOverlayImageView.layer.masksToBounds = true
|
blurhashOverlayImageView.layer.masksToBounds = true
|
||||||
blurhashOverlayImageView.layer.cornerRadius = ContentWarningOverlayView.cornerRadius
|
blurhashOverlayImageView.layer.cornerRadius = ContentWarningOverlayView.cornerRadius
|
||||||
blurhashOverlayImageView.layer.cornerCurve = .continuous
|
blurhashOverlayImageView.layer.cornerCurve = .continuous
|
||||||
blurhashOverlayImageView.contentMode = .scaleAspectFill
|
blurhashOverlayImageView.contentMode = .scaleAspectFill
|
||||||
blurhashOverlayImageViews.append(blurhashOverlayImageView)
|
|
||||||
blurhashOverlayImageView.translatesAutoresizingMaskIntoConstraints = false
|
blurhashOverlayImageView.translatesAutoresizingMaskIntoConstraints = false
|
||||||
contentView.addSubview(blurhashOverlayImageView)
|
contentView.addSubview(blurhashOverlayImageView)
|
||||||
NSLayoutConstraint.activate([
|
NSLayoutConstraint.activate([
|
||||||
|
@ -200,14 +208,9 @@ extension MosaicImageViewContainer {
|
||||||
container.addArrangedSubview(contentLeftStackView)
|
container.addArrangedSubview(contentLeftStackView)
|
||||||
container.addArrangedSubview(contentRightStackView)
|
container.addArrangedSubview(contentRightStackView)
|
||||||
|
|
||||||
var imageViews: [UIImageView] = []
|
let imageViews: [UIImageView] = (0..<count).map { i in self.imageViews[i] }
|
||||||
var blurhashOverlayImageViews: [UIImageView] = []
|
let blurhashOverlayImageViews: [UIImageView] = (0..<count).map { i in self.blurhashOverlayImageViews[i] }
|
||||||
for _ in 0..<count {
|
|
||||||
imageViews.append(UIImageView())
|
|
||||||
blurhashOverlayImageViews.append(UIImageView())
|
|
||||||
}
|
|
||||||
self.imageViews.append(contentsOf: imageViews)
|
|
||||||
self.blurhashOverlayImageViews.append(contentsOf: blurhashOverlayImageViews)
|
|
||||||
imageViews.forEach { imageView in
|
imageViews.forEach { imageView in
|
||||||
imageView.layer.masksToBounds = true
|
imageView.layer.masksToBounds = true
|
||||||
imageView.layer.cornerRadius = ContentWarningOverlayView.cornerRadius
|
imageView.layer.cornerRadius = ContentWarningOverlayView.cornerRadius
|
||||||
|
|
Loading…
Reference in New Issue