d

    Daniel

    1 year ago
    I needed a [Material ExposedDropdownMenu](https://material.io/components/menus#exposed-dropdown-menu), so I built one by combining an OutlinedTextField and a DropdownMenu. What I've built works, but feels a little hacky. I ended up needing to use SubcomposeLayout and MutableInteractionSource for the first time. Does that sound reasonable? The code: https://gist.github.com/danielzfranklin/6af017eec110dee4980167bb833077ef I use SubcomposeLayout because DropdownMenu opens a popup outside the normal flow, so if I want it to be properly positioned and sized I need to know the size of the field. I use MutableInteractionSource to make the text field focused when the menu is expanded, and visa-versa.
    But not happy with the result
    d

    Daniel

    1 year ago
    You might find what I did to properly set the width of the drop-down useful
    Thomas

    Thomas

    1 year ago
    Looks great! By the way, have you seen the following? It may be interesting to see what they did. https://android-review.googlesource.com/c/platform/frameworks/support/+/1539606
    d

    Daniel

    1 year ago
    Darn. Wish I'd noticed that...
    Thomas

    Thomas

    1 year ago
    Well I tried it and it does not work really well (talking about the gerrit link), but that is probably why it hasn't been merged. Maybe it contains something you find useful.
    d

    Daniel

    1 year ago
    Yeah, its a pretty similar general approach to what I ended up with
    One of the things I think they do better is using the
    FocusRequester
    api instead of a
    MutableInteractionSource
    , which I didn't know about
    They also change the DropdownMenu API to remove the need for the SubcomposeLayout I use