小编Foe*_*nix的帖子

在 Android 应用程序中启用 compose 指标

我想通过此官方文档启用撰写指标。

在 root gradle 中我添加了以下内容:

subprojects {
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
    kotlinOptions {
        if (project.findProperty("composeCompilerReports") == "true") {
            kotlinOptions.freeCompilerArgs = kotlinOptions.freeCompilerArgs + listOf(
                "-P",
                "plugin:androidx.compose.compiler.plugins.kotlin:reportsDestination=" +
                        project.buildDir.absolutePath + "/compose_reports"
            )
            kotlinOptions.freeCompilerArgs = kotlinOptions.freeCompilerArgs + listOf(
                "-P",
                "plugin:androidx.compose.compiler.plugins.kotlin:metricsDestination=" +
                        project.buildDir.absolutePath + "/compose_metrics"
            )
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

}

并通过以下命令启动构建:

./gradlew assembleRelease -PcomposeCompilerReports=true  --rerun-tasks
Run Code Online (Sandbox Code Playgroud)

构建开始,甚至会为其构建文件夹中的一个应用程序模块创建一份报告。但据我了解,进一步的过程出现了错误:

   > Task :core-common-feature-utils:kaptGenerateStubsReleaseKotlin FAILED
e: Multiple values are not allowed for plugin option androidx.compose.compiler.plugins.kotlin:metricsDestination

Plugin "androidx.compose.compiler.plugins.kotlin" usage:
  liveLiterals <true|false>  Enable Live Literals code generation
  liveLiteralsEnabled <true|false>
                             Enable Live …
Run Code Online (Sandbox Code Playgroud)

android gradle build.gradle

8
推荐指数
1
解决办法
1850
查看次数

Android Jetpack Compose:如何对库中第 3 方可组合项的状态变化做出反应(由 boguszpawlowski 编写的日历)

我调查了 boguszpawlowski Compose Calendar,但找不到跟踪组件状态更改的方法,因为它没有回调。例如,我只需要获取当月的事件(发送请求),之后我应该在日历中显示它们。当用户切换月份时,我应该再次发送请求。描述中的作者建议使用状态提升。

如果您需要对状态更改做出反应,或者从可组合项外部更改状态,则需要将状态从 Calendar 可组合项中提升出来:

  @Composable
  fun MainScreen() {
    val calendarState = rememberCalendarState()
    StaticCalendar(calendarState = calendarState)
   
    // now you can manipulate the state from scope of this composable
    calendarState.monthState.currentMonth = MonthYear.of(2020, 5)
  }
Run Code Online (Sandbox Code Playgroud)

我了解如何更改当前的初始月份,但我不知道当用户滑动日历或单击按钮更改月份时如何监听事件。我该怎么做?

boguszpawlowski ComposeCalendar github 链接

android android-jetpack-compose

1
推荐指数
1
解决办法
1316
查看次数