Skip to content

Open source CapCut alternative.

TypeScript

feat(app): pin the collapsed notch void to the camera

David Le7235cc59bcef
diff --git a/apps/Donkey/Sources/Donkey/UserQueryOverlayController.swift b/apps/Donkey/Sources/Donkey/UserQueryOverlayController.swift
index 1a0c980a..d20c30bd 100644
--- a/apps/Donkey/Sources/Donkey/UserQueryOverlayController.swift
+++ b/apps/Donkey/Sources/Donkey/UserQueryOverlayController.swift
@@ -575,7 +575,11 @@ final class UserQueryOverlayController {
// extra Y offset animate the donkey up and off-screen, then back down when it closes.
let hideOffset = (metrics.surfaceSize.height + Self.missionControlHideClearance) * missionControlHideProgress
let frame = CGRect(
- x: screen.frame.midX - metrics.surfaceSize.width / 2,
+ // Position by the void's center, not the surface's: the collapsed notch seats its void
+ // off-center (a wider trailing lane gives the live clock room) and must still land on the
+ // physical camera. Expanded and no-notch surfaces report a centered void, so this is a no-op
+ // for them.
+ x: screen.frame.midX - metrics.surfaceVoidCenterX,
y: screen.frame.maxY - metrics.surfaceSize.height + hideOffset,
width: metrics.surfaceSize.width,
height: metrics.surfaceSize.height
diff --git a/apps/Donkey/Sources/DonkeyContracts/UserQueryNotchLayout.swift b/apps/Donkey/Sources/DonkeyContracts/UserQueryNotchLayout.swift
index 57804e7e..2a247b6e 100644
--- a/apps/Donkey/Sources/DonkeyContracts/UserQueryNotchLayout.swift
+++ b/apps/Donkey/Sources/DonkeyContracts/UserQueryNotchLayout.swift
@@ -16,6 +16,10 @@ public struct UserQueryNotchLayout: Equatable, Sendable {
public var collapsedCornerRadius: CGFloat
public var expandedCornerRadius: CGFloat
public var canRenderTextInTopRow: Bool
+ /// Distance from the collapsed surface's left edge to the void's left edge — the leading lane width.
+ /// The trailing lane (the remainder past the void) is wider so the live clock fits beside the camera,
+ /// which seats the void off-center; the host is positioned to keep it on the physical camera anyway.
+ public var collapsedVoidLeadingInset: CGFloat
/// Height of the chin band that hangs below the collapsed notch row while a task streams
/// (0 when there is nothing to stream). The notch row itself stays `collapsedVisibleHeight`.
public var chinHeight: CGFloat
@@ -35,6 +39,7 @@ public struct UserQueryNotchLayout: Equatable, Sendable {
collapsedCornerRadius: CGFloat,
expandedCornerRadius: CGFloat,
canRenderTextInTopRow: Bool,
+ collapsedVoidLeadingInset: CGFloat = 0,
chinHeight: CGFloat = 0,
needsLogin: Bool = false
) {
@@ -50,6 +55,7 @@ public struct UserQueryNotchLayout: Equatable, Sendable {
self.collapsedCornerRadius = collapsedCornerRadius
self.expandedCornerRadius = expandedCornerRadius
self.canRenderTextInTopRow = canRenderTextInTopRow
+ self.collapsedVoidLeadingInset = collapsedVoidLeadingInset
self.chinHeight = chinHeight
self.needsLogin = needsLogin
}
@@ -154,11 +160,30 @@ public struct UserQueryNotchMetrics: Equatable, Sendable {
collapsedCornerRadius: Self.collapsedCornerRadius,
expandedCornerRadius: Self.expandedCornerRadius,
canRenderTextInTopRow: canRenderTextInTopRow,
+ collapsedVoidLeadingInset: collapsedVoidLeadingInset,
chinHeight: effectiveChinHeight,
needsLogin: needsLogin
)
}
+ /// X of the void's center within the surface currently being positioned. The collapsed real-notch
+ /// surface seats the void off-center (a wider trailing lane gives the live clock room), so the host
+ /// window is placed by this — not the surface center — to keep the void pinned to the physical
+ /// camera. The expanded panel and the no-notch pill stay centered, where the void already sits
+ /// mid-surface (or there is none).
+ public var surfaceVoidCenterX: CGFloat {
+ guard !isHostExpanded, voidWidth > 0 else { return surfaceSize.width / 2 }
+ return collapsedVoidLeadingInset + voidWidth / 2
+ }
+
+ /// Distance from the collapsed surface's left edge to the void's left edge (the leading lane width).
+ /// Derived from the actual collapsed width so any min/max clamp is split between the lanes in the
+ /// nominal ratio, keeping the void's seat stable.
+ private var collapsedVoidLeadingInset: CGFloat {
+ let laneTotal = max(0, collapsedSurfaceWidth - voidWidth)
+ return laneTotal * (Self.collapsedLeadingLaneWidth / Self.collapsedSideLaneTotal)
+ }
+
/// Only the real notch (with a void) grows a chin; no-notch displays show the
/// streaming line inline in the collapsed row instead.
private var effectiveChinHeight: CGFloat {
@@ -230,7 +255,7 @@ public struct UserQueryNotchMetrics: Equatable, Sendable {
max(
Self.minimumCollapsedSurfaceFrame.width,
Self.commonCollapsedSurfaceFrame.width,
- voidWidth + Self.collapsedSideLaneWidth * 2
+ voidWidth + Self.collapsedSideLaneTotal
)
)
}
@@ -271,7 +296,7 @@ public struct UserQueryNotchMetrics: Equatable, Sendable {
private static let commonCollapsedSurfaceFrame = CGRect(
x: 0,
y: 0,
- width: Self.fallbackVoidWidth + Self.collapsedSideLaneWidth * 2,
+ width: Self.fallbackVoidWidth + Self.collapsedSideLaneTotal,
height: Self.fallbackVoidHeight
)
private static let expandedContentDesignFrame = CGRect(
@@ -280,7 +305,13 @@ public struct UserQueryNotchMetrics: Equatable, Sendable {
width: UserQueryLayout.composerInputSurfaceWidth + Self.inputHorizontalMargin * 2,
height: 280
)
- private static let collapsedSideLaneWidth: CGFloat = 34
+ /// The collapsed surface's side lanes flank the void. The trailing (right) lane is wider than the
+ /// leading (left) one so the live elapsed clock — up to "Nh Nm Ns" — fits beside the camera; the
+ /// leading lane only carries the pointer. The void seats off-center between them (see
+ /// `surfaceVoidCenterX`), which the host positioning compensates for.
+ private static let collapsedLeadingLaneWidth: CGFloat = 34
+ private static let collapsedTrailingLaneWidth: CGFloat = 64
+ private static var collapsedSideLaneTotal: CGFloat { collapsedLeadingLaneWidth + collapsedTrailingLaneWidth }
private static let collapsedCornerRadius: CGFloat = 14
// Prototype spec: the expanded notch window and its input box both use a 14px radius.
private static let expandedCornerRadius: CGFloat = 14
diff --git a/apps/Donkey/Sources/DonkeyUI/UserQueryNotchStatusView.swift b/apps/Donkey/Sources/DonkeyUI/UserQueryNotchStatusView.swift
index 9853122d..1716ce83 100644
--- a/apps/Donkey/Sources/DonkeyUI/UserQueryNotchStatusView.swift
+++ b/apps/Donkey/Sources/DonkeyUI/UserQueryNotchStatusView.swift
@@ -177,6 +177,9 @@ public struct UserQueryNotchStatusView: View {
}
collapsedContentLayer
+ // Keep the off-center void pinned to the camera once the host opens into its wider,
+ // centered canvas (jumps in step with the instant host reframe, never slides).
+ .offset(x: collapsedChromeVoidShift)
// The collapsed chrome fades out as the notch grows open and fades back in as it
// collapses, so it cross-dissolves with the expanded content rather than popping.
.opacity(surfaceIsOpen ? 0 : 1)
@@ -377,6 +380,9 @@ public struct UserQueryNotchStatusView: View {
}
private var collapsedContent: some View {
+ // INVARIANT: every notch change must land on BOTH display kinds. `canRenderTextInTopRow` is the
+ // no-notch (no camera void) display — it renders inline here; the `else` is the physical-notch
+ // (void-aware) layout. A change that touches only one branch is a bug, not a layout choice.
Group {
if layout.canRenderTextInTopRow {
fullWidthCollapsedContent
@@ -409,10 +415,9 @@ public struct UserQueryNotchStatusView: View {
Spacer(minLength: 0)
// The gutter carries the live elapsed clock while a conversation runs, then the waiting-on-user "!"
- // glyph (or the update cloud) — the same indicators a void-aware host raises. With no camera void
- // to route around, the right gutter can stretch, so it shows the full elapsed time (hours,
- // minutes, and seconds) rather than the single largest unit.
- collapsedRightSlot(compactTime: false)
+ // glyph (or the update cloud) — the same indicators a void-aware host raises. The slot shows the
+ // full elapsed time (hours, minutes, and seconds), same as the notched layout's widened gutter.
+ collapsedRightSlot
}
.padding(.horizontal, max(10, layout.contentHorizontalInset))
.frame(
@@ -443,8 +448,8 @@ public struct UserQueryNotchStatusView: View {
.modifier(AttentionPulse(active: isPrimaryWaitingOnUser))
.position(x: collapsedLeadingLaneCenterX, y: layout.collapsedVisibleHeight / 2)
- collapsedRightSlot(compactTime: true)
- .frame(width: collapsedSideLaneWidth, height: layout.collapsedVisibleHeight)
+ collapsedRightSlot
+ .frame(width: collapsedTrailingLaneWidth, height: layout.collapsedVisibleHeight)
.position(x: collapsedTrailingLaneCenterX, y: layout.collapsedVisibleHeight / 2)
if layout.chinHeight > 0, let speaker {
@@ -750,16 +755,37 @@ public struct UserQueryNotchStatusView: View {
layout.expandedCommandOnlyTopPadding
}
- private var collapsedSideLaneWidth: CGFloat {
- max(0, (collapsedSurfaceWidth - layout.voidWidth) / 2)
+ /// The leading lane only holds the pointer; the trailing lane is wider so the live clock fits beside
+ /// the camera. The void seats off-center between them.
+ private var collapsedVoidLeadingInset: CGFloat {
+ layout.collapsedVoidLeadingInset
+ }
+
+ private var collapsedTrailingLaneWidth: CGFloat {
+ max(0, collapsedSurfaceWidth - collapsedVoidLeadingInset - layout.voidWidth)
+ }
+
+ private var collapsedVoidCenterX: CGFloat {
+ collapsedVoidLeadingInset + layout.voidWidth / 2
}
private var collapsedLeadingLaneCenterX: CGFloat {
- collapsedSideLaneWidth / 2
+ collapsedVoidLeadingInset / 2
}
private var collapsedTrailingLaneCenterX: CGFloat {
- collapsedSurfaceWidth - collapsedSideLaneWidth / 2
+ collapsedSurfaceWidth - collapsedTrailingLaneWidth / 2
+ }
+
+ /// While the host is open it sits centered, but the collapsed chrome is still cross-dissolving out of
+ /// that wider canvas. Because the collapsed surface seats the void off-center, a re-centered chrome
+ /// would slide the void off the camera mid-animation. Shift the chrome by the void's offset from the
+ /// surface center while the host is open so the void stays pinned to the camera. The host opens
+ /// instantly (no animation) and `isHostExpanded` tracks it, so the shift jumps in step rather than
+ /// sliding.
+ private var collapsedChromeVoidShift: CGFloat {
+ guard isHostExpanded, layout.voidWidth > 0 else { return 0 }
+ return collapsedSurfaceWidth / 2 - collapsedVoidCenterX
}
private var currentConversationRow: some View {
@@ -1342,7 +1368,7 @@ public struct UserQueryNotchStatusView: View {
/// time only rides alongside the chin (a running conversation always narrates), so the gutter never shows a
/// lonely clock; every state's full elapsed total lives in the expanded row.
@ViewBuilder
- private func collapsedRightSlot(compactTime: Bool) -> some View {
+ private var collapsedRightSlot: some View {
if surfacedErrorConversation != nil {
// A surfaced failure (e.g. an auth error) raises the red warning glyph here while its message
// holds the chin, until the user expands to acknowledge it.
@@ -1356,11 +1382,7 @@ public struct UserQueryNotchStatusView: View {
// Waiting on the user, same as a clarification or review — show the attention glyph.
attentionGlyph()
case .running:
- if compactTime {
- compactLiveTime(since: conversation.createdAt)
- } else {
- fullLiveTime(since: conversation.createdAt)
- }
+ fullLiveTime(since: conversation.createdAt)
case .completed, .paused, .interrupted, .failed, .chatting, .needsAttention, .timedOut:
// The gutter only ever carries the waiting-on-user icons or the live clock — a completed
// conversation keeps surfacing as a colored pointer + chin line, and the rest (including a benign
@@ -1407,34 +1429,15 @@ public struct UserQueryNotchStatusView: View {
.fixedSize()
}
- private func compactLiveTime(since start: Date) -> some View {
- TimelineView(.periodic(from: start, by: 1)) { context in
- slotText(Self.compactElapsed(from: start, to: context.date))
- }
- }
-
- /// Full elapsed time (hours, minutes, and seconds) for the stretchable right gutter on a no-notch
- /// host. Unlike `compactLiveTime`, which squeezes a single unit into the narrow lane beside the camera,
- /// this spells out the whole running total since the gutter has room to grow.
+ /// Full elapsed time (hours, minutes, and seconds) for the collapsed right gutter. The gutter's
+ /// trailing lane is sized to fit the whole running total beside the camera, so the clock never
+ /// collapses to a single unit.
private func fullLiveTime(since start: Date) -> some View {
TimelineView(.periodic(from: start, by: 1)) { context in
slotText(Self.elapsedDescription(from: start, to: context.date))
}
}
- /// Compact elapsed time for the ~34px right slot: a single unit — the largest non-zero value
- /// (hours, else minutes, else seconds) — so it stays legible instead of being shrunk to fit.
- static func compactElapsed(from start: Date, to now: Date) -> String {
- let totalSeconds = max(0, Int(now.timeIntervalSince(start)))
- let hours = totalSeconds / 3600
- let minutes = (totalSeconds % 3600) / 60
- let seconds = totalSeconds % 60
-
- if hours > 0 { return "\(hours)h" }
- if minutes > 0 { return "\(minutes)m" }
- return "\(seconds)s"
- }
-
private var isWorking: Bool {
primaryConversation?.status == .running || state.leadingSignalLevel == .thinking
}
diff --git a/apps/Donkey/Tests/DonkeyRuntimeTests/UserQueryNotchMetricsTests.swift b/apps/Donkey/Tests/DonkeyRuntimeTests/UserQueryNotchMetricsTests.swift
index 2c205822..b1b70f55 100644
--- a/apps/Donkey/Tests/DonkeyRuntimeTests/UserQueryNotchMetricsTests.swift
+++ b/apps/Donkey/Tests/DonkeyRuntimeTests/UserQueryNotchMetricsTests.swift
@@ -76,6 +76,52 @@ struct UserQueryNotchMetricsTests {
#expect(collapsedHeight(extra: 15) == collapsedHeight(extra: 0) + 15)
}
+ @Test
+ func collapsedRealNotchSeatsVoidOffCenterForTheClock() {
+ let metrics = UserQueryNotchMetrics(
+ voidWidth: UserQueryNotchMetrics.fallbackVoidWidth,
+ voidHeight: UserQueryNotchMetrics.fallbackVoidHeight,
+ expandedContentHeight: UserQueryNotchMetrics.expandedConversationContentHeight,
+ isExpanded: false,
+ isHostExpanded: false,
+ screenWidth: UserQueryNotchMetrics.defaultScreenWidth
+ )
+ let layout = metrics.layout
+ let leading = layout.collapsedVoidLeadingInset
+ let trailing = layout.collapsedSurfaceFrame.width - leading - metrics.voidWidth
+
+ // The trailing lane (the live clock's room) is the wider of the two, so the void seats left of
+ // the surface center — and the window positions by the void center, not the surface center.
+ #expect(trailing > leading)
+ #expect(metrics.surfaceVoidCenterX == leading + metrics.voidWidth / 2)
+ #expect(metrics.surfaceVoidCenterX < metrics.surfaceSize.width / 2)
+ }
+
+ @Test
+ func expandedAndNoVoidSurfacesPositionByTheirCenter() {
+ // Expanded host: the void sits mid-surface, so it positions by the surface center (no offset).
+ let expanded = UserQueryNotchMetrics(
+ voidWidth: UserQueryNotchMetrics.fallbackVoidWidth,
+ voidHeight: UserQueryNotchMetrics.fallbackVoidHeight,
+ expandedContentHeight: UserQueryNotchMetrics.expandedConversationContentHeight,
+ isExpanded: true,
+ isHostExpanded: true,
+ screenWidth: UserQueryNotchMetrics.defaultScreenWidth
+ )
+ #expect(expanded.surfaceVoidCenterX == expanded.surfaceSize.width / 2)
+
+ // No-notch collapsed pill: nothing to seat, so it stays centered too.
+ let noVoid = UserQueryNotchMetrics(
+ voidWidth: 0,
+ voidHeight: 0,
+ expandedContentHeight: UserQueryNotchMetrics.expandedConversationContentHeight,
+ isExpanded: false,
+ isHostExpanded: false,
+ screenWidth: UserQueryNotchMetrics.defaultScreenWidth
+ )
+ #expect(noVoid.surfaceVoidCenterX == noVoid.surfaceSize.width / 2)
+ }
+
@Test
func physicalVoidCollapsedRowIgnoresTopRowExtraHeight() {
// A real notch routes the second line into the chin band, so the inline top-row growth never