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