hotwired / turbo-android

Android framework for making Turbo native apps
MIT License
424 stars 50 forks source link

Clear back stack but keep the current location #295

Closed reaper closed 7 months ago

reaper commented 10 months ago

Hi, just try to clear the back stack but keep the current location as the start location.

An first try would be

activity.runOnUiThread {
    (activity.delegate.currentSessionNavHostFragment as MaloSessionNavHostFragment).let {
        it.currentNavDestination.location.let { currentLocation ->
            if (it.startLocation != currentLocation) {
                it.startLocation = currentLocation
                it.reset()
            }
        }
    }
}

but it hangs when calling back.

Any idea of how I can achieve this? Thank you!

jayohms commented 7 months ago

You can call clearBackStack() from any Fragment destination, which should get you the desired result.