BottomSheet

BottomSheet is an implementation of custom modal presentation style for thumb-friendly interactive views anchored to the bottom of the screen.

  • [x] Custom UIViewControllerTransitioningDelegate for dismissable modal bottom sheets
  • [x] BottomSheetView for displaying complementary content as a standard bottom sheet view
  • [x] Expanding bottom sheets with multiple states to transition between
  • [x] Support for automatic view height based on Auto Layout constraints
  • [x] Beatiful spring animation

Demo

BottomSheetx

Installation

BottomSheet is available through Carthage. Append this line to your Cartfile:

github "finn-no/BottomSheet"

BottomSheet is also available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'FINNBottomSheet'

To integrate using Apple's Swift package manager, add the following as a dependency to your Package.swift:

.package(name: "FINNBottomSheet", url: "https://github.com/finn-no/BottomSheet.git", .upToNextMajor(from: "1.0.0"))

Usage

View controller -based presentation:

import FINNBottomSheet

let transitioningDelegate = BottomSheetTransitioningDelegate(
    contentHeights: [.bottomSheetAutomatic, UIScreen.main.bounds.size.height - 200],
    startTargetIndex: 0
)
let viewController = UIViewController()
viewController.transitioningDelegate = transitioningDelegate
viewController.modalPresentationStyle = .custom

present(viewController, animated: true)

View -based presentation:

import FINNBottomSheet

let contentView = UIView()
contentView.backgroundColor = .red

let bottomSheetView = BottomSheetView(
    contentView: contentView,
    contentHeights: [100, 500]
)

// Can be presented in any UIView subclass
bottomSheetView.present(in: viewController.view, targetIndex: 0)

Known limitations

Using .bottomSheetAutomatic:

When using .bottomSheetAutomatic to calculate the content height and your view is constrained using the layoutMarginsGuide, you must be aware that the returned content height may actually be higher than the compressed layout size of your view. Also, it may result in the transition animation freezing. This problem is avoided simply by not using the layoutMarginsGuide.

GitHub