zalewski.se
04/08/2021, 10:04 PMTextField
size so it’s adjusting to the size of the text that’s currently set. I thought that wrapContentSize()
would do the job but I couldn’t be more wrong 😬
So having this:
TextField(
modifier = Modifier.wrapContentSize(),
textStyle = TextStyle(textAlign = TextAlign.End),
value = text,
onValueChange = { text = it },
label = { Text("Label") }
)
Gave me such result in preview 👇 which arises 2 questions:
1. Why TextAlign.End
set it around 40% of the width and what is the empty space behind it?
2. Why Modifier.wrapContentSize()
doesn’t wrap it around the value or label at least? 🤔Siyamed
04/08/2021, 10:05 PMSiyamed
04/08/2021, 10:06 PMSiyamed
04/08/2021, 10:06 PMzalewski.se
04/08/2021, 10:10 PMzalewski.se
04/08/2021, 10:13 PMModifier.defaultMinSize(minWidth = 0.dp).wrapContentSize()
but no luck 😕Siyamed
04/08/2021, 11:33 PMSiyamed
04/08/2021, 11:34 PMSiyamed
04/08/2021, 11:34 PMSiyamed
04/08/2021, 11:34 PMSiyamed
04/08/2021, 11:34 PMSean McQuillan [G]
04/09/2021, 12:05 AMzalewski.se
04/09/2021, 6:50 AMAnastasia [G]
04/09/2021, 11:19 AMsizeIn(minWidth = 5.dp)
. If it doesn’t work this way, then it is a bug.Anastasia [G]
04/09/2021, 11:20 AMAnastasia [G]
04/09/2021, 11:23 AMBasicTextField("a", {}, Modifier.background(Color.LightGray))
will appear wider than ‘a’ character which is probably not what we wantzalewski.se
04/09/2021, 10:13 PMTextFieldDelegate.kt
there is:
internal const val DefaultWidthCharCount = 10 // min width for TextField is 10 chars long
In my case it looks more like 12 chars (but maybe depends on the font).
So, does it work as expected or maybe I should raise it as a bug somewhere? I was able to achieve it with the old fashioned style EditText
(like in my screenshots here) so I hope it’s not gonna be Compose TextField limitation 😅Siyamed
04/09/2021, 10:17 PMSiyamed
04/09/2021, 10:17 PMSiyamed
04/09/2021, 10:17 PMSiyamed
04/09/2021, 10:18 PMSiyamed
04/09/2021, 10:18 PMzalewski.se
04/09/2021, 10:19 PMminWidth
, set it to wrapContent
, etc but it never can wrap around 1 or 2 char, it’s always widerSiyamed
04/09/2021, 10:20 PMSiyamed
04/09/2021, 10:21 PMSiyamed
04/09/2021, 10:22 PMzalewski.se
04/09/2021, 10:22 PMcalculate a char lengthWould probably work as if I specify exact width it’s the view is adjusting it’s size correctly
Siyamed
04/09/2021, 10:23 PMSiyamed
04/09/2021, 10:24 PMzalewski.se
04/09/2021, 10:24 PMSizeIn()
doesn’t work as it keeps the min width = 10 charSiyamed
04/09/2021, 10:25 PMzalewski.se
04/09/2021, 10:26 PMdp
would take my string and apply it to the width directly 🙂 (will try to check it tomorrow actually)zalewski.se
04/13/2021, 10:53 AM