Factor out code for the close button
This commit is contained in:
parent
0f28f9aedd
commit
dd95724d14
|
@ -98,6 +98,7 @@
|
|||
62FD27D52893708A00B205C5 /* BookmarkViewModel+Diffable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62FD27D42893708A00B205C5 /* BookmarkViewModel+Diffable.swift */; };
|
||||
85904C02293BC0EB0011C817 /* ImageProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 85904C01293BC0EB0011C817 /* ImageProvider.swift */; };
|
||||
85904C04293BC1940011C817 /* URLActivityItemWithMetadata.swift in Sources */ = {isa = PBXBuildFile; fileRef = 85904C03293BC1940011C817 /* URLActivityItemWithMetadata.swift */; };
|
||||
85BC11B1292FF92C00E191CD /* HUDButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 85BC11B0292FF92C00E191CD /* HUDButton.swift */; };
|
||||
87FFDA5D898A5C42ADCB35E7 /* Pods_Mastodon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A4ABE34829701A4496C5BB64 /* Pods_Mastodon.framework */; };
|
||||
C24C97032922F30500BAE8CB /* RefreshControl.swift in Sources */ = {isa = PBXBuildFile; fileRef = C24C97022922F30500BAE8CB /* RefreshControl.swift */; };
|
||||
D87BFC8B291D5C6B00FEE264 /* MastodonLoginView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D87BFC8A291D5C6B00FEE264 /* MastodonLoginView.swift */; };
|
||||
|
@ -620,6 +621,7 @@
|
|||
819CEC9DCAD8E8E7BD85A7BB /* Pods-Mastodon.asdk.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Mastodon.asdk.xcconfig"; path = "Target Support Files/Pods-Mastodon/Pods-Mastodon.asdk.xcconfig"; sourceTree = "<group>"; };
|
||||
85904C01293BC0EB0011C817 /* ImageProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageProvider.swift; sourceTree = "<group>"; };
|
||||
85904C03293BC1940011C817 /* URLActivityItemWithMetadata.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLActivityItemWithMetadata.swift; sourceTree = "<group>"; };
|
||||
85BC11B0292FF92C00E191CD /* HUDButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HUDButton.swift; sourceTree = "<group>"; };
|
||||
8850E70A1D5FF51432E43653 /* Pods-Mastodon-MastodonUITests.asdk - release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Mastodon-MastodonUITests.asdk - release.xcconfig"; path = "Target Support Files/Pods-Mastodon-MastodonUITests/Pods-Mastodon-MastodonUITests.asdk - release.xcconfig"; sourceTree = "<group>"; };
|
||||
8E79CCBE51FBC3F7FE8CF49F /* Pods-MastodonTests.release snapshot.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-MastodonTests.release snapshot.xcconfig"; path = "Target Support Files/Pods-MastodonTests/Pods-MastodonTests.release snapshot.xcconfig"; sourceTree = "<group>"; };
|
||||
8ED8C4B1F1BA2DCFF2926BB1 /* Pods-Mastodon-NotificationService.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Mastodon-NotificationService.debug.xcconfig"; path = "Target Support Files/Pods-Mastodon-NotificationService/Pods-Mastodon-NotificationService.debug.xcconfig"; sourceTree = "<group>"; };
|
||||
|
@ -1974,6 +1976,7 @@
|
|||
DBB45B5727B39FCC002DC5A7 /* Video */,
|
||||
DB6180F026391CAB0018D199 /* Image */,
|
||||
DB6180E1263919780018D199 /* Paging */,
|
||||
85BC11B0292FF92C00E191CD /* HUDButton.swift */,
|
||||
DB6180DC263918E30018D199 /* MediaPreviewViewController.swift */,
|
||||
DB6180F926391F2E0018D199 /* MediaPreviewViewModel.swift */,
|
||||
);
|
||||
|
@ -3419,6 +3422,7 @@
|
|||
2DCB73FD2615C13900EC03D4 /* SearchRecommendCollectionHeader.swift in Sources */,
|
||||
2A1FE47C2938BB2600784BF1 /* FollowedTagsViewModel+DiffableDataSource.swift in Sources */,
|
||||
DB852D1C26FB021500FC9D81 /* RootSplitViewController.swift in Sources */,
|
||||
85BC11B1292FF92C00E191CD /* HUDButton.swift in Sources */,
|
||||
DB697DD1278F4871004EF2F7 /* AutoGenerateTableViewDelegate.swift in Sources */,
|
||||
DB02CDBF2625AE5000D0A2AF /* AdaptiveUserInterfaceStyleBarButtonItem.swift in Sources */,
|
||||
DB3E6FFA2807C47900B035AE /* DiscoveryForYouViewModel+Diffable.swift in Sources */,
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
//
|
||||
// HUDButton.swift
|
||||
// Mastodon
|
||||
//
|
||||
// Created by Jed Fox on 2022-11-24.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
import MastodonUI
|
||||
|
||||
class HUDButton: UIView {
|
||||
|
||||
static let height: CGFloat = 30
|
||||
|
||||
let background: UIVisualEffectView = {
|
||||
let backgroundView = UIVisualEffectView(effect: UIBlurEffect(style: .systemUltraThinMaterial))
|
||||
backgroundView.alpha = 0.9
|
||||
backgroundView.layer.masksToBounds = true
|
||||
backgroundView.layer.cornerRadius = HUDButton.height * 0.5
|
||||
return backgroundView
|
||||
}()
|
||||
|
||||
let vibrancyView = UIVisualEffectView(effect: UIVibrancyEffect(blurEffect: UIBlurEffect(style: .systemUltraThinMaterial)))
|
||||
|
||||
let button: UIButton = {
|
||||
let button = HighlightDimmableButton()
|
||||
button.expandEdgeInsets = UIEdgeInsets(top: -10, left: -10, bottom: -10, right: -10)
|
||||
button.imageView?.tintColor = .label
|
||||
return button
|
||||
}()
|
||||
|
||||
init(configure: (UIButton) -> Void) {
|
||||
super.init(frame: .zero)
|
||||
|
||||
configure(button)
|
||||
_init()
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
super.init(coder: coder)
|
||||
_init()
|
||||
}
|
||||
|
||||
func _init() {
|
||||
translatesAutoresizingMaskIntoConstraints = false
|
||||
background.translatesAutoresizingMaskIntoConstraints = false
|
||||
addSubview(background)
|
||||
background.pinToParent()
|
||||
vibrancyView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
|
||||
background.contentView.addSubview(vibrancyView)
|
||||
|
||||
button.translatesAutoresizingMaskIntoConstraints = false
|
||||
vibrancyView.contentView.addSubview(button)
|
||||
button.pinToParent()
|
||||
NSLayoutConstraint.activate([
|
||||
heightAnchor.constraint(equalToConstant: HUDButton.height).priority(.defaultHigh),
|
||||
])
|
||||
}
|
||||
}
|
|
@ -16,8 +16,6 @@ import MastodonLocalization
|
|||
|
||||
final class MediaPreviewViewController: UIViewController, NeedsDependency {
|
||||
|
||||
static let closeButtonSize = CGSize(width: 30, height: 30)
|
||||
|
||||
weak var context: AppContext! { willSet { precondition(!isViewLoaded) } }
|
||||
weak var coordinator: SceneCoordinator! { willSet { precondition(!isViewLoaded) } }
|
||||
|
||||
|
@ -27,23 +25,9 @@ final class MediaPreviewViewController: UIViewController, NeedsDependency {
|
|||
let visualEffectView = UIVisualEffectView(effect: UIBlurEffect(style: .systemMaterial))
|
||||
let pagingViewController = MediaPreviewPagingViewController()
|
||||
|
||||
let closeButtonBackground: UIVisualEffectView = {
|
||||
let backgroundView = UIVisualEffectView(effect: UIBlurEffect(style: .systemUltraThinMaterial))
|
||||
backgroundView.alpha = 0.9
|
||||
backgroundView.layer.masksToBounds = true
|
||||
backgroundView.layer.cornerRadius = MediaPreviewViewController.closeButtonSize.width * 0.5
|
||||
return backgroundView
|
||||
}()
|
||||
|
||||
let closeButtonBackgroundVisualEffectView = UIVisualEffectView(effect: UIVibrancyEffect(blurEffect: UIBlurEffect(style: .systemUltraThinMaterial)))
|
||||
|
||||
let closeButton: UIButton = {
|
||||
let button = HighlightDimmableButton()
|
||||
button.expandEdgeInsets = UIEdgeInsets(top: -10, left: -10, bottom: -10, right: -10)
|
||||
button.imageView?.tintColor = .label
|
||||
let closeButton = HUDButton { button in
|
||||
button.setImage(UIImage(systemName: "xmark", withConfiguration: UIImage.SymbolConfiguration(pointSize: 16, weight: .bold))!, for: .normal)
|
||||
return button
|
||||
}()
|
||||
}
|
||||
|
||||
deinit {
|
||||
os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s", ((#file as NSString).lastPathComponent), #line, #function)
|
||||
|
@ -67,25 +51,12 @@ extension MediaPreviewViewController {
|
|||
visualEffectView.contentView.addSubview(pagingViewController.view)
|
||||
visualEffectView.pinTo(to: pagingViewController.view)
|
||||
pagingViewController.didMove(toParent: self)
|
||||
|
||||
closeButtonBackground.translatesAutoresizingMaskIntoConstraints = false
|
||||
view.addSubview(closeButtonBackground)
|
||||
NSLayoutConstraint.activate([
|
||||
closeButtonBackground.topAnchor.constraint(equalTo: view.layoutMarginsGuide.topAnchor, constant: 12),
|
||||
closeButtonBackground.leadingAnchor.constraint(equalTo: view.layoutMarginsGuide.leadingAnchor)
|
||||
])
|
||||
closeButtonBackgroundVisualEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
|
||||
closeButtonBackground.contentView.addSubview(closeButtonBackgroundVisualEffectView)
|
||||
|
||||
closeButton.translatesAutoresizingMaskIntoConstraints = false
|
||||
closeButtonBackgroundVisualEffectView.contentView.addSubview(closeButton)
|
||||
view.addSubview(closeButton)
|
||||
NSLayoutConstraint.activate([
|
||||
closeButton.topAnchor.constraint(equalTo: closeButtonBackgroundVisualEffectView.topAnchor),
|
||||
closeButton.leadingAnchor.constraint(equalTo: closeButtonBackgroundVisualEffectView.leadingAnchor),
|
||||
closeButtonBackgroundVisualEffectView.trailingAnchor.constraint(equalTo: closeButton.trailingAnchor),
|
||||
closeButtonBackgroundVisualEffectView.bottomAnchor.constraint(equalTo: closeButton.bottomAnchor),
|
||||
closeButton.heightAnchor.constraint(equalToConstant: MediaPreviewViewController.closeButtonSize.height).priority(.defaultHigh),
|
||||
closeButton.widthAnchor.constraint(equalToConstant: MediaPreviewViewController.closeButtonSize.width).priority(.defaultHigh),
|
||||
closeButton.topAnchor.constraint(equalTo: view.layoutMarginsGuide.topAnchor, constant: 12),
|
||||
closeButton.leadingAnchor.constraint(equalTo: view.layoutMarginsGuide.leadingAnchor),
|
||||
closeButton.widthAnchor.constraint(equalToConstant: HUDButton.height).priority(.defaultHigh),
|
||||
])
|
||||
|
||||
viewModel.mediaPreviewImageViewControllerDelegate = self
|
||||
|
@ -94,7 +65,7 @@ extension MediaPreviewViewController {
|
|||
pagingViewController.delegate = self
|
||||
pagingViewController.dataSource = viewModel
|
||||
|
||||
closeButton.addTarget(self, action: #selector(MediaPreviewViewController.closeButtonPressed(_:)), for: .touchUpInside)
|
||||
closeButton.button.addTarget(self, action: #selector(MediaPreviewViewController.closeButtonPressed(_:)), for: .touchUpInside)
|
||||
|
||||
// bind view model
|
||||
viewModel.$currentPage
|
||||
|
@ -126,7 +97,7 @@ extension MediaPreviewViewController {
|
|||
let attachment = previewContext.attachments[index]
|
||||
return attachment.kind == .video // not hide buttno for audio
|
||||
}()
|
||||
self.closeButtonBackground.isHidden = needsHideCloseButton
|
||||
self.closeButton.isHidden = needsHideCloseButton
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
@ -139,7 +110,7 @@ extension MediaPreviewViewController {
|
|||
.sink { [weak self] showingChrome in
|
||||
UIView.animate(withDuration: 0.3) {
|
||||
self?.setNeedsStatusBarAppearanceUpdate()
|
||||
self?.closeButtonBackground.alpha = showingChrome ? 1 : 0
|
||||
self?.closeButton.alpha = showingChrome ? 1 : 0
|
||||
}
|
||||
}
|
||||
.store(in: &disposeBag)
|
||||
|
|
|
@ -81,7 +81,7 @@ extension MediaHostToMediaPreviewViewControllerAnimatedTransitioning {
|
|||
transitionItem.transitionView = transitionImageView
|
||||
transitionContext.containerView.addSubview(transitionImageView)
|
||||
|
||||
toVC.closeButtonBackground.alpha = 0
|
||||
toVC.closeButton.alpha = 0
|
||||
|
||||
if UIAccessibility.isReduceTransparencyEnabled {
|
||||
toVC.visualEffectView.alpha = 0
|
||||
|
@ -101,7 +101,7 @@ extension MediaHostToMediaPreviewViewControllerAnimatedTransitioning {
|
|||
toVC.pagingViewController.view.alpha = 1
|
||||
transitionImageView.removeFromSuperview()
|
||||
UIView.animate(withDuration: 0.33, delay: 0, options: [.curveEaseInOut]) {
|
||||
toVC.closeButtonBackground.alpha = 1
|
||||
toVC.closeButton.alpha = 1
|
||||
}
|
||||
transitionContext.completeTransition(position == .end)
|
||||
}
|
||||
|
@ -140,11 +140,11 @@ extension MediaHostToMediaPreviewViewControllerAnimatedTransitioning {
|
|||
|
||||
// update close button
|
||||
UIView.animate(withDuration: 0.33, delay: 0, options: [.curveEaseInOut]) {
|
||||
fromVC.closeButtonBackground.alpha = 0
|
||||
fromVC.closeButton.alpha = 0
|
||||
}
|
||||
animator.addCompletion { position in
|
||||
UIView.animate(withDuration: 0.33, delay: 0, options: [.curveEaseInOut]) {
|
||||
fromVC.closeButtonBackground.alpha = position == .end ? 0 : 1
|
||||
fromVC.closeButton.alpha = position == .end ? 0 : 1
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -202,7 +202,7 @@ extension MediaHostToMediaPreviewViewControllerAnimatedTransitioning {
|
|||
mediaPreviewTransitionContext.snapshot.contentMode = .scaleAspectFill
|
||||
mediaPreviewTransitionContext.snapshot.clipsToBounds = true
|
||||
transitionMaskView.addSubview(mediaPreviewTransitionContext.snapshot)
|
||||
fromVC.view.bringSubviewToFront(fromVC.closeButtonBackground)
|
||||
fromVC.view.bringSubviewToFront(fromVC.closeButton)
|
||||
|
||||
transitionItem.transitionView = mediaPreviewTransitionContext.transitionView
|
||||
transitionItem.snapshotTransitioning = mediaPreviewTransitionContext.snapshot
|
||||
|
|
Loading…
Reference in New Issue