From 2a3027a5e72d88bd1c68143fc98a4c2fd2381a08 Mon Sep 17 00:00:00 2001 From: Alexey Tsvetkov <654232+AlexeyTsvetkov@users.noreply.github.com> Date: Fri, 26 Nov 2021 04:05:36 +0300 Subject: [PATCH] Try to fix images with preview in tooling (#1458) Maybe it will fix #1160 Fix for refactored Paragraph.getHorizontalPosition (#115) --- .../tooling/preview/rpc/RemotePreviewHost.kt | 18 +++++++-- .../simple-preview-example/build.gradle.kts | 4 +- .../pure-jvm/build.gradle.kts | 4 ++ .../pure-jvm/src/main/kotlin/preview.kt | 38 ++++++++++++++---- .../src/main/resources/compose-logo-white.png | Bin 0 -> 11031 bytes 5 files changed, 50 insertions(+), 14 deletions(-) create mode 100644 idea-plugin/examples/simple-preview-example/pure-jvm/src/main/resources/compose-logo-white.png diff --git a/gradle-plugins/preview-rpc/src/main/kotlin/org/jetbrains/compose/desktop/ui/tooling/preview/rpc/RemotePreviewHost.kt b/gradle-plugins/preview-rpc/src/main/kotlin/org/jetbrains/compose/desktop/ui/tooling/preview/rpc/RemotePreviewHost.kt index cd02d330ae..7b71c283aa 100644 --- a/gradle-plugins/preview-rpc/src/main/kotlin/org/jetbrains/compose/desktop/ui/tooling/preview/rpc/RemotePreviewHost.kt +++ b/gradle-plugins/preview-rpc/src/main/kotlin/org/jetbrains/compose/desktop/ui/tooling/preview/rpc/RemotePreviewHost.kt @@ -7,16 +7,12 @@ package org.jetbrains.compose.desktop.ui.tooling.preview.rpc import java.io.File import java.lang.RuntimeException -import java.lang.reflect.Method import java.net.SocketTimeoutException import java.net.URLClassLoader import java.util.concurrent.atomic.AtomicReference import kotlin.concurrent.thread import kotlin.system.exitProcess import kotlin.system.measureTimeMillis -import kotlin.time.DurationUnit -import kotlin.time.ExperimentalTime -import kotlin.time.measureTimedValue val PREVIEW_HOST_CLASS_NAME: String get() = PreviewHost::class.java.canonicalName @@ -111,6 +107,20 @@ internal class PreviewHost(private val log: PreviewLogger, connection: RemoteCon request: FrameRequest ): ByteArray { val classloader = classloaderProvider.getClassloader(classpath) + val thread = Thread.currentThread() + val prevContextClassloader = thread.contextClassLoader + thread.contextClassLoader = classloader + return try { + renderFrame(classloader, request) + } finally { + thread.contextClassLoader = prevContextClassloader + } + } + + private fun renderFrame( + classloader: ClassLoader, + request: FrameRequest + ): ByteArray { val previewFacade = classloader.loadClass(PREVIEW_FACADE_CLASS_NAME) val renderArgsClasses = arrayOf( String::class.java, diff --git a/idea-plugin/examples/simple-preview-example/build.gradle.kts b/idea-plugin/examples/simple-preview-example/build.gradle.kts index 2f642cb193..ab3325fc72 100644 --- a/idea-plugin/examples/simple-preview-example/build.gradle.kts +++ b/idea-plugin/examples/simple-preview-example/build.gradle.kts @@ -6,9 +6,9 @@ buildscript { } dependencies { // __LATEST_COMPOSE_RELEASE_VERSION__ - classpath("org.jetbrains.compose:compose-gradle-plugin:1.0.0-alpha1") + classpath("org.jetbrains.compose:compose-gradle-plugin:0.0.9-preview-images") // __KOTLIN_COMPOSE_VERSION__ - classpath(kotlin("gradle-plugin", version = "1.5.21")) + classpath(kotlin("gradle-plugin", version = "1.5.31")) } } diff --git a/idea-plugin/examples/simple-preview-example/pure-jvm/build.gradle.kts b/idea-plugin/examples/simple-preview-example/pure-jvm/build.gradle.kts index 4a21377d49..ca69c9a947 100644 --- a/idea-plugin/examples/simple-preview-example/pure-jvm/build.gradle.kts +++ b/idea-plugin/examples/simple-preview-example/pure-jvm/build.gradle.kts @@ -7,4 +7,8 @@ plugins { dependencies { implementation(compose.desktop.currentOs) +} + +compose.desktop.application { + mainClass = "PreviewKt" } \ No newline at end of file diff --git a/idea-plugin/examples/simple-preview-example/pure-jvm/src/main/kotlin/preview.kt b/idea-plugin/examples/simple-preview-example/pure-jvm/src/main/kotlin/preview.kt index 9c8d883b3e..dcc3252cb9 100644 --- a/idea-plugin/examples/simple-preview-example/pure-jvm/src/main/kotlin/preview.kt +++ b/idea-plugin/examples/simple-preview-example/pure-jvm/src/main/kotlin/preview.kt @@ -1,16 +1,38 @@ -import androidx.compose.material.Text -import androidx.compose.material.Button -import androidx.compose.runtime.* import androidx.compose.desktop.ui.tooling.preview.Preview +import androidx.compose.foundation.Image +import androidx.compose.foundation.layout.* +import androidx.compose.material.* +import androidx.compose.runtime.* +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.res.painterResource +import androidx.compose.ui.unit.dp +import androidx.compose.ui.window.singleWindowApplication @Preview @Composable fun ExamplePreview() { var text by remember { mutableStateOf("Hello, World!") } - - Button(onClick = { - text = "Hello, Desktop!" - }) { - Text(text) + val buttonColors = ButtonDefaults.buttonColors( + backgroundColor = Color.Blue, + contentColor = Color.White + ) + Button( + colors = buttonColors, + modifier = Modifier.padding(5.dp), + onClick = { text = "Hello, Desktop!" } + ) { + Row { + Image( + painterResource("compose-logo-white.png"), + "compose-logo", + modifier = Modifier.height(32.dp).width(32.dp), + ) + Text(text, modifier = Modifier.padding(top = 8.dp, start = 5.dp)) + } } +} + +fun main() = singleWindowApplication { + ExamplePreview() } \ No newline at end of file diff --git a/idea-plugin/examples/simple-preview-example/pure-jvm/src/main/resources/compose-logo-white.png b/idea-plugin/examples/simple-preview-example/pure-jvm/src/main/resources/compose-logo-white.png new file mode 100644 index 0000000000000000000000000000000000000000..6f97412563411516b2e5de26012275e6837b9708 GIT binary patch literal 11031 zcmeHt`8(9n`}d4Bd!>*iX(5ayvP{X6lAVyP!N?vHjqJvZrF=wD*+M8=F&InsWsqo) ztwxNsLJU!sVQk+seV*(251wDX*WGI%X(OiemLgC2CtXhU5LWHTQ=9hIR9(@i1emI zI9XD!$y%D0%1F-~eU*9;vU+A#>$2un>%mtVsjD|a!+EsCe^*R;WGy(ex{2raddsZ2ruH|_|B zt#$z4)vr!@pExb$r69KE4F5RUS#;=w^6!^tQDy{tZ>F9d#Z#EBV# zltH(&Emr7q+H1Ro5^yh6BJ%(Z{DoP?oB@w;>QjF^4rp)ct3B`9#i60B!32O>NTVgVJ5N z)|}s&)4X2Q%n-jac|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