Skip to content

Commit

Permalink
💫 Update: RNIModalView - Use State didChange
Browse files Browse the repository at this point in the history
  • Loading branch information
dominicstop committed Apr 14, 2023
1 parent 10413c2 commit b77ede7
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions ios/src_library/React Native/RNIModalView/RNIModalView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -761,9 +761,11 @@ extension RNIModalView: RNIViewControllerLifeCycleNotifiable {
guard sender.isBeingPresented else { return };
self.modalPresentationState.set(state: .PRESENTING_UNKNOWN);

self.onModalWillShow?(
self.synthesizedBaseEventData.synthesizedJSDictionary
);
if self.modalPresentationState.didChange {
self.onModalWillShow?(
self.synthesizedBaseEventData.synthesizedJSDictionary
);
};

self.modalPresentationNotificationDelegate
.notifyOnModalWillShow(sender: self);
Expand All @@ -773,9 +775,11 @@ extension RNIModalView: RNIViewControllerLifeCycleNotifiable {
guard sender.isBeingPresented else { return };
self.modalPresentationState.set(state: .PRESENTED_UNKNOWN);

self.onModalDidShow?(
self.synthesizedBaseEventData.synthesizedJSDictionary
);
if self.modalPresentationState.didChange {
self.onModalDidShow?(
self.synthesizedBaseEventData.synthesizedJSDictionary
);
};

self.modalPresentationNotificationDelegate
.notifyOnModalDidShow(sender: self);
Expand All @@ -786,9 +790,11 @@ extension RNIModalView: RNIViewControllerLifeCycleNotifiable {
guard sender.isBeingDismissed else { return };
self.modalPresentationState.set(state: .DISMISSING_UNKNOWN);

self.onModalWillHide?(
self.synthesizedBaseEventData.synthesizedJSDictionary
);
if self.modalPresentationState.didChange {
self.onModalWillHide?(
self.synthesizedBaseEventData.synthesizedJSDictionary
);
};

self.modalPresentationNotificationDelegate
.notifyOnModalWillHide(sender: self);
Expand All @@ -799,9 +805,11 @@ extension RNIModalView: RNIViewControllerLifeCycleNotifiable {
guard sender.isBeingDismissed else { return };
self.modalPresentationState.set(state: .DISMISSED);

self.onModalDidHide?(
self.synthesizedBaseEventData.synthesizedJSDictionary
);
if self.modalPresentationState.didChange {
self.onModalDidHide?(
self.synthesizedBaseEventData.synthesizedJSDictionary
);
};

self.modalPresentationNotificationDelegate
.notifyOnModalDidHide(sender: self);
Expand Down Expand Up @@ -888,6 +896,8 @@ extension RNIModalView: RNIViewControllerLifeCycleNotifiable {
extension RNIModalView: RNIModalFocusNotifiable {

public func onModalWillFocusNotification(sender: any RNIModal) {
guard self.modalFocusState.didChange else { return };

let eventData = RNIOnModalFocusEventData(
modalData: self.synthesizedBaseEventData,
senderInfo: sender.synthesizedModalData,
Expand All @@ -900,6 +910,7 @@ extension RNIModalView: RNIModalFocusNotifiable {
};

public func onModalDidFocusNotification(sender: any RNIModal) {
guard self.modalFocusState.didChange else { return };

let eventData = RNIOnModalFocusEventData(
modalData: self.synthesizedBaseEventData,
Expand All @@ -924,6 +935,8 @@ extension RNIModalView: RNIModalFocusNotifiable {
};

public func onModalWillBlurNotification(sender: any RNIModal) {
guard self.modalFocusState.didChange else { return };

let eventData = RNIOnModalFocusEventData(
modalData: self.synthesizedBaseEventData,
senderInfo: sender.synthesizedModalData,
Expand All @@ -936,6 +949,8 @@ extension RNIModalView: RNIModalFocusNotifiable {
};

public func onModalDidBlurNotification(sender: any RNIModal) {
guard self.modalFocusState.didChange else { return };

let eventData = RNIOnModalFocusEventData(
modalData: self.synthesizedBaseEventData,
senderInfo: sender.synthesizedModalData,
Expand Down

0 comments on commit b77ede7

Please sign in to comment.