Skip to content

Commit 8e2d42c

Browse files
committed
Store previous leading icon state to preserve Easter egg logos on focus change
When the omnibar gains focus, the leading icon changes to Search. Previously, if an Easter egg logo was displayed, it would be lost when focus was regained because the logic only checked the current leading icon state (which was Search). Changes: - Added previousLeadingIconState field to ViewState to store icon state before focus - Store current leading icon state when gaining focus - Use previous state (instead of current) when losing focus to restore Easter egg logos - Clear previous state after restoration to avoid memory retention This ensures Easter egg logos persist correctly through focus changes.
1 parent 4e23c4c commit 8e2d42c

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

app/src/main/java/com/duckduckgo/app/browser/omnibar/OmnibarLayoutViewModel.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ class OmnibarLayoutViewModel @Inject constructor(
152152
data class ViewState(
153153
val viewMode: ViewMode = Browser(null),
154154
val leadingIconState: LeadingIconState = Search,
155+
val previousLeadingIconState: LeadingIconState? = null,
155156
val privacyShield: PrivacyShieldState = PrivacyShieldState.UNKNOWN,
156157
val hasFocus: Boolean = false,
157158
val query: String = "",
@@ -286,6 +287,7 @@ class OmnibarLayoutViewModel @Inject constructor(
286287
hasFocus = true,
287288
expanded = true,
288289
leadingIconState = Search,
290+
previousLeadingIconState = it.leadingIconState,
289291
highlightPrivacyShield = HighlightableButton.Gone,
290292
showClearButton = showClearButton,
291293
showTabsMenu = showControls,
@@ -322,15 +324,16 @@ class OmnibarLayoutViewModel @Inject constructor(
322324
it.omnibarText
323325
}
324326

325-
val currentLogoUrl = when (val leadingIconState = it.leadingIconState) {
326-
is EasterEggLogo -> leadingIconState.logoUrl
327+
val currentLogoUrl = when (val previousState = it.previousLeadingIconState) {
328+
is EasterEggLogo -> previousState.logoUrl
327329
else -> null
328330
}
329331

330332
it.copy(
331333
hasFocus = false,
332334
expanded = false,
333335
leadingIconState = getLeadingIconState(false, it.url, currentLogoUrl),
336+
previousLeadingIconState = null,
334337
highlightFireButton = HighlightableButton.Visible(highlighted = false),
335338
showClearButton = false,
336339
showTabsMenu = true,

0 commit comments

Comments
 (0)