Skip to content

Commit

Permalink
🛠 Refactor: RNIModalView
Browse files Browse the repository at this point in the history
Related:
* TODO:2023-03-04-06-34-28 - Library Native Cleanup.
* TODO:2023-03-22-12-09-34 - Move to `get` property called `synthesizedNativeEventBase`.

Summary:  Replace `RNIModalView.createModalNativeEventDict` w/ `synthesizedBaseEventData`.
  • Loading branch information
dominicstop committed Mar 26, 2023
1 parent b5ad43a commit f8f3838
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 29 deletions.
45 changes: 18 additions & 27 deletions ios/src_library/React Native/RNIModalView/RNIModalView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,14 @@ class RNIModalView: UIView, RNIModalFocusNotifying, RNIModalIdentity,
return blurStyle;
};

var synthesizedBaseEventData: RNIModalBaseEventData {
RNIModalBaseEventData(
reactTag: self.reactTag.intValue,
modalID: self.modalID as? String,
modalData: self.synthesizedModalData
);
};

// MARK: - Init
// ------------

Expand Down Expand Up @@ -455,26 +463,6 @@ class RNIModalView: UIView, RNIModalFocusNotifying, RNIModalIdentity,
// MARK: - Functions - Internal
// ----------------------------

/// TODO:2023-03-22-12-09-34 - Move to `get` property called
/// `synthesizedNativeEventBase`
///
/// helper function to create a `NativeEvent` object
func createModalNativeEventDict() -> Dictionary<String, Any> {
let baseEvent = RNIModalBaseEventData(
reactTag: self.reactTag.intValue,
modalID: self.modalID as? String,
modalNativeID: self.modalNativeID,
modalIndex: self.modalIndex,
currentModalIndex: RNIModalManagerShared.currentModalIndex,
isModalPresented: self.isModalPresented,
isModalInFocus: self.isModalInFocus,
synthesizedIsModalInFocus: self.synthesizedIsModalInFocus,
synthesizedIsModalPresented: self.synthesizedIsModalPresented,
synthesizedModalIndex: self.synthesizedModalIndex
);

return baseEvent.synthesizedDictionary;
};

// MARK: - Functions - Public
// --------------------------
Expand Down Expand Up @@ -561,7 +549,7 @@ class RNIModalView: UIView, RNIModalFocusNotifying, RNIModalIdentity,
self.modalFocusDelegate.onModalDidFocusNotification(sender: self);

self.onModalShow?(
self.createModalNativeEventDict()
self.synthesizedBaseEventData.synthesizedDictionary
);

completion?(true, nil);
Expand Down Expand Up @@ -629,7 +617,7 @@ class RNIModalView: UIView, RNIModalFocusNotifying, RNIModalIdentity,
self.delegate?.onDismissModalView(modalView: self);

self.onModalDismiss?(
self.createModalNativeEventDict()
self.synthesizedBaseEventData.synthesizedDictionary
);

self.deinitControllers();
Expand All @@ -652,7 +640,10 @@ class RNIModalView: UIView, RNIModalFocusNotifying, RNIModalIdentity,
"visibility": visibility,
];

self.createModalNativeEventDict().forEach { (key, value) in
let baseEventDataDict =
self.synthesizedBaseEventData.synthesizedDictionary;

baseEventDataDict.forEach { (key, value) in
params[key] = value
};

Expand Down Expand Up @@ -686,7 +677,7 @@ extension RNIModalView: UIAdaptivePresentationControllerDelegate {
};

self.onModalWillDismiss?(
self.createModalNativeEventDict()
self.synthesizedBaseEventData.synthesizedDictionary
);

#if DEBUG
Expand All @@ -705,11 +696,11 @@ extension RNIModalView: UIAdaptivePresentationControllerDelegate {
self.delegate?.onDismissModalView(modalView: self);

self.onModalDidDismiss?(
self.createModalNativeEventDict()
self.synthesizedBaseEventData.synthesizedDictionary
);

self.onModalDismiss?(
self.createModalNativeEventDict()
self.synthesizedBaseEventData.synthesizedDictionary
);

self.deinitControllers();
Expand All @@ -723,7 +714,7 @@ extension RNIModalView: UIAdaptivePresentationControllerDelegate {

func presentationControllerDidAttemptToDismiss(_ presentationController: UIPresentationController) {
self.onModalAttemptDismiss?(
self.createModalNativeEventDict()
self.synthesizedBaseEventData.synthesizedDictionary
);

#if DEBUG
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,9 @@ extension RNIModalViewModule {

modalView.setModalVisibility(visibility: visibility) { isSuccess, error in
if isSuccess {
resolve(modalView.createModalNativeEventDict());
resolve(
modalView.synthesizedBaseEventData.synthesizedDictionary
);

} else {
reject(nil, error?.errorMessage, nil);
Expand All @@ -197,7 +199,9 @@ extension RNIModalViewModule {
return;
};

resolve(modalView.createModalNativeEventDict());
resolve(
modalView.synthesizedBaseEventData.synthesizedDictionary
);
};
};
};

0 comments on commit f8f3838

Please sign in to comment.