dave08
10/31/2022, 3:14 PMMutableSharedFlow
as a sort of event bus down the composable hierarchy that uses a sealed class with all possible actions callable on the viewModel, and then sending that in the top level composable? Or is it better to just stick to passing up all those onClicks as lambdas...?Kevin Del Castillo
10/31/2022, 3:24 PMMike
10/31/2022, 3:37 PMdave08
10/31/2022, 3:41 PMsealed class Events {
object Install : Events()
}
@Composable
fun InstallButton(eventBus: MutableSharedFlow<Events>) ...
// in the button: onClick = { eventBus.value = Install) }
dave08
10/31/2022, 3:43 PMKevin Del Castillo
10/31/2022, 3:46 PMMike
10/31/2022, 3:47 PM@Composable
fun InstallButton(onAction: (Events) -> Unit) {
...
onClick = { onAction(Install) }
}
Mike
10/31/2022, 3:48 PMdave08
10/31/2022, 3:53 PMKevin Del Castillo
10/31/2022, 3:57 PMstringResource
in Compose, as for the action (callback) I'll suggest you just store lambdas and wire them to your functions in your ViewModel or do it as Mike suggested with action identifiers and a single callback if you prefer that, now instead of storing a lambda you'd be storing the event identifier (e.g. Install
). The "event bus" with a MutableStateFlow
is kind of an overkill because you'll have to collect the flow to react to events.dave08
10/31/2022, 4:11 PMMutableSharedFlow
... I guess Mike's suggestion is just a good. The viewModel is currently a BIG mess... I even tried grouping these buttons in
// inside the viewModel... onInstall() being a function in it
val ActionButtons = object {
val install = Pair(R.string.install, this::onInstall())
}
but for some reason ActionButtons.install
is an unresolved function... so I thought to regroup them in the view code...dave08
10/31/2022, 4:13 PMdave08
10/31/2022, 4:27 PM