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 a3d5f4a commit 0de7e25
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ struct AdaptiveModalInterpolationPoint: Equatable {
modalView.layer.maskedCorners = self.modalMaskedCorners;
};

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

func apply(toModalBackgroundView modalBgView: UIView?){
modalBgView?.alpha = self.modalBackgroundOpacity;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class AdaptiveModalManager {
// ------------------------------------

var currentSizeProvider: () -> CGSize;

lazy var dummyModalView = UIView();

weak var targetView: UIView?;
weak var modalView: UIView?;
Expand Down Expand Up @@ -63,6 +65,8 @@ class AdaptiveModalManager {

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

self.dummyModalView.frame = newValue;
}
get {
self.modalView?.frame;
Expand Down Expand Up @@ -196,6 +200,8 @@ class AdaptiveModalManager {
self.backgroundDimmingView = backgroundDimmingView;

self.currentSizeProvider = currentSizeProvider;

self.setupdummyModalView();
};

deinit {
Expand All @@ -205,6 +211,17 @@ class AdaptiveModalManager {
// MARK: - Functions - Setup
// -------------------------

private func setupdummyModalView(){
guard let targetView = self.targetView else { return };
let dummyModalView = self.dummyModalView;

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 Down Expand Up @@ -720,6 +737,7 @@ class AdaptiveModalManager {
animator.addAnimations {
interpolationPoint.apply(toModalView: modalView);

interpolationPoint.apply(toDummyModalView: self.dummyModalView);
interpolationPoint.apply(toModalBackgroundView: self.modalBackgroundView);
interpolationPoint.apply(toBackgroundView: self.backgroundDimmingView);
};
Expand Down Expand Up @@ -830,8 +848,8 @@ class AdaptiveModalManager {
};

@objc func onDisplayLinkTick(displayLink: CADisplayLink) {
guard let modalView = self.modalView,
let modalViewPresentationLayer = modalView.layer.presentation(),
guard let dummyModalViewPresentationLayer =
self.dummyModalView.layer.presentation(),
let interpolationRangeMaxInput = self.interpolationRangeMaxInput
else { return };

Expand All @@ -844,7 +862,7 @@ class AdaptiveModalManager {
};

let prevModalFrame = self.prevModalFrame;
let nextModalFrame = modalViewPresentationLayer.frame;
let nextModalFrame = dummyModalViewPresentationLayer.frame;

guard prevModalFrame != nextModalFrame else { return };

Expand Down

0 comments on commit 0de7e25

Please sign in to comment.