2

I was able to access the below when I'm in Jetpack Compose 1.1.1

import androidx.savedstate.ViewTreeSavedStateRegistryOwner

However, when switching over to Jetpack Compose 1.2.0, I can no longer access it. It errors out stating

Unresolved reference: ViewTreeSavedStateRegistryOwner

e.g. In the view, I'm using it as below

ViewTreeSavedStateRegistryOwner.set(this, ViewTreeSavedStateRegistryOwner.get(composeView))

Is there any way I can still access it?

Elye
  • 53,639
  • 54
  • 212
  • 474

2 Answers2

2

In Jetpack Compose 1.2.0, we should use the below instead

import androidx.savedstate.findViewTreeSavedStateRegistryOwner
import androidx.savedstate.setViewTreeSavedStateRegistryOwner

e.g. in the view

setViewTreeSavedStateRegistryOwner(composeView.findViewTreeSavedStateRegistryOwner())
Elye
  • 53,639
  • 54
  • 212
  • 474
0

At first for me, it was a bit confusing and after spending an hour I learn how to implement it.

First of all, you don't need to import anything as nowadays Android Studio itself adds the supported library. But I am specifying just for your reference if anyone has not enabled the autoImport feature in Android studio:

import androidx.savedstate.setViewTreeSavedStateRegistryOwner

Here is a complete example below:

val views = ComposeView(context = context)
views.setContent {
      Your @Composable function/component
}
views.setViewTreeSavedStateRegistryOwner(LocalSavedStateRegistryOwner.current)
halfer
  • 19,824
  • 17
  • 99
  • 186
Milan Sheth
  • 884
  • 12
  • 11