Open source CapCut alternative.
TypeScript
fix(app): open the notch window instantly, animate only the content
David Le863648c682fb
diff --git a/apps/Donkey/Sources/Donkey/UserQueryOverlayController.swift b/apps/Donkey/Sources/Donkey/UserQueryOverlayController.swiftindex 3fe34beb..40e0855e 100644--- a/apps/Donkey/Sources/Donkey/UserQueryOverlayController.swift+++ b/apps/Donkey/Sources/Donkey/UserQueryOverlayController.swift@@ -34,9 +34,7 @@ final class UserQueryOverlayController {// are cancelled in order instead of racing into a stale animation origin.private var statusHoverPhase: StatusHoverPhase = .collapsedprivate var statusCollapseWorkItem: DispatchWorkItem?- private var statusExpansionWorkItem: DispatchWorkItem?private var statusHostShrinkWorkItem: DispatchWorkItem?- private var statusSurfacedAckWorkItem: DispatchWorkItem?private var spawnDesktopEmergeWorkItems: [String: DispatchWorkItem] = [:]private var hasPrewarmedInputPanel = falseprivate var hasPrewarmedStatusPanelExpansion = false@@ -208,12 +206,8 @@ final class UserQueryOverlayController {timer = nilstatusCollapseWorkItem?.cancel()statusCollapseWorkItem = nil- statusExpansionWorkItem?.cancel()- statusExpansionWorkItem = nilstatusHostShrinkWorkItem?.cancel()statusHostShrinkWorkItem = nil- statusSurfacedAckWorkItem?.cancel()- statusSurfacedAckWorkItem = nilcancelSpawnDesktopEmergeWorkItems()statusHoverPhase = .collapsedstopActivationMonitoring()@@ -607,6 +601,7 @@ final class UserQueryOverlayController {layout: metrics.layout,surfaceWidth: metrics.surfaceSize.width,surfaceHeight: metrics.surfaceSize.height,+ isHostExpanded: isStatusHostExpanded,isExpanded: isStatusExpanded,isCurrentTaskPaused: model.isCurrentTaskPaused,commandText: Binding(@@ -772,7 +767,7 @@ final class UserQueryOverlayController {statusCollapseWorkItem = nilstatusHostShrinkWorkItem?.cancel()statusHostShrinkWorkItem = nil- guard statusHoverPhase != .preparingOpen, statusHoverPhase != .expanded else { return }+ guard statusHoverPhase != .expanded else { return }applyStatusExpanded(true)return}@@ -782,42 +777,22 @@ final class UserQueryOverlayController {private func applyStatusExpanded(_ isExpanded: Bool) {if isExpanded {- guard statusHoverPhase != .preparingOpen, statusHoverPhase != .expanded else { return }-- statusHoverPhase = .preparingOpen- isStatusExpanded = false- // First render the collapsed visual notch inside the already-expanded- // host. The delayed flip below is the only step that should animate.- prepareStatusHostForExpansion()-- let workItem = DispatchWorkItem { [weak self] in- guard let self,- self.statusHoverPhase == .preparingOpen,- self.isStatusHostExpanded,- !self.isStatusExpanded else { return }- self.isStatusExpanded = true- self.statusHoverPhase = .expanded- self.statusExpansionWorkItem = nil- self.updateStatusPanelView()- self.focusStatusComposerTextInputIfAvailable()- // Opening the notch dismisses the completed pointers piled up in the collapsed- // surface — but only once the open spring has settled. Clearing them inside this- // expand transaction pulls the collapsed pointer cluster out of the animated- // subtree mid-spring, which makes SwiftUI snap the surface open instead of- // springing it. Deferring keeps the expand a pure `isExpanded` toggle.- self.scheduleSurfacedCompletionDismissal()- }- statusExpansionWorkItem = workItem- DispatchQueue.main.asyncAfter(- deadline: .now() + NotchMetrics.openHostPreparationDelay,- execute: workItem- )+ guard statusHoverPhase != .expanded else { return }++ // Mouse enter: open the window as fast as possible, with no animation, then animate the+ // content in. The host jumps to its expanded size inside updateStatusPanelView and the+ // black surface follows it instantly; only the expanded content animates, off the+ // `isStatusExpanded` change. No two-phase spring, so nothing to race.+ statusHoverPhase = .expanded+ isStatusHostExpanded = true+ isStatusExpanded = true+ // Opening the notch dismisses the completed pointers piled up in the collapsed surface.+ model.acknowledgeSurfacedCompletions()+ updateStatusPanelView()+ focusStatusComposerTextInputIfAvailable()return}- statusExpansionWorkItem?.cancel()- statusExpansionWorkItem = nil-guard statusHoverPhase != .collapsed else { return }guard statusHoverPhase != .closing else {if statusHostShrinkWorkItem == nil {@@ -827,10 +802,9 @@ final class UserQueryOverlayController {}if isStatusExpanded {- // The open already showed the full list; dismiss the surfaced completions now (the- // deferred post-spring dismissal may not have fired yet on a quick close) so the- // collapsing surface settles without the stale pointer cluster.- dismissSurfacedCompletionsForOpenedNotch()+ // Mouse exit is the reverse: animate the content out first. The host stays expanded so+ // the window keeps its size; it collapses instantly once the content has gone, when the+ // host shrink fires below.isStatusExpanded = falseupdateStatusPanelView()}@@ -839,43 +813,6 @@ final class UserQueryOverlayController {scheduleStatusHostShrink()}- /// Dismisses the completed pointers surfaced in the collapsed notch once the open spring has- /// settled. Runs outside the expand transaction so opening stays a pure `isExpanded` toggle —- /// the collapsed surface is hidden behind the expanded content by the time it updates, so the- /// cluster's removal is never visible.- private func scheduleSurfacedCompletionDismissal() {- statusSurfacedAckWorkItem?.cancel()- guard model.notchSurfacedTasks.contains(where: { $0.status == .completed }) else {- statusSurfacedAckWorkItem = nil- return- }-- let workItem = DispatchWorkItem { [weak self] in- guard let self, self.statusHoverPhase == .expanded else { return }- self.statusSurfacedAckWorkItem = nil- self.model.acknowledgeSurfacedCompletions()- self.updateStatusPanelView()- }- statusSurfacedAckWorkItem = workItem- DispatchQueue.main.asyncAfter(- deadline: .now() + Self.surfacedCompletionDismissDelay,- execute: workItem- )- }-- private func dismissSurfacedCompletionsForOpenedNotch() {- statusSurfacedAckWorkItem?.cancel()- statusSurfacedAckWorkItem = nil- model.acknowledgeSurfacedCompletions()- }-- private func prepareStatusHostForExpansion() {- isStatusHostExpanded = true- positionStatusPanel()- updateStatusPanelView()- flushStatusHostLayout()- }-private func prewarmStatusPanelExpansion() {guard !hasPrewarmedStatusPanelExpansion,statusPanel != nil else { return }@@ -1031,10 +968,6 @@ final class UserQueryOverlayController {private static let statusChinBandHeight: CGFloat = 20- /// How long after the notch starts opening to dismiss its surfaced completion pointers. Sits just- /// past the open spring's settle so the dismissal never perturbs the expand animation.- private static let surfacedCompletionDismissDelay: TimeInterval = 0.6-private var statusExpandedContentHeight: CGFloat {if hasStatusTaskDisplayText || !model.notchTasks.isEmpty || model.updateState.headerButtonTitle != nil {return NotchMetrics.expandedTaskContentHeight@@ -1492,7 +1425,6 @@ private enum StatusHoverPhase {// the SwiftUI notch surface. These phases keep quick hover churn from leaving// one layer expanded while the other is still opening or closing.case collapsed- case preparingOpencase expandedcase closing}diff --git a/apps/Donkey/Sources/DonkeyContracts/UserQueryNotchLayout.swift b/apps/Donkey/Sources/DonkeyContracts/UserQueryNotchLayout.swiftindex 6bd426da..37d9ce7e 100644--- a/apps/Donkey/Sources/DonkeyContracts/UserQueryNotchLayout.swift+++ b/apps/Donkey/Sources/DonkeyContracts/UserQueryNotchLayout.swift@@ -71,13 +71,10 @@ public struct UserQueryNotchMetrics: Equatable, Sendable {public static let expandedTaskContentHeight: CGFloat = 280public static let inputHorizontalMargin: CGFloat = 14public static let compactCommandContentVerticalPadding: CGFloat = 30- /// Gap between rendering the collapsed baseline inside the expanded host and flipping- /// `isExpanded` to spring the surface open. The collapsed render must fully commit first —- /// otherwise the two passes coalesce and the notch snaps open instead of springing. One frame- /// was too tight once the collapsed surface grew heavier content (pointer cluster + chin), whose- /// SwiftUI render lands a frame late, so give the baseline a few frames to settle.- public static let openHostPreparationDelay: TimeInterval = 0.08- public static let closeAnimationDuration: TimeInterval = 0.22+ /// How long the open window lingers after the content has animated out, before it closes+ /// instantly. Just past the content-dismiss fade so the window holds its size until the content+ /// is gone, then snaps shut.+ public static let closeAnimationDuration: TimeInterval = 0.12public var voidWidth: CGFloatpublic var voidHeight: CGFloatdiff --git a/apps/Donkey/Sources/DonkeyUI/UserQueryNotchStatusView.swift b/apps/Donkey/Sources/DonkeyUI/UserQueryNotchStatusView.swiftindex 273b9e15..c4ebc52e 100644--- a/apps/Donkey/Sources/DonkeyUI/UserQueryNotchStatusView.swift+++ b/apps/Donkey/Sources/DonkeyUI/UserQueryNotchStatusView.swift@@ -12,6 +12,9 @@ public struct UserQueryNotchStatusView: View {private let layout: UserQueryNotchLayoutprivate let surfaceWidth: CGFloatprivate let surfaceHeight: CGFloat+ /// Whether the host window is open. The window opens/closes instantly (no animation); only the+ /// content animates. The collapsed chrome belongs to the closed window, so it tracks this.+ private let isHostExpanded: Boolprivate let isExpanded: Boolprivate let isCurrentTaskPaused: Bool@Binding private var commandText: String@@ -41,6 +44,7 @@ public struct UserQueryNotchStatusView: View {layout: UserQueryNotchLayout,surfaceWidth: CGFloat,surfaceHeight: CGFloat,+ isHostExpanded: Bool,isExpanded: Bool,isCurrentTaskPaused: Bool,commandText: Binding<String>,@@ -67,6 +71,7 @@ public struct UserQueryNotchStatusView: View {self.layout = layoutself.surfaceWidth = surfaceWidthself.surfaceHeight = surfaceHeight+ self.isHostExpanded = isHostExpandedself.isExpanded = isExpandedself.isCurrentTaskPaused = isCurrentTaskPaused_commandText = commandText@@ -111,8 +116,9 @@ public struct UserQueryNotchStatusView: View {Color.blackcollapsedContentLayer- .opacity(isExpanded ? 0 : 1)- .animation(Self.restContentAnimation, value: isExpanded)+ // The collapsed chrome belongs to the closed window; it appears/disappears with the+ // window itself (instant), not with the animated content.+ .opacity(isHostExpanded ? 0 : 1)expandedContent.opacity(isExpanded ? 1 : 0)@@ -137,12 +143,13 @@ public struct UserQueryNotchStatusView: View {.frame(width: animatingSurfaceWidth, height: animatingSurfaceHeight, alignment: .top).clipShape(notchSurfaceShape(cornerRadius: animatingSurfaceCornerRadius)).shadow(- color: Color.black.opacity(isExpanded ? 0.5 : 0),- radius: isExpanded ? 24 : 0,+ color: Color.black.opacity(isHostExpanded ? 0.5 : 0),+ radius: isHostExpanded ? 24 : 0,x: 0,- y: isExpanded ? 12 : 0+ y: isHostExpanded ? 12 : 0)- .animation(isExpanded ? Self.openEnvelopeAnimation : Self.closeEnvelopeAnimation, value: isExpanded)+ // The window (black surface) snaps to its host size with no animation; only the content+ // inside animates. This is the whole interaction: open the window instantly, animate content..contentShape(Rectangle()).onDrop(of: [UTType.fileURL],@@ -222,12 +229,15 @@ public struct UserQueryNotchStatusView: View {animatingSurfaceFrame.height}+ /// The visible black surface fills the host window, which is resized instantly on open/close.+ /// It is no longer animated — the spring lived here and is gone; only the content animates.+ /// Collapsed chrome only renders while the host is collapsed, so this stays the collapsed size then.private var animatingSurfaceFrame: CGRect {- isExpanded ? layout.expandedSurfaceFrame : layout.collapsedSurfaceFrame+ CGRect(x: 0, y: 0, width: surfaceWidth, height: surfaceHeight)}private var animatingSurfaceCornerRadius: CGFloat {- isExpanded ? layout.expandedCornerRadius : layout.collapsedCornerRadius+ isHostExpanded ? layout.expandedCornerRadius : layout.collapsedCornerRadius}private var collapsedContent: some View {@@ -1003,16 +1013,9 @@ public struct UserQueryNotchStatusView: View {layout.cornerRadius}- private static let openEnvelopeAnimation = Animation.spring(- response: 0.55,- dampingFraction: 0.82,- blendDuration: 0- )- private static let closeEnvelopeAnimation = Animation.easeOut(duration: 0.22)- private static let restContentAnimation = Animation.easeOut(duration: 0.15)- private static let expandedContentAnimation = Animation- .easeOut(duration: 0.3)- .delay(0.15)+ // The window opens/closes instantly; only the content animates. These drive the content fade in+ // and out — the surface (window) itself is no longer animated.+ private static let expandedContentAnimation = Animation.easeOut(duration: 0.3)private static let expandedContentDismissAnimation = Animation.easeOut(duration: 0.1)private static let contentInset: CGFloat = 14private static let taskListCommandSpacing: CGFloat = 8