Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reader: Simplify cover presentation in post details #23895

Closed
wants to merge 8 commits into from
Closed
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 @@ -481,20 +481,9 @@ class ReaderDetailCoordinator {

/// Show the featured image fullscreen
///
private func showFeaturedImage(_ sender: CachedAnimatedImageView) {
guard let post else {
return
}

var controller: WPImageViewController
if post.featuredImageURL.isGif, let data = sender.animatedGifData {
controller = WPImageViewController(gifData: data)
} else if let featuredImage = sender.image {
controller = WPImageViewController(image: featuredImage)
} else {
return
}

private func showFeaturedImage() {
guard let post, let imageURL = post.featuredImage.flatMap(URL.init) else { return }
let controller = WPImageViewController(url: imageURL)
controller.modalTransitionStyle = .crossDissolve
controller.modalPresentationStyle = .fullScreen
viewController?.present(controller, animated: true)
Expand Down Expand Up @@ -686,7 +675,6 @@ class ReaderDetailCoordinator {
}
}

// MARK: - ReaderDetailHeaderViewDelegate
extension ReaderDetailCoordinator: ReaderDetailHeaderViewDelegate {
func didTapBlogName() {
previewSite()
Expand Down Expand Up @@ -718,23 +706,18 @@ extension ReaderDetailCoordinator: ReaderDetailHeaderViewDelegate {
}
ReaderCommentAction().execute(post: post, origin: viewController, source: .postDetails)
}
}

// MARK: - ReaderDetailFeaturedImageViewDelegate
extension ReaderDetailCoordinator: ReaderDetailFeaturedImageViewDelegate {
func didTapFeaturedImage(_ sender: CachedAnimatedImageView) {
showFeaturedImage(sender)
func didTapFeaturedImage() {
showFeaturedImage()
}
}

// MARK: - ReaderDetailLikesViewDelegate
extension ReaderDetailCoordinator: ReaderDetailLikesViewDelegate {
func didTapLikesView() {
showLikesList()
}
}

// MARK: - ReaderDetailToolbarDelegate
extension ReaderDetailCoordinator: ReaderDetailToolbarDelegate {
func didTapLikeButton(isLiked: Bool) {
guard let userAvatarURL = try? WPAccount.lookupDefaultWordPressComAccount(in: ContextManager.shared.mainContext)?.avatarURL else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,7 @@ class ReaderDetailViewController: UIViewController, ReaderDetailView {

private let activityIndicator = UIActivityIndicatorView(style: .medium)

/// The actual header
private let featuredImage: ReaderDetailFeaturedImageView = .loadFromNib()

/// The actual header
private lazy var header: ReaderDetailNewHeaderViewHost = {
return .init()
}()
private lazy var header = ReaderDetailHeaderHostingView()

/// Bottom toolbar
private let toolbar: ReaderDetailToolbar = .loadFromNib()
Expand Down Expand Up @@ -127,12 +121,6 @@ class ReaderDetailViewController: UIViewController, ReaderDetailView {
}
}

var currentPreferredStatusBarStyle = UIStatusBarStyle.lightContent {
didSet {
setNeedsStatusBarAppearanceUpdate()
}
}

override var hidesBottomBarWhenPushed: Bool {
set { }
get { true }
Expand All @@ -141,17 +129,6 @@ class ReaderDetailViewController: UIViewController, ReaderDetailView {
/// Tracks whether the webview has called -didFinish:navigation
var isLoadingWebView = true

/// Temporary work around until white headers are shipped app-wide,
/// allowing Reader Detail to use a blue navbar.
var useCompatibilityMode: Bool {
// This enables ALL Reader Detail screens to use a transparent navigation bar style,
// so that the display settings can be applied correctly.
//
// Plus, it looks like we don't have screens with a blue (legacy) navigation bar anymore,
// so it may be a good chance to clean up and remove `useCompatibilityMode`.
!ReaderDisplaySetting.customizationEnabled
}

/// Used to disable ineffective buttons when a Related post fails to load.
var enableRightBarButtons = true

Expand All @@ -178,7 +155,6 @@ class ReaderDetailViewController: UIViewController, ReaderDetailView {
configureNavigationBar()
applyStyles()
configureWebView()
configureFeaturedImage()
configureHeader()
configureRelatedPosts()
configureToolbar()
Expand All @@ -200,8 +176,8 @@ class ReaderDetailViewController: UIViewController, ReaderDetailView {

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)

updateLeftBarButtonItem()
setupFeaturedImage()
updateFollowButtonState()
toolbar.viewWillAppear()
}
Expand All @@ -213,18 +189,9 @@ class ReaderDetailViewController: UIViewController, ReaderDetailView {
return
}

featuredImage.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()
})
}

override func accessibilityPerformEscape() -> Bool {
navigationController?.popViewController(animated: true)
return true
Expand All @@ -233,7 +200,6 @@ class ReaderDetailViewController: UIViewController, ReaderDetailView {
func render(_ post: ReaderPost) {
configureDiscoverAttribution(post)

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

guard !featuredImage.isLoaded else {
return
}

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

navigateToCommentIfNecessary()
}

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

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

Expand Down Expand Up @@ -479,9 +436,6 @@ class ReaderDetailViewController: UIViewController, ReaderDetailView {
toolbarSafeAreaView.backgroundColor = toolbar.backgroundColor
}

// Featured image view
featuredImage.displaySetting = displaySetting

// Update Reader Post web view
if let contentForDisplay = post?.contentForDisplay() {
webView.displaySetting = displaySetting
Expand Down Expand Up @@ -534,55 +488,8 @@ class ReaderDetailViewController: UIViewController, ReaderDetailView {
}
}

private func setupFeaturedImage() {
configureFeaturedImage()

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

guard !featuredImage.isLoaded else {
return
}

// Load the image
featuredImage.load { [weak self] in
guard let self else {
return
}
self.hideLoading()
}
}

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

if ReaderDisplaySetting.customizationEnabled {
featuredImage.displaySetting = displaySetting
}

featuredImage.useCompatibilityMode = useCompatibilityMode

featuredImage.delegate = coordinator

view.insertSubview(featuredImage, 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)
])

headerContainerView.translatesAutoresizingMaskIntoConstraints = false
}

private func configureHeader() {
header.displaySetting = displaySetting
header.useCompatibilityMode = useCompatibilityMode
header.delegate = coordinator
headerContainerView.addSubview(header)
headerContainerView.translatesAutoresizingMaskIntoConstraints = false
Expand Down Expand Up @@ -961,17 +868,6 @@ extension ReaderDetailViewController: ReaderCardDiscoverAttributionViewDelegate
}
}

// MARK: - UpdatableStatusBarStyle
extension ReaderDetailViewController: UpdatableStatusBarStyle {
func updateStatusBarStyle(to style: UIStatusBarStyle) {
guard style != currentPreferredStatusBarStyle else {
return
}

currentPreferredStatusBarStyle = style
}
}

// MARK: - Transitioning Delegate

extension ReaderDetailViewController: UIViewControllerTransitioningDelegate {
Expand Down
Loading