https://kotlinlang.org logo
#android
Title
# android
h

Hiranyey Gajbhiye

07/12/2022, 5:36 AM
We are facing a problem with compose In screens, where we need bunch of clickhandlers we are writing code like this
Copy code
createFakeComposeScreen(state,clickHandler1,clickHandler2,clickHandler3,functionality4)
and the increasing amount of parameters is looking bad Do you know how to solve this problem??? We want something like this
Copy code
createFakeComposeScreen(state,groupOfFunctions)
and we can call groupOfFunctions.clickhandler1.invoke() in compose code 🤔
TLDR:- Is there any good kotlin structure which groups functions together?
k

Kazik

07/12/2022, 7:14 AM
You can make interface with methods for each clickHandler, and pass only one object to the composable
1
r

Roman Churkov

07/12/2022, 7:50 AM
Maybe you could go with something like this
Copy code
fun a(param: Int){ Log.d("FUN",param.toString())}
fun b(param: Int){ Log.d("FUN",param.toString())}
fun c(param: Int){ Log.d("FUN",param.toString())}

@Composable 
fun Comp(
    funArray: Array<(Int) -> Unit>
){}

Comp(funArray = arrayOf(::a, ::b, ::c))
2 Views