Fix detekt issue:

Lambda parameters in a @Composable that are referenced directly inside of restarting effects can cause issues or unpredictable behavior.

If restarting the effect is ok, you can add the reference to this parameter as a key in that effect, so when the parameter changes, a new effect is created.
However, if the effect is not to be restarted, you will need to use `rememberUpdatedState` on the parameter and use its result in the effect.

See https://mrmans0n.github.io/compose-rules/rules/#be-mindful-of-the-arguments-you-use-inside-of-a-restarting-effect for more information. [LambdaParameterInRestartableEffect]
This commit is contained in:
Benoit Marty 2024-01-19 20:44:43 +01:00 committed by Benoit Marty
parent 1c1cf60ba0
commit 3ced570b3c
12 changed files with 25 additions and 15 deletions

View file

@ -294,7 +294,7 @@ private fun AttachmentStateView(
) {
when (state) {
AttachmentsState.None -> Unit
is AttachmentsState.Previewing -> LaunchedEffect(state) {
is AttachmentsState.Previewing -> LaunchedEffect(state, onPreviewAttachments) {
onPreviewAttachments(state.attachments)
}
is AttachmentsState.Sending -> {

View file

@ -57,7 +57,7 @@ fun AttachmentsPreviewView(
}
if (state.sendActionState is SendActionState.Done) {
LaunchedEffect(state.sendActionState) {
LaunchedEffect(state.sendActionState, onDismiss) {
onDismiss()
}
}

View file

@ -42,6 +42,7 @@ import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
@ -193,10 +194,11 @@ private fun BoxScope.TimelineScrollHelper(
}
}
val latestOnScrollFinishedAt by rememberUpdatedState(onScrollFinishedAt)
LaunchedEffect(isScrollFinished, isTimelineEmpty) {
if (isScrollFinished && !isTimelineEmpty) {
// Notify the parent composable about the first visible item index when scrolling finishes
onScrollFinishedAt(lazyListState.firstVisibleItemIndex)
latestOnScrollFinishedAt(lazyListState.firstVisibleItemIndex)
}
}