Wondering if there is a notion of “scaling” a comp...
# compose
v
Wondering if there is a notion of “scaling” a composable. Like if I increase the display size or scale of my android device, how does compose honor that? Moreover, if I want to do that at an individual composable level, what’s the best way to do it?
g
On changing scale size settings, I guess nothing changed. The current behavior of dp and sp units should apply, handled by the system
v
yeah I tested that as well and it works as expected. I guess I was more interested in knowing how I can simulate that behavior for a given child composable that I don’t know anything about without actually changing the phone settings.
I think the answer is providing a custom
Density
object. I’ll play with it a bit and report back.
hmm using a custom Density doesn’t work coz some low level components(like CoreText) directly access the DensityAmbient. Still hoping to find an answer so let me know if anyone here has ideas 🙂
z
Are you using
Providers
to provide your own density ambient value?
c
I wonder how this will work for situations where you want the user to be able to "zoom" a single component
v
yeah I tried it with Providers but maybe I’m not using it correctly. Here’s the code I tried
Copy code
val density = DensityAmbient.current
val customDensity = Density(fontScale = density.fontScale * 2, density = density.density)
val CustomDensityAmbient = ambientOf<Density>(StructurallyEqual)
Providers(CustomDensityAmbient provides customDensity) {
            children()
        }
nvm I got it working. I just needed to use the same key instead of passing the custom key above
Copy code
val density = DensityAmbient.current
val customDensity = Density(fontScale = density.fontScale * 2, density = density.density)
Providers(DensityAmbient provides customDensity) {
            children()
        }
👍 2