From 8df85aad2ee1bdc87cc13fa1a07a9eab87a42621 Mon Sep 17 00:00:00 2001 From: Dominic Go Date: Fri, 27 Sep 2024 10:00:50 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=AB=20Update:=20Add=20Debug=20Logging?= =?UTF-8?q?=20in=20`ModalSheetViewControllerLifecycleNotifier`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...SheetViewControllerLifecycleNotifier.swift | 193 ++++++++++++++++-- 1 file changed, 179 insertions(+), 14 deletions(-) diff --git a/ios/Temp/ModalSheetViewControllerLifecycleNotifier.swift b/ios/Temp/ModalSheetViewControllerLifecycleNotifier.swift index 9e4ffe6c..1ff5d43b 100644 --- a/ios/Temp/ModalSheetViewControllerLifecycleNotifier.swift +++ b/ios/Temp/ModalSheetViewControllerLifecycleNotifier.swift @@ -96,6 +96,22 @@ open class ModalSheetViewControllerLifecycleNotifier: ViewControllerLifecycleNot }; let gesturePoint = panGesture.translation(in: presentedView); + + #if DEBUG + if Self._debugShouldLogGesture { + print( + "ModalSheetViewControllerLifecycleNotifier.\(#function)", + "\n - instance:", Unmanaged.passUnretained(self).toOpaque(), + "\n - className:", self.className, + "\n - panGesture:", panGesture.debugDescription, + "\n - panGesture.state:", panGesture.state, + "\n - panGesture, gesturePoint:", gesturePoint, + "\n - isBeingDismissed:", self.isBeingDismissed, + "\n - isBeingPresented:", self.isBeingPresented, + "\n" + ); + }; + #endif self.sheetLifecycleEventDelegates.invoke { $0.notifyOnSytemSheetPanGestureInvoked( @@ -105,6 +121,14 @@ open class ModalSheetViewControllerLifecycleNotifier: ViewControllerLifecycleNot ); }; }; + + // MARK: - Debug-Related + // --------------------- + + #if DEBUG + public static var _debugShouldLogSheetEvents = true; + public static var _debugShouldLogGesture = true; + #endif }; extension ModalSheetViewControllerLifecycleNotifier: UIAdaptivePresentationControllerDelegate { @@ -112,14 +136,32 @@ extension ModalSheetViewControllerLifecycleNotifier: UIAdaptivePresentationContr public func adaptivePresentationStyle( for controller: UIPresentationController ) -> UIModalPresentationStyle { - - if let delegate = self.presentationControllerDelegateProxy, - let presentationStyle = delegate.adaptivePresentationStyle?(for: controller) - { + + let nextPresentationStyle: UIModalPresentationStyle = { + guard let delegate = self.presentationControllerDelegateProxy, + let presentationStyle = delegate.adaptivePresentationStyle?(for: controller) + else { + return .pageSheet; + }; + return presentationStyle; + }(); + + #if DEBUG + if Self._debugShouldLogSheetEvents { + print( + "ModalSheetViewControllerLifecycleNotifier.\(#function)", + "\n - instance:", Unmanaged.passUnretained(self).toOpaque(), + "\n - className:", self.className, + "\n - presentationControllerDelegateProxy:", self.presentationControllerDelegateProxy?.debugDescription ?? "N/A", + "\n - arg, controller:", controller.debugDescription, + "\n - arg, nextPresentationStyle:", nextPresentationStyle, + "\n" + ); }; + #endif - return .pageSheet; + return nextPresentationStyle; }; public func adaptivePresentationStyle( @@ -127,13 +169,33 @@ extension ModalSheetViewControllerLifecycleNotifier: UIAdaptivePresentationContr traitCollection: UITraitCollection ) -> UIModalPresentationStyle { - if let delegate = self.presentationControllerDelegateProxy, - let presentationStyle = delegate.adaptivePresentationStyle?(for: controller, traitCollection: traitCollection) - { + let nextPresentationStyle: UIModalPresentationStyle = { + guard let delegate = self.presentationControllerDelegateProxy, + let presentationStyle = + delegate.adaptivePresentationStyle?(for: controller, traitCollection: traitCollection) + else { + return .none; + }; + return presentationStyle; + }(); + + #if DEBUG + if Self._debugShouldLogSheetEvents { + print( + "ModalSheetViewControllerLifecycleNotifier.\(#function)", + "\n - instance:", Unmanaged.passUnretained(self).toOpaque(), + "\n - className:", self.className, + "\n - presentationControllerDelegateProxy:", self.presentationControllerDelegateProxy?.debugDescription ?? "N/A", + "\n - arg, controller:", controller.debugDescription, + "\n - arg, traitCollection:", traitCollection.debugDescription, + "\n - arg, nextPresentationStyle:", nextPresentationStyle, + "\n" + ); }; + #endif - return .none; + return nextPresentationStyle; }; @available(iOS 15.0, *) @@ -145,17 +207,47 @@ extension ModalSheetViewControllerLifecycleNotifier: UIAdaptivePresentationContr presentationController, prepare: adaptivePresentationController ); + + #if DEBUG + if Self._debugShouldLogSheetEvents { + print( + "ModalSheetViewControllerLifecycleNotifier.\(#function)", + "\n - instance:", Unmanaged.passUnretained(self).toOpaque(), + "\n - className:", self.className, + "\n - presentationControllerDelegateProxy:", self.presentationControllerDelegateProxy?.debugDescription ?? "N/A", + "\n - arg, presentationController:", presentationController.debugDescription, + "\n" + ); + }; + #endif }; public func presentationController( _ controller: UIPresentationController, viewControllerForAdaptivePresentationStyle style: UIModalPresentationStyle ) -> UIViewController? { - - return self.presentationControllerDelegateProxy?.presentationController?( + + let nextController = self.presentationControllerDelegateProxy?.presentationController?( controller, viewControllerForAdaptivePresentationStyle: style ); + + #if DEBUG + if Self._debugShouldLogSheetEvents { + print( + "ModalSheetViewControllerLifecycleNotifier.\(#function)", + "\n - instance:", Unmanaged.passUnretained(self).toOpaque(), + "\n - className:", self.className, + "\n - presentationControllerDelegateProxy:", self.presentationControllerDelegateProxy?.debugDescription ?? "N/A", + "\n - arg, controller:", controller.debugDescription, + "\n - arg, viewControllerForAdaptivePresentationStyle:", style.caseString, + "\n - arg, nextController:", nextController?.debugDescription ?? "N/A", + "\n" + ); + }; + #endif + + return nextController; }; public func presentationController( @@ -169,16 +261,46 @@ extension ModalSheetViewControllerLifecycleNotifier: UIAdaptivePresentationContr willPresentWithAdaptiveStyle: style, transitionCoordinator: transitionCoordinator ); + + #if DEBUG + if Self._debugShouldLogSheetEvents { + print( + "ModalSheetViewControllerLifecycleNotifier.\(#function)", + "\n - instance:", Unmanaged.passUnretained(self).toOpaque(), + "\n - className:", self.className, + "\n - presentationControllerDelegateProxy:", self.presentationControllerDelegateProxy?.debugDescription ?? "N/A", + "\n - arg, presentationController:", presentationController.debugDescription, + "\n - arg, willPresentWithAdaptiveStyle:", style.caseString, + "\n - arg, transitionCoordinator:", transitionCoordinator?.debugDescription ?? "N/A", + "\n" + ); + }; + #endif }; public func presentationControllerShouldDismiss( _ presentationController: UIPresentationController ) -> Bool { - let shouldDismiss: Bool? = - self.presentationControllerDelegateProxy?.presentationControllerShouldDismiss?(presentationController); + let shouldDismiss: Bool = + self.presentationControllerDelegateProxy?.presentationControllerShouldDismiss?(presentationController) + ?? self.shouldAllowDismissal; + + #if DEBUG + if Self._debugShouldLogSheetEvents { + print( + "ModalSheetViewControllerLifecycleNotifier.\(#function)", + "\n - instance:", Unmanaged.passUnretained(self).toOpaque(), + "\n - className:", self.className, + "\n - presentationControllerDelegateProxy:", self.presentationControllerDelegateProxy?.debugDescription ?? "N/A", + "\n - arg, presentationController:", presentationController.debugDescription, + "\n - shouldDismiss:", shouldDismiss, + "\n" + ); + }; + #endif - return shouldDismiss ?? self.shouldAllowDismissal; + return shouldDismiss; }; public func presentationControllerWillDismiss( @@ -193,6 +315,21 @@ extension ModalSheetViewControllerLifecycleNotifier: UIAdaptivePresentationContr presentationController: presentationController ); }; + + #if DEBUG + if Self._debugShouldLogSheetEvents { + print( + "ModalSheetViewControllerLifecycleNotifier.\(#function)", + "\n - instance:", Unmanaged.passUnretained(self).toOpaque(), + "\n - className:", self.className, + "\n - presentationControllerDelegateProxy:", self.presentationControllerDelegateProxy?.debugDescription ?? "N/A", + "\n - arg, presentationController:", presentationController.debugDescription, + "\n - isBeingDismissed: ", self.isBeingDismissed, + "\n - isBeingPresented: ", self.isBeingPresented, + "\n" + ); + }; + #endif }; public func presentationControllerDidDismiss( @@ -208,6 +345,20 @@ extension ModalSheetViewControllerLifecycleNotifier: UIAdaptivePresentationContr presentationController: presentationController ); }; + + #if DEBUG + if Self._debugShouldLogSheetEvents { + print( + "ModalSheetViewControllerLifecycleNotifier.\(#function)", + "\n - instance:", Unmanaged.passUnretained(self).toOpaque(), + "\n - className:", self.className, + "\n - presentationControllerDelegateProxy:", self.presentationControllerDelegateProxy?.debugDescription ?? "N/A", + "\n - arg, presentationController:", presentationController.debugDescription, + "\n - isPresentedAsModal", self.isPresentedAsModal, + "\n" + ); + }; + #endif }; public func presentationControllerDidAttemptToDismiss( @@ -223,5 +374,19 @@ extension ModalSheetViewControllerLifecycleNotifier: UIAdaptivePresentationContr presentationController: presentationController ); }; + + #if DEBUG + if Self._debugShouldLogSheetEvents { + print( + "ModalSheetViewControllerLifecycleNotifier.\(#function)", + "\n - instance:", Unmanaged.passUnretained(self).toOpaque(), + "\n - className:", self.className, + "\n - presentationControllerDelegateProxy:", self.presentationControllerDelegateProxy?.debugDescription ?? "N/A", + "\n - arg, presentationController:", presentationController.debugDescription, + "\n - isPresentedAsModal", self.isPresentedAsModal, + "\n" + ); + }; + #endif }; };