Skip to content

Open source CapCut alternative.

TypeScript

feat(app): collapsed notch reads the latest line on two lines, on every display

David Le01e4934f62e5
diff --git a/apps/Donkey/Sources/Donkey/UserQueryOverlayController.swift b/apps/Donkey/Sources/Donkey/UserQueryOverlayController.swift
index fc93161a..2b9def0d 100644
--- a/apps/Donkey/Sources/Donkey/UserQueryOverlayController.swift
+++ b/apps/Donkey/Sources/Donkey/UserQueryOverlayController.swift
@@ -1013,7 +1013,8 @@ final class UserQueryOverlayController {
chinHeight: 0,
needsLogin: model.needsLogin
)
- let chinTextWidth = widthProbe.layout.collapsedSurfaceFrame.width - Self.statusChinHorizontalInset
+ let collapsedWidth = widthProbe.layout.collapsedSurfaceFrame.width
+ let chinTextWidth = collapsedWidth - Self.statusChinHorizontalInset
return NotchMetrics(
voidWidth: voidWidth,
@@ -1023,10 +1024,36 @@ final class UserQueryOverlayController {
isHostExpanded: isStatusHostExpanded,
screenWidth: screen.frame.width,
chinHeight: statusChinHeight(textWidth: chinTextWidth),
+ collapsedTopRowExtraHeight: statusCollapsedTopRowExtraHeight(
+ collapsedWidth: collapsedWidth,
+ hasNotch: hasNotch
+ ),
needsLogin: model.needsLogin
)
}
+ /// On a no-notch display the collapsed line renders inline in the top row (a real notch routes it into
+ /// the chin band instead). It shows the same rotating surfaced-task line the chin does, so size the
+ /// pill to the tallest line that can rotate through — the max wrapped-line count across the surfaced
+ /// tasks, or the headline fallback when nothing is surfaced — and grow by one line-height when that is
+ /// two lines. The text width subtracts the pill's pointer lane and gutter, measured narrow so the
+ /// prediction never under-counts and clips. A real notch returns 0 — its second line lives in
+ /// `statusChinHeight`.
+ private func statusCollapsedTopRowExtraHeight(collapsedWidth: CGFloat, hasNotch: Bool) -> CGFloat {
+ guard !hasNotch else { return 0 }
+ let textWidth = collapsedWidth - Self.statusCollapsedTopRowHorizontalReserve
+ let headline = UserQueryNotchStatusView.collapsedHeadline(
+ tasks: model.notchTasks,
+ state: model.promptState
+ )
+ let lines = model.notchSurfacedTasks.reduce(
+ Self.chinLineCount(for: headline, width: textWidth)
+ ) { partial, task in
+ max(partial, Self.chinLineCount(for: task.chinDisplayText, width: textWidth))
+ }
+ return lines >= 2 ? Self.statusChinLineHeight : 0
+ }
+
/// The collapsed chin hangs below the notch whenever a task is surfaced — running, a completion, or
/// a failure the user hasn't dismissed yet. The notch view rotates which one's line it shows. The
/// band fits one line by default and grows by a line-height to seat a wrapped second line (capped
@@ -1073,6 +1100,11 @@ final class UserQueryOverlayController {
private static let statusChinLineHeight: CGFloat = 15
private static let statusChinBottomMargin: CGFloat = 8
private static let statusChinHorizontalInset: CGFloat = 24
+ /// Horizontal chrome the no-notch collapsed top row spends before its text: the 14pt side paddings
+ /// (28), the three 7pt HStack gaps (21), the 14pt pointer, and the widest gutter slot — the running
+ /// clock (~46). Subtracting all of it leaves the narrowest width the text ever gets, so a wrap
+ /// predicted here always holds when the gutter is smaller, never clipping the grown second line.
+ private static let statusCollapsedTopRowHorizontalReserve: CGFloat = 109
private var statusExpandedContentHeight: CGFloat {
// Logged out: the expanded login is a short wide bar (label + Login button), not the full panel.
diff --git a/apps/Donkey/Sources/DonkeyContracts/UserQueryNotchLayout.swift b/apps/Donkey/Sources/DonkeyContracts/UserQueryNotchLayout.swift
index 35c3a02a..7aab22b8 100644
--- a/apps/Donkey/Sources/DonkeyContracts/UserQueryNotchLayout.swift
+++ b/apps/Donkey/Sources/DonkeyContracts/UserQueryNotchLayout.swift
@@ -85,6 +85,10 @@ public struct UserQueryNotchMetrics: Equatable, Sendable {
public var screenWidth: CGFloat
/// Chin band below the collapsed notch row while a task streams (0 otherwise).
public var chinHeight: CGFloat
+ /// Extra height for a wrapped second line of the no-notch collapsed headline. A real notch routes the
+ /// line into a chin band (`chinHeight`); a no-notch display renders it inline in the top row, so when
+ /// it wraps the pill grows by this instead. 0 on a real notch, and 0 when the line fits one row.
+ public var collapsedTopRowExtraHeight: CGFloat
/// Logged out: render the login call-to-action instead of the task surface. Collapsed shows just
/// the "Login to use Donkey" line; expanding reveals a wide, short bar with the Login button.
public var needsLogin: Bool
@@ -105,6 +109,7 @@ public struct UserQueryNotchMetrics: Equatable, Sendable {
isHostExpanded: Bool,
screenWidth: CGFloat,
chinHeight: CGFloat = 0,
+ collapsedTopRowExtraHeight: CGFloat = 0,
needsLogin: Bool = false
) {
self.voidWidth = voidWidth
@@ -114,6 +119,7 @@ public struct UserQueryNotchMetrics: Equatable, Sendable {
self.isHostExpanded = isHostExpanded
self.screenWidth = screenWidth
self.chinHeight = chinHeight
+ self.collapsedTopRowExtraHeight = collapsedTopRowExtraHeight
self.needsLogin = needsLogin
}
@@ -199,9 +205,12 @@ public struct UserQueryNotchMetrics: Equatable, Sendable {
}
/// The band below the collapsed notch row: the login call-to-action when logged out (real notch
- /// only — no-notch displays render it inline), otherwise the streaming chin.
+ /// only — no-notch displays render it inline), the streaming chin on a real notch, or — on a no-notch
+ /// display — the room for a wrapped second line of the inline headline.
private var collapsedExtraHeight: CGFloat {
- guard needsLogin else { return effectiveChinHeight }
+ guard needsLogin else {
+ return canRenderTextInTopRow ? collapsedTopRowExtraHeight : effectiveChinHeight
+ }
return canRenderTextInTopRow ? 0 : Self.loginCollapsedBandHeight
}
diff --git a/apps/Donkey/Sources/DonkeyUI/UserQueryNotchStatusView.swift b/apps/Donkey/Sources/DonkeyUI/UserQueryNotchStatusView.swift
index eea0af13..bf6faf33 100644
--- a/apps/Donkey/Sources/DonkeyUI/UserQueryNotchStatusView.swift
+++ b/apps/Donkey/Sources/DonkeyUI/UserQueryNotchStatusView.swift
@@ -379,30 +379,48 @@ public struct UserQueryNotchStatusView: View {
}
private var fullWidthCollapsedContent: some View {
- HStack(spacing: 7) {
- pointerCluster(size: 14)
- // While a task waits on the user, its pointer stays lit and pulses for attention — the
- // same cue the expanded row gives — so the blocked thread reads at a glance.
- .modifier(AttentionPulse(active: isPrimaryWaitingOnUser))
+ // A no-notch display has no camera void to route around, so the line lives inline here rather
+ // than in a chin band — but it reads the very same rotating line the chin does (the surfaced
+ // conversation's latest line), so both layouts narrate identically. It gets the same two-line
+ // budget; the pill grows by a line (see the controller's `statusCollapsedTopRowExtraHeight`)
+ // when that line wraps.
+ TimelineView(.periodic(from: Self.chinRotationAnchor, by: Self.chinRotationInterval)) { context in
+ let speaker = rotatingChinTask(at: context.date)
+ HStack(spacing: 7) {
+ pointerCluster(size: 14)
+ // While a task waits on the user, its pointer stays lit and pulses for attention — the
+ // same cue the expanded row gives — so the blocked thread reads at a glance.
+ .modifier(AttentionPulse(active: isPrimaryWaitingOnUser))
- Text(collapsedHeadline)
- .font(.system(size: 12, weight: .regular))
- .foregroundStyle(Color.white.opacity(0.92))
- .lineLimit(1)
- .truncationMode(.tail)
+ Text(collapsedTopRowText(speaker: speaker))
+ .font(.system(size: 12, weight: .regular))
+ .foregroundStyle(Color.white.opacity(0.92))
+ .lineLimit(2)
+ .truncationMode(.tail)
- Spacer(minLength: 0)
+ Spacer(minLength: 0)
- // The gutter carries the live elapsed clock while a task runs, then the waiting-on-user "!"
- // glyph (or the update cloud) — the same indicators a void-aware host raises.
- collapsedRightSlot
+ // The gutter carries the live elapsed clock while a task runs, then the waiting-on-user "!"
+ // glyph (or the update cloud) — the same indicators a void-aware host raises.
+ collapsedRightSlot
+ }
+ .padding(.horizontal, max(10, layout.contentHorizontalInset))
+ .frame(
+ width: collapsedSurfaceWidth,
+ height: collapsedSurfaceHeight,
+ alignment: .center
+ )
}
- .padding(.horizontal, max(10, layout.contentHorizontalInset))
- .frame(
- width: collapsedSurfaceWidth,
- height: collapsedSurfaceHeight,
- alignment: .center
- )
+ }
+
+ /// The line the no-notch collapsed row shows: the rotating surfaced task's latest line, identical to
+ /// the chin band. Only when nothing is surfaced does it fall back to the headline (e.g. "Thinking",
+ /// or a freshly typed prompt that has no conversation line yet).
+ private func collapsedTopRowText(speaker: UserQueryConversation?) -> String {
+ if let speaker {
+ return chinText(for: speaker)
+ }
+ return collapsedHeadline
}
private var voidAwareCollapsedContent: some View {
@@ -804,6 +822,10 @@ public struct UserQueryNotchStatusView: View {
/// `isAwaitingUserResponse` (which gates the Reply button): a permission request also waits on the
/// user and pulses for attention, but is answered with Approve / Deny rather than Reply.
private func isWaitingOnUser(_ task: UserQueryConversation) -> Bool {
+ Self.isWaitingOnUser(task)
+ }
+
+ static func isWaitingOnUser(_ task: UserQueryConversation) -> Bool {
task.status.isAwaitingUserResponse || task.status == .waitingForPermission
}
@@ -1197,19 +1219,23 @@ public struct UserQueryNotchStatusView: View {
}
private var taskTitle: String {
- if let primaryTask {
- return primaryTask.title
+ Self.taskTitle(tasks: tasks, state: state)
+ }
+
+ /// The notch's headline text. Factored to a static so the controller can measure the exact string the
+ /// pill renders when sizing the no-notch collapsed row for a wrapped second line.
+ static func taskTitle(tasks: [UserQueryConversation], state: UserQueryState) -> String {
+ if let primary = tasks.first {
+ return primary.title
}
- if let taskDisplayText {
- return taskDisplayText
+ if let display = taskDisplayText(state: state) {
+ return display
}
switch state.leadingSignalLevel {
- case .idle:
+ case .idle, .ready:
return "Idle"
- case .ready:
- return "Ready"
case .thinking:
return "Thinking"
}
@@ -1219,11 +1245,15 @@ public struct UserQueryNotchStatusView: View {
/// user, the notch reads back the agent's question (carried in `detail`) instead, so the pill shows
/// what the agent is asking rather than echoing what the user originally typed.
private var collapsedHeadline: String {
- if let primaryTask, isWaitingOnUser(primaryTask) {
- let question = primaryTask.detail.trimmingCharacters(in: .whitespacesAndNewlines)
+ Self.collapsedHeadline(tasks: tasks, state: state)
+ }
+
+ public static func collapsedHeadline(tasks: [UserQueryConversation], state: UserQueryState) -> String {
+ if let primary = tasks.first, isWaitingOnUser(primary) {
+ let question = primary.detail.trimmingCharacters(in: .whitespacesAndNewlines)
if !question.isEmpty { return question }
}
- return taskTitle
+ return taskTitle(tasks: tasks, state: state)
}
/// Whether the surfaced task is blocked on the user — drives the collapsed pointer's attention pulse.
@@ -1242,10 +1272,8 @@ public struct UserQueryNotchStatusView: View {
}
switch state.leadingSignalLevel {
- case .idle:
+ case .idle, .ready:
return hasTaskDisplayText ? "Needs attention" : "Idle"
- case .ready:
- return "Ready"
case .thinking:
return "Thinking"
}
@@ -1350,6 +1378,10 @@ public struct UserQueryNotchStatusView: View {
}
private var taskDisplayText: String? {
+ Self.taskDisplayText(state: state)
+ }
+
+ static func taskDisplayText(state: UserQueryState) -> String? {
let text = UserQueryCopy.normalizedDisplayText(state.promptText)
guard UserQueryCopy.isTaskDisplayText(text) else {
return nil
@@ -1359,7 +1391,7 @@ public struct UserQueryNotchStatusView: View {
}
private var isResting: Bool {
- state.leadingSignalLevel == .idle && !hasTaskDisplayText
+ (state.leadingSignalLevel == .idle || state.leadingSignalLevel == .ready) && !hasTaskDisplayText
}
private var accentColor: Color {
diff --git a/apps/Donkey/Tests/DonkeyRuntimeTests/UserQueryNotchMetricsTests.swift b/apps/Donkey/Tests/DonkeyRuntimeTests/UserQueryNotchMetricsTests.swift
index bf8c784b..06cd277d 100644
--- a/apps/Donkey/Tests/DonkeyRuntimeTests/UserQueryNotchMetricsTests.swift
+++ b/apps/Donkey/Tests/DonkeyRuntimeTests/UserQueryNotchMetricsTests.swift
@@ -57,4 +57,41 @@ struct UserQueryNotchMetricsTests {
UserQueryNotchMetrics.fallbackVoidHeight
)
}
+
+ @Test
+ func noVoidCollapsedRowGrowsForWrappedSecondLine() {
+ func collapsedHeight(extra: CGFloat) -> CGFloat {
+ UserQueryNotchMetrics(
+ voidWidth: 0,
+ voidHeight: 0,
+ expandedContentHeight: UserQueryNotchMetrics.expandedTaskContentHeight,
+ isExpanded: false,
+ isHostExpanded: false,
+ screenWidth: UserQueryNotchMetrics.defaultScreenWidth,
+ collapsedTopRowExtraHeight: extra
+ ).layout.collapsedSurfaceFrame.height
+ }
+
+ // The inline headline's second line adds exactly its line-height to the collapsed pill.
+ #expect(collapsedHeight(extra: 15) == collapsedHeight(extra: 0) + 15)
+ }
+
+ @Test
+ func physicalVoidCollapsedRowIgnoresTopRowExtraHeight() {
+ // A real notch routes the second line into the chin band, so the inline top-row growth never
+ // applies — the collapsed pill stays the single-row height regardless of the value passed.
+ func collapsedHeight(extra: CGFloat) -> CGFloat {
+ UserQueryNotchMetrics(
+ voidWidth: UserQueryNotchMetrics.fallbackVoidWidth,
+ voidHeight: UserQueryNotchMetrics.fallbackVoidHeight,
+ expandedContentHeight: UserQueryNotchMetrics.expandedTaskContentHeight,
+ isExpanded: false,
+ isHostExpanded: false,
+ screenWidth: UserQueryNotchMetrics.defaultScreenWidth,
+ collapsedTopRowExtraHeight: extra
+ ).layout.collapsedSurfaceFrame.height
+ }
+
+ #expect(collapsedHeight(extra: 15) == collapsedHeight(extra: 0))
+ }
}