iOS 18 Reworks TabView API

A deep dive into the iOS 18 beta reveals Apple has significantly rearchitected the `TabView` API, a core component for navigation-heavy apps. The update reportedly improves state management and animation, offering more predictable tab selection and new customization options that may reduce the need for common developer workarounds.

Prior to iOS 18, SwiftUI's `TabView` offered limited customization, often forcing developers to use `UITabBarAppearance` from UIKit for modifications like setting a background color or material effect. This approach was necessary, especially when dealing with scrollable content like a `List` or `ScrollView` that touched the `TabView`. The new API aims to provide more native SwiftUI solutions for styling and behavior. Historically, `TabView` has also presented challenges with state management and view lifecycle. Developers have reported issues with unexpected `onAppear` callbacks, particularly when a `TabView` is removed from the view hierarchy, and excessive callbacks when used with a `NavigationView`. In some cases, `TabView` could retain child views in memory even when they were no longer on screen, leading to potential memory retention and performance degradation. The iOS 18 update introduces a new, more type-safe syntax for declaring tabs. Instead of using the `.tabItem` modifier, developers now use a dedicated `Tab` struct, which is designed to make it easier to catch common errors at build time. Programmatic navigation between tabs has also been streamlined by binding the `TabView` to a selection property of a hashable type. A significant enhancement, particularly for iPadOS, is the introduction of the `.sidebarAdaptable` style. This allows a traditional tab bar to transform into a sidebar, providing a more structured and hierarchical navigation experience. On iPad, this new style places the tab bar at the top of the screen with text-only items, a departure from the traditional bottom bar. User customization is a key feature of the reworked API. By applying the `.tabViewCustomization` modifier and providing a unique `.customizationID` for each tab, developers can allow users to reorder, show, or hide tabs. This user-defined configuration can be persisted using `@AppStorage` or SwiftData. The new API also introduces `TabSection` to group related tabs, which is especially useful within the new sidebar interface on iPadOS. Developers can even add actions to these sections, which appear as buttons in the `TabView`, and control the visibility of sections on different platforms or size classes. For specific use cases, tabs can be assigned a special role, such as `.search`, to adopt system-standard behaviors.

Get your own daily briefing

Scout delivers personalized news, insights, and conversations tailored to your role and industry.

Download on the App Store

Shared from Scout - Be the smartest in the room.