https://kotlinlang.org logo
#splitties
Title
# splitties
p

patrickdelconte

04/04/2020, 3:40 PM
Is there any way to use the views dsl without constantly invoking
add()
for nesting
Copy code
verticalLayout {
        add(textView {
            textResource = R.string.some_text
        }, lParams())
}
Coming from other dsl’s it feels a bit cumbersome to me, I’d expect to be able to write something like
Copy code
verticalLayout {
    textview {
        textResource = R.string.some_text
    }
}
Am I missing something? I don’t have much experience with android
r

ribesg

04/06/2020, 8:22 AM
That other way may feel simpler but also hides more operations and gives you less freedom
1
l

louiscad

04/06/2020, 1:57 PM
@patrickdelconte After over 2 years, this is still the best I've got without messing with the compiler or dooing some unmaintainable hack. I'm not unhappy with it though, I like to know when the view is being added. I usually keep my views in private properties in the
Ui
implementations, so there's the declaration of the views, and then the layout in
root
initialization or in an
init
block. FYI, Anko Layouts didn't have
add
, but it meant being less flexible when it comes to custom views, viewgroups and their layout parameters, and wya bigger runtime, while Splitties runtime is almost nonexistent given most of it is inlined.
m

miha-x64

04/07/2020, 11:35 AM
What about annotating all View-returning methods with
@CheckResult
?
l

louiscad

04/07/2020, 3:11 PM
That's a good idea, can you open an issue for that?
6 Views