From d56cd14dd91cee89649fc67289bbe5615321f666 Mon Sep 17 00:00:00 2001 From: Dominic Go <18517029+dominicstop@users.noreply.github.com> Date: Wed, 31 May 2023 08:30:02 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=AB=20Update:=20Exp=20-=20`AdaptiveMod?= =?UTF-8?q?al`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Undo previous commit. --- .../AdaptiveModal/AdaptiveModalManager.swift | 46 +++++-------------- 1 file changed, 12 insertions(+), 34 deletions(-) diff --git a/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalManager.swift b/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalManager.swift index ff2ada7e..9aa3cb11 100644 --- a/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalManager.swift +++ b/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalManager.swift @@ -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?; @@ -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; @@ -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; }; @@ -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 }; @@ -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; }; }; @@ -392,7 +381,6 @@ class AdaptiveModalManager { self.animator = animator; - animator.addAnimations { modalView.frame = interpolationPoint.computedRect; }; @@ -403,11 +391,8 @@ class AdaptiveModalManager { animator.addCompletion { _ in self.animator = nil; - // modalView.backgroundColor = .red; - }; - - //modalView.backgroundColor = .red; + animator.startAnimation(); }; @@ -535,10 +520,6 @@ class AdaptiveModalManager { let modalViewPresentationLayer = modalView.layer.presentation() else { return }; - return; - - modalView.backgroundColor = .blue; - if self.isSwiping { self.endDisplayLink(); }; @@ -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)" + ); }; @@ -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;