From 9fbd460f4d450a454ac263660cdede95cca5a7d9 Mon Sep 17 00:00:00 2001 From: Dominic Go <18517029+dominicstop@users.noreply.github.com> Date: Mon, 19 Jun 2023 07:30:15 +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 | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalManager.swift b/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalManager.swift index 81dc8dc6..183c37d4 100644 --- a/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalManager.swift +++ b/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalManager.swift @@ -1115,7 +1115,7 @@ class AdaptiveModalManager: NSObject { let origin = $0.computedRect.origin; let coord = origin[keyPath: self.modalConfig.inputValueKeyForPoint]; - return abs(coord - inputCoordAdj); + return abs(inputCoordAdj - coord); }; let deltaSorted = delta.enumerated().sorted { @@ -1128,6 +1128,23 @@ class AdaptiveModalManager: NSObject { let interpolationPoint = interpolationSteps[closestInterpolationIndex]; let snapPointIndex = interpolationPoint.snapPointIndex; + let coords = self.interpolationSteps.map { + let origin = $0.computedRect.origin; + let coord = origin[keyPath: self.modalConfig.inputValueKeyForPoint]; + + return coord; + }; + + print( + "getClosestSnapPoint" + + "\n - inputCoordAdj: \(inputCoordAdj)" + + "\n - coords: \(coords)" + + "\n - delta: \(delta)" + + "\n - deltaSorted: \(deltaSorted)" + + "\n - closestInterpolationIndex: \(closestInterpolationIndex)" + + "\n" + ); + return ( interpolationIndex: closestInterpolationIndex, snapPointConfig: self.modalConfig.snapPoints[snapPointIndex], @@ -1274,6 +1291,15 @@ class AdaptiveModalManager: NSObject { y: gestureFinalPointRaw.y - (self.gestureOffset?.y ?? 0) ); + print( + "onDragPanGesture" + + "\n - gesturePoint: \(gesturePoint)" + + "\n - gestureVelocity: \(gestureVelocity)" + + "\n - gestureFinalPointRaw: \(gestureFinalPointRaw)" + + "\n - gestureFinalPoint: \(gestureFinalPoint)" + + "\n" + ); + self.snapToClosestSnapPoint(forPoint: gestureFinalPoint) { self.notifyOnModalDidSnap(); }; @@ -1532,6 +1558,16 @@ class AdaptiveModalManager: NSObject { let coord = point[keyPath: self.modalConfig.inputValueKeyForPoint]; let closestSnapPoint = self.getClosestSnapPoint(forCoord: coord); + print( + "snapToClosestSnapPoint" + + "\n - coord: \(coord)" + + "\n - closestSnapPoint.interpolationIndex: \(closestSnapPoint.interpolationIndex)" + + "\n - closestSnapPoint.snapDistance: \(closestSnapPoint.snapDistance)" + + "\n - closestSnapPoint.interpolationPoint: \(closestSnapPoint.interpolationPoint)" + + "\n - closestSnapPoint.snapPointConfig: \(closestSnapPoint.snapPointConfig)" + + "\n" + ); + let nextInterpolationIndex = self.adjustInterpolationIndex(for: closestSnapPoint.interpolationIndex);