Is there any sort of equivalent mechanism to `@Dis...
# compose
s
Is there any sort of equivalent mechanism to
@DisallowComposableCalls
that I can apply to my own functions to not allow them to be called from inside composable functions? Or if not, any ideas on how to improve the developer experience regarding this: I have a function that looks like this:
Copy code
inline val Int.dp: Int
    get() = (this * Resources.getSystem().displayMetrics.density).toInt()
That is used from normal non-composable functions, but is simply annoying as it always comes as a code completion suggestion when I’m inside composable functions, but in there I always want the
androidx.compose.ui.unit.dp
import instead.
t
You could make a scope object
X
that provides that extension, but you'd need to use
with(X) { int.dp }
everywhere
Kind of like
Density
in Compose
s
Yeah, we're using the view version of .dp in quite a lot of places, I wouldn't want to change how it looks like on the call site optimally. I recently read about this maybe it's what I was looking for actually