PanModal
An elegant and highly customizable presentation API for constructing bottom sheet modals on iOS.
Top Related Projects
Easy access to iOS address book
Quick Overview
PanModal is a powerful and customizable modal presentation controller for iOS. It provides a simple and intuitive way to present modals in your iOS applications, with support for various presentation styles and customization options.
Pros
- Flexible Presentation Styles: PanModal supports a variety of presentation styles, including bottom sheet, top sheet, and custom presentation styles, allowing you to choose the best fit for your app's user experience.
- Smooth Interaction: The library provides a smooth and responsive user experience, with support for interactive dismissal and customizable gestures.
- Customization Options: PanModal offers a wide range of customization options, enabling you to tailor the modal's appearance and behavior to match your app's design and requirements.
- Accessibility Support: The library includes built-in accessibility features, ensuring that your modals are accessible to users with disabilities.
Cons
- Dependency on UIKit: PanModal is tightly coupled with Apple's UIKit framework, which may limit its compatibility with other iOS development frameworks or platforms.
- Learning Curve: While the library provides a straightforward API, developers may need to invest some time in understanding the various configuration options and customization possibilities.
- Potential Performance Impact: Depending on the complexity of your modal content, the library's animation and gesture handling features may have a slight performance impact on your app.
- Limited Third-Party Integration: PanModal may not integrate seamlessly with all third-party libraries or frameworks used in your iOS project.
Code Examples
Presenting a Bottom Sheet Modal
let modalViewController = MyModalViewController()
let panModalPresentationController = PanModalPresentationController(presentedViewController: modalViewController, presenting: self)
panModalPresentationController.delegate = self
present(modalViewController, animated: true, completion: nil)
Customizing the Modal Appearance
let panModalPresentationController = PanModalPresentationController(presentedViewController: modalViewController, presenting: self)
panModalPresentationController.shortFormHeight = 300
panModalPresentationController.longFormHeight = 500
panModalPresentationController.cornerRadius = 16
panModalPresentationController.springDamping = 0.8
Handling Dismissal Gestures
extension MyViewController: PanModalPresentationControllerDelegate {
func shouldPanModalDismiss(_ panModalPresentationController: PanModalPresentationController) -> Bool {
// Implement custom dismissal logic
return true
}
}
Implementing a Custom Presentation Style
class CustomPresentationController: PanModalPresentationController {
override func presentationTransitionWillBegin() {
// Implement custom presentation logic
}
override func dismissalTransitionWillBegin() {
// Implement custom dismissal logic
}
}
Getting Started
To get started with PanModal, follow these steps:
-
Add the PanModal library to your project using a package manager like CocoaPods or Carthage.
# CocoaPods pod 'PanModal'
-
Import the PanModal framework in your Swift file.
import PanModal
-
Create an instance of the modal view controller you want to present and configure the PanModalPresentationController.
let modalViewController = MyModalViewController() let panModalPresentationController = PanModalPresentationController(presentedViewController: modalViewController, presenting: self) panModalPresentationController.delegate = self present(modalViewController, animated: true, completion: nil)
-
Customize the modal's appearance and behavior by adjusting the properties of the PanModalPresentationController.
panModalPresentationController.shortFormHeight = 300 panModalPresentationController.longFormHeight = 500 panModalPresentationController.cornerRadius = 16 panModalPresentationController.springDamping = 0.8
-
Implement the PanModalPresentationControllerDelegate protocol to handle custom dismissal logic or other events.
extension My
Competitor Comparisons
Easy access to iOS address book
Pros of Alterplay/APAddressBook
- Provides a simple and lightweight address book interface for iOS applications.
- Supports both local and iCloud-based address books.
- Includes a variety of customization options for the address book UI.
Cons of Alterplay/APAddressBook
- Limited functionality compared to PanModal, which offers a more comprehensive modal presentation solution.
- May not be as actively maintained or have as large a community as PanModal.
- Lacks some of the advanced features and customization options available in PanModal.
Code Comparison
PanModal (slackhq/PanModal):
let panModalVC = PanModalPresentationController(presentedViewController: self, presentingViewController: self.presentingViewController)
panModalVC.delegate = self
panModalVC.shortFormHeight = 300
panModalVC.longFormHeight = 500
self.present(panModalVC, animated: true, completion: nil)
Alterplay/APAddressBook:
let addressBookController = APAddressBookController()
addressBookController.delegate = self
addressBookController.modalPresentationStyle = .fullScreen
self.present(addressBookController, animated: true, completion: nil)
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
PanModal is an elegant and highly customizable presentation API for constructing bottom sheet modals on iOS.
Features ⢠Compatibility ⢠Installation ⢠Usage ⢠Documentation ⢠Contributing ⢠Authors ⢠License
Read our blog on how Slack is getting more :thumbsup: with PanModal
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
pod 'PanModal'
github "slackhq/PanModal"
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 Sowole ⢠Tosin Afolabi
License
PanModal is released under a MIT License. See LICENSE file for details.
Top Related Projects
Easy access to iOS address book
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot