Skip to content

Commit

Permalink
⭐️ Impl: Native Modal Events
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-15-54-06` - Impl. new `RNIModalView` native events.
  • Loading branch information
dominicstop committed Apr 14, 2023
1 parent d5c8449 commit 75a9b24
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 4 deletions.
86 changes: 82 additions & 4 deletions ios/src_library/React Native/RNIModalView/RNIModalView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,28 @@ public class RNIModalView:
// MARK: - Properties: React Props - Events
// ----------------------------------------


var onModalWillPresent: RCTBubblingEventBlock?;
var onModalDidPresent: RCTBubblingEventBlock?;

var onModalWillDismiss: RCTBubblingEventBlock?;
var onModalDidDismiss: RCTBubblingEventBlock?;

var onModalWillShow: RCTBubblingEventBlock?;
var onModalDidShow: RCTBubblingEventBlock?;

var onModalWillHide: RCTBubblingEventBlock?;
var onModalDidHide: RCTBubblingEventBlock?;

var onModalWillFocus: RCTBubblingEventBlock?;
var onModalDidFocus: RCTBubblingEventBlock?;

var onModalWillBlur: RCTBubblingEventBlock?;
var onModalDidBlur: RCTBubblingEventBlock?;

var onPresentationControllerWillDismiss: RCTBubblingEventBlock?;
var onPresentationControllerDidDismiss: RCTBubblingEventBlock?;
var onPresentationControllerDidAttemptToDismiss: RCTBubblingEventBlock?;

// MARK: - Properties: React Props - Value
// ---------------------------------------

Expand Down Expand Up @@ -475,11 +496,20 @@ public class RNIModalView:
/// set specific "presenting" state
self.modalPresentationState.set(state: .PRESENTING_PROGRAMMATIC);

self.onModalWillPresent?(
self.synthesizedBaseEventData.synthesizedJSDictionary
);

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

self.modalPresentationState.set(state: .PRESENTED);

self.onModalDidPresent?(
self.synthesizedBaseEventData.synthesizedJSDictionary
);

completion?(true, nil);

#if DEBUG
Expand Down Expand Up @@ -558,8 +588,17 @@ public class RNIModalView:
/// set specific "dismissing" state
self.modalPresentationState.set(state: .DISMISSING_PROGRAMMATIC);

self.onModalWillDismiss?(
self.synthesizedBaseEventData.synthesizedJSDictionary
);

presentedVC.dismiss(animated: true){
self.modalPresentationState.set(state: .DISMISSED);

self.onModalDidDismiss?(
self.synthesizedBaseEventData.synthesizedJSDictionary
);

completion?(true, nil);

#if DEBUG
Expand Down Expand Up @@ -722,6 +761,10 @@ extension RNIModalView: RNIViewControllerLifeCycleNotifiable {
guard sender.isBeingPresented else { return };
self.modalPresentationState.set(state: .PRESENTING_UNKNOWN);

self.onModalWillShow?(
self.synthesizedBaseEventData.synthesizedJSDictionary
);

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

self.onModalDidShow?(
self.synthesizedBaseEventData.synthesizedJSDictionary
);

self.modalPresentationNotificationDelegate
.notifyOnModalDidShow(sender: self);

Expand All @@ -739,6 +786,10 @@ extension RNIModalView: RNIViewControllerLifeCycleNotifiable {
guard sender.isBeingDismissed else { return };
self.modalPresentationState.set(state: .DISMISSING_UNKNOWN);

self.onModalWillHide?(
self.synthesizedBaseEventData.synthesizedJSDictionary
);

self.modalPresentationNotificationDelegate
.notifyOnModalWillHide(sender: self);

Expand All @@ -748,6 +799,10 @@ extension RNIModalView: RNIViewControllerLifeCycleNotifiable {
guard sender.isBeingDismissed else { return };
self.modalPresentationState.set(state: .DISMISSED);

self.onModalDidHide?(
self.synthesizedBaseEventData.synthesizedJSDictionary
);

self.modalPresentationNotificationDelegate
.notifyOnModalDidHide(sender: self);

Expand Down Expand Up @@ -833,7 +888,15 @@ extension RNIModalView: RNIViewControllerLifeCycleNotifiable {
extension RNIModalView: RNIModalFocusNotifiable {

public func onModalWillFocusNotification(sender: any RNIModal) {
/// No-op - TBA
let eventData = RNIOnModalFocusEventData(
modalData: self.synthesizedBaseEventData,
senderInfo: sender.synthesizedModalData,
isInitial: sender === self
);

self.onModalWillFocus?(
eventData.synthesizedJSDictionary
);
};

public func onModalDidFocusNotification(sender: any RNIModal) {
Expand All @@ -844,6 +907,10 @@ extension RNIModalView: RNIModalFocusNotifiable {
isInitial: sender === self
);

self.onModalDidFocus?(
eventData.synthesizedJSDictionary
);

#if DEBUG
print(
"Log - RNIModalView.onModalDidFocusNotification"
Expand All @@ -857,7 +924,15 @@ extension RNIModalView: RNIModalFocusNotifiable {
};

public func onModalWillBlurNotification(sender: any RNIModal) {
/// No-op - TBA
let eventData = RNIOnModalFocusEventData(
modalData: self.synthesizedBaseEventData,
senderInfo: sender.synthesizedModalData,
isInitial: sender === self
);

self.onModalWillBlur?(
eventData.synthesizedJSDictionary
);
};

public func onModalDidBlurNotification(sender: any RNIModal) {
Expand All @@ -867,6 +942,10 @@ extension RNIModalView: RNIModalFocusNotifiable {
isInitial: sender === self
);

self.onModalDidFocus?(
eventData.synthesizedJSDictionary
);

#if DEBUG
print(
"Log - RNIModalView.onModalDidBlurNotification"
Expand All @@ -876,6 +955,5 @@ extension RNIModalView: RNIModalFocusNotifiable {
+ " - arg sender.modalIndex: \(sender.modalIndex!)"
);
#endif

};
};
22 changes: 22 additions & 0 deletions ios/src_library/React Native/RNIModalView/RNIModalViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,28 @@ @interface RCT_EXTERN_MODULE(RNIModalViewManager, RCTViewManager)
// MARK: Props - Callbacks/Events
// ------------------------------

RCT_EXPORT_VIEW_PROPERTY(onModalWillPresent, RCTDirectEventBlock);
RCT_EXPORT_VIEW_PROPERTY(onModalDidPresent, RCTDirectEventBlock);

RCT_EXPORT_VIEW_PROPERTY(onModalWillDismiss, RCTDirectEventBlock);
RCT_EXPORT_VIEW_PROPERTY(onModalDidDismiss, RCTDirectEventBlock);

RCT_EXPORT_VIEW_PROPERTY(onModalWillShow, RCTDirectEventBlock);
RCT_EXPORT_VIEW_PROPERTY(onModalDidShow, RCTDirectEventBlock);

RCT_EXPORT_VIEW_PROPERTY(onModalWillHide, RCTDirectEventBlock);
RCT_EXPORT_VIEW_PROPERTY(onModalDidHide, RCTDirectEventBlock);

RCT_EXPORT_VIEW_PROPERTY(onModalWillFocus, RCTDirectEventBlock);
RCT_EXPORT_VIEW_PROPERTY(onModalDidFocus, RCTDirectEventBlock);

RCT_EXPORT_VIEW_PROPERTY(onModalWillBlur, RCTDirectEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onModalDidBlur, RCTDirectEventBlock)

RCT_EXPORT_VIEW_PROPERTY(onPresentationControllerWillDismiss, RCTDirectEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onPresentationControllerDidDismiss, RCTDirectEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onPresentationControllerDidAttemptToDismiss, RCTDirectEventBlock);

// --------------------------------
// MARK: Props - RN Component Props
// --------------------------------
Expand Down

0 comments on commit 75a9b24

Please sign in to comment.