Skip to content

Commit

Permalink
💫 Update: Add Logging to ModalSheetPresentationStateMachine
Browse files Browse the repository at this point in the history
  • Loading branch information
dominicstop committed Sep 27, 2024
1 parent 5bb4fe8 commit 33c5c99
Showing 1 changed file with 61 additions and 3 deletions.
64 changes: 61 additions & 3 deletions ios/Temp/ModalSheetPresentationStateMachine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,28 @@ public class ModalSheetPresentationStateMachine {
public var didPresent = false;
public var didDismissAfterPresented = false;

public var eventDelegates:
MulticastDelegate<ModalSheetStateEventNotifiable> = .init();

// MARK: - Methods
// ---------------

public func setStateExplicit(nextState: ModalSheetState){
let prevState = self.prevState;
let currentState = self.currentState;

#if DEBUG
if Self._debugShouldLog {
print(
"ModalSheetPresentationStateMachine.\(#function) - PRE",
"\n - instance:", Unmanaged.passUnretained(self).toOpaque(),
"\n - prevState:", prevState?.rawValue ?? "N/A",
"\n - currentState:", currentState,
"\n - arg, nextState:", nextState,
"\n - self.didPresent:", self.didPresent,
"\n - self.didDismissAfterPresented:", self.didDismissAfterPresented,
"\n"
);
};
#endif

self.prevState = self.currentState;
self.currentState = nextState;
Expand All @@ -41,9 +57,34 @@ public class ModalSheetPresentationStateMachine {
default:
break;
};

#if DEBUG
if Self._debugShouldLog {
print(
"ModalSheetPresentationStateMachine.\(#function) - POST",
"\n - instance:", Unmanaged.passUnretained(self).toOpaque(),
"\n - self.prevState:", self.prevState?.rawValue ?? "N/A",
"\n - self.currentState:", self.currentState,
"\n - self.didPresent:", self.didPresent,
"\n - self.didDismissAfterPresented:", self.didDismissAfterPresented,
"\n"
);
};
#endif
};

public func setState(nextState: ModalSheetState){
public func setState(nextState: ModalSheetState) {
#if DEBUG
if Self._debugShouldLog {
print(
"ModalSheetPresentationStateMachine.\(#function)",
"\n - instance:", Unmanaged.passUnretained(self).toOpaque(),
"\n - arg, nextState:", nextState,
"\n"
);
};
#endif

switch (self.prevState, self.currentState, nextState) {

default:
Expand All @@ -54,12 +95,29 @@ public class ModalSheetPresentationStateMachine {
};

public func reset(){
#if DEBUG
if Self._debugShouldLog {
print(
"ModalSheetPresentationStateMachine.\(#function)",
"\n - instance:", Unmanaged.passUnretained(self).toOpaque(),
"\n"
);
};
#endif

self.prevState = nil;
self.currentState = .dismissed;

self.didPresent = false;
self.didDismissAfterPresented = false;
};

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

#if DEBUG
public static var _debugShouldLog = true;
#endif
};

extension ModalSheetPresentationStateMachine: ViewControllerLifecycleNotifiable {
Expand Down

0 comments on commit 33c5c99

Please sign in to comment.