LBBottomSheet gives you the ability to present a controller in a kind of

Overview

LBBottomSheet

Installation

Swift Package Manager

To install using Swift Package Manager, in Xcode, go to File > Add Packages..., and use this URL to find the LBBottomSheet package: https://github.com/LunabeeStudio/LBBottomSheet.git

After adding this Swift Package to your project, you have to import the module:

import LBBottomSheet

Usage

The BottomSheet gives you the ability to present a controller in a kind of "modal" for which you can choose the height you want.

The are 3 differents ways of configuring the BottomSheet height represented by the HeightMode enum.
Here are the available height modes:

HeightMode Description
fitContent The bottom sheet will call preferredHeightInBottomSheet on the embedded controller to get the needed height.
free The bottom sheet height will be contained between minHeight and maxHeight and the bottom sheet will remain where the user releases it.
specific The bottom sheet will have multiple height values. When the user releases it, it will be attached to the nearest provided specific value. When presented, the bottom sheet will use the minimum value. It can be swipped up to the maximum value. You don't have to take care of the values order, the bottom sheet will sort them to find the matching one.

We'll see through the following examples, how you can configure it (don't hesitate to look at the documentation to see all what you can do).

FitContent - Example #1

To show MyViewController in a bottom sheet above the current controller, you just need to call this from a view controller:

let controller: MyViewController = .init()
presentAsBottomSheet(controller)

A default Theme and a default Behavior will be used.

In this example, the grabber background is transparent. This way you see the tableView content behind the grabber when scrolling, which is the default configuration. Let's see in the next example how to configure this.

FitContent - Example #2

If you want, you can provide your own Theme and Behavior configurations.
For example, here we customize the grabber background and the swipeMode:

let controller: MyViewController = .init()
let grabberBackground: BottomSheetController.Theme.Grabber.Background = .color(.tableViewBackground.withAlphaComponent(0.9), isTranslucent: true)
let grabber: BottomSheetController.Theme.Grabber = .init(background: grabberBackground)
let theme: BottomSheetController.Theme = .init(grabber: grabber)
let behavior: BottomSheetController.Behavior = .init(swipeMode: .full)
presentAsBottomSheet(controller, theme: theme, behavior: behavior)

In this example, the background is translucent and we have a swipeMode set to .full which means that the swipe down gesture will be detected from all the BottomSheet (this is the default behavior).

FitContent - Example #3

In this example, the grabber background is opaque and the swipeMode is set to .top which means that the swipe down gesture will only be detected from the grabber zone:

let controller: MyViewController = .init()
let grabberBackground: BottomSheetController.Theme.Grabber.Background = .color(.tableViewBackground, isTranslucent: false)
let grabber: BottomSheetController.Theme.Grabber = .init(background: grabberBackground)
let theme: BottomSheetController.Theme = .init(grabber: grabber)
let behavior: BottomSheetController.Behavior = .init(swipeMode: .top)
presentAsBottomSheet(controller, theme: theme, behavior: behavior)


FitContent - Example #4

By default, the BottomSheet prevents you from interacting with the controller presenting it (like a standard modal).
It is possible to configure this in the Behavior using this parameter: forwardEventsToRearController.
This way you can continue to interact with the controller behind it. For a better experience, we advise you to set the dimmingBackgroundColor color to .clear and to implement the BottomSheetPositionDelegate on the controller presenting your BottomSheet to dynamically adapt its bottom content inset if needed.
Here is the BottomSheet configuration code:

let controller: MyViewController = .init()
let grabberBackground: BottomSheetController.Theme.Grabber.Background = .color(.tableViewBackground, isTranslucent: false)
let grabber: BottomSheetController.Theme.Grabber = .init(background: grabberBackground)
let theme: BottomSheetController.Theme = .init(grabber: grabber, dimmingBackgroundColor: .clear)
let behavior: BottomSheetController.Behavior = .init(swipeMode: .full, forwardEventsToRearController: true)
presentAsBottomSheet(controller, theme: theme, behavior: behavior)

Here is the BottomSheetPositionDelegate implementation on the controller presenting the BottomSheet:

extension MainViewController: BottomSheetPositionDelegate {
    func bottomSheetPositionDidUpdate(y: CGFloat) {
        tableView.contentInset.bottom = tableView.frame.height - y
    }
}

This will prevent you from having content hidden by the BottomSheet in case you need to interact with it.

FitContent - Advanced configuration

In this mode, by default, the height is automatically calculated:

  • If the BottomSheet contains a UITableView/UICollectionView even if contained in a parent controller, it will use the contentInset top, bottom and the content size height to determine the needed height.
  • Otherwise, it will take the frame height of the embedded controller view.

If you want to customize this calculation, you have to declare this variable on the controller you're embedding en the BottomSheet:

@objc var preferredHeightInBottomSheet: CGFloat { /* Do your custom calculation here */ }

When this variable is declared, the BottomSheet will find and use it instead of the default calculation.

If you present in a BottomSheet a controller for which the height can change while it is visible, you can tell the BottomSheet to update its height in order to keep a height matching the embbeded controller needs. This update is animated by the BottomSheet.
To tell the BottomSheet to update its height, you just have to call this:

bottomSheetController?.preferredHeightInBottomSheetDidUpdate()

bottomSheetController is available in any UIViewController as navigationController or tabBarController for example.

The last thing for this mode is about the dynamic types. If you present in a BottomSheet, a controller using dynamic types to manage the font size changes based on the user's choices, the controller might need more height than the initial one if the font size changes while the controller is presented.
You don't have to manage this as the BottomSheet is listening for the content size category changes notification. If the user changes the font size, the BottomSheet will automatically trigger a height update.


Free height - Example #1

Examples to come.


Specific heights - Example #1

Examples to come.


Customization

On the BottomSheet, it is possible to configure its appearance and its behavior.
To do this you have 2 structs: Theme and Behavior.
Thanks to these structs, you can configure things like:

You can find all the available configuration parameters in the documentation.

Author

The iOS team at Lunabee Studio

License

LBBottomSheet is available under the Apache 2.0 license. See the LICENSE file for more info.

You might also like...
JAlert - This is "Alert View" project for UIKit + SwiftUI. you can use easily

JAlert Example To run the example project, clone the repo, and run pod install from the Example directory first. Requirements Installation JAlert is a

An extension that gives UIImageView the ability to focus on faces within an image.
An extension that gives UIImageView the ability to focus on faces within an image.

FaceAware Sometimes the aspect ratios of images we need to work with don't quite fit within the confines of our UIImageViews. In most cases we can use

Rock - Paper - Scissors game. CPU gives you a sign and asks to win or lose your move. Than you have to decide witch sign do you choose to score a point
Rock - Paper - Scissors game. CPU gives you a sign and asks to win or lose your move. Than you have to decide witch sign do you choose to score a point

RockPaperScissors 2nd challange from HackingWithSwift.com. The CPU gives you a sign (rock, paper or scissors) and asks you either to win or to lose th

A library, which adds the ability to hide navigation bar when view controller is pushed via hidesNavigationBarWhenPushed flag
A library, which adds the ability to hide navigation bar when view controller is pushed via hidesNavigationBarWhenPushed flag

HidesNavigationBarWhenPushed A library, which adds the ability to hide navigation bar when view controller is pushed via hidesNavigationBarWhenPushed

Visualize your dividend growth. DivRise tracks dividend prices of your stocks, gives you in-depth information about dividend paying stocks like the next dividend date and allows you to log your monthly dividend income.
Visualize your dividend growth. DivRise tracks dividend prices of your stocks, gives you in-depth information about dividend paying stocks like the next dividend date and allows you to log your monthly dividend income.

DivRise DivRise is an iOS app written in Pure SwiftUI that tracks dividend prices of your stocks, gives you in-depth information about dividend paying

You can monitor your APIs and websites on your menubar. Gives you status code 🎉 Cool & good
You can monitor your APIs and websites on your menubar. Gives you status code 🎉 Cool & good

Hope not. Monitor your APIs and websites on your menubar. For macOS. Right now! YyeeeHav!

Light and scrollable view controller for tvOS to present blocks of text
Light and scrollable view controller for tvOS to present blocks of text

TvOSTextViewer Light and scrollable view controller for tvOS to present blocks of text Description TvOSTextViewer is a view controller to present bloc

iOS custom controller used in Jobandtalent app to present new view controllers as cards
iOS custom controller used in Jobandtalent app to present new view controllers as cards

CardStackController iOS custom controller used in the Jobandtalent app to present new view controllers as cards. This controller behaves very similar

UIViewController extension to present view / view controller as bottom-half modal.
UIViewController extension to present view / view controller as bottom-half modal.

UIViewController extension to present view / view controller as bottom-half modal. Installation CocoaPods pod 'SemiModalViewController' Swift Package

AREK is a clean and easy way to request any kind of iOS permission (with some nifty features 🤖)
AREK is a clean and easy way to request any kind of iOS permission (with some nifty features 🤖)

AREK is a clean and easy to use wrapper over any kind of iOS permission written in Swift. Why AREK could help you building a better app is well descri

PrettyBorder is a SwiftUI package for managing an customized border and background at any kind of view.
PrettyBorder is a SwiftUI package for managing an customized border and background at any kind of view.

PrettyBorder Description PrettyBorder is a SwiftUI package for managing an customized border and background at any kind of view. Preview of end result

IMBeeHive is a kind of modular programming method
IMBeeHive is a kind of modular programming method

概述 IMBeeHive是用于iOS的App模块化编程的框架实现方案,本项目主要借鉴了阿里巴巴BeeHive,在此基础上通过逆向了一些大厂的APP使得功能更加强大完善。同时现在也在寻找一起开发这个框架的开发者,如果您对此感兴趣,请联系我的微信:alvinkk01. 背景 随着公司业务的不断发展,项目

JustPeek is an iOS Library that adds support for Force Touch-like Peek and Pop interactions on devices that do not natively support this kind of interaction.
JustPeek is an iOS Library that adds support for Force Touch-like Peek and Pop interactions on devices that do not natively support this kind of interaction.

JustPeek Warning: This library is not supported anymore by Just Eat. JustPeek is an iOS Library that adds support for Force Touch-like Peek and Pop in

Kind of tired to need an Android Device on me, just to read manga, so here we are.

Dokusho Kind of tired to need an Android Device on me, just to read manga, so here we are. I am going to prioritize feature based on how I feel and no

An unofficial logbook for bouldering at Mandala. Kind of a SwiftUI playground as well.
An unofficial logbook for bouldering at Mandala. Kind of a SwiftUI playground as well.

BoulderLogbook An unofficial boulder logbook for Dresden's boulder gym Mandala. Features When finished it should allow you to: log all your tops for a

Image slide-show viewer with multiple predefined transition styles, with ability to create new transitions with ease.
Image slide-show viewer with multiple predefined transition styles, with ability to create new transitions with ease.

ATGMediaBrowser ATGMediaBrowser is an image slide-show viewer that supports multiple predefined transition styles, and also allows the client to defin

Localization of the application with ability to change language
Localization of the application with ability to change language "on the fly" and support for plural form in any language.

L10n-swift is a simple framework that improves localization in swift app, providing cleaner syntax and in-app language switching. Overview 🌟 Features

Publish–subscribe design pattern implementation framework, with an ability to publish events by topic.
Publish–subscribe design pattern implementation framework, with an ability to publish events by topic.

TopicEventBus Publish–subscribe design pattern implementation framework, with ability to publish events by topic. (NotificationCenter extended alterna

A library that provides the ability to import/export Realm files from a variety of data container formats.

Realm Converter Realm Converter is an open source software utility framework to make it easier to get data both in and out of Realm. It has been built

Comments
  • Delegate When Tapping outside area when dismissing

    Delegate When Tapping outside area when dismissing

    Any option to get a completion block or delegate when manually tapping outside and sheet is getting dismissed. When dismissing by this way, have to do some activity in the View controller.

    enhancement 
    opened by harshadanu 2
  • Support CocoaPods

    Support CocoaPods

    While new projects often use Swift Package Manager, older projects often still use Cocoapods. Some frameworks even require it. It would be great if LBBottomSheet could also provide a Cocoapod in addition to the SPM install mechanism.

    opened by mhamann 0
Present a sheet ViewController easily and control ViewController height with pangesture

PanControllerHeight is designed to present a sheet ViewController easily and control ViewController height with pangesture.

null 2 May 3, 2022
Swift UI Kit to present clean modal/alert

CleanyModal is a good way to use UI-Customised alerts with ease Features Present some kind of clean alerts (With same API as UIAlertViewController) Ad

Lory Huz 487 Dec 2, 2022
An easier constructor for UIAlertController. Present an alert from anywhere.

ALRT An easier constructor for UIAlertController. Present an alert from anywhere like this. ALRT.create(.alert, title: "Alert?").addOK().addCancel().s

Masahiro Watanabe 97 Nov 11, 2022
SwiftMessages is a very flexible view and view controller presentation library for iOS.

SwiftMessages Overview SwiftMessages is a very flexible view and view controller presentation library for iOS. Message views and view controllers can

SwiftKick Mobile 6.7k Jan 2, 2023
Fully customizable and extensible action sheet controller written in Swift

XLActionController By XMARTLABS. XLActionController is an extensible library to quickly create any custom action sheet controller. Examples The action

xmartlabs 3.3k Dec 31, 2022
BottomSheetDemo - Bottom sheet modal view controller with swift

当我们想弹出一个预览视图,bottom sheet modal view controller 非常实用。在 iOS 中,长按拖拽手势可以让 controlle

null 8 Oct 29, 2022
AlertTransition is a extensible library for making view controller transitions, especially for alert transitions.

AlertTransition AlertTransition is a extensible library for making view controller transitions, especially for alert transitions. Overview AlertTransi

Loopeer 570 Nov 29, 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
BPStatusBarAlert is a library that allows you to easily make text-based alert that appear on the status bar and below navigation bar.

BPStatusBarAlert BPStatusBarAlert is a library that allows you to easily make text-based alert that appear on the status bar and below navigation bar.

Ben.Park 131 Aug 12, 2022
ColorAssetsFinder can help you find particular color assets easily by hex color code.

ColorAssetsFinder ColorAssetsFinder can help you find particular color assets easily by hex color code. Features Find particular color assets in Asset

Phil Chang 2 May 11, 2022