Comments (4)
Hi, can you provide more information or an example project that reproduce this bug? I've check the todo sample and it's working for me.
2023-04-16.105025.mp4
from precompose.
class NoteListViewModel : ViewModel() {
init {
println("NoteListViewModel instance ${this.hashCode()}")
}
...
class NoteEditViewModel(
private val id: Int?,
) : ViewModel() {
init {
println("NoteEditViewModel instance ${this.hashCode()}")
}
...
@Composable
fun App() {
val navigator = rememberNavigator()
...
NoteEditScene(
id = id,
onDone = {
navigator.goBack()
},
onBack = {
navigator.navigate("/home")
//navigator.goBack()
}
)
Before switching to PreCompose, I used androidx.navigation
composable("/home") {
val viewModel: HomeViewModel = viewModel(factory = HomeViewModel.provideFactory(...))
and there the viewModel was not created again. Therefore, I expected the same behavior after switching to PreCompose.
17.04.2023.16.51.42.webm
from precompose.
You use navigator.navigate("/home")
instead of navigator.goBack()
in NoteEditScene's onBack callback, which navigates to a new route and eventually creates a new instance of HomeViewModel, that's by design. If you want to navigate to the home while keeping the HomeViewModel as a single instance, you can use navigator.navigate("/home", options = NavOptions(launchSingleTop = true))
.
from precompose.
Thank you. It would be nice to be able to see the back stack of state routes while developing, debugging, and learning how to use the library. For example, the ability to observe the current position as a string "/home/page1/page2" and so on.
from precompose.
Related Issues (20)
- back button doesn't close floating scene HOT 3
- Sliding transition HOT 8
- Add previousEntry alongside currentEntry to Navigator HOT 3
- 什么时候支持 kotlin 2.0 哇,以及 kotlin.wasm.target HOT 2
- return result without go Back HOT 1
- BackStackEntry extension "path" throws an exception. HOT 2
- Precompose navigation got my current scene unactive HOT 3
- Multiple back stacks NavigationBar HOT 6
- Android navigation doesn't survive process death HOT 6
- Scenes freezing when quickly switching routes with transitions HOT 11
- ViewModel from an unexpected class
- value didn't update in NavHost HOT 2
- PreCompose doesn't work with Compose Multiplatform 1.6.0-rc02 HOT 14
- UIImagePickerController Causing iOS Application Restart in Compose Multiplatform (iOS) HOT 2
- Navigation stuck when using with NavigationBar HOT 1
- Nested Dialog navigate HOT 1
- How do I add wrapping content to a scene? HOT 6
- how can i use ViewModel like android in desktop module? HOT 1
- [BUG] rememberNavigator returns different instances inside and outside of NavHost HOT 3
- Very high memory usage on ios when upgrading to 1.6.0 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from precompose.