From b5079791973ba36313e0beb2ebb00705e7547a87 Mon Sep 17 00:00:00 2001 From: Fernando Bunn Date: Wed, 18 Dec 2024 16:00:57 -0300 Subject: [PATCH] Fix alpha animation --- ...undedPageSheetContainerViewController.swift | 18 +++++++++++++++++- .../RoundedPageSheetPresentationAnimator.swift | 6 ++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/DuckDuckGo/RoundedPageContainer/RoundedPageSheetContainerViewController.swift b/DuckDuckGo/RoundedPageContainer/RoundedPageSheetContainerViewController.swift index fdceff2c95..3ce8888906 100644 --- a/DuckDuckGo/RoundedPageContainer/RoundedPageSheetContainerViewController.swift +++ b/DuckDuckGo/RoundedPageContainer/RoundedPageSheetContainerViewController.swift @@ -22,6 +22,7 @@ import UIKit final class RoundedPageSheetContainerViewController: UIViewController { let contentViewController: UIViewController private let allowedOrientation: UIInterfaceOrientationMask + let backgroundView = UIView() private var interactiveDismissalTransition: UIPercentDrivenInteractiveTransition? private var isInteractiveDismissal = false @@ -52,8 +53,9 @@ final class RoundedPageSheetContainerViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() - view.backgroundColor = .black + view.backgroundColor = .clear + setupBackgroundView() setupContentViewController() } @@ -86,6 +88,20 @@ final class RoundedPageSheetContainerViewController: UIViewController { } } + private func setupBackgroundView() { + view.addSubview(backgroundView) + + backgroundView.backgroundColor = .black + backgroundView.translatesAutoresizingMaskIntoConstraints = false + + NSLayoutConstraint.activate([ + backgroundView.topAnchor.constraint(equalTo: view.topAnchor), + backgroundView.bottomAnchor.constraint(equalTo: view.bottomAnchor), + backgroundView.leadingAnchor.constraint(equalTo: view.leadingAnchor), + backgroundView.trailingAnchor.constraint(equalTo: view.trailingAnchor) + ]) + } + private func setupContentViewController() { addChild(contentViewController) view.addSubview(contentViewController.view) diff --git a/DuckDuckGo/RoundedPageContainer/RoundedPageSheetPresentationAnimator.swift b/DuckDuckGo/RoundedPageContainer/RoundedPageSheetPresentationAnimator.swift index f86aab1bcd..85cd7d8787 100644 --- a/DuckDuckGo/RoundedPageContainer/RoundedPageSheetPresentationAnimator.swift +++ b/DuckDuckGo/RoundedPageContainer/RoundedPageSheetPresentationAnimator.swift @@ -66,6 +66,7 @@ class RoundedPageSheetDismissalAnimator: NSObject, UIViewControllerAnimatedTrans let fromView = fromViewController.view, let contentView = fromViewController.contentViewController.view else { return } + let fromBackgroundView = fromViewController.backgroundView let containerView = transitionContext.containerView UIView.animate(withDuration: AnimatorConstants.duration, @@ -74,7 +75,7 @@ class RoundedPageSheetDismissalAnimator: NSObject, UIViewControllerAnimatedTrans initialSpringVelocity: AnimatorConstants.springVelocity, options: .curveEaseInOut, animations: { - fromView.alpha = 0 + fromBackgroundView.alpha = 0 contentView.transform = CGAffineTransform(translationX: 0, y: containerView.bounds.height) }, completion: { finished in fromView.removeFromSuperview() @@ -94,10 +95,11 @@ class RoundedPageSheetDismissalAnimator: NSObject, UIViewControllerAnimatedTrans } let containerView = transitionContext.containerView + let fromBackgroundView = fromViewController.backgroundView let animator = UIViewPropertyAnimator(duration: AnimatorConstants.duration, dampingRatio: AnimatorConstants.springDamping) { - fromView.alpha = 0 + fromBackgroundView.alpha = 0 contentView.transform = CGAffineTransform(translationX: 0, y: containerView.bounds.height) }