Elevate Your Tab and Sidebar Experience in iPadOS - WWDC24
Peter Yaacoub •
Introduction
The new tab and sidebar experience in iPadOS has been expanded to all Apple platforms, including iOS, visionOS, macOS, and tvOS. This session covers the enhancements and adjustments to the tab bar and sidebar, making them more intuitive and versatile across different devices. Let’s explore these updates and how you can implement them in your apps.
Changes Across Platforms
Unified Tab Bar Experience
The new tab bar experience is now consistent across all Apple platforms:
- iOS: Traditional bottom tab bar.
- iPadOS: Centered on the top navigation bar, enhancing visibility.
- macOS, visionOS, tvOS: Adaptive to different screen sizes and orientations.
No code changes are required for this visual shift, maintaining a seamless transition across devices.
Tab Bar Structure
- Fixed Items: Always visible tabs.
- Customizable Items: User-configurable tabs.
- Pinned Items: Always accessible, even when scrolling.
SwiftUI Enhancements
SwiftUI introduces several new features for handling tabs and sidebars seamlessly:
Using TabView and TabViewStyle
- Syntax: Use
TabView
withTabViewStyle
to create tabs. - Special Roles: Utilize tabs with special roles, like
searchTab
.
Sidebar Integration
- Automatic Sidebar Transition: Use
tabViewStyle(sidebarAdaptable)
for iPadOS, macOS, visionOS, and tvOS. - Organizing Items: Use
TabViewStyle
views andsectionActions(content:)
modifier for section management. - Drag and Drop Handling: Implement
dropDestination(for:action:isTargeted:)
to manage item dragging.
Customization
Use tabViewCustomization(_:)
, customizationIdentifier
, defaultVisibility(_:for:)
, and customizationBehavior(_:for:)
for full customization.
UIKit Integration
Setting Up Tabs
In UIKit, creating and customizing tabs is straightforward:
- Use
UITabBarController
: Manage tabs withtabs
property andUITab
variants likeUISearchTab
.
Sidebar Experience
- Modify
mode
Property: UseUITabBarControllerMode
for sidebar setup. - SwiftUI Equivalents: Convert
TabSections
toUITabGroup
andsectionActions(content:)
tosidebarActions
. - Drag and Drop Handling: Implement
UITabBarControllerDelegate
for drag and drop functionality.
Additional Properties
- Properties: Use
allowsHiding
,preferredPlacement
,allowsReordering
, anddisplayOrderIdentifiers
for enhanced control.
Conclusion
The enhancements to the tab and sidebar experience in iPadOS and across all Apple platforms bring a new level of flexibility and functionality to app development. Whether using SwiftUI or UIKit, these updates streamline the creation of intuitive and user-friendly interfaces.