Skip to content

Commit

Permalink
💫 Update: Add Debug Logging in `ModalSheetViewControllerLifecycleNoti…
Browse files Browse the repository at this point in the history
…fier`
  • Loading branch information
dominicstop committed Sep 27, 2024
1 parent 9d5624d commit 8df85aa
Showing 1 changed file with 179 additions and 14 deletions.
193 changes: 179 additions & 14 deletions ios/Temp/ModalSheetViewControllerLifecycleNotifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -105,35 +121,81 @@ open class ModalSheetViewControllerLifecycleNotifier: ViewControllerLifecycleNot
);
};
};

// MARK: - Debug-Related
// ---------------------

#if DEBUG
public static var _debugShouldLogSheetEvents = true;
public static var _debugShouldLogGesture = true;
#endif
};

extension ModalSheetViewControllerLifecycleNotifier: UIAdaptivePresentationControllerDelegate {

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(
for controller: UIPresentationController,
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, *)
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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
};
};

0 comments on commit 8df85aa

Please sign in to comment.