How can I manage layout programmatically in my app...
# compose
i
How can I manage layout programmatically in my app? I want to add more columns in a row with specific component inside by button click. How can I do it?
that i want to get
f
Are you trying to do a mobile or desktop app? #compose-desktop would be better for the latter. If you are not familiar with Compose, then I would recommend starting with the official documentation by Google.
i
desktop one
f
The basics of Compose are the same for Android and desktop so the official tutorial is your best bet :) There are also nice examples of desktop specific stuff in the Jetbrains compose Repository on GitHub
👍 1
a
this is a very general compose question so this is the right channel for this 🙂
possibly the getting started with compose question since it speaks to a fundamental difference of declarative toolkits
the way to do this is to define your UI in terms of your data. You have a list of modules somewhere, so your UI code becomes:
Copy code
Row {
  for (module in modules) {
    key(module) {
      ModuleColumn(module)
    }
  }
}
i
It is smart enough to detect changes in modules array and redraw UI ?
a
if you're using an observable collection like that returned by
mutableStateListOf()
, yes
alternatively, if you're using immutable collections of some sort and something observable emits new copies of the list with changes, that's also fine
i
Where I can read about app state ? For example how I can save app dimensions and when user close app and start it again it restores it position and configuration (height and width)
I came from angular so i trying to match that experience
a
the info at https://developer.android.com/jetpack/compose/state might help, if you're working on desktop then ignore the parts where it talks about parcelize/androidx ViewModel, the rest of it about state holders all still applies regardless of platform
👍 1