Skip to content

Commit

Permalink
⭐️ Impl: RNIModalIdentity.modalIndexPrev
Browse files Browse the repository at this point in the history
Related:
* `TODO:2023-03-04-13-15-11` - Refactor: Update Modal Events.
*  `TODO:2023-03-30-16-25-01` - Impl: `RNIModal.modalIndexPrev`.

Summary:
* Update `RNIModalIdentity` - Add `modalIndexPrev` property.
* Update `RNIModalView` - Add `modalIndexPrev` property.
* Update `RNIModalManager` - Impl. logic to init. + update `RNIModalIdentity.modalIndexPrev`.
  • Loading branch information
dominicstop committed Mar 30, 2023
1 parent 68b642f commit 99c2903
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
3 changes: 3 additions & 0 deletions ios/src_library/React Native/RNIModal/RNIModal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ public protocol RNIModalIdentity: AnyObject {

var modalIndex: Int! { set get };

var modalIndexPrev: Int! { set get };

var modalNativeID: String! { set get };

};

/// Contains modal-related properties for keeping track of the state of the
Expand Down
14 changes: 12 additions & 2 deletions ios/src_library/React Native/RNIModal/RNIModalManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public let RNIModalManagerShared = RNIModalManager.sharedInstance;
/// window instance, and only updating it based on the modal's associated
/// window instance.
///
/// * This can also be fixed by programmatically determining the modal's
/// `modalIndex`.
///
public class RNIModalManager {

// MARK: - Static Properties
Expand Down Expand Up @@ -193,7 +196,9 @@ public class RNIModalManager {
let key = self.createModalNativeID();

modal.modalNativeID = key;

modal.modalIndex = -1;
modal.modalIndexPrev = -1;

modal.isModalPresented = false;
modal.isModalInFocus = false;
Expand All @@ -215,9 +220,12 @@ extension RNIModalManager: RNIModalFocusNotifiable {
public func onModalWillFocusNotification(
sender modal: RNIModal
) {
self.currentModalIndex += 1;
let nextModalIndex = self.currentModalIndex + 1;
self.currentModalIndex = nextModalIndex;

modal.modalIndexPrev = modal.modalIndex;
modal.modalIndex = nextModalIndex;

modal.modalIndex = self.currentModalIndex;
modal.onModalWillFocusNotification(sender: modal);

self.modalInstances.forEach {
Expand Down Expand Up @@ -251,6 +259,8 @@ extension RNIModalManager: RNIModalFocusNotifiable {

public func onModalWillBlurNotification(sender modal: RNIModal) {
self.currentModalIndex -= 1;

modal.modalIndexPrev = modal.modalIndex;
modal.modalIndex = -1;

modal.onModalWillBlurNotification(sender: modal);
Expand Down
2 changes: 2 additions & 0 deletions ios/src_library/React Native/RNIModalView/RNIModalView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class RNIModalView: UIView, RNIModalFocusNotifying, RNIModalIdentity,
// -------------------------------------

var modalIndex: Int!;
var modalIndexPrev: Int!;

var modalNativeID: String!;

// MARK: - Properties - RNIModalState
Expand Down

0 comments on commit 99c2903

Please sign in to comment.