Skip to content

Build the tab bar's tabs once - #26301

Merged
crazytonyli merged 1 commit into
trunkfrom
jkmassel/wptabbarcontroller-build-tabs-once
Dec 1, 2026
Merged

crazytonyli merged 1 commit into
trunkfrom
jkmassel/wptabbarcontroller-build-tabs-once

Conversation

@jkmassel

@jkmassel jkmassel commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

WPTabBarController now builds each tab once. When the account or the app UI type changes, it replaces the tab's first screen and keeps the tab. Stacked on #26300.

Why

Before this change, a tab was thrown away and rebuilt whenever its first screen had to change:

When What was rebuilt
Sign-in finishes (reloadTabs) All four tabs
WordPress.com account changes (defaultAccountDidChange:) The Reader tab
Notifications switches to the Moved-to-Jetpack poster (setShouldUseStaticNotifications:) The Notifications tab

Each rebuild created a new navigation controller, which also meant a new tab bar item. Two problems came from that:

Changes

  • WPTabBarController.m: build the Reader, Notifications and Me navigation controllers once, in init. Two new methods replace only a tab's first screen: showFirstReaderScreenInNavigationController: and showFirstNotificationsScreenInNavigationController:. The lazy getters and tabViewControllers are gone.
  • Reader: every WordPress.com account change now gives the tab a new presenter and first screen, whether or not the notification carries an account. reloadTabs no longer resets the Reader, since the account change already has. This is the fix for Reader menu and Reader links stop working on iPhone after signing in to WordPress.com again #26228.
  • Notifications and Me: unchanged behaviour. Sign-in still gives Notifications a new list and pops Me to its first screen. The poster switch keeps the selected tab without re-selecting it.
  • ReaderPresenter.swift: prepareForTabBarPresentation(in:) fills the tab's existing navigation controller instead of returning a new one.
  • WPTabBarController.h: readerNavigationController and notificationsNavigationController are now nonnull. They could never return nil.

Test plan

  • New tests in RootViewCoordinatorTests:
  • Three of the four new tests fail on the parent commit, every time across three retries: Executed 28 tests, with 12 failures. The poster-switch test passes on both. It guards the selected tab, which the old code also kept.
  • WordPressTest/RootViewCoordinatorTests and WordPressTest/NotificationsViewControllerTests pass: Executed 41 tests, with 0 failures.
    Simulator checks, all on iOS 27.0, signed in to a local self-hosted site and/or WordPress.com. A temporary debug hook logged the tab bar's address and its four tab addresses at every step. In every row below they stayed the same.

iPhone 18 Pro

  • Jetpack (WPTabBarController(staticScreens: false)):
    • Self-hosted only: the Reader tab shows the logged-out screen.
    • Sign In from that screen: the same tab switches to the live Reader menu, and Discover opens from it.
    • Re-post the account change with the account attached (the Reader menu and Reader links stop working on iPhone after signing in to WordPress.com again #26228 trigger): Saved opens from the menu, and a /read/search link opens Reader Search.
    • Log out of WordPress.com while the self-hosted site stays: the Reader goes back to the logged-out screen, the Me tab goes back to the default icon, and the tab bar stays.
  • WordPress app, static screens (StaticScreensTabBarWrapper, both posters): both tabs show the Moved-to-Jetpack poster with no Reader presenter. A re-posted account change keeps both posters and the selected tab. Logout goes to the sign-in screen.
  • WordPress app, staticScreensWithReader (live Reader, Notifications poster): Saved opens from the menu. After a re-posted account change Likes opens from the menu, and a wpdebug:///read/search link opens Reader Search. Notifications stays on the poster.
  • WordPress app, self-hosted only: no tab bar to test. That state uses the simplified UI.

iPad Pro 13-inch (M5), using the compact tab bar inside SplitViewRootPresenter:

  • Jetpack, wide window, self-hosted only: the hidden compact tab bar already has the logged-out Reader.
  • Jetpack, narrowed window: Sign In from the compact Reader gives the live Reader in the same tab, and Saved opens from its menu.
  • Jetpack, the collapse hand-off after an account change: widen, choose Likes in the wide Reader, re-post the account change while wide (the hidden tab bar gets a new presenter), then narrow. The compact Reader opens Likes through the new presenter.
  • Jetpack, log out while narrow: the compact Reader shows the logged-out screen. A widen and narrow cycle afterwards keeps it, with no assertions in the log.
  • WordPress app, staticScreensWithReader (appUITypeDidChange → shouldUseStaticNotifications):
    • Log out while on the Notifications tab: the same tab bar swaps in the live list, Notifications stays selected, and the bell updates.
    • Sign in again: the poster swaps back in, in the same tab bar.
  • On a fresh install the remote readerInWordPressApp flag isn't cached during the first session, so that session runs as staticScreens. There, sign-in replaces the whole split-view presenter, and the compact tab bar keeps the live tabs. This is existing behaviour; it doesn't go through the code this PR changes.
iPhone, Jetpack, self-hosted only iPhone, Jetpack, after re-post iPhone, Jetpack, /read/search link iPhone, Jetpack, after logout
Reader tab showing ‘Join the conversation’ and a Sign In button Saved screen opened from the Reader menu Reader Search opened from a link Reader tab back on ‘Join the conversation’, Me tab showing the default icon
iPhone, WordPress, static screens iPad compact, Jetpack, Reader menu iPad compact, Jetpack, after logout iPad compact, WordPress, Notifications poster
Reader tab showing the Moved-to-Jetpack poster Saved screen in the narrow iPad window Logged-out Reader in the narrow iPad window Notifications tab showing the Moved-to-Jetpack poster in the narrow iPad window

Not tried: a physical device. Every path above ran on simulators only.

Related issues

@jkmassel jkmassel self-assigned this Oct 29, 2026
@dangermattic

Copy link
Copy Markdown
Collaborator
1 Message
📖 This PR is still a Draft: some checks will be skipped.

Generated by 🚫 Danger

@crazytonyli

Copy link
Copy Markdown
Contributor

This PR seems to fix https://linear.app/a8c/issue/CMM-2581. Can you double check that please?

@wpmobilebot wpmobilebot modified the milestones: 27.5, 27.6 Nov 20, 2026
@wpmobilebot

Copy link
Copy Markdown
Contributor

Version 27.5 has now entered code-freeze, so the milestone of this PR has been updated to 27.6.

WPTabBarController replaced whole tabs when the account or app UI type
changed: sign-in rebuilt all four, logout rebuilt the Reader tab, and
switching to the Notifications poster rebuilt that tab. Each rebuild
threw away the tab bar item and its configuration, and a tab released
without being reinstalled left a stale screen on display.

Create each tab's navigation controller once and replace only its first
screen. Every WordPress.com account change now gives the Reader tab a
new presenter and first screen, including the same account signing in
again, which used to leave the tab without a presenter.
@crazytonyli
crazytonyli force-pushed the jkmassel/wptabbarcontroller-build-tabs-once branch from bbadc09 to 11a7526 Compare November 27, 2026 04:34
@crazytonyli
crazytonyli marked this pull request as ready for review November 27, 2026 04:35

@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.

Approve. Building the tabs once and swapping only their first screen fixes #26228, and I found no regressions.

Device: iPhone 18 Pro simulator, iOS 27.2, Jetpack Debug build of 11a7526, a local self-hosted WordPress site and a WordPress.com test account. All of the steps below ran on the same tab bar:

  • Self-hosted only: the Reader tab shows the logged-out screen.
  • Sign In from that screen: the same tab shows the live Reader menu with Saved, and the Me tab gets the avatar. Saved opens from the menu, and jpdebug:///read/search opens Reader Search.
  • Log out of WordPress.com from Me while the self-hosted site stays: the Reader goes from Saved back to the logged-out screen. Me shows the default icon, and Notifications shows the signed-out connect screen with no stale list.
  • Sign In from the Reader again: Discover opens. The bell drops its unread dot, so it still refreshes without the removed updateNotificationBadgeVisibility call in reloadTabs.

The layouts looked right on every screen I checked.

Tests:

  • RootViewCoordinatorTests, ReaderPresenterTests, NotificationsViewControllerTests and WPTabBarControllerTests all pass.
  • With the base WPTabBarController.m and ReaderPresenter.swift put back, testAccountChangeWithAnAccountKeepsTheReaderTabWorking fails with a nil ReaderPresenter, which is the #26228 bug.
  • I also ran my own unit tests (not pushed). After an account change, the replaced ReaderPresenter and its sidebar are freed, so the old presenter can't push into the shared navigation controller. After the switch to the live list, the Moved-to-Jetpack poster no longer stays the reused Notifications navigation controller's (portrait-only) delegate. A deep Reader stack goes back to one logged-out screen on sign-out.

Nit: the shouldUseStaticNotifications doc in WPTabBarController.h still says "Changing it rebuilds the Notifications tab". It now only replaces the tab's first screen. Also, the description lists WPTabBarController.h under Changes, but this PR doesn't modify it.

Gaps: I didn't test the iPad split view or the WordPress app's staticScreensWithReader mode. My unit tests cover the compact tab bar logic, and CI is green.

XCTAssertTrue(tabBar.showsPoster(in: .notifications))
}

func testTabsKeepTheirNavigationControllersWhenTheAccountOrAppUIChanges() {

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: AGENTS.md says to use Swift Testing for new tests. These four could go in the Swift Testing WPTabBarControllerTests suite, which already covers tab identity across sign-in and the poster switch. Fine to keep them here if you'd rather reuse this class's account helpers.

@crazytonyli
crazytonyli added this pull request to the merge queue Dec 1, 2026
Merged via the queue into trunk with commit 84e6162 Dec 1, 2026
21 checks passed
@crazytonyli
crazytonyli deleted the jkmassel/wptabbarcontroller-build-tabs-once branch December 1, 2026 21:45
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.

Reader menu and Reader links stop working on iPhone after signing in to WordPress.com again

4 participants