Hello, I have the following code in my project (I ...
# compose
h
Hello, I have the following code in my project (I saw it in JetNews repo)
Copy code
@Model
object AppNavigator {
    var currentScreen: Screen = Screen.Home()
}

/**
 * Temporary solution pending navigation support.
 */
fun navigateTo(destination: Screen) {
    AppNavigator.currentScreen = destination
}
But now I'm using dev12, and we know that
@Model
is deprecated. How do you guys would fix it? I've tryied:
Copy code
object AppNavigator {
    var currentScreen: MutableState<Screen> = state { Screen.Home() }
}
But it does not work, states must be called inside composables
k
var currentScreen by mutableStateOf(Screen.Home())
๐Ÿ™Œ 1
โ˜๏ธ 1
There are some problems with auto Import in the recent versions of AndroidStudio If the Idea throws error: Type 'MutableState<TypeVariable(T)>' has no method 'getValue(ThemeState, KProperty<*>)' and thus it cannot serve as a delegate Import getValue and SetValue manually.
Copy code
import androidx.compose.getValue
import androidx.compose.setValue
v
@Kazemihabib1996 it does not work.
๐Ÿค” 1
k
@Val Salamakha throws error?
v
yes
k
what's the error?
v
Copy code
import androidx.compose.getValue
import androidx.compose.setValue
The abovementioned is not active and they are shown as unused .
k
I had experiences like that but it builds with out problem, it's the kotlin plugins bug I think
v
Finally it works as Screen.Home
Copy code
var currentScreen by mutableStateOf( Screen.Home )
Anyway thanks to @Kazemihabib1996
๐Ÿ‘ 1
@henrikhorbovyi The last version of Jetnews is working when you change code in the file Status.kt to the following :
Copy code
import androidx.compose.getValue
import androidx.compose.setValueobject                                              ...                                                 object JetnewsStatus {
    var currentScreen by mutableStateOf( Screen.Home as Screen )
    val favorites by mutableStateOf(ModelList<String>())
    val selectedTopics by mutableStateOf(ModelList<String>())

}
other code without changes.
๐Ÿ‘ 1
โœ”๏ธ 1
a
You don't need to use mutableStateOf around ModelLists
๐Ÿ‘ 1
n
Jetnews is updated to
dev12
on the
develop
branch. We still need to merge this back https://github.com/android/compose-samples/blob/develop/JetNews/app/src/main/java/com/example/jetnews/ui/Status.kt#L33
โค๏ธ 1
๐Ÿ‘ 1
h
@Kazemihabib1996 it worked \o/ Thanks
๐Ÿ‘ 1
I've tried this before but, I saw an error, but now it worked when I passed a
<T>
Copy code
... mutableStateOf<Screen>(...)
I think was exactly the "import error" that you mentioned @Kazemihabib1996
And @nickbutcher, I didn't see this pull request and I created the issue for
@Model
๐Ÿ˜„
Thanks to share it
n
No worries, thanks for filling it. We should maybe make the
develop
branch more prominent as it's the most useful.
๐Ÿ‘ 1