From 71e9bc58f611812959ee108313bb1fd17a688c72 Mon Sep 17 00:00:00 2001 From: Dominic Go <18517029+dominicstop@users.noreply.github.com> Date: Wed, 7 Jun 2023 01:12:40 +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`. --- .../AdaptiveModalInterpolationPoint.swift | 2 +- .../AdaptiveModal/AdaptiveModalManager.swift | 32 +++++++++---------- .../AdaptiveModalRangePropertyAnimator.swift | 2 +- ...ers.swift => AdaptiveModalUtilities.swift} | 6 ++-- .../project.pbxproj | 8 ++--- 5 files changed, 25 insertions(+), 25 deletions(-) rename experiments/swift-programmatic-modal/AdaptiveModal/{AdaptiveModalManager+Helpers.swift => AdaptiveModalUtilities.swift} (97%) diff --git a/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalInterpolationPoint.swift b/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalInterpolationPoint.swift index 10639847..1347a849 100644 --- a/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalInterpolationPoint.swift +++ b/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalInterpolationPoint.swift @@ -114,7 +114,7 @@ struct AdaptiveModalInterpolationPoint: Equatable { let percent = inputValue / maxRangeInput; return modalConfig.shouldInvertPercent - ? AdaptiveModalManager.invertPercent(percent) + ? AdaptiveModalUtilities.invertPercent(percent) : percent; case .index: diff --git a/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalManager.swift b/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalManager.swift index ac5cc351..b50acf20 100644 --- a/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalManager.swift +++ b/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalManager.swift @@ -154,12 +154,12 @@ class AdaptiveModalManager { y: (gestureVelocity.y / 2).clamped(minMax: maxVelocity) ); - let nextX = Self.computeFinalPosition( + let nextX = AdaptiveModalUtilities.computeFinalPosition( position: gesturePoint.x, initialVelocity: gestureVelocityClamped.x ); - let nextY = Self.computeFinalPosition( + let nextY = AdaptiveModalUtilities.computeFinalPosition( position: gesturePoint.y, initialVelocity: gestureVelocityClamped.y ); @@ -351,7 +351,7 @@ class AdaptiveModalManager { let interpolationRangeInput = rangeInput ?? self.interpolationRangeInput else { return nil }; - return Self.interpolate( + return AdaptiveModalUtilities.interpolate( inputValue: inputValue, rangeInput: interpolationRangeInput, rangeOutput: interpolationSteps.map { @@ -375,7 +375,7 @@ class AdaptiveModalManager { let interpolationRangeInput = rangeInput ?? self.interpolationRangeInput else { return nil }; - return Self.interpolateColor( + return AdaptiveModalUtilities.interpolateColor( inputValue: inputValue, rangeInput: interpolationRangeInput, rangeOutput: interpolationSteps.map { @@ -676,7 +676,7 @@ class AdaptiveModalManager { forInputPercentValue: inputPercentValue ); - Self.setProperty( + AdaptiveModalUtilities.unwrapAndSetProperty( forObject: modalView, forPropertyKey: \.transform, withValue: self.interpolateModalTransform( @@ -684,7 +684,7 @@ class AdaptiveModalManager { ) ); - Self.setProperty( + AdaptiveModalUtilities.unwrapAndSetProperty( forObject: modalView, forPropertyKey: \.alpha, withValue: self.interpolate( @@ -693,7 +693,7 @@ class AdaptiveModalManager { ) ); - Self.setProperty( + AdaptiveModalUtilities.unwrapAndSetProperty( forObject: modalView, forPropertyKey: \.layer.cornerRadius, withValue: self.interpolateModalBorderRadius( @@ -701,7 +701,7 @@ class AdaptiveModalManager { ) ); - Self.setProperty( + AdaptiveModalUtilities.unwrapAndSetProperty( forObject: self.modalBackgroundView, forPropertyKey: \.backgroundColor, withValue: self.interpolateColor( @@ -710,7 +710,7 @@ class AdaptiveModalManager { ) ); - Self.setProperty( + AdaptiveModalUtilities.unwrapAndSetProperty( forObject: self.modalBackgroundView, forPropertyKey: \.alpha, withValue: self.interpolate( @@ -719,7 +719,7 @@ class AdaptiveModalManager { ) ); - Self.setProperty( + AdaptiveModalUtilities.unwrapAndSetProperty( forObject: self.modalBackgroundVisualEffectView, forPropertyKey: \.alpha, withValue: self.interpolate( @@ -728,7 +728,7 @@ class AdaptiveModalManager { ) ); - Self.setProperty( + AdaptiveModalUtilities.unwrapAndSetProperty( forObject: self.backgroundDimmingView, forPropertyKey: \.backgroundColor, withValue: self.interpolateColor( @@ -737,7 +737,7 @@ class AdaptiveModalManager { ) ); - Self.setProperty( + AdaptiveModalUtilities.unwrapAndSetProperty( forObject: self.backgroundDimmingView, forPropertyKey: \.alpha, withValue: self.interpolate( @@ -746,7 +746,7 @@ class AdaptiveModalManager { ) ); - Self.setProperty( + AdaptiveModalUtilities.unwrapAndSetProperty( forObject: self.backgroundVisualEffectView, forPropertyKey: \.alpha, withValue: self.interpolate( @@ -780,7 +780,7 @@ class AdaptiveModalManager { let percent = inputValue / interpolationRangeMaxInput; let percentAdj = shouldInvertPercent - ? Self.invertPercent(percent) + ? AdaptiveModalUtilities.invertPercent(percent) : percent; self.applyInterpolationToModal(forInputPercentValue: percentAdj); @@ -1014,7 +1014,7 @@ class AdaptiveModalManager { let percent = inputCoord / interpolationRangeMaxInput; let percentAdj = self.modalConfig.shouldInvertPercent - ? Self.invertPercent(percent) + ? AdaptiveModalUtilities.invertPercent(percent) : percent; @@ -1125,7 +1125,7 @@ class AdaptiveModalManager { self.getClosestSnapPoint(forRect: self.modalFrame) else { return }; - let interpolatedDuration = Self.interpolate( + let interpolatedDuration = AdaptiveModalUtilities.interpolate( inputValue: closestSnapPoint.snapDistance, rangeInput: [0, targetView.frame.height], rangeOutput: [0.2, 0.7] diff --git a/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalRangePropertyAnimator.swift b/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalRangePropertyAnimator.swift index 94e4938e..da0c8daf 100644 --- a/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalRangePropertyAnimator.swift +++ b/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalRangePropertyAnimator.swift @@ -96,7 +96,7 @@ struct AdaptiveModalRangePropertyAnimator { return [0, 1]; }(); - let percent = AdaptiveModalManager.interpolate( + let percent = AdaptiveModalUtilities.interpolate( inputValue: inputPercentValue, rangeInput: range.map { $0.percent diff --git a/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalManager+Helpers.swift b/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalUtilities.swift similarity index 97% rename from experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalManager+Helpers.swift rename to experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalUtilities.swift index 5fa07da0..f3f9f0b4 100644 --- a/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalManager+Helpers.swift +++ b/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalUtilities.swift @@ -7,7 +7,7 @@ import UIKit -extension AdaptiveModalManager { +class AdaptiveModalUtilities { static func interpolate( inputValue : CGFloat, @@ -180,7 +180,7 @@ extension AdaptiveModalManager { return 1 - percent + offset; }; - static func setProperty( + static func unwrapAndSetProperty( forObject object: O?, forPropertyKey propertyKey: WritableKeyPath, withValue value: T? @@ -192,7 +192,7 @@ extension AdaptiveModalManager { object[keyPath: propertyKey] = value; }; - static func setProperty( + static func unwrapAndSetProperty( for valueType: inout O?, forPropertyKey propertyKey: WritableKeyPath, withValue newValue: T? diff --git a/experiments/swift-programmatic-modal/swift-programmatic-modal.xcodeproj/project.pbxproj b/experiments/swift-programmatic-modal/swift-programmatic-modal.xcodeproj/project.pbxproj index 78d45d7f..beb9eef2 100644 --- a/experiments/swift-programmatic-modal/swift-programmatic-modal.xcodeproj/project.pbxproj +++ b/experiments/swift-programmatic-modal/swift-programmatic-modal.xcodeproj/project.pbxproj @@ -8,7 +8,7 @@ /* Begin PBXBuildFile section */ 880492582A23F89000D74E9F /* AdaptiveModalInterpolationPoint.swift in Sources */ = {isa = PBXBuildFile; fileRef = 880492572A23F89000D74E9F /* AdaptiveModalInterpolationPoint.swift */; }; - 88075E272A2121FE00B78388 /* AdaptiveModalManager+Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 88075E262A2121FE00B78388 /* AdaptiveModalManager+Helpers.swift */; }; + 88075E272A2121FE00B78388 /* AdaptiveModalUtilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = 88075E262A2121FE00B78388 /* AdaptiveModalUtilities.swift */; }; 88203DC12A122AC20088C8E2 /* RNIDynamicModal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 88203DC02A122AC20088C8E2 /* RNIDynamicModal.swift */; }; 88B7D0EF29C593F400490628 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 88B7D0EE29C593F400490628 /* AppDelegate.swift */; }; 88B7D0F129C593F400490628 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 88B7D0F029C593F400490628 /* SceneDelegate.swift */; }; @@ -96,7 +96,7 @@ /* Begin PBXFileReference section */ 880492572A23F89000D74E9F /* AdaptiveModalInterpolationPoint.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdaptiveModalInterpolationPoint.swift; sourceTree = ""; }; - 88075E262A2121FE00B78388 /* AdaptiveModalManager+Helpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AdaptiveModalManager+Helpers.swift"; sourceTree = ""; }; + 88075E262A2121FE00B78388 /* AdaptiveModalUtilities.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdaptiveModalUtilities.swift; sourceTree = ""; }; 88203DC02A122AC20088C8E2 /* RNIDynamicModal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RNIDynamicModal.swift; sourceTree = ""; }; 88B7D0EB29C593F400490628 /* swift-programmatic-modal.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "swift-programmatic-modal.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 88B7D0EE29C593F400490628 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; @@ -526,7 +526,7 @@ 880492572A23F89000D74E9F /* AdaptiveModalInterpolationPoint.swift */, 88C2F45D2A278A9200DA7450 /* AdaptiveModalRangePropertyAnimator.swift */, 88D0188D2A1DCA61004664D2 /* AdaptiveModalManager.swift */, - 88075E262A2121FE00B78388 /* AdaptiveModalManager+Helpers.swift */, + 88075E262A2121FE00B78388 /* AdaptiveModalUtilities.swift */, 88C2F4612A2CD81F00DA7450 /* AdaptiveModalEventNotifiable.swift */, 88C2F4632A2D8D3400DA7450 /* AdaptiveModalKeyframePropertyAnimator.swift */, ); @@ -660,7 +660,7 @@ 88D018272A1B3030004664D2 /* RNIInternalCleanupMode.swift in Sources */, 88D018782A1B3030004664D2 /* RNIComputableSize.swift in Sources */, 88D018732A1B3030004664D2 /* RNIModalCustomSheetDetent.swift in Sources */, - 88075E272A2121FE00B78388 /* AdaptiveModalManager+Helpers.swift in Sources */, + 88075E272A2121FE00B78388 /* AdaptiveModalUtilities.swift in Sources */, 88D018252A1B3030004664D2 /* UIViewController+Helpers.swift in Sources */, 88D018882A1D0A36004664D2 /* AdaptiveModalConfig.swift in Sources */, 88D018432A1B3030004664D2 /* UIGestureRecognizer+Helpers.swift in Sources */,