Accompanist for Kotlin: Complete Guide with Examples

Online Python Trainer for Beginners

Learn Python easily without overwhelming theory. Solve practical tasks with automatic checking, get hints in Russian, and write code directly in your browser — no installation required.

Start Course
\n

Accompanist for Kotlin: Complete Guide with Examples

\n\n
\n

1. What It Is and Why You Need It

\n

Accompanist is a collection of extension libraries for Jetpack Compose, developed by the Google team. It provides ready-made solutions for tasks that either have not yet been included in the stable Compose API or require complex implementation from scratch. The library solves problems every Compose developer faces: working with gestures, system bars, animations, web views, adapting to different screens, and much more.

\n

Why do you need it? First, Accompanist saves time. Instead of writing your own gesture handler or custom modifier for system bars, you use a ready-made, tested component. Second, the library follows official Google recommendations and often serves as a prototype for future stable Compose APIs. For example, HorizontalPager from Accompanist was later added to Compose Foundation as HorizontalPager.

\n

At the time of writing, Accompanist includes modules such as: systemuicontroller (status bar and navigation bar management), permissions (runtime permission requests), webview (embedding WebView), pager (horizontal/vertical page scrolling), swiperefresh (pull-to-refresh gesture), placeholder (skeleton loading), adaptive (adaptive layouts), navigation-animation (transition animations), and others.

\n
\n\n
\n

2. Installation

\n

Accompanist is a library for Gradle (Android/Kotlin Multiplatform). Installation is done by adding dependencies to your module's build.gradle.kts (or build.gradle) file. Commands like pip, npm, cargo, or go get are not used, as this is not Python, JavaScript, Rust, or Go.

\n

The exact command for adding a specific module (e.g., systemuicontroller):

\n
// build.gradle.kts (Module)\ndependencies {\n    implementation("com.google.accompanist:accompanist-systemuicontroller:0.34.0")\n    // For other modules:\n    // implementation("com.google.accompanist:accompanist-permissions:0.34.0")\n    // implementation("com.google.accompanist:accompanist-pager:0.34.0")\n    // implementation("com.google.accompanist:accompanist-swiperefresh:0.34.0")\n    // implementation("com.google.accompanist:accompanist-webview:0.34.0")\n    // implementation("com.google.accompanist:accompanist-placeholder:0.34.0")\n}
\n

Important: check the latest version on GitHub Releases. Version 0.34.0 is the latest stable at the time of writing. Ensure your Kotlin and Compose versions are compatible with the chosen Accompanist version.

\n
\n\n
\n

3. Quick Start — Minimal Working Example

\n

Let's create a screen that changes the status bar color when a button is pressed. For this, we'll use the systemuicontroller module.

\n
import androidx.compose.foundation.background\nimport androidx.compose.foundation.layout.*\nimport androidx.compose.material3.*\nimport androidx.compose.runtime.*\nimport androidx.compose.ui.Modifier\nimport androidx.compose.ui.graphics.Color\nimport androidx.compose.ui.unit.dp\nimport com.google.accompanist.systemuicontroller.rememberSystemUiController\n\n@Composable\nfun QuickStartExample() {\n    val systemUiController = rememberSystemUiController()\n    var isDark by remember { mutableStateOf(false) }\n\n    // Set status bar color based on state\n    LaunchedEffect(isDark) {\n        if (isDark) {\n                    

Recommendations