Questions tagged [android-jetpack-compose-preview]

Compose tooling

Android Studio brings a lot of new features specifically for Jetpack Compose. It embraces a code-first approach while improving the developer productivity without having to choose between design interface or code editor only.

To enable a preview of a composable, you need to create another composable, annotated with @Composable and @Preview, emitting the composable you’ve created initially:

https://developer.android.com/jetpack/compose/tooling#preview-features

34 questions
3
votes
1 answer

Jetpack Compose Preview failing with LocalDate.now() from ThreeTen

Rendering the Jetpack Compose Preview fails when we have some code calling LocalDate.now() from it. We have tried setting a locale on the preview but that does not help, and we have not found any other way to set context information on the…
3
votes
1 answer

Jetpack Compose - The preview does not render in real-time

I use Compose with AS Arctic Fox v2020.3.1. When I update the code, the preview does not render in real-time. AS show the message "The preview is out of date" and I must click "Build & Refresh". I'd like it to render UI in real-time, similar to XML…
2
votes
0 answers

Vector Drawables in Compose Preview

Simple scenario, I have a vector drawable in my res folder, which I wish to access in a Compose Preview. Actually, it is a Canvas that draws the vector, and so, I use a painter (a vector painter, to be precise). This is the method used @Preview …
2
votes
1 answer

Jetpack Compose Preview fails in Multi Module app

I have a multi module app where I recently began implementing Jetpack Compose. I defined some composables to be shared by different modules. I put those in another library module and imported in relevant places. Example composable: // Nothing…
2
votes
0 answers

how i can mock view model to use compose preview?

I have a MainScreen composable being injected with a viewmModel using hilt. @Composable fun MainScreen( viewModel: MainScreenViewModel = hiltViewModel() ) {} The problem is that I cannot use this in the preview because will not generate…
2
votes
2 answers

Jetpack Compose - About Preview widthDp and heightDp

What are widthDp and heightDp as a @Preview parameter? 【My environment】 Android Studio Arctic Fox | 2020.3.1 Patch3 build on October 1, 2021 Gradle: 7.0.2 AGP: 7.0.3 androidx.compose.ui:ui-tooling-preview:1.0.1 Here is my code. @Preview( …
2
votes
1 answer

Can You Expand a DropdownMenu in the Jetpack Compose Preview?

I have the following composable function that creates a TopAppBar. The preview shows the bar just fine, but can I get the menu to expand in the preview as well? @Composable @Preview fun AppBarTop(refreshOnClickHandler: (() -> Unit)? = null) { …
1
vote
1 answer

Preview of an AlertDialog doesn't work in Jetpack Compose

Problem description I'm trying to see a preview of my AlertDialog in compose but I'm not getting it, the preview doesn't render it even though it doesn't show any error. I'm sure the problem is only with this composable function because I can see…
1
vote
1 answer

Why does Android Studio Kotlin Compose Template display text wrong when app is run?

I built an app from the Android Studio template using the new Compose feature (official docs). The Preview looks like the following: However, when I run the application, it looks like this (text is much smaller & is not centered in the View): Is…
1
vote
1 answer

Jetpack Compose nested theming preview

Let's consider the following @Composable functions: @Composable fun WelcomeScreen() { ... ButtonTheme { Button(...) {...} } } @Composable @Preview fun MockWelcome() { AppTheme { WelcomeScreen { } …
0
votes
1 answer

how to using a injected variable in compose preview

I have a fragment which has an injected variable timeZoneId, which now I have to pass to a composable. @Inject lateinit var timeZoneId: ZoneId In Composable I have a preview, how can I add this to the preview as a parameter please. @Composable fun…
0
votes
0 answers

Passing Application object to class in a compose preview function

I have the following preview function: @Preview( name = "Light Mode", ) @Composable fun LM_HomePageSecondaryBarPreview() { val viewModel = HomePageViewModel( projectRepository =…
0
votes
1 answer

Jetpack Compose preview ClassNotFoundException when class is defined in java module

My app has a module that uses Jetpack Compose and another non-Android (plain Java Library) module with some Java classes. I ran into an issue where Jetpack Compose preview is failing with a render error if I use a class defined in a plain…
0
votes
2 answers

Using jetpack compose landscapist library, will the previewPlaceholder image get bundled into my apk (increasing app size)

During android jetpack compose development I use this code to see some preview result: GlideImage( imageModel = { imageUrl }, modifier = Modifier.aspectRatio(0.8f), previewPlaceholder = R.drawable.poster ) Let's say that the poster preview…
0
votes
1 answer

Creating a Preview for a Composable that takes Google Billing API information such as a `ProductDetail`

Consider a Composable screen with the following parameters: @Composable fun PurchaseSubscriptionScreenContent( availableSubscriptions: List, selectedSubscription: ProductDetails, isLoading: Boolean, onPurchaseClicked:…