diff --git a/ios/src_library/React Native/RNIModal/RNIModalPresentationState.swift b/ios/src_library/React Native/RNIModal/RNIModalPresentationState.swift index 7f1465d0..d86dd42c 100644 --- a/ios/src_library/React Native/RNIModal/RNIModalPresentationState.swift +++ b/ios/src_library/React Native/RNIModal/RNIModalPresentationState.swift @@ -142,6 +142,11 @@ public struct RNIModalPresentationStateMachine { public var onDismissWillCancel: (() -> Void)?; public var onDismissDidCancel: (() -> Void)?; + // MARK: - Properties + // ------------------ + + public var wasCancelledDismissViaGesture: Bool = false; + // MARK: - Computed Properties // --------------------------- @@ -149,13 +154,17 @@ public struct RNIModalPresentationStateMachine { 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; @@ -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?(); @@ -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; + }; }; }; diff --git a/ios/src_library/React Native/RNIModalView/RNIModalView.swift b/ios/src_library/React Native/RNIModalView/RNIModalView.swift index e40f7c92..806d6002 100644 --- a/ios/src_library/React Native/RNIModalView/RNIModalView.swift +++ b/ios/src_library/React Native/RNIModalView/RNIModalView.swift @@ -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 );