Introduction
Vico is a light and extensible chart library for Android. It’s compatible with both Jetpack Compose and the view system, but its two main modules—compose
and views
—are independent.
Foreword by Patryk Goworowski
As a library compatible with both Jetpack Compose and views, Vico is quite unique. It doesn’t depend on the interoperability between the two UI systems. The shared, main logic resides in the
core
module and depends on the Android SDK. It doesn’t know anything about Jetpack Compose or views. Likewise, thecompose
module doesn’t know anything about views, and theviews
module doesn’t know anything about Jetpack Compose.I was a little curious about Jetpack Compose’s internals and how come it is interoperable with views. “Can you, fairly easily, share the code used to draw on the canvas between these two UI paradigms?” I asked myself. The answer is yes.
core
usesandroid.graphics.Canvas
(also used by views) to draw charts, andDrawScope
(used by Jetpack Compose) exposes an instance ofandroid.graphics.Canvas
viaDrawScope#canvas#nativeCanvas
. It’s similar for other APIs, likePath
. This approach encourages a greater level of abstraction and promotes the separation of concerns. It also helped make Vico’s API highly extensible.