4

I’m using Android Studio with Jetpack Compose, and I often use the “Find in Files” feature (Cmd + Shift + F / Ctrl + Shift + F / clicking in a function/class to see the usages) to search for code references. However, all the @Preview composable functions show up in the search results, which makes it harder to locate the real usages of a composable within the app code.

For example, if I search for a composable name like LoginScreen, I get dozens of preview hits like this:

@Preview
@Composable
fun PreviewLoginScreen() {
    LoginScreen()
}

These previews are only for design visualization and not actual code references.

Is there a way to exclude or disable Compose preview functions from showing up in code search results (e.g., by adjusting indexing, search filters, or naming conventions) inside Android Studio? Ideally, I’d like to keep previews functional for design, but not pollute my search results when looking for real usages in production code.

0

1 Answer 1

-1

Your previews can be private.

@Preview
@Composable
private fun PreviewLoginScreen() {
    LoginScreen()
}

this also allow you to have the same Preview name in multiple files within the same package.

NOTE: they'll still show up in "usage" or "calls" of your "LoginScreen" for example, but they shouldn't autocomplete

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.