From 4323710a82e7d80ffc09fb6878bf30d5743ede89 Mon Sep 17 00:00:00 2001 From: Dominic Go <18517029+dominicstop@users.noreply.github.com> Date: Tue, 6 Jun 2023 06:05:30 +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`. --- .../AdaptiveModalManager+Helpers.swift | 24 +++++++ .../AdaptiveModal/AdaptiveModalManager.swift | 70 ++++++++++--------- .../Test/RNIDraggableTestViewController.swift | 2 +- 3 files changed, 62 insertions(+), 34 deletions(-) diff --git a/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalManager+Helpers.swift b/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalManager+Helpers.swift index d6723bab..e5e787ba 100644 --- a/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalManager+Helpers.swift +++ b/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalManager+Helpers.swift @@ -111,4 +111,28 @@ extension AdaptiveModalManager { let offset = percent > 1 ? abs(percent - 1) : 0; return 1 - percent + offset; }; + + static func setProperty( + forObject object: O?, + forPropertyKey propertyKey: WritableKeyPath, + withValue value: T? + ) { + guard var object = object, + let value = value + else { return }; + + object[keyPath: propertyKey] = value; + }; + + static func setProperty( + for valueType: inout O?, + forPropertyKey propertyKey: WritableKeyPath, + withValue newValue: T? + ) { + guard var valueType = valueType, + let newValue = newValue + else { return }; + + valueType[keyPath: propertyKey] = newValue; + }; }; diff --git a/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalManager.swift b/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalManager.swift index 18e561b9..f972daaa 100644 --- a/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalManager.swift +++ b/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalManager.swift @@ -678,45 +678,49 @@ class AdaptiveModalManager { ) { guard let modalView = self.modalView else { return }; - if let nextModalRect = self.interpolateModalRect( + self.modalFrame = self.interpolateModalRect( forInputPercentValue: inputPercentValue - ) { - self.modalFrame = nextModalRect; - }; + ); - if let nextModalTransform = self.interpolateModalTransform( - forInputPercentValue: inputPercentValue - ) { - modalView.transform = nextModalTransform; - }; + Self.setProperty( + forObject: modalView, + forPropertyKey: \.transform, + withValue: self.interpolateModalTransform( + forInputPercentValue: inputPercentValue + ) + ); - if let nextModalOpacity = self.interpolateOpacity( - forInputPercentValue: inputPercentValue - ) { - modalView.alpha = nextModalOpacity; - }; + Self.setProperty( + forObject: modalView, + forPropertyKey: \.alpha, + withValue: self.interpolateOpacity( + forInputPercentValue: inputPercentValue + ) + ); - if let nextModalRadius = self.interpolateModalBorderRadius( - forInputPercentValue: inputPercentValue - ) { - modalView.layer.cornerRadius = nextModalRadius; - }; + Self.setProperty( + forObject: modalView, + forPropertyKey: \.layer.cornerRadius, + withValue: self.interpolateModalBorderRadius( + forInputPercentValue: inputPercentValue + ) + ); - if let modalBgView = self.modalBackgroundView, - let nextModalBgOpacity = self.interpolateModalBackgroundOpacity( - forInputPercentValue: inputPercentValue - ) { - - modalBgView.alpha = nextModalBgOpacity; - }; + Self.setProperty( + forObject: self.modalBackgroundView, + forPropertyKey: \.alpha, + withValue: self.interpolateModalBackgroundOpacity( + forInputPercentValue: inputPercentValue + ) + ); - if let bgDimmingView = self.backgroundDimmingView, - let nextBgOpacity = self.interpolateBackgroundOpacity( - forInputPercentValue: inputPercentValue - ) { - - bgDimmingView.alpha = nextBgOpacity; - }; + Self.setProperty( + forObject: self.backgroundDimmingView, + forPropertyKey: \.alpha, + withValue: self.interpolateBackgroundOpacity( + forInputPercentValue: inputPercentValue + ) + ); self.applyInterpolationToBackgroundVisualEffect( forInputPercentValue: inputPercentValue diff --git a/experiments/swift-programmatic-modal/Test/RNIDraggableTestViewController.swift b/experiments/swift-programmatic-modal/Test/RNIDraggableTestViewController.swift index 51806f5b..53a7ac99 100644 --- a/experiments/swift-programmatic-modal/Test/RNIDraggableTestViewController.swift +++ b/experiments/swift-programmatic-modal/Test/RNIDraggableTestViewController.swift @@ -10,7 +10,7 @@ import UIKit enum AdaptiveModalConfigTestPresets: CaseIterable { - static let `default`: Self = .testModalTransform01; + static let `default`: Self = .test03; case testModalTransform01;