Skip to content

Commit

Permalink
💫 Update: RNIModalFocusNotifiable
Browse files Browse the repository at this point in the history
Summary: Update parameters in `RNIModalFocusNotifiable`, and update existing usage.
  • Loading branch information
dominicstop committed Mar 30, 2023
1 parent 5787d82 commit 2aa36cb
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 41 deletions.
8 changes: 4 additions & 4 deletions ios/src_library/React Native/RNIModal/RNIModal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ public protocol RNIModalRequestable: AnyObject {
/// modal "focus/blur"-related notifications.
///
public protocol RNIModalFocusNotifiable: AnyObject {
func onModalWillFocusNotification(sender modal: any RNIModal);
func onModalWillFocusNotification(sender: any RNIModal);

func onModalDidFocusNotification(sender modal: any RNIModal);
func onModalDidFocusNotification(sender: any RNIModal);

func onModalWillBlurNotification(sender modal: any RNIModal);
func onModalWillBlurNotification(sender: any RNIModal);

func onModalDidBlurNotification(sender modal: any RNIModal);
func onModalDidBlurNotification(sender: any RNIModal);

};

Expand Down
48 changes: 23 additions & 25 deletions ios/src_library/React Native/RNIModal/RNIModalManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -204,78 +204,76 @@ public class RNIModalManager {
///
extension RNIModalManager: RNIModalFocusNotifiable {

public func onModalWillFocusNotification(
sender modal: any RNIModal
) {
public func onModalWillFocusNotification(sender: any RNIModal) {
let nextModalIndex = self.currentModalIndex + 1;
self.currentModalIndex = nextModalIndex;

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

modal.onModalWillFocusNotification(sender: modal);
sender.onModalWillFocusNotification(sender: sender);

self.modalInstances.forEach {
guard $0 !== modal,
guard $0 !== sender,
$0.isModalPresented,
$0.isModalInFocus,
$0.modalIndex == self.currentModalIndex - 1
else { return };

$0.onModalWillBlurNotification(sender: modal);
$0.onModalWillBlurNotification(sender: sender);
};
};

public func onModalDidFocusNotification(sender modal: any RNIModal) {
modal.isModalInFocus = true;
modal.isModalPresented = true;
public func onModalDidFocusNotification(sender: any RNIModal) {
sender.isModalInFocus = true;
sender.isModalPresented = true;

modal.onModalDidFocusNotification(sender: modal);
sender.onModalDidFocusNotification(sender: sender);

self.modalInstances.forEach {
guard $0 !== modal,
guard $0 !== sender,
$0.isModalPresented,
$0.isModalInFocus,
$0.modalIndex == self.currentModalIndex - 1
else { return };

$0.isModalInFocus = false;
$0.onModalDidBlurNotification(sender: modal);
$0.onModalDidBlurNotification(sender: sender);
};
};

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

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

modal.onModalWillBlurNotification(sender: modal);
sender.onModalWillBlurNotification(sender: sender);

self.modalInstances.forEach {
guard $0 !== modal,
guard $0 !== sender,
$0.isModalPresented,
!$0.isModalInFocus,
$0.modalIndex >= self.currentModalIndex
else { return };

$0.onModalWillFocusNotification(sender: modal);
$0.onModalWillFocusNotification(sender: sender);
};
};

public func onModalDidBlurNotification(sender modal: any RNIModal) {
modal.isModalInFocus = false;
modal.isModalPresented = false;
public func onModalDidBlurNotification(sender: any RNIModal) {
sender.isModalInFocus = false;
sender.isModalPresented = false;

self.modalInstances.forEach {
guard $0 !== modal,
guard $0 !== sender,
$0.isModalPresented,
!$0.isModalInFocus,
$0.modalIndex >= self.currentModalIndex
else { return };

$0.isModalInFocus = true;
$0.onModalDidFocusNotification(sender: modal);
$0.onModalDidFocusNotification(sender: sender);
};
};
};
24 changes: 12 additions & 12 deletions ios/src_library/React Native/RNIModalView/RNIModalView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -717,25 +717,25 @@ extension RNIModalView: RNIModalRequestable {

extension RNIModalView: RNIModalFocusNotifiable {

func onModalWillFocusNotification(sender modal: any RNIModal) {
func onModalWillFocusNotification(sender: any RNIModal) {
/// No-op - TBA
};

func onModalDidFocusNotification(sender modal: any RNIModal) {
func onModalDidFocusNotification(sender: any RNIModal) {

let eventData = RNIOnModalFocusEventData(
modalData: self.synthesizedBaseEventData,
senderInfo: modal.synthesizedModalData,
isInitial: modal === self
senderInfo: sender.synthesizedModalData,
isInitial: sender === self
);

#if DEBUG
print(
"Log - RNIModalView.onModalDidFocusNotification"
+ " - self.synthesizedStringID: \(self.synthesizedStringID)"
+ " - self.modalIndex: \(self.modalIndex!)"
+ " - arg modal.synthesizedStringID: \(modal.synthesizedStringID)"
+ " - arg modal.modalIndex: \(modal.modalIndex!)"
+ " - arg modal.synthesizedStringID: \(sender.synthesizedStringID)"
+ " - arg modal.modalIndex: \(sender.modalIndex!)"
);
#endif

Expand All @@ -744,24 +744,24 @@ extension RNIModalView: RNIModalFocusNotifiable {
);
};

func onModalWillBlurNotification(sender modal: any RNIModal) {
func onModalWillBlurNotification(sender: any RNIModal) {
/// No-op - TBA
};

func onModalDidBlurNotification(sender modal: any RNIModal) {
func onModalDidBlurNotification(sender: any RNIModal) {
let eventData = RNIOnModalFocusEventData(
modalData: self.synthesizedBaseEventData,
senderInfo: modal.synthesizedModalData,
isInitial: modal === self
senderInfo: sender.synthesizedModalData,
isInitial: sender === self
);

#if DEBUG
print(
"Log - RNIModalView.onModalDidBlurNotification"
+ " - self.synthesizedStringID: \(self.synthesizedStringID)"
+ " - self.modalIndex: \(self.modalIndex!)"
+ " - arg modal.synthesizedStringID: \(modal.synthesizedStringID)"
+ " - arg modal.modalIndex: \(modal.modalIndex!)"
+ " - arg modal.synthesizedStringID: \(sender.synthesizedStringID)"
+ " - arg modal.modalIndex: \(sender.modalIndex!)"
);
#endif

Expand Down

0 comments on commit 2aa36cb

Please sign in to comment.