diff --git a/Tusker/Screens/Large Image/LargeImageViewController.swift b/Tusker/Screens/Large Image/LargeImageViewController.swift index 1397a069..45ae7728 100644 --- a/Tusker/Screens/Large Image/LargeImageViewController.swift +++ b/Tusker/Screens/Large Image/LargeImageViewController.swift @@ -17,17 +17,16 @@ class LargeImageViewController: UIViewController, UIScrollViewDelegate, LargeIma @IBOutlet weak var scrollView: UIScrollView! @IBOutlet weak var topControlsView: UIView! - @IBOutlet weak var topControlsHeightConstraint: NSLayoutConstraint! - @IBOutlet weak var shareButton: UIButton! - @IBOutlet weak var shareButtonTopConstraint: NSLayoutConstraint! - @IBOutlet weak var shareButtonLeadingConstraint: NSLayoutConstraint! - @IBOutlet weak var closeButton: UIButton! - @IBOutlet weak var closeButtonTopConstraint: NSLayoutConstraint! - @IBOutlet weak var closeButtonTrailingConstraint: NSLayoutConstraint! - @IBOutlet weak var bottomControlsView: UIView! @IBOutlet weak var descriptionLabel: UILabel! + private var shareContainer: UIView! + private var shareImage: UIImageView! + private var shareButtonTopConstraint: NSLayoutConstraint! + private var shareButtonLeadingConstraint: NSLayoutConstraint! + private var closeButtonTopConstraint: NSLayoutConstraint! + private var closeButtonTrailingConstraint: NSLayoutConstraint! + var contentView: LargeImageContentView { didSet { oldValue.removeFromSuperview() @@ -86,9 +85,13 @@ class LargeImageViewController: UIViewController, UIScrollViewDelegate, LargeIma super.viewDidLoad() setupContentView() - + setupControls() + setControlsVisible(initialControlsVisible, animated: false) - shareButton.isEnabled = !contentView.activityItemsForSharing.isEmpty + if contentView.activityItemsForSharing.isEmpty { + shareContainer.isUserInteractionEnabled = false + shareImage.tintColor = .systemGray + } scrollView.delegate = self @@ -125,6 +128,62 @@ class LargeImageViewController: UIViewController, UIScrollViewDelegate, LargeIma contentViewTopConstraint, ]) } + + private func setupControls() { + shareContainer = UIView() + shareContainer.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(sharePressed))) + shareContainer.translatesAutoresizingMaskIntoConstraints = false + topControlsView.addSubview(shareContainer) + shareImage = UIImageView(image: UIImage(systemName: "square.and.arrow.up")) + shareImage.tintColor = .white + shareImage.contentMode = .scaleAspectFit + shareImage.translatesAutoresizingMaskIntoConstraints = false + shareContainer.addSubview(shareImage) + shareButtonTopConstraint = shareImage.topAnchor.constraint(greaterThanOrEqualTo: shareContainer.topAnchor) + shareButtonLeadingConstraint = shareImage.leadingAnchor.constraint(greaterThanOrEqualTo: shareContainer.leadingAnchor) + NSLayoutConstraint.activate([ + shareContainer.topAnchor.constraint(equalTo: topControlsView.topAnchor), + shareContainer.leadingAnchor.constraint(equalTo: topControlsView.leadingAnchor), + shareContainer.bottomAnchor.constraint(equalTo: topControlsView.bottomAnchor), + shareContainer.widthAnchor.constraint(greaterThanOrEqualToConstant: 50), + shareContainer.heightAnchor.constraint(greaterThanOrEqualToConstant: 50), + + shareImage.centerXAnchor.constraint(equalTo: shareContainer.centerXAnchor), + shareImage.centerYAnchor.constraint(equalTo: shareContainer.centerYAnchor), + shareButtonTopConstraint, + shareButtonLeadingConstraint, + + shareImage.widthAnchor.constraint(equalToConstant: 24), + shareImage.heightAnchor.constraint(equalToConstant: 24), + ]) + + let closeContainer = UIView() + closeContainer.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(closeButtonPressed))) + closeContainer.translatesAutoresizingMaskIntoConstraints = false + topControlsView.addSubview(closeContainer) + let closeImage = UIImageView(image: UIImage(systemName: "xmark")) + closeImage.tintColor = .white + closeImage.contentMode = .scaleAspectFit + closeImage.translatesAutoresizingMaskIntoConstraints = false + closeContainer.addSubview(closeImage) + closeButtonTopConstraint = closeImage.topAnchor.constraint(greaterThanOrEqualTo: closeContainer.topAnchor) + closeButtonTrailingConstraint = closeContainer.trailingAnchor.constraint(greaterThanOrEqualTo: closeImage.trailingAnchor) + NSLayoutConstraint.activate([ + closeContainer.topAnchor.constraint(equalTo: topControlsView.topAnchor), + closeContainer.trailingAnchor.constraint(equalTo: topControlsView.trailingAnchor), + closeContainer.bottomAnchor.constraint(equalTo: closeContainer.bottomAnchor), + closeContainer.widthAnchor.constraint(greaterThanOrEqualToConstant: 50), + closeContainer.heightAnchor.constraint(greaterThanOrEqualToConstant: 50), + + closeImage.centerXAnchor.constraint(equalTo: closeContainer.centerXAnchor), + closeImage.centerYAnchor.constraint(equalTo: closeContainer.centerYAnchor), + closeButtonTopConstraint, + closeButtonTrailingConstraint, + + closeImage.widthAnchor.constraint(equalToConstant: 24), + closeImage.heightAnchor.constraint(equalToConstant: 24), + ]) + } override func viewDidLayoutSubviews() { super.viewDidLayoutSubviews() @@ -156,7 +215,7 @@ class LargeImageViewController: UIViewController, UIScrollViewDelegate, LargeIma // since the corner radius didn't change let notchWidth: CGFloat = 210 let earWidth = (view.bounds.width - notchWidth) / 2 - let offset = (earWidth - shareButton.bounds.width) / 2 + let offset = (earWidth - shareImage.bounds.width) / 2 shareButtonLeadingConstraint.constant = offset closeButtonTrailingConstraint.constant = offset } else if pillDeviceTopInsets.contains(view.safeAreaInsets.top) { @@ -275,7 +334,7 @@ class LargeImageViewController: UIViewController, UIScrollViewDelegate, LargeIma @IBAction func sharePressed(_ sender: Any) { let activityVC = UIActivityViewController(activityItems: contentView.activityItemsForSharing, applicationActivities: nil) - activityVC.popoverPresentationController?.sourceView = shareButton + activityVC.popoverPresentationController?.sourceView = shareImage present(activityVC, animated: true) } diff --git a/Tusker/Screens/Large Image/LargeImageViewController.xib b/Tusker/Screens/Large Image/LargeImageViewController.xib index 7c1eb9e7..2bdfd34b 100644 --- a/Tusker/Screens/Large Image/LargeImageViewController.xib +++ b/Tusker/Screens/Large Image/LargeImageViewController.xib @@ -11,15 +11,8 @@ - - - - - - - @@ -33,45 +26,8 @@ - + - - - - - - - - - - - - - @@ -110,8 +66,4 @@ - - - -