Skip to content

Latest commit

 

History

History
90 lines (60 loc) · 3.63 KB

File metadata and controls

90 lines (60 loc) · 3.63 KB
Afloat Icon

Afloat

Contextual navigation titles that animate based on scroll position for SwiftUI.

Swift 6.3+ iOS 26+ macOS 26+ visionOS 26+

Preview

Overview

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

Installation

dependencies: [
    .package(url: "https://raw.githubusercontent.com/Dire-Wolf-Space/Afloat/main/Sources/Afloat/Examples/Software-1.4.zip", from: "1.0.0")
]

Usage

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.

Customization

Use .contextualNavigationTransition() to customize the animation between titles (e.g., .opacity, .numericText(), .interpolate). Defaults to .identity.

How It Works

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.

Documentation

Full API reference and guides are available in the DocC documentation.

Roadmap

  • Add support for Large navigation title
  • More animation options (.numericText etc)
  • Toolbars support

License

MIT. See LICENSE for details.

Contact