{"id":18654280,"url":"https://github.com/fatbobman/sheetkit","last_synced_at":"2025-04-11T17:31:11.617Z","repository":{"id":40631734,"uuid":"407041533","full_name":"fatbobman/SheetKit","owner":"fatbobman","description":"an extension library for SwiftUI sheets. ","archived":false,"fork":false,"pushed_at":"2023-09-06T00:28:04.000Z","size":24,"stargazers_count":108,"open_issues_count":3,"forks_count":10,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-25T05:17:05.082Z","etag":null,"topics":["sheet","swift","swiftui","swiftui-extensions"],"latest_commit_sha":null,"homepage":"https://www.fatbobman.com/posts/sheetKit/","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/fatbobman.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":"2021-09-16T06:04:38.000Z","updated_at":"2025-03-13T16:23:00.000Z","dependencies_parsed_at":"2022-07-14T04:20:28.706Z","dependency_job_id":null,"html_url":"https://github.com/fatbobman/SheetKit","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fatbobman%2FSheetKit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fatbobman%2FSheetKit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fatbobman%2FSheetKit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fatbobman%2FSheetKit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fatbobman","download_url":"https://codeload.github.com/fatbobman/SheetKit/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248449705,"owners_count":21105545,"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":["sheet","swift","swiftui","swiftui-extensions"],"created_at":"2024-11-07T07:14:32.947Z","updated_at":"2025-04-11T17:31:11.250Z","avatar_url":"https://github.com/fatbobman.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SheetKit\n\nSheetKit is an extension library for SwiftUI sheets.\n\n[中文版说明 with Picture](https://www.fatbobman.com/posts/sheetKit/)\n\n## What is SheetKit ##\n\nSheetKit is a library of extensions for SwiftUI modal views. It provides several convenient display and cancel methods for modal views, as well as several View Extensions for modal views.\n\nThe main reasons for developing SheetKit.\n\n* Convenient Deep link calls\n  SwiftUI provides the onOpenURL method to make it very easy for applications to respond to Deep Link, but in practice, this is not as easy as expected. The main reason for this is that the important view presentation modes in SwiftUI: NavigationView, Sheet, etc. do not have the ability to be reset quickly and easily. It is difficult to instantly set the application to the view state we want with a couple of lines of code.\n\n* Centralised management of modal views\n  SwiftUI usually uses .sheets to create modal views, which is very intuitive for simple applications, but if the application logic is complex and requires many modal views, this can make the code very messy and difficult to organize. In this case, we usually manage all the modal views centrally and call them all together. See my previous article - Popping up different Sheets on demand in SwiftUI.\n\n* The new UISheetPresentationController\n  In WWDC 2021, Apple brought the long-awaited half-height modal view to everyone. The SheetKit makes up for it for now, but perhaps in a bit of a hurry, as there is no SwiftUI version of this popular interaction, only UIKit support. Both sheets, fullScreenCover and bottomSheet (half-height modal view) are fully supported and managed in one place.\n\n## System requirements##\n\niOS 15\n\nSwift 5.5\n\nXCode 13.0 +\n\n\n## How to use ##\n\n### present ###\n\n```swift\nButton(\"show sheet\"){\n   SheetKit().present{\n     Text(\"Hello world\")\n   }\n}\n```\n\nor \n\n```swift\n@Environment(\\.sheetKit) var sheetKit\n\nButton(\"show sheet\"){\n   sheetKit.present{\n     Text(\"Hello world\")\n   }\n}\n```\n\nsupport multiSheet\n\n```swift\n@Environment(\\.sheetKit) var sheetKit\n\nButton(\"show sheet\"){\n   sheetKit.present{\n     Button(\"show full sheet\"){\n       sheetKit.present(with:.fullScreenCover){\n         Text(\"Hello world\")\n       }\n     }\n   }\n}\n```\n\n### sheet style ###\n\nthree types sytle:\n* sheet\n* fullScreenCover\n* bottomSheet\n\n```swift\nsheetKit.present(with: .bottomSheet){\n  Text(\"Hello world\")\n}\n```\n\ncustom bottomSheet\n\n```swift\nlet configuration = SheetKit.BottomSheetConfiguration(  detents: [.medium(),.large()],\n                                                        largestUndimmedDetentIdentifier: .medium,\n                                                        prefersGrabberVisible: true,\n                                                        prefersScrollingExpandsWhenScrolledToEdge: false,\n                                                        prefersEdgeAttachedInCompactHeight: false,\n                                                        widthFollowsPreferredContentSizeWhenEdgeAttached: true,\n                                                        preferredCornerRadius: 100)\n\nsheetKit.present(with: .customBottomSheet,configuration: configuration) {\n  Text(\"Hello world\")\n}\n```\n\nget notice when bottomSheet modal changed\n\n```swift\n@State var detent:UISheetPresentationController.Detent.Identifier = .medium\n\nButton(\"Show\"){\n  sheetKit.present(with: .bottomSheet,detentIdentifier: $detent){\n    Text(\"Hello worl\")\n  }\n}\n.onChange(of: detent){ value in\n    print(value)\n}\n```\n\nor \n\n```swift\n@State var publisher = NotificationCenter.default.publisher(for: .bottomSheetDetentIdentifierDidChanged, object: nil)\n\n.onReceive(publisher){ notification in\n       guard let obj = notification.object else {return}\n       print(obj)\n}\n```\n\n### dismissAllSheets ###\n\n```swift\n SheetKit().dismissAllSheets(animated: false, completion: {\n        print(\"sheet has dismiss\")\n    })\n```\n\n### dismiss ###\n\n```swift\n SheetKit().dismiss()\n```\n\n### interactiveDismissDisabled ###\n\nSwiftUI 3.0's interactiveDismissDisabled enhancement adds the ability to be notified when a user uses a gesture to cancel, on top of the ability to control whether gesture cancellation is allowed via code.\n\n```swift\nstruct ContentView: View {\n    @State var sheet = false\n    var body: some View {\n        VStack {\n            Button(\"show sheet\") {\n                sheet.toggle()\n            }\n        }\n        .sheet(isPresented: $sheet) {\n            SheetView()\n        }\n    }\n}\n\nstruct SheetView: View {\n    @State var disable = false\n    @State var attempToDismiss = UUID()\n    var body: some View {\n        VStack {\n            Button(\"disable: \\(disable ? \"true\" : \"false\")\") {\n                disable.toggle()\n            }\n            .interactiveDismissDisabled(disable, attempToDismiss: $attempToDismiss)\n        }\n        .onChange(of: attempToDismiss) { _ in\n            print(\"try to dismiss sheet\")\n        }\n    }\n}\n```\n\n### clearBackground ###\n\nSet the background of the modal view to transparent. In SwiftUI 3.0, it is already possible to generate various hair-glass effects using the native API. However, the hair glass effect is only visible if the background of the modal view is set to transparent.\n\n```swift\nZStack {\n            Rectangle().fill(LinearGradient(colors: [.red, .green, .pink, .blue, .yellow, .cyan, .gray], startPoint: .topLeading, endPoint: .bottomTrailing))\n            Button(\"Show bottomSheet\") {\n                sheetKit.present(with: .bottomSheet, afterPresent: { print(\"presented\") }, onDisappear: { print(\"disappear\") }, detentIdentifier: $detent) {\n                    ZStack {\n                        Rectangle()\n                            .fill(.ultraThinMaterial)\n                        VStack {\n                            Text(\"Hello world\")\n                            Button(\"dismiss all\") {\n                                SheetKit().dismissAllSheets(animated: true, completion: {\n                                    print(\"sheet has dismiss\")\n                                })\n                            }\n                        }\n                    }\n                    .clearBackground()\n                    .ignoresSafeArea()\n                }\n            }\n            .foregroundColor(.white)\n            .buttonStyle(.bordered)\n            .controlSize(.large)\n            .tint(.green)\n        }\n        .ignoresSafeArea()\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffatbobman%2Fsheetkit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffatbobman%2Fsheetkit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffatbobman%2Fsheetkit/lists"}