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 568bd62 commit adec25c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ struct AdaptiveModalInterpolationPoint: Equatable {
};

func apply(toModalView modalView: UIView){
modalView.transform = self.modalTransform;
modalView.alpha = self.modalOpacity;

modalView.layer.cornerRadius = self.modalCornerRadius;
Expand All @@ -253,6 +252,10 @@ struct AdaptiveModalInterpolationPoint: Equatable {
modalWrapperView.frame = self.computedRect;
};

func apply(toModalWrapperTransformView view: UIView?){
view?.transform = self.modalTransform;
};

func apply(toDummyModalView dummyModalView: UIView){
dummyModalView.frame = self.computedRect;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class AdaptiveModalManager: NSObject {

lazy var dummyModalView = UIView();
lazy var modalWrapperView = UIView();
lazy var modalWrapperTransformView = UIView();

var prevModalFrame: CGRect = .zero;

Expand Down Expand Up @@ -276,16 +277,13 @@ class AdaptiveModalManager: NSObject {
guard let targetView = self.targetView else { return };
let dummyModalView = self.dummyModalView;

dummyModalView.removeAllAncestorConstraints();
dummyModalView.removeFromSuperview();

dummyModalView.backgroundColor = .clear;
dummyModalView.alpha = 0.1;
dummyModalView.isUserInteractionEnabled = false;

targetView.addSubview(dummyModalView);
};

func setupAddViews() {
guard let modalView = self.modalView,
let targetView = self.targetView
Expand All @@ -310,9 +308,12 @@ class AdaptiveModalManager: NSObject {
let modalWrapperView = self.modalWrapperView;
targetView.addSubview(modalWrapperView);

let modalWrapperTransformView = self.modalWrapperTransformView;
modalWrapperView.addSubview(modalWrapperTransformView);

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

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

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

NSLayoutConstraint.activate([
modalView.centerXAnchor.constraint(equalTo: self.modalWrapperView.centerXAnchor),
modalView.centerYAnchor.constraint(equalTo: self.modalWrapperView.centerYAnchor),
modalView.widthAnchor .constraint(equalTo: self.modalWrapperView.widthAnchor ),
modalView.heightAnchor .constraint(equalTo: self.modalWrapperView.heightAnchor ),
]);

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 ),
]);
};

if let parentView = modalView.superview {
modalView.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 ),
]);
};

if let bgDimmingView = self.backgroundDimmingView {
bgDimmingView.translatesAutoresizingMaskIntoConstraints = false;

Expand Down Expand Up @@ -733,7 +747,7 @@ class AdaptiveModalManager: NSObject {
);

AdaptiveModalUtilities.unwrapAndSetProperty(
forObject: modalView,
forObject: self.modalWrapperTransformView,
forPropertyKey: \.transform,
withValue: self.interpolateModalTransform(
forInputPercentValue: inputPercentValue
Expand Down Expand Up @@ -1071,14 +1085,17 @@ class AdaptiveModalManager: NSObject {

animator.addAnimations {
interpolationPoint.apply(toModalView: modalView);

interpolationPoint.apply(toModalWrapperView: self.modalWrapperView);
interpolationPoint.apply(toModalWrapperTransformView: self.modalWrapperTransformView);

interpolationPoint.apply(toDummyModalView: self.dummyModalView);
interpolationPoint.apply(toModalBackgroundView: self.modalBackgroundView);
interpolationPoint.apply(toBackgroundView: self.backgroundDimmingView);

interpolationPoint.apply(toModalBackgroundEffectView: self.modalBackgroundVisualEffectView);
interpolationPoint.apply(toBackgroundVisualEffectView: self.backgroundVisualEffectView);

};

if let completion = completion {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import UIKit

enum AdaptiveModalConfigTestPresets: CaseIterable {

static let `default`: Self = .test03;
static let `default`: Self = .testModalTransform01;

case testModalTransform01;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class TestModalViewController: UIViewController, AdaptiveModalEventNotifiable {
class AdaptiveModalPresentationTestViewController : UIViewController {

lazy var adaptiveModalManager = AdaptiveModalManager(
modalConfig: AdaptiveModalConfigTestPresets.test03.config
modalConfig: AdaptiveModalConfigTestPresets.default.config
);

override func viewDidLoad() {
Expand Down

0 comments on commit adec25c

Please sign in to comment.