From 67fc0d44116a7302d23bad3bfb4b2868ccb74407 Mon Sep 17 00:00:00 2001 From: Dominic Go <18517029+dominicstop@users.noreply.github.com> Date: Fri, 5 May 2023 09:19:54 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9E=20Fix:=20`RNIPresentedViewControll?= =?UTF-8?q?erCache`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RNIPresentedViewControllerCache.swift | 24 ++++++------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/ios/src_library/React Native/RNIModal/RNIPresentedViewControllerCache.swift b/ios/src_library/React Native/RNIModal/RNIPresentedViewControllerCache.swift index 764f1d76..63f0ac51 100644 --- a/ios/src_library/React Native/RNIModal/RNIPresentedViewControllerCache.swift +++ b/ios/src_library/React Native/RNIModal/RNIPresentedViewControllerCache.swift @@ -13,25 +13,14 @@ class RNIPresentedViewControllerCache { class Cache { weak var targetWindow: UIWindow? = nil; - var cacheRequestCount = 0 { - willSet { - guard newValue <= 0 else { return }; - self._cache = nil; - } - } + var cacheRequestCount = 0; // note: this retains the vc instances... - private var _cache: [UIViewController]?; + var cache: [UIViewController]?; - var cache: [UIViewController]? { - get { - guard self.cacheRequestCount > 0 else { return nil }; - return self._cache; - } - set { - self._cache = newValue; - self.targetWindow = nil; - } + func clear(){ + self.targetWindow = nil; + self.cache = nil; }; }; @@ -62,6 +51,8 @@ class RNIPresentedViewControllerCache { cache.cacheRequestCount -= 1; guard cache.cacheRequestCount <= 0 else { return }; + + cache.clear(); self.map.removeValue(forKey: windowID); }; }; @@ -69,7 +60,6 @@ class RNIPresentedViewControllerCache { func getPresentedViewControllers( forWindow window: UIWindow? ) -> [UIViewController] { - return RNIUtilities.getPresentedViewControllers(for: window); guard let windowID = window?.synthesizedStringID, let cacheContainer = self.map[windowID], let vcItemsCached = cacheContainer.cache