3 ms·
Just made a big push to Anvil repository - it can now inflate layout from XMLs! This means you may use your favourite IDE to design layouts, then use Anvil to b
by zserge 11y ago
Just made a big push to Anvil repository - it can now inflate layout from XMLs! This means you may use your favourite IDE to design layouts, then use Anvil to bind data and event listeners to make your UI reactive:
public override fun view() {
// A designer gave us an XML with some fancy layout:
// a viewgroup with a button and a progress bar in it
xml(R.layout.my_layout) {
backgroudnColor(Settings.bgColor) // will modify root layout view color
withId(R.id.my_button) {
// button state may depend on some variable
enabled(isMyButtonEnabled)
// button click listener can be attached
onClick { v ->
...
}
}
withId(R.id.my_progress_bar) {
visible(isMyProgressBarShown)
progress(someProgressValue)
}
}
}
I know many people are opposed to defining layouts in code, so this can be a good compromise for them. Also, it's very helpful if you have a large project made with XMLs and want to refactor it.
- habosa 11y agoThat's fantastic! Can you upgrade the README with a little detail on this?
- zserge 11y agoDone. I will try to cover more within the next few days, hopefully I will add an example to `anvil-examples` repository and make a blog post tell more about recent changes in Anvil.
- PeCaN 11y agoWoah, that's very useful. Might even be your killer feature, actually. Totally checking this out.