Skip to content

Commit 338f738

Browse files
committed
Avoid clearing backstack
1 parent 7e6909e commit 338f738

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

app/src/main/java/at/bitfire/icsdroid/MainActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class MainActivity : AppCompatActivity() {
2121
super.onCreate(savedInstanceState)
2222

2323
setContentThemed {
24-
MainApp(savedInstanceState, intent.extras)
24+
MainApp(savedInstanceState, intent.extras, ::finish)
2525
}
2626
}
2727

app/src/main/java/at/bitfire/icsdroid/ui/nav/MainApp.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ private fun calculateInitialDestination(intentExtras: Bundle?): Destination {
5151
fun MainApp(
5252
savedInstanceState: Bundle?,
5353
intentExtras: Bundle?,
54+
onFinish: () -> Unit,
5455
) {
5556
// If EXTRA_PERMISSION is true, request the calendar permissions
5657
val requestPermissions = intentExtras?.getBoolean(EXTRA_REQUEST_CALENDAR_PERMISSION, false) == true
@@ -76,13 +77,19 @@ fun MainApp(
7677

7778
val backStack = rememberNavBackStack(calculateInitialDestination(intentExtras))
7879

80+
fun goBack(depth: Int = 1) {
81+
if (backStack.size <= 1) onFinish()
82+
else repeat(depth) { backStack.removeAt(backStack.lastIndex) }
83+
}
84+
7985
NavDisplay(
8086
entryDecorators = listOf(
8187
rememberSceneSetupNavEntryDecorator(),
8288
rememberSavedStateNavEntryDecorator(),
8389
rememberViewModelStoreNavEntryDecorator()
8490
),
8591
backStack = backStack,
92+
onBack = ::goBack,
8693
entryProvider = entryProvider {
8794
entry(Destination.SubscriptionList) {
8895
SubscriptionsScreen(
@@ -107,7 +114,7 @@ fun MainApp(
107114
title = destination.title,
108115
color = destination.color,
109116
url = url,
110-
onBackRequested = backStack::removeLastOrNull
117+
onBackRequested = { goBack() }
111118
)
112119
}
113120
}

0 commit comments

Comments
 (0)