Vico

4.2. Factory functions

As discussed in 1.1, core uses android.graphics APIs shared between Compose and views. In this context, dp dimensions are Floats, colors are Ints, and so on. The same applies to the view system, which uses android.graphics APIs quite directly.

Jetpack Compose, on the other hand, introduces a larger abstraction layer over the underlying android.graphics APIs, with classes such as Dp and Color. Under the hood, it ultimately converts instances of these to android.graphics-compatible types, but this doesn’t concern the consumer.

Thus, to enable the natural use of Vico with Compose, the compose module provides factory functions with parameters of Compose types. These wrap core constructors and factory functions, handling the conversion to android.graphics types internally, much like Compose itself does. Some of these factory functions also provide defaults based on the theming system.

You should therefore never find yourself using android.graphics-like constructs—such as Floats for dp dimensions or Ints for colors—when working with Vico and Compose. Call the appropriate compose factory functions instead. This isn’t to say that all core APIs are off limits for Compose. Many core constructors and factory functions have no parameters (1) of types for which Compose has abstractions or (2) that require defaults based on the theming system. These are perfectly appropriate to use in Compose—in fact, they have no compose counterparts, as these would be identical.