All Projects → NicholasBellucci → Statefultabview

NicholasBellucci / Statefultabview

Licence: mit
A SwiftUI TabView that retains the state of each tab as well as some other goodies.

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Statefultabview

Dtpagercontroller
A fully customizable container view controller to display a set of ViewControllers in a horizontal scroll view. Written in Swift.
Stars: ✭ 240 (+189.16%)
Mutual labels:  xcode, swift-package-manager
Swift5 Module Template
An opinionated starting point for awesome, reusable Swift 5 modules
Stars: ✭ 331 (+298.8%)
Mutual labels:  xcode, swift-package-manager
Roundcode
Custom rounded QR code with lots of customization.
Stars: ✭ 267 (+221.69%)
Mutual labels:  xcode, swift-package-manager
Cdmarkdownkit
An extensive Swift framework providing simple and customizable markdown parsing.
Stars: ✭ 158 (+90.36%)
Mutual labels:  xcode, swift-package-manager
Bfkit Swift
BFKit-Swift is a collection of useful classes, structs and extensions to develop Apps faster.
Stars: ✭ 963 (+1060.24%)
Mutual labels:  xcode, swift-package-manager
Carting
🚘 A simple tool for updating Carthage script phase
Stars: ✭ 182 (+119.28%)
Mutual labels:  xcode, swift-package-manager
Loadingshimmer
An easy way to add a shimmering effect to any view with just one line of code. It is useful as an unobtrusive loading indicator.
Stars: ✭ 1,180 (+1321.69%)
Mutual labels:  xcode, swift-package-manager
Surmagic
🚀 The better way to deal with Binary Frameworks on iOS, Mac Catalyst, tvOS, macOS, and watchOS. Create XCFrameworks with ease.
Stars: ✭ 119 (+43.37%)
Mutual labels:  xcode, swift-package-manager
Swiftlyext
SwiftlyExt is a collection of useful extensions for Swift 3 standard classes and types 🚀
Stars: ✭ 31 (-62.65%)
Mutual labels:  xcode, swift-package-manager
Brisk
A proof of concept scripting library for Swift
Stars: ✭ 478 (+475.9%)
Mutual labels:  xcode, swift-package-manager
Licenseplist
A license list generator of all your dependencies for iOS applications
Stars: ✭ 1,996 (+2304.82%)
Mutual labels:  xcode, swift-package-manager
Dtgradientbutton
Easy way to set gradient background to your buttons.
Stars: ✭ 76 (-8.43%)
Mutual labels:  xcode, swift-package-manager
Natrium
A pre-build (Swift) script to alter your Xcode project at pre-build-time per environment, build configuration and target.
Stars: ✭ 131 (+57.83%)
Mutual labels:  xcode, swift-package-manager
Dtphotoviewercontroller
A fully customizable photo viewer ViewController to display single photo or collection of photos, inspired by Facebook photo viewer.
Stars: ✭ 212 (+155.42%)
Mutual labels:  xcode, swift-package-manager
Swift Xcode
Use Swift Package Manager directly from within Xcode, w/o the cmdline
Stars: ✭ 121 (+45.78%)
Mutual labels:  xcode, swift-package-manager
Containercontroller
UI Component. This is a copy swipe-panel from app: Apple Maps, Stocks. Swift version
Stars: ✭ 273 (+228.92%)
Mutual labels:  xcode, swift-package-manager
Swifterswift
A handy collection of more than 500 native Swift extensions to boost your productivity.
Stars: ✭ 10,706 (+12798.8%)
Mutual labels:  xcode, swift-package-manager
Alamofire
Elegant HTTP Networking in Swift
Stars: ✭ 36,896 (+44353.01%)
Mutual labels:  xcode, swift-package-manager
Xcbeautify
A little beautifier tool for xcodebuild
Stars: ✭ 372 (+348.19%)
Mutual labels:  xcode, swift-package-manager
Xclogparser
Tool to parse Xcode and xcodebuild logs stored in the xcactivitylog format
Stars: ✭ 978 (+1078.31%)
Mutual labels:  xcode, swift-package-manager

StatefulTabView

A SwiftUI UITabBarController implementation that retains state between tab changes. Big thanks to Amzd and everyone who helped to refine this gist as it was a major jumping off point for setting up this project.

Requirements

  • iOS 13.0+
  • Xcode 11.2+
  • Swift 5+

Installation

Swift Package Manager

In Xcode 11 or greater, navigate to File > Swift Packages > Add Package Dependency.... From there just simply add https://github.com/NicholasBellucci/StatefulTabView as the package repository url and use the master branch or the most recent version. Master will always be inline with the newest release.

Table of Contents

Features

  • [x] State driven selected index
  • [x] TabBar appearance configuration
  • [x] TabBar custom tint color
  • [x] TabBar custom background color
  • [x] TabBarItem custom title and image
  • [x] TabBarItem badge value
  • [x] State retention from tab to tab
  • [x] Pop to root functionality when selecting the already selected tab
  • [x] Scroll to top functionality when selecting the already selected tab at the root view

Usage

Setting up StatefulTabView is relatively simple and works similar to the native TabView. The main difference is that the content of the tabs is wrapped in a Tab struct. There is no limitation on how many tabs can be used. Once more than 5 are used, the Apple standard more tab will become available. Feel free to check out the example project for the exact usage.

Basic

StatefulTabView {
    Tab(title: "Tab 1", systemImageName: "circle.fill") {
        NavigationView {
            List {
                Section {
                    ForEach(0..<20, id: \.self) { index in
                        NavigationLink(destination: PushedView(text: "Pushed number \(index)")) {
                            Text("\(index)")
                        }
                    }
                }
            }
            .navigationBarTitle("Navigation View 1")
        }
    }
}

Appearance Modifications

All appearance modifications can be made by using extensions for the StatefulTabView.

StatefulTabView {
    ...
}
.barTintColor(.red)
.unselectedItemTintColor(.green)
.barBackgroundColor(.yellow)
.barAppearanceConfiguration(.transparent)

Selected Index

The selected index of the StatefulTabView can be set within the initializer. The passed value is a binding.

@State var selectedIndex: Int = 2

StatefulTabView(selectedIndex: $selectedIndex) {
    ...
}

Badge Value

The TabBarItem badge value can be set in the initializer of a Tab.

@State var badgeValue: String = "1"

Tab(title: "Tab 1", systemImageName: "circle.fill", badgeValue: badgeValue) {
    ...
}

Scroll to Top with Large Titles

Scroll to top is handled when selecting the already selected tab that contains a scrollView in the heirarchy. The only issue is that large titles in navigation bars are not factored in when calling scrollRectToVisible(CGRect(x: 0, y: 0, width: 1, height: 1), animated: true) for obvious reasons. Due to this limitation adding .prefersLargeTitle(true) to a Tab will fix this issue. For root navigation views that do not use a large title no change to a Tab is needed.

Tab(title: "Tab 1", systemImageName: "circle.fill") {
    NavigationView {
        List {
            ...
        }
        .navigationBarTitle("Navigation View 1", displayMode: .large)
    }
}
.prefersLargeTitle(true)

License

StatefulTabView is, and always will be, MIT licensed. See LICENSE for details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].