GithubHelp home page GithubHelp logo

onl1ner / tabbar Goto Github PK

View Code? Open in Web Editor NEW
383.0 5.0 37.0 40 KB

๐Ÿ“ฑ TabBar โ€“ highly customizable tab bar (i.e. TabView) for your SwiftUI application.

License: MIT License

Swift 100.00%
tabbar tab bar swiftui swift xcode library custom-tabbar custom-tab-bar tabview

tabbar's Issues

How to hide tabor dynamically

Is it possible to hide tab bar when user selects second tab item only, for example? I want to have several items and if selects first item tabbar should be show but for another (or navigation links) - not.

Feature Request: Allow badges

It would be nice to have the possibility to show a badge on a tabBar icon if needed/wanted.

The idea would be to extend TabItemStyle with a badgeNumber: Int? parameter, which would allow handling the drawing of badges. Additionally, the Tabbable protocol must also be extended with a function func badgeNumber(for item: Tabbable) -> Int?, can have a default implementation { nil }

It seems the page will be recreated when switch between tabs each time.

struct ContentView: View {
    
    private enum Item: Int, Tabbable {
        case first = 0
        case second
        case third
        
        var icon: String {
            switch self {
                case .first: return "house"
                case .second: return "magnifyingglass"
                case .third: return "person"
            }
        }
        
        var title: String {
            switch self {
                case .first: return "First"
                case .second: return "Second"
                case .third: return "Third"
            }
        }
    }
    
    @State private var selection: Item = .first
    @State private var visibility: TabBarVisibility = .visible
    
    var body: some View {
        TabBar(selection: $selection, visibility: $visibility) {
            Button {
                withAnimation {
                    visibility.toggle()
                }
            } label: {
                Text("Hide/Show TabBar")
            }
            .tabItem(for: Item.first)
            
			Second()
                .tabItem(for: Item.second)
            
            Text("Third")
                .tabItem(for: Item.third)
        }
        .tabBar(style: CustomTabBarStyle())
        .tabItem(style: CustomTabItemStyle())
    }
}

struct ContentSystemTabView: View {
	var body: some View {
		TabView {
			Text("First")
				.tabItem {
					Text("first")
				}

			Second()
				.tabItem {
					Text("second")
				}
		}
	}
}

struct Second: View {
	init() {
		print("init...")
	}
	var body: some View {
		Text("Second")
	}
}

You will find the difference between TabView.

Content is hidden behind TabBar

Simulator Screen Shot - iPhone 14 Pro - 2023-01-23 at 19 53 20

diff --git a/Example/Example/ContentView.swift b/Example/Example/ContentView.swift
index 5b7e8e3..8e591c2 100644
--- a/Example/Example/ContentView.swift
+++ b/Example/Example/ContentView.swift
@@ -61,14 +61,23 @@ struct ContentView: View {
                 Text("Hide/Show TabBar")
             }
             .tabItem(for: Item.first)
-            
-            Text("Second")
-                .tabItem(for: Item.second)
+
+            ScrollView {
+                VStack {
+                    ForEach(0..<100, id: \.self) { i in
+                        Rectangle()
+                            .fill(Color.accentColor)
+                            .overlay(
+                                TextField("\(i)", text: .constant("\(i)"))
+                            )
+                    }
+                }
+            }
+            .tabItem(for: Item.second)
             
             Text("Third")
                 .tabItem(for: Item.third)
         }
-        .tabBar(style: CustomTabBarStyle())
         .tabItem(style: CustomTabItemStyle())
     }
 }

Perform action when user presses or long presses a tab item

Hello,

I didn't see this in the documentation, but it would be great if we could attach gesture recognizers to tabs (individually or as a group) to perform other actions on a tab.

As an example (what I want to do):

  • When a tab is active, pressing the tab item again should scroll to the top and refresh the content
  • Long pressing on a tab to go back to the root view
  • Adding haptics when a user presses a tab

This is lower priority for me, but when I have more time, I'll probably explore this on my own if no one else gets to it.

Thanks for considering!

No releases

It would be great if the project had releases and used semantic versioning. It would make the usage and update much easier.

Right now it has to be integrated using branches or commits.

Hide/Show TabBar

hey, great work really. Is it possible to hide the navbar? (remove from screen)|
The idea is when a user clicks on a navigation button and go to another view the navbar should fall down and when the user click on Back button it should appear again.

Updating Selection from Another View

How I can updated selected State if I'm navigating to view (presented TabBar), but not from TabBar, like from button inside of another view, or using NavigationLink in another view.

Thank you

View with TabBar

struct GeneralView View {
    
    enum Item: Int, Tabbable {
        case home = 0
        case letters
        case heritage
        case bookmarks
        case third
        
        
        var icon: String {
            switch self {
                case .letters: return "textformat"
                case .heritage: return "command"
                case .home: return "house.fill"
                case .third: return "quote.bubble"
                case .bookmarks: return "bookmark.fill"
               
            }
        }
        
        var title: String {
            switch self {
                case .letters: return "Letters"
                case .heritage: return "Heritage"
                case .home: return "Arageel"
                case .third: return "Third"
                case .bookmarks: return "Bookmarks"
               
            }
        }
    }
    
    @State private var selection: Item = .home
    @State private var visibility: TabBarVisibility = .visible
    
    
    var body: some View {
        
        TabBar(selection: $selection, visibility: $visibility) {
            LettersGridView()
                .tabItem(for: Item.letters)
            
            HeritageZineHomeView()
                .environmentObject(RSSReader())
                .tabItem(for: Item.heritage)
            HomeView()
                .tabItem(for: Item.home)
            PBHomeView()
                .tabItem(for: Item.third)
            
            PBHomeView()
                .tabItem(for: Item.bookmarks)
        }
        .tabBar(style: CustomTabBarStyle())
        .tabItem(style: CustomTabItemStyle())
        .ignoresSafeArea(.all)
    }
}

Another View

    var stickyHeaderView: some View {
        HStack {
            Text("Heritage").modifier(MainStoryTitle(color: "BlackDark"))
            Spacer()
            NavigationLink (
                destination:
                    HeritageHomeView()
            ) {
                Image(systemName: "arrow.up.forward")
                    .foregroundColor(Color("Orange"))
            }
        }
        .padding(.horizontal, 30)

    }

Using environmental size classes

Is there a way to use environmental size classes when defining a custom TabItemStyle?

I would like to show text bellow the icon when the app has a .regular .horizontalSizeClass, and only show the icon when it is .compact. With the current implementation I'm not really sure how to do it in a way that the size class variable gets updated correctly and I don't get "Accessing Environment<Optional<UserInterfaceSizeClass>>'s value outside of being installed on a View. This will always read the default value and will not update."

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.