Composables should be as decoupled as possible but...
# compose
j
Composables should be as decoupled as possible but not decoupled beyond what's practical. Use your best judgement. As a general rule of thumb, widgets should not know how to perform actions in your app (eg. a button should never launch an activity), and should instead notify their parent of an action so the parent can handle it appropriately. Similarly for the size of Composables, it is a somewhat subjective judgement call. I think most new compose developers tend to be a bit paranoid about function length and try to break up composables into helper functions that are far too small. There are benefits to having large composable functions, like being able to use lexical scoping to get data to the appropriate child widget. In the absence of specifics, I'd tell people not to worry too much about length. Instead, focus on what pieces are reusable widgets that will be used elsewhere in your app, and make each of those into a separate composable function. With regards to getting an instance of a view model inside a composable... the best way to get data into a composable is always to pass it in as a parameter.
👍 1