Use visual effect views for sensitive media hide button so the button is

visible regardless of the image color
This commit is contained in:
Shadowfacts 2019-11-17 12:28:21 -05:00
parent 42a0a8890c
commit 6ce96764f3
Signed by untrusted user: shadowfacts
GPG Key ID: 94A5AB95422746E5
2 changed files with 39 additions and 24 deletions

View File

@ -105,14 +105,7 @@ class AttachmentView: UIImageView, GIFAnimatable {
}
@objc func imagePressed() {
// switch attachment.kind {
// case .image:
delegate?.showAttachmentsGallery(startingAt: index)
// case .video:
// delegate?.showVideo(attachment: attachment)
// default:
// fatalError()
// }
delegate?.showAttachmentsGallery(startingAt: index)
}
}

View File

@ -19,17 +19,17 @@ class AttachmentsContainerView: UIView {
let attachmentViews: NSHashTable<AttachmentView> = .weakObjects()
var blurView: UIVisualEffectView?
var hideButton: UIButton?
var hideButtonView: UIVisualEffectView?
var contentHidden: Bool! {
didSet {
guard let blurView = blurView,
let hideButton = hideButton else { return }
let hideButtonContainerView = hideButtonView else { return }
blurView.alpha = contentHidden ? 0 : 1
hideButton.alpha = contentHidden ? 1 : 0
hideButtonContainerView.alpha = contentHidden ? 1 : 0
UIView.animate(withDuration: 0.2) {
blurView.alpha = self.contentHidden ? 1 : 0
hideButton.alpha = self.contentHidden ? 0 : 1
hideButtonContainerView.alpha = self.contentHidden ? 0 : 1
}
}
}
@ -231,21 +231,43 @@ class AttachmentsContainerView: UIView {
}
private func createHideButton() {
let hideButton = UIButton()
hideButton.translatesAutoresizingMaskIntoConstraints = false
hideButton.alpha = 0
hideButton.layer.cornerRadius = 2
hideButton.layer.masksToBounds = true
hideButton.setImage(UIImage(systemName: "eye.slash.fill"), for: .normal)
hideButton.addTarget(self, action: #selector(hideButtonTapped), for: .touchUpInside)
let blurEffect = UIBlurEffect(style: .regular)
let hideButtonBlurView = UIVisualEffectView(effect: blurEffect)
hideButtonBlurView.translatesAutoresizingMaskIntoConstraints = false
hideButtonBlurView.alpha = 0
hideButtonBlurView.isUserInteractionEnabled = true
hideButtonBlurView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(hideButtonTapped)))
addSubview(hideButtonBlurView)
self.hideButtonView = hideButtonBlurView
addSubview(hideButton)
let maskLayer = CALayer()
let image = UIImage(systemName: "eye.slash.fill")!
maskLayer.contents = image.cgImage!
maskLayer.frame = CGRect(origin: .zero, size: image.size)
hideButtonBlurView.layer.mask = maskLayer
let hideButtonVibrancyView = UIVisualEffectView(effect: UIVibrancyEffect(blurEffect: blurEffect, style: .label))
hideButtonVibrancyView.translatesAutoresizingMaskIntoConstraints = false
hideButtonBlurView.contentView.addSubview(hideButtonVibrancyView)
let fillView = UIView()
fillView.translatesAutoresizingMaskIntoConstraints = false
fillView.backgroundColor = UIColor(displayP3Red: 0, green: 0, blue: 0, alpha: 0.5)
hideButtonVibrancyView.contentView.addSubview(fillView)
NSLayoutConstraint.activate([
hideButton.topAnchor.constraint(equalTo: topAnchor, constant: 8),
hideButton.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 8)
hideButtonBlurView.topAnchor.constraint(equalTo: topAnchor, constant: 8),
hideButtonBlurView.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 8),
hideButtonBlurView.widthAnchor.constraint(equalToConstant: image.size.width),
hideButtonBlurView.heightAnchor.constraint(equalToConstant: image.size.height),
hideButtonVibrancyView.leadingAnchor.constraint(equalTo: hideButtonBlurView.contentView.leadingAnchor),
hideButtonVibrancyView.trailingAnchor.constraint(equalTo: hideButtonBlurView.contentView.trailingAnchor),
hideButtonVibrancyView.topAnchor.constraint(equalTo: hideButtonBlurView.contentView.topAnchor),
hideButtonVibrancyView.bottomAnchor.constraint(equalTo: hideButtonBlurView.contentView.bottomAnchor),
fillView.leadingAnchor.constraint(equalTo: hideButtonBlurView.contentView.leadingAnchor),
fillView.trailingAnchor.constraint(equalTo: hideButtonBlurView.contentView.trailingAnchor),
fillView.topAnchor.constraint(equalTo: hideButtonBlurView.contentView.topAnchor),
fillView.bottomAnchor.constraint(equalTo: hideButtonBlurView.contentView.bottomAnchor),
])
self.hideButton = hideButton
}
private func fillView(_ view: UIView, in parentView: UIView? = nil) {