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

Allow tapping diff header title to visit associated page #4677

Merged
merged 2 commits into from
Nov 29, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 13 additions & 1 deletion Wikipedia/Code/DiffContainerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,7 @@ private extension DiffContainerViewController {
default:
break
}
diffHeaderView?.configure(with: headerViewModel)
diffHeaderView?.configure(with: headerViewModel, titleViewTapDelegate: self)
headerExtendedView?.update(headerViewModel)
navigationBar.isExtendedViewHidingEnabled = headerViewModel.isExtendedViewHidingEnabled
}
Expand Down Expand Up @@ -1507,3 +1507,15 @@ extension DiffContainerViewController: WatchlistControllerDelegate {
diffToolbarView?.updateMoreButton(needsWatchButton: true, needsUnwatchHalfButton: false, needsUnwatchFullButton: false, needsArticleEditHistoryButton: true)
}
}

extension DiffContainerViewController: DiffHeaderTitleViewTapDelegate {

func userDidTapTitleLabel() {
guard let navigationURL = fetchPageURL() else {
return
}

navigate(to: navigationURL)
}

}
33 changes: 27 additions & 6 deletions Wikipedia/Code/DiffHeaderTitleView.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import UIKit

protocol DiffHeaderTitleViewTapDelegate: AnyObject {
func userDidTapTitleLabel()
}

class DiffHeaderTitleView: UIView {

@IBOutlet var contentView: UIView!
@IBOutlet var headingLabel: UILabel!
@IBOutlet var titleLabel: UILabel!
@IBOutlet var subtitleLabel: UILabel!


weak var titleViewTapDelegate: DiffHeaderTitleViewTapDelegate?

private(set) var viewModel: DiffHeaderTitleViewModel?

override init(frame: CGRect) {
Expand All @@ -27,10 +33,11 @@ class DiffHeaderTitleView: UIView {
}
}

func update(_ viewModel: DiffHeaderTitleViewModel) {
func update(_ viewModel: DiffHeaderTitleViewModel, titleViewTapDelegate: DiffHeaderTitleViewTapDelegate? = nil) {

self.viewModel = viewModel

self.titleViewTapDelegate = titleViewTapDelegate

headingLabel.text = viewModel.heading
titleLabel.text = viewModel.title

Expand All @@ -54,6 +61,12 @@ class DiffHeaderTitleView: UIView {
guard !UIAccessibility.isVoiceOverRunning else {
return super.point(inside: point, with: event)
}

let titleConverted = convert(point, to: titleLabel)
if titleLabel.point(inside: titleConverted, with: event) {
return true
}

return false
}
}
Expand All @@ -66,6 +79,10 @@ private extension DiffHeaderTitleView {
contentView.autoresizingMask = [.flexibleHeight, .flexibleWidth]
updateFonts(with: traitCollection)
contentView.isAccessibilityElement = true

let tapGesture = UITapGestureRecognizer(target: self, action: #selector(userDidTapTitleLabel))
titleLabel.isUserInteractionEnabled = true
titleLabel.addGestureRecognizer(tapGesture)
}

func updateFonts(with traitCollection: UITraitCollection) {
Expand All @@ -77,6 +94,10 @@ private extension DiffHeaderTitleView {
subtitleLabel.font = UIFont.wmf_font(DynamicTextStyle.footnote, compatibleWithTraitCollection: traitCollection)
}
}

@objc func userDidTapTitleLabel() {
titleViewTapDelegate?.userDidTapTitleLabel()
}
}

extension DiffHeaderTitleView: Themeable {
Expand All @@ -85,8 +106,8 @@ extension DiffHeaderTitleView: Themeable {
backgroundColor = theme.colors.paperBackground
contentView.backgroundColor = theme.colors.paperBackground
headingLabel.textColor = theme.colors.secondaryText
titleLabel.textColor = theme.colors.primaryText
titleLabel.textColor = theme.colors.link

if let subtitleColor = viewModel?.subtitleColor {
subtitleLabel.textColor = subtitleColor
} else {
Expand Down
14 changes: 10 additions & 4 deletions Wikipedia/Code/DiffHeaderView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ final class DiffHeaderView: SetupView {

}

func configure(with vm: DiffHeaderViewModel) {
func configure(with vm: DiffHeaderViewModel, titleViewTapDelegate: DiffHeaderTitleViewTapDelegate? = nil) {
self.viewModel = vm
if let viewModel {
updateTitleView(with: viewModel.title)
updateTitleView(with: viewModel.title, titleViewTapDelegate: titleViewTapDelegate)
updateImageView(with: viewModel)
}
}
Expand All @@ -77,14 +77,20 @@ final class DiffHeaderView: SetupView {
}
}

func updateTitleView(with viewModel: DiffHeaderTitleViewModel) {
headerTitleView.update(viewModel)
func updateTitleView(with viewModel: DiffHeaderTitleViewModel, titleViewTapDelegate: DiffHeaderTitleViewTapDelegate? = nil) {
headerTitleView.update(viewModel, titleViewTapDelegate: titleViewTapDelegate)
}

override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
guard !UIAccessibility.isVoiceOverRunning else {
return super.point(inside: point, with: event)
}

let headerTitleViewConvertedPoint = convert(point, to: headerTitleView)
if headerTitleView.point(inside: headerTitleViewConvertedPoint, with: event) {
return true
}

return false
}

Expand Down