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

Support removing navigables from LazySetNavigator #304

Merged

Conversation

gerin98
Copy link
Contributor

@gerin98 gerin98 commented Oct 23, 2024

Adding support for LazySetNavigator to remove navigables

  • Can remove a single Navigable
  • Can remove multiple Navigables
  • Can update the navigator's Navigables which can add and remove Navigables

Comment on lines +67 to +69
if (navigablesToRemove.contains(currentNavigable)) {
handleCurrentTabRemoval()
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's an edge case to be aware of when removing a Navigable that is currently visible. We need to switch to another navigable before we can remove it because once you call removeFromLifecycle on a navigable you can't call replace on it anymore. I wrote a test updateMultipleNavigables_andRemoveCurrentNavigable describing this case.

lifecycleRegistry.attachToLifecycleWithMaxState(navigable, LifecycleLimit.CREATED)
}

public fun removeNavigables(navigables: Set<NavigableCompat>) {
for (navigable in navigables) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a risk of ConcurrentModificationException if one of the navigables tries to add / remove a navigable in its onDestroy ? I don't know enough about mutableSetOf to know if it allows concurrent modification

@gerin98 gerin98 force-pushed the allow-lazySetNavigator-to-remove-navigables branch from c9fa578 to 2123832 Compare October 24, 2024 17:00
public fun removeNavigable(navigable: NavigableCompat) {
existingNavigables.removeIf { it == navigable }
if (lifecycleRegistry.children.contains(navigable)) {
lifecycleRegistry.removeFromLifecycle(navigable)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

removeIf avoids ConcurrentModificationException but requires API level 24

@gerin98 gerin98 requested a review from Kritarie October 25, 2024 15:59
@cmathew cmathew merged commit a103949 into wealthfront:master Oct 25, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants