ste
03/09/2022, 12:55 PMfun Modifier.clickable(
context: CoroutineContext,
enabled: Boolean = true,
onClick: suspend CoroutineScope.() -> Unit
) = composed {
val coroutineScope = rememberCoroutineScope()
clickable(enabled = enabled) { coroutineScope.launch(context = context, block = onClick) }
}
efemoney
03/09/2022, 4:42 PMStylianos Gakis
03/09/2022, 4:59 PMEric Chee
03/09/2022, 5:34 PMste
03/09/2022, 7:48 PMViewModel
user... it looks like boilerplate code to me - is it just a matter of where to put the code? What are the benefits of using the ViewModel
scope?Eric Chee
03/09/2022, 9:27 PMEric Chee
03/09/2022, 9:37 PMfun Modifier.myClickable(
scope: CoroutineScope,
onClick: suspend CoroutineScope.() -> {}
) = scope.launch{ onClick() }
ste
03/10/2022, 9:27 AMStylianos Gakis
03/10/2022, 9:31 AMStylianos Gakis
03/10/2022, 9:33 AMste
03/10/2022, 9:46 AMfun Modifier.clickable(
scope: CoroutineScope,
onClick: suspend CoroutineScope.() -> Unit
) = clickable(enabled = enabled) { scope.launch(block = onClick) }
efemoney
03/10/2022, 9:48 AMste
03/10/2022, 9:53 AMval coroutineScope = rememberCoroutineScope()
// ...
Spacer(Modifier.clickable { coroutineScope.launch { ... } })
?ste
03/10/2022, 9:54 AM