diff --git a/Packages/Duckable/Sources/Duckable/API.swift b/Packages/Duckable/Sources/Duckable/API.swift index fb6da599..6cd2979e 100644 --- a/Packages/Duckable/Sources/Duckable/API.swift +++ b/Packages/Duckable/Sources/Duckable/API.swift @@ -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 { diff --git a/Packages/Duckable/Sources/Duckable/DuckableContainerViewController.swift b/Packages/Duckable/Sources/Duckable/DuckableContainerViewController.swift index f22baf5c..ff77ce37 100644 --- a/Packages/Duckable/Sources/Duckable/DuckableContainerViewController.swift +++ b/Packages/Duckable/Sources/Duckable/DuckableContainerViewController.swift @@ -135,14 +135,18 @@ public class DuckableContainerViewController: UIViewController, DuckableViewCont guard case .presentingDucked(let viewController, isFirstPresentation: _) = state else { return } - guard viewController.duckableViewControllerShouldDuck() else { + switch viewController.duckableViewControllerShouldDuck() { + case .duck: + let placeholder = createPlaceholderForDuckedViewController(viewController) + state = .ducked(viewController, placeholder: placeholder) + configureChildForDuckedPlaceholder() + dismiss(animated: true) + case .block: viewController.sheetPresentationController!.selectedDetentIdentifier = .large - return + case .dismiss: + duckableViewControllerWillDismiss(animated: true) + dismiss(animated: true) } - let placeholder = createPlaceholderForDuckedViewController(viewController) - state = .ducked(viewController, placeholder: placeholder) - configureChildForDuckedPlaceholder() - dismiss(animated: true) } private func configureChildForDuckedPlaceholder() { diff --git a/Tusker/Screens/Compose/ComposeHostingController.swift b/Tusker/Screens/Compose/ComposeHostingController.swift index 490e4904..bb2730fa 100644 --- a/Tusker/Screens/Compose/ComposeHostingController.swift +++ b/Tusker/Screens/Compose/ComposeHostingController.swift @@ -138,6 +138,14 @@ class ComposeHostingController: UIHostingController DuckAttemptAction { + if controller.draft.hasContent { + return .duck + } else { + return .dismiss + } + } + func duckableViewControllerWillAnimateDuck(withDuration duration: CGFloat, afterDelay delay: CGFloat) { controller.deleteDraftOnDisappear = false