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
37
votes
2 answers

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: -androidx.compose.ui.tooling.ComposeViewAdapter(Open…
18
votes
4 answers

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.Resources$NotFoundException: Could not resolve resource…
17
votes
2 answers

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 dimensions) from -land/ resource folders. I know that…
machfour
  • 1,929
  • 2
  • 14
  • 21
16
votes
1 answer

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 = "Screen", showBackground = true ) @Preview( name =…
12
votes
2 answers

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 of having something like @Composable fun…
10
votes
2 answers

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 retrieved In custom view for example we have…
9
votes
2 answers

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 compose. Now the Problem is that when using DI in…
9
votes
3 answers

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..Navigation_ComponentsKt. at…
6
votes
3 answers

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 compose function like…
6
votes
5 answers

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 when I try to call "LocalContext.current" and…
5
votes
0 answers

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. For example if I have this…
5
votes
1 answer

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 = ImageRequest.Builder(LocalContext.current) …
4
votes
0 answers

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.NoSuchMethodError: 'androidx.compose.ui.Modifier…
4
votes
1 answer

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", modifier = modifier.padding(all = 16.dp) …
3
votes
2 answers

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 to show a background or system UI. The compiled…
1
2 3