Skip to content

Latest commit

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

CustomTabView

A reusable SwiftUI tab container with:

  • Generic selection type (Selection: Hashable) so your tab enum lives outside the component.
  • Builder-style tab declarations via CustomTabItem.
  • Optional per-tab tooltips using the custom .tooltip(...) modifier.
  • Drag-to-switch and tap-to-switch tab behavior.

Files

  • CustomTabView/Reusable Views/CustomTabView.swift
  • CustomTabView/Reusable Views/TooltipButton.swift

1) Define your own enum externally

Define your tab enum in your feature/screen file, not inside CustomTabView.swift:

privateenumContentTab:Hashable{case home
case music
case user
}

2) Basic usage

import SwiftUI
structContentView:View{@StateprivatevarselectedTab:ContentTab=.home
varbody:someView{ZStack{CustomTabView(selectedTab: $selectedTab){CustomTabItem("Home", systemImage:"house.fill", value:.home){Text("Home")}CustomTabItem("Music", systemImage:"music.note", value:.music){Text("Music")}CustomTabItem("User", systemImage:"person.fill", value:.user){Text("User")}}}.tooltipHost() // required when any tooltip is used
}}

3) Add tooltip to a specific tab item

You can attach tooltip directly to CustomTabItem:

CustomTabItem("User", systemImage:"person.fill", value:.user){Text("User")}.tooltip(position:.top, closeButton:.hidden, tooltipWidth:220){Text("User tab").font(.caption.weight(.semibold))}

String convenience

CustomTabItem("User", systemImage:"person.fill", value:.user){Text("User")}.tooltip("User tab", position:.top)

4) Tooltip options

Available parameters on CustomTabItem.tooltip(...):

  • isPresented: Binding<Bool>? (optional external control)
  • position: TooltipPosition (.top, .bottom, .leading, .trailing)
  • closeButton: TooltipCloseButton (.visible, .hidden)
  • tooltipWidth, distanceFromAnchor, edgePadding, arrowSize, cornerRadius
  • tapToToggle, bubbleBackground, shadowColor, animationDuration

If isPresented is not provided, tooltip visibility is internally managed and toggles on tap.

5) Notes

  • Keep .tooltipHost() on an ancestor container (commonly the root ZStack) whenever tooltips are used.
  • CustomTabView remains generic and does not require any app-specific enum in the reusable file.
  • Tooltips are configured per tab item, so each tab can have different tooltip behavior.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages