adrielcafe / voyager

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

viewmodel not destroy in recomposition state #477

Open javad0470 opened 1 month ago

javad0470 commented 1 month ago

Hello,

I hope this message finds you well.

I'm currently using Voyager version 1.1.0-beta02 along with Koin for dependency injection. Following the sample provided, I’m defining ViewModels within my composable screens as shown below: val vm = koinScreenModel()

However, I've encountered an issue where, during each recomposition of the composable screen, everything gets destroyed except for the ViewModel. While this behavior might be useful for temporarily sharing a ViewModel content between two composable screens, it causes significant challenges in other scenarios. Unfortunately, this issue persists across previous versions as well.

I would greatly appreciate it if you could address this issue or provide guidance on how to resolve it in my project.

Thank you so much for your help.

cjrvdev commented 3 weeks ago

As far as I know (Im rather new in kotlin/compose), the idea behind viewmodel is to survive recomposition. That should be the intented behavior