Id love to align the `trailingIcon` of my `TextFie...
# compose
z
Id love to align the
trailingIcon
of my
TextField
with the input text. Is there a "safe" way to do this? All I can think of is offsetting it by some magic number based on the entire fields size.. but that doesnt feel like a good solution in the long run blob sweat smile
z
You could align by the last baseline, but that might not work when the text is empty. @Halil Ozercan do you have any ideas?
z
How would I go about doing that? I know that RowScope has
Modifier.alignByBaseline()
but the trailing lambda for the icon is just
@Composable () -> Unit
z
I guess you’d need to copy the implementation of the material text field
h
TextField uses a custom layout to place its items. Trailing Icon is placed according to
CenterVertically
alignment. https://cs.android.com/androidx/platform/tools/dokka-devsite-plugin/+/master:testData/compose/source/androidx/compose/material/TextField.kt;l=733 You would have to go very deep in your copy paste and change this alignment. There is
textPosition
in arguments, it might be of help.
z
Thanks to you both for responding. I was afraid that this would be the solution. Ill leave it be for now homer disappear
a
Maybe do your own thing with BasicTextFields’ decoration box?? Might be less traumatising? Still not sure thatll work without magic padding
z
Thanks @Ale Stamato! I have similar trauma/issues with that unfortunately. Both solutions would eventually lead to me having a rough time keeping up with design changes, either on my end of things, or in material itself. It would be nice to solve this issue (in a simpler way) but for me it doesnt seem worth it to copy or create my own variant just to be able to do this!