Skip to content

0x1-company/swiftui-pager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

swiftui-pager

A simple SwiftUI pager component that provides tab navigation with swipeable pages and a highlight indicator.

Requirements

  • Swift 6.2+
  • iOS, tvOS, watchOS, visionOS

Installation

Add the package to your Package.swift:

dependencies: [
    .package(url: "https://github.com/0x1-company/swiftui-pager", from: "1.0.0")
]

Then add Pager to your target dependencies:

.target(
    name: "YourApp",
    dependencies: ["Pager"]
)

Usage

import Pager

PagerView {
  Page {
    Text("Home")
  } label: {
    Text("Home")
  }

  Page {
    Text("Search")
  } label: {
    Text("Search")
  }

  Page {
    Text("Account")
  } label: {
    Text("Account")
  }
}

Custom Selection Type

PagerView supports a generic Selection type, allowing you to use a custom Hashable enum instead of the default Int index. Pass a Binding<Selection> to track and control the selected page.

import Pager

enum Tab: Hashable {
  case home, search, account
}

struct ContentView: View {
  @State private var selectedTab: Tab = .home

  var body: some View {
    PagerView(selection: $selectedTab) {
      Page(id: Tab.home) {
        Text("Home Content")
      } label: {
        Text("Home")
      }

      Page(id: Tab.search) {
        Text("Search Content")
      } label: {
        Text("Search")
      }

      Page(id: Tab.account) {
        Text("Account Content")
      } label: {
        Text("Account")
      }
    }
  }
}

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages