Skip to content

Open source Grok Bot alternative, Bring your own agent and subscription: message Claude Code, Codex, Gemini CLI, Cursor, Copilot and 40+ AI agents as bots on your own computer, from iPhone, Mac, Windows, Linux or terminal. Agent-agnostic and free. Also a Muse and Dots alternative. Built in Rust.

test(ios): render live activity and widget cards to png sheets

leepokai47fab287f898
diff --git a/apps/ios/Kit/Tests/CodyncKitTests/SurfaceRenderTests.swift b/apps/ios/Kit/Tests/CodyncKitTests/SurfaceRenderTests.swift
new file mode 100644
index 00000000..3876cf74
--- /dev/null
+++ b/apps/ios/Kit/Tests/CodyncKitTests/SurfaceRenderTests.swift
@@ -0,0 +1,69 @@
+import Foundation
+import SwiftUI
+import Testing
+@testable import CodyncKit
+
+/// Renders the Live Activity, Dynamic Island and widget cards to PNG contact sheets for design
+/// review (the simulator's screenshots don't show Live Activities). Runs only when asked:
+/// `TEST_RUNNER_CODYNC_RENDER_DIR=<dir> xcodebuild test … -only-testing:CodyncKitTests/renderSurfaces`
+@MainActor @Test func renderSurfaces() throws {
+ guard let dir = ProcessInfo.processInfo.environment["CODYNC_RENDER_DIR"] else { return }
+ let bot = Bot.widgetPreview[0]
+ let started = Date.now - 154
+ let phases: [(String, BotActivityPresentation)] = [
+ ("Working", .init(status: "working", activity: "Running the test suite.")),
+ ("Needs you", .init(status: "needsInput", activity: "Review the proposed changes.")),
+ ("Done", .init(status: "idle", activity: "")),
+ ("Failed", .init(status: "error", activity: "")),
+ ("Update delayed", .init(status: "working", activity: "", isStale: true)),
+ ]
+
+ func label(_ text: String) -> some View {
+ Text(text).font(.system(size: 11, weight: .medium)).foregroundStyle(Palette.secondary)
+ }
+
+ for scheme in [ColorScheme.light, .dark] {
+ let activities = VStack(alignment: .leading, spacing: 28) {
+ ForEach(phases, id: \.0) { name, state in
+ VStack(alignment: .leading, spacing: 10) {
+ label(name)
+ HStack(alignment: .top, spacing: 20) {
+ BotActivityPreview(bot: bot, state: state, form: .lockScreen, startedAt: started).frame(width: 360)
+ VStack(spacing: 10) {
+ BotActivityPreview(bot: bot, state: state, form: .compact, startedAt: started)
+ BotActivityPreview(bot: bot, state: state, form: .minimal, startedAt: started)
+ }
+ BotActivityPreview(bot: bot, state: state, form: .expanded, startedAt: started).frame(width: 370)
+ }
+ }
+ }
+ }
+ try save(activities, scheme: scheme, to: "\(dir)/activity-\(scheme == .dark ? "dark" : "light").png")
+
+ let widgets = HStack(alignment: .top, spacing: 20) {
+ VStack(alignment: .leading, spacing: 8) {
+ label("Team")
+ BotsTeamCard(bots: Bot.widgetPreview).padding(14).frame(width: 170, height: 170)
+ .background(Palette.surface, in: RoundedRectangle(cornerRadius: 22))
+ }
+ VStack(alignment: .leading, spacing: 8) {
+ label("Bots · Small")
+ BotsWidgetCard(bots: Bot.widgetPreview, wide: false).padding(14).frame(width: 170, height: 170)
+ .background(Palette.surface, in: RoundedRectangle(cornerRadius: 22))
+ }
+ VStack(alignment: .leading, spacing: 8) {
+ label("Bots · Medium")
+ BotsWidgetCard(bots: Bot.widgetPreview, wide: true).padding(14).frame(width: 364, height: 170)
+ .background(Palette.surface, in: RoundedRectangle(cornerRadius: 22))
+ }
+ }
+ try save(widgets, scheme: scheme, to: "\(dir)/widgets-\(scheme == .dark ? "dark" : "light").png")
+ }
+}
+
+@MainActor private func save(_ view: some View, scheme: ColorScheme, to path: String) throws {
+ let renderer = ImageRenderer(content: view.padding(28).background(Palette.background).environment(\.colorScheme, scheme))
+ renderer.scale = 2
+ let data = try #require(renderer.uiImage?.pngData())
+ try data.write(to: URL(fileURLWithPath: path))
+}
diff --git a/docs/design/mobile-widgets.md b/docs/design/mobile-widgets.md
index 85d13bbb..5eb2b772 100644
--- a/docs/design/mobile-widgets.md
+++ b/docs/design/mobile-widgets.md
@@ -61,6 +61,13 @@ State 分頁的 Live Activity 頁顯示鎖定畫面形式,Dynamic Island 頁
狀態色:待回應琥珀(`Palette.attention`)、失敗紅、完成綠;工作中的說明維持灰色,只有需要注意的狀態跳出來。經過時間用 `Text(startedAt, style: .timer)` 由系統自己往上數,不需要推播(`startedAt` 已在 remote content state 裡)。狀態切換時頭像舊臉放大淡出、新臉縮放進場,文字用 `.contentTransition(.interpolate)`,Review/時間列由下往上進場,全部用 `Motion.activityPhase`(0.6 s spring,在 iOS 給 activity 更新的 2 s 內)。Review 只開啟對話,核准仍在 App 的 permission card。
+模擬器截圖看不到 Live Activity,所以 Live Activity、動態島(各狀態 × Lock Screen/Compact/Minimal/Expanded,淺色與深色)和 widget 卡片改用 render 測試輸出 PNG 檢查:
+
+```sh
+cd apps/ios/Kit && TEST_RUNNER_CODYNC_RENDER_DIR=<輸出資料夾> xcodebuild test -scheme CodyncKit-Package \
+ -derivedDataPath ../../../build/dd -destination 'platform=iOS Simulator,id=<sim-id>' '-only-testing:CodyncKitTests/renderSurfaces()'
+```
+
實際形式由 iOS 根據裝置、活動數量與互動決定;App 內的形式選單只控制設計預覽。[Apple Live Activities 設計指南](https://developer.apple.com/design/human-interface-guidelines/live-activities)
所有形式共用 `BotActivityPresentation` 的狀態判斷: