Has anyone been able to use Composables within a T...
# compose
b
Has anyone been able to use Composables within a TextField? Looking to replace our Chips InputView edittext with compose
👍 1
annotatedString only allows text/char from what I can tell. and TextField doesn’t have a
content
to implement
c
If you mean to modify the content of a TextField, one can always use
BasicTextField
to fully customize it: https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/package-summary#BasicTextField(androidx.[…]s.Brush,kotlin.Function1)
z
It might be easier to create something that looks like a TextField but can hold arbitrary composables, and place TextFields where you actually want there to be cursors. Of course, making selection work between text and chips would probably be complicated and idk if it’s even possible.
c
But by default,
TextField
and
OutlinedTextField
don’t have content params because they are designed to the Material Design spec
b
yep makes sense; was checking out BasicTextField after I sent that 🙂
👍 1
onTextLayout looks helpful
and transformations
z
curious to see what you come up with, i think i very much misunderstood your question lol
b
i’m curious too
reading up on AnnotatedString to see how I can use custom composable for a SpanStyle
maybe
z
You can’t. SpanStyle and ParagraphStyle are only for styling font things
b
yeah seeing that
z
The only way to so something like what you’re asking would be with
inlineContent
, but that seems to be only a
Text
thing, not
TextField
b
yep
have an idea how to possibly do this
z
And it requires knowing the size of each piece of content before composing it, which is awkward for things like chips which could be any size
b
not as elegant as I was hoping
b
yep
z
You could put a TextField at the end of a
FlowRow
of chips, intercept backspace/arrow keys to “select” chips, etc
b
ooo wait
may have found something
đź‘€ 1
AnnotatedString.Builder.appendInlineContent
z
Yea, that’s for
BasicText
only though, and you have to define the placeholder sizes before composing them
I tried to hack something to try to do dynamic sizing here, but it is very hacky and lags by a frame, and again only good for
BasicText
not text fields
b
damn
a
This is one area where I'd really like to expand what you can do with focus and soft keyboard interactions while representing the actual displayed content with whatever arbitrary stuff you could come up with
🦜 3
b
yeah there is a lot of cool things that could be done with that foundation
probably gonna roll with the FlowRow impl for now; that’s essentially what I’m doing currently when boiled down (currently subclassing TextInputEditText and chipping text on terminators replacing them with ChipDrawables with edit/remove support)
l
If you want to just use material text field decoration(not ime and text editing things), you can use this: https://gist.github.com/lhwdev/1eb4955f32c5d8986965b80b025f01a1 I used this to implement material dropdown. Most things are copy-pasted from compose material source code.
b
Nice thanks. I kind of have something shaping up similarly so I'll definitely use this as cross ref