Thread
#compose
    c

    codeslubber

    2 years ago
    I am updating an android app I have had out there a long time. (Not using Compose in it yet, want to.. 🙂 ).. Question is, I am running this app on a Pixel4XL and it was originally written a while ago. I have a screen where you use a slider to set a target amount and it’s too small. Just read a bunch of stuff and it seems like I literally have to make a duplicate layout for higher density phones? I guess that’s what I have to do? my other question is how is Compose going to handle this? Thanks.
    l

    Leland Richardson [G]

    2 years ago
    basically not much more than
    if (tooSmall(currentConfiguration)) {
      MySmallSliderAlternative(...)
    } else {
      Slider(...)
    }
    you might have something like
    currentConfiguration.screenWidth
    for instance
    additionally, screenWidth might not be the right thing (since the app might not be filling the whole screen), but you can also do like
    WithConstraints { 
      if (it.maxWidth < MIN_SLIDER_SIZE) {
        MySmallSliderAlternative(...)
      } else {
        Slider(...)
      }
    }
    c

    codeslubber

    2 years ago
    It’s funny the other dev on this project was like ‘wait they don’t just automatically scale the components?’ hahaha um, no
    Looks like my ideal solution will be a custom component, which I will wait and do in Compose, just making the thumbtack larger for now.
    Zach Klippenstein (he/him) [MOD]

    Zach Klippenstein (he/him) [MOD]

    2 years ago
    Is this an issue with screen size or density? If your layout uses
    dp
    units it should be density-independent. Most composables also use
    Dp
    for dimensions as well. If it's a screen size issue, you don't necessarily need to duplicate the whole layout, you can just redefine the dimension resource values.
    r

    romainguy

    2 years ago
    You can definitely write a layout that automatically adapts to different resolutions
    Standard widgets automatically adapts to different densities
    It's hard to answer your question without knowing more about how your layout is defined and what views you are using
    If you're using the standard slider it should already scale with density
    l

    Leland Richardson [G]

    2 years ago
    yeah, i might have misunderstood the question. If there’s a component that has an intrinsic minimum size that is too big to fit on some screen, you might have to do a trick like the above. Other than that, all layouts in compose should be “responsive” by default and be able to change size depending on the size available to them. Hope that makes sense
    c

    codeslubber

    2 years ago
    Hey guys, I noticed a review where a user had said they could no longer use the slider to set a target amount. So I tried it on my Pixel4XL and it was indeed difficult to do. But it was possible. If Android autoscaled it, might be time to take a look at those defaults and how they impact haptic usability. I ended up making the thumbtack larger, which was not a terrible ordeal so I am happy now. While discussing it with the other dev on the project, she showed me an interface where targets are set by tapping within the dial, which I really liked, so I might end up implementing that in Compose.
    l

    Leland Richardson [G]

    2 years ago
    i see, so what you’re saying is that the non-compose Slider seems to be hard to use on the Pixel4XL? and this is potentially because of autoscaling? When you say it was difficult to do, what was difficult? Were the tap targets just too small on a screen that size?
    c

    codeslubber

    2 years ago
    yes, that on larger phones, the default configuration ends up being too small a target for users, and I concurred after trying it on the P4XL
    l

    Leland Richardson [G]

    2 years ago
    i see. yeah, i misunderstood your question entirely, sorry. that just sounds like a buggy implementation that should be fixed. I’m not sure if our slider suffers from the same problem, but if it does, feel free to file a bug!
    r

    romainguy

    2 years ago
    @codeslubber Could you share your layout/setup?
    We use sliders in numerous standard apps and I don’t recall anybody filing bugs or complaining about them. I’d like to understand what’s going on
    c

    codeslubber

    2 years ago
    @romainguy sure, it is in a
    LinearLayout
    code predates
    ConstraintLayout
    and I did think about porting the view to CL, one of the documents seemed to imply that you would get a better result in adapting to a larger screen, but if it’s just doing it based on pixel density not clear how that would be.@Leland Richardson [G] will for sure do that when I try it in compose!
    Just to be super clear too: no one EVER complained about this in the past, then when I tried it I could not get my finger on the thumbtack, so we enlarged it but that’s the extent of it, not saying it doesn’t work or anything, just that the hit target on a large phone is very small.