Accompanist
repository·main·Indexed 27 days ago
https://github.com/google/accompanistA suite of libraries providing supplemental features for Jetpack Compose, serving as a laboratory for new APIs before they are integrated into the official AndroidX toolkit. Available libraries include Permissions for runtime permission support, Drawable Painter for using Android Drawables as Compose Painters, and Adaptive for creating adaptive layouts with components like TwoPane and FoldAwareColumn. It also provides a theme adapter to bridge AppCompat XML themes with Compose.
What's inside Accompanist
- Accompanist is a collection of libraries designed to supplement Jetpack Compose with features not yet available in the official toolkit. These libraries serve as a testing ground for new APIs and are intended to be eventually upstreamed into the official AndroidX Compose libraries. Once a feature is moved to the official toolkit, the corresponding Accompanist library is deprecated and removed.
Available Accompanist libraries
mainThe following libraries are currently available in the Accompanist repository:
- Permissions: Provides Android runtime permissions support for Jetpack Compose.
- Drawable Painter: Provides a way to use Android Drawables as Jetpack Compose
Painters. - Adaptive: Provides a collection of utilities for creating adaptive layouts.
Migrate from Accompanist Navigation Material to androidx.compose.material.navigation
mainThe Accompanist Navigation Material library is deprecated. All functionality has been moved to the official
androidx.compose.material.navigationlibrary (available inandroidx.compose.materialversion 1.7.0-alpha04 and later).To migrate:
- Replace the dependency: Change
com.google.accompanist:accompanist-navigation-material:<version>toandroidx.compose.material:material-navigation:<version>. - Update imports: All class names remain the same, but you must update the package names:
ModalBottomSheetLayout:com.google.accompanist.navigation.material.ModalBottomSheetLayout$\rightarrow$androidx.compose.material.navigation.ModalBottomSheetLayoutbottomSheet:com.google.accompanist.navigation.material.bottomSheet$\rightarrow$androidx.compose.material.navigation.bottomSheetrememberBottomSheetNavigator:com.google.accompanist.navigation.material.rememberBottomSheetNavigator$\rightarrow$androidx.compose.material.navigation.rememberBottomSheetNavigatorBottomSheetNavigator:com.google.accompanist.navigation.material.BottomSheetNavigator$\rightarrow$androidx.compose.material.navigation.BottomSheetNavigatorBottomSheetNavigatorSheetState:com.google.accompanist.navigation.material.BottomSheetNavigatorSheetState$\rightarrow$androidx.compose.material.navigation.BottomSheetNavigatorSheetState
- Replace the dependency: Change
Install Accompanist Permissions
mainTo use the Accompanist Permissions library in your Jetpack Compose project, add the following dependency to your
build.gradlefile. Ensure you havemavenCentral()in your repositories block.repositories { mavenCentral() } dependencies { implementation "com.google.accompanist:accompanist-permissions:<version>" }Use Android Drawables as Compose Painters with Drawable Painter
mainThe
accompanist-drawablepainterlibrary allows you to use standard Android drawables as Jetpack Compose Painters. It supports most drawable configurations and Animatable drawables, such asAnimatedVectorDrawable.@Composable fun DrawDrawable() { val drawable = AppCompatResources.getDrawable(LocalContext.current, R.drawable.rectangle) Image( painter = rememberDrawablePainter(drawable = drawable), contentDescription = "content description", ) }Match Accompanist version with Compose UI version
mainWhen using Accompanist, you must ensure the version of the library you select matches your project's Compose UI version. Upgrading Accompanist may upgrade your Compose libraries via transitive dependencies.
Compose UI Version Accompanist Version (approximate prefix) 1.0.x 0.20 1.1.x 0.23 1.2.x 0.25 1.3.x 0.28 1.4.x 0.30 1.5.x 0.32 1.6.x 0.34 1.7.x+ 0.37 Install Accompanist Drawable Painter
mainTo use Accompanist Drawable Painter in your project, add the following dependency to your
build.gradlefile. Ensure thatmavenCentral()is included in your repositories block.repositories { mavenCentral() } dependencies { implementation "com.google.accompanist:accompanist-drawablepainter:<version>" }Use a Snapshot Version of Accompanist
mainTo use the cutting-edge version of Accompanist (updated on every commit to
main), you must add the Sonatype OSSRH snapshot repository to yourrepositoriesblock and use the corresponding-SNAPSHOTdependency.Note that
x.x.x-SNAPSHOTversions depend on the latest tagged Jetpack Compose release.repositories { // ... maven { url 'https://oss.sonatype.org/content/repositories/snapshots' } } dependencies { // Check the latest SNAPSHOT version from the Sonatype repository classpath 'com.google.accompanist:accompanist-coil:XXX-SNAPSHOT' }Install the Accompanist Adaptive library
mainTo use adaptive utilities in your Jetpack Compose project, add the
accompanist-adaptivedependency to yourbuild.gradlefile. Ensure you havemavenCentral()in your repositories block.repositories { mavenCentral() } dependencies { implementation "com.google.accompanist:accompanist-adaptive:<version>" }Migrate from dev.chrisbanes.accompanist to com.google.accompanist
mainThe Accompanist project migrated from thedev.chrisbanes.accompanistpackage and Maven group ID tocom.google.accompanist. To update your project, you must refactor all code imports and update your Gradle dependencies to use the new package name and group ID.Add Accompanist WebView to your project
mainTo use the WebView wrapper, add the
accompanist-webviewdependency to yourbuild.gradlefile. EnsuremavenCentral()is included in your repositories.Note: This library is deprecated and the API is no longer maintained. It is recommended to fork the implementation and customize it for your needs.
repositories { mavenCentral() } dependencies { implementation "com.google.accompanist:accompanist-webview:<version>" }Install SystemUIController
mainTo use the System UI Controller in your project, add the dependency to your
build.gradlefile. EnsuremavenCentral()is included in your repositories.Note: Replace
<version>with the appropriate version for your project.repositories { mavenCentral() } dependencies { implementation "com.google.accompanist:accompanist-systemuicontroller:<version>" }