Skip to content

Commit

Permalink
🛠 Refactor: Rename synthesized- Suffix Usage
Browse files Browse the repository at this point in the history
  • Loading branch information
dominicstop committed Apr 10, 2023
1 parent 7b875e1 commit db9f121
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 25 deletions.
38 changes: 21 additions & 17 deletions ios/src_library/React Native/RNIModal/RNIModal+Helpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@ extension RNIModalState where Self: RNIIdentifiable {

extension RNIModalState where Self: RNIModalPresentation {

internal var synthesizedWindowMapData: RNIWindowMapData? {
guard let window = self.window else { return nil };
return RNIModalWindowMapShared.get(forWindow: window);
};

/// Programmatically check if this instance is presented
public var synthesizedIsModalPresented: Bool {
public var computedIsModalPresented: Bool {
let listPresentedVC =
RNIModalManager.getPresentedViewControllers(for: self.window);

Expand All @@ -26,12 +31,12 @@ extension RNIModalState where Self: RNIModalPresentation {
};

/// Programmatically check if this instance is in focus
public var synthesizedIsModalInFocus: Bool {
public var computedIsModalInFocus: Bool {
let listPresentedVC =
RNIModalManager.getPresentedViewControllers(for: self.window);

guard let topmostVC = listPresentedVC.last
else { return self.isModalInFocus };
else { return self.synthesizedIsModalInFocus };

return topmostVC === self.modalViewController;
};
Expand All @@ -41,7 +46,7 @@ extension RNIModalState where Self: RNIModalPresentation {
/// * This is based on the view controller hierarchy
/// * So parent/child view controller that aren't modals are also counted
///
public var synthesizedViewControllerIndex: Int {
public var computedViewControllerIndex: Int {
let listPresentedVC =
RNIModalManager.getPresentedViewControllers(for: self.window);

Expand All @@ -54,7 +59,7 @@ extension RNIModalState where Self: RNIModalPresentation {
};

/// Programmatically get the "modal index"
public var synthesizedModalIndex: Int {
public var computedModalIndex: Int {
guard let window = self.window,
let modalVC = self.modalViewController
else { return -1 };
Expand All @@ -65,16 +70,15 @@ extension RNIModalState where Self: RNIModalPresentation {
);
};

public var synthesizedCurrentModalIndex: Int {
RNIModalManager.computeModalIndex(forWindow: self.window);
public var currentModalIndex: Int {
self.synthesizedWindowMapData?.modalIndexCurrent ?? -1;
};

internal var synthesizedWindowMapData: RNIWindowMapData? {
guard let window = self.window else { return nil };
return RNIModalWindowMapShared.get(forWindow: window);
public var computedCurrentModalIndex: Int {
RNIModalManager.computeModalIndex(forWindow: self.window);
};

public var isModalInFocus: Bool {
public var synthesizedIsModalInFocus: Bool {
self.modalPresentationState.isPresented &&
self.modalFocusState.state.isFocused;
};
Expand All @@ -86,13 +90,13 @@ extension RNIModalState where Self: RNIModal {
return RNIModalData(
modalNativeID: self.modalNativeID,
modalIndex: self.modalIndex,
currentModalIndex: self.synthesizedCurrentModalIndex,
currentModalIndex: self.currentModalIndex,
isModalPresented: self.modalPresentationState.isPresented,
isModalInFocus: self.isModalInFocus,
synthesizedIsModalInFocus: self.synthesizedIsModalInFocus,
synthesizedIsModalPresented: self.synthesizedIsModalPresented,
synthesizedModalIndex: self.synthesizedModalIndex,
synthesizedViewControllerIndex: self.synthesizedViewControllerIndex,
isModalInFocus: self.synthesizedIsModalInFocus,
computedIsModalInFocus: self.computedIsModalInFocus,
computedIsModalPresented: self.computedIsModalPresented,
computedModalIndex: self.computedModalIndex,
computedViewControllerIndex: self.computedViewControllerIndex,
synthesizedWindowID: self.window?.synthesizedStringID
);
};
Expand Down
8 changes: 4 additions & 4 deletions ios/src_library/React Native/RNIModal/RNIModalData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ public struct RNIModalData: RNIDictionarySynthesizable {
public let isModalPresented: Bool;
public let isModalInFocus: Bool;

public let synthesizedIsModalInFocus: Bool;
public let synthesizedIsModalPresented: Bool;
public let computedIsModalInFocus: Bool;
public let computedIsModalPresented: Bool;

public let synthesizedModalIndex: Int;
public let synthesizedViewControllerIndex: Int;
public let computedModalIndex: Int;
public let computedViewControllerIndex: Int;

public let synthesizedWindowID: String?;
};
8 changes: 4 additions & 4 deletions ios/src_library/React Native/RNIModalView/RNIModalView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ public class RNIModalView: UIView, RNIIdentifiable,
return;
};

guard !self.synthesizedIsModalPresented else {
guard !self.computedIsModalPresented else {
#if DEBUG
print(
"Error - RNIModalView.presentModal"
Expand Down Expand Up @@ -514,7 +514,7 @@ public class RNIModalView: UIView, RNIIdentifiable,
};

public func dismissModal(completion: CompletionHandler? = nil) {
guard self.synthesizedIsModalPresented else {
guard self.computedIsModalPresented else {
#if DEBUG
print(
"Error - RNIModalView.dismissModal"
Expand All @@ -539,7 +539,7 @@ public class RNIModalView: UIView, RNIIdentifiable,
return;
};

let isModalInFocus = self.synthesizedIsModalInFocus;
let isModalInFocus = self.computedIsModalInFocus;

let shouldDismiss = isModalInFocus
? true
Expand All @@ -552,7 +552,7 @@ public class RNIModalView: UIView, RNIIdentifiable,
+ " - self.modalNativeID: \(self.modalNativeID)"
+ " - Guard check failed: Unable to dismiss"
+ " - shouldDismiss: \(shouldDismiss)"
+ " - isModalInFocus: \(isModalInFocus)"
+ " - isModalInFocus: \(computedIsModalInFocus)"
);
#endif
completion?(false, .modalDismissFailedNotInFocus);
Expand Down

0 comments on commit db9f121

Please sign in to comment.