Skip to content

Use native tabs in WPTabBarController - #26439

Merged
crazytonyli merged 2 commits into
trunkfrom
task/native-tab-definitions
Nov 26, 2026
Merged

crazytonyli merged 2 commits into
trunkfrom
task/native-tab-definitions

Conversation

@crazytonyli

@crazytonyli crazytonyli commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Description

Migrate WPTabBarController to the iOS 18 UITab API, replacing index-based selection with stable destination identifiers.

Tab updates reuse existing destinations and navigation controllers where possible, preserving unaffected navigation stacks when account changes replace a tab. The existing tab order, repeated-tap navigation, analytics, notification indicators, and avatar appearance are preserved.

What I ran

  • I built this change and ran the affected tests locally

Testing instructions

@crazytonyli
crazytonyli added this pull request to stack #26443 November 22, 2026 21:51
@crazytonyli
crazytonyli requested a review from jkmassel November 22, 2026 22:52
@crazytonyli crazytonyli added this to the 27.6 milestone Nov 22, 2026
@crazytonyli
crazytonyli marked this pull request as ready for review November 22, 2026 23:03
Base automatically changed from bugfix/table-header-fitting-width to trunk November 25, 2026 23:58
@crazytonyli
crazytonyli force-pushed the task/native-tab-definitions branch from dbd0270 to 08aae20 Compare November 25, 2026 23:59

@jkmassel jkmassel left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

From Claude: Approving. We ran this on iOS 18.6, 26.5 and 27.2 simulators. The tab bar behaves like trunk: tapping the selected tab still returns to its first screen and scrolls to the top, Reader keeps its tab bar background, and the Me avatar is dimmed when Me isn't selected on iOS 18. The nits are inline, and none of them blocks.

Follow-up, not blocking: please land #26301 soon after this. Before iOS 27, when the selected tab is replaced by a new tab with the same identifier, UIKit keeps returning the removed tab from selectedTab. In the app, logging out while on Reader (for example from the expired-token alert) with a self-hosted site still signed in leaves the signed-in Reader screens in memory until the user switches tabs. The screen itself is correct. Building each tab once and resetting its screens, as #26301 does, means a selected tab is never replaced.

Nit: the description is still the template, and the "ran the affected tests" box is unticked. A short summary and test plan would help whoever reads this later.

How this was checked
  • WPTabBarControllerTests and RootViewCoordinatorTests on iOS 18.6, 26.5 and 27.2. Everything passes on 27.2. replacingNotificationsPreservesOtherTabsAndTheirStacks fails on 18.6 and 26.5 at line 62.
  • A temporary probe comparing the viewControllers and tabs APIs: the tab bar items are still the screens' own tabBarItems, and a reselect tap still calls shouldSelectTab:, pops to the first screen and calls tabBar:didSelectItem:.
  • The Jetpack app, signed in, with real taps on iOS 27.2 and 18.6.
  • The logout case on iOS 26.5: a temporary hook called the same logout as the expired-token alert's Log out button while Reader was selected. Before logout, selectedTab was the current Reader tab. After logout, it was the removed tab, and the old Reader screens were still alive. Switching to My Site released them.

}

extension UITab {
func configureAccountAvatar(_ avatar: UIImage?, isSelected: Bool) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Finding from Claude:
Nit: this repeats the avatar styling in UITabBarItem.configureAccountAvatar below it (26 pt Gravatar icon, dimmed copy before iOS 26, tab-bar-me fallback). A shared helper that returns the selected and dimmed images would keep the main app and the Reader app from drifting apart.

}

@Test func programmaticSelectionUpdatesMinimization() throws {
guard #available(iOS 26, *) else { return }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Finding from Claude:
Nit: before iOS 26 this test returns early and is reported as passed without checking anything. A trait such as .enabled(if: ProcessInfo.processInfo.isOperatingSystemAtLeast(OperatingSystemVersion(majorVersion: 26, minorVersion: 0, patchVersion: 0))) would report it as skipped instead.

#expect(controller.tabs[index] === originalTabs[index])
}
#expect(controller.readerNavigationController.topViewController === detail)
#expect(controller.selectedTab?.viewController === controller.notificationsNavigationController)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Finding from Claude:
Nit: this expectation fails on iOS 18.6 and 26.5 simulators, and passes on 27.2, which CI uses. Before iOS 27, UIKit keeps returning the replaced tab from selectedTab even though the new tab is on screen. #26301 avoids replacing the tab, so this should pass everywhere once it lands. Until then, a short comment here would save someone a confusing local failure.

@wpmobilebot wpmobilebot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approving. I ran the PR's WPTabBarControllerTests and RootViewCoordinatorTests plus my own probe tests, and drove the Jetpack app (signed in to WordPress.com) on an iPhone 18 Pro simulator with iOS 27.2 and an iPhone 17 Pro simulator with iOS 26.5. On both, the tab order, titles, notification dot and its "Notifications Unread" label, Me avatar and Reader tab bar background render correctly, with no truncation or overlap. Real taps still call tabBar:didSelectItem:, and tapping Reader again on a pushed screen pops back to the Reader root. The tab bar items are still the screens' own tabBarItems, so Reader's scrollEdgeAppearance and the UITab image and label updates reach the bar. The one Suggestion is inline. It only shows up before iOS 27, after a selected tab is replaced. All suites pass on 27.2. On 26.5, replacingNotificationsPreservesOtherTabsAndTheirStacks fails at line 62 for the same reason. Gap: Xcode 27.2 can't download an iOS 18 simulator runtime, so I couldn't check the pre-iOS 26 dimmed-avatar path.

UINavigationController *navController = (UINavigationController *)viewController;
[navController scrollContentToTopAnimated:YES];
}
if (tab != tabBarController.selectedTab) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggestion: before iOS 27 this pointer check misclassifies a reselect after the selected tab is replaced. updateTabsSelecting: installs a new UITab with the same identifier. UIKit treats it as equal to the old one (isEqual: returns YES), so iOS 26.5 keeps returning the removed tab from selectedTab. The next tap on the visibly selected tab arrives here with the new tab, tab != tabBarController.selectedTab is true, and the code takes the "new tab" branch. It records another readerAccessed event and skips scrollContentToTopAnimated:. Trunk compared indexes, so this didn't happen there.

You can reach this by logging out of WordPress.com while Reader is selected and a self-hosted site keeps the app UI up (e.g. from the expired-token alert, via defaultAccountDidChange:), or when appUITypeDidChange flips shouldUseStaticNotifications while Notifications is selected. The impact is small: a duplicate analytics event and no scroll-to-top on that tap. UIKit still pops to the root. The same stale tab also feeds supportedInterfaceOrientations (selectedTab?.viewController).

Evidence:

  • This probe test (kept locally) passes on iOS 27.2 and fails on iOS 26.5 with count == 0 failed (readerAccessedOnReselect=1):
    controller.showReaderTab()   // window shown, staticReader: false
    NotificationCenter.default.post(name: .wpAccountDefaultWordPressComAccountChanged, object: nil)
    TestAnalyticsTracker.setup()
    let reader = try #require(controller.tab(forAppTab: .reader))
    _ = controller.delegate?.tabBarController?(controller, shouldSelectTab: reader)
    #expect(TestAnalyticsTracker.tracked.filter { $0.stat == .readerAccessed }.count == 0)
    On 26.5, controller.selectedTab === newReader also fails, while oldReader.isEqual(newReader) is true.
  • In the Jetpack app on 26.5, a temporary hook posted the same notification while Reader was selected, then I tapped Reader again for real. The log here showed shouldSelectTab=reader selected=reader same=0. On 27.2 it showed same=1. On trunk with the same hook, selectedViewController was the new Reader controller on both OSes.

Comparing identifiers (e.g. ![tab.identifier isEqualToString:tabBarController.selectedTab.identifier]) would fix the check here. Resolving selectedTab through tabForAppTab:self.selectedAppTab would also fix the orientation lookup. Building each tab once, as #26301 does, removes the cause.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Resolved. At 4ab38a8, updateTabsSelecting: clears selectedTab before installing the replacement. I checked it on an iPhone 17 Pro simulator with iOS 26.5 and an iPhone 18 Pro with iOS 27.2:

  • My reselect probe now passes on both: after the logout rebuild while Reader is selected, selectedTab is the new Reader tab and readerAccessed isn't recorded again. The PR's replacingNotificationsPreservesOtherTabsAndTheirStacks, which failed on 26.5 before, passes too.
  • In the Jetpack app, the same temporary hook rebuilt Reader while it was selected, then I tapped Reader again for real. On both OSes the log shows shouldSelectTab=reader selected=reader same=1, and the Reader root is shown.
  • A spy probe found no side effects from the intermediate nil selection: My Site and Me get no viewWillAppear, and selectedTab changes nil → reader only.

if #available(iOS 26, *) {
image = icon
} else {
image = isSelected ? icon : icon.blackAndWhite?.withAlpha(0.36)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: on iOS 18–25, every selection change now rebuilds the dimmed avatar: gravatarIcon(size:) plus the blackAndWhite CIFilter, which creates a new CIContext on every call. updateAccountAvatarForSelection runs from both setSelectedTab: and didSelectTab:previousTab:. Before, both images were built once, when the avatar changed. Building the full and dimmed icons in the avatar sink and only swapping them here would avoid repeating that work on the main thread. I couldn't measure this, because an iOS 18 simulator runtime isn't available for Xcode 27.2.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not resolved. 4ab38a8 doesn't change this code: updateAccountAvatarForSelection still rebuilds the dimmed avatar on each selection change before iOS 26. It's still optional, and I still couldn't measure it without an iOS 18 runtime.

Before iOS 27, UIKit keeps returning a removed tab from selectedTab when its
replacement has the same identifier. Clearing the selection first makes the new
tab the selection, so reselect tracking, scroll-to-top and orientation use it.

Also report the iOS 26 minimization test as skipped on older systems.

@wpmobilebot wpmobilebot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approving 4ab38a8. Clearing selectedTab before installing replacement tabs fixes the stale selection before iOS 27, and the intermediate nil doesn't show or load another tab. I ran WPTabBarControllerTests, RootViewCoordinatorTests and my probes on an iPhone 17 Pro simulator with iOS 26.5 and an iPhone 18 Pro with iOS 27.2, and all pass. I also rebuilt Reader while it was selected in the Jetpack app and tapped it again; the tap is handled as a reselect on both OSes. Gap: there's still no iOS 18 runtime for Xcode 27.2, so I couldn't check the pre-iOS 26 avatar path or confirm that the new @available(iOS 26, *) test is reported as skipped there.

@wpmobilebot

Copy link
Copy Markdown
Contributor

🤖 Build Failure Analysis

This build has failures. Claude has analyzed them - check the build annotations for details.

@crazytonyli
crazytonyli added this pull request to the merge queue Nov 26, 2026
Merged via the queue into trunk with commit dc4e2c9 Nov 26, 2026
20 of 23 checks passed
@crazytonyli
crazytonyli deleted the task/native-tab-definitions branch November 26, 2026 08:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants