https://github.com/benedom/autoresizingsheet
Use automagically self-resizing sheets in Swift
https://github.com/benedom/autoresizingsheet
animation bottomsheet ios resizing sheet swift swift-package-manager swift5 swiftui uikit
Last synced: about 2 months ago
JSON representation
Use automagically self-resizing sheets in Swift
- Host: GitHub
- URL: https://github.com/benedom/autoresizingsheet
- Owner: benedom
- License: mit
- Created: 2024-03-13T13:07:03.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2024-12-28T20:30:34.000Z (5 months ago)
- Last Synced: 2025-04-05T10:04:18.626Z (about 2 months ago)
- Topics: animation, bottomsheet, ios, resizing, sheet, swift, swift-package-manager, swift5, swiftui, uikit
- Language: Swift
- Homepage:
- Size: 11 MB
- Stars: 9
- Watchers: 1
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# AutoResizingSheet
[](https://github.com/benedom/AutoResizingSheet/actions/workflows/build-swift.yml)
[](https://github.com/benedom/AutoResizingSheet/releases)



![]()
![]()
![]()
![]()
## π Overview
AutoResizingSheet is a SwiftPackage which allows to display sheets which will automatically resize itself with an animation when the content height changes. This is useful when the sheet fetches data, where it is not known how large the content will be.It also works for static sheet content. The height of the sheet is calculated so it matches the content perfectly.
AutoResizingSheet also solves the issue of height detents for different devices. The content in the sheet will automatically be displayed, so that it fits the current device perfectly - no more blank spaces.
AutoResizingSheet can be displayed using a SwiftUI ViewModifier or presented as a UIKit ViewController. See [Usage](#π οΈ-usage) for details.
## π Contents
- [Requirements](#-requirements)
- [Installation](#-installation)
- [Demo App](#π±-demo-app)
- [Usage](#-usage)
- [Contributors](#-contributors)
- [Author](#-author)
- [License](#-license)## π§³ Requirements
- iOS 16.0 or later
- Xcode 15.0 or later
- Swift 5.9 or later## π» Installation
There are two ways to use AutoResizingSheet in your project:
- using Swift Package Manager
- manual install (embed Xcode Project)### Swift Package Manager
The [Swift Package Manager](https://swift.org/package-manager/) is a tool for managing the distribution of Swift code. Itβs integrated with the Swift build system to automate the process of downloading, compiling, and linking dependencies.
To integrate `AutoResizingSheet` into your Xcode project using Xcode 15.0 or later, specify it in `File > Swift Packages > Add Package Dependency...`:
```ogdl
https://github.com/benedom/AutoResizingSheet
```You can also specify a version instead of using the `master` branch.
### Manually
If you prefer not to use any of dependency managers, you can integrate `AutoResizingSheet` into your project manually. Put `Sources/AutoResizingSheet` folder in your Xcode project. Make sure to enable `Copy items if needed` and `Create groups`.
## π± Demo App
To get a feeling how `AutoResizingSheet` works and in what scenarios it can be used, you can run the demo app. The demo app provides multiple sheet implementations to test and also a fully configurable `AutoResizingSheetConfiguration`.
## π οΈ Usage
### SwiftUI
This example shows how to display `AutoResizingSheet` inside a SwiftUI View:
```swift
import SwiftUI
import UIKit
import AutoResizingSheetstruct ExampleView: View {
@State private var showSheet: Bool = falsevar body: some View {
VStack {
Button("Show sheet") {
showSheet.toggle()
}
}
.autoResizingSheet(
isPresented: $showSheet
) {
// Your sheet content View
SheetContentView()
}
}
}
```:bangbang: NOTE :bangbang:
```
The resizing will not work properly if your view is wrapped inside a ScrollView. Use scrollable of AutoResizingSheetConfiguration instead, to make the content scrollable.
```The viewModifier takes multiple parameters:
| Paramter | Description |
| ----------- | ----------- |
| `isPresented` | `Binding`: Binding to control the displaying of the sheet. |
| `configuration` | `AutoResizingSheetConfiguration`: The custom configuration to use. If not set, uses default configuration. |
| `@ViewBuilder content` | `@escaping () -> Content`: The content of the sheet as a SwiftUI View. |
You can also configure `AutoResizingSheet` by passing a `AutoResizingSheetConfiguration`. A configuration has the following properties:| Property | Description |
| ----------- | ----------- |
| `scrollable` | `Bool`: Should the content be wrapped inside a scroll view. Defaults to `true`. |
| `showGrabber` | `Bool`: If the grabber should be shown. Defaults to `true`. |
| `extendableToFullSize` | `Bool`: If the sheet is extendable to full size using the grabber. Defaults to `true`, will be `false` if `showGrabber` is `false`. |
| `scrollBackground` | `UIColor`: If scrollable, defines the background color of the `ScrollView`. Defaults to `.clear`. |Create a configuration like this:
```swift
let configuration = AutoResizingSheetConfiguration(
scrollable: true,
showGrabber: true,
extendableToFullSize: true,
scrollBackground: .clear
)
```and use it like this:
```swift
.autoResizingSheet(
isPresented: $showSheet,
configuration: configuration
) {
// Your sheet content View
SheetContentView()
}
```### UIKit
This example shows how to display `AutoResizingSheet` using a `UIViewController` in UIKit:```swift
func showSheet() {
// Create the view for the sheet content
let sheetContentView = YourSwiftUISheetView()
// Present the sheet
yourViewController.presentViewAsAutoResizingSheet(content: sheetContentView)
}
```The function takes multiple parameters:
| Paramter | Description |
| ----------- | ----------- |
| `content` | `@escaping () -> Content`: The content of the sheet as a SwiftUI View. |
| `configuration` | `AutoResizingSheetConfiguration`: The custom configuration to use. If not set, uses default configuration. |
| `onDismiss` | `(() -> Void)?`: A closure that is executed when the sheet is dismissed. Defaults to `nil`. |Just like using the SwiftUI ViewModifier, you can pass a `AutoResizingSheetConfiguration`.
## π¨βπ» Contributors
All issue reports, feature requests, pull requests and GitHub stars are welcomed and much appreciated.
## βοΈ Author
Benedikt Betz & CHECK24
## π License
`AutoResizingSheet` is available under the MIT license. See the [LICENSE](https://github.com/benedom/SwiftyCrop/blob/master/LICENSE.md) file for more info.