Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wouter125/bottomsheet
An iOS library for SwiftUI to create draggable sheet experiences similar to iOS applications like Maps and Stocks.
https://github.com/wouter125/bottomsheet
bottomsheet ios sheet swift swiftui
Last synced: 3 days ago
JSON representation
An iOS library for SwiftUI to create draggable sheet experiences similar to iOS applications like Maps and Stocks.
- Host: GitHub
- URL: https://github.com/wouter125/bottomsheet
- Owner: Wouter125
- License: mit
- Created: 2022-03-10T20:39:57.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-08-07T22:40:17.000Z (5 months ago)
- Last Synced: 2024-12-14T03:07:21.632Z (10 days ago)
- Topics: bottomsheet, ios, sheet, swift, swiftui
- Language: Swift
- Homepage:
- Size: 83 KB
- Stars: 208
- Watchers: 6
- Forks: 21
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# BottomSheet
An iOS library for SwiftUI to create draggable sheet experiences similar to iOS applications like Maps and Stocks.
## Feature overview
The library currently supports;
- [x] Unlimited snap positions
- [x] Realtime position callback
- [x] Absolute and relative positioning
- [x] Customizable animation parameters
- [x] An optional sticky header
- [x] Views with and without a scrollview## How to install
Currently BottomSheet is only available through the [Swift Package Manager](https://swift.org/package-manager/) or manual install.
1. Installation through Swift Package Manager can be done by going to `File > Add Packages`. Then enter the following URL in the searchbar; `https://github.com/Wouter125/BottomSheet`.
2. Manual installation can be done by cloning this repository and dragging all assets into your Xcode Project.
## How to use
1. Import BottomSheet
2. Create a state property that contains the presentation state of the bottom sheet and one for the current selection;
```
@Published var isPresented = false
@Published var selectedDetent: BottomSheet.PresentationDetent = .medium
```4. Add the `BottomSheetView` to your SwiftUI view hierachy by using a view modifier;
```
.sheetPlus(
isPresented: $isPresented,
header: { },
main: {
EmptyView()
.presentationDetentsPlus(
[.height(244), .fraction(0.4), .medium, .large],
selection: $selectedDetent
)
}
)
```5. Optionally receive the current panel position with a callback, change the background color, show a drag indicator or limit the background interaction based on the height;
```
.sheetPlus(
isPresented: $isPresented,
background: (
Color(UIColor.secondarySystemBackground)
),
onDrag: { translation in
print(translation)
},
header: { EmptyView() },
main: {
EmptyView()
.presentationDetentsPlus(
[.height(244), .fraction(0.4), .medium, .large],
selection: $selectedDetent
)
.presentationDragIndicatorPlus(.visible)
.presentationBackgroundInteractionPlus(.enabled(upThrough: .height(380)))
}
)
```## Interface
| Modifier | Type | Default | Description |
|--------------------------|---------------------|---------|-----------------------------------------------------------------------------------|
| animationCurve.mass | Double | 1.2 | The mass of the object attached to the spring. |
| animationCurve.stiffness | Double | 200 | The stiffness of the spring. |
| animationCurve.damping | Double | 25 | The spring damping value. |## Example
To give you an idea of how to use this library you can use the example that is attached to this repo. Simply clone it and open the `BottomSheetExample` folder in Xcode.
## Roadmap
1. Add landscape support
2. Add iPad support