From 86ac40e1736100fd58a516753bf9345f995c0700 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sat, 7 Nov 2026 21:46:32 -0800 Subject: [PATCH] Make timeline layout settings on iOS better match Mac version in order and presentation. --- Shared/Localizable.xcstrings | 29 ++-- iOS/Settings/Settings.storyboard | 56 -------- iOS/Settings/TickMarkSlider.swift | 90 ------------ iOS/Settings/TimelineCustomizerCell.swift | 64 --------- ...neCustomizerCollectionViewController.swift | 133 +++++++++++------- 5 files changed, 100 insertions(+), 272 deletions(-) delete mode 100644 iOS/Settings/TickMarkSlider.swift delete mode 100644 iOS/Settings/TimelineCustomizerCell.swift diff --git a/Shared/Localizable.xcstrings b/Shared/Localizable.xcstrings index 49546dc97..566273dfb 100644 --- a/Shared/Localizable.xcstrings +++ b/Shared/Localizable.xcstrings @@ -621,6 +621,9 @@ } } }, + "Feed Icon Size" : { + "comment" : "Feed Icon Size" + }, "Feed Icons" : { "comment" : "Feed Icons" }, @@ -675,8 +678,8 @@ "from cache" : { "comment" : "Activity log — appended when a download was served from cache instead of the network" }, - "Full Titles, No Preview" : { - "comment" : "Timeline Layout: switch that shows whole titles, without the article preview, in the timeline" + "Full Title, No Preview" : { + "comment" : "Timeline Layout: Rows choice that shows the whole title, without the article preview, in the timeline" }, "General" : { "comment" : "Preferences", @@ -760,9 +763,6 @@ "iCloud Storage Stats" : { "comment" : "iCloud Storage Stats window title" }, - "Icon Size" : { - "comment" : "Icon Size" - }, "Import Failed" : { "comment" : "Import Failed" }, @@ -813,6 +813,9 @@ "Light" : { "comment" : "Light" }, + "Lines" : { + "comment" : "Lines" + }, "Link:" : { "comment" : "Link" }, @@ -1014,9 +1017,6 @@ "Notifications need to be enabled in the Settings app." : { "comment" : "Notifications need to be enabled in the Settings app." }, - "Number of Lines" : { - "comment" : "Number of Lines" - }, "OK" : { "comment" : "OK button" }, @@ -1136,6 +1136,9 @@ "Return to Previous Scan Results" : { "comment" : "Return to previous scan results button" }, + "Rows" : { + "comment" : "Rows" + }, "Running" : { "comment" : "Running" }, @@ -1269,6 +1272,9 @@ "Shows current activity" : { "comment" : "Current Activity accessibility hint" }, + "Shows the whole title, up to %d lines." : { + "comment" : "Timeline Layout: explains the Full Title, No Preview choice" + }, "Sign in to your BazQux account and sync your feeds across your devices. Your username and password will be encrypted and stored in Keychain.\n\nDon’t have a BazQux account?" : { "comment" : "BazQux" }, @@ -1441,8 +1447,8 @@ "This will delete:" : { "comment" : "Clean up confirmation prefix" }, - "Thumbnail Size" : { - "comment" : "Thumbnail Size" + "Thumbnails" : { + "comment" : "Thumbnails" }, "Timeline" : { "comment" : "Timeline" @@ -1501,6 +1507,9 @@ "Title (Optional)" : { "comment" : "Feed title placeholder" }, + "Title and Preview" : { + "comment" : "Title and Preview" + }, "To add an account to NetNewsWire,\nclick its icon above.\n\nOr click the + button in the lower left." : { "comment" : "Add Account Explainer", "localizations" : { diff --git a/iOS/Settings/Settings.storyboard b/iOS/Settings/Settings.storyboard index eeedb5189..bcbdd84cb 100644 --- a/iOS/Settings/Settings.storyboard +++ b/iOS/Settings/Settings.storyboard @@ -838,62 +838,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/iOS/Settings/TickMarkSlider.swift b/iOS/Settings/TickMarkSlider.swift deleted file mode 100644 index 240e8388d..000000000 --- a/iOS/Settings/TickMarkSlider.swift +++ /dev/null @@ -1,90 +0,0 @@ -// -// TickMarkSlider.swift -// NetNewsWire-iOS -// -// Created by Maurice Parker on 11/8/19. -// Copyright © 2019 Ranchero Software. All rights reserved. -// - -import UIKit - -final class TickMarkSlider: UISlider { - - private var enableFeedback = false - private let feedbackGenerator = UISelectionFeedbackGenerator() - - private var roundedValue: Float? - override var value: Float { - didSet { - let testValue = value.rounded() - if testValue != roundedValue && enableFeedback && value.truncatingRemainder(dividingBy: 1) == 0 { - roundedValue = testValue - feedbackGenerator.selectionChanged() - } - } - } - - func addTickMarks() { - if #available(iOS 26, *) { - return - } - - enableFeedback = true - - let numberOfGaps = Int(maximumValue) - Int(minimumValue) - - var gapLayoutGuides = [UILayoutGuide]() - - for i in 0...numberOfGaps { - - let tick = UIView() - tick.translatesAutoresizingMaskIntoConstraints = false - tick.backgroundColor = .tertiaryLabel - insertSubview(tick, at: 0) - - tick.widthAnchor.constraint(equalToConstant: 3).isActive = true - tick.heightAnchor.constraint(equalToConstant: 10).isActive = true - tick.centerYAnchor.constraint(equalTo: self.centerYAnchor).isActive = true - - if i == 0 { - tick.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true - } - - if let lastGapLayoutGuide = gapLayoutGuides.last { - lastGapLayoutGuide.trailingAnchor.constraint(equalTo: tick.leadingAnchor).isActive = true - } - - if i != numberOfGaps { - let gapLayoutGuide = UILayoutGuide() - gapLayoutGuides.append(gapLayoutGuide) - addLayoutGuide(gapLayoutGuide) - tick.trailingAnchor.constraint(equalTo: gapLayoutGuide.leadingAnchor).isActive = true - } else { - tick.trailingAnchor.constraint(equalTo: trailingAnchor).isActive = true - } - } - - if let firstGapLayoutGuide = gapLayoutGuides.first { - for i in 1.. Bool { - if #available(iOS 26, *) { - return super.continueTracking(touch, with: event) - } - let result = super.continueTracking(touch, with: event) - value = value.rounded() - return result - } - - override func endTracking(_ touch: UITouch?, with event: UIEvent?) { - if #available(iOS 26, *) { - super.endTracking(touch, with: event) - return - } - value = value.rounded() - } -} diff --git a/iOS/Settings/TimelineCustomizerCell.swift b/iOS/Settings/TimelineCustomizerCell.swift deleted file mode 100644 index 00b84e21b..000000000 --- a/iOS/Settings/TimelineCustomizerCell.swift +++ /dev/null @@ -1,64 +0,0 @@ -// -// TimelineCustomizerCell.swift -// NetNewsWire-iOS -// -// Created by Stuart Breckenridge on 21/08/2025. -// Copyright © 2025 Ranchero Software. All rights reserved. -// - -import UIKit -import Images - -enum SliderConfiguration { - case numberOfLines - case iconSize -} - -final class TimelineCustomizerCell: UICollectionViewCell { - @IBOutlet var slider: TickMarkSlider! - - var sliderConfiguration: SliderConfiguration! { - didSet { - switch sliderConfiguration { - case .numberOfLines: - slider.minimumValue = 1 - slider.maximumValue = 6 - if #available(iOS 26, *) { - slider.trackConfiguration = .init(allowsTickValuesOnly: true, numberOfTicks: 6) - } - slider.value = Float(AppDefaults.timelineNumberOfLines) - slider.addTickMarks() - case .iconSize: - slider.minimumValue = 1 - slider.maximumValue = 3 - if #available(iOS 26, *) { - slider.trackConfiguration = .init(allowsTickValuesOnly: true, numberOfTicks: 3) - } - slider.value = Float(AppDefaults.timelineIconSize.rawValue) - slider.addTickMarks() - case .none: - return - } - } - } - - @IBAction func sliderValueChanges(_ sender: Any) { - switch sliderConfiguration { - case .numberOfLines: - AppDefaults.timelineNumberOfLines = Int(slider.value.rounded()) - case .iconSize: - guard let iconSize = IconSize(rawValue: Int(slider.value.rounded())) else { return } - AppDefaults.timelineIconSize = iconSize - case .none: - return - } - } - - override func updateConfiguration(using state: UICellConfigurationState) { - var backgroundConfig = UIBackgroundConfiguration.listCell().updated(for: state) - backgroundConfig.backgroundColor = traitCollection.userInterfaceStyle == .dark ? .secondarySystemBackground : .white - backgroundConfig.cornerRadius = 20 - self.backgroundConfiguration = backgroundConfig - } - -} diff --git a/iOS/Settings/TimelineCustomizerCollectionViewController.swift b/iOS/Settings/TimelineCustomizerCollectionViewController.swift index cb24f694a..2e52949fb 100644 --- a/iOS/Settings/TimelineCustomizerCollectionViewController.swift +++ b/iOS/Settings/TimelineCustomizerCollectionViewController.swift @@ -13,8 +13,6 @@ import Images class TimelineCustomizerCollectionViewController: UICollectionViewController { private enum Section: Int, CaseIterable { - case iconSize - case numberOfLines case options case preview case previewWithThumbnail @@ -32,14 +30,19 @@ class TimelineCustomizerCollectionViewController: UICollectionViewController { } } + /// Same order as the Mac Timeline settings. private enum OptionsRow: Int, CaseIterable { case feedIcons + case feedIconSize case thumbnails - case fullTitles + case rows + case numberOfLines case fadeReadArticles case feedNameAndDateAboveTitle } + private static let numberOfLinesChoices = 1...6 + private var previewArticle: Article { var components = DateComponents() components.year = 1954 @@ -69,9 +72,6 @@ class TimelineCustomizerCollectionViewController: UICollectionViewController { status: ArticleStatus(articleID: "_testArticleID", read: false, starred: false, dateArrived: .now)) } - private var cachedTimelineLines: Int = AppDefaults.timelineNumberOfLines - private var cachedIconSize: IconSize = AppDefaults.timelineIconSize - // Created up front, since UIKit disallows creating a registration in cellForItemAt. private let optionsCellRegistration = UICollectionView.CellRegistration { cell, _, optionsRow in TimelineCustomizerCollectionViewController.configureOptionsCell(cell, optionsRow: optionsRow) @@ -81,23 +81,10 @@ class TimelineCustomizerCollectionViewController: UICollectionViewController { super.viewDidLoad() title = NSLocalizedString("Timeline Layout", comment: "Timeline Layout") - NotificationCenter.default.addObserver(forName: UserDefaults.didChangeNotification, object: nil, queue: .main) { [weak self] _ in - guard let self = self else { return } - Task { @MainActor in - - if AppDefaults.timelineNumberOfLines != self.cachedTimelineLines { - self.cachedTimelineLines = AppDefaults.timelineNumberOfLines - self.userDefaultsDidChange() - } - - if AppDefaults.timelineIconSize != self.cachedIconSize { - self.cachedIconSize = AppDefaults.timelineIconSize - self.userDefaultsDidChange() - } - } - } NotificationCenter.default.addObserver(self, selector: #selector(handleTimelineFeedIconsDisplayDidChange(_:)), name: .timelineFeedIconsDisplayDidChange, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(handleTimelineIconSizeDidChange(_:)), name: .timelineIconSizeDidChange, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(handleTimelineThumbnailsDisplayDidChange(_:)), name: .timelineThumbnailsDisplayDidChange, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(handleTimelineNumberOfLinesDidChange(_:)), name: .timelineNumberOfLinesDidChange, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(handleTimelineShowFullTitlesDidChange(_:)), name: .timelineShowFullTitlesDidChange, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(handleTimelineFadeReadArticlesDidChange(_:)), name: .timelineFadeReadArticlesDidChange, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(handleTimelineFeedNameAndDateAboveTitleDidChange(_:)), name: .timelineFeedNameAndDateAboveTitleDidChange, object: nil) @@ -150,16 +137,6 @@ class TimelineCustomizerCollectionViewController: UICollectionViewController { override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { switch Section(rawValue: indexPath.section) { - case .iconSize: - let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "IconSizeSelector", for: indexPath) as! TimelineCustomizerCell - cell.sliderConfiguration = .iconSize - return cell - case .numberOfLines: - let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "NumberOfLinesSelector", for: indexPath) as! TimelineCustomizerCell - cell.sliderConfiguration = .numberOfLines - // The number of lines applies only to the title and summary. - cell.slider.isEnabled = !AppDefaults.timelineShowFullTitles - return cell case .options: let optionsRow = OptionsRow(rawValue: indexPath.item) ?? .feedIcons return collectionView.dequeueConfiguredReusableCell(using: optionsCellRegistration, for: indexPath, item: optionsRow) @@ -186,10 +163,6 @@ class TimelineCustomizerCollectionViewController: UICollectionViewController { ) as! TimelineHeaderView switch Section(rawValue: indexPath.section) { - case .iconSize: - header.label.text = NSLocalizedString("Icon Size", comment: "Icon Size") - case .numberOfLines: - header.label.text = NSLocalizedString("Number of Lines", comment: "Number of Lines") case .preview, .previewWithThumbnail, .previewWithFeedIcon, .previewWithFeedIconAndThumbnail: header.label.text = Self.previewHeaderTitle(Section(rawValue: indexPath.section) ?? .preview) case .options, .none: @@ -204,21 +177,16 @@ class TimelineCustomizerCollectionViewController: UICollectionViewController { } override func collectionView(_ collectionView: UICollectionView, shouldSelectItemAt indexPath: IndexPath) -> Bool { - switch Section(rawValue: indexPath.section) { - case .iconSize, .numberOfLines: - return true - default: - return false - } + false } // MARK: Notifications - func userDefaultsDidChange() { - reloadPreviews() + @objc func handleTimelineFeedIconsDisplayDidChange(_ notification: Notification) { + reloadOptionsRowsAndPreviews() } - @objc func handleTimelineFeedIconsDisplayDidChange(_ notification: Notification) { + @objc func handleTimelineIconSizeDidChange(_ notification: Notification) { reloadOptionsRowsAndPreviews() } @@ -226,8 +194,11 @@ class TimelineCustomizerCollectionViewController: UICollectionViewController { reloadOptionsRowsAndPreviews() } + @objc func handleTimelineNumberOfLinesDidChange(_ notification: Notification) { + reloadOptionsRowsAndPreviews() + } + @objc func handleTimelineShowFullTitlesDidChange(_ notification: Notification) { - collectionView.reloadSections(IndexSet(integer: Section.numberOfLines.rawValue)) reloadOptionsRowsAndPreviews() } @@ -304,20 +275,33 @@ private extension TimelineCustomizerCollectionViewController { static private func configureOptionsCell(_ cell: TimelineCustomizerOptionsCell, optionsRow: OptionsRow) { // The pop-up menu accessory shows only a chevron, so the value cell’s secondary text shows the current choice. var content = UIListContentConfiguration.valueCell() + cell.isUserInteractionEnabled = true switch optionsRow { case .feedIcons: content.text = NSLocalizedString("Feed Icons", comment: "Feed Icons") content.secondaryText = AppDefaults.timelineFeedIconsDisplay.description cell.accessories = [.popUpMenu(timelineFeedIconsDisplayMenu())] + case .feedIconSize: + content.text = NSLocalizedString("Feed Icon Size", comment: "Feed Icon Size") + content.secondaryText = iconSizeTitle(AppDefaults.timelineIconSize) + cell.accessories = [.popUpMenu(timelineIconSizeMenu())] case .thumbnails: - content.text = NSLocalizedString("Thumbnail Size", comment: "Thumbnail Size") + content.text = NSLocalizedString("Thumbnails", comment: "Thumbnails") content.secondaryText = AppDefaults.timelineThumbnailsDisplay.description cell.accessories = [.popUpMenu(timelineThumbnailsDisplayMenu())] - case .fullTitles: - content = UIListContentConfiguration.cell() - content.text = NSLocalizedString("Full Titles, No Preview", comment: "Timeline Layout: switch that shows whole titles, without the article preview, in the timeline") - configureSwitch(cell, isOn: AppDefaults.timelineShowFullTitles) { isOn in - AppDefaults.timelineShowFullTitles = isOn + case .rows: + content.text = NSLocalizedString("Rows", comment: "Rows") + content.secondaryText = AppDefaults.timelineShowFullTitles ? fullTitleTitle : titleAndPreviewTitle + cell.accessories = [.popUpMenu(timelineRowsMenu())] + case .numberOfLines: + content.text = NSLocalizedString("Lines", comment: "Lines") + content.secondaryText = AppDefaults.timelineNumberOfLines.formatted() + cell.accessories = [.popUpMenu(timelineNumberOfLinesMenu())] + // The number of lines applies only to the title and preview. + if AppDefaults.timelineShowFullTitles { + content.textProperties.color = .secondaryLabel + content.secondaryTextProperties.color = .tertiaryLabel + cell.isUserInteractionEnabled = false } case .fadeReadArticles: content = UIListContentConfiguration.cell() @@ -334,7 +318,6 @@ private extension TimelineCustomizerCollectionViewController { } cell.contentConfiguration = content - // Matches TimelineCustomizerCell. cell.configurationUpdateHandler = { cell, state in var backgroundConfig = UIBackgroundConfiguration.listCell().updated(for: state) backgroundConfig.backgroundColor = cell.traitCollection.userInterfaceStyle == .dark ? .secondarySystemBackground : .white @@ -359,6 +342,52 @@ private extension TimelineCustomizerCollectionViewController { return UIMenu(options: .singleSelection, children: actions) } + static let titleAndPreviewTitle = NSLocalizedString("Title and Preview", comment: "Title and Preview") + static let fullTitleTitle = NSLocalizedString("Full Title, No Preview", comment: "Timeline Layout: Rows choice that shows the whole title, without the article preview, in the timeline") + + static func iconSizeTitle(_ iconSize: IconSize) -> String { + switch iconSize { + case .small: + NSLocalizedString("Small", comment: "Small") + case .medium: + NSLocalizedString("Medium", comment: "Medium") + case .large: + NSLocalizedString("Large", comment: "Large") + } + } + + static func timelineIconSizeMenu() -> UIMenu { + let currentIconSize = AppDefaults.timelineIconSize + let actions = IconSize.allCases.map { iconSize in + UIAction(title: iconSizeTitle(iconSize), state: iconSize == currentIconSize ? .on : .off) { _ in + AppDefaults.timelineIconSize = iconSize + } + } + return UIMenu(options: .singleSelection, children: actions) + } + + static func timelineRowsMenu() -> UIMenu { + let showFullTitles = AppDefaults.timelineShowFullTitles + let titleAndPreviewAction = UIAction(title: titleAndPreviewTitle, state: showFullTitles ? .off : .on) { _ in + AppDefaults.timelineShowFullTitles = false + } + let fullTitleSubtitle = String(format: NSLocalizedString("Shows the whole title, up to %d lines.", comment: "Timeline Layout: explains the Full Title, No Preview choice"), MainTimelineCellData.fullTitleMaximumNumberOfLines) + let fullTitleAction = UIAction(title: fullTitleTitle, subtitle: fullTitleSubtitle, state: showFullTitles ? .on : .off) { _ in + AppDefaults.timelineShowFullTitles = true + } + return UIMenu(options: .singleSelection, children: [titleAndPreviewAction, fullTitleAction]) + } + + static func timelineNumberOfLinesMenu() -> UIMenu { + let currentNumberOfLines = AppDefaults.timelineNumberOfLines + let actions = numberOfLinesChoices.map { numberOfLines in + UIAction(title: numberOfLines.formatted(), state: numberOfLines == currentNumberOfLines ? .on : .off) { _ in + AppDefaults.timelineNumberOfLines = numberOfLines + } + } + return UIMenu(options: .singleSelection, children: actions) + } + static func timelineThumbnailsDisplayMenu() -> UIMenu { let currentThumbnailsDisplay = AppDefaults.timelineThumbnailsDisplay let actions = TimelineThumbnailsDisplay.allCases.map { thumbnailsDisplay in