Skip to content

Commit

Permalink
💫 Update: RNIModalPresentationState
Browse files Browse the repository at this point in the history
  • Loading branch information
dominicstop committed Apr 7, 2023
1 parent 50eee67 commit eca2283
Showing 1 changed file with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,22 @@ public struct RNIModalPresentationStateMachine {

public mutating func set(state nextState: RNIModalPresentationState){
let prevState = self.state;

guard prevState != nextState else {
// early exit if no change
return
};

self.statePrev = prevState;

/// Do not over-write specific/"known state", with non-specific/"unknown
/// state", e.g.
///
/// * ✅: `PRESENTING_UNKNOWN` -> `PRESENTING_PROGRAMMATIC`
/// * ❌: `DISMISSING_GESTURE` -> `DISMISSING_UNKNOWN`
///
guard prevState.isNotSpecific && !nextState.isNotSpecific else { return };

if prevState.isDismissingViaGesture && nextState.isPresenting {
self.state = .DISMISS_GESTURE_CANCELLING;
self.onDismissWillCancel?();
Expand All @@ -127,14 +141,6 @@ public struct RNIModalPresentationStateMachine {
self.state = nextState;
self.onDismissDidCancel?();

} else if !prevState.isNotSpecific && nextState.isNotSpecific {
/// Do not over-write specific/"known state", with non-specific/"unknown
/// state", e.g.
///
/// * ✅: `PRESENTING_UNKNOWN` -> `PRESENTING_PROGRAMMATIC`
/// * ❌: `DISMISSING_GESTURE` -> `DISMISSING_UNKNOWN`
return;

} else {
self.state = nextState;
};
Expand Down

0 comments on commit eca2283

Please sign in to comment.