fix(#135): guard goBack() against empty back stack (#157)

goBack() now uses ChatScreen as a fallback when the stack has
only one item, preventing the Settings back-button crash.

Co-authored-by: M57 <hy4ri@users.noreply.github.com>
This commit is contained in:
M57andM57 authored and GitHub committed 2026-06-20 13:29:19 +03:00
1 parent 62b1115924
commit c6d7a45905
2 files changed
+16 -6

No files matched your search

@@ -53,8 +53,17 @@ object NavigationController {
backStack?.add(key)
}
fun goBack() {
/**
* Navigate back one step, or fall back to [fallback] when the stack has only one item.
* Never leaves the stack empty.
*/
fun goBack(fallback: NavKey = ChatScreen) {
val stack = backStack ?: return
if (stack.size > 1) stack.removeLastOrNull()
if (stack.size > 1) {
stack.removeLastOrNull()
} else if (stack.size == 1) {
stack.clear()
stack.add(fallback)
}
}
}