Accompanist

repository·main·Indexed 27 days ago

https://github.com/google/accompanist

A 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.

Tokens
9.2K
Snippets
25
Records
43
Agent score
85%

What's inside Accompanist

  1. Overview of Accompanist libraries

    main
    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.
  2. Available Accompanist libraries

    main

    The 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.
  3. Migrate from Accompanist Navigation Material to androidx.compose.material.navigation

    main

    The Accompanist Navigation Material library is deprecated. All functionality has been moved to the official androidx.compose.material.navigation library (available in androidx.compose.material version 1.7.0-alpha04 and later).

    To migrate:

    1. Replace the dependency: Change com.google.accompanist:accompanist-navigation-material:<version> to androidx.compose.material:material-navigation:<version>.
    2. 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.ModalBottomSheetLayout
      • bottomSheet: com.google.accompanist.navigation.material.bottomSheet $\rightarrow$ androidx.compose.material.navigation.bottomSheet
      • rememberBottomSheetNavigator: com.google.accompanist.navigation.material.rememberBottomSheetNavigator $\rightarrow$ androidx.compose.material.navigation.rememberBottomSheetNavigator
      • BottomSheetNavigator: com.google.accompanist.navigation.material.BottomSheetNavigator $\rightarrow$ androidx.compose.material.navigation.BottomSheetNavigator
      • BottomSheetNavigatorSheetState: com.google.accompanist.navigation.material.BottomSheetNavigatorSheetState $\rightarrow$ androidx.compose.material.navigation.BottomSheetNavigatorSheetState
  4. Install Accompanist Permissions

    main

    To use the Accompanist Permissions library in your Jetpack Compose project, add the following dependency to your build.gradle file. Ensure you have mavenCentral() in your repositories block.

    repositories {
        mavenCentral()
    }
    
    dependencies {
        implementation "com.google.accompanist:accompanist-permissions:<version>"
    }
  5. Use Android Drawables as Compose Painters with Drawable Painter

    main

    The accompanist-drawablepainter library allows you to use standard Android drawables as Jetpack Compose Painters. It supports most drawable configurations and Animatable drawables, such as AnimatedVectorDrawable.

    @Composable
    fun DrawDrawable() {
        val drawable = AppCompatResources.getDrawable(LocalContext.current, R.drawable.rectangle)
    
        Image(
            painter = rememberDrawablePainter(drawable = drawable),
            contentDescription = "content description",
        )
    }
  6. Match Accompanist version with Compose UI version

    main

    When 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 VersionAccompanist Version (approximate prefix)
    1.0.x0.20
    1.1.x0.23
    1.2.x0.25
    1.3.x0.28
    1.4.x0.30
    1.5.x0.32
    1.6.x0.34
    1.7.x+0.37
  7. Install Accompanist Drawable Painter

    main

    To use Accompanist Drawable Painter in your project, add the following dependency to your build.gradle file. Ensure that mavenCentral() is included in your repositories block.

    repositories {
        mavenCentral()
    }
    
    dependencies {
        implementation "com.google.accompanist:accompanist-drawablepainter:<version>"
    }
  8. Use a Snapshot Version of Accompanist

    main

    To use the cutting-edge version of Accompanist (updated on every commit to main), you must add the Sonatype OSSRH snapshot repository to your repositories block and use the corresponding -SNAPSHOT dependency.

    Note that x.x.x-SNAPSHOT versions 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'
    }
  9. Install the Accompanist Adaptive library

    main

    To use adaptive utilities in your Jetpack Compose project, add the accompanist-adaptive dependency to your build.gradle file. Ensure you have mavenCentral() in your repositories block.

    repositories {
        mavenCentral()
    }
    
    dependencies {
        implementation "com.google.accompanist:accompanist-adaptive:<version>"
    }
  10. Migrate from dev.chrisbanes.accompanist to com.google.accompanist

    main
    The Accompanist project migrated from the dev.chrisbanes.accompanist package and Maven group ID to com.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.
  11. Add Accompanist WebView to your project

    main

    To use the WebView wrapper, add the accompanist-webview dependency to your build.gradle file. Ensure mavenCentral() 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>"
    }
  12. Install SystemUIController

    main

    To use the System UI Controller in your project, add the dependency to your build.gradle file. Ensure mavenCentral() 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>"
    }