201 lines
5.5 KiB
Swift
201 lines
5.5 KiB
Swift
//
|
|
// PanModalPresentable.swift
|
|
// PanModal
|
|
//
|
|
// Copyright © 2017 Tiny Speck, Inc. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
/**
|
|
This is the configuration object for a view controller
|
|
that will be presented using the PanModal transition.
|
|
|
|
Usage:
|
|
```
|
|
extension UIViewController: PanModalPresentable {
|
|
func shouldRoundTopCorners: Bool { return false }
|
|
}
|
|
```
|
|
*/
|
|
public protocol PanModalPresentable {
|
|
|
|
/**
|
|
The scroll view embedded in the view controller.
|
|
Setting this value allows for seamless transition scrolling between the embedded scroll view
|
|
and the pan modal container view.
|
|
*/
|
|
var panScrollable: UIScrollView? { get }
|
|
|
|
/**
|
|
The offset between the top of the screen and the top of the pan modal container view.
|
|
|
|
Default value is the topLayoutGuide.length + 21.0.
|
|
*/
|
|
var topOffset: CGFloat { get }
|
|
|
|
/**
|
|
The height of the pan modal container view
|
|
when in the shortForm presentation state.
|
|
|
|
This value is capped to .max, if provided value exceeds the space available.
|
|
|
|
Default value is the longFormHeight.
|
|
*/
|
|
var shortFormHeight: PanModalHeight { get }
|
|
|
|
/**
|
|
The height of the pan modal container view
|
|
when in the longForm presentation state.
|
|
|
|
This value is capped to .max, if provided value exceeds the space available.
|
|
|
|
Default value is .max.
|
|
*/
|
|
var longFormHeight: PanModalHeight { get }
|
|
|
|
/**
|
|
The springDamping value used to determine the amount of 'bounce'
|
|
seen when transitioning to short/long form.
|
|
|
|
Default Value is 0.8.
|
|
*/
|
|
var springDamping: CGFloat { get }
|
|
|
|
/**
|
|
The background view alpha.
|
|
|
|
- Note: This is only utilized at the very start of the transition.
|
|
|
|
Default Value is 0.7.
|
|
*/
|
|
var backgroundAlpha: CGFloat { get }
|
|
|
|
/**
|
|
We configure the panScrollable's scrollIndicatorInsets interally so override this value
|
|
to set custom insets.
|
|
|
|
- Note: Use `panModalSetNeedsLayoutUpdate()` when updating insets.
|
|
*/
|
|
var scrollIndicatorInsets: UIEdgeInsets { get }
|
|
|
|
/**
|
|
A flag to determine if scrolling should be limited to the longFormHeight.
|
|
Return false to cap scrolling at .max height.
|
|
|
|
Default value is true.
|
|
*/
|
|
var anchorModalToLongForm: Bool { get }
|
|
|
|
/**
|
|
A flag to determine if scrolling should seamlessly transition from the pan modal container view to
|
|
the embedded scroll view once the scroll limit has been reached.
|
|
|
|
Default value is false.
|
|
Unless a scrollView is provided and the content exceeds the longForm height
|
|
*/
|
|
var allowsExtendedPanScrolling: Bool { get }
|
|
|
|
/**
|
|
A flag to determine if dismissal should be initiated when swiping down on the presented view.
|
|
Return false to fallback to the short form state instead of dismissing.
|
|
|
|
Default value is true.
|
|
*/
|
|
var allowsDragToDismiss: Bool { get }
|
|
|
|
/**
|
|
A flag to determine if scrolling should be enabled on the entire view.
|
|
|
|
- Note: Returning false will disable scrolling on the embedded scrollview as well as on the
|
|
pan modal container view.
|
|
|
|
Default value is true.
|
|
*/
|
|
var isPanScrollEnabled: Bool { get }
|
|
|
|
/**
|
|
A flag to toggle user interactions on the container view.
|
|
|
|
- Note: Return false to forward touches to the presentingViewController.
|
|
|
|
Default is true.
|
|
*/
|
|
var isUserInteractionEnabled: Bool { get }
|
|
|
|
/**
|
|
A flag to determine if haptic feedback should be enabled during presentation.
|
|
|
|
Default value is true.
|
|
*/
|
|
var isHapticFeedbackEnabled: Bool { get }
|
|
|
|
/**
|
|
A flag to determine if the top corners should be rounded.
|
|
|
|
Default value is true.
|
|
*/
|
|
var shouldRoundTopCorners: Bool { get }
|
|
|
|
/**
|
|
The corner radius used when `shouldRoundTopCorners` is enabled.
|
|
|
|
Default Value is `8.0`
|
|
*/
|
|
var cornerRadius: CGFloat { get }
|
|
|
|
/**
|
|
A flag to determine if a drag indicator should be shown
|
|
above the pan modal container view.
|
|
|
|
Default value is true.
|
|
*/
|
|
var showDragIndicator: Bool { get }
|
|
|
|
/**
|
|
Notifies the delegate when the pan modal gesture recognizer state is either
|
|
`began` or `changed`. This method gives the delegate a chance to prepare
|
|
for the gesture recognizer state change.
|
|
|
|
For example, when the pan modal view is about to scroll.
|
|
|
|
Default value is an empty implementation.
|
|
*/
|
|
func willRespond(to panGestureRecognizer: UIPanGestureRecognizer)
|
|
|
|
/**
|
|
Asks the delegate if the pan modal gesture recognizer should be prioritized.
|
|
|
|
For example, you can use this to define a region
|
|
where you would like to restrict where the pan gesture can start.
|
|
|
|
If false, then we rely on the internal conditions of when a pan gesture
|
|
should succeed or fail, such as, if we're actively scrolling on the scrollView
|
|
|
|
Default return value is false.
|
|
*/
|
|
func shouldPrioritize(panModalGestureRecognizer: UIPanGestureRecognizer) -> Bool
|
|
|
|
/**
|
|
Asks the delegate if the pan modal should transition to a new state.
|
|
|
|
Default value is true.
|
|
*/
|
|
func shouldTransition(to state: PanModalPresentationController.PresentationState) -> Bool
|
|
|
|
/**
|
|
Notifies the delegate that the pan modal is about to transition to a new state.
|
|
|
|
Default value is an empty implementation.
|
|
*/
|
|
func willTransition(to state: PanModalPresentationController.PresentationState)
|
|
|
|
/**
|
|
Notifies the delegate that the pan modal is about to be dismissed.
|
|
|
|
Default value is an empty implementation.
|
|
*/
|
|
func panModalWillDismiss()
|
|
|
|
}
|