Skip to content

Commit

Permalink
⭐️ Impl: Property wasCancelledPresent
Browse files Browse the repository at this point in the history
Related:
* `TODO:2023-03-04-13-15-11` - Refactor: Update Modal Events
* `TODO:2023-04-14-23-40-15` - Impl. Update `RNIModalData` - Add more modal-related data.

Summary: Impl. `RNIModalPresentationStateMachine.wasCancelledPresent`.
  • Loading branch information
dominicstop committed Apr 14, 2023
1 parent b2d4ad4 commit 95b3872
Showing 1 changed file with 29 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,17 +146,21 @@ public struct RNIModalPresentationStateMachine {
// ------------------

private var _isInitialPresent: Bool? = nil;
private var _wasCancelledPresent: Bool = false;

public var wasCancelledDismissViaGesture: Bool = false;


// MARK: - Computed Properties
// ---------------------------

public var isInitialPresent: Bool {
self._isInitialPresent ?? true;
};

public var wasCancelledPresent: Bool {
self._wasCancelledPresent || self.wasCancelledDismissViaGesture;
};

public var isPresented: Bool {
self.state.isPresented
};
Expand Down Expand Up @@ -219,31 +223,46 @@ public struct RNIModalPresentationStateMachine {
self.state = nextState;
};

if nextState.isPresenting && self._isInitialPresent == nil {
self._isInitialPresent = true;

} else if nextState.isPresenting && self._isInitialPresent == true {
self._isInitialPresent = false;
};

self.updateProperties();
self.resetIfNeeded();

#if DEBUG
print(
"Log - RNIModalPresentationStateMachine.set"
+ " - statePrev: \(self.statePrev)"
+ " - nextState: \(self.state)"
+ " - wasCancelledDismissViaGesture: \(wasCancelledDismissViaGesture)"
+ " - wasCancelledDismissViaGesture: \(self.wasCancelledDismissViaGesture)"
+ " - isInitialPresent: \(self.isInitialPresent)"
+ " - wasCancelledPresent: \(self.wasCancelledPresent)"
);
#endif
};

mutating func resetIfNeeded(){
private mutating func updateProperties(){
let nextState = self.state;
let prevState = self.statePrev;

if nextState.isPresenting && self._isInitialPresent == nil {
self._isInitialPresent = true;

} else if nextState.isPresenting && self._isInitialPresent == true {
self._isInitialPresent = false;
};

if prevState.isPresenting && nextState.isDismissing {
self._wasCancelledPresent = true;
};
};

private mutating func resetIfNeeded(){
if self.state == .DISMISSED {
// reset
self.wasCancelledDismissViaGesture = false;
self._isInitialPresent = false;
};

if self.state.isPresenting {
self._wasCancelledPresent = false;
};
};
};

0 comments on commit 95b3872

Please sign in to comment.