Skip to content

Commit

Permalink
⭐️ Impl: Property wasCancelledDismiss
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.wasCancelledDismiss`.
  • Loading branch information
dominicstop committed Apr 14, 2023
1 parent 78122b1 commit b6c7ec1
Showing 1 changed file with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ public struct RNIModalPresentationStateMachine {
// ------------------

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

public var wasCancelledPresent: Bool = false;
public var wasCancelledDismissViaGesture: Bool = false;
Expand All @@ -172,6 +173,10 @@ public struct RNIModalPresentationStateMachine {
self.state.isPresented
};

public var wasCancelledDismiss: Bool {
self._wasCancelledDismiss || self.wasCancelledDismissViaGesture;
};

// MARK: - Functions
// -----------------

Expand Down Expand Up @@ -238,9 +243,10 @@ public struct RNIModalPresentationStateMachine {
"Log - RNIModalPresentationStateMachine.set"
+ " - statePrev: \(self.statePrev)"
+ " - nextState: \(self.state)"
+ " - wasCancelledDismissViaGesture: \(self.wasCancelledDismissViaGesture)"
+ " - isInitialPresent: \(self.isInitialPresent)"
+ " - wasCancelledPresent: \(self.wasCancelledPresent)"
+ " - wasCancelledDismiss: \(self.wasCancelledDismiss)"
+ " - wasCancelledDismissViaGesture: \(self.wasCancelledDismissViaGesture)"
);
#endif
};
Expand All @@ -258,18 +264,21 @@ public struct RNIModalPresentationStateMachine {

if prevState.isPresenting && nextState.isDismissedOrDismissing {
self.wasCancelledPresent = true;

} else if prevState.isDismissing && nextState.isPresentedOrPresenting {
self._wasCancelledDismiss = true;
};
};

private mutating func resetIfNeeded(){
if self.state == .DISMISSED {
if self.state.isPresented {
self.wasCancelledPresent = false;

} else if self.state == .DISMISSED {
// reset
self.wasCancelledDismissViaGesture = false;
self._isInitialPresent = false;
};

if self.state.isPresented {
self.wasCancelledPresent = false;
self._wasCancelledDismiss = false;
};
};
};

0 comments on commit b6c7ec1

Please sign in to comment.