Repository navigation
Build the tab bar's tabs once - #26301
Conversation
Generated by 🚫 Danger |
|
This PR seems to fix https://linear.app/a8c/issue/CMM-2581. Can you double check that please? |
|
Version |
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.
bbadc09 to
11a7526
Compare
wpmobilebot
left a comment
There was a problem hiding this comment.
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/searchopens 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
updateNotificationBadgeVisibilitycall inreloadTabs.
The layouts looked right on every screen I checked.
Tests:
RootViewCoordinatorTests,ReaderPresenterTests,NotificationsViewControllerTestsandWPTabBarControllerTestsall pass.- With the base
WPTabBarController.mandReaderPresenter.swiftput back,testAccountChangeWithAnAccountKeepsTheReaderTabWorkingfails with a nilReaderPresenter, which is the #26228 bug. - I also ran my own unit tests (not pushed). After an account change, the replaced
ReaderPresenterand 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() { |
There was a problem hiding this comment.
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.
WPTabBarControllernow 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:
reloadTabs)defaultAccountDidChange:)setShouldUseStaticNotifications:)Each rebuild created a new navigation controller, which also meant a new tab bar item. Two problems came from that:
updateNotificationBadgeVisibilityagain after each rebuild, and why the Me avatar subscription had to live in a lazy getter.Changes
WPTabBarController.m: build the Reader, Notifications and Me navigation controllers once, ininit. Two new methods replace only a tab's first screen:showFirstReaderScreenInNavigationController:andshowFirstNotificationsScreenInNavigationController:. The lazy getters andtabViewControllersare gone.reloadTabsno 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.ReaderPresenter.swift:prepareForTabBarPresentation(in:)fills the tab's existing navigation controller instead of returning a new one.WPTabBarController.h:readerNavigationControllerandnotificationsNavigationControllerare nownonnull. They could never returnnil.Test plan
RootViewCoordinatorTests: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/RootViewCoordinatorTestsandWordPressTest/NotificationsViewControllerTestspass: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
WPTabBarController(staticScreens: false)):/read/searchlink opens Reader Search.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.staticScreensWithReader(live Reader, Notifications poster): Saved opens from the menu. After a re-posted account change Likes opens from the menu, and awpdebug:///read/searchlink opens Reader Search. Notifications stays on the poster.iPad Pro 13-inch (M5), using the compact tab bar inside
SplitViewRootPresenter:staticScreensWithReader(appUITypeDidChange→shouldUseStaticNotifications):readerInWordPressAppflag isn't cached during the first session, so that session runs asstaticScreens. 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./read/searchlinkNot tried: a physical device. Every path above ran on simulators only.
Related issues