parent
346888db41
commit
99b74559da
|
@ -10,7 +10,7 @@ import UIKit
|
|||
public protocol DuckableViewController: UIViewController {
|
||||
var duckableDelegate: DuckableViewControllerDelegate? { get set }
|
||||
|
||||
func duckableViewControllerShouldDuck() -> Bool
|
||||
func duckableViewControllerShouldDuck() -> DuckAttemptAction
|
||||
|
||||
func duckableViewControllerMayAttemptToDuck()
|
||||
|
||||
|
@ -20,7 +20,7 @@ public protocol DuckableViewController: UIViewController {
|
|||
}
|
||||
|
||||
extension DuckableViewController {
|
||||
public func duckableViewControllerShouldDuck() -> Bool { true }
|
||||
public func duckableViewControllerShouldDuck() -> DuckAttemptAction { .duck }
|
||||
public func duckableViewControllerMayAttemptToDuck() {}
|
||||
public func duckableViewControllerWillAnimateDuck(withDuration duration: CGFloat, afterDelay delay: CGFloat) {}
|
||||
public func duckableViewControllerDidFinishAnimatingDuck() {}
|
||||
|
@ -30,6 +30,12 @@ public protocol DuckableViewControllerDelegate: AnyObject {
|
|||
func duckableViewControllerWillDismiss(animated: Bool)
|
||||
}
|
||||
|
||||
public enum DuckAttemptAction {
|
||||
case duck
|
||||
case dismiss
|
||||
case block
|
||||
}
|
||||
|
||||
extension UIViewController {
|
||||
@available(iOS 16.0, *)
|
||||
public func presentDuckable(_ viewController: DuckableViewController, animated: Bool, isDucked: Bool = false) -> Bool {
|
||||
|
|
|
@ -135,14 +135,18 @@ public class DuckableContainerViewController: UIViewController, DuckableViewCont
|
|||
guard case .presentingDucked(let viewController, isFirstPresentation: _) = state else {
|
||||
return
|
||||
}
|
||||
guard viewController.duckableViewControllerShouldDuck() else {
|
||||
viewController.sheetPresentationController!.selectedDetentIdentifier = .large
|
||||
return
|
||||
}
|
||||
switch viewController.duckableViewControllerShouldDuck() {
|
||||
case .duck:
|
||||
let placeholder = createPlaceholderForDuckedViewController(viewController)
|
||||
state = .ducked(viewController, placeholder: placeholder)
|
||||
configureChildForDuckedPlaceholder()
|
||||
dismiss(animated: true)
|
||||
case .block:
|
||||
viewController.sheetPresentationController!.selectedDetentIdentifier = .large
|
||||
case .dismiss:
|
||||
duckableViewControllerWillDismiss(animated: true)
|
||||
dismiss(animated: true)
|
||||
}
|
||||
}
|
||||
|
||||
private func configureChildForDuckedPlaceholder() {
|
||||
|
|
|
@ -138,6 +138,14 @@ class ComposeHostingController: UIHostingController<ComposeHostingController.Vie
|
|||
|
||||
// MARK: Duckable
|
||||
|
||||
func duckableViewControllerShouldDuck() -> DuckAttemptAction {
|
||||
if controller.draft.hasContent {
|
||||
return .duck
|
||||
} else {
|
||||
return .dismiss
|
||||
}
|
||||
}
|
||||
|
||||
func duckableViewControllerWillAnimateDuck(withDuration duration: CGFloat, afterDelay delay: CGFloat) {
|
||||
controller.deleteDraftOnDisappear = false
|
||||
|
||||
|
|
Loading…
Reference in New Issue