Swiftpack.co - Package - finn-no/BottomSheet

CircleCI Carthage compatible CocoaPods compatible Swift Package Manager compatible

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

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

Demo

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

link
Stars: 82

Dependencies

Used By

Total: 0

Releases

-

Changes since 5.0.0

  • #36 Accessibility improvement

5.0.0 -

Breaking change from 4.2.1

  • #33: Rename the SwiftPM package to "FINNBottomSheet"

Migration guide

This breaking change only affects users that use this package through the swift-package-manager.

Previously, when using SPM, you would import like:

import BottomSheet

To make it consistent with the way the package is imported when using it with Cocoapods, we just do now:

import FINNBottomSheet

That's it.

-

Changes since 4.2.0

  • #31: Add public methods to copy/hide background overlay
  • #28: Add "Known limitations" section
  • #26: Rename option in README

4.2.0 -

Draggable height as configuration option #23

4.1.0 -

Make it possible to stretch content view on resize #22

4.0.2 -

Remove content view constraints on dismiss #21

4.0.1 -

Override navigation controller init #20

4.0.0 -

Introduce dismissal delegate #19

3.2.0 -

Make transitioning delegate and bottom sheet view more customisable #18

3.1.1 -

Update podspec

3.1.0 -

Add a helper class to work with navigation controllers #17

3.0.0 -

Initialize BottomSheetView with contentHeights #14

2.3.0 -

Support navigation controllers #13

2.2.0 -

#9 Fix present without animation #10 Dismiss presented view controller when tapping dimmed background #11 Add initial velocity to spring animation #12 Make sure interactive presentation works properly

2.1.0 -

Animate to currentTargetOffset in reset method #8

2.0.1 -

Add rubber band effect to the bottom target #7

2.0.0 -

  • Improve threshold and offset calculations #5
  • Replace translationState function with array of models #6

1.0.0 -

Initial release 🎉