From 95b3872d8534474a75c3c0c202d57dac02f93303 Mon Sep 17 00:00:00 2001 From: Dominic Go <18517029+dominicstop@users.noreply.github.com> Date: Sat, 15 Apr 2023 00:03:05 +0800 Subject: [PATCH] =?UTF-8?q?=E2=AD=90=EF=B8=8F=20Impl:=20Property=20`wasCan?= =?UTF-8?q?celledPresent`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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.wasCancelledPresent`. --- .../RNIModal/RNIModalPresentationState.swift | 39 ++++++++++++++----- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/ios/src_library/React Native/RNIModal/RNIModalPresentationState.swift b/ios/src_library/React Native/RNIModal/RNIModalPresentationState.swift index 7590ac34..347f9e2a 100644 --- a/ios/src_library/React Native/RNIModal/RNIModalPresentationState.swift +++ b/ios/src_library/React Native/RNIModal/RNIModalPresentationState.swift @@ -146,10 +146,10 @@ public struct RNIModalPresentationStateMachine { // ------------------ private var _isInitialPresent: Bool? = nil; + private var _wasCancelledPresent: Bool = false; public var wasCancelledDismissViaGesture: Bool = false; - // MARK: - Computed Properties // --------------------------- @@ -157,6 +157,10 @@ public struct RNIModalPresentationStateMachine { self._isInitialPresent ?? true; }; + public var wasCancelledPresent: Bool { + self._wasCancelledPresent || self.wasCancelledDismissViaGesture; + }; + public var isPresented: Bool { self.state.isPresented }; @@ -219,13 +223,7 @@ public struct RNIModalPresentationStateMachine { self.state = nextState; }; - if nextState.isPresenting && self._isInitialPresent == nil { - self._isInitialPresent = true; - - } else if nextState.isPresenting && self._isInitialPresent == true { - self._isInitialPresent = false; - }; - + self.updateProperties(); self.resetIfNeeded(); #if DEBUG @@ -233,17 +231,38 @@ public struct RNIModalPresentationStateMachine { "Log - RNIModalPresentationStateMachine.set" + " - statePrev: \(self.statePrev)" + " - nextState: \(self.state)" - + " - wasCancelledDismissViaGesture: \(wasCancelledDismissViaGesture)" + + " - wasCancelledDismissViaGesture: \(self.wasCancelledDismissViaGesture)" + " - isInitialPresent: \(self.isInitialPresent)" + + " - wasCancelledPresent: \(self.wasCancelledPresent)" ); #endif }; - mutating func resetIfNeeded(){ + private mutating func updateProperties(){ + let nextState = self.state; + let prevState = self.statePrev; + + if nextState.isPresenting && self._isInitialPresent == nil { + self._isInitialPresent = true; + + } else if nextState.isPresenting && self._isInitialPresent == true { + self._isInitialPresent = false; + }; + + if prevState.isPresenting && nextState.isDismissing { + self._wasCancelledPresent = true; + }; + }; + + private mutating func resetIfNeeded(){ if self.state == .DISMISSED { // reset self.wasCancelledDismissViaGesture = false; self._isInitialPresent = false; }; + + if self.state.isPresenting { + self._wasCancelledPresent = false; + }; }; };