Skip to content

Commit

Permalink
💫 Update: Exp - AdaptiveModal
Browse files Browse the repository at this point in the history
💫 Update: Exp - `AdaptiveModal`
6b43793
Summary: Update experiment/test - `swift-programmatic-modal/AdaptiveModal`.
  • Loading branch information
dominicstop committed Jun 5, 2023
1 parent 40576ed commit de02dc7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -216,19 +216,23 @@ struct AdaptiveModalInterpolationPoint: Equatable {
};

func apply(toModalView modalView: UIView){
modalView.frame = self.computedRect;
//modalView.frame = self.computedRect;

modalView.layer.cornerRadius = self.modalCornerRadius;
modalView.layer.maskedCorners = self.modalMaskedCorners;
};

func apply(toModalWrapperView modalWrapperView: UIView){
//modalView.frame = self.computedRect;
modalWrapperView.frame = self.computedRect;
};

func apply(toDummyModalView dummyModalView: UIView){
dummyModalView.frame = self.computedRect;
};

func apply(toModalBackgroundView modalBgView: UIView?){
modalBgView?.alpha = self.modalBackgroundOpacity;
modalBgView?.transform = self.modalTransform;
};

func apply(toBackgroundEffectView effectView: UIVisualEffectView?){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class AdaptiveModalManager {
weak var eventDelegate: AdaptiveModalEventNotifiable?;

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

weak var targetView: UIView?;
weak var modalView: UIView?;
Expand Down Expand Up @@ -74,8 +75,8 @@ class AdaptiveModalManager {
let newValue = newValue
else { return };

self.prevModalFrame = modalView.frame;
modalView.frame = newValue;
self.prevModalFrame = dummyModalView.frame;
self.modalWrapperView.frame = newValue;

self.dummyModalView.frame = newValue;
}
Expand Down Expand Up @@ -253,10 +254,12 @@ class AdaptiveModalManager {
bgDimmingView.alpha = 0;
};

targetView.addSubview(modalView);
let modalWrapperView = self.modalWrapperView;
targetView.addSubview(modalWrapperView);

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

if let modalBackgroundView = self.modalBackgroundView {
modalView.addSubview(modalBackgroundView);
Expand Down Expand Up @@ -292,6 +295,15 @@ class AdaptiveModalManager {
]);
};

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

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

Expand Down Expand Up @@ -746,6 +758,7 @@ class AdaptiveModalManager {

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

interpolationPoint.apply(toDummyModalView: self.dummyModalView);
interpolationPoint.apply(toModalBackgroundView: self.modalBackgroundView);
Expand Down

0 comments on commit de02dc7

Please sign in to comment.