Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,12 @@ class OmnibarLayout @JvmOverloads constructor(
duckAISidebar.setOnClickListener {
omnibarItemPressedListener?.onDuckAISidebarButtonPressed()
}
newCustomTabToolbarContainer.customTabInnerContainer.setOnClickListener {
cancelCustomTabAnimations()
}
trackersAnimation.setOnClickListener {
cancelAddressBarAnimations()
}
}

override fun setLogoClickListener(logoClickListener: LogoClickListener) {
Expand Down Expand Up @@ -1038,6 +1044,12 @@ class OmnibarLayout @JvmOverloads constructor(
}
}

private fun cancelCustomTabAnimations() {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Cancel methods omit shieldViews, potentially leaving icons faded

The cancelAddressBarAnimations() and cancelCustomTabAnimations() methods call cancelAnimations() without passing shieldViews() or customTabShieldViews(). The fallback mechanism in stopCookiesAnimation() that resets currentShieldViews has an early return if cookie views aren't initialized yet. If the user cancels during the trackers animation (before cookies animation starts), shield views may remain with modified alpha since neither the explicit shieldViews parameter nor the currentShieldViews fallback will reset them.

Additional Locations (1)

Fix in Cursor Fix in Web

if (this::animatorHelper.isInitialized) {
animatorHelper.cancelAnimations(customTabViews())
}
}

private fun startTrackersAnimation(events: List<Entity>?, isCustomTab: Boolean) {
if (!isCustomTab) {
if (addressBarTrackersAnimationFeatureToggle.feature().isEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,15 @@ class BrowserLottieTrackersAnimatorHelper @Inject constructor(
private lateinit var cookieScene: ViewGroup
private lateinit var cookieViewBackground: View
private var cookieCosmeticHide: Boolean = false
private var currentShieldViews: List<View> = emptyList()

private var enqueueCookiesAnimation = false
private var isCookiesAnimationRunning = false
private var hasCookiesAnimationBeenCanceled = false

private val conflatedJob = ConflatedJob()
private val coroutineScope = CoroutineScope(SupervisorJob() + dispatcherProvider.main())
private val runningCookieAnimators = mutableListOf<Animator>()

lateinit var firstScene: Scene
lateinit var secondScene: Scene
Expand Down Expand Up @@ -146,6 +148,8 @@ class BrowserLottieTrackersAnimatorHelper @Inject constructor(
) {
if (isCookiesAnimationRunning || addressBarTrackersAnimator.isAnimationRunning) return

currentShieldViews = shieldViews

addressBarTrackersAnimator.startAnimation(
context = context,
sceneRoot = sceneRoot,
Expand All @@ -163,6 +167,9 @@ class BrowserLottieTrackersAnimatorHelper @Inject constructor(
}
},
)
sceneRoot.setOnClickListener {
cancelAnimations(omnibarViews, shieldViews)
}
}

override fun createCookiesAnimation(
Expand Down Expand Up @@ -199,12 +206,15 @@ class BrowserLottieTrackersAnimatorHelper @Inject constructor(

override fun cancelAnimations(
omnibarViews: List<View>,
shieldViews: List<View>,
) {
conflatedJob.cancel()
addressBarTrackersAnimator.cancelAnimation()
stopTrackersAnimation()
stopCookiesAnimation()
enqueueCookiesAnimation = false
omnibarViews.forEach { it.alpha = 1f }
shieldViews.forEach { it.alpha = 1f }
}

private fun tryToStartCookiesAnimation(
Expand All @@ -222,6 +232,11 @@ class BrowserLottieTrackersAnimatorHelper @Inject constructor(
omnibarViews: List<View>,
) {
if (omnibarViews.any { it.id == R.id.customTabDomain }) return // Do not show cookies animation in custom tabs

// Cancel any running animators before starting new ones
runningCookieAnimators.forEach { it.cancel() }
runningCookieAnimators.clear()

isCookiesAnimationRunning = true

if (cookieCosmeticHide) {
Expand All @@ -233,7 +248,7 @@ class BrowserLottieTrackersAnimatorHelper @Inject constructor(
}

hasCookiesAnimationBeenCanceled = false
val allOmnibarViews: List<View> = (omnibarViews).filterNotNull().toList()
val allOmnibarViews: List<View> = omnibarViews
cookieView.show()
cookieView.alpha = 0F
if (theme.isLightModeEnabled()) {
Expand Down Expand Up @@ -272,6 +287,7 @@ class BrowserLottieTrackersAnimatorHelper @Inject constructor(
listener?.onAnimationFinished()
},
)
runningCookieAnimators.add(this)
start()
}
} else {
Expand All @@ -280,6 +296,7 @@ class BrowserLottieTrackersAnimatorHelper @Inject constructor(
}
},
)
runningCookieAnimators.add(this)
start()
}
}
Expand All @@ -298,6 +315,7 @@ class BrowserLottieTrackersAnimatorHelper @Inject constructor(
if (!hasCookiesAnimationBeenCanceled) {
AnimatorSet().apply {
play(commonAddressBarAnimationHelper.animateViewsIn(allOmnibarViews))
runningCookieAnimators.add(this)
start()
}
cookieScene.gone()
Expand Down Expand Up @@ -339,6 +357,7 @@ class BrowserLottieTrackersAnimatorHelper @Inject constructor(
cookieView.playAnimation()
},
)
runningCookieAnimators.add(this)
start()
}
}
Expand Down Expand Up @@ -408,13 +427,36 @@ class BrowserLottieTrackersAnimatorHelper @Inject constructor(
private fun stopCookiesAnimation() {
if (!::cookieViewBackground.isInitialized || !::cookieView.isInitialized) return

hasCookiesAnimationBeenCanceled = true
if (this::firstScene.isInitialized) {
TransitionManager.go(firstScene)
// Always cancel any pending animators and transitions to prevent glimpses
runningCookieAnimators.forEach { animator ->
animator.cancel()
animator.removeAllListeners()
}
runningCookieAnimators.clear()

// Cancel cookie view animations
cookieView.cancelAnimation()
cookieView.removeAllAnimatorListeners()

// End any ongoing transitions without triggering new ones
if (::cookieScene.isInitialized) {
TransitionManager.endTransitions(cookieScene)
cookieScene.gone()
}

// If animation was already stopped by user, skip redundant state updates
if (userHasCanceledCookieAnimation && !isCookiesAnimationRunning) {
return
}

hasCookiesAnimationBeenCanceled = true
isCookiesAnimationRunning = false

// Reset view states directly without triggering transitions
shieldAnimation?.alpha = 1f
currentShieldViews.forEach { it.alpha = 1f }
cookieViewBackground.alpha = 0f
cookieScene.gone()
cookieView.alpha = 0f
cookieView.gone()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,11 @@ interface BrowserTrackersAnimatorHelper {
* Cancel a running animation.
*
* @param omnibarViews are the views that should become visible after canceling the running animation.
* @param shieldViews are the shield views that should become visible after canceling the running animation.
*/
fun cancelAnimations(
omnibarViews: List<View>,
shieldViews: List<View> = emptyList(),
)

/**
Expand Down