Skip to content

Commit

Permalink
🛠 Refactor: Rename RNIModal.modalState
Browse files Browse the repository at this point in the history
Summary: Rename `RNIModal.modalState` to `modalPresentationState`.
  • Loading branch information
dominicstop committed Apr 10, 2023
1 parent fa04652 commit 891eef9
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ extension RNIModalState where Self: RNIModal {
modalNativeID: self.modalNativeID,
modalIndex: self.modalIndex,
currentModalIndex: self.synthesizedCurrentModalIndex,
isModalPresented: self.modalState.isPresented,
isModalPresented: self.modalPresentationState.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,9 +33,9 @@ public protocol RNIModalState: AnyObject {

var modalIndex: Int! { set get };

var modalState: RNIModalPresentationStateMachine { set get };

var isModalInFocus: Bool { set get };
var modalPresentationState: RNIModalPresentationStateMachine { set get };

};

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

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

Expand Down Expand Up @@ -355,7 +355,7 @@ extension RNIModalManager: RNIModalPresentationNotifiable {
);
#endif

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

modalInstances.forEach {
Expand Down Expand Up @@ -418,7 +418,7 @@ extension RNIModalManager: RNIModalPresentationNotifiable {
#endif

sender.isModalInFocus = true;
sender.modalState.set(state: .PRESENTED_FOCUSED);
sender.modalPresentationState.set(state: .PRESENTED_UNKNOWN);

sender.onModalDidFocusNotification(sender: sender);

Expand Down Expand Up @@ -485,7 +485,7 @@ extension RNIModalManager: RNIModalPresentationNotifiable {
);
#endif

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

modalInstances.forEach {
Expand Down Expand Up @@ -548,7 +548,7 @@ extension RNIModalManager: RNIModalPresentationNotifiable {
#endif

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

sender.onModalDidBlurNotification(sender: sender);

Expand Down
26 changes: 14 additions & 12 deletions ios/src_library/React Native/RNIModalView/RNIModalView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class RNIModalView: UIView, RNIIdentifiable,
// MARK: - Properties - RNIModalState
// ----------------------------------

public lazy var modalState = RNIModalPresentationStateMachine(
public lazy var modalPresentationState = RNIModalPresentationStateMachine(
onDismissWillCancel: { [weak self] in
// no-op - TBA
},
Expand Down Expand Up @@ -493,12 +493,13 @@ public class RNIModalView: UIView, RNIIdentifiable,
self.presentingViewController = topMostPresentedVC;

/// set specific "presenting" state
self.modalState.set(state: .PRESENTING_PROGRAMMATIC);
self.modalPresentationState.set(state: .PRESENTING_PROGRAMMATIC);

topMostPresentedVC.present(modalVC, animated: true) { [unowned self] in
// Reset swipe gesture before it was temporarily disabled
self.enableSwipeGesture();


self.modalPresentationState.set(state: .PRESENTED);
completion?(true, nil);

#if DEBUG
Expand Down Expand Up @@ -575,7 +576,7 @@ public class RNIModalView: UIView, RNIIdentifiable,
self.enableSwipeGesture(false);

/// set specific "dismissing" state
self.modalState.set(state: .DISMISSING_PROGRAMMATIC);
self.modalPresentationState.set(state: .DISMISSING_PROGRAMMATIC);

presentedVC.dismiss(animated: true){
completion?(true, nil);
Expand Down Expand Up @@ -662,7 +663,7 @@ extension RNIModalView: UIAdaptivePresentationControllerDelegate {
/// * 4 - `viewDidAppear`
///
public func presentationControllerWillDismiss(_ presentationController: UIPresentationController) {
self.modalState.set(state: .DISMISSING_GESTURE);
self.modalPresentationState.set(state: .DISMISSING_GESTURE);

#if DEBUG
print(
Expand Down Expand Up @@ -735,20 +736,20 @@ extension RNIModalView: RNIViewControllerLifeCycleNotifiable {

public func viewWillAppear(sender: UIViewController, animated: Bool) {
guard sender.isBeingPresented else { return };
self.modalState.set(state: .PRESENTING_UNKNOWN);
self.modalPresentationState.set(state: .PRESENTING_UNKNOWN);

self.modalPresentationNotificationDelegate
.notifyOnModalWillShow(sender: self);
};

public func viewDidAppear(sender: UIViewController, animated: Bool) {
guard sender.isBeingPresented else { return };
self.modalState.set(state: .PRESENTED_UNKNOWN);
self.modalPresentationState.set(state: .PRESENTED_UNKNOWN);

self.modalPresentationNotificationDelegate
.notifyOnModalDidShow(sender: self);

if !self.modalState.wasDismissViaGestureCancelled {
if !self.modalPresentationState.wasDismissViaGestureCancelled {
self.onModalShow?(
self.synthesizedBaseEventData.synthesizedDictionary
);
Expand All @@ -757,12 +758,12 @@ extension RNIModalView: RNIViewControllerLifeCycleNotifiable {

public func viewWillDisappear(sender: UIViewController, animated: Bool) {
guard sender.isBeingDismissed else { return };
self.modalState.set(state: .DISMISSING_UNKNOWN);
self.modalPresentationState.set(state: .DISMISSING_UNKNOWN);

self.modalPresentationNotificationDelegate
.notifyOnModalWillHide(sender: self);

if self.modalState.state.isDismissingViaGesture {
if self.modalPresentationState.state.isDismissingViaGesture {
self.onModalWillDismiss?(
self.synthesizedBaseEventData.synthesizedDictionary
);
Expand All @@ -771,15 +772,16 @@ extension RNIModalView: RNIViewControllerLifeCycleNotifiable {

public func viewDidDisappear(sender: UIViewController, animated: Bool) {
guard sender.isBeingDismissed else { return };
self.modalState.set(state: .DISMISSED);
self.modalPresentationState.set(state: .DISMISSED);

self.modalPresentationNotificationDelegate
.notifyOnModalDidHide(sender: self);

if self.modalState.statePrev.isDismissingViaGesture {
if self.modalPresentationState.statePrev.isDismissingViaGesture {
self.onModalDidDismiss?(
self.synthesizedBaseEventData.synthesizedDictionary
);

} else {
self.onModalDismiss?(
self.synthesizedBaseEventData.synthesizedDictionary
Expand Down

0 comments on commit 891eef9

Please sign in to comment.