Yofou
04/02/2021, 11:43 PMdecompose
for my navigation and to decouple my logic from my UI, however I'm little bit stumpped on this one problem, two pages I have need to share same state and I'm struggling to figure out how to pass it down to both of them, the closest I got was to put it in my NavComponent class and try to pass it down through the child render
functions, I reckon if i tinckered abit more, I could maybe of got it too work, however this was getting really ugly and hard to maintain which makes me feel like I'm doing it wrong, so I reverted the changes back and I'm now asking for any examples or further advice on how to aproach something like this with decompose
Colton Idle
04/03/2021, 12:37 AMjim
04/03/2021, 1:04 AMYofou
04/03/2021, 1:12 AMArkadii Ivanov
04/03/2021, 8:57 AMYofou
04/03/2021, 9:00 AMArkadii Ivanov
04/03/2021, 9:05 AMclass MyChild(val state: State<SharedState>) {}
If you need to put children in separate Gradle modules then I recommend to define separate state data class for each child, to avoid coupling. And pass it as Value<State>
. In the parent you can map it as follows: state.map { ... }
.Yofou
04/03/2021, 8:10 PMMyChild
) that I pass the state through it, but then how do I pass that class to both of my logic components (classes),
or do you mean I pass the state through the logic components class constructor? and then pass it down through the componentFactory function I supply to the router?Arkadii Ivanov
04/03/2021, 8:30 PMYofou
04/03/2021, 9:21 PMException in thread "AWT-EventQueue-0" java.lang.NoSuchFieldError: Companion
fun main() = Window(
title = "Cache Monkey",
size = IntSize(1100, 635),
undecorated = true,
resizable = true,
) {
MaterialTheme {
Surface(
color = Color(32, 32, 32),
modifier = Modifier.fillMaxSize()
) {
rememberRootComponent(factory = ::NavComponent).render()
}
}
}
Arkadii Ivanov
04/04/2021, 12:01 AM0.2.1
is compiled against Compose 0.4.0-build177
. Please make sure you are using this version.Yofou
04/04/2021, 2:55 AM