SuperAPI AI 工具集

compose-preview

前端与建站

查看项目

更新于 10-16 12:38

技能介绍

用途:在 Android Studio 之外将 Compose @Preview 渲染为 PNG,用于验证 UI 改动、迭代设计和对比前后状态。支持 Android(Robolectric)与 Compose Multiplatform Desktop(ImageComposeScene + Skia)。

主要能力:提供 Gradle 插件(ee.schimke.composeai.preview),从编译类中发现 @Preview 并注册渲染任务(discoverPreviews、renderAllPreviews,Gradle 可缓存);compose-preview CLI 通过 Tooling API 驱动构建并输出 PNG 路径;VS Code 扩展提供预览面板、CodeLens 与悬停操作。CLI 命令包括 show、list、render、a11y、doctor,支持 --module、--variant、--filter、--id、--json、--output 等选项;JSON 输出含 pngPath、sha256 与 changed 标记。还支持多预览注解、暂停帧时钟、@ScrollingPreview 滚动截图及 ATF 无障碍检查。

使用方式:先安装 CLI 并运行医生检查:curl -fsSL https://raw.githubusercontent.com/yschimke/compose-ai-tools/main/scripts/install.sh | bash 然后 compose-preview doctor;在模块 build.gradle.kts 中应用插件 id("ee.schimke.composeai.preview") version "0.7.11"。设计可预览 composable 推荐状态提升,拆出无状态内层组件。

限制:@Preview 仅调用无参或全默认参数 composable;a11y 模式会禁用暂停时钟,不宜与动画时间线并用;CMP Desktop 无逐预览时钟控制;@ScrollingPreview 仅支持 Android 且仅垂直滚动。具体收费、价格与平台支持细节暂未提供。