Skip to content

Commit

Permalink
Hide Browsing menu when preparing animations to avoid UI glitches (#1868
Browse files Browse the repository at this point in the history
)

Task/Issue URL: https://app.asana.com/0/414709148257752/1203462254653694/f
Tech Design URL:
CC:

Description:

Ensure Browsing menu won't be presented when it is being prepared for animation by temporarily hiding it behind current MainView snapshot.
  • Loading branch information
bwaresiak authored Jul 26, 2023
1 parent 98592c3 commit 1222c3e
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion DuckDuckGo/BrowsingMenu/BrowsingMenuAnimator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,21 @@ final class BrowsingMenuAnimator: NSObject, UIViewControllerAnimatedTransitionin

func animatePresentation(from fromViewController: MainViewController, to toViewController: BrowsingMenuViewController, with transitionContext: UIViewControllerContextTransitioning) {

let fromSnapshot = fromViewController.view.snapshotView(afterScreenUpdates: false)

toViewController.view.frame = transitionContext.containerView.bounds
toViewController.view.autoresizingMask = [.flexibleHeight, .flexibleWidth]
transitionContext.containerView.addSubview(toViewController.view)

if let fromSnapshot {
transitionContext.containerView.addSubview(fromSnapshot)
}

toViewController.bindConstraints(to: fromViewController.currentTab?.webView)
toViewController.view.layoutIfNeeded()

let snapshot = toViewController.menuView.snapshotView(afterScreenUpdates: true)
if let snapshot = snapshot {
if let snapshot {
snapshot.frame = Self.menuOriginFrameForAnimation(for: toViewController)
snapshot.alpha = 0
toViewController.menuView.superview?.addSubview(snapshot)
Expand All @@ -70,6 +76,7 @@ final class BrowsingMenuAnimator: NSObject, UIViewControllerAnimatedTransitionin
toViewController.menuView.isHidden = true

UIView.animate(withDuration: Constants.appearAnimationDuration, delay: 0, options: .curveEaseOut) {
fromSnapshot?.removeFromSuperview()
snapshot?.frame = toViewController.menuView.frame
snapshot?.alpha = 1
} completion: { _ in
Expand Down

0 comments on commit 1222c3e

Please sign in to comment.