chore: extract the common blur effect part from MosaicImageViewContainer
This commit is contained in:
parent
37db8784bd
commit
2e31280819
|
@ -170,8 +170,8 @@ extension StatusSection {
|
||||||
}
|
}
|
||||||
cell.statusView.statusMosaicImageViewContainer.isHidden = mosiacImageViewModel.metas.isEmpty
|
cell.statusView.statusMosaicImageViewContainer.isHidden = mosiacImageViewModel.metas.isEmpty
|
||||||
let isStatusSensitive = statusItemAttribute.isStatusSensitive
|
let isStatusSensitive = statusItemAttribute.isStatusSensitive
|
||||||
cell.statusView.statusMosaicImageViewContainer.blurVisualEffectView.effect = isStatusSensitive ? MosaicImageViewContainer.blurVisualEffect : nil
|
cell.statusView.statusMosaicImageViewContainer.contentWarningOverlayView.blurVisualEffectView.effect = isStatusSensitive ? ContentWarningOverlayView.blurVisualEffect : nil
|
||||||
cell.statusView.statusMosaicImageViewContainer.vibrancyVisualEffectView.alpha = isStatusSensitive ? 1.0 : 0.0
|
cell.statusView.statusMosaicImageViewContainer.contentWarningOverlayView.vibrancyVisualEffectView.alpha = isStatusSensitive ? 1.0 : 0.0
|
||||||
|
|
||||||
// set audio
|
// set audio
|
||||||
if let audioAttachment = mediaAttachments.filter({ $0.type == .audio }).first {
|
if let audioAttachment = mediaAttachments.filter({ $0.type == .audio }).first {
|
||||||
|
@ -193,7 +193,7 @@ extension StatusSection {
|
||||||
return CGSize(width: maxWidth, height: maxWidth * scale)
|
return CGSize(width: maxWidth, height: maxWidth * scale)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
cell.statusView.playerContainerView.contentWarningOverlayView.blurVisualEffectView.effect = isStatusSensitive ? MosaicImageViewContainer.blurVisualEffect : nil
|
cell.statusView.playerContainerView.contentWarningOverlayView.blurVisualEffectView.effect = isStatusSensitive ? ContentWarningOverlayView.blurVisualEffect : nil
|
||||||
cell.statusView.playerContainerView.contentWarningOverlayView.vibrancyVisualEffectView.alpha = isStatusSensitive ? 1.0 : 0.0
|
cell.statusView.playerContainerView.contentWarningOverlayView.vibrancyVisualEffectView.alpha = isStatusSensitive ? 1.0 : 0.0
|
||||||
cell.statusView.playerContainerView.contentWarningOverlayView.isUserInteractionEnabled = isStatusSensitive
|
cell.statusView.playerContainerView.contentWarningOverlayView.isUserInteractionEnabled = isStatusSensitive
|
||||||
|
|
||||||
|
|
|
@ -46,30 +46,16 @@ extension StatusTableViewCellDelegate where Self: StatusProvider {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func statusTableViewCell(_ cell: StatusTableViewCell, mosaicImageViewContainer: MosaicImageViewContainer, didTapContentWarningVisualEffectView visualEffectView: UIVisualEffectView) {
|
func statusTableViewCell(_ cell: StatusTableViewCell, mosaicImageViewContainer: MosaicImageViewContainer, contentWarningOverlayViewDidPressed contentWarningOverlayView: ContentWarningOverlayView) {
|
||||||
guard let diffableDataSource = self.tableViewDiffableDataSource else { return }
|
statusTableViewCell(cell, contentWarningOverlayViewDidPressed: contentWarningOverlayView)
|
||||||
guard let item = item(for: cell, indexPath: nil) else { return }
|
|
||||||
|
|
||||||
switch item {
|
|
||||||
case .homeTimelineIndex(_, let attribute):
|
|
||||||
attribute.isStatusSensitive = false
|
|
||||||
case .toot(_, let attribute):
|
|
||||||
attribute.isStatusSensitive = false
|
|
||||||
default:
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var snapshot = diffableDataSource.snapshot()
|
|
||||||
snapshot.reloadItems([item])
|
|
||||||
UIView.animate(withDuration: 0.33) {
|
|
||||||
cell.statusView.statusMosaicImageViewContainer.blurVisualEffectView.effect = nil
|
|
||||||
cell.statusView.statusMosaicImageViewContainer.vibrancyVisualEffectView.alpha = 0.0
|
|
||||||
} completion: { _ in
|
|
||||||
diffableDataSource.apply(snapshot, animatingDifferences: false, completion: nil)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func statusTableViewCell(_ cell: StatusTableViewCell, playerContainerView: PlayerContainerView, contentWarningOverlayViewDidPressed contentWarningOverlayView: ContentWarningOverlayView) {
|
func statusTableViewCell(_ cell: StatusTableViewCell, playerContainerView: PlayerContainerView, contentWarningOverlayViewDidPressed contentWarningOverlayView: ContentWarningOverlayView) {
|
||||||
|
contentWarningOverlayView.isUserInteractionEnabled = false
|
||||||
|
statusTableViewCell(cell, contentWarningOverlayViewDidPressed: contentWarningOverlayView)
|
||||||
|
}
|
||||||
|
|
||||||
|
func statusTableViewCell(_ cell: StatusTableViewCell, contentWarningOverlayViewDidPressed contentWarningOverlayView: ContentWarningOverlayView) {
|
||||||
guard let diffableDataSource = self.tableViewDiffableDataSource else { return }
|
guard let diffableDataSource = self.tableViewDiffableDataSource else { return }
|
||||||
guard let item = item(for: cell, indexPath: nil) else { return }
|
guard let item = item(for: cell, indexPath: nil) else { return }
|
||||||
|
|
||||||
|
|
|
@ -15,15 +15,12 @@ protocol MosaicImageViewContainerPresentable: class {
|
||||||
|
|
||||||
protocol MosaicImageViewContainerDelegate: class {
|
protocol MosaicImageViewContainerDelegate: class {
|
||||||
func mosaicImageViewContainer(_ mosaicImageViewContainer: MosaicImageViewContainer, didTapImageView imageView: UIImageView, atIndex index: Int)
|
func mosaicImageViewContainer(_ mosaicImageViewContainer: MosaicImageViewContainer, didTapImageView imageView: UIImageView, atIndex index: Int)
|
||||||
func mosaicImageViewContainer(_ mosaicImageViewContainer: MosaicImageViewContainer, didTapContentWarningVisualEffectView visualEffectView: UIVisualEffectView)
|
func mosaicImageViewContainer(_ mosaicImageViewContainer: MosaicImageViewContainer, contentWarningOverlayViewDidPressed contentWarningOverlayView: ContentWarningOverlayView)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final class MosaicImageViewContainer: UIView {
|
final class MosaicImageViewContainer: UIView {
|
||||||
|
|
||||||
static let cornerRadius: CGFloat = 4
|
|
||||||
static let blurVisualEffect = UIBlurEffect(style: .systemUltraThinMaterial)
|
|
||||||
|
|
||||||
weak var delegate: MosaicImageViewContainerDelegate?
|
weak var delegate: MosaicImageViewContainerDelegate?
|
||||||
|
|
||||||
let container = UIStackView()
|
let container = UIStackView()
|
||||||
|
@ -37,14 +34,10 @@ final class MosaicImageViewContainer: UIView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let blurVisualEffectView = UIVisualEffectView(effect: MosaicImageViewContainer.blurVisualEffect)
|
|
||||||
let vibrancyVisualEffectView = UIVisualEffectView(effect: UIVibrancyEffect(blurEffect: MosaicImageViewContainer.blurVisualEffect))
|
let contentWarningOverlayView: ContentWarningOverlayView = {
|
||||||
let contentWarningLabel: UILabel = {
|
let contentWarningOverlayView = ContentWarningOverlayView()
|
||||||
let label = UILabel()
|
return contentWarningOverlayView
|
||||||
label.font = UIFontMetrics(forTextStyle: .body).scaledFont(for: .systemFont(ofSize: 15))
|
|
||||||
label.text = L10n.Common.Controls.Status.mediaContentWarning
|
|
||||||
label.textAlignment = .center
|
|
||||||
return label
|
|
||||||
}()
|
}()
|
||||||
|
|
||||||
private var containerHeightLayoutConstraint: NSLayoutConstraint!
|
private var containerHeightLayoutConstraint: NSLayoutConstraint!
|
||||||
|
@ -61,9 +54,16 @@ final class MosaicImageViewContainer: UIView {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension MosaicImageViewContainer: ContentWarningOverlayViewDelegate {
|
||||||
|
func contentWarningOverlayViewDidPressed(_ contentWarningOverlayView: ContentWarningOverlayView) {
|
||||||
|
self.delegate?.mosaicImageViewContainer(self, contentWarningOverlayViewDidPressed: contentWarningOverlayView)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
extension MosaicImageViewContainer {
|
extension MosaicImageViewContainer {
|
||||||
|
|
||||||
private func _init() {
|
private func _init() {
|
||||||
|
contentWarningOverlayView.delegate = self
|
||||||
container.translatesAutoresizingMaskIntoConstraints = false
|
container.translatesAutoresizingMaskIntoConstraints = false
|
||||||
container.axis = .horizontal
|
container.axis = .horizontal
|
||||||
container.distribution = .fillEqually
|
container.distribution = .fillEqually
|
||||||
|
@ -77,32 +77,13 @@ extension MosaicImageViewContainer {
|
||||||
containerHeightLayoutConstraint
|
containerHeightLayoutConstraint
|
||||||
])
|
])
|
||||||
|
|
||||||
// add blur visual effect view in the setup method
|
addSubview(contentWarningOverlayView)
|
||||||
blurVisualEffectView.layer.masksToBounds = true
|
|
||||||
blurVisualEffectView.layer.cornerRadius = MosaicImageViewContainer.cornerRadius
|
|
||||||
blurVisualEffectView.layer.cornerCurve = .continuous
|
|
||||||
|
|
||||||
vibrancyVisualEffectView.translatesAutoresizingMaskIntoConstraints = false
|
|
||||||
blurVisualEffectView.contentView.addSubview(vibrancyVisualEffectView)
|
|
||||||
NSLayoutConstraint.activate([
|
NSLayoutConstraint.activate([
|
||||||
vibrancyVisualEffectView.topAnchor.constraint(equalTo: blurVisualEffectView.topAnchor),
|
contentWarningOverlayView.topAnchor.constraint(equalTo: container.topAnchor),
|
||||||
vibrancyVisualEffectView.leadingAnchor.constraint(equalTo: blurVisualEffectView.leadingAnchor),
|
contentWarningOverlayView.leadingAnchor.constraint(equalTo: container.leadingAnchor),
|
||||||
vibrancyVisualEffectView.trailingAnchor.constraint(equalTo: blurVisualEffectView.trailingAnchor),
|
contentWarningOverlayView.bottomAnchor.constraint(equalTo: container.bottomAnchor),
|
||||||
vibrancyVisualEffectView.bottomAnchor.constraint(equalTo: blurVisualEffectView.bottomAnchor),
|
contentWarningOverlayView.trailingAnchor.constraint(equalTo: container.trailingAnchor),
|
||||||
])
|
])
|
||||||
|
|
||||||
contentWarningLabel.translatesAutoresizingMaskIntoConstraints = false
|
|
||||||
vibrancyVisualEffectView.contentView.addSubview(contentWarningLabel)
|
|
||||||
NSLayoutConstraint.activate([
|
|
||||||
contentWarningLabel.leadingAnchor.constraint(equalTo: vibrancyVisualEffectView.contentView.layoutMarginsGuide.leadingAnchor),
|
|
||||||
contentWarningLabel.trailingAnchor.constraint(equalTo: vibrancyVisualEffectView.contentView.layoutMarginsGuide.trailingAnchor),
|
|
||||||
contentWarningLabel.centerYAnchor.constraint(equalTo: vibrancyVisualEffectView.contentView.centerYAnchor),
|
|
||||||
])
|
|
||||||
|
|
||||||
blurVisualEffectView.isUserInteractionEnabled = true
|
|
||||||
let tapGesture = UITapGestureRecognizer.singleTapGestureRecognizer
|
|
||||||
tapGesture.addTarget(self, action: #selector(MosaicImageViewContainer.visualEffectViewTapGestureRecognizerHandler(_:)))
|
|
||||||
blurVisualEffectView.addGestureRecognizer(tapGesture)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -117,9 +98,9 @@ extension MosaicImageViewContainer {
|
||||||
container.subviews.forEach { subview in
|
container.subviews.forEach { subview in
|
||||||
subview.removeFromSuperview()
|
subview.removeFromSuperview()
|
||||||
}
|
}
|
||||||
blurVisualEffectView.removeFromSuperview()
|
contentWarningOverlayView.removeFromSuperview()
|
||||||
blurVisualEffectView.effect = MosaicImageViewContainer.blurVisualEffect
|
contentWarningOverlayView.blurVisualEffectView.effect = ContentWarningOverlayView.blurVisualEffect
|
||||||
vibrancyVisualEffectView.alpha = 1.0
|
contentWarningOverlayView.vibrancyVisualEffectView.alpha = 1.0
|
||||||
imageViews = []
|
imageViews = []
|
||||||
|
|
||||||
container.spacing = 1
|
container.spacing = 1
|
||||||
|
@ -140,7 +121,7 @@ extension MosaicImageViewContainer {
|
||||||
let imageView = UIImageView()
|
let imageView = UIImageView()
|
||||||
imageViews.append(imageView)
|
imageViews.append(imageView)
|
||||||
imageView.layer.masksToBounds = true
|
imageView.layer.masksToBounds = true
|
||||||
imageView.layer.cornerRadius = MosaicImageViewContainer.cornerRadius
|
imageView.layer.cornerRadius = ContentWarningOverlayView.cornerRadius
|
||||||
imageView.layer.cornerCurve = .continuous
|
imageView.layer.cornerCurve = .continuous
|
||||||
imageView.contentMode = .scaleAspectFill
|
imageView.contentMode = .scaleAspectFill
|
||||||
|
|
||||||
|
@ -155,13 +136,12 @@ extension MosaicImageViewContainer {
|
||||||
containerHeightLayoutConstraint.constant = floor(rect.height)
|
containerHeightLayoutConstraint.constant = floor(rect.height)
|
||||||
containerHeightLayoutConstraint.isActive = true
|
containerHeightLayoutConstraint.isActive = true
|
||||||
|
|
||||||
blurVisualEffectView.translatesAutoresizingMaskIntoConstraints = false
|
addSubview(contentWarningOverlayView)
|
||||||
addSubview(blurVisualEffectView)
|
|
||||||
NSLayoutConstraint.activate([
|
NSLayoutConstraint.activate([
|
||||||
blurVisualEffectView.topAnchor.constraint(equalTo: imageView.topAnchor),
|
contentWarningOverlayView.topAnchor.constraint(equalTo: imageView.topAnchor),
|
||||||
blurVisualEffectView.leadingAnchor.constraint(equalTo: imageView.leadingAnchor),
|
contentWarningOverlayView.leadingAnchor.constraint(equalTo: imageView.leadingAnchor),
|
||||||
blurVisualEffectView.trailingAnchor.constraint(equalTo: imageView.trailingAnchor),
|
contentWarningOverlayView.trailingAnchor.constraint(equalTo: imageView.trailingAnchor),
|
||||||
blurVisualEffectView.bottomAnchor.constraint(equalTo: imageView.bottomAnchor),
|
contentWarningOverlayView.bottomAnchor.constraint(equalTo: imageView.bottomAnchor),
|
||||||
])
|
])
|
||||||
|
|
||||||
return imageView
|
return imageView
|
||||||
|
@ -193,7 +173,7 @@ extension MosaicImageViewContainer {
|
||||||
self.imageViews.append(contentsOf: imageViews)
|
self.imageViews.append(contentsOf: imageViews)
|
||||||
imageViews.forEach { imageView in
|
imageViews.forEach { imageView in
|
||||||
imageView.layer.masksToBounds = true
|
imageView.layer.masksToBounds = true
|
||||||
imageView.layer.cornerRadius = MosaicImageViewContainer.cornerRadius
|
imageView.layer.cornerRadius = ContentWarningOverlayView.cornerRadius
|
||||||
imageView.layer.cornerCurve = .continuous
|
imageView.layer.cornerCurve = .continuous
|
||||||
imageView.contentMode = .scaleAspectFill
|
imageView.contentMode = .scaleAspectFill
|
||||||
}
|
}
|
||||||
|
@ -242,13 +222,12 @@ extension MosaicImageViewContainer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
blurVisualEffectView.translatesAutoresizingMaskIntoConstraints = false
|
addSubview(contentWarningOverlayView)
|
||||||
addSubview(blurVisualEffectView)
|
|
||||||
NSLayoutConstraint.activate([
|
NSLayoutConstraint.activate([
|
||||||
blurVisualEffectView.topAnchor.constraint(equalTo: container.topAnchor),
|
contentWarningOverlayView.topAnchor.constraint(equalTo: container.topAnchor),
|
||||||
blurVisualEffectView.leadingAnchor.constraint(equalTo: container.leadingAnchor),
|
contentWarningOverlayView.leadingAnchor.constraint(equalTo: container.leadingAnchor),
|
||||||
blurVisualEffectView.trailingAnchor.constraint(equalTo: container.trailingAnchor),
|
contentWarningOverlayView.trailingAnchor.constraint(equalTo: container.trailingAnchor),
|
||||||
blurVisualEffectView.bottomAnchor.constraint(equalTo: container.bottomAnchor),
|
contentWarningOverlayView.bottomAnchor.constraint(equalTo: container.bottomAnchor),
|
||||||
])
|
])
|
||||||
|
|
||||||
return imageViews
|
return imageViews
|
||||||
|
@ -260,7 +239,7 @@ extension MosaicImageViewContainer {
|
||||||
|
|
||||||
@objc private func visualEffectViewTapGestureRecognizerHandler(_ sender: UITapGestureRecognizer) {
|
@objc private func visualEffectViewTapGestureRecognizerHandler(_ sender: UITapGestureRecognizer) {
|
||||||
os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s", ((#file as NSString).lastPathComponent), #line, #function)
|
os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s", ((#file as NSString).lastPathComponent), #line, #function)
|
||||||
delegate?.mosaicImageViewContainer(self, didTapContentWarningVisualEffectView: blurVisualEffectView)
|
delegate?.mosaicImageViewContainer(self, contentWarningOverlayViewDidPressed: contentWarningOverlayView)
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc private func photoTapGestureRecognizerHandler(_ sender: UITapGestureRecognizer) {
|
@objc private func photoTapGestureRecognizerHandler(_ sender: UITapGestureRecognizer) {
|
||||||
|
|
|
@ -22,7 +22,7 @@ protocol StatusTableViewCellDelegate: class {
|
||||||
|
|
||||||
|
|
||||||
func statusTableViewCell(_ cell: StatusTableViewCell, statusView: StatusView, contentWarningActionButtonPressed button: UIButton)
|
func statusTableViewCell(_ cell: StatusTableViewCell, statusView: StatusView, contentWarningActionButtonPressed button: UIButton)
|
||||||
func statusTableViewCell(_ cell: StatusTableViewCell, mosaicImageViewContainer: MosaicImageViewContainer, didTapContentWarningVisualEffectView visualEffectView: UIVisualEffectView)
|
func statusTableViewCell(_ cell: StatusTableViewCell, mosaicImageViewContainer: MosaicImageViewContainer, contentWarningOverlayViewDidPressed contentWarningOverlayView: ContentWarningOverlayView)
|
||||||
func statusTableViewCell(_ cell: StatusTableViewCell, mosaicImageViewContainer: MosaicImageViewContainer, didTapImageView imageView: UIImageView, atIndex index: Int)
|
func statusTableViewCell(_ cell: StatusTableViewCell, mosaicImageViewContainer: MosaicImageViewContainer, didTapImageView imageView: UIImageView, atIndex index: Int)
|
||||||
func statusTableViewCell(_ cell: StatusTableViewCell, playerContainerView: PlayerContainerView, contentWarningOverlayViewDidPressed contentWarningOverlayView: ContentWarningOverlayView)
|
func statusTableViewCell(_ cell: StatusTableViewCell, playerContainerView: PlayerContainerView, contentWarningOverlayViewDidPressed contentWarningOverlayView: ContentWarningOverlayView)
|
||||||
func statusTableViewCell(_ cell: StatusTableViewCell, actionToolbarContainer: ActionToolbarContainer, likeButtonDidPressed sender: UIButton)
|
func statusTableViewCell(_ cell: StatusTableViewCell, actionToolbarContainer: ActionToolbarContainer, likeButtonDidPressed sender: UIButton)
|
||||||
|
@ -215,8 +215,8 @@ extension StatusTableViewCell: MosaicImageViewContainerDelegate {
|
||||||
delegate?.statusTableViewCell(self, mosaicImageViewContainer: mosaicImageViewContainer, didTapImageView: imageView, atIndex: index)
|
delegate?.statusTableViewCell(self, mosaicImageViewContainer: mosaicImageViewContainer, didTapImageView: imageView, atIndex: index)
|
||||||
}
|
}
|
||||||
|
|
||||||
func mosaicImageViewContainer(_ mosaicImageViewContainer: MosaicImageViewContainer, didTapContentWarningVisualEffectView visualEffectView: UIVisualEffectView) {
|
func mosaicImageViewContainer(_ mosaicImageViewContainer: MosaicImageViewContainer, contentWarningOverlayViewDidPressed contentWarningOverlayView: ContentWarningOverlayView) {
|
||||||
delegate?.statusTableViewCell(self, mosaicImageViewContainer: mosaicImageViewContainer, didTapContentWarningVisualEffectView: visualEffectView)
|
delegate?.statusTableViewCell(self, mosaicImageViewContainer: mosaicImageViewContainer, contentWarningOverlayViewDidPressed: contentWarningOverlayView)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue