I have a question, how does a Composable function ...
# compose
m
I have a question, how does a Composable function with a non-Unit return value works? Will the result of that function call be cached if the Composable function parameters doesn't change? I've found this pattern for Dialog works pretty well. It returns a MutableState so code outside can mutate it to show the dialog
a
@Leland Richardson [G] can speak to the precise skipping rules, I believe they're about to change a bit but it shouldn't affect what you're doing here.
Either way we consider it better to pass in this kind of state as a parameter rather than returning a control surface
By offering it as a parameter it's clearer that the surrounding environment is controlling the dialog's behavior and that that surrounding environment owns that state
It also doesn't impose ordering requirements on the caller; the caller can pass that kind of state to other things before invoking the
InputDialog
if it would make more sense/be clearer to do so
For dialogs in particular we've found it's quite nice to bring the conditional logic of showing the dialog out of the dialog functions entirely, e.g.:
Copy code
var shown by savedInstanceState { false }

if (shown) {
    InputDialog(...)
}
👍 1
So that when the dialog enters composition, it's shown, and when it leaves composition, it's dismissed