Skip to content

Commit

Permalink
⭐️ Impl: synthesizedViewControllerIndex
Browse files Browse the repository at this point in the history
Summary:
* Impl. `RNIModalData.synthesizedViewControllerIndex`.
* Impl. `RNIModal.synthesizedViewControllerIndex`.
  • Loading branch information
dominicstop committed Apr 6, 2023
1 parent d5068e3 commit 60c5411
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
18 changes: 18 additions & 0 deletions ios/src_library/React Native/RNIModal/RNIModal+Helpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,23 @@ extension RNIModalState where Self: RNIModalPresentation {
return topmostVC === self.modalViewController;
};

/// Note:2023-03-31-15-41-04
///
/// * This is based on the view controller hierarchy
/// * So parent/child view controller that aren't modals are also counted
///
var synthesizedViewControllerIndex: Int {
let listPresentedVC =
RNIModalManager.getPresentedViewControllers(for: self.window);

for (index, vc) in listPresentedVC.enumerated() {
guard vc === self.modalViewController else { continue };
return index;
};

return -1;
};

/// Programmatically get the "modal index"
var synthesizedModalIndex: Int {
let listPresentedVC =
Expand Down Expand Up @@ -73,6 +90,7 @@ extension RNIModalState where Self: RNIModal {
synthesizedIsModalInFocus: self.synthesizedIsModalInFocus,
synthesizedIsModalPresented: self.synthesizedIsModalPresented,
synthesizedModalIndex: self.synthesizedModalIndex,
synthesizedViewControllerIndex: self.synthesizedViewControllerIndex,
synthesizedWindowID: self.window?.synthesizedStringID
);
};
Expand Down
2 changes: 2 additions & 0 deletions ios/src_library/React Native/RNIModal/RNIModalData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ public struct RNIModalData: RNIDictionarySynthesizable {

let synthesizedIsModalInFocus: Bool;
let synthesizedIsModalPresented: Bool;

let synthesizedModalIndex: Int;
let synthesizedViewControllerIndex: Int;

let synthesizedWindowID: String?;
};

0 comments on commit 60c5411

Please sign in to comment.