Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class ReaderDetailViewController: UIViewController, ReaderDetailView {
private let activityIndicator = UIActivityIndicatorView(style: .medium)

/// The actual header
private let featuredImage = ReaderDetailFeaturedImageView()
private let featuredImageView = ReaderDetailFeaturedImageView()

/// The actual header
private lazy var header: ReaderDetailHeaderHostingView = {
Expand Down Expand Up @@ -202,15 +202,15 @@ class ReaderDetailViewController: UIViewController, ReaderDetailView {
return
}

featuredImage.viewWillDisappear()
featuredImageView.viewWillDisappear()
toolbar.viewWillDisappear()
}

override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator)

coordinator.animate(alongsideTransition: { _ in
self.featuredImage.deviceDidRotate()
self.featuredImageView.deviceDidRotate()
})
}

Expand All @@ -222,7 +222,7 @@ class ReaderDetailViewController: UIViewController, ReaderDetailView {
func render(_ post: ReaderPost) {
configureDiscoverAttribution(post)

featuredImage.configure(for: post, with: self)
featuredImageView.configure(for: post, with: self)
toolbar.configure(for: post, in: self)
header.configure(for: post)
fetchLikes()
Expand All @@ -245,12 +245,12 @@ class ReaderDetailViewController: UIViewController, ReaderDetailView {
self?.webView.loadHTMLString(post.contentForDisplay())
}

guard !featuredImage.isLoaded else {
guard !featuredImageView.isLoaded else {
return
}

// Load the image
featuredImage.load { [weak self] in
featuredImageView.load { [weak self] in
self?.hideLoading()
}

Expand Down Expand Up @@ -301,7 +301,7 @@ class ReaderDetailViewController: UIViewController, ReaderDetailView {
}

func hideLoading() {
guard !featuredImage.isLoading, !isLoadingWebView else {
guard !featuredImageView.isLoading, !isLoadingWebView else {
return
}

Expand Down Expand Up @@ -448,7 +448,7 @@ class ReaderDetailViewController: UIViewController, ReaderDetailView {
}

// Featured image view
featuredImage.displaySetting = displaySetting
featuredImageView.displaySetting = displaySetting

// Update Reader Post web view
if let contentForDisplay = post?.contentForDisplay() {
Expand Down Expand Up @@ -507,18 +507,18 @@ class ReaderDetailViewController: UIViewController, ReaderDetailView {
private func setupFeaturedImage() {
configureFeaturedImage()

featuredImage.configure(
featuredImageView.configure(
scrollView: scrollView,
navigationBar: navigationController?.navigationBar,
navigationItem: navigationItem
)

guard !featuredImage.isLoaded else {
guard !featuredImageView.isLoaded else {
return
}

// Load the image
featuredImage.load { [weak self] in
featuredImageView.load { [weak self] in
guard let self else {
return
}
Expand All @@ -527,24 +527,24 @@ class ReaderDetailViewController: UIViewController, ReaderDetailView {
}

private func configureFeaturedImage() {
guard featuredImage.superview == nil else {
guard featuredImageView.superview == nil else {
return
}

if ReaderDisplaySetting.customizationEnabled {
featuredImage.displaySetting = displaySetting
featuredImageView.displaySetting = displaySetting
}

featuredImage.useCompatibilityMode = useCompatibilityMode
featuredImageView.useCompatibilityMode = useCompatibilityMode

featuredImage.delegate = coordinator
featuredImageView.delegate = coordinator

view.insertSubview(featuredImage, belowSubview: webView)
view.insertSubview(featuredImageView, belowSubview: webView)

NSLayoutConstraint.activate([
featuredImage.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 0),
featuredImage.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: 0),
featuredImage.topAnchor.constraint(equalTo: view.topAnchor, constant: 0)
featuredImageView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 0),
featuredImageView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: 0),
featuredImageView.topAnchor.constraint(equalTo: view.topAnchor, constant: 0)
])

headerContainerView.translatesAutoresizingMaskIntoConstraints = false
Expand Down Expand Up @@ -812,8 +812,6 @@ class ReaderDetailViewController: UIViewController, ReaderDetailView {

extension ReaderDetailViewController: UIScrollViewDelegate {
func scrollViewDidScroll(_ scrollView: UIScrollView) {
guard traitCollection.horizontalSizeClass == .compact else { return }

let currentOffset = scrollView.contentOffset.y
// Using `safeAreaLayoutGuide.layoutFrame.height` because it doesn't
// change when we extend the scroll view size by hiding the toolbar
Expand Down Expand Up @@ -1143,17 +1141,6 @@ private extension ReaderDetailViewController {
let image = image.withRenderingMode(.alwaysTemplate)
return UIBarButtonItem(image: image, style: .plain, target: self, action: action)
}

/// Checks if the view is visible in the viewport.
func isVisibleInScrollView(_ view: UIView) -> Bool {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused code.

guard view.superview != nil, !view.isHidden else {
return false
}

let scrollViewFrame = CGRect(origin: scrollView.contentOffset, size: scrollView.frame.size)
let convertedViewFrame = scrollView.convert(view.bounds, from: view)
return scrollViewFrame.intersects(convertedViewFrame)
}
}

// MARK: - NoResultsViewControllerDelegate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,11 @@ final class ReaderDetailFeaturedImageView: UIView {
imageView.pinEdges()

addSubview(gradientView)
gradientView.heightAnchor.constraint(equalToConstant: 120).isActive = true
gradientView.pinEdges([.top, .horizontal])
NSLayoutConstraint.activate([
gradientView.heightAnchor.constraint(equalToConstant: 120).withPriority(999),
gradientView.bottomAnchor.constraint(lessThanOrEqualTo: bottomAnchor) // Make sure it collapses
])

isUserInteractionEnabled = false

Expand Down