From b1cb0de1fc93ca328c38ac56948db1b505b28710 Mon Sep 17 00:00:00 2001 From: Dominic Go <18517029+dominicstop@users.noreply.github.com> Date: Thu, 8 Jun 2023 09:51:43 +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/AdaptiveModalConfig.swift | 8 +++- .../AdaptiveModalInterpolationPoint.swift | 19 ++++++++++ .../AdaptiveModalSnapPoint.swift | 16 +++++++- .../AdaptiveModalSnapPointPreset.swift | 37 +++++++++++++------ 4 files changed, 66 insertions(+), 14 deletions(-) diff --git a/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalConfig.swift b/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalConfig.swift index d98f88fb..01b6e772 100644 --- a/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalConfig.swift +++ b/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalConfig.swift @@ -33,6 +33,7 @@ struct AdaptiveModalConfig { let snapAnimationConfig: AdaptiveModalSnapAnimationConfig; let interpolationClampingConfig: AdaptiveModalClampingConfig; + let initialSnapPoint: AdaptiveModalSnapPointPreset; let overshootSnapPoint: AdaptiveModalSnapPointPreset; // let entranceConfig: AdaptiveModalEntranceConfig; @@ -75,17 +76,22 @@ struct AdaptiveModalConfig { snapPercentStrategy: SnapPercentStrategy = .position, snapAnimationConfig: AdaptiveModalSnapAnimationConfig = .default, interpolationClampingConfig: AdaptiveModalClampingConfig = .default, + initialSnapPoint: AdaptiveModalSnapPointPreset? = nil, overshootSnapPoint: AdaptiveModalSnapPointPreset? = nil ) { self.snapPoints = snapPoints; + self.snapDirection = snapDirection; self.snapPercentStrategy = snapPercentStrategy; self.snapAnimationConfig = snapAnimationConfig; self.interpolationClampingConfig = interpolationClampingConfig; + self.initialSnapPoint = initialSnapPoint + ?? .getDefaultInitialSnapPoint(forDirection: snapDirection); + self.overshootSnapPoint = overshootSnapPoint - ?? .getDefault(forDirection: snapDirection); + ?? .getDefaultOvershootSnapPoint(forDirection: snapDirection); }; // MARK: - Functions diff --git a/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalInterpolationPoint.swift b/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalInterpolationPoint.swift index 1347a849..02fcf176 100644 --- a/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalInterpolationPoint.swift +++ b/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalInterpolationPoint.swift @@ -286,6 +286,25 @@ extension AdaptiveModalInterpolationPoint { var items: [AdaptiveModalInterpolationPoint] = []; +// items.append({ +// let nextSnapPointConfig = modalConfig.snapPoints.first!; +// +// let initialSnapPointConfig = AdaptiveModalSnapPointConfig( +// fromSnapPointPreset: modalConfig.initialSnapPoint, +// fromBaseLayoutConfig: nextSnapPointConfig.snapPoint, +// withTargetRect: targetRect, +// currentSize: currentSize +// ); +// +// return AdaptiveModalInterpolationPoint( +// usingModalConfig: modalConfig, +// snapPointIndex: -1, +// withTargetRect: targetRect, +// currentSize: currentSize, +// snapPointConfig: initialSnapPointConfig +// ); +// }()); + for (index, snapConfig) in modalConfig.snapPoints.enumerated() { items.append( AdaptiveModalInterpolationPoint( diff --git a/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalSnapPoint.swift b/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalSnapPoint.swift index cc0d5fc4..b2c50431 100644 --- a/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalSnapPoint.swift +++ b/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalSnapPoint.swift @@ -24,7 +24,7 @@ struct AdaptiveModalSnapPointConfig { fromBaseLayoutConfig baseLayoutConfig: RNILayout, withTargetRect targetRect: CGRect, currentSize: CGSize - ){ + ) { let snapPointLayoutPreset = snapPointPreset.snapPointPreset; let snapPointLayout = snapPointLayoutPreset.getLayoutConfig( @@ -37,3 +37,17 @@ struct AdaptiveModalSnapPointConfig { self.animationKeyframe = snapPointPreset.animationKeyframe; }; }; + +//extension AdaptiveModalSnapPointConfig { +// +// static func deriveSnapPoints( +// initialSnapPoint: AdaptiveModalSnapPointPreset, +// inBetweenSnapPoints: [AdaptiveModalSnapPointConfig], +// overshootSnapPoint: AdaptiveModalSnapPointPreset +// ) -> [AdaptiveModalSnapPointConfig] { +// +// var snapPoints: [AdaptiveModalSnapPointConfig] = []; +// +// return snapPoints; +// }; +//}; diff --git a/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalSnapPointPreset.swift b/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalSnapPointPreset.swift index 0c2b5e11..612089d1 100644 --- a/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalSnapPointPreset.swift +++ b/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalSnapPointPreset.swift @@ -22,22 +22,35 @@ struct AdaptiveModalSnapPointPreset { }; extension AdaptiveModalSnapPointPreset { - static func getDefaultSnapPoint( + static func getDefaultOvershootSnapPoint( forDirection direction: AdaptiveModalConfig.Direction - ) -> RNILayoutPreset { - switch direction { - case .bottomToTop: return .edgeTop; - case .topToBottom: return .edgeBottom; - case .leftToRight: return .edgeLeft; - case .rightToLeft: return .edgeRight; - }; + ) -> Self { + + let snapPoint: RNILayoutPreset = { + switch direction { + case .bottomToTop: return .edgeTop; + case .topToBottom: return .edgeBottom; + case .leftToRight: return .edgeLeft; + case .rightToLeft: return .edgeRight; + }; + }(); + + return self.init(snapPoint: snapPoint); }; - static func getDefault( + static func getDefaultInitialSnapPoint( forDirection direction: AdaptiveModalConfig.Direction ) -> Self { - Self.init( - snapPoint: Self.getDefaultSnapPoint(forDirection: direction) - ); + + let snapPoint: RNILayoutPreset = { + switch direction { + case .bottomToTop: return .offscreenBottom; + case .topToBottom: return .offscreenTop; + case .leftToRight: return .offscreenLeft; + case .rightToLeft: return .offscreenRight; + }; + }(); + + return self.init(snapPoint: snapPoint); }; };