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);