43 questions
4
votes
1
answer
71
views
How to disable Jetpack Compose preview functions for code search in Android Studio
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 ...
1
vote
1
answer
246
views
Why doesn’t Jetpack Compose preview show padding bounds when hovering over Text composable?
I'm learning Jetpack Compose and working with Android Studio's preview feature. When I hover over a Text composable that has padding applied, the layout bounds (blue outline) only show the text ...
5
votes
1
answer
312
views
Android Studio always opens up Compose Preview pane no matter what kind of Kotlin file gets created
Recently, I stumbled upon what seems to be a strange glitch in Android Studio. No matter what kind of Kotlin file I create (object, interface, class—anything), the IDE always opens it as if it ...
0
votes
0
answers
24
views
Compose preview - Font distorted
I am using a Google font. I downloaded the ttf files and properly set the FontFamily and Typography. Preview are correctly showing the fonts, but they are distorted. They seem pixelated. My goal is to ...
7
votes
1
answer
686
views
Android Compose Preview Screenshot Testing on alpha02 and higher not working
I have followed https://developer.android.com/studio/preview/compose-screenshot-testing and can't seem to get any version outside of 0.0.1-alpha01 to work.
With alpha02 and higher I am seeing:
An ...
5
votes
0
answers
718
views
Android Compose Preview Screenshot Testing Fails due to Could not load font
I just started exploring android compose preview screenshot testing.
In my first attempting running the tests via ./gradlew updateDebugScreenshotTest I got the following error
Cannot update reference ...
0
votes
1
answer
525
views
Multi-module Jetpack Compose UI Previews
I have the issue that whenever I have a multi-module project, all Jetpack Compose UI previews except for the ones in the app module display an additional TopAppBar with the text androidx.compose.ui....
0
votes
1
answer
521
views
Jetpack compose WindowsInsets does not apply on Preview
Using WindowsInsets(android tutorial) in app with jetpack compose, doesn't show on @Preview.
Here my Modifier.windowInsetsPadding(WindowInsets.safeContent) does not apply as Preview.
If I replace ...
2
votes
0
answers
398
views
How to alter the default background color of composable preview without altering android:windowBackground
I'm currently improving previews in my android app (which is using mostly jetpack compose).
When i only use @Preview(showBackground=true) the background color of the preview defaults to almost-black, ...
1
vote
0
answers
143
views
StackOverflowError when using Jetpack Compose @Preview in Android project
I'm facing an issue when trying to use the Jetpack Compose @Preview annotation in my Android project. Whenever I try to preview a Composable function, I encounter a java.lang.StackOverflowError.
Here ...
4
votes
1
answer
2k
views
Jetpack Compose Preview background color is different from theme background color
I'm just learnig Compose. I want to make Compose Preview background color setting the same as run app mode. What is wrong with my code?
Preview code
@Preview(showBackground = true)
@Composable
fun ...
1
vote
1
answer
468
views
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 ...
7
votes
2
answers
3k
views
Preview java.lang.NoSuchMethodError: androidx.compose.foundation.layout.SizeKt.fillMaxWidth$default
I started migrate our code to Compose and have problem with @Preview.
For example, when I use modifier.fillMaxWidth() without default param "fraction = 1f" I have render problem
java.lang....
1
vote
1
answer
1k
views
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 ...
0
votes
2
answers
319
views
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....
0
votes
1
answer
94
views
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<ProductDetails>,
selectedSubscription: ...
9
votes
1
answer
4k
views
Why does Jetpack Compose preview show the wrong string resources?
Sometimes when I use a string resource in my composable, the preview will show the wrong string. It always works fine for literal strings, only string resources are wrong. The bug isn't consistent.
...
11
votes
3
answers
5k
views
Jetpack Compose Preview is not showing when having a ViewModel parameter
I am using Jetpack Compose and noticed that the preview is not shown. I read articles like this, but it seems my problem has a different root cause. Even I added defaults to all parameters in the ...
4
votes
1
answer
968
views
Can we or should use Preview compose function for main widget as well?
Like below are two functions
@Composable
private fun WaterCounter(modifier: Modifier = Modifier) {
val count = 0
Text(
text = "You've had $count glasses of water",
...
1
vote
1
answer
1k
views
Passing a click action for preview in android jetpack compose
What I have :
I have a compose class that has a button
I want to see the preview in the design view
Issue I am facing :
For the click How to pass as an object on the line I have marked in
code
Is ...
10
votes
1
answer
4k
views
how to make Compose Preview display image/vector resources loaded from web?
I use Coil to load .svg resources from the web, for example:
@Composable
fun Widget(modifier: Modifier = Modifier) {
AsyncImage(
modifier = Modifier.fillMaxSize(),
model = ...
19
votes
5
answers
10k
views
Jetpack Compose Preview not working when using Koin for Dependency Injection
I want to use Jetpack Compose in my App. I am already using Koin for DI. Because I have a lot of convenience methods in my BaseFragment I want to inherit from it and build the corresponding view with ...
8
votes
5
answers
13k
views
Jetpack Compose Preview Render Problem when casting LocalContext.current
Android Studio Chipmunk 2021.2.1;
Compose Version = '1.1.1';
Gradle Version 7.4.2;
Kotlin 1.6.10;
Up to one point, everything was working. Then this error appeared and the preview stopped working ...
4
votes
1
answer
1k
views
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 ...
39
votes
2
answers
13k
views
Can no longer view Jetpack Compose Previews. Failed to instantiate one or more classes (ComposeViewAdapter)
I've recently got an error preventing any Jetpack Compose previews from being displayed as follows:
Failed to instantiate one or more classes
The following classes could not be instantiated:
-...
2
votes
1
answer
4k
views
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 ...
7
votes
3
answers
8k
views
Jetpack Compose Previews: No Backgrounds, No System UI
I am bootstrapping a new app with Jetpack Compose and Material 3. I've created a bunch of new apps lately with this configuration, so this problem has me stuck: I cannot get the IDE's compose previews ...
1
vote
1
answer
1k
views
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 ...
1
vote
1
answer
247
views
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 ...
2
votes
0
answers
99
views
how i can mock view model to use compose preview? [duplicate]
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 ...
3
votes
3
answers
5k
views
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-...
0
votes
2
answers
6k
views
Blur Modifier in Jetpack Compose Doesn't Work in Preview
I'm trying to use the Modifier.blur feature of Jetpack Compose for a project for work and it seems to not do anything in the preview. I'm using it like this:
Column(modifier = Modifier
.blur(30.dp)...
13
votes
2
answers
4k
views
Jetpack Compose State Hoisting, Previews, and ViewModels best practices
So it seems like the recommended thing in Jetpack Compose is to hoist state out of your composables, to make them stateless, reusable, and testable, and allow using them in previews easily.
So instead ...
7
votes
1
answer
2k
views
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 ...
21
votes
6
answers
4k
views
Jetpack Compose preview stopped working in Arctic Fox with Patch 1
With the first patch for AS Arctic Fox Jetpack Compose previews stopped working.
I'm getting this error for all previews - even older ones, which worked fine a while back:
android.content.res....
14
votes
3
answers
3k
views
Analog of isInEditMode for @Preview in JetpackCompose
I am developing an app using Jetpack compose and have a problem with fonts import during Jetpack preview. Preview is empty and show an error (Render problem):
Font resource ID #0x... cannot be ...
3
votes
2
answers
2k
views
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(...
19
votes
1
answer
3k
views
Reuse a single set of preview annotations in Jetpack Compose across composable functions
Taking first steps in Jetpack Compose, which is quite amazing except one annoying issue.
I have a constant set of previews: Normal, Dark and RTL:
@Preview(
name = "Normal",
group = &...
5
votes
1
answer
3k
views
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 &...
13
votes
5
answers
11k
views
Studio BumbleBee "Render Problem" For Compose Preview
I am unable to preview anything in Studio, extending to something as simple as a Text. I get a "Render Error", revealing this stack trace.
java.lang.NoSuchMethodException: com.<...
28
votes
4
answers
15k
views
How to preview Compose layouts in landscape mode
I'm using Android Studio Bumblebee 2021.1.1 Canary 3 + Compose 1.0-rc02, and there seems to be no easy way to force landscape mode for a preview, which includes using resources (in particular ...
1
vote
1
answer
6k
views
Jetpack Compose nested theming preview
Let's consider the following @Composable functions:
@Composable
fun WelcomeScreen() {
...
ButtonTheme {
Button(...) {...}
}
}
@Composable
@Preview
fun MockWelcome() {
AppTheme ...
68
votes
8
answers
31k
views
ViewModels creation is not supported in Preview
I followed the official guide to create viewModel instance and it works perfectly. However, when there is any viewModel in the @composable, Android Studio isn't able to render the preview and with the ...