BottomSheet makes it easy to take advantage of the new UISheetPresentationController in SwiftUI with a simple .bottomSheet modifier on existing views.

Overview

BottomSheet

Feature Graphic Platform

BottomSheet makes it easy to take advantage of the new UISheetPresentationController in SwiftUI with a simple .bottomSheet modifier on existing views.

  1. Requirements
  2. Integration
  3. Usage

Requirements

  • iOS 15+
  • Xcode 13+

Integration

Swift Package Manager

BottomSheet can be added to your app via Swift Package Manager in Xcode using the following configuration:

dependencies: [
    .package(url: "https://github.com/adamfootdev/BottomSheet.git", from: "0.1.3")
]

Usage

To get started with BottomSheet, you'll need to import the framework first:

import BottomSheet

Presenting the Sheet

You can then apply the .bottomSheet modifier to any SwiftUI view, ensuring you attach a binding to the isPresented property - just like the standard .sheet modifier:

.bottomSheet(isPresented: $isPresented) {
    Text("Hello, world!")
}

BottomSheet also supports passing an Optional item to it, displaying the sheet if the item is not nil:

.bottomSheet(item: $item) {
    Text("Hello, world!")
}

Customizing the Sheet

BottomSheet can be customized in the same way a UISheetPresentationController can be customized in UIKit. This is done by specifying additional properties in the modifier:

.bottomSheet(
    isPresented: $isPresented,
    detents: [.medium(), .large()],
    prefersGrabberVisible: true,
    smallestUndimmedDetentIdentifier: nil,
    prefersScrollingExpandsWhenScrolledToEdge: true,
    prefersEdgeAttachedInCompactHeight: false,
    widthFollowsPreferredContentSizeWhenEdgeAttached: false
) {
    Text("Hello, world!")
}

For more information on UISheetPresentationController, read Apple's documentation: https://developer.apple.com/documentation/uikit/uisheetpresentationcontroller

Please note BottomSheet is currently missing the ability to be resized programmatically as the delegate doesn't work in iOS 15 beta 1. You may also run into issues when used on an iPad with multi-window support and have multiple instances of the same app side-by-side running.

Comments
  • 'shared' is unavailable in application extensions for iOS

    'shared' is unavailable in application extensions for iOS

    I'm trying to implement BottomSheet with Xcode 13 beta 3 and iOS 15 beta 3 but I get this compiler error:

    'shared' is unavailable in application extensions for iOS: Use view controller based solutions where appropriate instead.

    Perhaps this has changed in a recent iOS 15 beta?

    opened by lvandal 6
  • contentView not updated when state in containing view changes

    contentView not updated when state in containing view changes

    In the following example, the sheet content is not updated when the 'Add' button is pressed:

    class ExampleModel: ObservableObject {
        var rows: [String] = []
    }
    
    struct ContentView: View {
        @State private var bottomSheetPresented = false
        @StateObject var exampleModel = ExampleModel()
    
        var body: some View {
            VStack {
                Button("Show Sheet") {
                    bottomSheetPresented = true
                }
            }
            .onAppear {
                bottomSheetPresented = true
            }
            .ignoresSafeArea()
            .bottomSheet(
                isPresented: $bottomSheetPresented,
                contentView: {
                    List {
                        Button("Add") {
                            exampleModel.rows.append("Foo")
                        }
                        ForEach(exampleModel.rows, id: \.self) { row in
                            Text(row)
                        }
                    }
                }
            )
        }
    }
    

    This works for a plain .sheet. Extracting the contentView in a separate View struct and making it observe the model as well does the trick as a workaround.

    opened by ralfebert 4
  • No sheet appearing when isPresented is initially true

    No sheet appearing when isPresented is initially true

    No sheet appears for this example (0.2.2, Simulator in Xcode 13 Beta 5):

    import SwiftUI
    import BottomSheet
    
    struct ContentView: View {
        @State private var bottomSheetPresented = true
        
        var body: some View {
            Color.yellow
                .ignoresSafeArea()
                .bottomSheet(isPresented: $bottomSheetPresented) {
                    Text("Hello, world!")
                }
        }
    }
    

    The interactive version works:

    struct ContentView: View {
        @State private var bottomSheetPresented = false
        
        var body: some View {
            VStack {
                Button("Show Sheet") {
                    bottomSheetPresented = true
                }
            }
            .bottomSheet(isPresented: $bottomSheetPresented) {
                Text("Hello, world!")
            }
        }
    }
    

    Is there a way to get a sheet that's permanently visible / is it supposed to work with isPresented == true initially?

    opened by ralfebert 4
  • Removed smallestUndimmedDetentIdentifier

    Removed smallestUndimmedDetentIdentifier

    Removed smallestUndimmedDetentIdentifier because it has been deprecated as of Xcode 13 beta 3. There doesn't appear to be any replacement for it.

    https://developer.apple.com/documentation/uikit/uisheetpresentationcontroller/3801909-smallestundimmeddetentidentifier?changes=_2_1

    opened by Rspoon3 2
  • Prevent dismissal

    Prevent dismissal

    Hi there, Thanks a lot for making & sharing this library!

    Could you add the option to prevent dismissal? I have a map beneath the sheet, so the sheet is supposed to stay opened.

    opened by LinusGeffarth 1
  • BottomSheet content does not update after initial render

    BottomSheet content does not update after initial render

    Hey there! I'm having an issue where the contents of the bottom sheet does not change after initial render even though the content view build is re-run and returns a new view.

    My code looks something like the following:

    .bottomSheet(item: self.$selectedItem, detents: [.medium()], prefersGrabberVisible: true) {
        if let item = self.selectedItem {
            Text("Item: \(item.title)")
        } else {
            Text("No item selected").
        }
    }
    

    When initially rendering this the view which has the bottomSheet modifier, self.$selectedItem is nil and thus the bottom sheet is not presented but the content view builder is invoked. This is expected. The initial render will produce the "No item selected" label.

    When self.$selectedItem is updated to refer to a selected item I want the bottom sheet to be presented and display the item's title. What happens instead is that the bottom sheet is presented but displays "No item selected". Using breakpoints in Xcode I can confirm that the content view builder re-invoked when an item is selected and the correct branch of the if statement is invoked, so it should be displaying my item title. It seems that the hosting view controller is not updated with the new content view though.

    opened by emilsjolander 1
  • Project won't compile after installing the package

    Project won't compile after installing the package

    after installing the library, I get this error: Screen Shot 2021-09-10 at 7 57 59 AM

    I think this thread will help a lot in fixing this issue: https://twitter.com/twannl/status/1415643862761152513

    opened by NaifAlrashed 1
  • Fix missing content view on first render

    Fix missing content view on first render

    This PR fixes the bug where the content view is missing on the first render. Basically, the content view is not built during initialization. Instead, it is built when it is passed to the view controller.

    This fixes both #10 and #11.

    opened by rmnblm 0
  • Allows the selected detent to be updated programmatically

    Allows the selected detent to be updated programmatically

    Allows the user to pass a binding to a detent identifier when instantating a bottom sheet, giving the ability to get and set the selected detent/size.

    opened by tomhut 0
  • Allow import into projects with min target < iOS 15, presentedViewController chaining fix

    Allow import into projects with min target < iOS 15, presentedViewController chaining fix

    I had a use for this package in a project that cannot require iOS 15 yet, though current config didn't allow for that use case. Setting an older minimum for the package but annotating the views and extensions with @available(iOS 15, *) keeps usage as intended.

    Also found an issue where in a stack of presented view controllers the bottom sheet would not be presented, this is because the view controller this bottom sheet would be presented from is not at the top of the stack. Fix was just to follow the .presentedViewController chain to find the top most presented view controller.

    opened by camdeardorff 0
  • Add .bottomSheet(item: Binding<Optional<T>>) modifier

    Add .bottomSheet(item: Binding>) modifier

    This PR adds the second overload of standard sheets: A binding to an optional item, that presents the sheet if the item is not nil.

    I would have liked to also change the contentView closure to take in the item (unwrapped), but that would have meant rewriting a lot of other code, which I think would overcomplicate things.

    opened by chFlorian 0
  • onDismiss never called !

    onDismiss never called !

    Hi, I notice anythings inside onDismiss never called ! when I change it back to sheet onDismiss does called

    so I think there is issue with the logic on your library could you fix it ?

    opened by X901 0
  • add background color when BottomSheet open

    add background color when BottomSheet open

    Hi, I think it's important to have background color on BottomSheet

    I tried to add it like this

     func body(content: Content) -> some View {
            ZStack {
            content
                .onChange(of: isPresented, perform: updatePresentation)
                .onChange(of: selectedDetentIdentifier, perform: updateSelectedDetentIdentifier)
                
                if isPresented {
                 Color.black.opacity(0.5).ignoresSafeArea()
                        .animation(.easeIn, value: isPresented)
                }
            }
        }
    
    

    But I notice it take awhile until the background disappeared after bottomSheet closed is there a better way to do it ?

    opened by X901 0
  • blurred or transparent background instead of opaque white

    blurred or transparent background instead of opaque white

    I am not too familiar with UIKits UISheetPresentationController, but it would be quite useful to be able to define a material/blur and an opacity to the sheets background.

    Is that in the scope of this package? If not, where would be the point to add the feature in a custom branch, would it be around here?: https://github.com/adamfootdev/BottomSheet/blob/main/Sources/BottomSheet/View%20Controllers/BottomSheetViewController.swift#L63

    I imagine it could be done by inserting a UIVisualEffectView with UIBlurEffect just before the contentView is added there.

    opened by nylki 1
  • Pass in item to ContentView

    Pass in item to ContentView

    When binding to an optional item. What are your thoughts on passing the item to the content view?

    Similar to the sheet modifier.

    func sheet<Item, Content>(item: Binding<Item?>, onDismiss: (() -> Void)? = nil, content: @escaping (Item) -> Content) -> some View where Item : Identifiable, Content : View
    
    opened by corysullivan 3
  • Feature request: Set preferredContentSize

    Feature request: Set preferredContentSize

    Hi, thanks for making this!

    I was watching the WWDC sheets session and at around the 9:15 mark, Russell mentions that the sheet should respect a preferredContentSize if widthFollowsPreferredContentSizeWhenEdgeAttached = true.

    I was wondering if it would be possible to automatically set preferredContentSize in this component to something like view.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize) so that the sheet only takes up the width of the contentView?

    Or alternatively provide a way to set a preferredContentSize?

    I failed to get this to work, but I was hoping you would know how to do it.

    Here's the example from the session:

    Before:

    large

    After:

    small

    opened by benubois 1
Owner
Adam Foot
iOS Developer (Swift)
Adam Foot
PageSheet - Customizable sheets using UISheetPresentationController in SwiftUI

PageSheet Customizable sheet presentations in SwiftUI. Using UISheetPresentation

Eric Lewis 50 Oct 7, 2022
Multiplatform (iOS, macOS) SwiftUI bottom sheet drawer. Expandable bottomsheet. Slide out bottom menu

Multiplatform (iOS, macOS) SwiftUI bottom sheet drawer Features It does not re-render the background content while manipulating with the sheet iOS and

Igor 8 Nov 18, 2022
This is a small View modifier that adds detents for native .sheet representations that appeared in iOS 16

SheetDetentsModifier This is a small View modifier that adds detents for .sheet representations that appeared in iOS 16 It works starting with iOS 15

Alex Artemev 19 Oct 9, 2022
BottomSheet Component 🧪🧪🧪

BCSComponent This Source code provide a bottom sheet which allow you custom own cell,you able to show it on the bottom sheet Get started First thing f

Kien Pham 3 Dec 1, 2022
Highly configurable iOS Alert Views with custom content views

NYAlertViewController NYAlertViewController is a replacement for UIAlertController/UIAlertView with support for content views and UI customization. Fe

Nealon Young 609 Nov 20, 2022
It is a highly configurable iOS library which allows easy styling with built in styles as well as extra header and footer views so that you can make extremely unique alerts and action sheets.

 CFAlertViewController CFAlertViewController is a library that helps you display and customise Alerts, Action Sheets, and Notifications on iPad and i

Crowdfire Inc. 1.1k Dec 18, 2022
💬 A tiny extension for UIAlertController that makes working with it very simple. Only 150 lines of code.

AlertController ?? A tiny extension for UIAlertController that makes working with it very simple. Only 150 lines of code. Alert let alert = UIAlertCon

Mezhevikin Alexey 9 Nov 2, 2022
Whisper is a component that will make the task of display messages and in-app notifications simple. It has three different views inside

Description ?? Break the silence of your UI, whispering, shouting or whistling at it. Whisper is a component that will make the task of displaying mes

HyperRedink 3.7k Dec 25, 2022
A SwiftUI wrapper of the new UIKit sheetPresentationController's capabilities in iOS15.

BottomSheet Bring to SwiftUI the UIKit bottom sheet capabilities that came with iOS15. Usage Show the bottom sheet Button(action: { show.toggle() }) {

Kaww 8 Dec 29, 2022
A customizable framework to create draggable views

CFNotify CFNotify is written in Swift. Using UIKit Dynamics as animator. It can make ANY UIView object draggable and throwable. This library mainly us

Johnny Tsoi 491 Nov 20, 2022
A customizable framework to create draggable views

CFNotify CFNotify is written in Swift. Using UIKit Dynamics as animator. It can make ANY UIView object draggable and throwable. This library mainly us

Johnny Tsoi 491 Nov 20, 2022
Action sheet allows including your custom views and buttons.

CustomizableActionSheet Action sheet allows including your custom views and buttons. Installation CocoaPods Edit your Podfile: pod 'CustomizableAction

Ryuta Kibe 191 Nov 26, 2021
(Experimental libraries) Controls interrupt handling, such as alert views, and is compatible with UIKit and Swift UI.

UIPresentCoordinator Controls interrupt handling, such as alert views, and is compatible with UIKit and Swift UI. This library manages items that are

Yuki Tamazawa 1 Jan 22, 2022
An infinite scroll control implemented with two views.

LCCycleBanner An infinite scroll control implemented with two views. Requirements iOS 9.0+ Swift 4.0+ Programming in Objective-C? Try LCInfiniteScroll

LiuChang 3 Jun 13, 2022
Customizable simple Alert and simple ActionSheet for Swift

SimpleAlert It is simple and easily customizable alert. Can be used as UIAlertController. Appetize's Demo Requirements Swift 5.0 iOS 9.0 or later How

Kyohei Ito 397 Dec 6, 2022
Easy Swift UIAlertController

EZAlertController Easy Swift UIAlertController One line setup for all UIAlertControllers Button action with closures instead of selectors Easily custo

Kan Yilmaz 366 Sep 14, 2022
🍞 Loaf is a Swifty Framework for Easy iOS Toasts

Loaf ?? Inspired by Android's Toast, Loaf is a Swifty Framework for Easy iOS Toasts Usage From any view controller, a Loaf can be presented by calling

Mat Schmid 995 Dec 28, 2022
A Swift package for iOS/tvOS for easy alert presentation

AlertPresenter Listed on the Swift Package Index and originally posted on my blog. It can be fiddly to handle the presentation of alerts on a specific

Chris Mash 14 Jul 1, 2022
💌 Easy to use and customizable messages/notifications for iOS à la Tweetbot

Notice: TSMessages is no longer being maintained/updated. We recommend everyone migrate to RMessage. This repository will be kept as is for those who

Felix Krause 4.9k Dec 31, 2022