PanModal

An elegant and highly customizable presentation API for constructing bottom sheet modals on iOS.

Github星跟踪图

PanModal is an elegant and highly customizable presentation API for constructing bottom sheet modals on iOS.

Swift 4.2 support can be found on the Swift4.2 branch.

Features

  • Supports any type of UIViewController
  • Seamless transition between modal and content
  • Maintains 60 fps performance

Compatibility

PanModal requires iOS 10+ and is compatible with Swift 4.2 projects.

Installation

  • CocoaPods:
pod 'PanModal'
  • Carthage:
github "slackhq/PanModal"
  • Swift Package Manager, add the following line to your Package.swift:
dependencies: [
  .package(url: "https://github.com/slackhq/PanModal.git", .exact("1.2.6")),
],

Usage

PanModal was designed to be used effortlessly. Simply call presentPanModal in the same way you would expect to present a UIViewController

.presentPanModal(yourViewController)

The presented view controller must conform to PanModalPresentable to take advantage of the customizable options

extension YourViewController: PanModalPresentable {

    var panScrollable: UIScrollView? {
        return nil
    }
}

PanScrollable

If the presented view controller has an embedded UIScrollView e.g. as is the case with UITableViewController, panModal will seamlessly transition pan gestures between the modal and the scroll view

class TableViewController: UITableViewController, PanModalPresentable {

    var panScrollable: UIScrollView? {
        return tableView
    }
}

Adjusting Heights

Height values of the panModal can be adjusted by overriding shortFormHeight or longFormHeight

var shortFormHeight: PanModalHeight {
    return .contentHeight(300)
}

var longFormHeight: PanModalHeight {
    return .maxHeightWithTopInset(40)
}

Updates at Runtime

Values are stored during presentation, so when adjusting at runtime you should call panModalSetNeedsLayoutUpdate()

func viewDidLoad() {
    hasLoaded = true

    panModalSetNeedsLayoutUpdate()
    panModalTransition(to: .shortForm)
}

var shortFormHeight: PanModalHeight {
    if hasLoaded {
        return .contentHeight(200)
    }
    return .maxHeight
}

Sample App

Check out the Sample App for more complex configurations of PanModalPresentable, including navigation controllers and stacked modals.

Documentation

Option + click on any of PanModal's methods or notes for detailed documentation.

Contributing

We're glad to be open sourcing this library. We use it in numerous places within the slack app and expect it to be easy to use as well as modify; we've added extensive documentation within the code to support that.

We will only be fixing critical bugs, thus, for any non-critical issues or feature requests we hope to be able to rely on the community using the library to add what they need. For more information, please read the contributing guidelines.

Authors

Stephen SowoleTosin Afolabi

License

PanModal is released under a MIT License. See LICENSE file for details.

主要指标

概览
名称与所有者slackhq/PanModal
主编程语言Swift
编程语言Ruby (语言数: 3)
平台
许可证MIT License
所有者活动
创建于2019-02-26 01:15:57
推送于2024-03-14 12:12:47
最后一次提交2020-04-21 20:16:30
发布数15
最新版本名称1.2.7 (发布于 )
第一版名称1.0 (发布于 )
用户参与
星数3.7k
关注者数45
派生数540
提交数86
已启用问题?
问题数135
打开的问题数70
拉请求数27
打开的拉请求数23
关闭的拉请求数26
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?