Skip to content

Commit

Permalink
💫 Update: RNIModalManager
Browse files Browse the repository at this point in the history
  • Loading branch information
dominicstop committed Apr 27, 2023
1 parent cd86c6d commit 7ea800a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 28 deletions.
6 changes: 3 additions & 3 deletions ios/src_library/React Native/RNIModal/RNIModal+Helpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ extension RNIModalState where Self: RNIModalPresentation {
/// Programmatically check if this instance is presented
public var computedIsModalPresented: Bool {
let listPresentedVC =
RNIModalManager.getPresentedViewControllers(for: self.window);
RNIUtilities.getPresentedViewControllers(for: self.window);

return listPresentedVC.contains {
$0 === self.modalViewController;
Expand All @@ -33,7 +33,7 @@ extension RNIModalState where Self: RNIModalPresentation {
/// Programmatically check if this instance is in focus
public var computedIsModalInFocus: Bool {
let listPresentedVC =
RNIModalManager.getPresentedViewControllers(for: self.window);
RNIUtilities.getPresentedViewControllers(for: self.window);

guard let topmostVC = listPresentedVC.last
else { return self.synthesizedIsModalInFocus };
Expand All @@ -48,7 +48,7 @@ extension RNIModalState where Self: RNIModalPresentation {
///
public var computedViewControllerIndex: Int {
let listPresentedVC =
RNIModalManager.getPresentedViewControllers(for: self.window);
RNIUtilities.getPresentedViewControllers(for: self.window);

for (index, vc) in listPresentedVC.enumerated() {
guard vc === self.modalViewController else { continue };
Expand Down
44 changes: 22 additions & 22 deletions ios/src_library/React Native/RNIModal/RNIModalManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,9 @@

import Foundation

public let RNIModalManagerShared = RNIModalManager.sharedInstance;


/// Archived/Old Notes
/// * `Note:2023-04-07-03-22-48`
/// * `Note:2023-03-30-19-36-33`
///
public class RNIModalManager {

// MARK: - Static Properties
// -------------------------

public static let sharedInstance = RNIModalManager();

// MARK: - Static Functions
// ------------------------

/// TODO:2023-03-20-21-29-36 - Move to `RNIUtilities`
/// TODO:2023-03-20-21-29-36 - Move to `RNIUtilities`
extension RNIUtilities {
public static func getWindows() -> [UIWindow] {
var windows: [UIWindow] = [];

Expand Down Expand Up @@ -84,7 +69,6 @@ public class RNIModalManager {
return windows;
};

/// TODO:2023-03-20-21-29-36 - Move to `RNIUtilities`
public static func getRootViewController(
for window: UIWindow? = nil
) -> UIViewController? {
Expand All @@ -96,7 +80,6 @@ public class RNIModalManager {
return Self.getWindows().first?.rootViewController;
};

/// TODO:2023-03-20-21-29-36 - Move to `RNIUtilities`
public static func getPresentedViewControllers(
for window: UIWindow? = nil
) -> [UIViewController] {
Expand Down Expand Up @@ -125,15 +108,32 @@ public class RNIModalManager {
return presentedVCList;
};

/// TODO:2023-03-20-21-29-36 - Move to `RNIUtilities`
public static func getTopmostPresentedViewController(
for window: UIWindow? = nil
) -> UIViewController? {
return Self.getPresentedViewControllers(for: window).last;
};
};

public let RNIModalManagerShared = RNIModalManager.sharedInstance;


/// Archived/Old Notes
/// * `Note:2023-04-07-03-22-48`
/// * `Note:2023-03-30-19-36-33`
///
public class RNIModalManager {

// MARK: - Static Properties
// -------------------------

public static let sharedInstance = RNIModalManager();

// MARK: - Static Functions
// ------------------------

static func getPresentedModals(forWindow window: UIWindow) -> [any RNIModal] {
let vcItems = Self.getPresentedViewControllers(for: window);
let vcItems = RNIUtilities.getPresentedViewControllers(for: window);

return vcItems.compactMap {
guard let modalVC = $0 as? RNIModalViewController else { return nil };
Expand All @@ -147,7 +147,7 @@ public class RNIModalManager {
) -> Int {

let listPresentedVC =
RNIModalManager.getPresentedViewControllers(for: window);
RNIUtilities.getPresentedViewControllers(for: window);

var index = -1;

Expand Down
4 changes: 2 additions & 2 deletions ios/src_library/React Native/RNIModalView/RNIModalView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ public class RNIModalView:
/// helper func to hide/show the other modals that are below level
private func setIsHiddenForViewBelowLevel(_ level: Int, isHidden: Bool){
let presentedVCList =
RNIModalManager.getPresentedViewControllers(for: self.window);
RNIUtilities.getPresentedViewControllers(for: self.window);

for (index, vc) in presentedVCList.enumerated() {
if index < level {
Expand Down Expand Up @@ -689,7 +689,7 @@ public class RNIModalView:
};

let presentedViewControllers =
RNIModalManager.getPresentedViewControllers(for: self.window);
RNIUtilities.getPresentedViewControllers(for: self.window);

guard let topMostPresentedVC = presentedViewControllers.last else {
#if DEBUG
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class RNIModalViewModule: RCTEventEmitter {
callback: @escaping RCTResponseSenderBlock
) {
DispatchQueue.main.async {
let listPresentedVC = RNIModalManager.getPresentedViewControllers();
let listPresentedVC = RNIUtilities.getPresentedViewControllers();

guard listPresentedVC.count > 0 else {
#if DEBUG
Expand Down

0 comments on commit 7ea800a

Please sign in to comment.