From d94b1e66d65ada90bedc4b784b07f15f36fd534b Mon Sep 17 00:00:00 2001 From: Dominic Go <18517029+dominicstop@users.noreply.github.com> Date: Thu, 15 Jun 2023 22:20:57 +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 Summary: Update experiment/test - `swift-programmatic-modal/AdaptiveModal`. --- .../AdaptiveModal/AdaptiveModalManager.swift | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalManager.swift b/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalManager.swift index 99299dae..2df2050f 100644 --- a/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalManager.swift +++ b/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalManager.swift @@ -938,9 +938,16 @@ class AdaptiveModalManager: NSObject { let inputCoord = coord ?? inputRect.origin[keyPath: self.modalConfig.inputValueKeyForPoint]; + + let inputCoordAdj = inputCoord < 0 + ? min(inputCoord, 0) + : inputCoord; let delta = self.interpolationSteps.map { - abs($0.computedRect.origin[keyPath: self.modalConfig.inputValueKeyForPoint] - inputCoord); + let origin = $0.computedRect.origin; + let coord = origin[keyPath: self.modalConfig.inputValueKeyForPoint]; + + return abs(coord - inputCoordAdj); }; let deltaSorted = delta.enumerated().sorted { @@ -1076,7 +1083,6 @@ class AdaptiveModalManager: NSObject { case .changed: self.modalAnimator?.stopAnimation(true); - self.applyInterpolationToModal(forGesturePoint: gesturePoint); self.notifyOnModalWillSnap(); @@ -1086,7 +1092,12 @@ class AdaptiveModalManager: NSObject { return; }; - let gestureFinalPoint = self.gestureFinalPoint ?? gesturePoint; + let gestureFinalPointRaw = self.gestureFinalPoint ?? gesturePoint; + + let gestureFinalPoint = CGPoint( + x: gestureFinalPointRaw.x - self.gestureOffset!.x, + y: gestureFinalPointRaw.y - self.gestureOffset!.y + ); self.snapToClosestSnapPoint(forPoint: gestureFinalPoint) { self.endDisplayLink(); @@ -1169,7 +1180,7 @@ class AdaptiveModalManager: NSObject { let interpolationSteps = self.interpolationSteps!; let prevIndex = self.currentInterpolationIndex; - let nextIndex: Int = { + let nextIndexRaw: Int = { guard let nextIndex = self.nextInterpolationIndex else { let closestSnapPoint = self.getClosestSnapPoint(); return closestSnapPoint.interpolationPoint.snapPointIndex; @@ -1178,6 +1189,7 @@ class AdaptiveModalManager: NSObject { return nextIndex; }(); + let nextIndex = self.adjustInterpolationIndex(for: nextIndexRaw); let nextPoint = self.interpolationSteps[nextIndex]; guard prevIndex != nextIndex else { return };