Thread
#compose
    brandonmcansh

    brandonmcansh

    1 year ago
    Has anyone been able to use Composables within a TextField? Looking to replace our Chips InputView edittext with compose
    annotatedString only allows text/char from what I can tell. and TextField doesn’t have a
    content
    to implement
    Chris Sinco [G]

    Chris Sinco [G]

    1 year ago
    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)
    Zach Klippenstein (he/him) [MOD]

    Zach Klippenstein (he/him) [MOD]

    1 year ago
    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.
    Chris Sinco [G]

    Chris Sinco [G]

    1 year ago
    But by default,
    TextField
    and
    OutlinedTextField
    don’t have content params because they are designed to the Material Design spec
    brandonmcansh

    brandonmcansh

    1 year ago
    yep makes sense; was checking out BasicTextField after I sent that 🙂
    onTextLayout looks helpful
    and transformations
    Zach Klippenstein (he/him) [MOD]

    Zach Klippenstein (he/him) [MOD]

    1 year ago
    curious to see what you come up with, i think i very much misunderstood your question lol
    brandonmcansh

    brandonmcansh

    1 year ago
    i’m curious too
    reading up on AnnotatedString to see how I can use custom composable for a SpanStyle
    maybe
    Zach Klippenstein (he/him) [MOD]

    Zach Klippenstein (he/him) [MOD]

    1 year ago
    You can’t. SpanStyle and ParagraphStyle are only for styling font things
    brandonmcansh

    brandonmcansh

    1 year ago
    yeah seeing that
    Zach Klippenstein (he/him) [MOD]

    Zach Klippenstein (he/him) [MOD]

    1 year ago
    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
    brandonmcansh

    brandonmcansh

    1 year ago
    yep
    have an idea how to possibly do this
    Zach Klippenstein (he/him) [MOD]

    Zach Klippenstein (he/him) [MOD]

    1 year ago
    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
    brandonmcansh

    brandonmcansh

    1 year ago
    not as elegant as I was hoping
    brandonmcansh

    brandonmcansh

    1 year ago
    yep
    Zach Klippenstein (he/him) [MOD]

    Zach Klippenstein (he/him) [MOD]

    1 year ago
    You could put a TextField at the end of a
    FlowRow
    of chips, intercept backspace/arrow keys to “select” chips, etc
    brandonmcansh

    brandonmcansh

    1 year ago
    ooo wait
    may have found something
    AnnotatedString.Builder.appendInlineContent
    Zach Klippenstein (he/him) [MOD]

    Zach Klippenstein (he/him) [MOD]

    1 year ago
    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
    brandonmcansh

    brandonmcansh

    1 year ago
    damn
    Adam Powell

    Adam Powell

    1 year ago
    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
    brandonmcansh

    brandonmcansh

    1 year ago
    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

    lhwdev

    1 year ago
    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.
    brandonmcansh

    brandonmcansh

    1 year ago
    Nice thanks. I kind of have something shaping up similarly so I'll definitely use this as cross ref