From 565d17970fa22587db7e4e49a4630c8d389a23f7 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Tue, 13 Dec 2022 13:57:42 -0500 Subject: [PATCH] Make attachment description scrollable beyond a certain height Closes #168 --- .../LargeImageViewController.swift | 36 +++++++++++++++---- .../Large Image/LargeImageViewController.xib | 36 ++++++++----------- 2 files changed, 43 insertions(+), 29 deletions(-) diff --git a/Tusker/Screens/Large Image/LargeImageViewController.swift b/Tusker/Screens/Large Image/LargeImageViewController.swift index 66d206b0..428b7442 100644 --- a/Tusker/Screens/Large Image/LargeImageViewController.swift +++ b/Tusker/Screens/Large Image/LargeImageViewController.swift @@ -17,8 +17,7 @@ class LargeImageViewController: UIViewController, UIScrollViewDelegate, LargeIma @IBOutlet weak var scrollView: UIScrollView! @IBOutlet weak var topControlsView: UIView! - @IBOutlet weak var bottomControlsView: UIView! - @IBOutlet weak var descriptionLabel: UILabel! + @IBOutlet weak var descriptionTextView: UITextView! private var shareContainer: UIView! private var closeContainer: UIView! @@ -47,6 +46,7 @@ class LargeImageViewController: UIViewController, UIScrollViewDelegate, LargeIma } var shrinkGestureEnabled = true + private var isInitialAppearance = true private var prevZoomScale: CGFloat? private var isGrayscale = false private var contentViewSizeObservation: NSKeyValueObservation? @@ -99,9 +99,14 @@ class LargeImageViewController: UIViewController, UIScrollViewDelegate, LargeIma if let imageDescription = imageDescription, !imageDescription.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty { - descriptionLabel.text = imageDescription.trimmingCharacters(in: .whitespacesAndNewlines) + descriptionTextView.text = imageDescription.trimmingCharacters(in: .whitespacesAndNewlines) + descriptionTextView.textContainerInset = UIEdgeInsets(top: 8, left: 8, bottom: 8, right: 8) + // i'm not sure why .automatic doesn't work for this + descriptionTextView.contentInsetAdjustmentBehavior = .always + let height = min(150, descriptionTextView.contentSize.height) + descriptionTextView.topAnchor.constraint(equalTo: descriptionTextView.safeAreaLayoutGuide.bottomAnchor, constant: -(height + 16)).isActive = true } else { - bottomControlsView.isHidden = true + descriptionTextView.isHidden = true } if shrinkGestureEnabled { @@ -121,7 +126,7 @@ class LargeImageViewController: UIViewController, UIScrollViewDelegate, LargeIma accessibilityElements = [ topControlsView!, contentView, - bottomControlsView!, + descriptionTextView!, ] } @@ -243,6 +248,20 @@ class LargeImageViewController: UIViewController, UIScrollViewDelegate, LargeIma } } + override func viewDidAppear(_ animated: Bool) { + super.viewDidAppear(animated) + + // on the first appearance, the text view flashes its own scroll indicators automatically + // so we only need to do it on subsequent appearances + if isInitialAppearance { + isInitialAppearance = false + } else { + if animated && controlsVisible && !descriptionTextView.isHidden { + descriptionTextView.flashScrollIndicators() + } + } + } + @objc private func preferencesChanged() { if isGrayscale != Preferences.shared.grayscaleImages { isGrayscale = Preferences.shared.grayscaleImages @@ -257,6 +276,9 @@ class LargeImageViewController: UIViewController, UIScrollViewDelegate, LargeIma self.contentView.setControlsVisible(controlsVisible) self.updateControlsView() } + if controlsVisible && !descriptionTextView.isHidden { + descriptionTextView.flashScrollIndicators() + } } else { updateControlsView() } @@ -266,8 +288,8 @@ class LargeImageViewController: UIViewController, UIScrollViewDelegate, LargeIma let topOffset = self.controlsVisible ? 0 : -self.topControlsView.bounds.height self.topControlsView.transform = CGAffineTransform(translationX: 0, y: topOffset) if self.imageDescription != nil { - let bottomOffset = self.controlsVisible ? 0 : self.bottomControlsView.bounds.height + self.view.safeAreaInsets.bottom - self.bottomControlsView.transform = CGAffineTransform(translationX: 0, y: bottomOffset) + let bottomOffset = self.controlsVisible ? 0 : self.descriptionTextView.bounds.height + self.view.safeAreaInsets.bottom + self.descriptionTextView.transform = CGAffineTransform(translationX: 0, y: bottomOffset) } } diff --git a/Tusker/Screens/Large Image/LargeImageViewController.xib b/Tusker/Screens/Large Image/LargeImageViewController.xib index 2bdfd34b..3f0506e7 100644 --- a/Tusker/Screens/Large Image/LargeImageViewController.xib +++ b/Tusker/Screens/Large Image/LargeImageViewController.xib @@ -10,8 +10,7 @@ - - + @@ -29,41 +28,34 @@ - - - - - - + + + - - - - + - + Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Nam liber te conscient to factor tum poen legum odioque civiuda. + + + + - - + + - + - +