-
Notifications
You must be signed in to change notification settings - Fork 80
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
Conversation
compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/res/DesktopSvgResources.desktop.kt
Show resolved
Hide resolved
compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/res/DesktopSvgResources.desktop.kt
Outdated
Show resolved
Hide resolved
compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/res/DesktopSvgResources.desktop.kt
Outdated
Show resolved
Hide resolved
compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/res/DesktopSvgResources.desktop.kt
Outdated
Show resolved
Hide resolved
@ExperimentalComposeUiApi | ||
@Deprecated("Migrate to the compose resources library") |
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.
We don't need to
- Remove experimental
- Deprecate experimental (just remove)
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.
We cannot delete these function because they are being used in non experimental public API 🤷
Example:
//non experimental
fun painterResource(resourcePath: String, loader: ResourceLoader): Painter
//non experimental
private fun rememberSvgResource(
resourcePath: String,
loader: ResourceLoader = ResourceLoader.Default
): Painter
//experimental
internal inline fun <T> useResource(
resourcePath: String,
loader: ResourceLoader,
block: (InputStream) -> T
): T
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.
Can we make it internal then?
Checked with Compose 1.7.0 and Kotlin 2.0.20.
(button's texts, scroll items and a logo use compose resources) |
037d679
to
7668150
Compare
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.
Removing experimental marks still doesn't LGTM. We can just remove it instead of committing for endless "deprecation" compatibility support
We can do that for the experimental API, but we should move the implementation inside non-experimental API |
@@ -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( |
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.
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)
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.
@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.
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.
Why? The resource: String
is not a file path here. It is a name in the system
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 is actually a file path. See
Line 152 in eece65f
Font("NotoSans-Italic.ttf") |
compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/res/DesktopSvgResources.desktop.kt
Outdated
Show resolved
Hide resolved
compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/res/Resources.desktop.kt
Outdated
Show resolved
Hide resolved
compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/res/Resources.desktop.kt
Outdated
Show resolved
Hide resolved
@ExperimentalComposeUiApi | ||
class ClassLoaderResourceLoader : ResourceLoader { | ||
override fun load(resourcePath: String): InputStream { | ||
@Deprecated("Migrate to the Compose resources library. See https://www.jetbrains.com/help/kotlin-multiplatform-dev/compose-images-resources.html") |
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.
@Deprecated("Migrate to the Compose resources library. See https://www.jetbrains.com/help/kotlin-multiplatform-dev/compose-images-resources.html") |
Let's wait for a second approval |
@terrakok I believe this broke |
I checked it with the code and it works: @Composable
internal fun App() = AppTheme {
val (gif, setGif) = remember { mutableStateOf<AnimatedImage?>(null) }
LaunchedEffect(Unit) {
setGif(loadAnimatedImage(Res.getUri("files/olaf.gif")))
}
if (gif != null) {
Image(
modifier = Modifier.size(100.dp),
bitmap = gif.animate(),
contentDescription = null
)
}
} If you have a problem then file an issue on the YouTrack, please |
To work with resources in the desktop compose the recommended way is to use the special resources library.
Fixes https://youtrack.jetbrains.com/issue/CMP-1108
Migration snippet
To read java resources by path as Painters you may use:
Release Notes
Breaking changes - Resources
compose.ui
in favour of the new resource library