From 37591d0eacf63efedf46c4dbc7f90445abffb32b Mon Sep 17 00:00:00 2001 From: Stuart Breckenridge Date: Fri, 23 Jan 2026 22:24:20 +0800 Subject: [PATCH] Fix timeline customiser --- iOS/MainTimeline/Cells/MainTimelineCell.swift | 34 ++- iOS/Settings/Settings.storyboard | 237 ++++++++++-------- ...imelineCustomizerTableViewController.swift | 90 +++---- 3 files changed, 204 insertions(+), 157 deletions(-) diff --git a/iOS/MainTimeline/Cells/MainTimelineCell.swift b/iOS/MainTimeline/Cells/MainTimelineCell.swift index 8069e60e4..9b92a03f2 100644 --- a/iOS/MainTimeline/Cells/MainTimelineCell.swift +++ b/iOS/MainTimeline/Cells/MainTimelineCell.swift @@ -29,6 +29,7 @@ class MainTimelineCell: UITableViewCell { MainActor.assumeIsolated { super.awakeFromNib() indicatorView.alpha = 0.0 + feedIcon?.translatesAutoresizingMaskIntoConstraints = false configureStackView() } } @@ -50,7 +51,7 @@ class MainTimelineCell: UITableViewCell { } if feedIcon != nil { - setIconImage(cellData.iconImage) + setIconImage(cellData.iconImage, with: cellData.iconSize) } articleDate.text = cellData.dateString @@ -110,6 +111,26 @@ class MainTimelineCell: UITableViewCell { } } + private func setIconImage(_ iconImage: IconImage?, with size: IconSize) { + feedIcon!.iconImage = iconImage + updateIconViewSizeConstraints(to: size.size) + } + + private func updateIconViewSizeConstraints(to size: CGSize) { + guard feedIcon != nil else { return } + + for constraint in feedIcon!.constraints.compactMap({ $0 }) { + constraint.isActive = false + } + + NSLayoutConstraint.activate([ + feedIcon!.widthAnchor.constraint(equalToConstant: size.width), + feedIcon!.heightAnchor.constraint(equalToConstant: size.height) + ]) + + setNeedsLayout() + } + private func addArticleContent(_ state: UICellConfigurationState) { let attributedCellText = NSMutableAttributedString() @@ -170,15 +191,20 @@ class MainTimelineCell: UITableViewCell { } let linesUsed = countLines(of: attributedCellText, width: articleContent.bounds.width) + if attributedCellText.string.contains("Bree-folk") { + print("Bree-folk: \(linesUsed), \(self.feedIcon != nil)") + } if linesUsed >= cellData.numberOfLines { // The title already fills 3 lines, set it and exit articleContent.attributedText = attributedCellText articleContent.lineBreakMode = .byTruncatingTail return + } else { + articleContent.attributedText = attributedCellText + articleContent.lineBreakMode = .byWordWrapping } - articleContent.attributedText = attributedCellText - + } func titleTextColor(for state: UICellConfigurationState) -> UIColor { @@ -216,7 +242,7 @@ class MainTimelineCell: UITableViewCell { super.updateConfiguration(using: state) var backgroundConfig = UIBackgroundConfiguration.listCell().updated(for: state) - backgroundConfig.cornerRadius = traitCollection.userInterfaceIdiom == .pad ? 20 : 0 + backgroundConfig.cornerRadius = 20 if traitCollection.userInterfaceIdiom == .pad { backgroundConfig.edgesAddingLayoutMarginsToBackgroundInsets = [.leading, .trailing] backgroundConfig.backgroundInsets = NSDirectionalEdgeInsets(top: 0, leading: !isPreview ? -4 : -12, bottom: 0, trailing: !isPreview ? -4 : -12) diff --git a/iOS/Settings/Settings.storyboard b/iOS/Settings/Settings.storyboard index 3c0c5eb09..d9e9015e9 100644 --- a/iOS/Settings/Settings.storyboard +++ b/iOS/Settings/Settings.storyboard @@ -276,19 +276,19 @@ - + - + - - + - + - - + - + - - - + + + - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - + + + + + + + + + + + + + + - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -967,6 +985,9 @@ + + + diff --git a/iOS/Settings/TimelineCustomizerTableViewController.swift b/iOS/Settings/TimelineCustomizerTableViewController.swift index a5c09146b..46727b3e4 100644 --- a/iOS/Settings/TimelineCustomizerTableViewController.swift +++ b/iOS/Settings/TimelineCustomizerTableViewController.swift @@ -15,9 +15,9 @@ import Articles final class TimelineCustomizerTableViewController: UITableViewController { private var previewArticle: Article { var components = DateComponents() - components.year = 1925 - components.month = 4 - components.day = 10 + components.year = 1954 + components.month = 7 + components.day = 29 let calendar = Calendar.current let date = calendar.date(from: components)! @@ -26,9 +26,9 @@ final class TimelineCustomizerTableViewController: UITableViewController { articleID: "_testArticleID", feedID: "_testFeedID", uniqueID: UUID().uuidString, - title: "Chapter 1", + title: "At The Sign Of The Prancing Pony", contentHTML: nil, - contentText: "In my younger and more vulnerable years my father gave me some advice that I’ve been turning over in my mind ever since. “Whenever you feel like criticizing any one,” he told me, “just remember that all the people in this world haven’t had the advantages that you’ve had.”", + contentText: "Bree was the chief village of Bree-land, a small country a few miles broad whose chief claim to fame was its aluminum siding industry. The Men of Bree were cheerful and independant: they belonged to nobody but themselves. In the lands beyond Bree there were mysterious wanderers.", markdown: nil, url: nil, externalURL: nil, @@ -36,7 +36,7 @@ final class TimelineCustomizerTableViewController: UITableViewController { imageURL: nil, datePublished: date, dateModified: nil, - authors: Set([Author(authorID: "_testAuthorID", name: "F. Scott Fitzgerald", url: nil, avatarURL: nil, emailAddress: nil)!]), + authors: Set([Author(authorID: "_testAuthorID", name: "J. R. R. Tolkien", url: nil, avatarURL: nil, emailAddress: nil)!]), status: ArticleStatus(articleID: "_testArticleID", read: false, starred: false, dateArrived: .now)) } @@ -75,45 +75,45 @@ final class TimelineCustomizerTableViewController: UITableViewController { override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { -// if indexPath.section == 0 { -// let cell = tableView.dequeueReusableCell(withIdentifier: "IconSizeCell") as! ModernTimelineSliderCell -// cell.sliderConfiguration = .iconSize -// return cell -// } -// -// if indexPath.section == 1 { -// let cell = tableView.dequeueReusableCell(withIdentifier: "NumberOfLinesCell") as! ModernTimelineSliderCell -// cell.sliderConfiguration = .numberOfLines -// return cell -// } -// -// if indexPath.section == 2 { -// let cell = tableView.dequeueReusableCell(withIdentifier: "MainTimelineIconFeedCell") as? MainTimelineIconFeedCell ?? MainTimelineIconFeedCell() -// cell.cellData = MainTimelineCellData(article: previewArticle, -// showFeedName: .byline, -// feedName: "The Great Gatsby", -// byline: "F. Scott Fitzgerald", -// iconImage: IconImage(Assets.Images.nnwFeedIcon), -// showIcon: true, -// numberOfLines: AppDefaults.shared.timelineNumberOfLines, -// iconSize: AppDefaults.shared.timelineIconSize) -// cell.isPreview = true -// return cell -// } -// -// if indexPath.section == 3 { -// let cell = tableView.dequeueReusableCell(withIdentifier: "MainTimelineFeedCell") as? MainTimelineFeedCell ?? MainTimelineFeedCell() -// cell.cellData = MainTimelineCellData(article: previewArticle, -// showFeedName: .byline, -// feedName: "The Great Gatsby", -// byline: "F. Scott Fitzgerald", -// iconImage: nil, -// showIcon: false, -// numberOfLines: AppDefaults.shared.timelineNumberOfLines, -// iconSize: AppDefaults.shared.timelineIconSize) -// cell.isPreview = true -// return cell -// } + if indexPath.section == 0 { + let cell = tableView.dequeueReusableCell(withIdentifier: "IconSizeCell") as! ModernTimelineSliderCell + cell.sliderConfiguration = .iconSize + return cell + } + + if indexPath.section == 1 { + let cell = tableView.dequeueReusableCell(withIdentifier: "NumberOfLinesCell") as! ModernTimelineSliderCell + cell.sliderConfiguration = .numberOfLines + return cell + } + + if indexPath.section == 2 { + let cell = tableView.dequeueReusableCell(withIdentifier: standardCellIdentifierIcon) as! MainTimelineCell + cell.cellData = MainTimelineCellData(article: previewArticle, + showFeedName: .byline, + feedName: "The Fellowship of the Ring", + byline: "J. R. R. Tolkien", + iconImage: IconImage(Assets.Images.nnwFeedIcon), + showIcon: true, + numberOfLines: AppDefaults.shared.timelineNumberOfLines, + iconSize: AppDefaults.shared.timelineIconSize) + cell.isPreview = true + return cell + } + + if indexPath.section == 3 { + let cell = tableView.dequeueReusableCell(withIdentifier: standardCellIdentifier) as! MainTimelineCell + cell.cellData = MainTimelineCellData(article: previewArticle, + showFeedName: .byline, + feedName: "The Fellowship of the Ring", + byline: "J. R. R. Tolkien", + iconImage: nil, + showIcon: false, + numberOfLines: AppDefaults.shared.timelineNumberOfLines, + iconSize: AppDefaults.shared.timelineIconSize) + cell.isPreview = true + return cell + } return UITableViewCell()