Skip to content

Commit

Permalink
Properly handle navigate back/up from a bottom sheet dialog fragment …
Browse files Browse the repository at this point in the history
…by cancelling the dialog instead of popping the backstack
  • Loading branch information
jayohms committed Feb 24, 2024
1 parent 95de8a7 commit 00b875b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,7 @@ class TurboFragmentDelegate(private val navDestination: TurboNavDestination) {
navDestination.toolbarForNavigation()?.let {
NavigationUI.setupWithNavController(it, fragment.findNavController())
it.setNavigationOnClickListener {
when (fragment) {
is DialogFragment -> fragment.requireDialog().cancel()
else -> navDestination.navigateUp()
}
navDestination.navigateUp()
}
}
}
Expand Down
12 changes: 10 additions & 2 deletions turbo/src/main/kotlin/dev/hotwire/turbo/nav/TurboNavigator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,21 @@ internal class TurboNavigator(private val navDestination: TurboNavDestination) {

fun navigateUp() {
onNavigationVisit {
currentController().navigateUp()
if (fragment is DialogFragment) {
fragment.requireDialog().cancel()
} else {
currentController().navigateUp()
}
}
}

fun navigateBack() {
onNavigationVisit {
currentController().popBackStack()
if (fragment is DialogFragment) {
fragment.requireDialog().cancel()
} else {
currentController().popBackStack()
}
}
}

Expand Down

0 comments on commit 00b875b

Please sign in to comment.