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

Title stack #395

Merged
merged 5 commits into from
Aug 19, 2024
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 @@ -53,7 +53,7 @@ class UICatalogSectionTitleViewController: UITableViewController {
tableView.sectionFooterHeight = 0.0

tableView.register(ListTableViewCell.self, forCellReuseIdentifier: Constants.listCellReusableIdentifier)
tableView.register(TitleView.self, forHeaderFooterViewReuseIdentifier: Constants.sectionTitleReusableIdentifier)
tableView.register(TitleHeaderFooterView.self, forHeaderFooterViewReuseIdentifier: Constants.sectionTitleReusableIdentifier)
}

override func numberOfSections(in _: UITableView) -> Int {
Expand All @@ -74,11 +74,14 @@ class UICatalogSectionTitleViewController: UITableViewController {
}

override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let headerView = tableView.dequeueReusableHeaderFooterView(withIdentifier: Constants.sectionTitleReusableIdentifier) as! TitleView
let headerView = tableView.dequeueReusableHeaderFooterView(withIdentifier: Constants.sectionTitleReusableIdentifier) as! TitleHeaderFooterView
let style = Constants.styles[section]
headerView.title = style.title
headerView.style = style.titleStyle
headerView.linkTitle = style.linkTitle
headerView.onLinkLabelTapped = {
print("onLinkLabelTapped")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

just to verify it's not broken

}
return headerView
}
}
91 changes: 91 additions & 0 deletions Sources/Mistica/Components/Title/TitleHeaderFooterView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
//
// TitleHeaderFooterView.swift
//
// Made with ❀️ by Novum
//
// Copyright Β© Telefonica. All rights reserved.
//

import UIKit

public class TitleHeaderFooterView: UITableViewHeaderFooterView {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

the original component. It inherits from UITableViewHeaderFooterView but we need a UIView.
We expose this TitleHeaderFooterView which is a wrap of a TitleView inheriting from UITableViewHeaderFooterView

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I know it's a breaking change but I think it should be....
Do you prefer keeping TitleView and call the internal view something like... TitleStack?? IMO it's worse but let me know.
I found occurrences in SmartWifi and iphoneapp, but it should be super easy to resolve them.

Copy link
Contributor

Choose a reason for hiding this comment

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

IMHO I prefer the breaking change and fix in the project, should be no problem

Copy link
Contributor

Choose a reason for hiding this comment

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

I rather prefer the breaking change too.This won't be to difficult to update.

public typealias Style = TitleView.Style

private lazy var titleView = TitleView()

public var onLinkLabelTapped: (() -> Void)? {
Copy link
Contributor

Choose a reason for hiding this comment

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

the get first and more consise version :

    public var onLinkLabelTapped: (() -> Void)? {
        get {  titleView.onLinkLabelTapped }
        set {  titleView.onLinkLabelTapped = newValue }
    }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done! thx!

get {
titleView.onLinkLabelTapped
}
set {
titleView.onLinkLabelTapped = newValue
}
}

public var style: Style {
set {
titleView.style = newValue
}
get {
titleView.style
}
}

public var title: String? {
get {
titleView.title
}
set {
titleView.title = newValue
}
}

public var linkTitle: String? {
get {
titleView.linkTitle
}
set {
titleView.linkTitle = newValue
}
}

override public init(reuseIdentifier: String?) {
super.init(reuseIdentifier: reuseIdentifier)

commonInit()
}

public required init?(coder: NSCoder) {
super.init(coder: coder)

commonInit()
}

public init(style: Style, reuseIdentifier: String? = nil) {
super.init(reuseIdentifier: reuseIdentifier)
self.style = style

commonInit()
}
}

// MARK: - Accessibility

public extension TitleHeaderFooterView {
var titleAccessibilityTraits: UIAccessibilityTraits {
get {
titleView.accessibilityTraits
}
set {
titleView.accessibilityTraits = newValue
}
}
}

// MARK: - Private methods

private extension TitleHeaderFooterView {
func commonInit() {
contentView.addSubview(withDefaultConstraints: titleView)
}
}
21 changes: 7 additions & 14 deletions Sources/Mistica/Components/Title/TitleView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ private enum ViewStyles {
static let minimumHeight: CGFloat = 40
}

public class TitleView: UITableViewHeaderFooterView {
public class TitleView: UIView {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

what we need!

public enum Style {
case title1
case title2
Expand Down Expand Up @@ -82,8 +82,8 @@ public class TitleView: UITableViewHeaderFooterView {
}
}

override public init(reuseIdentifier: String?) {
super.init(reuseIdentifier: reuseIdentifier)
override public init(frame: CGRect) {
super.init(frame: frame)

commonInit()
}
Expand All @@ -93,13 +93,6 @@ public class TitleView: UITableViewHeaderFooterView {

commonInit()
}

public init(style: Style, reuseIdentifier: String? = nil) {
super.init(reuseIdentifier: reuseIdentifier)
self.style = style

commonInit()
}
}

// MARK: - Accessibility
Expand All @@ -124,7 +117,7 @@ private extension TitleView {
}

func updateStyle() {
contentView.backgroundColor = .background
backgroundColor = .background

titleLabel.text = style.format(text: unformattedTitle)
titleLabel.font = style.font
Expand All @@ -139,6 +132,7 @@ private extension TitleView {
func layoutViews() {
linkLabel.setContentHuggingPriority(.required, for: .horizontal)
linkLabel.setContentCompressionResistancePriority(.required, for: .horizontal)
linkLabel.isUserInteractionEnabled = true
Copy link
Contributor Author

Choose a reason for hiding this comment

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

the link didn't work!!!!!!
I don't know if it's already broken in SW/iphoneapp (where it's being used)

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess that if it is working for them it is because they are using

titleView.isUserInteractionEnabled = true
titleView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(linkLabelTapped)))

directly on the TitleView instance.

linkLabel.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(linkLabelTapped)))

let stackView = UIStackView(arrangedSubviews: [
Expand All @@ -149,9 +143,8 @@ private extension TitleView {
stackView.alignment = .firstBaseline

preservesSuperviewLayoutMargins = false
contentView.preservesSuperviewLayoutMargins = false
contentView.addSubview(constrainedToLayoutMarginsGuideOf: stackView)
contentView.directionalLayoutMargins = NSDirectionalEdgeInsets(
addSubview(constrainedToLayoutMarginsGuideOf: stackView)
directionalLayoutMargins = NSDirectionalEdgeInsets(
top: ViewStyles.topMargin,
leading: ViewStyles.horizontalMargin,
bottom: ViewStyles.bottomMargin,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// TitleViewTests.swift
// TitleHeaderFooterViewTests.swift
//
// Made with ❀️ by Novum
//
Expand All @@ -10,7 +10,7 @@
import SnapshotTesting
import XCTest

final class TitleViewTests: XCTestCase {
final class TitleHeaderFooterViewTests: XCTestCase {
override func setUp() {
super.setUp()
UIView.setAnimationsEnabled(false)
Expand Down Expand Up @@ -75,18 +75,18 @@ final class TitleViewTests: XCTestCase {
}
}

private extension TitleViewTests {
func makeSectionTitle(title: String, linkTitle: String? = nil, style: TitleView.Style) -> UIViewController {
SectionTitleViewController(titleText: title, linkTitleText: linkTitle, style: style)
private extension TitleHeaderFooterViewTests {
func makeSectionTitle(title: String, linkTitle: String? = nil, style: TitleHeaderFooterView.Style) -> UIViewController {
SectionTitleHeaderFooterViewController(titleText: title, linkTitleText: linkTitle, style: style)
}
}

private class SectionTitleViewController: UITableViewController {
private class SectionTitleHeaderFooterViewController: UITableViewController {
private let titleText: String
private let linkTitleText: String?
private let style: TitleView.Style
private let style: TitleHeaderFooterView.Style

init(titleText: String, linkTitleText: String?, style: TitleView.Style) {
init(titleText: String, linkTitleText: String?, style: TitleHeaderFooterView.Style) {
self.titleText = titleText
self.linkTitleText = linkTitleText
self.style = style
Expand All @@ -106,7 +106,7 @@ private class SectionTitleViewController: UITableViewController {
tableView.tableFooterView = UIView(frame: CGRect.zero)
tableView.sectionFooterHeight = 0.0

tableView.register(TitleView.self, forHeaderFooterViewReuseIdentifier: "Header")
tableView.register(TitleHeaderFooterView.self, forHeaderFooterViewReuseIdentifier: "Header")
}

override func numberOfSections(in _: UITableView) -> Int {
Expand All @@ -122,7 +122,7 @@ private class SectionTitleViewController: UITableViewController {
}

override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let headerView = tableView.dequeueReusableHeaderFooterView(withIdentifier: "Header") as! TitleView
let headerView = tableView.dequeueReusableHeaderFooterView(withIdentifier: "Header") as! TitleHeaderFooterView
headerView.title = titleText
headerView.style = style
headerView.linkTitle = linkTitleText
Expand Down
Loading