Reputation: 11
When wrapping a ExposedDropdownMenuBox within a scrollable Composable like LazyColum or Column, scrolling results in numerous recompositions of the ExposedDropdownMenuBox and the Text within it. Is this the expected behavior? How could this be fixed or is this a bug in the implementation of ExposedDropdownMenuBox? (I'm using compose version 1.4.0-alpha03)
Below is some minimal example code to reproduce the issue:
Column(
modifier = Modifier
.fillMaxWidth()
.verticalScroll(rememberScrollState())
) {
(1..100).forEach { _ ->
ExposedDropdownMenuBox(
modifier = Modifier
.fillMaxWidth(),
expanded = false,
onExpandedChange = {}
) {
Text(text = "Text")
}
}
}
With the above code example, I'm expecting no recompositions of the ExposedDropdownMenuBox and the composables within it when scrolling. However with each scrolling of the list multiple recompositions happen.
Upvotes: 1
Views: 205
Reputation: 1491
this doesn't appear to be an anticipated situation. The same issue persists in the latest version of Material below.
implementation 'androidx.compose.material:material:1.6.0-beta01'
You can opt for Material 3 if you prefer. I tested it in the latest Material 3 version below and didn't encounter recomposition. You can use both concurrently; it might be a bit confusing (such as determining which one to import when using a component). I also suggest transitioning to Material 3.
implementation 'androidx.compose.material3:material3:1.2.0-alpha11'
Upvotes: 1