@@ -51,6 +51,7 @@ private fun calculateInitialDestination(intentExtras: Bundle?): Destination {
5151fun 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