Skip to content

Commit

Permalink
🛠 Refactor: Replace RNIModal.isModalPresented
Browse files Browse the repository at this point in the history
Related:
* `TODO:2023-03-31-18-33-34` - Unify/streamline/consolidate logic for invoking modal focus/blur.
* `TODO:2023-04-07-06-10-22` Refactor - Replace `RNIModalState.isModalPresented`  w/  `RNIModalPresentationState`.

Summary:
* Replace `RNIModalState.isModalPresented` w/ `modalState`.
* Remove `RNIModalView.isModalPresented`.
* Impl. `RNIModalView.modalState`.
* Impl. `RNIModalPresentationState.isPresented`.
* Replace all usage of `RNIModalState.isModalPresented` w/ `RNIModalPresentationStateMachine.isPresented`.
  • Loading branch information
dominicstop committed Apr 6, 2023
1 parent 1a8f5e0 commit 9e4fac4
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ extension RNIModalState where Self: RNIModal {
modalNativeID: self.modalNativeID,
modalIndex: self.modalIndex,
currentModalIndex: self.synthesizedCurrentModalIndex,
isModalPresented: self.isModalPresented,
isModalPresented: self.modalState.isPresented,
isModalInFocus: self.isModalInFocus,
synthesizedIsModalInFocus: self.synthesizedIsModalInFocus,
synthesizedIsModalPresented: self.synthesizedIsModalPresented,
Expand Down
2 changes: 1 addition & 1 deletion ios/src_library/React Native/RNIModal/RNIModal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public protocol RNIModalState: AnyObject {

var modalIndex: Int! { set get };

var isModalPresented: Bool { set get };
var modalState: RNIModalPresentationStateMachine { set get };

var isModalInFocus: Bool { set get };

Expand Down
17 changes: 9 additions & 8 deletions ios/src_library/React Native/RNIModal/RNIModalManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public class RNIModalManager {

public var presentedModals: [any RNIModal] {
self.modalInstances.compactMap {
$0.isModalPresented ? $0 : nil;
$0.modalState.isPresented ? $0 : nil;
};
};

Expand All @@ -196,7 +196,6 @@ public class RNIModalManager {
modal.modalIndex = -1;
modal.modalIndexPrev = -1;

modal.isModalPresented = false;
modal.isModalInFocus = false;

modal.modalFocusDelegate = self;
Expand Down Expand Up @@ -263,11 +262,12 @@ extension RNIModalManager: RNIModalFocusNotifiable {

self.setCurrentModalIndex(for: senderWindow, index: nextModalIndex);

sender.modalState.set(state: .PRESENTING_UNKNOWN);
sender.onModalWillFocusNotification(sender: sender);

self.modalInstances.forEach {
guard $0 !== sender,
$0.isModalPresented,
$0.modalState.isPresented,
$0.isModalInFocus,
$0.modalIndex == prevModalIndex
else { return };
Expand All @@ -291,7 +291,7 @@ extension RNIModalManager: RNIModalFocusNotifiable {
let currentModalIndex = self.getCurrentModalIndex(for: senderWindow);

sender.isModalInFocus = true;
sender.isModalPresented = true;
sender.modalState.set(state: .PRESENTED);

#if DEBUG
print(
Expand All @@ -307,7 +307,7 @@ extension RNIModalManager: RNIModalFocusNotifiable {

self.modalInstances.forEach {
guard $0 !== sender,
$0.isModalPresented,
$0.modalState.isPresented,
$0.isModalInFocus,
$0.modalIndex == currentModalIndex - 1
else { return };
Expand Down Expand Up @@ -337,11 +337,12 @@ extension RNIModalManager: RNIModalFocusNotifiable {
sender.modalIndexPrev = sender.modalIndex;
sender.modalIndex = -1;

sender.modalState.set(state: .DISMISSING_UNKNOWN);
sender.onModalWillBlurNotification(sender: sender);

self.modalInstances.forEach {
guard $0 !== sender,
$0.isModalPresented,
$0.modalState.isPresented,
!$0.isModalInFocus,
$0.modalIndex >= nextModalIndex
else { return };
Expand All @@ -365,7 +366,7 @@ extension RNIModalManager: RNIModalFocusNotifiable {
let currentModalIndex = self.getCurrentModalIndex(for: senderWindow);

sender.isModalInFocus = false;
sender.isModalPresented = false;
sender.modalState.set(state: .DISMISSED);

#if DEBUG
print(
Expand All @@ -381,7 +382,7 @@ extension RNIModalManager: RNIModalFocusNotifiable {

self.modalInstances.forEach {
guard $0 !== sender,
$0.isModalPresented,
$0.modalState.isPresented,
!$0.isModalInFocus,
$0.modalIndex >= currentModalIndex
else { return };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ public struct RNIModalPresentationStateMachine {
// MARK: - Computed Properties
// ---------------------------

var isPresented: Bool {
self.state == .PRESENTED;
};

var wasDismissViaGestureCancelled: Bool {
self.statePrev.isDismissViaGestureCancelling
};
Expand Down
20 changes: 9 additions & 11 deletions ios/src_library/React Native/RNIModalView/RNIModalView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,6 @@ class RNIModalView: UIView, RNIIdentifiable, RNIModalFocusNotifying,
var modalContentWrapper: RNIWrapperView?;
var modalVC: RNIModalViewController?;

lazy var modalState = RNIModalPresentationStateMachine(
onDismissWillCancel: { [weak self] in
// no-op - TBA
},
onDismissDidCancel: { [weak self] in
// no-op - TBA
}
);


// MARK: - Properties - RNIModalFocusNotifying
// -------------------------------------------

Expand All @@ -54,7 +44,15 @@ class RNIModalView: UIView, RNIIdentifiable, RNIModalFocusNotifying,
// MARK: - Properties - RNIModalState
// ----------------------------------

var isModalPresented: Bool = false;
lazy var modalState = RNIModalPresentationStateMachine(
onDismissWillCancel: { [weak self] in
// no-op - TBA
},
onDismissDidCancel: { [weak self] in
// no-op - TBA
}
);

var isModalInFocus: Bool = false;

// MARK: - Properties - RNIModalPresentation
Expand Down

0 comments on commit 9e4fac4

Please sign in to comment.