From 24a07513fc4cc7f7a7987aced0e6aeb103db22bd Mon Sep 17 00:00:00 2001 From: Abe White Date: Sat, 7 Sep 2024 17:46:07 -0500 Subject: [PATCH] Fix TabView so that tabs do *not* participate in Android system back button --- Sources/SkipUI/SkipUI/Containers/TabView.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sources/SkipUI/SkipUI/Containers/TabView.swift b/Sources/SkipUI/SkipUI/Containers/TabView.swift index 396f5c0f..fe6b9ca4 100644 --- a/Sources/SkipUI/SkipUI/Containers/TabView.swift +++ b/Sources/SkipUI/SkipUI/Containers/TabView.swift @@ -248,7 +248,10 @@ public struct TabView : View { private func navigate(controller navController: NavHostController, route: String) { navController.navigate(route) { - popUpTo(navController.graph.startDestinationId) { + // Clear back stack so that tabs don't participate in Android system back button + let destinationID = navController.currentBackStackEntry?.destination?.id ?? navController.graph.startDestinationId + popUpTo(destinationID) { + inclusive = true saveState = true } // Avoid multiple copies of the same destination when reselecting the same item