Skip to content

Commit

Permalink
Fix ReaderDetailFeaturedImageView gradienet showing up when no image …
Browse files Browse the repository at this point in the history
…is present
  • Loading branch information
kean committed Jan 6, 2025
1 parent 40f7142 commit fe68ae3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
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
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

0 comments on commit fe68ae3

Please sign in to comment.