Contents

ohkanghoon/floatingbottomsheet

A library that displays floating bottom sheet.

Compatibility

FloatingBottomSheet requires iOS 11+ and is compatible with Swift 5 projects.

Installation

Swift Package Manager.

The preferred way of installing FloatingBottomSheet is via the Swift Package Manager

  1. In Xcode, open your project and navigate to FileAdd Packages
  2. Paste the repository URL (https://github.com/OhKanghoon/FloatingBottomSheet) and click Next.
  3. For Rules, select Up to Next Major Version.
  4. Click Add Package.

CocoaPods

# Podfile
use_frameworks!

target 'YOUR_TARGET_NAME' do
  pod 'FloatingBottomSheet'
end

Replace YOUR_TARGET_NAME and then, in the Podfile directory, type:

$ pod install

Usage

<img src="assets/floatingbottomsheet.gif" width="35%" alt="Preview">

Configuration

To use the FloatingBottomSheet, your ViewController must conform to the FloatingBottomSheetPresentable protocol.

Start by implementing the bottomSheetScrollable and bottomSheetHeight properties.

final class ViewController: UIViewController, FloatingBottomSheetPresentable {

  var bottomSheetScrollable: UIScrollView? {
    // Return a scrollable view
  }

  var bottomSheetHeight: any FloatingBottomSheetSizing {
    // Set the height of the bottom sheet
    .fixed(400)
  }
}

You can choose from different sizing options:

  • Fixed height: Use .fixed(_) for a constant height

``swift var bottomSheetHeight: any FloatingBottomSheetSizing { .fixed(400) } ``

  • Dynamic height: Use .viewSizeThatFits to calculate height based on content

``swift var bottomSheetHeight: any FloatingBottomSheetSizing { .viewSizeThatFits } ``

Present bottom sheet

Simply present the floating bottom sheet using the presentFloatingBottomSheet function like this:

let viewController = ViewController()

presentFloatingBottomSheet(viewController)

Updates bottom sheet height at runtime

To update the bottom sheet's height dynamically during runtime, update your bottomSheetHeight property and call bottomSheetPerformLayout:

// Update your height property
bottomSheetHeight = .fixed(500)

// Apply the layout change
bottomSheetPerformLayout(animated: true)

You can change the value of bottomSheetHeight to your desired sizing configuration and then call the bottomSheetPerformLayout function to update the bottom sheet's layout with optional animation.

If you don't want animation, set animated to false.

License

FloatingBottomSheet is under MIT license. See the LICENSE for more info.

Package Metadata

Repository: ohkanghoon/floatingbottomsheet

Default branch: main

README: README.md