-
Notifications
You must be signed in to change notification settings - Fork 72
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
Support removing navigables from LazySetNavigator #304
Conversation
if (navigablesToRemove.contains(currentNavigable)) { | ||
handleCurrentTabRemoval() | ||
} |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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
c9fa578
to
2123832
Compare
public fun removeNavigable(navigable: NavigableCompat) { | ||
existingNavigables.removeIf { it == navigable } | ||
if (lifecycleRegistry.children.contains(navigable)) { | ||
lifecycleRegistry.removeFromLifecycle(navigable) |
There was a problem hiding this comment.
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
Adding support for
LazySetNavigator
to remove navigables