桌面上的 Compose 入门程序在 Linux 上非常滞后
我刚刚使用 Intellij 启动了一个桌面项目,使用默认生成的代码构建,在 Linux 上运行它,并且它有效。然后我为按钮文本添加了一个计数器变量(如下所示),它也像以前一样运行。但是当我点击按钮时,点击反应后文本的变化需要长达 10 秒的时间。想知道可能出了什么问题。
我运行的是 Xubuntu 22.04。
@Composable
@Preview
fun App() {
var text by remember { mutableStateOf("Hello, World!") }
var ic by remember { mutableStateOf(0) }
MaterialTheme {
Button(onClick = {
ic++
text = "Hello, Desktop! $ic"
}) {
Text(text)
}
}
}
fun main() = application {
Window(onCloseRequest = ::exitApplication) {
App()
}
}
我的构建.gradle:
import org.jetbrains.compose.compose
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm") version "1.6.10"
id("org.jetbrains.compose") version "1.1.1"
}
group = "me.xxxx"
version = "1.0"
repositories {
google()
mavenCentral()
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
}
dependencies {
implementation(compose.desktop.currentOs)
}
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "11"
}
compose.desktop {
application {
mainClass = "MainKt"
nativeDistributions {
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
packageName = "Test"
packageVersion = "1.0.0"
}
}
}
I just started a desktop project with Intellij, built with the default generated code, ran it on Linux, and it worked. Then I added a counter variable for the button text (shown as follows), it also ran as before. But when I click on the button, the change of text on reaction to the click takes as long as 10 seconds. Wonder what can be wrong.
I am running Xubuntu 22.04.
@Composable
@Preview
fun App() {
var text by remember { mutableStateOf("Hello, World!") }
var ic by remember { mutableStateOf(0) }
MaterialTheme {
Button(onClick = {
ic++
text = "Hello, Desktop! $ic"
}) {
Text(text)
}
}
}
fun main() = application {
Window(onCloseRequest = ::exitApplication) {
App()
}
}
My build.gradle:
import org.jetbrains.compose.compose
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm") version "1.6.10"
id("org.jetbrains.compose") version "1.1.1"
}
group = "me.xxxx"
version = "1.0"
repositories {
google()
mavenCentral()
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
}
dependencies {
implementation(compose.desktop.currentOs)
}
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "11"
}
compose.desktop {
application {
mainClass = "MainKt"
nativeDistributions {
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
packageName = "Test"
packageVersion = "1.0.0"
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,事实证明一个虚拟盒设置问题。我在MacBook Pro托管的VirtualBox上运行Xubuntu。我需要将图形控制器设置为VirtualBox上的VMSVGA。所以现在响应迅速。
Well, it turns out a VirtualBox setting issue. I run Xubuntu on VirtualBox hosted by MacBook Pro. I need to set graphics controller to VMSVGA on VirtualBox. So now it's responsive.