icerockdev / moko-widgets

Multiplatform UI DSL with screen management in common code for mobile (android & ios) Kotlin Multiplatform development
https://moko.icerock.dev
Apache License 2.0
389 stars 32 forks source link

Change widget style by state #159

Open Tetraquark opened 4 years ago

Tetraquark commented 4 years ago

I need to create a widget similar to Android RadioGroup and RadioButton views - there is one active button for all group, and active and inactive buttons have different styles (background, text style, border, etc.). It should look like this:

radiogroup

Currently, it's not possible to do that with set of ButtonWidget because it's impossible to change button style after the widget has been created (because the style is described for the widget factory). And there is no any stateful widgets that can allow change the widget style based on the state in some LiveData.

Alex009 commented 4 years ago

this issue is tied to the fundamental limitation of widget / factory separation. for this case we can create something like

rebuiltWidget(data) { value ->
    // here create widgets that will be fully recreated when data will be change
}

but without full recreation of view now it can't be done as i think (or we should use virtual dom on platform side with diffing like React - something like https://github.com/inkremental/inkremental maybe)