https://kotlinlang.org logo
#compose
Title
# compose
a

Antanas A.

07/17/2019, 9:33 AM
Hi everybody, I've design question when using tools such Jetpack Compose. Is it possible to have some "methods" on a GUI components? example ListGrid.selectRecord(), ListGrid.sortColumn(), ListGrid.hideColumn(), ListGrid.disableClicks()? Or this is the same as React Redux and we can control components UI only thru explicit view state management? Or do you have some alternatives for this scenario? Problem is that currently we need for simple list grid to create "View Object (for rendering)", "View Component/Controller (for managing state) with methods" have some state container, bind state container to View Object and to View Component, and do actions thru some action dispatchers aka reducers which do not have references to either View Object nor View Component. How to handle that if there is multiple list grids or many different objects. I've largely used MVC / MVP / MVVM styles of GUI programming, and MVVM without two way binding was best available at time and now it's hard to understand how do you do programming when you do not have some reference-able graph of objects which can have a "methods". Do you thought about this during Jetpack Compose design? Any recommended way to handle state (more focus on state of UI component, not the model state)? (disclose: I personally dislike redux like designs where everything is completely separated and by that becomes hard to track what belongs to whom with custom made dynamic dispatch system which emulates OOP language method calls)
t

themishkun

07/17/2019, 10:12 AM
You can have a some kind of a UIModel with methods changing its state, which is rendered by Compose
Also you can still slap all of the ‘view’ from MVC methods on your host activity and just use Compose as a fancy replacement for xml layouts
But other people, who interested in Redux/MVVM like reactive UI architecture will have a chance to actually implement it without unnecessary boilerplate or perfomance drawbacks
New UI framework truly enables declarative-reactive UI’s, but it does not forces you to be into it, either
2
a

Antanas A.

07/17/2019, 11:43 AM
Thank you for reply
So if I correctly understood, you are saying I can just use Compose as a 'view' as of View in MVVM and just annotate my ViewModel with @Model and pass it to Compose and then implement methods on ViewModel directly or have just some kind of Controller which has reference to that ViewModel object and do manipulation on it from controller?
t

themishkun

07/17/2019, 12:27 PM
@Antanas A. Exactly 😉. Note that even if you use plain old MVP you’ll get better separation between what changed (the
@Model
) and how this changed state can be rendered
4 Views