Skip to content

AppleArealidea/ARBottomSheetViewController

Repository files navigation

ARBottomSheetViewController

A lightweight, customizable bottom sheet component for iOS built with Swift using UIPresentationController.

Features

  • Custom presentation via UIPresentationController — works with standard present(_:animated:) flow
  • Swipe-to-dismiss with velocity-based threshold
  • Tap on dimming background to dismiss
  • Scroll view coordination — pan gesture seamlessly hands off to an embedded scroll view
  • Dynamic content height via delegate
  • Rounded top corners with a drag indicator (handle)
  • Safe area support (top and bottom insets)
  • Supports iOS 12+ with adaptive colors for Dark Mode (iOS 13+)

Requirements

Minimum
iOS 12.0+
Swift 5.9+
Xcode 15.0+

Installation

Swift Package Manager

Add the dependency to your Package.swift:

dependencies: [
    .package(url: "https://github.com/Areal-Group/ARBottomSheetViewController.git", .upToNextMajor(from: "1.0.0"))
]

Or in Xcode: File → Add Package Dependencies… and paste the repository URL.

Usage

1. Create a bottom sheet and set the delegate

let bottomSheet = ARBottomSheetViewController()
bottomSheet.sheetDelegate = self

2. Add your content to contentBackgroundView

let label = UILabel()
label.text = "Hello, Bottom Sheet!"
bottomSheet.contentBackgroundView.addSubview(label)
label.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
    label.topAnchor.constraint(equalTo: bottomSheet.contentBackgroundView.topAnchor, constant: 16),
    label.leadingAnchor.constraint(equalTo: bottomSheet.contentBackgroundView.leadingAnchor, constant: 16),
    label.trailingAnchor.constraint(equalTo: bottomSheet.contentBackgroundView.trailingAnchor, constant: -16),
    label.bottomAnchor.constraint(equalTo: bottomSheet.contentBackgroundView.bottomAnchor, constant: -16)
])

3. Present it

present(bottomSheet, animated: true)

4. Implement the delegate

extension YourViewController: ARBottomSheetViewControllerDelegate {
    var contentHeight: CGFloat {
        return 300
    }

    var childScrollView: UIScrollView? {
        return nil // or return a scroll view for coordinated scrolling
    }
}

If you return a UIScrollView from childScrollView, the bottom sheet will coordinate its dismiss gesture with the scroll view — swiping down only dismisses the sheet when the scroll view is at the top of its content.

API

ARBottomSheetViewControllerDelegate

public protocol ARBottomSheetViewControllerDelegate: AnyObject {
    var contentHeight: CGFloat { get }
    var childScrollView: UIScrollView? { get }
}
Property Description
contentHeight The desired height of the content area (excluding the handle and safe area)
childScrollView Optional scroll view for coordinated pan gesture handling

ARBottomSheetViewController

Property / Method Description
sheetDelegate Weak reference to ARBottomSheetViewControllerDelegate
contentBackgroundView The view where you should add your content subviews
init() Creates a new bottom sheet instance

License

This project is licensed under the MIT License — see the LICENSE file for details.

About

iOS bottom sheet written on Swift

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors