diff --git a/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalInterpolationPoint.swift b/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalInterpolationPoint.swift index 9ff1029c..49d0414c 100644 --- a/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalInterpolationPoint.swift +++ b/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalInterpolationPoint.swift @@ -19,40 +19,40 @@ struct AdaptiveModalInterpolationPoint: Equatable { // MARK: - Properties // ------------------ - let percent: CGFloat; - let snapPointIndex: Int; + var percent: CGFloat; + var snapPointIndex: Int; /// The computed frames of the modal based on the snap points - let computedRect: CGRect; + var computedRect: CGRect; // MARK: - Properties - Keyframes // ------------------------------ - let modalRotation: CGFloat; + var modalRotation: CGFloat; - let modalScaleX: CGFloat; - let modalScaleY: CGFloat; + var modalScaleX: CGFloat; + var modalScaleY: CGFloat; - let modalTranslateX: CGFloat; - let modalTranslateY: CGFloat; + var modalTranslateX: CGFloat; + var modalTranslateY: CGFloat; - let modalOpacity: CGFloat; - let modalBackgroundColor: UIColor; - let modalBackgroundOpacity: CGFloat; + var modalOpacity: CGFloat; + var modalBackgroundColor: UIColor; + var modalBackgroundOpacity: CGFloat; - let modalCornerRadius: CGFloat; - let modalMaskedCorners: CACornerMask; + var modalCornerRadius: CGFloat; + var modalMaskedCorners: CACornerMask; - let modalBackgroundVisualEffect: UIVisualEffect?; - let modalBackgroundVisualEffectOpacity: CGFloat; - let modalBackgroundVisualEffectIntensity: CGFloat; + var modalBackgroundVisualEffect: UIVisualEffect?; + var modalBackgroundVisualEffectOpacity: CGFloat; + var modalBackgroundVisualEffectIntensity: CGFloat; - let backgroundColor: UIColor; - let backgroundOpacity: CGFloat; + var backgroundColor: UIColor; + var backgroundOpacity: CGFloat; - let backgroundVisualEffect: UIVisualEffect?; - let backgroundVisualEffectOpacity: CGFloat; - let backgroundVisualEffectIntensity: CGFloat; + var backgroundVisualEffect: UIVisualEffect?; + var backgroundVisualEffectOpacity: CGFloat; + var backgroundVisualEffectIntensity: CGFloat; // MARK: - Computed Properties // --------------------------- diff --git a/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalManager+UIViewControllerAnimatedTransitioning.swift b/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalManager+UIViewControllerAnimatedTransitioning.swift index 091581c8..8ed95df9 100644 --- a/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalManager+UIViewControllerAnimatedTransitioning.swift +++ b/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalManager+UIViewControllerAnimatedTransitioning.swift @@ -34,7 +34,7 @@ extension AdaptiveModalManager: UIViewControllerAnimatedTransitioning { }; case .dismissing: - self.dismissModal(){ + self.hideModal(){ transitionContext.completeTransition(true); }; diff --git a/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalManager.swift b/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalManager.swift index 5634d1f4..4ccdb672 100644 --- a/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalManager.swift +++ b/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalManager.swift @@ -1310,7 +1310,8 @@ class AdaptiveModalManager: NSObject { }; func prepareForPresentation( - presentingViewController presentingVC: UIViewController + viewControllerToPresent presentingVC: UIViewController, + presentingViewController presentedVC: UIViewController ) { self.modalViewController = presentingVC; self.modalView = presentingVC.view; @@ -1401,7 +1402,7 @@ class AdaptiveModalManager: NSObject { self.snapTo(interpolationIndex: nextIndex, completion: completion); }; - func dismissModal( + func hideModal( useInBetweenSnapPoints: Bool = false, completion: (() -> Void)? = nil ){ @@ -1413,20 +1414,23 @@ class AdaptiveModalManager: NSObject { } else { let currentSnapPointConfig = self.currentSnapPointConfig; + let currentInterpolationStep = self.currentInterpolationStep; let undershootSnapPointConfig = AdaptiveModalSnapPointConfig( fromSnapPointPreset: self.modalConfig.undershootSnapPoint, fromBaseLayoutConfig: currentSnapPointConfig.snapPoint ); - let undershootInterpolationPoint = AdaptiveModalInterpolationPoint( + var undershootInterpolationPoint = AdaptiveModalInterpolationPoint( usingModalConfig: self.modalConfig, snapPointIndex: nextIndex, layoutValueContext: self.layoutValueContext, - snapPointConfig: undershootSnapPointConfig, - prevInterpolationPoint: self.currentInterpolationStep + snapPointConfig: undershootSnapPointConfig ); + undershootInterpolationPoint.modalCornerRadius = + currentInterpolationStep.modalCornerRadius; + self.snapTo( interpolationIndex: nextIndex, interpolationPoint: undershootInterpolationPoint, @@ -1434,4 +1438,22 @@ class AdaptiveModalManager: NSObject { ); }; }; + + public func presentModal( + viewControllerToPresent modalVC: UIViewController, + presentingViewController targetVC: UIViewController, + animated: Bool = true, + completion: (() -> Void)? = nil + ) { + self.prepareForPresentation( + viewControllerToPresent: modalVC, + presentingViewController: targetVC + ); + + targetVC.present( + modalVC, + animated: animated, + completion: completion + ); + }; }; diff --git a/experiments/swift-programmatic-modal/Test/AdaptiveModalPresentationTestViewController.swift b/experiments/swift-programmatic-modal/Test/AdaptiveModalPresentationTestViewController.swift index 31140e02..1c73b18b 100644 --- a/experiments/swift-programmatic-modal/Test/AdaptiveModalPresentationTestViewController.swift +++ b/experiments/swift-programmatic-modal/Test/AdaptiveModalPresentationTestViewController.swift @@ -145,10 +145,10 @@ class AdaptiveModalPresentationTestViewController : UIViewController { self.adaptiveModalManager.eventDelegate = testVC; testVC.modalManager = self.adaptiveModalManager; - self.adaptiveModalManager.prepareForPresentation( - presentingViewController: testVC - ); - self.present(testVC, animated: true); + self.adaptiveModalManager.presentModal( + viewControllerToPresent: testVC, + presentingViewController: self + ); }; };