Nick
08/20/2021, 1:19 PMTin Tran
08/20/2021, 1:22 PMStylianos Gakis
08/20/2021, 1:23 PMonClick = {}
and it will work just fine.Nick
08/20/2021, 1:26 PMCompositionLocal
for click events? Is that appropriate?Tin Tran
08/20/2021, 1:28 PMNick
08/20/2021, 1:29 PMStylianos Gakis
08/20/2021, 1:33 PM@Composable
fun MyScreen(stuff: Whatever, navigationActions: NavigationActions)
class NavigationActions(whatever: Any) {
val doSomething: () -> Unit { // stuff }
val doSomethingElse: () -> Unit {}
}
Where NavigationActions could be whatever fits your use case, usually those actions have some logical grouping that can fit them inside one/more class(es)
And then on the composable that takes this actions class, call the leaf composable that will just take them individually something like
@Composable
fun MyScreen(actions: NavigationActions) {
val viewModel: MyViewModel = hiltViewModel()
MyScreen(
setThis = { clickedSomething ->
viewModel.setSomething(clickedSomething)
},
goToDetailsScreen = { someId: Int ->
actions.goToDetailsScreen(someId)
},
goBack = {
actions.goBack()
},
)
}
Then you can pass your actions whatever they may be bundled inside one class and pass that down the hierarchy?Nick
08/20/2021, 1:47 PMColton Idle
08/20/2021, 6:32 PMZach Klippenstein (he/him) [MOD]
08/20/2021, 7:56 PMfun A() {
B(a)
}
fun B(b) {
C(b)
}
fun C(c) {
D(c)
}
You would have
fun A() {
B {
D(a)
}
}
fun B(content: @Composable () -> Unit) {
C(content)
}
fun C(content: @Composable () -> Unit) {
content()
}