Skip to content

aessam/DualCapsuleTabBar

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

iOS 26 Modern TabBar Implementation πŸ“±

A custom SwiftUI implementation of a modern, scrollable tab bar with smooth animations and expandable search functionality, inspired by modern iOS design patterns.

Demo Session

✨ Features

  • 🎯 Dual Capsule Design: Two separate capsules - one for scrollable tabs, one for search
  • πŸ“± 7 Scrollable Tabs: Horizontally scrollable tab bar with smooth auto-centering
  • πŸ”΅ Sliding Selection Indicator: Animated blue background that slides between selected tabs
  • πŸ” Expandable Search: Search button that expands into a full search bar
  • ✨ Smooth Animations: Beautiful transitions using SwiftUI's latest animation APIs
  • 🎨 Material Background: Ultra-thin material backgrounds for a modern look

πŸ“Έ Screenshots

Recents Tab

Recents Tab

For You Tab

For You Tab

Search Functionality

Search

πŸš€ Getting Started

Prerequisites

  • iOS 16.0+
  • Xcode 14.0+
  • SwiftUI

Installation

  1. Clone the repository:
git clone https://github.com/yourusername/iOS26TabBarLike.git
cd iOS26TabBarLike
  1. Open the project in Xcode:
open iOS26TabBarLike.xcodeproj
  1. Build and run the project on your simulator or device.

πŸ—οΈ Architecture

The project consists of three main components:

1. TabItem Enum

Defines the available tabs with their icons and labels:

enum TabItem: String, CaseIterable, Equatable {
    case recents = "Recents"
    case shared = "Shared" 
    case browse = "Browse"
    case albums = "Albums"
    case search = "Search"
    case library = "Library"
    case forYou = "For You"
    
    var symbol: String {
        // Returns appropriate SF Symbol for each tab
    }
}

2. CustomTabBar View

The main tab bar component featuring:

  • Horizontal scroll view with 7 tabs
  • Sliding selection indicator using matchedGeometryEffect
  • Expandable search functionality
  • Auto-scroll to selected tab

3. ContentView

The main container that:

  • Manages tab selection state
  • Displays content for each tab
  • Coordinates between tab bar and content views

🎨 Key Implementation Details

Sliding Selection Animation

.background {
    if activeTab == tab {
        Capsule()
            .fill(Color.blue)
            .matchedGeometryEffect(id: "activeTab", in: animation)
    }
}

Auto-Scroll to Selection

.onChange(of: activeTab) { newTab in
    withAnimation(.smooth(duration: 0.3)) {
        proxy.scrollTo(newTab, anchor: .center)
    }
}

Expandable Search

// Main tab bar hides when search expands
if !isSearchExpanded {
    ScrollViewReader { proxy in
        // Tab bar content
    }
    .transition(.asymmetric(
        insertion: .move(edge: .leading).combined(with: .opacity),
        removal: .move(edge: .leading).combined(with: .opacity)
    ))
}

🎯 Usage

Basic Implementation

struct ContentView: View {
    @State private var activeTab: TabItem = .recents
    
    var body: some View {
        ZStack(alignment: .bottom) {
            TabContentView(tab: activeTab)
            CustomTabBar(activeTab: $activeTab)
        }
    }
}

Customizing Tabs

To add or modify tabs:

  1. Update the TabItem enum with your new cases
  2. Add corresponding SF Symbols in the symbol computed property
  3. The tab bar will automatically accommodate the new tabs

Customizing Appearance

// Change accent color
var accentColor: Color {
    return .blue // Change to your preferred color
}

// Modify background material
.background {
    Capsule()
        .fill(.ultraThinMaterial) // Try .regularMaterial or .thickMaterial
}

πŸ“± Design Patterns Used

  • State Management: Using @State and @Binding for reactive UI updates
  • Namespace: For matchedGeometryEffect animations
  • ViewBuilder: For clean, reusable view components
  • ScrollViewReader: For programmatic scroll control
  • FocusState: For keyboard management in search

πŸ”§ Technical Features

Animations

  • Duration: Consistent 0.3-second animations throughout
  • Easing: .smooth() animation curve for natural feel
  • Transitions: Asymmetric slide transitions for tab switching

Performance

  • Lazy Loading: Content views are only created when needed
  • Efficient Scrolling: ScrollView with optimized content rendering
  • Memory Management: Proper state cleanup when switching tabs

🀝 Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • Inspired by modern iOS design patterns
  • Built with SwiftUI's latest animation capabilities
  • SF Symbols for beautiful, consistent iconography

πŸ“ž Support

If you have any questions or need help implementing this in your project:

  • Open an issue on GitHub
  • Follow the implementation guide above
  • Check out the demo video for visual reference

Made with ❀️ using SwiftUI

About

πŸš€ Modern iOS Tab Bar with Scrollable Tabs, Sliding Selection Indicator & Expandable Search - Built with SwiftUI

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages