Skip to content

alchyo/SwiftUI-InfiniteTabView

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

SwiftUI Infinite TabView

A simple example demonstrating how to implement infinite swiping behavior using only three TabView pages in SwiftUI.
This technique avoids memory bloat and provides a smooth, continuous paging experience for calendar or carousel-like UIs.


🎯 Overview

This demo shows how to: - Implement infinite month paging with TabView - Recycle three views (previous, current, next) for continuous swiping - Reset the tab index to maintain an endless loop - Handle direction detection via @State and .onDisappear - Prevent glitching with temporary interaction disabling


🧠 Core Concept

Instead of generating dozens of pages for each month, this approach uses only three pages:

[-1] ← [0] β†’ [+1]

Each time the user swipes left or right: 1. Detect direction from currentTab (-1, 0, or 1) 2. Update the currentDate (previous or next month) 3. Reset currentTab to 0
4. Re-render with the new previous / current / next dates

This creates the illusion of infinite paging without extra memory overhead.


🧩 Code Structure

SwiftUI-InfiniteTabView/
β”œβ”€β”€ InfiniteMonthPagingView.swift   # Main demo view
└── README.md                       # Project documentation

πŸ–₯️ Preview

(You can add a GIF or screenshot here later)

#Preview {
    InfiniteMonthPagingView()
}

πŸ“¦ Technologies Used

  • SwiftUI for UI and state management\
  • TabView with .page style\
  • @State and .onDisappear for paging control\
  • DateFormatter for month display

πŸš€ Getting Started

git clone https://github.com/<your-username>/SwiftUI-InfiniteTabView.git
cd SwiftUI-InfiniteTabView
open SwiftUI-InfiniteTabView.xcodeproj

Then run the preview or build in Xcode.


🧾 License

This project is released under the MIT License.


✨ Author

Developed by ** alchyo **
SwiftUI / iOS Developer
πŸ“ Taiwan

About

A simple example showing how to implement infinite swiping using three TabView pages.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages