Hello, im trying to have a AnimatedVisiblity compo...
# compose
r
Hello, im trying to have a AnimatedVisiblity composable inside a Box, which is nested inside a Column like this:
Copy code
Column {
        Box {
           AnimatedVisibility(visible = true) {
               Text("test")
           }
        }
    }
This results into an error:
'fun ColumnScope.AnimatedVisibility(visible: Boolean, modifier: Modifier = ..., enter: EnterTransition = ..., exit: ExitTransition = ..., label: String = ..., content: AnimatedVisibilityScope.() -> Unit): Unit' can't be called in this context by implicit receiver. Use the explicit one if necessary
The provided fix from IDE is to annotate the AnimatedVisibility with
Copy code
Column {
        Box {
            this@Column.AnimatedVisibility(visible = true) {
                Text("test")
            }
        }
    }
Then everything works fine. The question is why is this necessary? Is this the correct fix? Why cant I call this composable like every other composable?
a
It looks like it's using/importing the wrong function, which expects a receiver of type
ColumnScope
. The "normal" function: https://developer.android.com/reference/kotlin/androidx/compose/animation/package-summary#AnimatedVisibility(kotlin.B[…]lin.String,kotlin.Function1) The column scope extension function: https://developer.android.com/reference/kotlin/androidx/compose/animation/package-summary#(androidx.compose.foundatio[…]lin.String,kotlin.Function1)
AnimatedVisibility
inside a box should probably use the non-extension function. Make sure to select the correct
AnimatedVisibility
function when using autocomplete, although I believe it should automatically pick the correct one.
a
This is a Kotlin issue and no, your code is not the correct fix as
ColumnScope
is not actually accessible there. The
AnimatedVisibility
function without a receiver is what you should use. You can extract the
AnimatedVisibility
to a new function. Using the fully qualified name
androidx.compose.animation.AnimatedVisibility
also seems to fix the problem.
🙏 1
r
thanks for the support! 🙂 will fix temporary with fully qualified name