anko icon indicating copy to clipboard operation
anko copied to clipboard

Styled blocks should use the (Context, AttributeSet, style: Int) constructor where possible

Open yanex opened this issue 8 years ago • 8 comments

yanex avatar May 03 '17 15:05 yanex

I would love to see this fixed! I would be willing to take a look at this but I am not really sure where to get started. From what I gather the Factories for views are generated here: https://github.com/Kotlin/anko/blob/0f99e9fd5e4c8b44f5df645206005d3e2d7d958d/anko/library/generator/src/org/jetbrains/android/anko/render/viewRenderers.kt#L107-L112

So I guess you could generate code using the 3-argument constructor instead but I am really unsure of the details (like where to take the arguments for the constructor from). I will look into this some more but if anyone could provide a few details it would certainly help a lot.

hatzel avatar May 06 '18 20:05 hatzel

@hatzel Have you made any progress on this? I would also love to see this fixed.

I think the solution might be to have a factory lambda that takes style as second argument, and then ankoView function, that accepts factory with style argument.

I would also like to help on this, as I wouldn't have to hack around this in my code.

filipproch avatar Jun 21 '18 12:06 filipproch

No I have not made any progress, sorry. With some guidance I'd still be up for but I am mostly working on unrelated projects currently.

hatzel avatar Jun 22 '18 18:06 hatzel

I investigated in applying xml styles programmatically and saw that it's only possible with the 4 arguments View constructor available only on select views on API 21+, excluding Android support libraries/AndroidX views, so there's no viable option. The third parameter expects an attribute resource id, not a style resource id, so it only works for styles defined in the theme like buttonStyle.

Ok, Airbnb engineers found an over-engineered way to apply xml styles programmatically: https://github.com/airbnb/paris

LouisCAD avatar Jun 22 '18 20:06 LouisCAD

@hatzel any progress on this bug?

ezralazuardy avatar Nov 14 '19 08:11 ezralazuardy

Nope, don't see this happening anytime soon for me. Not building apps at the moment and I'd probably be using flutter for new projects.

hatzel avatar Nov 14 '19 08:11 hatzel

oh sad :( , btw I was able to style my button using themedButton(), but any background style is not applied to it..

ezralazuardy avatar Nov 14 '19 10:11 ezralazuardy

Just FYI, it's possible to hack the theme a little to be able to use xml styles. That's what I'm doing in Splitties Views DSL (and the Material and AppCompat extension modules).

LouisCAD avatar Nov 14 '19 20:11 LouisCAD