diff --git a/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalManager.swift b/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalManager.swift index 6dab9030..3eaec5f1 100644 --- a/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalManager.swift +++ b/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalManager.swift @@ -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 // ----------------------------------------- diff --git a/experiments/swift-programmatic-modal/Test/RNIDraggableTestViewController.swift b/experiments/swift-programmatic-modal/Test/RNIDraggableTestViewController.swift index d9d7cc29..856154bb 100644 --- a/experiments/swift-programmatic-modal/Test/RNIDraggableTestViewController.swift +++ b/experiments/swift-programmatic-modal/Test/RNIDraggableTestViewController.swift @@ -212,7 +212,7 @@ enum AdaptiveModalConfigTestPresets: CaseIterable { ) ), animationKeyframe: AdaptiveModalAnimationConfig( - modalBackgroundOpacity: 0.85, + modalBackgroundOpacity: 0.83, modalCornerRadius: 15, modalMaskedCorners: [ .layerMinXMinYCorner, @@ -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() {