1 /*
2  * Copyright 2020 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package androidx.compose.ui.tooling.preview
18 
19 import kotlin.jvm.JvmDefaultWithCompatibility
20 import kotlin.reflect.KClass
21 
22 /**
23  * Interface to be implemented by any provider of values that you want to be injected as @[Preview]
24  * parameters. This allows providing sample information for previews.
25  */
26 @JvmDefaultWithCompatibility
27 interface PreviewParameterProvider<T> {
28     /** [Sequence] of values of type [T] to be passed as @[Preview] parameter. */
29     val values: Sequence<T>
30 
31     /** Returns the number of elements in the [values] [Sequence]. */
32     val count
33         get() = values.count()
34 }
35 
36 /**
37  * [PreviewParameter] can be applied to any parameter of a @[Preview].
38  *
39  * @param provider A [PreviewParameterProvider] class to use to inject values to the annotated
40  *   parameter.
41  * @param limit Max number of values from [provider] to inject to this parameter.
42  */
43 annotation class PreviewParameter(
44     val provider: KClass<out PreviewParameterProvider<*>>,
45     val limit: Int = Int.MAX_VALUE
46 )
47