Chris Sinco [G]
03/23/2021, 2:25 AMsvgResource
function expected to work in the context of a Compose Desktop app running in an IntelliJ plugin? I tried adding a simple SVG into the resources
directory, using the IDEA plugin example, then referenced it in an Icon
. I get this error now from openResourceStream
java.lang.IllegalArgumentException: Resource circle.svg not found
at androidx.compose.ui.res.Resources_desktopKt.openResourceStream(Resources.desktop.kt:23)
at androidx.compose.ui.res.DesktopSvgResources_desktopKt.svgResource(DesktopSvgResources.desktop.kt:48)
at com.jetbrains.compose.ComposableSingletons$ComposeDemoActionKt$lambda-1$1.invoke(ComposeDemoAction.kt:60)
at com.jetbrains.compose.ComposableSingletons$ComposeDemoActionKt$lambda-1$1.invoke(ComposeDemoAction.kt:54)
Chris Sinco [G]
03/23/2021, 2:27 AMWindow
and main
it just works.olonho
03/23/2021, 7:38 AMIgor Demin
03/23/2021, 8:06 AMChris Sinco [G]
03/23/2021, 5:22 PMvectorXmlResource
(pointing to a vector drawable in resources
instead of an SVG), and the same problem. I think it’s because both functions under the hood call openResourceStream
which is where the resource path issue is happening.Chris Sinco [G]
03/23/2021, 5:22 PMChris Sinco [G]
03/23/2021, 5:23 PMresources
folder in the project, then point to it using an Icon
composable in this function: https://github.com/JetBrains/compose-jb/blob/master/examples/intelliJPlugin/src/main/kotlin/com/jetbrains/compose/ComposeDemoAction.kt#L52Chris Sinco [G]
03/23/2021, 5:24 PMolonho
03/23/2021, 6:11 PMsamuel
03/23/2021, 7:04 PMERROR - llij.ide.plugins.PluginManager - Resource * not found
The work around did not help for me at leastChris Sinco [G]
03/23/2021, 7:17 PMIcon(
imageVector = vectorXmlResource("ic_circle.xml"),
contentDescription = "Circle icon"
)
Chris Sinco [G]
03/23/2021, 7:18 PMsamuel
03/23/2021, 7:25 PM// Called from DemoDialog
ImageComposable(classLoader = this@DemoDialog::class.java.classLoader)
@Composable
fun ImageComposable(classLoader: ClassLoader) {
Thread.currentThread().contextClassLoader = classLoader
Image(
// bitmap = imageResource("some_image.png"), // If you want to use an ImageBitmap
imageVector = vectorXmlResource("some_image.xml"),
contentDescription = "Sample",
modifier = Modifier.fillMaxSize()
)
}
samuel
03/23/2021, 7:26 PMClassLoader.getSystemClassLoader()
was supposed to be used as he described, but passing the classloader from the dialog instead works for meChris Sinco [G]
03/23/2021, 7:28 PMsamuel
03/23/2021, 7:42 PMDemoAction
/ DemoDialog
directly, rather than having it as a parameter
Thread.currentThread().contextClassLoader = ComposeDemoAction::class.java.classLoader
Chris Sinco [G]
03/23/2021, 7:42 PMClassLoader
instance all the way down my Compose hierarchies to the call site of vectorResource
svgResource
, etc?Chris Sinco [G]
03/23/2021, 7:45 PMsamuel
03/23/2021, 7:48 PMChris Sinco [G]
03/23/2021, 7:50 PMChris Sinco [G]
03/23/2021, 7:51 PMChris Sinco [G]
03/23/2021, 7:52 PMThread.currentThread().contextClassLoader = PluginAction::class.java.classLoader
samuel
03/23/2021, 8:02 PMYou can callI tried this but it didn’t work, only when i specified it at the root of the hierarchy did it workthere, not in Composable function.Thread.currentThread().contextClassLoader = ClassLoader.getSystemClassLoader()
samuel
03/23/2021, 8:03 PMClassLoader.getSystemClassLoader()
on its own never worked eitherChris Sinco [G]
03/23/2021, 11:08 PM