DEV Community

loading...
Cover image for Browsing Jetpack Compose samples

Browsing Jetpack Compose samples

Anton Shilov
Android dev exploring Jetpack Compose
・2 min read

Problem

While writing apps with Jetpack Compose you can always Cmd+Click on a library function to check their sources and comments. And often you can find a link to the sample code with an example of usages for that function. Unfortunately, sample code is not published together with the Jetpack Compose library so you cannot browse them.
Sample documentation

Jetpack Compose has two kinds of samples. The API samples - small examples of api usages, and sample apps repo on github. In this post we're talking about API samples.

Easy Solution

All Jetpack Compose sources are open and published as a part of the AndroidX repo. We can quickly find sample code using Android Code Search website.

code-search

  1. Copy sample name from the sources
  2. Open https://cs.android.com in the browser
  3. Search for the sample code

Better solution

Keeping a browser tab open and manually copying function name is quite a hassle. We can do better, we can automate it! And CodeSearch plugin can help us with that. It allows us to launch search queries right from the IDE, and we can add a custom search engine.

  1. Install Code Search plugin https://plugins.jetbrains.com/plugin/12578-codesearch
  2. Add Android Code Search engine to plugin settings(IDE restart required).
    Name: Android CS
    Url: https://cs.android.com/search?q=lang:kotlin usage:
    Search settings

  3. Select the sample name and search for it
    Plugin usage

Hope you found this post useful 😄. You can follow me to get the latest news about Compose.

Discussion (0)