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

Change back handler behavior #273

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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 @@ -173,6 +173,11 @@ public class Navigator @InternalVoyagerApi constructor(
}
}

internal fun popRecursively() {
if (pop()) return
parent?.popRecursively()
}
Comment on lines +176 to +179
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you make this function public annotated with @InternalVoyagerApi?

Choose a reason for hiding this comment

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

Hey, @DevNatan are you going to fix this ?


@InternalVoyagerApi
public fun dispose(
screen: Screen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,21 @@ internal fun NavigatorBackHandler(
navigator: Navigator,
onBackPressed: OnBackPressed
) {
if (onBackPressed != null) {
if (onBackPressed == null) {
BackHandler(
enabled = navigator.canPop || navigator.parent?.canPop ?: false,
enabled = navigator.size > 1,
onBack = navigator::popRecursively
)
} else {
// `navigator.size == 1` covers onBackPressed = { false } and empty stack
// because `navigator.canPop` always returns `false` when stack min size is 1
BackHandler(
enabled = (navigator.size == 1 && !onBackPressed(navigator.lastItem)) ||
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think we should use the onBackPressed function here. The assumption is that the onBackPressed will be called when is actually poping the navigation.

navigator.canPop ||
navigator.parent?.canPop ?: false,
onBack = {
if (onBackPressed(navigator.lastItem)) {
if (navigator.pop().not()) {
navigator.parent?.pop()
}
navigator.popRecursively()
}
}
)
Expand Down