{"id":13779186,"url":"https://github.com/NicholasBellucci/StatefulTabView","last_synced_at":"2025-05-11T12:32:54.206Z","repository":{"id":36999260,"uuid":"262447545","full_name":"NicholasBellucci/StatefulTabView","owner":"NicholasBellucci","description":"A SwiftUI TabView that retains the state of each tab as well as some other goodies.","archived":false,"fork":false,"pushed_at":"2022-10-31T17:03:30.000Z","size":51,"stargazers_count":324,"open_issues_count":0,"forks_count":25,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-06T15:12:45.440Z","etag":null,"topics":["swift-package-manager","swiftui","tabview","xcode"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/NicholasBellucci.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-05-08T23:16:51.000Z","updated_at":"2025-02-24T15:50:46.000Z","dependencies_parsed_at":"2022-08-19T00:11:22.901Z","dependency_job_id":null,"html_url":"https://github.com/NicholasBellucci/StatefulTabView","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NicholasBellucci%2FStatefulTabView","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NicholasBellucci%2FStatefulTabView/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NicholasBellucci%2FStatefulTabView/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NicholasBellucci%2FStatefulTabView/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NicholasBellucci","download_url":"https://codeload.github.com/NicholasBellucci/StatefulTabView/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253567334,"owners_count":21928817,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["swift-package-manager","swiftui","tabview","xcode"],"created_at":"2024-08-03T18:01:02.270Z","updated_at":"2025-05-11T12:32:53.947Z","avatar_url":"https://github.com/NicholasBellucci.png","language":"Swift","funding_links":[],"categories":["TabBar-and-Tabs"],"sub_categories":["Content"],"readme":"# StatefulTabView\n\nA SwiftUI UITabBarController implementation that retains state between tab changes. Big thanks to [Amzd](https://gist.github.com/Amzd) and everyone who helped to refine this [gist](https://gist.github.com/Amzd/2eb5b941865e8c5cccf149e6e07c8810) as it was a major jumping off point for setting up this project.\n\n#### Requirements\n- iOS 13.0+\n- Xcode 11.2+\n- Swift 5+\n\n## Installation\n\n### Swift Package Manager\nIn Xcode 11 or greater, navigate to `File \u003e Swift Packages \u003e 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.\n\n## Table of Contents\n   * [Features](#features)\n   * [Usage](#usage)\n        * [Basic](#basic)\n        * [Appearance Modifications](#appearance-modifications)\n        * [Selected Index](#selected-index)\n        * [Badge Value](#badge-value)\n        * [Scroll to Top with Large Titles](#scroll-to-top-with-large-titles)\n   * [License](#license)\n\n## Features\n- [x] State driven selected index\n- [x] TabBar appearance configuration\n- [x] TabBar custom tint color\n- [x] TabBar custom background color\n- [x] TabBarItem custom title and image\n- [x] TabBarItem badge value\n- [x] State retention from tab to tab\n- [x] Pop to root functionality when selecting the already selected tab\n- [x] Scroll to top functionality when selecting the already selected tab at the root view\n\n## Usage\n\nSetting 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.\n\n### Basic\n```Swift\nStatefulTabView {\n    Tab(title: \"Tab 1\", systemImageName: \"circle.fill\") {\n        NavigationView {\n            List {\n                Section {\n                    ForEach(0..\u003c20, id: \\.self) { index in\n                        NavigationLink(destination: PushedView(text: \"Pushed number \\(index)\")) {\n                            Text(\"\\(index)\")\n                        }\n                    }\n                }\n            }\n            .navigationBarTitle(\"Navigation View 1\")\n        }\n    }\n}\n```\n\n### Appearance Modifications\n\nAll appearance modifications can be made by using extensions for the StatefulTabView.\n\n```Swift\nStatefulTabView {\n    ...\n}\n.barTintColor(.red)\n.unselectedItemTintColor(.green)\n.barBackgroundColor(.yellow)\n.barAppearanceConfiguration(.transparent)\n```\n\n### Selected Index\n\nThe selected index of the StatefulTabView can be set within the initializer. The passed value is a binding.\n\n```Swift\n@State var selectedIndex: Int = 2\n\nStatefulTabView(selectedIndex: $selectedIndex) {\n    ...\n}\n```\n\n### Badge Value\n\nThe TabBarItem badge value can be set in the initializer of a Tab.\n\n```Swift\n@State var badgeValue: String = \"1\"\n\nTab(title: \"Tab 1\", systemImageName: \"circle.fill\", badgeValue: badgeValue) {\n    ...\n}\n```\n\n### Scroll to Top with Large Titles\n\nScroll 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.\n\n```Swift\nTab(title: \"Tab 1\", systemImageName: \"circle.fill\") {\n    NavigationView {\n        List {\n            ...\n        }\n        .navigationBarTitle(\"Navigation View 1\", displayMode: .large)\n    }\n}\n.prefersLargeTitle(true)\n```\n\n## License\n\nStatefulTabView is, and always will be, MIT licensed. See [LICENSE](LICENSE) for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNicholasBellucci%2FStatefulTabView","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FNicholasBellucci%2FStatefulTabView","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNicholasBellucci%2FStatefulTabView/lists"}