Let duckable VCs prevent ducking

This commit is contained in:
Shadowfacts 2023-04-23 21:55:14 -04:00
parent a20e8b2f48
commit 2febb37a8e
2 changed files with 7 additions and 1 deletions

View File

@ -10,6 +10,8 @@ import UIKit
public protocol DuckableViewController: UIViewController {
var duckableDelegate: DuckableViewControllerDelegate? { get set }
func duckableViewControllerShouldDuck() -> Bool
func duckableViewControllerMayAttemptToDuck()
func duckableViewControllerWillAnimateDuck(withDuration duration: CGFloat, afterDelay delay: CGFloat)
@ -18,6 +20,7 @@ public protocol DuckableViewController: UIViewController {
}
extension DuckableViewController {
public func duckableViewControllerShouldDuck() -> Bool { true }
public func duckableViewControllerMayAttemptToDuck() {}
public func duckableViewControllerWillAnimateDuck(withDuration duration: CGFloat, afterDelay delay: CGFloat) {}
public func duckableViewControllerDidFinishAnimatingDuck() {}

View File

@ -135,6 +135,10 @@ public class DuckableContainerViewController: UIViewController, DuckableViewCont
guard case .presentingDucked(let viewController, isFirstPresentation: _) = state else {
return
}
guard viewController.duckableViewControllerShouldDuck() else {
viewController.sheetPresentationController!.selectedDetentIdentifier = .large
return
}
let placeholder = createPlaceholderForDuckedViewController(viewController)
state = .ducked(viewController, placeholder: placeholder)
configureChildForDuckedPlaceholder()
@ -235,4 +239,3 @@ extension DuckableContainerViewController: UISheetPresentationControllerDelegate
}
}
}