Skip to content
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

CMP-1108: Deprecate resources in compose.ui in favour of the new resource library #1457

Merged
merged 9 commits into from
Sep 4, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import org.jetbrains.skia.svg.SVGPreserveAspectRatioAlign
* will be drawn with the specified size, density will have no effect.
* @return the decoded SVG image associated with the resource
*/
@Deprecated("Migrate to the Compose resources library. See https://www.jetbrains.com/help/kotlin-multiplatform-dev/compose-images-resources.html")
fun loadSvgPainter(
inputStream: InputStream,
density: Density
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import org.xml.sax.InputSource
* will be drawn with the specified size, density will have no effect.
* @return the decoded vector image associated with the image
*/
@Deprecated("Migrate to the Compose resources library. See https://www.jetbrains.com/help/kotlin-multiplatform-dev/compose-images-resources.html")
fun loadXmlImageVector(
inputSource: InputSource,
density: Density
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ import org.jetbrains.skia.Image
* stream, but stream will not be closed after this method.
* @return the decoded SVG image associated with the resource
*/
@Deprecated("Migrate to the Compose resources library. See https://www.jetbrains.com/help/kotlin-multiplatform-dev/compose-images-resources.html")
fun loadImageBitmap(inputStream: InputStream): ImageBitmap =
Image.makeFromEncoded(inputStream.readAllBytes()).toComposeImageBitmap()
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import org.xml.sax.InputSource
* @param loader resources loader
* @return [Painter] used for drawing the loaded resource
*/
@OptIn(ExperimentalComposeUiApi::class)
@Deprecated("Migrate to the Compose resources library. See https://www.jetbrains.com/help/kotlin-multiplatform-dev/compose-images-resources.html")
@Composable
fun painterResource(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides painterResource, we need to deprecate in another PR:

fun Font(
    resource: String,
    weight: FontWeight = FontWeight.Normal,
    style: FontStyle = FontStyle.Normal
): Font = ResourceFont(resource, weight, style)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@terrakok, we need to do that as soon as possible. painterResource and Font technically of one kind of features, better to deprecated them in one release.

Copy link
Member Author

@terrakok terrakok Sep 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? The resource: String is not a file path here. It is a name in the system

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resourcePath: String
Expand All @@ -59,7 +59,7 @@ fun painterResource(
ResourceLoader.Default
)

@ExperimentalComposeUiApi
@Deprecated("Migrate to the Compose resources library. See https://www.jetbrains.com/help/kotlin-multiplatform-dev/compose-images-resources.html")
@Composable
fun painterResource(
resourcePath: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import java.io.FileInputStream
*
* @throws IllegalArgumentException if there is no [resourcePath] in resources
*/
@ExperimentalComposeUiApi
@Deprecated("Migrate to the Compose resources library. See https://www.jetbrains.com/help/kotlin-multiplatform-dev/compose-images-resources.html")
internal inline fun <T> useResource(
resourcePath: String,
loader: ResourceLoader,
Expand All @@ -49,6 +49,7 @@ internal inline fun <T> useResource(
*
* @throws IllegalArgumentException if there is no [resourcePath] in resources
*/
@Deprecated("Migrate to the Compose resources library. See https://www.jetbrains.com/help/kotlin-multiplatform-dev/compose-images-resources.html")
inline fun <T> useResource(
resourcePath: String,
block: (InputStream) -> T
Expand All @@ -63,7 +64,7 @@ inline fun <T> useResource(
* @throws IllegalArgumentException if there is no [resourcePath] in resources
*/
@PublishedApi
@ExperimentalComposeUiApi
@Deprecated("Migrate to the Compose resources library. See https://www.jetbrains.com/help/kotlin-multiplatform-dev/compose-images-resources.html")
internal fun openResource(
resourcePath: String,
loader: ResourceLoader
Expand All @@ -79,7 +80,7 @@ internal fun openResource(
* @throws IllegalArgumentException if there is no [resourcePath] in resources
*/
@PublishedApi
@OptIn(ExperimentalComposeUiApi::class)
@Deprecated("Migrate to the Compose resources library. See https://www.jetbrains.com/help/kotlin-multiplatform-dev/compose-images-resources.html")
internal fun openResource(
resourcePath: String,
): InputStream {
Expand All @@ -94,15 +95,14 @@ internal fun openResource(
* Also the resource should be always available to load, and if you need to handle exceptions,
* it is better to use these functions as well.
*/
@ExperimentalComposeUiApi
@Deprecated("Migrate to the Compose resources library. See https://www.jetbrains.com/help/kotlin-multiplatform-dev/compose-images-resources.html")
interface ResourceLoader {
companion object {
/**
* Resource loader which is capable to load resources from `resources` folder in an application's
* project. Ability to load from dependent modules resources is not guaranteed in the future.
* Use explicit `ClassLoaderResourceLoader` instance if such guarantee is needed.
*/
@ExperimentalComposeUiApi
val Default = ClassLoaderResourceLoader()
}
fun load(resourcePath: String): InputStream
Expand All @@ -111,7 +111,7 @@ interface ResourceLoader {
/**
* Resource loader based on JVM current context class loader.
*/
@ExperimentalComposeUiApi
@Deprecated("Migrate to the Compose resources library. See https://www.jetbrains.com/help/kotlin-multiplatform-dev/compose-images-resources.html")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@Deprecated("Migrate to the Compose resources library. See https://www.jetbrains.com/help/kotlin-multiplatform-dev/compose-images-resources.html")

class ClassLoaderResourceLoader : ResourceLoader {
override fun load(resourcePath: String): InputStream {
// TODO(/~https://github.com/JetBrains/compose-jb/issues/618): probably we shouldn't use
Expand All @@ -126,7 +126,7 @@ class ClassLoaderResourceLoader : ResourceLoader {
/**
* Resource loader from the file system relative to a certain root location.
*/
@ExperimentalComposeUiApi
@Deprecated("Migrate to the Compose resources library. See https://www.jetbrains.com/help/kotlin-multiplatform-dev/compose-images-resources.html")
class FileResourceLoader(val root: File) : ResourceLoader {
override fun load(resourcePath: String): InputStream {
return FileInputStream(File(root, resourcePath))
Expand Down