-
Notifications
You must be signed in to change notification settings - Fork 1.3k
KMT-879: Make org.jetbrains.compose.ui.tooling.preview.PreviewParameterProvider
an actual implementation of androidx.compose.ui.tooling.preview.PreviewParameterProvider
on Android
#5319
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…terProvider` an actual implementation of `androidx.compose.ui.tooling.preview.PreviewParameterProvider` on Android. This is required for the preview parameters to be correctly picked up by the preview adapter in IDE, which expects the provider to be a subclass of the AndroidX's interface, and fails with the ClassCaseException otherwise.
.../src/desktopMain/kotlin/org/jetbrains/compose/ui/tooling/preview/PreviewParameter.desktop.kt
Outdated
Show resolved
Hide resolved
components/gradle/libs.versions.toml
Outdated
@@ -4,6 +4,7 @@ androidx-appcompat = "1.6.1" | |||
androidx-activity-compose = "1.8.2" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Highlights - Android
- It looks not major feature. Maybe even it is a bugfix, as it is available, but doesn't work?
- It is not only for Android, I assume (as it available in common)
So, please change it to "Fixes - Multiple Platforms" or to "Features - Multiple Platforms" if it isn't a bugfix.
org.jetbrains.compose.ui.tooling.preview.PreviewParameterProvider becomes an alias to androidx.compose.ui.tooling.preview.PreviewParameterProvider on Android.
This describes the change from implementation details perspective, but it should describe the change from user perspective. What is changed for them? org.jetbrains.compose.ui.tooling.preview.PreviewParameterProvider
now works in IntelliJ IDEs?
Could you also add a code snippet to the release notes on how to use it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the release notes, please take a look if that works better now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I rewrote it more, please check
@@ -52,3 +52,7 @@ configureMavenPublication( | |||
name = "Experimental Compose Multiplatform tooling library API. This library provides the API required to declare " + | |||
"@Preview composables in user apps." | |||
) | |||
|
|||
dependencies { | |||
compileOnly(libs.androidx.ui.tooling.preview.android) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't this mean, that this will crash:
class SampleUserProvider: PreviewParameterProvider<User> {
override val values = sequenceOf(User("Jens",31),User("Jim",44))
}
If users don't include it explicitly?
If so, we have to fix it. The common preview ideally should require including only it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will crash regardless. Rendering previews in Android requires ui-tooling-preview
from AndroidX to be on the classpath. However, I agree that changing it to implementation
might require the user to have fewer dependencies. On the other hand, what would happen if there is a conflict between the user project's version of the ui-tooling-preview
and this one? I assume a compileOnly
dependency here might be a more reliable approach from this perspective.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to implementation, as we discussed in DMs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems the implementation
doesn't work for the expect
way if there is no Android preview in the classpath:
.
Let's change it to api
:
api(libs.androidx.ui.tooling.preview.android)
It adds another issue for the common preview - it exposes 2 API for previews in androidMain
(2 Preview annotations and 2 PreviewParameter classes). But current users already see 2 APIs as there is no way to enable Preview other than including debugImplementation(compose.uiTooling)
If anything goes wrong, we can revert it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MatkovIvan, as it is new "API", please review it as well
.../src/androidMain/kotlin/org/jetbrains/compose/ui/tooling/preview/PreviewParameter.android.kt
Outdated
Show resolved
Hide resolved
...w/library/src/commonMain/kotlin/org/jetbrains/compose/ui/tooling/preview/PreviewParameter.kt
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR!
…wParameterProvider` an actual implementation of `androidx.compose.ui.tooling.preview.PreviewParameterProvider` on Android.
...rary/src/appleMain/kotlin/org/jetbrains/compose/ui/tooling/preview/PreviewParameter.apple.kt
Outdated
Show resolved
Hide resolved
…wParameterProvider` an actual implementation of `androidx.compose.ui.tooling.preview.PreviewParameterProvider` on Android.
...w/library/src/commonMain/kotlin/org/jetbrains/compose/ui/tooling/preview/PreviewParameter.kt
Show resolved
Hide resolved
…wParameterProvider` an actual implementation of `androidx.compose.ui.tooling.preview.PreviewParameterProvider` on Android.
LGTM after the change |
…wParameterProvider` an actual implementation of `androidx.compose.ui.tooling.preview.PreviewParameterProvider` on Android.
…wParameterProvider` an actual implementation of `androidx.compose.ui.tooling.preview.PreviewParameterProvider` on Android.
…terProvider` an actual implementation of `androidx.compose.ui.tooling.preview.PreviewParameterProvider` on Android (#5319) This is required for the preview parameters to be correctly picked up by the preview adapter in IDE, which expects the provider to be a subclass of AndroidX's interface, and fails with the `ClassCastException` otherwise. ## Release Notes ### Fixes - Multiple Platforms - Support Preview parameters for Previews in common source sets in IJ and AS. Note: IDEs also need to implement support on their end. Please check the respective IDE release notes to confirm this is supported. Example usage: ``` import androidx.compose.runtime.Composable import org.jetbrains.compose.ui.tooling.preview.Preview import org.jetbrains.compose.ui.tooling.preview.PreviewParameter import org.jetbrains.compose.ui.tooling.preview.PreviewParameterProvider class MyPreviewParameterProvider : PreviewParameterProvider<String> { override val values = sequenceOf("Hello, Compose!", "Hello, World!") } /** * This function will generate two preview images with different texts. */ @Preview @composable fun MyPreview(@PreviewParameter(MyPreviewParameterProvider::class) text: String) { Text(text) } ```
…terProvider` an actual implementation of `androidx.compose.ui.tooling.preview.PreviewParameterProvider` on Android (#5319) (#5323) This is required for the preview parameters to be correctly picked up by the preview adapter in IDE, which expects the provider to be a subclass of AndroidX's interface, and fails with the `ClassCastException` otherwise. ## Release Notes ### Fixes - Multiple Platforms - Support Preview parameters for Previews in common source sets in IJ and AS. Note: IDEs also need to implement support on their end. Please check the respective IDE release notes to confirm this is supported. Example usage: ``` import androidx.compose.runtime.Composable import org.jetbrains.compose.ui.tooling.preview.Preview import org.jetbrains.compose.ui.tooling.preview.PreviewParameter import org.jetbrains.compose.ui.tooling.preview.PreviewParameterProvider class MyPreviewParameterProvider : PreviewParameterProvider<String> { override val values = sequenceOf("Hello, Compose!", "Hello, World!") } /** * This function will generate two preview images with different texts. */ @Preview @composable fun MyPreview(@PreviewParameter(MyPreviewParameterProvider::class) text: String) { Text(text) } ``` Describe proposed changes and the issue being fixed (Optional) Fixes https://youtrack.jetbrains.com/issue/CMP-8220 ## Testing Once https://youtrack.jetbrains.com/issue/KMT-879 is merged in IJ, this change can be tested on Nightly Builds (ETA tomorrow)
Fixes https://youtrack.jetbrains.com/issue/CMP-8220
This is required for the preview parameters to be correctly picked up by the preview adapter in IDE, which expects the provider to be a subclass of AndroidX's interface, and fails with the
ClassCastException
otherwise.Release Notes
Fixes - Multiple Platforms
Example usage: