Another question about View DSL: are there any exa...
# splitties
w
Another question about View DSL: are there any examples for binding streams to specific view methods? I’m a big fan of DataBinding, and I’m curious if there’s some already established patter to e.g. directly pass
LiveData<String>
to
TextView::setText
? Probably couple of extension methods would be enough for majority of use cases, but I imagine something like adapters/converters would make view dsl very interesting
l
There's no such thing in Splitties, but there's also nothing in the way of doing it.
In my case, I use coroutines a lot in my apps, and I use them along with regular functions to asbtract the UI away.
That helps me have a clearer view of what the UI can actually do, and my UI and the code controlling it are very decoupled since those suspending and regular functions are defined in an interface.
w
Bu you have suspended fucntions like
setSomeViewProperty
, right?
For the first example taken from Splitties sample (on the current develop branch), here's an example of the implementation of the interface: https://github.com/LouisCAD/Splitties/blob/aa28eaaa6da877f09f8565ec6c6f4d3825b2d291/samples/android-app/src/androidMain/kotlin/com/example/splitties/main/MainUiImpl.kt
I do my kind of data-binding with coroutines, loops, and `Flow`s where apprioriate. There might be a better way though, and I'm interested to read your thoughts about it.
w
That’s very interesting patter 🤔 Right now I’m evaluating Splitties to possibly replace part of my app where we build some views dynamically from predefined components like title, tags etc., some of which take parameters. Right now I do this via custom binding adapters and just bunch of code that inflates these custom layouts into the ConstraintLayout. It works, but I don’t love it. I’ll definitely try to use view dsl for this at some point and I’ll let you know my thoughts 🙂 I don’t use Flow or coroutines yet, though. But in my case these views are pretty static, so I don’t need much either.
Anyway once I have some extra time I’ll check this out, was just wondering if there’s already something ready for those bindings
l
FYI, the reason why I'm using coroutines is because of the amazing possibilities when you take advantage of cancellation support and `try`/`finally`. But I started to do programmatic UIs with Splitties without abstracting it with `interface`s and using coroutines so much.