slackhq / compose-lints

Lint checks to aid with a healthy adoption of Compose
https://slackhq.github.io/compose-lints
Apache License 2.0
388 stars 22 forks source link

False positive for SlotReusedDetector using it like in the Do's of the descritpion #424

Open timo-drick opened 2 days ago

timo-drick commented 2 days ago

In version 1.4.0 and 1.4.1 i get an "Composables should only be emit from one source" error for following code that is very close to the correct implementation described in https://android.googlesource.com/platform/frameworks/support/+/androidx-main/compose/docs/compose-component-api-guidelines.md#lifecycle-expectations-for-slot-parameters. Also changing it to use val movableContent = remember(content) { movableContentOf(content)} will not remove the error detection.

@Composable
fun SplitLayoutVerticalSimple(
    first: @Composable () -> Unit,
    modifier: Modifier = Modifier,
    second: @Composable () -> Unit
) {
    Layout(
        modifier = modifier.clipToBounds(),
        content = {
            Box(
                Modifier
                    .layoutId("first")
                    .consumeWindowInsets(
                        WindowInsets.safeDrawing.only(WindowInsetsSides.End)
                    )
            ) {
                first()
            }
            Box(
                Modifier
                    .layoutId("second")
                    .consumeWindowInsets(
                        WindowInsets.safeDrawing.only(WindowInsetsSides.Start)
                    )
            ) {
                second()
            }
        }
    ) { measurable, constraints ->
    ...