Skip to content

Commit

Permalink
🐞 Fix: RNIPresentedViewControllerCache
Browse files Browse the repository at this point in the history
  • Loading branch information
dominicstop committed May 5, 2023
1 parent ca20ef3 commit 67fc0d4
Showing 1 changed file with 7 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
};

Expand Down Expand Up @@ -62,14 +51,15 @@ class RNIPresentedViewControllerCache {
cache.cacheRequestCount -= 1;

guard cache.cacheRequestCount <= 0 else { return };

cache.clear();
self.map.removeValue(forKey: windowID);
};
};

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
Expand Down

0 comments on commit 67fc0d4

Please sign in to comment.