forked from shadowfacts/Tusker
Fix DuckableContainerVC not resetting when dismissed programatically
Fixes #396
This commit is contained in:
parent
9a734565b0
commit
473ef018c9
|
@ -8,8 +8,6 @@
|
|||
import UIKit
|
||||
|
||||
public protocol DuckableViewController: UIViewController {
|
||||
var duckableDelegate: DuckableViewControllerDelegate? { get set }
|
||||
|
||||
func duckableViewControllerShouldDuck() -> DuckAttemptAction
|
||||
|
||||
func duckableViewControllerMayAttemptToDuck()
|
||||
|
@ -26,10 +24,6 @@ extension DuckableViewController {
|
|||
public func duckableViewControllerDidFinishAnimatingDuck() {}
|
||||
}
|
||||
|
||||
public protocol DuckableViewControllerDelegate: AnyObject {
|
||||
func duckableViewControllerWillDismiss(animated: Bool)
|
||||
}
|
||||
|
||||
public enum DuckAttemptAction {
|
||||
case duck
|
||||
case dismiss
|
||||
|
|
|
@ -11,7 +11,7 @@ let duckedCornerRadius: CGFloat = 10
|
|||
let detentHeight: CGFloat = 44
|
||||
|
||||
@available(iOS 16.0, *)
|
||||
public class DuckableContainerViewController: UIViewController, DuckableViewControllerDelegate {
|
||||
public class DuckableContainerViewController: UIViewController {
|
||||
|
||||
public let child: UIViewController
|
||||
private var bottomConstraint: NSLayoutConstraint!
|
||||
|
@ -87,7 +87,6 @@ public class DuckableContainerViewController: UIViewController, DuckableViewCont
|
|||
}
|
||||
|
||||
private func doPresentDuckable(_ viewController: DuckableViewController, animated: Bool, completion: (() -> Void)?) {
|
||||
viewController.duckableDelegate = self
|
||||
viewController.modalPresentationStyle = .custom
|
||||
viewController.transitioningDelegate = self
|
||||
present(viewController, animated: animated) {
|
||||
|
@ -96,7 +95,10 @@ public class DuckableContainerViewController: UIViewController, DuckableViewCont
|
|||
}
|
||||
}
|
||||
|
||||
public func duckableViewControllerWillDismiss(animated: Bool) {
|
||||
func dismissalTransitionWillBegin() {
|
||||
guard case .presentingDucked(_, _) = state else {
|
||||
return
|
||||
}
|
||||
state = .idle
|
||||
bottomConstraint.isActive = false
|
||||
bottomConstraint = child.view.bottomAnchor.constraint(equalTo: view.bottomAnchor)
|
||||
|
@ -144,7 +146,7 @@ public class DuckableContainerViewController: UIViewController, DuckableViewCont
|
|||
case .block:
|
||||
viewController.sheetPresentationController!.selectedDetentIdentifier = .large
|
||||
case .dismiss:
|
||||
duckableViewControllerWillDismiss(animated: true)
|
||||
// duckableViewControllerWillDismiss()
|
||||
dismiss(animated: true)
|
||||
}
|
||||
}
|
||||
|
@ -189,7 +191,7 @@ public class DuckableContainerViewController: UIViewController, DuckableViewCont
|
|||
@available(iOS 16.0, *)
|
||||
extension DuckableContainerViewController: UIViewControllerTransitioningDelegate {
|
||||
public func presentationController(forPresented presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController? {
|
||||
let controller = UISheetPresentationController(presentedViewController: presented, presenting: presenting)
|
||||
let controller = DuckableSheetPresentationController(presentedViewController: presented, presenting: presenting)
|
||||
controller.delegate = self
|
||||
controller.prefersGrabberVisible = true
|
||||
controller.selectedDetentIdentifier = .large
|
||||
|
@ -215,6 +217,14 @@ extension DuckableContainerViewController: UIViewControllerTransitioningDelegate
|
|||
}
|
||||
}
|
||||
|
||||
@available(iOS 16.0, *)
|
||||
class DuckableSheetPresentationController: UISheetPresentationController {
|
||||
override func dismissalTransitionWillBegin() {
|
||||
super.dismissalTransitionWillBegin()
|
||||
(self.delegate as! DuckableContainerViewController).dismissalTransitionWillBegin()
|
||||
}
|
||||
}
|
||||
|
||||
@available(iOS 16.0, *)
|
||||
extension DuckableContainerViewController: UISheetPresentationControllerDelegate {
|
||||
public func presentationController(_ presentationController: UIPresentationController, willPresentWithAdaptiveStyle style: UIModalPresentationStyle, transitionCoordinator: UIViewControllerTransitionCoordinator?) {
|
||||
|
|
|
@ -23,7 +23,6 @@ protocol ComposeHostingControllerDelegate: AnyObject {
|
|||
class ComposeHostingController: UIHostingController<ComposeHostingController.View>, DuckableViewController {
|
||||
|
||||
weak var delegate: ComposeHostingControllerDelegate?
|
||||
weak var duckableDelegate: DuckableViewControllerDelegate?
|
||||
|
||||
let controller: ComposeController
|
||||
let mastodonController: MastodonController
|
||||
|
@ -107,7 +106,6 @@ class ComposeHostingController: UIHostingController<ComposeHostingController.Vie
|
|||
return
|
||||
} else {
|
||||
dismiss(animated: true)
|
||||
duckableDelegate?.duckableViewControllerWillDismiss(animated: true)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue