https://kotlinlang.org logo
Title
l

Lucas Kivi

01/30/2023, 11:06 PM
Can we invoke a function without causing recompositions? This causes everything within the current
@Composable
scope to recompose.
val boolean by remember {
    derivedStateOf { uiState.offset.value > 0 }
}

stateHolder.handleState(boolean)
this works but feels really bad because it builds a flow every time the key changes and is asynchronous…
LaunchedEffect(uiState) {
    snapshotFlow { uiState.offset.value > 0 }
        .onEach { stateHolder.handleState(boolean) }
        .collect()
}
Also, if this is just a really bad idea please let me know 🙂
t

Tung97 Hl

01/31/2023, 7:09 AM
Can you share entire the composable function?
l

Lucas Kivi

01/31/2023, 3:53 PM
I think my issue is caused by something else..
t

Tung97 Hl

01/31/2023, 4:20 PM
If you share the composable function entirely it will be easier to detect the issue.
Because compose compiler is very magic :)))
l

Lucas Kivi

01/31/2023, 7:02 PM
hahah ya I tried to break it down into a very simple example and the same issue didn’t occur
So I think the issue I am seeing is related to something else.. I will keep investigating 🙂
a

Andy Himberger

02/08/2023, 1:59 AM
If you remove the 'by' and use state.value only in a lambda scope where its needed you can control what composables are getting invoked when the value changes