diff --git a/ios/src_library/React Native/RNIModal/RNIModalPresentationState.swift b/ios/src_library/React Native/RNIModal/RNIModalPresentationState.swift index cfd4fa38..a0055d36 100644 --- a/ios/src_library/React Native/RNIModal/RNIModalPresentationState.swift +++ b/ios/src_library/React Native/RNIModal/RNIModalPresentationState.swift @@ -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?(); @@ -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; };