Afloat provides dynamic navigation titles and subtitles that respond to scroll events in SwiftUI. Perfect for list-based interfaces where you want the navigation bar to display context about what the user is viewing.
- Contextual Navigation — Titles and subtitles that change as users scroll
- Native Look & Feel — Animations match iOS's default behavior
- Cross-Platform — iOS, macOS, and visionOS
- SwiftUI Native — Drop-in replacements for standard modifiers
- Lightweight — No dependencies, small footprint
dependencies: [
.package(url: "https://github.com/AdelaideSky/Afloat.git", from: "1.0.0")
]import Afloat
NavigationStack {
ScrollView {
ForEach(sections) { section in
SectionHeader(section)
.navigationTitle(.contextual, section.name)
.navigationSubtitle(.contextual, "\(section.items.count) items")
}
}
.contextualNavigation(defaultTitle: "All Sections")
}See RecipeBookExample.swift for a complete example.
Use .contextualNavigationTransition() to customize the animation between titles (e.g., .opacity, .numericText(), .interpolate). Defaults to .identity.
Afloat uses SwiftUI's PreferenceKey system to track the position of views marked with contextual navigation modifiers. When a view scrolls past the top edge of the screen, its title and subtitle are collected and displayed in the navigation bar. The ContextualNavigationManager monitors these preference updates and determines which title should be active based on scroll position, creating smooth transitions between sections.
Full API reference and guides are available in the DocC documentation.
- Add support for Large navigation title
- More animation options (.numericText etc)
- Toolbars support
MIT. See LICENSE for details.