Skip to content
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
1 change: 1 addition & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* [*] iPad: Fix the app getting stuck in the compact tab bar layout after resizing or switching apps [#26123]
* [*] Reader: Fix post tag outlines almost disappearing after switching between light and dark mode [#26168]
* [*] Reader: Fix some article toolbar icons turning white after liking a post on iOS 26 [#26169]
* [*] Reader: Make the article toolbar buttons easier to see over images on iOS 26 and later [#26176]

27.3
-----
Expand Down
103 changes: 88 additions & 15 deletions Tests/KeystoneTests/Tests/Reader/ReaderDetailToolbarTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct ReaderDetailToolbarTests {
#expect(itemsAfter.count == itemsBefore.count)
#expect(zip(itemsBefore, itemsAfter).allSatisfy { $0 === $1 })

let likeButton = try #require(itemsAfter.last?.customView as? UIButton)
let likeButton = try #require(buttons(in: itemsAfter).last)
#expect(likeButton.configuration?.title == 1234.formatted(.number.notation(.compactName)))
}

Expand All @@ -39,13 +39,13 @@ struct ReaderDetailToolbarTests {
let toolbar = ReaderDetailToolbar()

toolbar.configure(for: post, in: viewController)
let likeButton = try #require(viewController.toolbarItems?.last?.customView as? UIButton)
let wideWidth = likeButton.frame.width
let likeButton = try #require(buttons(in: viewController.toolbarItems).last)
let wideWidth = width(of: likeButton)

post.likeCount = 2

#expect(likeButton.frame.width < wideWidth)
#expect(likeButton.frame.width == likeButton.intrinsicContentSize.width)
#expect(width(of: likeButton) < wideWidth)
#expect(abs(width(of: likeButton) - likeButton.sizeThatFits(UIView.layoutFittingCompressedSize).width) < 1)
}

@Test("the like button grows when its count gets slightly wider")
Expand All @@ -58,13 +58,13 @@ struct ReaderDetailToolbarTests {
let toolbar = ReaderDetailToolbar()

toolbar.configure(for: post, in: viewController)
let likeButton = try #require(viewController.toolbarItems?.last?.customView as? UIButton)
let narrowWidth = likeButton.frame.width
let likeButton = try #require(buttons(in: viewController.toolbarItems).last)
let narrowWidth = width(of: likeButton)

post.likeCount = 9

#expect(likeButton.frame.width > narrowWidth)
#expect(likeButton.frame.width == likeButton.sizeThatFits(UIView.layoutFittingCompressedSize).width)
#expect(width(of: likeButton) > narrowWidth)
#expect(abs(width(of: likeButton) - likeButton.sizeThatFits(UIView.layoutFittingCompressedSize).width) < 1)
}

@Test("the toolbar is rebuilt when the comment button has to appear")
Expand All @@ -76,16 +76,89 @@ struct ReaderDetailToolbarTests {
post.commentsOpen = false
post.commentCount = 0
let viewController = UIViewController()
let toolbar = ReaderDetailToolbar()
let toolbar = ReaderDetailToolbar(isLoggedIn: { true })

toolbar.configure(for: post, in: viewController)
let itemsBefore = try #require(viewController.toolbarItems)
#expect(!itemsBefore.contains { $0.customView != nil })
#expect(buttons(in: viewController.toolbarItems).count == 2) // Save and reblog

post.commentCount = 1

let itemsAfter = try #require(viewController.toolbarItems)
let commentButton = try #require(itemsAfter.compactMap { $0.customView as? UIButton }.first)
#expect(commentButton.configuration?.title == 1.formatted(.number.notation(.compactName)))
let buttonsAfter = buttons(in: viewController.toolbarItems)
#expect(buttonsAfter.count == 3)
#expect(buttonsAfter.last?.configuration?.title == 1.formatted(.number.notation(.compactName)))
}

@Test(
"the reblog button is shown only when the post can be reblogged",
arguments: [
(isLoggedIn: true, isBlogPrivate: false, showsReblog: true),
(isLoggedIn: true, isBlogPrivate: true, showsReblog: false),
(isLoggedIn: false, isBlogPrivate: false, showsReblog: false)
]
)
func reblogButtonVisibility(isLoggedIn: Bool, isBlogPrivate: Bool, showsReblog: Bool) throws {
let context = ContextManager.forTesting().mainContext
let post = ReaderPostBuilder(context).build()
post.isBlogPrivate = isBlogPrivate
post.isLikesEnabled = false
post.commentsOpen = false
post.commentCount = 0
let viewController = UIViewController()
let toolbar = ReaderDetailToolbar(isLoggedIn: { isLoggedIn })

toolbar.configure(for: post, in: viewController)

let labels = buttons(in: viewController.toolbarItems).map(\.accessibilityLabel)
#expect(labels.contains("Reblog post") == showsReblog)
#expect(labels.count == (showsReblog ? 2 : 1)) // Save, and reblog when shown
}

@Test("a frosted capsule fits its buttons after a count changes width")
func capsuleFitsItsButtons() throws {
guard #available(iOS 26, *) else { return }

let context = ContextManager.forTesting().mainContext
let post = ReaderPostBuilder(context).build()
post.isLikesEnabled = true
post.likeCount = 3
let viewController = UIViewController()
let toolbar = ReaderDetailToolbar()

toolbar.configure(for: post, in: viewController)
let capsule = try #require(viewController.toolbarItems?.last?.customView)
let narrowWidth = capsule.intrinsicContentSize.width

post.likeCount = 1234

#expect(capsule.intrinsicContentSize.width > narrowWidth)
#expect(capsule.frame.width == capsule.intrinsicContentSize.width)
for button in buttons(in: capsule) {
#expect(width(of: button) >= button.sizeThatFits(UIView.layoutFittingCompressedSize).width)
}

post.likeCount = 3

#expect(capsule.intrinsicContentSize.width == narrowWidth)
#expect(capsule.frame.width == narrowWidth)
}

// MARK: - Helpers

/// The toolbar's buttons in order, whether each is its own item or they share a frosted capsule (iOS 26+).
private func buttons(in items: [UIBarButtonItem]?) -> [UIButton] {
(items ?? []).compactMap(\.customView).flatMap { buttons(in: $0) }
}

private func buttons(in view: UIView) -> [UIButton] {
if let button = view as? UIButton {
return [button]
}
return view.subviews.flatMap { buttons(in: $0) }
}

/// The width the toolbar gives a button: its pinned width on a frosted capsule (iOS 26+), or its frame.
private func width(of button: UIButton) -> CGFloat {
let pinned = button.constraints.first { $0.firstAttribute == .width && $0.secondItem == nil }
return pinned?.constant ?? button.frame.width
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ class ReaderDetailViewController: UIViewController, ReaderDetailView {
configureHeader()
configureRelatedPosts()
configureToolbar()
if #available(iOS 26, *) {
// The toolbar buttons sit on their own frosted capsules (see `ReaderDetailToolbar`). With them,
// the automatic edge effect draws a frosted band behind the whole toolbar on iOS 27.
scrollView.bottomEdgeEffect.isHidden = true
}
configureNoResultsViewController()
observeWebViewHeight()
configureNotifications()
Expand Down
Loading