Skip to content
This repository was archived by the owner on Nov 3, 2025. It is now read-only.

Commit a75b607

Browse files
committed
Add didTransition in PanModalPresentable delegate
1 parent 0ba076e commit a75b607

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

PanModal/Controller/PanModalPresentationController.swift

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,11 +259,15 @@ public extension PanModalPresentationController {
259259

260260
presentable?.willTransition(to: state)
261261

262+
let completion: () -> Void = { [weak self] in
263+
self?.presentable?.didTransition(to: state)
264+
}
265+
262266
switch state {
263267
case .shortForm:
264-
snap(toYPosition: shortFormYPosition)
268+
snap(toYPosition: shortFormYPosition, completion: completion)
265269
case .longForm:
266-
snap(toYPosition: longFormYPosition)
270+
snap(toYPosition: longFormYPosition, completion: completion)
267271
}
268272
}
269273

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

646-
func snap(toYPosition yPos: CGFloat) {
650+
func snap(toYPosition yPos: CGFloat, completion: (() -> Void)? = nil) {
647651
PanModalAnimator.animate({ [weak self] in
648652
self?.adjust(toYPosition: yPos)
649653
self?.isPresentedViewAnimating = true
650654
}, config: presentable) { [weak self] didComplete in
651655
self?.isPresentedViewAnimating = !didComplete
656+
if didComplete {
657+
completion?()
658+
}
652659
}
653660
}
654661

PanModal/Presentable/PanModalPresentable+Defaults.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ public extension PanModalPresentable where Self: UIViewController {
117117

118118
}
119119

120+
func didTransition(to state: PanModalPresentationController.PresentationState) {
121+
122+
}
123+
120124
func panModalWillDismiss() {
121125

122126
}

PanModal/Presentable/PanModalPresentable.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,13 @@ public protocol PanModalPresentable: AnyObject {
220220
*/
221221
func willTransition(to state: PanModalPresentationController.PresentationState)
222222

223+
/**
224+
Notifies the delegate that the pan modal transitioned to a new state.
225+
226+
Default value is an empty implementation.
227+
*/
228+
func didTransition(to state: PanModalPresentationController.PresentationState)
229+
223230
/**
224231
Notifies the delegate that the pan modal is about to be dismissed.
225232

0 commit comments

Comments
 (0)