henrikhorbovyi
09/19/2024, 11:54 AMLaunchedEffect
inside of Modifier extension?
private fun Modifier.myModifier(): Modifier = composed {
val shape = // ...
LaunchedEffect(condition) {
// ...
}
this then background(shape = shape)
}
Context: Detekt is complaining about the use of `composed` or @Composable on Modifier extensions. So we need to add a Suppress, and our goal is to remove the composed or @Composable notation.
ephemient
09/19/2024, 12:02 PMcomposed
over @Composable
has been rescinded, https://developer.android.com/develop/ui/compose/custom-modifiers#create_a_custom_modifier_using_a_composable_modifier_factoryephemient
09/19/2024, 12:03 PMModifier.Node
may be better. you'll have a coroutine scope to use toohenrikhorbovyi
09/19/2024, 12:04 PMModifier.Node
, but I couldn't use LaunchedEffect
inside of itephemient
09/19/2024, 12:06 PMcoroutineScope
onAttach
and onDetach
henrikhorbovyi
09/19/2024, 12:07 PMLaunchedEffect
block?henrikhorbovyi
09/19/2024, 12:08 PMephemient
09/19/2024, 12:08 PMhenrikhorbovyi
09/19/2024, 12:08 PMephemient
09/19/2024, 12:08 PMhenrikhorbovyi
09/19/2024, 12:10 PMhenrikhorbovyi
09/19/2024, 12:20 PMLouis Pullen-Freilich [G]
09/19/2024, 3:58 PMLouis Pullen-Freilich [G]
09/19/2024, 4:00 PMLaunchedEffect() { suspendFoo() }
Becomes
scope.launch { suspendFoo() }
Inside onAttachephemient
09/19/2024, 4:07 PMvar job: Job? = null
fun onAttach() {
job?.cancel()
job = coroutineScope.launch { ... }
}
fun onDetach() {
job?.cancel()
job = null
}
for more completenessLouis Pullen-Freilich [G]
09/19/2024, 4:08 PMhenrikhorbovyi
09/20/2024, 2:36 PMhenrikhorbovyi
09/20/2024, 2:36 PM