Why `confirmStateChange` not using the latest sta...
# compose
k
Why
confirmStateChange
not using the latest state?. I want to disable state change while loading. My code is like this.
Copy code
val uiState = viewModel.uiState.value
Logger.d(SNAP_TAG, "UISTATE $uiState")

val bottomSheetState = rememberBottomSheetState(
     initialValue = BottomSheetValue.Expanded,
     confirmStateChange = {
           Logger.d(SNAP_TAG, "UISTATE $uiState")
           !(uiState is UiState.Loading)
     }
)
But
confirmStateChange
lambda always have uiState as Loading, even-though state changed to Success. My logs are like this whenever i tried to collapse
Copy code
UISTATE com.example.state.UiState$Loading@f06c50e
UISTATE Success

UISTATE com.example.state.UiState$Loading@f06c50e
UISTATE com.example.state.UiState$Loading@f06c50e
d
What is UI state inside your your viewmodel?
Is this a mutableStateOf or a StateFlow?
k
mutableState
j
🚦 not answer hey karthick, I wanted to understand what is the use of
confirmStateChange
?
k
when user trying to swipe it down
confirmStateChange
lambda will call and we have to return boolean. If true swiping down gesture will make bottom sheet to collapse. else it wont swipe down. Its like we are not allowing. I want to disable swipe when loading.. @jasu
j
understood, thanks
f
Why
confirmStateChange
not using the latest state?
It is using the state that was captured in lambda. Either user
uiState.value
inside the lambda or use property delagate:
val uiState by viewmodel.uiState