Comments (7)
I somehow completely missed noticing this issue! Thanks for reporting it, I'm going to take a look!
from showkase.
@peterfortuin I think this might be related to the difference between the compose versions used in the library and the one you are using. Can you try using the alpha02
version of Jetpack Compose and giving it a shot?
I recently just bumped up the library to the latest version - #112. I'll be doing a release in the next couple days so you should be able to use the latest library version soon. In the meanwhile, I'm curious to see if it works fine when you use Jetpack Compose v 1.0.0-alpha02
from showkase.
@peterfortuin Can you try the latest release of this library. I believe that will certainly fix your problem!
implementation "com.airbnb.android:showkase:1.0.0-alpha03"
kapt "com.airbnb.android:showkase-processor:1.0.0-alpha03"
from showkase.
If I downgrade to compose 1.0.0-alpha02 I have another problem. Maybe not related to this. I'm not sure if I can upgrade to the latest version of compose. Have to check.
To be continued.
from showkase.
@peterfortuin You don't need to downgrade anymore! You can use the latest version of compose as this library has been upgraded!
from showkase.
I have included showkase:1.0.0-alpha03
into my project with compose:1.0.0-alpha04
and that seems to work.
But now that I have it working, I'm not sure how useful it is for me.
Some things that I noticed:
- The Components part directly crashes for me, because I use ViewModels on a lot of places inside @composable functions and those ViewModels have constructor parameters. Of course Showkase doesn't know what to do with those parameters of course.
This is not only a problem with Showkase, but this is a general problem I have with the @Preview annotation of Compose. - Currently I have the colors of my application as Color Resources in xml and read them with colorResource function into my Theme and other places. As far I can see from the documentation I have to add the colors again to show up in Showkaze. But I prefer not to write down the colors in two places. (Changes are big that they will not match any more after some changes in the future). Is there no way to read them from the resources like this?
@ShowkaseColor(name = "Primary Color", group = "Material Design")
val primaryColor = colorResource(R.color.colorPrimary)
- Same problem for the typography. I create those inside my AppTheme @composable function. I copy them from the MaterialTheme and change some values. I can't do that outside of the function and annotate that.
I hope you can do something with my feedback or maybe tell me how I can structure my application differently to be more compatible with Showkase.
from showkase.
Hey @peterfortuin,
I'm glad the original issue that you reported is fixed now. I can try to address some of the points you raised -
- Showkase (and Jetpack Compose) does have a way to provide parameters for preview. It does so using the
@PreviewParameter
annotation. I recently added support for it but I still have another PR to go, hence I have not mentioned it in the README just yet. This is how you can use it to provide parameters and use view models with Showkase. I'm not sure if@Preview
in Android Studio allows using ViewModel, but Showkase certainly does! Here is what it would roughly look like in practice.
data class ViewModelParameters(
val param1: String,
val param2: Int
)
@ShowkaseComposable("Component with ViewModel")
@Composable
fun test(
@PreviewParameter(provider = CustomPreviewProvider::class) viewModelParameters: ViewModelParameters
) {
val factory = MyViewModelFactory(viewModelParameters.param1, viewModelParameters.param2)
val viewModel: MyViewModel = viewModel(factory = factory)
Text(viewModel.param1)
}
class MyViewModel(
val param1: String,
val param2: Int
): ViewModel() {}
class MyViewModelFactory(
val param1: String,
val param2: Int
): ViewModelProvider.Factory {
override fun <T : ViewModel?> create(modelClass: Class<T>): T {
if (modelClass.isAssignableFrom(MyViewModel::class.java)) {
return MyViewModel(param1, param2) as T
}
throw IllegalArgumentException("Model class ${modelClass.name} not valid")
}
}
class CustomPreviewProvider: PreviewParameterProvider<ViewModelParameters> {
override val values: Sequence<ViewModelParameters>
get() = sequenceOf(
ViewModelParameters(param1 = "Param1", param2 = 5)
)
}
- This is a reasonable request but there is no easy way to solve this as
colorResource
can only be used in the scope of a Composable function and the code that is generated doesn't have @composable scope. I can think of a few approaches to potentially support this but it's going to be a good amount of work. I might give this a shot at some point.
I'll close this ticket for now since the original problem is fixed but I'll create a separate issue (2) as a feature request. Tracking it here - #115
from showkase.
Related Issues (20)
- Is that possible to download an image from url? HOT 2
- Showkase silently ignores duplicate ShowkaseComposables
- IllegalStateException on ShowkaseMultiPreviewCodegenMetadata HOT 6
- When using Showkase version 1.01 or 1.0.2 I get this error "error: cannot find symbol - import androidx.room.util.RelationUtil; " HOT 1
- old account label bypassing all fraud measures HOT 1
- Multi module: same package name leads to silently ignoring previews
- Class file has wrong version 61.0, should be 55.0 HOT 1
- Showkase ignoring the Locale parameter for @Preview
- Feature Request: Compose Multiplatform Support HOT 4
- Fatal Exception: java.lang.RuntimeException: Unable to start activity ShowkaseBrowserActivity HOT 12
- Any plans to add support for other compose multiplatform targets like ios and desktop? HOT 2
- Feature request: Add support for K2 compiler.
- Root module codegen preventing incremental compilation for KSP HOT 3
- Remote Image Not Displaying in Showcase Using Coil's AsyncImage HOT 1
- Impossible to use `@ShowkaseColor` or `@ShowkaseTypography` on objects' fields that have a constructor with no parameters
- showkaseName for composable is unstable when referencing custom multipreview annotation from another module HOT 1
- Qualified night/dark assets not being picked up in @Preview snapshot tests
- Multi-module project - @ShowkaseRoot per module causes tests to have @Previews from dependent modules
- Generic/Custom Showkase Annotation
- Compose 1.4.2+ support
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from showkase.