https://kotlinlang.org logo
#compose
Title
# compose
m

mattinger

02/03/2022, 3:54 PM
Does anyone know the rationale behind not exposing any semantic properties for text styles? All i seem to be able to validate is the text string, but not the font size, font family, etc….
t

tad

02/04/2022, 6:06 AM
Because semantic properties are primarily meant for accessibility services
m

mattinger

02/04/2022, 2:18 PM
@tad That’s kind of the issue though. How else would you test things like that? There’s no actual view to access with discrete properties. Semantics are the only way to test anything conditions in compose. Im not directly looking to test things like color. But i do have custom properties to test. I have a button which has a “tone” property that when combined with a “variant” and “size” affect colors, padding, etc…. I don’t necessarily need to test the colors and fonts directly, but i did add semantic properties for these 3 attributes so i can ensure that a given UI is putting the right type of button in the right slot.
I’m just wishing that more things were exposed in the semantic properties to validate this sort of stuff.
To be honest, it’s a big miss in my opinion to be able to create a text field like this in your UI:
Copy code
Text(..., style=MaterialTheme.typography.body1)
And not be able to write a test case to make sure the proper style has been set on it.
t

tad

02/04/2022, 5:54 PM
You can set tags, and it's not hard to create semantics keys
But at some point you have to trust that the Composable did the right thing with the arguments you provided to it
Otherwise you're testing the framework, and not your app