Skip to content

Commit

Permalink
💫 Update: Exp - AdaptiveModal
Browse files Browse the repository at this point in the history
Undo previous commit.
  • Loading branch information
dominicstop committed May 31, 2023
1 parent f16e8c0 commit d56cd14
Showing 1 changed file with 12 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ class AdaptiveModalManager {
weak var targetView: UIView?;
weak var modalView: UIView?;

var modalMaskView: UIView?;

var gestureOffset: CGFloat?;
var gestureVelocity: CGPoint?;
var gestureInitialPoint: CGPoint?;
Expand All @@ -50,13 +48,11 @@ class AdaptiveModalManager {
var modalFrame: CGRect? {
set {
guard let modalView = self.modalView,
let modalMaskView = self.modalMaskView,
let newValue = newValue
else { return };

self.prevModalFrame = modalView.frame;
modalView.frame = newValue;
modalMaskView.frame = newValue;
}
get {
self.modalView?.frame;
Expand Down Expand Up @@ -163,12 +159,6 @@ class AdaptiveModalManager {
self.modalView = modalView;
self.targetView = targetView;
self.currentSizeProvider = currentSizeProvider;

let modalMaskView = UIView(frame: modalView.frame);
modalMaskView.backgroundColor = .blue;
modalView.mask = modalMaskView;

self.modalMaskView = modalMaskView;
};


Expand Down Expand Up @@ -306,7 +296,6 @@ class AdaptiveModalManager {

func interpolateModal(forGesturePoint gesturePoint: CGPoint){
guard let modalView = self.modalView,
let modalMaskView = self.modalMaskView,
let gestureInitialPoint = self.gestureInitialPoint
else { return };

Expand Down Expand Up @@ -336,9 +325,9 @@ class AdaptiveModalManager {

if let modalBorderRadiusMask = self.interpolateModalBorderRadius(
forInputValue: gestureInput,
modalBounds: modalMaskView.bounds
modalBounds: modalView.bounds
) {
modalMaskView.layer.mask = modalBorderRadiusMask;
modalView.layer.mask = modalBorderRadiusMask;
};
};

Expand Down Expand Up @@ -392,7 +381,6 @@ class AdaptiveModalManager {

self.animator = animator;


animator.addAnimations {
modalView.frame = interpolationPoint.computedRect;
};
Expand All @@ -403,11 +391,8 @@ class AdaptiveModalManager {

animator.addCompletion { _ in
self.animator = nil;
// modalView.backgroundColor = .red;

};

//modalView.backgroundColor = .red;

animator.startAnimation();
};

Expand Down Expand Up @@ -535,10 +520,6 @@ class AdaptiveModalManager {
let modalViewPresentationLayer = modalView.layer.presentation()
else { return };

return;

modalView.backgroundColor = .blue;

if self.isSwiping {
self.endDisplayLink();
};
Expand All @@ -549,21 +530,21 @@ class AdaptiveModalManager {
let inputValueNext = nextModalFrame.origin[keyPath: self.inputAxisKey];
let inputValuePrev = prevModalFrame.origin[keyPath: self.inputAxisKey];

//guard inputValueNext != inputValuePrev else { return };
guard inputValueNext != inputValuePrev else { return };
self.prevModalFrame = nextModalFrame;

print(
"onDisplayLinkTick"
+ "\n - displayLink.timestamp: \(displayLink.timestamp)"
+ "\n - inputValueNext: \(inputValueNext)"
);

if let nextModalBorderRadiusMask = self.interpolateModalBorderRadius(
forInputValue: inputValueNext,
modalBounds: modalViewPresentationLayer.bounds
) {
modalView.layer.mask = nextModalBorderRadiusMask;
};

print(
"onDisplayLinkTick"
+ "\n - displayLink.timestamp: \(displayLink.timestamp)"
+ "\n - presentation frame: \(modalView.layer.presentation()?.frame)"
);
};


Expand All @@ -589,17 +570,14 @@ class AdaptiveModalManager {
self.gestureVelocity = gestureVelocity;

switch gesture.state {
case .began, .cancelled:
case .began:
self.gestureInitialPoint = gesturePoint;

self.endDisplayLink();
self.animator?.stopAnimation(true);
self.animator = nil;

case .changed:
self.interpolateModal(forGesturePoint: gesturePoint);

case .ended:
case .cancelled, .ended:
guard self.enableSnapping else {
self.clearGestureValues();
return;
Expand Down

0 comments on commit d56cd14

Please sign in to comment.