From 11d3481e6f538452eba4e684a60d5d97b768d7e1 Mon Sep 17 00:00:00 2001 From: Dony Chen Date: Mon, 9 Sep 2024 17:41:01 +0800 Subject: [PATCH 1/2] Fix AlbumsView present issue after use SwiftUI wrapper ImagePickerController --- .../Dropdown/DropdownPresentationController.swift | 12 +++++++++++- .../Dropdown/DropdownTransitionDelegate.swift | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Sources/Presentation/Dropdown/DropdownPresentationController.swift b/Sources/Presentation/Dropdown/DropdownPresentationController.swift index bf202c50..f21f1f06 100644 --- a/Sources/Presentation/Dropdown/DropdownPresentationController.swift +++ b/Sources/Presentation/Dropdown/DropdownPresentationController.swift @@ -26,6 +26,16 @@ import UIKit class DropdownPresentationController: UIPresentationController { private let dropDownHeight: CGFloat = 200 private let backgroundView = UIView() + private weak var source: UIViewController? + + init(presentedViewController: UIViewController, presenting presentingViewController: UIViewController?, source: UIViewController) { + super.init(presentedViewController: presentedViewController, presenting: presentingViewController) + + self.source = source + backgroundView.autoresizingMask = [.flexibleWidth, .flexibleHeight] + backgroundView.backgroundColor = .clear + backgroundView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(backgroundTapped(_:)))) + } override init(presentedViewController: UIViewController, presenting presentingViewController: UIViewController?) { super.init(presentedViewController: presentedViewController, presenting: presentingViewController) @@ -62,7 +72,7 @@ class DropdownPresentationController: UIPresentationController { withParentContainerSize: presentingView.bounds.size) let position: CGPoint - if let navigationBar = (presentingViewController as? UINavigationController)?.navigationBar { + if let navigationBar = (source as? UINavigationController)?.navigationBar { // We can't use the frame directly since iOS 13 new modal presentation style let navigationRect = navigationBar.convert(navigationBar.bounds, to: nil) let presentingRect = presentingView.convert(presentingView.frame, to: containerView) diff --git a/Sources/Presentation/Dropdown/DropdownTransitionDelegate.swift b/Sources/Presentation/Dropdown/DropdownTransitionDelegate.swift index 98099933..74ef5c89 100644 --- a/Sources/Presentation/Dropdown/DropdownTransitionDelegate.swift +++ b/Sources/Presentation/Dropdown/DropdownTransitionDelegate.swift @@ -25,7 +25,7 @@ import UIKit class DropdownTransitionDelegate: NSObject, UIViewControllerTransitioningDelegate { func presentationController(forPresented presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController? { - return DropdownPresentationController(presentedViewController: presented, presenting: presenting) + return DropdownPresentationController(presentedViewController: presented, presenting: presenting, source: source) } func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? { From 968d64043133070c5c235fe402e1250335892149 Mon Sep 17 00:00:00 2001 From: Dony Chen Date: Mon, 9 Sep 2024 19:06:53 +0800 Subject: [PATCH 2/2] small refactor --- .../Dropdown/DropdownPresentationController.swift | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Sources/Presentation/Dropdown/DropdownPresentationController.swift b/Sources/Presentation/Dropdown/DropdownPresentationController.swift index f21f1f06..b50420cf 100644 --- a/Sources/Presentation/Dropdown/DropdownPresentationController.swift +++ b/Sources/Presentation/Dropdown/DropdownPresentationController.swift @@ -32,14 +32,16 @@ class DropdownPresentationController: UIPresentationController { super.init(presentedViewController: presentedViewController, presenting: presentingViewController) self.source = source - backgroundView.autoresizingMask = [.flexibleWidth, .flexibleHeight] - backgroundView.backgroundColor = .clear - backgroundView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(backgroundTapped(_:)))) + setupBackgroundView() } override init(presentedViewController: UIViewController, presenting presentingViewController: UIViewController?) { super.init(presentedViewController: presentedViewController, presenting: presentingViewController) + self.setupBackgroundView() + } + + private func setupBackgroundView() { backgroundView.autoresizingMask = [.flexibleWidth, .flexibleHeight] backgroundView.backgroundColor = .clear backgroundView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(backgroundTapped(_:))))