Skip to content

Commit

Permalink
🛠 Refactor: RNIDictionarySynthesizable
Browse files Browse the repository at this point in the history
Summary: Re-write `RNIDictionarySynthesizable.synthesizedDictionary`, and update usage.
  • Loading branch information
dominicstop committed Apr 10, 2023
1 parent db9f121 commit 043d64e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 23 deletions.
35 changes: 26 additions & 9 deletions ios/src_library/Helpers+Utilities/RNIDictionarySynthesizable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ public protocol RNIDictionarySynthesizable {
static var synthesizedDictionaryInlinedProperties: [PartialKeyPath<Self>] { get };

/// A map of the property names and their respective values
var synthesizedDictionary: Dictionary<String, Any> { get };

func synthesizedDictionary(isJSDict: Bool) -> Dictionary<String, Any>;
};

extension RNIDictionarySynthesizable {
Expand All @@ -35,7 +34,10 @@ extension RNIDictionarySynthesizable {
[];
};

public var synthesizedDictionary: Dictionary<String, Any> {
public func synthesizedDictionary(
isJSDict: Bool
) -> Dictionary<String, Any> {

let mirror = Mirror(reflecting: self);
let properties = mirror.children;

Expand All @@ -58,11 +60,22 @@ extension RNIDictionarySynthesizable {
!Self.synthesizedDictionaryIgnore.contains(propertyKey)
else { return nil };

if let synthesizableDict = value as? (any RNIDictionarySynthesizable) {
return(propertyKey, synthesizableDict.synthesizedDictionary);
};
let parseValue: Any = {
if let synthesizableDict = value as? (any RNIDictionarySynthesizable) {
return synthesizableDict.synthesizedDictionary;

} else if isJSDict,
let rawValue = value as? any RawRepresentable {

return rawValue.rawValue;
};

return value;
}();


return (propertyKey, value)

return (propertyKey, parseValue)
};

var baseDict = Dictionary(
Expand All @@ -73,10 +86,14 @@ extension RNIDictionarySynthesizable {
guard let value = self[keyPath: $0] as? (any RNIDictionarySynthesizable)
else { return };

baseDict =
baseDict.merging(value.synthesizedDictionary){ old, _ in old };
let inlindedDict = value.synthesizedDictionary(isJSDict: isJSDict);
baseDict = baseDict.merging(inlindedDict){ old, _ in old };
};

return baseDict;
};

public var synthesizedJSDictionary: Dictionary<String, Any> {
self.synthesizedDictionary(isJSDict: true);
};
};
4 changes: 0 additions & 4 deletions ios/src_library/React Native/RNIModal/RNIModal+Helpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,4 @@ extension RNIModalState where Self: RNIModal {
synthesizedWindowID: self.window?.synthesizedStringID
);
};

public var synthesizedModalDataDict: Dictionary<String, Any> {
self.synthesizedModalData.synthesizedDictionary;
};
};
16 changes: 8 additions & 8 deletions ios/src_library/React Native/RNIModalView/RNIModalView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ public class RNIModalView: UIView, RNIIdentifiable,
];

let baseEventDataDict =
self.synthesizedBaseEventData.synthesizedDictionary;
self.synthesizedBaseEventData.synthesizedJSDictionary;

baseEventDataDict.forEach { (key, value) in
params[key] = value
Expand Down Expand Up @@ -694,7 +694,7 @@ extension RNIModalView: UIAdaptivePresentationControllerDelegate {
///
public func presentationControllerDidAttemptToDismiss(_ presentationController: UIPresentationController) {
self.onModalAttemptDismiss?(
self.synthesizedBaseEventData.synthesizedDictionary
self.synthesizedBaseEventData.synthesizedJSDictionary
);

#if DEBUG
Expand Down Expand Up @@ -751,7 +751,7 @@ extension RNIModalView: RNIViewControllerLifeCycleNotifiable {

if !self.modalPresentationState.wasDismissViaGestureCancelled {
self.onModalShow?(
self.synthesizedBaseEventData.synthesizedDictionary
self.synthesizedBaseEventData.synthesizedJSDictionary
);
};
};
Expand All @@ -765,7 +765,7 @@ extension RNIModalView: RNIViewControllerLifeCycleNotifiable {

if self.modalPresentationState.state.isDismissingViaGesture {
self.onModalWillDismiss?(
self.synthesizedBaseEventData.synthesizedDictionary
self.synthesizedBaseEventData.synthesizedJSDictionary
);
};
};
Expand All @@ -779,12 +779,12 @@ extension RNIModalView: RNIViewControllerLifeCycleNotifiable {

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

} else {
self.onModalDismiss?(
self.synthesizedBaseEventData.synthesizedDictionary
self.synthesizedBaseEventData.synthesizedJSDictionary
);
};

Expand Down Expand Up @@ -892,7 +892,7 @@ extension RNIModalView: RNIModalFocusNotifiable {
#endif

self.onModalFocus?(
eventData.synthesizedDictionary
eventData.synthesizedJSDictionary
);
};

Expand All @@ -918,7 +918,7 @@ extension RNIModalView: RNIModalFocusNotifiable {
#endif

self.onModalBlur?(
eventData.synthesizedDictionary
eventData.synthesizedJSDictionary
);
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class RNIModalViewModule: RCTEventEmitter {
modalView.setModalVisibility(visibility: visibility) { isSuccess, error in
if isSuccess {
resolve(
modalView.synthesizedBaseEventData.synthesizedDictionary
modalView.synthesizedBaseEventData.synthesizedJSDictionary
);

} else {
Expand All @@ -183,7 +183,7 @@ class RNIModalViewModule: RCTEventEmitter {
};

resolve(
modalView.synthesizedBaseEventData.synthesizedDictionary
modalView.synthesizedBaseEventData.synthesizedJSDictionary
);
};
};
Expand Down

0 comments on commit 043d64e

Please sign in to comment.