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 4, 2023
1 parent 2dec67d commit ea46c45
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,80 @@ class AdaptiveModalManager {
self.clearAnimators();
};

// MARK: - Functions - Setup
// -------------------------

func setupAddViews(){
guard let modalView = self.modalView,
let targetView = self.targetView
else { return };

if let bgVisualEffectView = self.backgroundVisualEffectView {
targetView.addSubview(bgVisualEffectView);

bgVisualEffectView.clipsToBounds = true;
bgVisualEffectView.backgroundColor = .clear;
};

targetView.addSubview(modalView);

modalView.clipsToBounds = true;
modalView.backgroundColor = .clear;

if let modalBackgroundView = self.modalBackgroundView {
modalView.addSubview(modalBackgroundView);
modalView.sendSubviewToBack(modalBackgroundView);

modalBackgroundView.backgroundColor = .systemBackground;
};

if let modalBGVisualEffectView = self.modalBackgroundVisualEffectView {
modalView.addSubview(modalBGVisualEffectView);
modalView.sendSubviewToBack(modalBGVisualEffectView);

modalBGVisualEffectView.clipsToBounds = true;
modalBGVisualEffectView.backgroundColor = .clear;
};
};

func setupViewConstraints(){
guard let modalView = self.modalView,
let targetView = self.targetView
else { return };

if let bgVisualEffectView = self.backgroundVisualEffectView {
bgVisualEffectView.translatesAutoresizingMaskIntoConstraints = false;

NSLayoutConstraint.activate([
bgVisualEffectView.topAnchor .constraint(equalTo: targetView.topAnchor ),
bgVisualEffectView.bottomAnchor .constraint(equalTo: targetView.bottomAnchor ),
bgVisualEffectView.leadingAnchor .constraint(equalTo: targetView.leadingAnchor ),
bgVisualEffectView.trailingAnchor.constraint(equalTo: targetView.trailingAnchor),
]);
};

if let modalBGView = self.modalBackgroundView {
modalBGView.translatesAutoresizingMaskIntoConstraints = false;

NSLayoutConstraint.activate([
modalBGView.topAnchor .constraint(equalTo: modalView.topAnchor ),
modalBGView.bottomAnchor .constraint(equalTo: modalView.bottomAnchor ),
modalBGView.leadingAnchor .constraint(equalTo: modalView.leadingAnchor ),
modalBGView.trailingAnchor.constraint(equalTo: modalView.trailingAnchor),
]);
};

if let modalBGVisualEffectView = self.modalBackgroundVisualEffectView {
modalBGVisualEffectView.translatesAutoresizingMaskIntoConstraints = false;

NSLayoutConstraint.activate([
modalBGVisualEffectView.topAnchor .constraint(equalTo: modalView.topAnchor ),
modalBGVisualEffectView.bottomAnchor .constraint(equalTo: modalView.bottomAnchor ),
modalBGVisualEffectView.leadingAnchor .constraint(equalTo: modalView.leadingAnchor ),
modalBGVisualEffectView.trailingAnchor.constraint(equalTo: modalView.trailingAnchor),
]);
};
};

// MARK: - Functions - Interpolation-Related
// -----------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ enum AdaptiveModalConfigTestPresets: CaseIterable {
)
),
animationKeyframe: AdaptiveModalAnimationConfig(
modalBackgroundOpacity: 0.85,
modalBackgroundOpacity: 0.83,
modalCornerRadius: 15,
modalMaskedCorners: [
.layerMinXMinYCorner,
Expand Down Expand Up @@ -335,54 +335,19 @@ class RNIDraggableTestViewController : UIViewController {
let dummyBackgroundView = self.dummyBackgroundView;
self.view.addSubview(dummyBackgroundView);

let modalBackgroundView = self.modalBackgroundView;
let modalBackgroundVisualEffectView = self.modalBackgroundVisualEffectView;

self.floatingView.addSubview(modalBackgroundView);
self.floatingView.addSubview(modalBackgroundVisualEffectView);

self.floatingView.sendSubviewToBack(modalBackgroundView);
self.floatingView.sendSubviewToBack(modalBackgroundVisualEffectView);

let backgroundVisualEffectView = self.backgroundVisualEffectView;
self.view.addSubview(backgroundVisualEffectView);

// backgroundVisualEffectView.effect = nil;

let floatingView = self.floatingView;
self.view.addSubview(floatingView);

backgroundVisualEffectView.clipsToBounds = true;
floatingView.clipsToBounds = true;

self.floatingViewLabel.text = "\(self.modalManager.currentSnapPointIndex)";

dummyBackgroundView.translatesAutoresizingMaskIntoConstraints = false;
modalBackgroundView.translatesAutoresizingMaskIntoConstraints = false;
modalBackgroundVisualEffectView.translatesAutoresizingMaskIntoConstraints = false;
backgroundVisualEffectView.translatesAutoresizingMaskIntoConstraints = false;


NSLayoutConstraint.activate([
dummyBackgroundView.topAnchor.constraint(equalTo: self.view.topAnchor),
dummyBackgroundView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor),
dummyBackgroundView.leadingAnchor.constraint(equalTo: self.view.leadingAnchor),
dummyBackgroundView.trailingAnchor.constraint(equalTo: self.view.trailingAnchor),

modalBackgroundView.topAnchor.constraint(equalTo: self.floatingView.topAnchor),
modalBackgroundView.bottomAnchor.constraint(equalTo: self.floatingView.bottomAnchor),
modalBackgroundView.leadingAnchor.constraint(equalTo: self.floatingView.leadingAnchor),
modalBackgroundView.trailingAnchor.constraint(equalTo: self.floatingView.trailingAnchor),

modalBackgroundVisualEffectView.topAnchor.constraint(equalTo: self.floatingView.topAnchor),
modalBackgroundVisualEffectView.bottomAnchor.constraint(equalTo: self.floatingView.bottomAnchor),
modalBackgroundVisualEffectView.leadingAnchor.constraint(equalTo: self.floatingView.leadingAnchor),
modalBackgroundVisualEffectView.trailingAnchor.constraint(equalTo: self.floatingView.trailingAnchor),

backgroundVisualEffectView.topAnchor.constraint(equalTo: self.view.topAnchor),
backgroundVisualEffectView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor),
backgroundVisualEffectView.leadingAnchor.constraint(equalTo: self.view.leadingAnchor),
backgroundVisualEffectView.trailingAnchor.constraint(equalTo: self.view.trailingAnchor),
]);

self.modalManager.setupAddViews();
self.modalManager.setupViewConstraints();
};

override func viewDidLayoutSubviews() {
Expand Down

0 comments on commit ea46c45

Please sign in to comment.