Skip to content

Commit

Permalink
Add didTransition in PanModalPresentable delegate
Browse files Browse the repository at this point in the history
  • Loading branch information
closure11 committed Oct 31, 2022
1 parent 0ba076e commit a75b607
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
13 changes: 10 additions & 3 deletions PanModal/Controller/PanModalPresentationController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,15 @@ public extension PanModalPresentationController {

presentable?.willTransition(to: state)

let completion: () -> Void = { [weak self] in
self?.presentable?.didTransition(to: state)
}

switch state {
case .shortForm:
snap(toYPosition: shortFormYPosition)
snap(toYPosition: shortFormYPosition, completion: completion)
case .longForm:
snap(toYPosition: longFormYPosition)
snap(toYPosition: longFormYPosition, completion: completion)
}
}

Expand Down Expand Up @@ -643,12 +647,15 @@ private extension PanModalPresentationController {
return (abs(velocity) - (1000 * (1 - Constants.snapMovementSensitivity))) > 0
}

func snap(toYPosition yPos: CGFloat) {
func snap(toYPosition yPos: CGFloat, completion: (() -> Void)? = nil) {
PanModalAnimator.animate({ [weak self] in
self?.adjust(toYPosition: yPos)
self?.isPresentedViewAnimating = true
}, config: presentable) { [weak self] didComplete in
self?.isPresentedViewAnimating = !didComplete
if didComplete {
completion?()
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions PanModal/Presentable/PanModalPresentable+Defaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ public extension PanModalPresentable where Self: UIViewController {

}

func didTransition(to state: PanModalPresentationController.PresentationState) {

}

func panModalWillDismiss() {

}
Expand Down
7 changes: 7 additions & 0 deletions PanModal/Presentable/PanModalPresentable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,13 @@ public protocol PanModalPresentable: AnyObject {
*/
func willTransition(to state: PanModalPresentationController.PresentationState)

/**
Notifies the delegate that the pan modal transitioned to a new state.

Default value is an empty implementation.
*/
func didTransition(to state: PanModalPresentationController.PresentationState)

/**
Notifies the delegate that the pan modal is about to be dismissed.

Expand Down

0 comments on commit a75b607

Please sign in to comment.