Skip to content

Commit

Permalink
⭐️ Impl: Add RNIModalFlags
Browse files Browse the repository at this point in the history
  • Loading branch information
dominicstop committed Apr 27, 2023
1 parent 34e998b commit 4f8ba70
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ extension UIViewController {
};

internal static func swizzleMethods() {
guard RNIModalSwizzling.shouldEnableSwizzling else { return };
guard RNIModalFlagsShared.shouldSwizzleViewControllers else { return };

#if DEBUG
print(
Expand Down
21 changes: 21 additions & 0 deletions ios/src_library/React Native/RNIModal/RNIModalFlags.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// RNIModalFlags.swift
// react-native-ios-modal
//
// Created by Dominic Go on 4/27/23.
//

import Foundation

public var RNIModalFlagsShared = RNIModalFlags.sharedInstance;

public class RNIModalFlags {
static let sharedInstance = RNIModalFlags();

var isModalViewPresentationNotificationEnabled = true;

var shouldSwizzleViewControllers = true;
var shouldSwizzledViewControllerNotifyAll = false;
var shouldWrapAllViewControllers = false;

};
12 changes: 0 additions & 12 deletions ios/src_library/React Native/RNIModal/RNIModalSwizzling.swift

This file was deleted.

30 changes: 20 additions & 10 deletions ios/src_library/React Native/RNIModalView/RNIModalView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,10 @@ public class RNIModalView:
return nil;
};

var isModalViewPresentationNotificationEnabled: Bool {
RNIModalFlagsShared.isModalViewPresentationNotificationEnabled
};

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

Expand Down Expand Up @@ -1102,8 +1106,10 @@ extension RNIModalView: RNIViewControllerLifeCycleNotifiable {
);
};

self.modalPresentationNotificationDelegate
.notifyOnModalWillShow(sender: self);
if self.isModalViewPresentationNotificationEnabled {
self.modalPresentationNotificationDelegate
.notifyOnModalWillShow(sender: self);
};
};

public func viewDidAppear(sender: UIViewController, animated: Bool) {
Expand All @@ -1116,9 +1122,10 @@ extension RNIModalView: RNIViewControllerLifeCycleNotifiable {
);
};

self.modalPresentationNotificationDelegate
.notifyOnModalDidShow(sender: self);

if self.isModalViewPresentationNotificationEnabled {
self.modalPresentationNotificationDelegate
.notifyOnModalDidShow(sender: self);
};
};

public func viewWillDisappear(sender: UIViewController, animated: Bool) {
Expand All @@ -1131,9 +1138,10 @@ extension RNIModalView: RNIViewControllerLifeCycleNotifiable {
);
};

self.modalPresentationNotificationDelegate
.notifyOnModalWillHide(sender: self);

if self.isModalViewPresentationNotificationEnabled {
self.modalPresentationNotificationDelegate
.notifyOnModalWillHide(sender: self);
};
};

public func viewDidDisappear(sender: UIViewController, animated: Bool) {
Expand All @@ -1146,8 +1154,10 @@ extension RNIModalView: RNIViewControllerLifeCycleNotifiable {
);
};

self.modalPresentationNotificationDelegate
.notifyOnModalDidHide(sender: self);
if self.isModalViewPresentationNotificationEnabled {
self.modalPresentationNotificationDelegate
.notifyOnModalDidHide(sender: self);
};

self.deinitControllers();
};
Expand Down

0 comments on commit 4f8ba70

Please sign in to comment.