Skip to content

Commit

Permalink
💫 Update: Exp - AdaptiveModal
Browse files Browse the repository at this point in the history
Summary: Update experiment/test - `swift-programmatic-modal/AdaptiveModal`.
  • Loading branch information
dominicstop committed Jun 16, 2023
1 parent adec25c commit 6a07637
Showing 1 changed file with 31 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class AdaptiveModalManager: NSObject {
lazy var dummyModalView = UIView();
lazy var modalWrapperView = UIView();
lazy var modalWrapperTransformView = UIView();
lazy var modalWrapperShadowView = UIView();

var prevModalFrame: CGRect = .zero;

Expand Down Expand Up @@ -305,15 +306,24 @@ class AdaptiveModalManager: NSObject {
bgDimmingView.alpha = 0;
};

let modalWrapperView = self.modalWrapperView;
targetView.addSubview(modalWrapperView);
let wrapperViews = [
self.modalWrapperView,
self.modalWrapperTransformView,
self.modalWrapperShadowView,
modalView,
];

let modalWrapperTransformView = self.modalWrapperTransformView;
modalWrapperView.addSubview(modalWrapperTransformView);
wrapperViews.enumerated().forEach {
guard let prev = wrapperViews[safeIndex: $0.offset - 1] else {
targetView.addSubview($0.element);
return;
};

prev.addSubview($0.element);
};

modalView.clipsToBounds = true;
modalView.backgroundColor = .clear;
modalWrapperTransformView.addSubview(modalView);

if let modalBackgroundView = self.modalBackgroundView {
modalView.addSubview(modalBackgroundView);
Expand Down Expand Up @@ -349,25 +359,21 @@ class AdaptiveModalManager: NSObject {
]);
};

if let parentView = self.modalWrapperTransformView.superview {
self.modalWrapperTransformView.translatesAutoresizingMaskIntoConstraints = false;

NSLayoutConstraint.activate([
self.modalWrapperTransformView.centerXAnchor.constraint(equalTo: parentView.centerXAnchor),
self.modalWrapperTransformView.centerYAnchor.constraint(equalTo: parentView.centerYAnchor),
self.modalWrapperTransformView.widthAnchor .constraint(equalTo: parentView.widthAnchor ),
self.modalWrapperTransformView.heightAnchor .constraint(equalTo: parentView.heightAnchor ),
]);
};
let wrapperViews = [
self.modalWrapperTransformView,
self.modalWrapperShadowView,
modalView,
];

if let parentView = modalView.superview {
modalView.translatesAutoresizingMaskIntoConstraints = false;
wrapperViews.forEach {
guard let parentView = $0.superview else { return };
$0.translatesAutoresizingMaskIntoConstraints = false;

NSLayoutConstraint.activate([
modalView.centerXAnchor.constraint(equalTo: parentView.centerXAnchor),
modalView.centerYAnchor.constraint(equalTo: parentView.centerYAnchor),
modalView.widthAnchor .constraint(equalTo: parentView.widthAnchor ),
modalView.heightAnchor .constraint(equalTo: parentView.heightAnchor ),
$0.centerXAnchor.constraint(equalTo: parentView.centerXAnchor),
$0.centerYAnchor.constraint(equalTo: parentView.centerYAnchor),
$0.widthAnchor .constraint(equalTo: parentView.widthAnchor ),
$0.heightAnchor .constraint(equalTo: parentView.heightAnchor ),
]);
};

Expand Down Expand Up @@ -904,8 +910,11 @@ class AdaptiveModalManager: NSObject {

private func cleanupViews() {
let viewsToCleanup: [UIView?] = [
self.modalWrapperView,
self.dummyModalView,
self.modalWrapperView,
// self.modalWrapperTransformView,
// self.nodalView,
self.modalWrapperShadowView,
self.modalBackgroundView,
self.modalBackgroundVisualEffectView,
self.backgroundDimmingView,
Expand Down

0 comments on commit 6a07637

Please sign in to comment.