Is there a way we can change `fontScale` in `Densi...
# compose
l
Is there a way we can change
fontScale
in
Density
? I am working on a feature which users can change the
fontScale
within the app. I thought doing sth like this would be elegant:
Copy code
val density = LocalDensity.current.copy(fonScale = customizedFontScale)
            CompositionLocalProvider(LocalDensity provides density) {
                content()
            }
However,
Density
is an interface I can not copy it. Also I found the real implementation is
DensityWithConverter
which is a private class I can not access it as well. So is there anything I can do or any better approach?
z
You’re very close realizing it’s an interface:
Copy code
val parentDensity = LocalDensity.current
val myDensity = remember(parentDensity) {
  object : Density by parentDensity {
    // override whatever you want
  }
}
// provide myDensity
💯 1
l
👍 Thanks Zach. It works like a charm. I haven't thought of interface delegation.
👍🏻 1