Skip to content

Commit

Permalink
⭐️ Impl. Update: wasCancelledDismissViaGesture
Browse files Browse the repository at this point in the history
Summary: Replace  `RNIModalPresentationStateMachine.wasDismissViaGestureCancelled` w/ `wasCancelledDismissViaGesture`.
  • Loading branch information
dominicstop committed Apr 13, 2023
1 parent 100317a commit 3e6286d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,20 +142,29 @@ public struct RNIModalPresentationStateMachine {
public var onDismissWillCancel: (() -> Void)?;
public var onDismissDidCancel: (() -> Void)?;

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

public var wasCancelledDismissViaGesture: Bool = false;

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

public var isPresented: Bool {
self.state.isPresented
};

public var wasDismissViaGestureCancelled: Bool {
self.statePrev.isDismissViaGestureCancelling
};

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

init(
onDismissWillCancel: ( () -> Void)? = nil,
onDismissDidCancel: ( () -> Void)? = nil
) {
self.onDismissWillCancel = onDismissWillCancel;
self.onDismissDidCancel = onDismissDidCancel;
}

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

Expand Down Expand Up @@ -191,6 +200,7 @@ public struct RNIModalPresentationStateMachine {
self.statePrev = prevState;

if prevState.isDismissingViaGesture && nextState.isPresenting {
self.wasCancelledDismissViaGesture = true;
self.state = .DISMISS_GESTURE_CANCELLING;
self.onDismissWillCancel?();

Expand All @@ -201,5 +211,23 @@ public struct RNIModalPresentationStateMachine {
} else {
self.state = nextState;
};

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

self.resetIfNeeded();
};

mutating func resetIfNeeded(){
if self.state == .DISMISSED {
// reset
self.wasCancelledDismissViaGesture = false;
};
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ extension RNIModalView: RNIViewControllerLifeCycleNotifiable {
self.modalPresentationNotificationDelegate
.notifyOnModalDidShow(sender: self);

if !self.modalPresentationState.wasDismissViaGestureCancelled {
if !self.modalPresentationState.wasCancelledDismissViaGesture {
self.onModalShow?(
self.synthesizedBaseEventData.synthesizedJSDictionary
);
Expand Down

0 comments on commit 3e6286d

Please sign in to comment.