Tariyel Islami
03/25/2022, 5:45 PMobject Transformer {
private var transformerMap = mutableMapOf<String, Any>()
fun put(key: String, t: Any) {
transformerMap[key] = t
}
fun pull(key: String): Any {
return transformerMap[key]!!
}
}
The logic is simple,
When you use the navigate function you have to put the parameters which you want to send
Where you use the Composable function, you need to pull it and give it as a parameter.
It is perfectly working. I am wondering that is this wrong way ?Zun
03/25/2022, 5:48 PMCasey Brooks
03/25/2022, 6:03 PMcomposable()
route is no longer a pure function. And since your Transformer class is not immutable (it’s using mutableMapOf()
) there’s the possibility of new values put into the map being changed unintentionally in the receiving route. And consider that Composables may be run many times, so doing a pull
in the route will only work for the first time it’s composed, but break if it ever gets recomposed for some reason.Casey Brooks
03/25/2022, 6:06 PMMovie
should not be directly passed at all. Just pass the ID of that Movie in NavArgs, and let the destination screen fetch that Movie by the ID that was passed to it.Tariyel Islami
03/25/2022, 6:14 PM