From c71d6a7581abcc1832714b6c3ebdbb42f94840fe Mon Sep 17 00:00:00 2001 From: Dominic Go <18517029+dominicstop@users.noreply.github.com> Date: Tue, 20 Jun 2023 11:21:19 +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 | 35 +++++++++---------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalManager.swift b/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalManager.swift index d85d8206..e18bca86 100644 --- a/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalManager.swift +++ b/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalManager.swift @@ -122,7 +122,7 @@ class AdaptiveModalManager: NSObject { private var shouldClearOverrideSnapPoints: Bool { self.shouldUseOverrideSnapPoints && - self.currentOverrideInterpolationIndex == 0; + self.currentOverrideInterpolationIndex < overrideInterpolationPoints!.count - 2; }; // MARK: - Properties - Interpolation Points @@ -1798,7 +1798,7 @@ class AdaptiveModalManager: NSObject { ) { self.cleanupSnapPointOverride(); - let prevInterpolationPoint: AdaptiveModalInterpolationPoint = { + let prevInterpolationPoints: [AdaptiveModalInterpolationPoint] = { let overrideInterpolationPoint = AdaptiveModalInterpolationPoint( usingModalConfig: self.modalConfig, snapPointIndex: 1, @@ -1806,19 +1806,20 @@ class AdaptiveModalManager: NSObject { snapPointConfig: overrideSnapPointConfig ); - let match = self.configInterpolationSteps.first { + let items = self.configInterpolationSteps.filter { $0.percent < overrideInterpolationPoint.percent; }; - guard let match = match else { - return self.configInterpolationSteps.first!; + guard items.count > 0 else { + return [self.configInterpolationSteps.first!]; }; - return match; + return items; }(); - let prevSnapPointConfig = - self.modalConfig.snapPoints[prevInterpolationPoint.snapPointIndex]; + let prevSnapPointConfigs = prevInterpolationPoints.map { + self.modalConfig.snapPoints[$0.snapPointIndex]; + }; let overshootSnapPointPreset = overshootSnapPointPreset ?? .getDefaultOvershootSnapPoint(forDirection: modalConfig.snapDirection); @@ -1828,15 +1829,17 @@ class AdaptiveModalManager: NSObject { fromBaseLayoutConfig: overrideSnapPointConfig.snapPoint ); - let snapPoints = [ - prevSnapPointConfig, + let snapPoints = prevSnapPointConfigs + [ overrideSnapPointConfig, overshootSnapPointConfig, ]; - var interpolationPoints: [AdaptiveModalInterpolationPoint] = [ - prevInterpolationPoint - ]; + var interpolationPoints = prevInterpolationPoints.enumerated().map { + var copy = $0.element; + copy.snapPointIndex = $0.offset; + + return copy; + }; let nextInterpolationPoint = AdaptiveModalInterpolationPoint( usingModalConfig: self.modalConfig, @@ -1862,12 +1865,6 @@ class AdaptiveModalManager: NSObject { self.overrideSnapPoints = snapPoints; self.overrideInterpolationPoints = interpolationPoints; - print( - "\n - interpolationPoints.percent:", interpolationPoints.map({$0.percent}), - "\n - interpolationPoints.snapPointIndex:", interpolationPoints.map({$0.snapPointIndex}), - "\n - interpolationPoints.computedRect:", interpolationPoints.map({$0.computedRect}) - ); - self.animateModal(to: nextInterpolationPoint) { _ in completion?(); };