Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swiping tabs: Fix duplicate animations & edit mode detection #5481

Open
wants to merge 11 commits into
base: feature/ondrej/swiping-tabs
Choose a base branch
from

Conversation

0nko
Copy link
Member

@0nko 0nko commented Jan 16, 2025

Task/Issue URL: https://app.asana.com/0/1207418217763355/1209152058231741/f

Description

This PR removes the onboarding restriction that prevents tab swiping until onboarding is complete. It also fixes a bug that shows duplicate omnibar highlight animations. The bug is caused due to RecyclerView calling the View.onAttachedToWindow() every time the current item is changed, resulting in duplicate PulseAnimation instances.

The fix involves removing PulseAnimation initialization from the onAttachedToWindow() callback, so that it’s initialized only once.

I also moved the injection to the constructor to avoid repeated injection calls and refactored the ViewModel flows collection to only happen during active lifecycle states.

While working on this, I discovered that edit mode wasn’t working properly and there’s a simpler way to do it, so I included it here.

Steps to test this PR

  • Make sure you enable the tab swiping feature in the settings and restart the app
  • Go through onboarding until you get to the privacy shield step (the shield animation is displayed)
  • Add a new tab
  • Swipe back to the tab with the shield animation
  • Notice there is only one animation
  • Go to the tab switcher and come back
  • Notice there is still only one animation

@0nko 0nko requested a review from malmstein January 16, 2025 17:58
tabRepository.flowTabs
.onEach { tabs ->
_viewState.update {
it.copy(
shouldUpdateTabsCount = tabs.count() != it.tabs.count() || tabs.isNotEmpty(),
tabs = tabs,
shouldUpdateTabsCount = tabs.size != it.tabCount && tabs.isNotEmpty(),
Copy link
Member Author

Choose a reason for hiding this comment

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

I think the original condition was wrong — we don’t ever want to show 0 (the initial ViewState value), because the actual count will always be at least 1.

@@ -99,7 +98,8 @@ class OmnibarLayoutViewModel @Inject constructor(
val updateOmnibarText: Boolean = false,
val shouldMoveCaretToEnd: Boolean = false,
val shouldMoveCaretToStart: Boolean = false,
val tabs: List<TabEntity> = emptyList(),
Copy link
Member Author

Choose a reason for hiding this comment

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

This list was only used to count the tabs. Each tab would contain a list of all these entities and with lots of tabs this would unnecessarily take up a lot of memory.

@@ -238,24 +246,30 @@ class OmnibarLayout @JvmOverloads constructor(
)[OmnibarLayoutViewModel::class.java]
}

// One OmnibarLayout is always removed from the view hierarchy, we should cancel any flow subscriptions
fun onRemoved() {
Copy link
Member Author

@0nko 0nko Jan 17, 2025

Choose a reason for hiding this comment

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

Either the bottom or the top omnibar is always removed but its ViewModel flow subscriptions would keep collecting & rendering state for no reason.

@0nko 0nko changed the title Swiping tabs: Fix duplicate animations Swiping tabs: Fix duplicate animations & edit mode detection Jan 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant