xxfast / Decompose-Router

A Compose-multiplatform navigation library that leverage Decompose to create an API inspired by Conductor
https://xxfast.github.io/Decompose-Router/
229 stars 9 forks source link

Fix value subscription on ios and web targets #64

Closed xxfast closed 1 year ago

xxfast commented 1 year ago

Hi @arkivanov. I think #59 broke the router for both iOS and the Web targets. I was able to pinpoint the issue down to how the Values are subscribed as State in this extension function

private fun <T : Any> Value<T>.asState(lifecycle: Lifecycle): State<T> {
  val state = mutableStateOf(value)
  observe(lifecycle = lifecycle) { state.value = it }
  return state
}

This works for both Android and Desktop, but not on iOS and Web for some unknown reason.

For now, I was able to fix it temporarily with expect/actual for ios and web to fall back to the previous approach with subscribeAsAState. But this still introduces the issue of the nested router failing to navigate upon returning back.

Before

https://github.com/xxfast/Decompose-Router/assets/13775137/4527a42b-1c93-4e47-a9b9-bfbebbce79de

After

https://github.com/xxfast/Decompose-Router/assets/13775137/2b0f8cde-eb18-4f9d-be0c-8913eaf80771

This PR will

xxfast commented 1 year ago

As @arkivanov pointed out, this issue was due to the LifecycleRegistry being misconfigured for iOS and Web. No other changes necessary