escodro
09/24/2021, 6:48 PMState
only occurs when inside an action from a @Composable
?
For example:
var state by rememberSaveable { mutableStateOf(StateA) }
when (state) {
StateA -> { if(condition) { state = StateB } else { state = StateC } } // This does not trigger
StateB -> Button(onClick = state = StateD) { Text("Click me") } // This works fine when clicked
...
}
I’m trying to do some condition check before showing UI for the user and tried using State
. Any thoughts?
Thanks a lot! ❤️Zach Klippenstein (he/him) [MOD]
09/24/2021, 6:58 PMvar primaryState by rememberSaveable { mutableStateOf(StateA) }
val secondaryState by remember {
derivedStateOf {
if(condition) StateB else StateC
}
}
And then it would make sense for StateA
and `StateB`/`StateC` to not share a parent type.escodro
09/24/2021, 9:50 PMAlertDialogs
to inform the user about the download process.
The State
are:
RequestDownload -> show a dialog to the user
Downloading -> show a dialog with progress
FeatureReady -> open the DFM
Previously, I had another State
called FeatureVerification
, which checked if the feature is already installed so it could jump to FeatureReady
state.
Based on your comment, I updated to the following code:
val isFeatureReady = isFeatureInstalled(featureName = featureName)
val initialState = if (isFeatureReady) FeatureReady else RequestDownload
var state by rememberSaveable { mutableStateOf(initialState) }
when (state) {
RequestDownload -> ...
Downloading -> ...
FeatureReady -> ...
}
What do you think about it? 😊Zach Klippenstein (he/him) [MOD]
09/27/2021, 3:26 PMisFeatureInstalled
change the value that it returns over time? If it can, this code could be tricky to reason about.escodro
09/27/2021, 4:39 PMval isFeatureReady = isFeatureInstalled(featureName = featureName)
val initialState = remember {
derivedStateOf { if (isFeatureReady) FeatureReady else RequestDownload }
}
var state by rememberSaveable { mutableStateOf(initialState.value) }
when (state) {
RequestDownload -> ...
Downloading -> ...
FeatureReady -> ...
}
Zach Klippenstein (he/him) [MOD]
09/27/2021, 5:28 PMstate
will still only read the value when it’s initialized, and not even then if it’s being restored.escodro
09/27/2021, 5:44 PMZach Klippenstein (he/him) [MOD]
09/27/2021, 5:59 PMescodro
09/27/2021, 6:12 PMDmitrii Smirnov
09/29/2021, 6:36 AM