Skip to content

KMT-879: Make org.jetbrains.compose.ui.tooling.preview.PreviewParameterProvider an actual implementation of androidx.compose.ui.tooling.preview.PreviewParameterProvider on Android (#5319) #5323

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

Merged
merged 1 commit into from
May 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion components/ui-tooling-preview/library/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl

plugins {
Expand Down Expand Up @@ -31,6 +30,32 @@ kotlin {
}
macosX64()
macosArm64()

applyDefaultHierarchyTemplate()

sourceSets {
val commonMain by getting

androidMain.dependencies {
api(libs.androidx.ui.tooling.preview)
}

val nonAndroidMain by creating {
dependsOn(commonMain)
}

val appleMain by getting
appleMain.dependsOn(nonAndroidMain)

val desktopMain by getting
desktopMain.dependsOn(nonAndroidMain)

val jsMain by getting
jsMain.dependsOn(nonAndroidMain)

val wasmJsMain by getting
wasmJsMain.dependsOn(nonAndroidMain)
}
}

android {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.jetbrains.compose.ui.tooling.preview

/**
* Interface to be implemented by any provider of values that you want to be injected as @[Preview]
* parameters. This allows providing sample information for previews.
*/
actual typealias PreviewParameterProvider<T> = androidx.compose.ui.tooling.preview.PreviewParameterProvider<T>
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import kotlin.reflect.KClass
* Interface to be implemented by any provider of values that you want to be injected as @[Preview]
* parameters. This allows providing sample information for previews.
*/
interface PreviewParameterProvider<T> {
expect interface PreviewParameterProvider<T> {
/**
* [Sequence] of values of type [T] to be passed as @[Preview] parameter.
*/
Expand All @@ -31,7 +31,7 @@ interface PreviewParameterProvider<T> {
/**
* Returns the number of elements in the [values] [Sequence].
*/
val count get() = values.count()
open val count: Int
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.jetbrains.compose.ui.tooling.preview

/**
* Interface to be implemented by any provider of values that you want to be injected as @[Preview]
* parameters. This allows providing sample information for previews.
*/
actual interface PreviewParameterProvider<T> {
/**
* [Sequence] of values of type [T] to be passed as @[Preview] parameter.
*/
actual val values: Sequence<T>

/**
* Returns the number of elements in the [values] [Sequence].
*/
actual val count: Int
get() = values.count()
}