Hello everyone, i am showing multiple bottomSheet using BottomSheetScaffold but for closing the sheet i am creating a property like this, Is it fine to define properties like
closeSheet
and
openSheet
inside Composable because Main can recompose very often?
Copy code
@Composable
fun Main() {
val closeSheet: () -> Unit = {
scope.launch {
scaffoldState.bottomSheetState.collapse()
}
}
val openSheet: (BottomSheetScreen) -> Unit = {
currentBottomSheet = it
scope.launch {
delay(100)
scaffoldState.bottomSheetState.expand()
}
}
if (scaffoldState.bottomSheetState.isCollapsed)
currentBottomSheet = null
}
a
andrew
04/24/2022, 3:41 PM
All of your composables can recompose 100s of times in succession, you'll be fine to scope your variables to your main composable, and if needed, use remember and pass in a key
j
jossiwolf
04/25/2022, 9:36 AM
Setting
currentBottomSheet
(or mutating any state's value as a matter of fact) is a side effect and should be declared as one. Creating the lambdas like that is fine though you could
remember
them with the appropriate keys to make it a bit more efficient.