adrielcafe / voyager

🛸 A pragmatic navigation library for Jetpack Compose
https://voyager.adriel.cafe
MIT License
2.27k stars 109 forks source link

Retain old screen #400

Open grandleaf opened 3 weeks ago

grandleaf commented 3 weeks ago

While I appreciate Voyager’s pragmatic interface and flexibility, I’ve encountered an issue: when navigating to a new screen, the old screen gets disposed. Is there an option to instruct Voyager to retain the old screen without destroying it? My concern arises because I’ve integrated a WebView, and disposing and recomposing screens could lead to performance degradation and state loss. Thank you.

Hightower87 commented 2 weeks ago

I guess, If you want to retain something on your screen which is in the background, use screenModel. This is compose thing: when a screen is removed from screen, it should be disposed.

grandleaf commented 2 weeks ago

@Hightower87, thanks for the suggestion. Basically I want to put a WebView into the navigation framework. And it is really expensive to recompose a WebView even though its states can somehow be saved by some unofficial approaches.

duanemalcolm commented 4 days ago

I was after the same behaviour because recomposing my main view was expensive. My work around was to do the following. I'm not sure if this is a good or best approach and would welcome feedback.

var navigator: Navigator? = null

AppTheme() {

    MainScreen(onNavigate = { navigator?.push(it) })

    Navigator(EmptyScreen) { nav ->
        navigator = nav
        SlideTransition(nav)
    }
}